Skip to content

Commit

Permalink
Merge branch 'pgrete/dncycle' into pgrete/next-opmd-ncycle
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrete committed Nov 29, 2024
2 parents 543dbf9 + 07948ef commit 3147043
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 272 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR 1210]](https://github.com/parthenon-hpc-lab/parthenon/pull/1210) Add cycle based output
- [[PR 1103]](https://github.com/parthenon-hpc-lab/parthenon/pull/1103) Add sparsity to vector wave equation test
- [[PR 1185]](https://github.com/parthenon-hpc-lab/parthenon/pull/1185) Bugfix to particle defragmentation
- [[PR 1184]](https://github.com/parthenon-hpc-lab/parthenon/pull/1184) Fix swarm block neighbor indexing in 1D, 2D
Expand Down
14 changes: 12 additions & 2 deletions doc/sphinx/src/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ Outputs
Outputs from Parthenon are controlled via ``<parthenon/output*>`` blocks,
where ``*`` should be replaced by a unique integer for each block.

The frequency of outputs can be controlled for each block separately
and can be triggered by either (simulation) time or cycle, i.e.,

- ``dt = 0.1`` means that the output for the block is written every 0.1
in simulation time.
- ``dn = 100`` means that the output for the block is written every 100
cycles.

Note that only one option can be chosen for a given block.
To disable an output block without removing it from the input file set
the block's ``dt < 0.0``.
the block's ``dt < 0.0`` and ``dn < 0`` (which is also happening by default
if the paramter is not provided in the input file).

In addition to time base outputs, two additional options to trigger
In addition to time or cycle based outputs, two additional options to trigger
outputs (applies to HDF5, restart and histogram outputs) exist.

- Signaling: If ``Parthenon`` catches a signal, e.g., ``SIGALRM`` which
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ add_library(parthenon
outputs/restart_hdf5.hpp
outputs/restart_opmd.cpp
outputs/restart_opmd.hpp
outputs/vtk.cpp

parthenon/driver.hpp
parthenon/package.hpp
Expand Down
10 changes: 8 additions & 2 deletions src/outputs/ascent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,15 @@ void AscentOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,

// advance output parameters
output_params.file_number++;
output_params.next_time += output_params.dt;
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
if (output_params.dt > 0.0) {
output_params.next_time += output_params.dt;
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
}
if (output_params.dn > 0) {
output_params.next_n += output_params.dn;
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
}
}

} // namespace parthenon
10 changes: 8 additions & 2 deletions src/outputs/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,15 @@ void HistogramOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm
// Only applies to default time-based data dumps, so that writing "now" and "final"
// outputs does not change the desired output numbering.
output_params.file_number++;
output_params.next_time += output_params.dt;
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
if (output_params.dt > 0.0) {
output_params.next_time += output_params.dt;
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
}
if (output_params.dn > 0) {
output_params.next_n += output_params.dn;
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/outputs/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,15 @@ void HistoryOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,

// advance output parameters
output_params.file_number++;
output_params.next_time += output_params.dt;
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
if (output_params.dt > 0.0) {
output_params.next_time += output_params.dt;
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
}
if (output_params.dn > 0) {
output_params.next_n += output_params.dn;
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
}
}

} // namespace parthenon
3 changes: 2 additions & 1 deletion src/outputs/output_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct OutputParameters {
std::string data_format;
std::vector<std::string> packages;
Real next_time, dt;
int next_n, dn;
int file_number;
bool include_ghost_zones, cartesian_vector;
bool single_precision_output;
Expand All @@ -53,7 +54,7 @@ struct OutputParameters {
bool write_swarm_xdmf;
// TODO(felker): some of the parameters in this class are not initialized in constructor
OutputParameters()
: block_number(0), next_time(0.0), dt(-1.0), file_number(0),
: block_number(0), next_time(0.0), dt(-1.0), next_n(0), dn(-1), file_number(0),
include_ghost_zones(false), cartesian_vector(false),
single_precision_output(false), sparse_seed_nans(false),
hdf5_compression_level(5), write_xdmf(false), write_swarm_xdmf(false) {}
Expand Down
36 changes: 28 additions & 8 deletions src/outputs/outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,31 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
op.block_name.assign(pib->block_name);

Real dt = 0.0; // default value == 0 means that initial data is written by default
// for temporal drivers, setting dt to tlim ensures a final output is also written
int dn = -1;
if (tm != nullptr) {
dt = pin->GetOrAddReal(op.block_name, "dt", tm->tlim);
dn = pin->GetOrAddInteger(op.block_name, "dn", -1.0);

// If this is a dn controlled output (dn >= 0), soft disable dt based triggering
// (-> dt = -1), otherwise setting dt to tlim ensures a final output is also
// written for temporal drivers.
const auto tlim = dn >= 0 ? -1 : tm->tlim;
dt = pin->GetOrAddReal(op.block_name, "dt", tlim);
}
// if this output is "soft-disabled" (negative value) skip processing
if (dt < 0.0) {
if (dt < 0.0 && dn < 0) {
pib = pib->pnext; // move to next input block name
continue;
}

PARTHENON_REQUIRE_THROWS(!(dt >= 0.0 && dn >= 0),
"dt and dn are enabled for the same output block, which "
"is not supported. Please set at most one value >= 0.");
// set time of last output, time between outputs
if (tm != nullptr) {
op.next_time = pin->GetOrAddReal(op.block_name, "next_time", tm->time);
op.dt = dt;
op.next_n = pin->GetOrAddInteger(op.block_name, "next_n", tm->ncycle);
op.dn = dn;
}

// set file number, basename, id, and format
Expand Down Expand Up @@ -264,8 +276,6 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
if (op.file_type == "hst") {
pnew_type = new HistoryOutput(op);
num_hst_outputs++;
} else if (op.file_type == "vtk") {
pnew_type = new VTKOutput(op);
} else if (op.file_type == "ascent") {
pnew_type = new AscentOutput(op);
} else if (op.file_type == "openpmd") {
Expand Down Expand Up @@ -457,9 +467,19 @@ void Outputs::MakeOutputs(Mesh *pm, ParameterInput *pin, SimTime *tm,
OutputType *ptype = pfirst_type_;
while (ptype != nullptr) {
if ((tm == nullptr) ||
((ptype->output_params.dt >= 0.0) &&
((tm->ncycle == 0) || (tm->time >= ptype->output_params.next_time) ||
(tm->time >= tm->tlim) || (signal == SignalHandler::OutputSignal::now) ||
// output is not soft disabled and
(((ptype->output_params.dt >= 0.0) || (ptype->output_params.dn >= 0)) &&
// either dump initial data
((tm->ncycle == 0) ||
// or by triggering time or cycle based conditions
((ptype->output_params.dt >= 0.0) &&
((tm->time >= ptype->output_params.next_time) ||
(tm->tlim > 0.0 && tm->time >= tm->tlim))) ||
((ptype->output_params.dn >= 0) &&
((tm->ncycle >= ptype->output_params.next_n) ||
(tm->nlim > 0 && tm->ncycle >= tm->nlim))) ||
// or by manual triggers
(signal == SignalHandler::OutputSignal::now) ||
(signal == SignalHandler::OutputSignal::final) ||
(signal == SignalHandler::OutputSignal::analysis &&
ptype->output_params.analysis_flag)))) {
Expand Down
12 changes: 0 additions & 12 deletions src/outputs/outputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,6 @@ class HistoryOutput : public OutputType {
const SignalHandler::OutputSignal signal) override;
};

//----------------------------------------------------------------------------------------
//! \class VTKOutput
// \brief derived OutputType class for vtk dumps

class VTKOutput : public OutputType {
public:
explicit VTKOutput(const OutputParameters &oparams) : OutputType(oparams) {}
void WriteContainer(SimTime &tm, Mesh *pm, ParameterInput *pin, bool flag) override;
void WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
const SignalHandler::OutputSignal signal) override;
};

//----------------------------------------------------------------------------------------
//! \class AscentOutput
// \brief derived OutputType class for Ascent in situ situ visualization and analysis
Expand Down
10 changes: 8 additions & 2 deletions src/outputs/parthenon_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,15 @@ std::string PHDF5Output::GenerateFilename_(ParameterInput *pin, SimTime *tm,
// Only applies to default time-based data dumps, so that writing "now" and "final"
// outputs does not change the desired output numbering.
output_params.file_number++;
output_params.next_time += output_params.dt;
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
if (output_params.dt > 0.0) {
output_params.next_time += output_params.dt;
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
}
if (output_params.dn > 0) {
output_params.next_n += output_params.dn;
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
}
}
return filename;
}
Expand Down
Loading

0 comments on commit 3147043

Please sign in to comment.