Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
58397e0
Remove unused `Context` constructor
ZedThree Dec 1, 2025
ab96f26
Add cell indices to `generator::Context`
ZedThree Dec 2, 2025
c5ef3d1
Add ability to use variables from grid files in input expressions
ZedThree Dec 2, 2025
a843556
tests: Only remove temp files if test passes
ZedThree Dec 2, 2025
7c44c66
Enable reading `Field2D`s as well as `Field3D`s for expressions
ZedThree Dec 2, 2025
d3b1346
Refactor reading grid variables for input expressions
ZedThree Dec 2, 2025
42b88b4
Apply clang-format changes
ZedThree Dec 2, 2025
5491001
FieldFactory: Use fieldmesh not localmesh
bendudson Mar 26, 2026
7901046
GridVariable: Load grid variables lazily
bendudson Mar 26, 2026
e9475ff
FieldData: Don't getCoordinates in constructor
bendudson Mar 27, 2026
ab22970
GridVariable: Check mesh->get return
bendudson Mar 27, 2026
d0726d9
FieldGenerators: Fixes and tidying
bendudson Mar 27, 2026
2e96778
GridVariable unit tests: Fix unit test
bendudson Mar 28, 2026
5e18e16
Field2D/3D: Defer sizing until allocation
bendudson Mar 28, 2026
95b01d8
Miscellaneous tidying
bendudson Mar 28, 2026
fe00722
Field2D/3D: Partly revert 8ebc0a0
bendudson Mar 28, 2026
cd04c41
FieldFactory: Don't test values in Y boundary
bendudson Mar 28, 2026
7875384
Clang formatting
bendudson Mar 28, 2026
f94a1e1
Use `gridvar:` namespace for input variables read from grid
ZedThree Jun 19, 2026
64bb897
Merge branch 'next' into field-variable-expression
bendudson Jun 26, 2026
5ccd8d7
FieldFactory::read_grid_variables Catch null mesh
bendudson Jun 29, 2026
74310f6
GridVariable::LazyLoad thread safety and performance
bendudson Jun 29, 2026
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 include/bout/field2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Field2D;
#include "bout/region.hxx"

#include <cstddef>
#include <iostream>
#include <ostream>
#include <string>

Expand Down
4 changes: 2 additions & 2 deletions include/bout/invertable_operator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public:
: operatorFunction(func), preconditionerFunction(func),
opt(optIn == nullptr ? Options::getRoot()->getSection("invertableOperator")
: optIn),
localmesh(localmeshIn == nullptr ? bout::globals::mesh : localmeshIn), lib(opt){
localmesh(localmeshIn == nullptr ? bout::globals::mesh : localmeshIn), lib(opt) {

};
};

