Skip to content

Commit

Permalink
blob2d: Use outputVars to write to output
Browse files Browse the repository at this point in the history
Quantities can be written to output with attributes like units
and conversion factors.
  • Loading branch information
bendudson committed Nov 14, 2023
1 parent 59c176b commit 273f5cf
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions examples/blob2d/blob2d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Blob2D : public PhysicsModel {
nullptr}; ///< Performs Laplacian inversions to calculate phi

protected:
int init(bool UNUSED(restarting)) {
int init(bool UNUSED(restarting)) override {

/******************Reading options *****************/

Expand Down Expand Up @@ -116,17 +116,42 @@ class Blob2D : public PhysicsModel {
phi = 0.0; // Starting guess for first solve (if iterative)

/************ Tell BOUT++ what to solve ************/

SOLVE_FOR(n, omega);

// Output phi
SAVE_REPEAT(phi);
SAVE_ONCE(rho_s, c_s, Omega_i);

return 0;
}

int rhs(BoutReal UNUSED(t)) {
/// Add variables to the output. This can be used to calculate
/// diagnostics
///
/// @param[inout] state A nested dictionary that can be added to
void outputVars(Options& state) override {
// Set time-varying quantity (assignRepeat)
state["phi"].assignRepeat(phi).setAttributes({{"units", "V"},
{"conversion", Te0},
{"standard_name", "potential"},
{"long_name", "Plasma potential"}});

// Force updates to non-varying quantities
state["rho_s"].force(rho_s).setAttributes(
{{"units", "m"},
{"conversion", 1},
{"standard_name", "length normalisation"},
{"long_name", "Gyro-radius length normalisation"}});

state["c_s"].force(c_s).setAttributes({{"units", "m/s"},
{"conversion", 1},
{"standard_name", "velocity normalisation"},
{"long_name", "Sound speed normalisation"}});

state["Omega_i"].force(Omega_i).setAttributes(
{{"units", "s^-1"},
{"conversion", 1},
{"standard_name", "frequency normalisation"},
{"long_name", "Cyclotron frequency normalisation"}});
}

int rhs(BoutReal UNUSED(t)) override {

// Run communications
////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 273f5cf

Please sign in to comment.