Skip to content

Commit

Permalink
Merge pull request boutproject#2042 from boutproject/physics-model-mesh
Browse files Browse the repository at this point in the history
Add PhysicsModel::mesh/dump members
  • Loading branch information
ZedThree authored May 29, 2020
2 parents 63b2c9d + e74fd7d commit c5d712a
Show file tree
Hide file tree
Showing 60 changed files with 171 additions and 98 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
- The `MUMPS` Laplacian inversion wrapper has been removed. It is still possible
to use `MUMPS` for Laplacian inversions through the `PETSc`
wrapper. [\#2018](https://github.com/boutproject/BOUT-dev/pull/2018)
- The `using namespace bout::globals` statement has been removed from
`physics_model.hxx`, and `PhysicsModel` has gained public `mesh` and
`dump` members. Custom `main`s, free functions and legacy models
will need to be updated to either use `bout::globals::mesh` or
`Field::getMesh()` in free
functions. [\#2042](https://github.com/boutproject/BOUT-dev/pull/2042)


## [v4.3.1](https://github.com/boutproject/BOUT-dev/tree/v4.3.1) (2020-03-27)
Expand Down
3 changes: 3 additions & 0 deletions examples/6field-simple/elm_6f.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <math.h>
#include <msg_stack.hxx>

using bout::globals::dump;
using bout::globals::mesh;

BoutReal n0_height, n0_ave, n0_width, n0_center,
n0_bottom_x; // the total height, average width and center of profile of N0
BoutReal Tconst; // the ampitude of congstant temperature
Expand Down
2 changes: 1 addition & 1 deletion examples/IMEX/advection-reaction/split_operator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int physics_init(bool UNUSED(restarting)) {

int physics_run(BoutReal UNUSED(time)) {
// Need communication
mesh->communicate(U);
U.getMesh()->communicate(U);

// Form of advection operator for reduced MHD type models
ddt(U) = -bracket(phi, U, BRACKET_SIMPLE);
Expand Down
1 change: 1 addition & 0 deletions examples/advdiff2/init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <boutmain.hxx>
#include "globals.hxx"

using bout::globals::mesh;

int physics_init(bool restarting)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/advdiff2/run.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#include <derivs.hxx>
#include "globals.hxx"


int physics_run(BoutReal UNUSED(t)) {
// Run communications
mesh->communicate(V);
V.getMesh()->communicate(V);

//ddt(V) = D2DX2(V) + 0.5*DDX(V) + D2DY2(V);
ddt(V) = DDX(V);
Expand Down
2 changes: 2 additions & 0 deletions examples/bout_runners_example/diffusion_3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// Gives PI and TWOPI
#include <bout/constants.hxx>

using bout::globals::mesh;

// Global variable initialization
// ############################################################################
Field3D n; // Evolved variable
Expand Down
4 changes: 2 additions & 2 deletions examples/conduction-snb/conduction-snb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char** argv) {
Field3D Ne = opt["Ne"].doc("Electron density in m^-3").as<Field3D>();
Field3D Te = opt["Te"].doc("Electron temperature in eV").as<Field3D>();

mesh->communicate(Ne, Te);
bout::globals::mesh->communicate(Ne, Te);

// Calculate divergence of heat flux
HeatFluxSNB snb;
Expand All @@ -23,7 +23,7 @@ int main(int argc, char** argv) {

// Save to the output
SAVE_ONCE(Ne, Te, Div_Q, Div_Q_SH);
dump.write();
bout::globals::dump.write();

BoutFinalise();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions examples/constraints/laplace-dae/laplace_dae.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Field3D phibdry; // Used for calculating error in the boundary

bool constraint;

using bout::globals::mesh;

std::unique_ptr<Laplacian> phiSolver{nullptr}; ///< Inverts a Laplacian to get phi from U

// Preconditioner
Expand Down
6 changes: 3 additions & 3 deletions examples/finite-volume/test/finite_volume.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ int main(int argc, char** argv) {
BoutInitialise(argc, argv);

Field3D f = 0.0;
mesh->communicate(f);

f.getMesh()->communicate(f);

Field3D g = FV::D4DY4_Index(f);

BoutFinalise();
Expand Down
3 changes: 2 additions & 1 deletion examples/laplace-petsc3d/test-laplace3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int main(int argc, char** argv) {
///////////////////////////////////////////////////////////////////////////////////////

Field3D f, rhs;
auto* mesh = f.getMesh();
mesh->get(rhs, "rhs");

// initial profile of f only used to set boundary values
Expand Down Expand Up @@ -153,7 +154,7 @@ int main(int argc, char** argv) {
BoutReal error_max = max(abs(error), true);

SAVE_ONCE(f, rhs, rhs_check, error, error_max);
dump.write();
bout::globals::dump.write();

laplace_solver.reset(nullptr);
BoutFinalise();
Expand Down
6 changes: 4 additions & 2 deletions examples/laplacexy/laplace_perp/test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <derivs.hxx>
#include <field_factory.hxx>

using bout::globals::mesh;

int main(int argc, char** argv) {
BoutInitialise(argc, argv);

Expand Down Expand Up @@ -61,8 +63,8 @@ int main(int argc, char** argv) {

// Write fields to output
SAVE_ONCE3(input, solved, result);
dump.write();
bout::globals::dump.write();

BoutFinalise();
return 0;
}
Expand Down
13 changes: 7 additions & 6 deletions examples/laplacexy/simple/test-laplacexy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ int main(int argc, char** argv) {
BoutInitialise(argc, argv);

/// Create a LaplaceXY object
LaplaceXY laplacexy(mesh);
LaplaceXY laplacexy(bout::globals::mesh);

/// Generate rhs function
Field2D rhs = FieldFactory::get()->create2D("laplacexy:rhs", Options::getRoot(), mesh);

Field2D rhs = FieldFactory::get()->create2D("laplacexy:rhs", Options::getRoot(),
bout::globals::mesh);

/// Solution
Field2D x = 0.0;

x = laplacexy.solve(rhs, x);

SAVE_ONCE2(rhs, x);
dump.write(); // Save output file
bout::globals::dump.write(); // Save output file

BoutFinalise();
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions examples/performance/bracket/bracket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
2 changes: 1 addition & 1 deletion examples/performance/communications/communications.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(int argc, char** argv) {

Timer timer("comms");
for (int i = 0; i < iterations; ++i) {
mesh->communicate(f);
f.getMesh()->communicate(f);
}
BoutReal run_length = timer.getTime();

Expand Down
1 change: 1 addition & 0 deletions examples/performance/ddx/ddx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
1 change: 1 addition & 0 deletions examples/performance/ddy/ddy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
1 change: 1 addition & 0 deletions examples/performance/ddz/ddz.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
1 change: 1 addition & 0 deletions examples/performance/iterator-offsets/iterator-offsets.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
1 change: 1 addition & 0 deletions examples/performance/iterator/iterator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using bout::globals::mesh;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{__VA_ARGS__ \
Expand Down
6 changes: 3 additions & 3 deletions examples/performance/laplace/laplace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char **argv) {
ConditionalOutput time_output(Output::getInstance());
time_output.enable(true);

FieldFactory f{mesh};
FieldFactory f{bout::globals::mesh};

Field3D input = f.create3D("(1-gauss(x-0.5,0.2))*gauss(y-pi)*gauss(z-pi)");
Field2D a = f.create2D("gauss(x) * sin(y)");
Expand Down Expand Up @@ -167,8 +167,8 @@ int main(int argc, char **argv) {
);

// Write and close the output file
dump.write();
dump.close();
bout::globals::dump.write();
bout::globals::dump.close();

MPI_Barrier(BoutComm::get()); // Wait for all processors to write data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using SteadyClock = std::chrono::time_point<std::chrono::steady_clock>;
using Duration = std::chrono::duration<double>;
using namespace std::chrono;
using namespace bout::globals;

#define ITERATOR_TEST_BLOCK(NAME, ...) \
{ \
Expand Down
8 changes: 6 additions & 2 deletions examples/preconditioning/wave/test_precon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ int physics_init(bool UNUSED(restarting)) {
}

int physics_run(BoutReal UNUSED(t)) {
mesh->communicate(u,v);
u.getMesh()->communicate(u, v);

ddt(u) = Grad_par(v);
ddt(v) = Grad_par(u);

Expand All @@ -53,6 +53,8 @@ int physics_run(BoutReal UNUSED(t)) {
*
*********************************************************/
int precon(BoutReal UNUSED(t), BoutReal gamma, BoutReal UNUSED(delta)) {
auto* mesh = u.getMesh();

// Communicate vector to be inverted
mesh->communicate(ddt(u), ddt(v));

Expand Down Expand Up @@ -94,6 +96,8 @@ int precon(BoutReal UNUSED(t), BoutReal gamma, BoutReal UNUSED(delta)) {
*********************************************************/

int jacobian(BoutReal UNUSED(t)) {
auto* mesh = u.getMesh();

mesh->communicate(ddt(u), ddt(v));
Field3D utmp = Grad_par(ddt(v)); // Shouldn't overwrite ddt(u) before using it
ddt(v) = Grad_par(ddt(u));
Expand Down
3 changes: 2 additions & 1 deletion examples/staggered_grid/test_staggered.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#include <bout.hxx>
#include <boutmain.hxx>

#include <derivs.hxx>

using bout::globals::mesh;

Field3D n, v;
CELL_LOC maybe_ylow{CELL_CENTRE};

Expand Down
7 changes: 0 additions & 7 deletions include/bout.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@
#include "bout/solver.hxx"
#include "bout/version.hxx"

#ifndef BOUT_NO_USING_NAMESPACE_BOUTGLOBALS
// Include using statement by default in user code.
// Macro allows us to include bout.hxx or physicsmodel.hxx without the using
// statement in library code.
using namespace bout::globals;
#endif // BOUT_NO_USING_NAMESPACE_BOUTGLOBALS

// BOUT++ main functions

/*!
Expand Down
5 changes: 5 additions & 0 deletions include/bout/physicsmodel.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PhysicsModel;
#include "utils.hxx"
#include "bout/macro_for_each.hxx"

class Mesh;

/*!
Base class for physics models
*/
Expand All @@ -57,6 +59,9 @@ public:

virtual ~PhysicsModel() = default;

Mesh* mesh{nullptr};
Datafile& dump;

/*!
* Initialse the model, calling the init() and postInit() methods
*
Expand Down
3 changes: 2 additions & 1 deletion src/physics/physicsmodel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

#include <bout/mesh.hxx>

PhysicsModel::PhysicsModel() : modelMonitor(this) {
PhysicsModel::PhysicsModel()
: mesh(bout::globals::mesh), dump(bout::globals::dump), modelMonitor(this) {

// Set up restart file
restart = Datafile(Options::getRoot()->getSection("restart"));
Expand Down
2 changes: 2 additions & 0 deletions tests/MMS/diffusion/diffusion.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <bout/constants.hxx>
#include <unused.hxx>

using bout::globals::mesh;

void solution(Field3D &f, BoutReal t, BoutReal D);
class ErrorMonitor: public Monitor{
public:
Expand Down
4 changes: 3 additions & 1 deletion tests/MMS/spatial/fci/fci_mms.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
int main(int argc, char** argv) {
BoutInitialise(argc, argv);

using bout::globals::mesh;

Field3D input{FieldFactory::get()->create3D("input", Options::getRoot(), mesh)};
Field3D solution{FieldFactory::get()->create3D("solution", Options::getRoot(), mesh)};

Expand All @@ -22,7 +24,7 @@ int main(int argc, char** argv) {
SAVE_ONCE2(input.ynext(-slice), input.ynext(slice));
}

dump.write();
bout::globals::dump.write();

BoutFinalise();
}
6 changes: 3 additions & 3 deletions tests/integrated/test-attribs/test-attribs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ int main(int argc, char** argv) {
Field3D a = 0.0;

SAVE_ONCE(a);
dump.setAttribute("a", "meta", "something useful");
dump.setAttribute("g12", "value", 42);
dump.write();
bout::globals::dump.setAttribute("a", "meta", "something useful");
bout::globals::dump.setAttribute("g12", "value", 42);
bout::globals::dump.write();

BoutFinalise();
return 0;
Expand Down
6 changes: 4 additions & 2 deletions tests/integrated/test-communications/test-communications.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
int main(int argc, char** argv) {
BoutInitialise(argc, argv);

using bout::globals::mesh;

Field3D f = -1.;

// fill non-guard cells:
Expand Down Expand Up @@ -80,8 +82,8 @@ int main(int argc, char** argv) {
// communicate f to fill guard cells
mesh->communicate(f);

dump.add(f, "f", true);
dump.write();
bout::globals::dump.add(f, "f", true);
bout::globals::dump.write();

BoutFinalise();
}
Loading

0 comments on commit c5d712a

Please sign in to comment.