/// Destructor just has to cleanup the PETSc owned objects.
~InvertableOperator() {
Expand Down
2 changes: 1 addition & 1 deletion include/bout/mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public:
virtual int getLocalZIndexNoBoundaries(int zglobal) const = 0;

/// Size of the mesh on this processor including guard/boundary cells
int LocalNx, LocalNy, LocalNz;
int LocalNx{0}, LocalNy{0}, LocalNz{0};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'LocalNx' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int LocalNx{0}, LocalNy{0}, LocalNz{0};
      ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'LocalNy' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int LocalNx{0}, LocalNy{0}, LocalNz{0};
                  ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'LocalNz' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int LocalNx{0}, LocalNy{0}, LocalNz{0};
                              ^


/// Local ranges of data (inclusive), excluding guard cells
int xstart, xend, ystart, yend, zstart, zend;
Expand Down
8 changes: 4 additions & 4 deletions include/bout/output.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ class ConditionalOutput : public Output {
public:
/// @param[in] base The Output object which will be written to if enabled
/// @param[in] enabled Should this be enabled by default?
ConditionalOutput(Output* base, bool enabled = true) : base(base), enabled(enabled){};
ConditionalOutput(Output* base, bool enabled = true) : base(base), enabled(enabled) {};

/// Constuctor taking ConditionalOutput. This allows several layers of conditions
///
/// @param[in] base A ConditionalOutput which will be written to if enabled
///
ConditionalOutput(ConditionalOutput* base) : base(base), enabled(base->enabled){};
ConditionalOutput(ConditionalOutput* base) : base(base), enabled(base->enabled) {};

/// If enabled, writes a string using fmt formatting
/// by calling base->write
Expand Down Expand Up @@ -237,7 +237,7 @@ private:
/// output_debug << "debug message";
/// compile but have no effect if BOUT_USE_OUTPUT_DEBUG is false
template <typename T>
DummyOutput& operator<<(DummyOutput& out, T const& UNUSED(t)) {
DummyOutput& operator<<(DummyOutput& out, const T& UNUSED(t)) {
return out;
}

Expand All @@ -261,7 +261,7 @@ inline ConditionalOutput& operator<<(ConditionalOutput& out, stream_manipulator
}

template <typename T>
ConditionalOutput& operator<<(ConditionalOutput& out, T const& t) {
ConditionalOutput& operator<<(ConditionalOutput& out, const T& t) {
if (out.isEnabled()) {
*out.getBase() << t;
}
Expand Down
47 changes: 22 additions & 25 deletions include/bout/physicsmodel.hxx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*!************************************************************************
* \file physicsmodel.hxx
*
*
* @brief Base class for Physics Models
*
*
*
*
*
* Changelog:
*
*
* 2013-08 Ben Dudson <benjamin.dudson@york.ac.uk>
* * Initial version
*
*
**************************************************************************
* Copyright 2013 B.D.Dudson
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -167,9 +167,9 @@ public:
*
* Output
* ------
*
*
* The time derivatives will be put in the ddt() variables
*
*
* Returns a flag: 0 indicates success, non-zero an error flag
*/
int runRHS(BoutReal time, bool linear = false);
Expand Down Expand Up @@ -203,7 +203,7 @@ public:
bool hasPrecon();

/*!
* Run the preconditioner. The system state should be in the
* Run the preconditioner. The system state should be in the
* evolving variables, and the vector to be solved in the ddt() variables.
* The result will be put in the ddt() variables.
*
Expand All @@ -219,7 +219,7 @@ public:

/*!
* Run the Jacobian-vector multiplication function
*
*
* Note: this is usually only called by the Solver
*/
int runJacobian(BoutReal t);
Expand All @@ -241,10 +241,10 @@ protected:
// The init and rhs functions are implemented by user code to specify problem
/*!
* @brief This function is called once by the solver at the start of a simulation.
*
*
* A valid PhysicsModel must implement this function
*
* Variables should be read from the inputs, and the variables to
*
* Variables should be read from the inputs, and the variables to
* be evolved should be specified.
*/
virtual int init(bool restarting) = 0;
Expand All @@ -258,7 +258,7 @@ protected:
/*!
* @brief This function is called by the time integration solver
* at least once per time step
*
*
* Variables being evolved will be set by the solver
* before the call, and this function must calculate
* and set the time-derivatives.
Expand All @@ -278,10 +278,10 @@ protected:
/// Add additional variables other than the evolving variables to the restart files
virtual void restartVars(Options& options);

/*
/*
If split operator is set to true, then
convective() and diffusive() are called instead of rhs()

For implicit-explicit schemes, convective() will typically
be treated explicitly, whilst diffusive() will be treated implicitly.
For unsplit methods, both convective and diffusive will be called
Expand Down Expand Up @@ -334,7 +334,7 @@ protected:
*
* @param[in] var The variable to evolve
* @param[in] name The name to use for variable initialisation and output
*
*
* Note that the variable must not be destroyed (e.g. go out of scope)
* after this call, since a pointer to \p var is stored in the solver.
*
Expand All @@ -358,11 +358,11 @@ protected:
* Specify a constrained variable \p var, which will be
* adjusted to make \p F_var equal to zero.
* If the solver does not support constraints then this will throw an exception
*
*
* @param[in] var The variable the solver should modify
* @param[in] F_var The control variable, which the user will set
* @param[in] name The name to use for initialisation and output
*
*
*/
bool bout_constrain(Field3D& var, Field3D& F_var, const char* name);

Expand Down Expand Up @@ -491,8 +491,7 @@ private:

/// Add fields to the solver.
/// This should accept up to ten arguments
#define SOLVE_FOR(...) \
{ MACRO_FOR_EACH(SOLVE_FOR1, __VA_ARGS__) }
#define SOLVE_FOR(...) {MACRO_FOR_EACH(SOLVE_FOR1, __VA_ARGS__)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variadic macro 'SOLVE_FOR' used; consider using a 'constexpr' variadic template function [cppcoreguidelines-macro-usage]

#define SOLVE_FOR(...) {MACRO_FOR_EACH(SOLVE_FOR1, __VA_ARGS__)}
        ^


/// Write this variable once to the grid file
#define SAVE_ONCE1(var) dump.addOnce(var, #var);
Expand Down Expand Up @@ -532,8 +531,7 @@ private:
dump.addOnce(var6, #var6); \
}

#define SAVE_ONCE(...) \
{ MACRO_FOR_EACH(SAVE_ONCE1, __VA_ARGS__) }
#define SAVE_ONCE(...) {MACRO_FOR_EACH(SAVE_ONCE1, __VA_ARGS__)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variadic macro 'SAVE_ONCE' used; consider using a 'constexpr' variadic template function [cppcoreguidelines-macro-usage]

#define SAVE_ONCE(...) {MACRO_FOR_EACH(SAVE_ONCE1, __VA_ARGS__)}
        ^


/// Write this variable every timestep
#define SAVE_REPEAT1(var) dump.addRepeat(var, #var);
Expand Down Expand Up @@ -573,7 +571,6 @@ private:
dump.addRepeat(var6, #var6); \
}

#define SAVE_REPEAT(...) \
{ MACRO_FOR_EACH(SAVE_REPEAT1, __VA_ARGS__) }
#define SAVE_REPEAT(...) {MACRO_FOR_EACH(SAVE_REPEAT1, __VA_ARGS__)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variadic macro 'SAVE_REPEAT' used; consider using a 'constexpr' variadic template function [cppcoreguidelines-macro-usage]

#define SAVE_REPEAT(...) {MACRO_FOR_EACH(SAVE_REPEAT1, __VA_ARGS__)}
        ^


#endif // BOUT_PHYSICS_MODEL_H
15 changes: 10 additions & 5 deletions include/bout/sys/generator_context.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ public:
: Context(i.x(), i.y(), 0, (loc == CELL_ZLOW) ? CELL_CENTRE : loc, msh, t) {}

/// Specify a cell index, together with the cell location, mesh and time
///
Context(int ix, int iy, int iz, CELL_LOC loc, Mesh* msh, BoutReal t);

/// Specify the values directly
Context(BoutReal x, BoutReal y, BoutReal z, Mesh* msh, BoutReal t);

/// If constructed without parameters, contains no values (null).
/// Requesting x,y,z or t throws an exception
Context() = default;

/// The location on the boundary
Context(const BoundaryRegion* bndry, int iz, CELL_LOC loc, BoutReal t, Mesh* msh);
Context(const BoundaryRegion* bndry, CELL_LOC loc, BoutReal t, Mesh* msh)
: Context(bndry, 0, loc, t, msh){};
: Context(bndry, 0, loc, t, msh) {};

BoutReal x() const { return get("x"); }
BoutReal y() const { return get("y"); }
BoutReal z() const { return get("z"); }
BoutReal t() const { return get("t"); }

/// Cell indices
int ix() const { return ix_; }
int jy() const { return jy_; }
int kz() const { return kz_; }

/// Set the value of a parameter with given name
Context& set(const std::string& name, BoutReal value) {
parameters[name] = value;
Expand Down Expand Up @@ -76,6 +77,10 @@ public:
}

private:
int ix_{0};
int jy_{0};
int kz_{0};

Mesh* localmesh{nullptr}; ///< The mesh on which the position is defined

/// Contains user-set values which can be set and retrieved
Expand Down
Loading
Loading