Skip to content

Commit 8739373

Browse files
authored
Merge branch 'develop' into lroberts36/add-combined-buffer-communication
2 parents 822a859 + 4cde093 commit 8739373

11 files changed

+75
-272
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added (new features/APIs/variables/...)
66
- [[PR 1192]](https://github.com/parthenon-hpc-lab/parthenon/pull/1103) Coalesced buffer communication
7+
- [[PR 1210]](https://github.com/parthenon-hpc-lab/parthenon/pull/1210) Add cycle based output
78
- [[PR 1103]](https://github.com/parthenon-hpc-lab/parthenon/pull/1103) Add sparsity to vector wave equation test
89
- [[PR 1185]](https://github.com/parthenon-hpc-lab/parthenon/pull/1185) Bugfix to particle defragmentation
910
- [[PR 1184]](https://github.com/parthenon-hpc-lab/parthenon/pull/1184) Fix swarm block neighbor indexing in 1D, 2D

doc/sphinx/src/outputs.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ Outputs
66
Outputs from Parthenon are controlled via ``<parthenon/output*>`` blocks,
77
where ``*`` should be replaced by a unique integer for each block.
88

9+
The frequency of outputs can be controlled for each block separately
10+
and can be triggered by either (simulation) time or cycle, i.e.,
11+
12+
- ``dt = 0.1`` means that the output for the block is written every 0.1
13+
in simulation time.
14+
- ``dn = 100`` means that the output for the block is written every 100
15+
cycles.
16+
17+
Note that only one option can be chosen for a given block.
918
To disable an output block without removing it from the input file set
10-
the block's ``dt < 0.0``.
19+
the block's ``dt < 0.0`` and ``dn < 0`` (which is also happening by default
20+
if the paramter is not provided in the input file).
1121

12-
In addition to time base outputs, two additional options to trigger
22+
In addition to time or cycle based outputs, two additional options to trigger
1323
outputs (applies to HDF5, restart and histogram outputs) exist.
1424

1525
- Signaling: If ``Parthenon`` catches a signal, e.g., ``SIGALRM`` which

src/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ add_library(parthenon
211211
outputs/restart.hpp
212212
outputs/restart_hdf5.cpp
213213
outputs/restart_hdf5.hpp
214-
outputs/vtk.cpp
215214

216215
parthenon/driver.hpp
217216
parthenon/package.hpp

src/outputs/ascent.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,15 @@ void AscentOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
210210

211211
// advance output parameters
212212
output_params.file_number++;
213-
output_params.next_time += output_params.dt;
214213
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
215-
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
214+
if (output_params.dt > 0.0) {
215+
output_params.next_time += output_params.dt;
216+
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
217+
}
218+
if (output_params.dn > 0) {
219+
output_params.next_n += output_params.dn;
220+
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
221+
}
216222
}
217223

218224
} // namespace parthenon

src/outputs/histogram.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,15 @@ void HistogramOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm
559559
// Only applies to default time-based data dumps, so that writing "now" and "final"
560560
// outputs does not change the desired output numbering.
561561
output_params.file_number++;
562-
output_params.next_time += output_params.dt;
563562
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
564-
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
563+
if (output_params.dt > 0.0) {
564+
output_params.next_time += output_params.dt;
565+
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
566+
}
567+
if (output_params.dn > 0) {
568+
output_params.next_n += output_params.dn;
569+
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
570+
}
565571
}
566572
}
567573

src/outputs/history.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,15 @@ void HistoryOutput::WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
211211

212212
// advance output parameters
213213
output_params.file_number++;
214-
output_params.next_time += output_params.dt;
215214
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
216-
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
215+
if (output_params.dt > 0.0) {
216+
output_params.next_time += output_params.dt;
217+
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
218+
}
219+
if (output_params.dn > 0) {
220+
output_params.next_n += output_params.dn;
221+
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
222+
}
217223
}
218224

219225
} // namespace parthenon

