Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 1362]](https://github.com/parthenon-hpc-lab/parthenon/pull/1362) Add support for completely custom "user" output


### Changed (changing behavior/API/variables/...)
Expand Down
26 changes: 26 additions & 0 deletions doc/sphinx/src/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,32 @@ The following is a minimal example to plot a 1D and 2D histogram from the output
plt.pcolormesh(x,y,z,)
plt.show()

User
----

Parthenon provides a simple callback for downstream codes to enroll their own
output routines.
In the input file, include a ``<parthenon/output*>`` block and specify
``file_type = user``.
Output frequency is controlld via ``dt`` or ``dn`` as for other output types.
Using this callback requires a downstream code to implement the
``UserOutput::WriteOutputFile`` (required) and ``UserOutput::GenerateFilename_``
(optional, but recommended given the structure of the other output types)
functions.

.. code:: c++

class UserOutput : public OutputType {
public:
explicit UserOutput(const OutputParameters &oparams) : OutputType(oparams) {}
void WriteOutputFile(Mesh *pm, ParameterInput *pin, SimTime *tm,
const SignalHandler::OutputSignal signal) override;
private:
std::string GenerateFilename_(ParameterInput *pin, SimTime *tm,
const SignalHandler::OutputSignal signal);
};
Comment thread
Yurlungur marked this conversation as resolved.


Ascent (optional)
-----------------

Expand Down
4 changes: 3 additions & 1 deletion src/outputs/outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
// set output variable and optional data format string used in formatted writes
if ((op.file_type != "hst") && (op.file_type != "rst") &&
(op.file_type != "corehdf5") && (op.file_type != "ascent") &&
(op.file_type != "histogram")) {
(op.file_type != "histogram") && op.file_type != "user") {
// Do not use GetOrAddVector because it will pollute the input parameters for
// restarts
if (pin->DoesParameterExist(op.block_name, "variables")) {
Expand Down Expand Up @@ -365,6 +365,8 @@ Outputs::Outputs(Mesh *pm, ParameterInput *pin, SimTime *tm) {
<< std::endl;
PARTHENON_FAIL(msg);
#endif // ifdef ENABLE_HDF5
} else if (op.file_type == "user") {
pnew_type = std::make_shared<UserOutput>(op);
} else if (is_hdf5_output) {
restart = (op.file_type == "rst");
const bool coredump = (op.file_type == "corehdf5");
Expand Down
15 changes: 15 additions & 0 deletions src/outputs/outputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ class HistogramOutput : public OutputType {
};
#endif // ifdef ENABLE_HDF5

//----------------------------------------------------------------------------------------
//! \class UserOutput
// \brief derived OutputType class for User enrolled outputs

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

private:
std::string GenerateFilename_(ParameterInput *pin, SimTime *tm,
const SignalHandler::OutputSignal signal);
};

//----------------------------------------------------------------------------------------
//! \class Outputs

Expand Down
Loading