src/outputs/output_parameters.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct OutputParameters {
4444
std::string data_format;
4545
std::vector<std::string> packages;
4646
Real next_time, dt;
47+
int next_n, dn;
4748
int file_number;
4849
bool include_ghost_zones, cartesian_vector;
4950
bool single_precision_output;
@@ -53,7 +54,7 @@ struct OutputParameters {
5354
bool write_swarm_xdmf;
5455
// TODO(felker): some of the parameters in this class are not initialized in constructor
5556
OutputParameters()
56-
: block_number(0), next_time(0.0), dt(-1.0), file_number(0),
57+
: block_number(0), next_time(0.0), dt(-1.0), next_n(0), dn(-1), file_number(0),
5758
include_ghost_zones(false), cartesian_vector(false),
5859
single_precision_output(false), sparse_seed_nans(false),
5960
hdf5_compression_level(5), write_xdmf(false), write_swarm_xdmf(false) {}

src/outputs/outputs.cpp

+28-8
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,31 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
117117
op.block_name.assign(pib->block_name);
118118

119119
Real dt = 0.0; // default value == 0 means that initial data is written by default
120-
// for temporal drivers, setting dt to tlim ensures a final output is also written
120+
int dn = -1;
121121
if (tm != nullptr) {
122-
dt = pin->GetOrAddReal(op.block_name, "dt", tm->tlim);
122+
dn = pin->GetOrAddInteger(op.block_name, "dn", -1.0);
123+
124+
// If this is a dn controlled output (dn >= 0), soft disable dt based triggering
125+
// (-> dt = -1), otherwise setting dt to tlim ensures a final output is also
126+
// written for temporal drivers.
127+
const auto tlim = dn >= 0 ? -1 : tm->tlim;
128+
dt = pin->GetOrAddReal(op.block_name, "dt", tlim);
123129
}
124130
// if this output is "soft-disabled" (negative value) skip processing
125-
if (dt < 0.0) {
131+
if (dt < 0.0 && dn < 0) {
126132
pib = pib->pnext; // move to next input block name
127133
continue;
128134
}
135+
136+
PARTHENON_REQUIRE_THROWS(!(dt >= 0.0 && dn >= 0),
137+
"dt and dn are enabled for the same output block, which "
138+
"is not supported. Please set at most one value >= 0.");
129139
// set time of last output, time between outputs
130140
if (tm != nullptr) {
131141
op.next_time = pin->GetOrAddReal(op.block_name, "next_time", tm->time);
132142
op.dt = dt;
143+
op.next_n = pin->GetOrAddInteger(op.block_name, "next_n", tm->ncycle);
144+
op.dn = dn;
133145
}
134146

135147
// set file number, basename, id, and format
@@ -259,8 +271,6 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
259271
if (op.file_type == "hst") {
260272
pnew_type = new HistoryOutput(op);
261273
num_hst_outputs++;
262-
} else if (op.file_type == "vtk") {
263-
pnew_type = new VTKOutput(op);
264274
} else if (op.file_type == "ascent") {
265275
pnew_type = new AscentOutput(op);
266276
} else if (op.file_type == "histogram") {
@@ -438,9 +448,19 @@ void Outputs::MakeOutputs(Mesh *pm, ParameterInput *pin, SimTime *tm,
438448
OutputType *ptype = pfirst_type_;
439449
while (ptype != nullptr) {
440450
if ((tm == nullptr) ||
441-
((ptype->output_params.dt >= 0.0) &&
442-
((tm->ncycle == 0) || (tm->time >= ptype->output_params.next_time) ||
443-
(tm->time >= tm->tlim) || (signal == SignalHandler::OutputSignal::now) ||
451+
// output is not soft disabled and
452+
(((ptype->output_params.dt >= 0.0) || (ptype->output_params.dn >= 0)) &&
453+
// either dump initial data
454+
((tm->ncycle == 0) ||
455+
// or by triggering time or cycle based conditions
456+
((ptype->output_params.dt >= 0.0) &&
457+
((tm->time >= ptype->output_params.next_time) ||
458+
(tm->tlim > 0.0 && tm->time >= tm->tlim))) ||
459+
((ptype->output_params.dn >= 0) &&
460+
((tm->ncycle >= ptype->output_params.next_n) ||
461+
(tm->nlim > 0 && tm->ncycle >= tm->nlim))) ||
462+
// or by manual triggers
463+
(signal == SignalHandler::OutputSignal::now) ||
444464
(signal == SignalHandler::OutputSignal::final) ||
445465
(signal == SignalHandler::OutputSignal::analysis &&
446466
ptype->output_params.analysis_flag)))) {

src/outputs/outputs.hpp

-12
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,6 @@ class HistoryOutput : public OutputType {
143143
const SignalHandler::OutputSignal signal) override;
144144
};
145145

146-
//----------------------------------------------------------------------------------------
147-
//! \class VTKOutput
148-
// \brief derived OutputType class for vtk dumps
149-
150-
class VTKOutput : public OutputType {
151-
public:
152-
explicit VTKOutput(const OutputParameters &oparams) : OutputType(oparams) {}
153-
void WriteContainer(SimTime &tm, Mesh *pm, ParameterInput *pin, bool flag) override;
154-
void WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
155-
const SignalHandler::OutputSignal signal) override;
156-
};
157-
158146
//----------------------------------------------------------------------------------------
159147
//! \class AscentOutput
160148
// \brief derived OutputType class for Ascent in situ situ visualization and analysis

src/outputs/parthenon_hdf5.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,15 @@ std::string PHDF5Output::GenerateFilename_(ParameterInput *pin, SimTime *tm,
597597
// Only applies to default time-based data dumps, so that writing "now" and "final"
598598
// outputs does not change the desired output numbering.
599599
output_params.file_number++;
600-
output_params.next_time += output_params.dt;
601600
pin->SetInteger(output_params.block_name, "file_number", output_params.file_number);
602-
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
601+
if (output_params.dt > 0.0) {
602+
output_params.next_time += output_params.dt;
603+
pin->SetReal(output_params.block_name, "next_time", output_params.next_time);
604+
}
605+
if (output_params.dn > 0) {
606+
output_params.next_n += output_params.dn;
607+
pin->SetInteger(output_params.block_name, "next_n", output_params.next_n);
608+
}
603609
}
604610
return filename;
605611
}

0 commit comments

Comments
 (0)