Skip to content
6 changes: 1 addition & 5 deletions src/mesh/impls/bout/boutmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
/// MPI type of BoutReal for communications
#define PVEC_REAL_MPI_TYPE MPI_DOUBLE

BoutMesh::BoutMesh(GridDataSource *s, Options *options) : Mesh(s, options) {
if (options == NULL) {
options = Options::getRoot()->getSection("mesh");
}

BoutMesh::BoutMesh(GridDataSource *s, Options *opt) : Mesh(s, opt) {
OPTION(options, symmetricGlobalX, true);
if (!options->isSet("symmetricGlobalY")) {
std::string optionfile;
Expand Down
4 changes: 4 additions & 0 deletions src/mesh/mesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Mesh::Mesh(GridDataSource *s, Options* opt) : source(s), coords(0), options(opt)
if(s == NULL)
throw BoutException("GridDataSource passed to Mesh::Mesh() is NULL");

if (options == nullptr) {
options = Options::getRoot()->getSection("mesh");
}

/// Get mesh options
OPTION(options, StaggerGrids, false); // Stagger grids
OPTION(options, maxregionblocksize, MAXREGIONBLOCKSIZE);
Expand Down
32 changes: 20 additions & 12 deletions src/solver/solver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ void Solver::add(Vector3D &v, const char* name) {
**************************************************************************/

void Solver::constraint(Field2D &v, Field2D &C_v, const char* name) {

if (name == nullptr) {
throw BoutException("ERROR: Constraint requested for variable with NULL name\n");
}

TRACE("Constrain 2D scalar: Solver::constraint(%s)", name);

#if CHECK > 0
Expand All @@ -352,9 +357,6 @@ void Solver::constraint(Field2D &v, Field2D &C_v, const char* name) {
if(initialised)
throw BoutException("Error: Cannot add constraints to solver after initialisation\n");

if(name == NULL)
throw BoutException("WARNING: Constraint requested for variable with NULL name\n");

VarStr<Field2D> d;

d.constraint = true;
Expand All @@ -366,6 +368,11 @@ void Solver::constraint(Field2D &v, Field2D &C_v, const char* name) {
}

void Solver::constraint(Field3D &v, Field3D &C_v, const char* name) {

if (name == nullptr) {
throw BoutException("ERROR: Constraint requested for variable with NULL name\n");
}

TRACE("Constrain 3D scalar: Solver::constraint(%s)", name);

#if CHECK > 0
Expand All @@ -379,9 +386,6 @@ void Solver::constraint(Field3D &v, Field3D &C_v, const char* name) {
if(initialised)
throw BoutException("Error: Cannot add constraints to solver after initialisation\n");

if(name == NULL)
throw BoutException("WARNING: Constraint requested for variable with NULL name\n");

VarStr<Field3D> d;

d.constraint = true;
Expand All @@ -394,6 +398,11 @@ void Solver::constraint(Field3D &v, Field3D &C_v, const char* name) {
}

void Solver::constraint(Vector2D &v, Vector2D &C_v, const char* name) {

if (name == nullptr) {
throw BoutException("ERROR: Constraint requested for variable with NULL name\n");
}

TRACE("Constrain 2D vector: Solver::constraint(%s)", name);

#if CHECK > 0
Expand All @@ -407,9 +416,6 @@ void Solver::constraint(Vector2D &v, Vector2D &C_v, const char* name) {
if(initialised)
throw BoutException("Error: Cannot add constraints to solver after initialisation\n");

if(name == NULL)
throw BoutException("WARNING: Constraint requested for variable with NULL name\n");

VarStr<Vector2D> d;

d.constraint = true;
Expand All @@ -433,6 +439,11 @@ void Solver::constraint(Vector2D &v, Vector2D &C_v, const char* name) {
}

void Solver::constraint(Vector3D &v, Vector3D &C_v, const char* name) {

if (name == nullptr) {
throw BoutException("ERROR: Constraint requested for variable with NULL name\n");
}

TRACE("Constrain 3D vector: Solver::constraint(%s)", name);

#if CHECK > 0
Expand All @@ -446,9 +457,6 @@ void Solver::constraint(Vector3D &v, Vector3D &C_v, const char* name) {
if(initialised)
throw BoutException("Error: Cannot add constraints to solver after initialisation\n");

if(name == NULL)
throw BoutException("WARNING: Constraint requested for variable with NULL name\n");

VarStr<Vector3D> d;

d.constraint = true;
Expand Down
12 changes: 6 additions & 6 deletions src/sys/comm_group.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ namespace comm_group {

return (root == handle->myrank);
}


bool Comm_wait(Comm_handle_t *handle)
{
TRACE("Comm_gather_wait(%d)", handle->root);

if(handle == NULL)
bool Comm_wait(Comm_handle_t *handle) {
if (handle == nullptr) {
return false;
}

TRACE("Comm_gather_wait(%d)", handle->root);

if(!handle->current)
return false;

Expand Down
46 changes: 46 additions & 0 deletions tests/unit/mesh/test_boutmesh.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "gtest/gtest.h"

#include "../src/mesh/impls/bout/boutmesh.hxx"
#include "bout/mesh.hxx"
#include "output.hxx"
#include "unused.hxx"

class FakeGridDataSource : public GridDataSource {
public:
FakeGridDataSource(){};
~FakeGridDataSource(){};
bool hasVar(const string &UNUSED(name)) { return false; };
bool get(Mesh *UNUSED(m), int &UNUSED(ival), const string &UNUSED(name)) {
return true;
};
bool get(Mesh *UNUSED(m), BoutReal &UNUSED(rval), const string &UNUSED(name)) {
return true;
}
bool get(Mesh *UNUSED(m), Field2D &UNUSED(var), const string &UNUSED(name),
BoutReal UNUSED(def) = 0.0) {
return true;
}
bool get(Mesh *UNUSED(m), Field3D &UNUSED(var), const string &UNUSED(name),
BoutReal UNUSED(def) = 0.0) {
return true;
}
bool get(Mesh *UNUSED(m), vector<int> &UNUSED(var), const string &UNUSED(name),
int UNUSED(len), int UNUSED(offset) = 0,
Direction UNUSED(dir) = GridDataSource::X) {
return true;
}
bool get(Mesh *UNUSED(m), vector<BoutReal> &UNUSED(var), const string &UNUSED(name),
int UNUSED(len), int UNUSED(offset) = 0,
Direction UNUSED(dir) = GridDataSource::X) {
return true;
}
};

TEST(BoutMeshTest, NullOptionsCheck) {
// Temporarily turn off outputs to make test quiet
output_info.disable();
output_warn.disable();
EXPECT_NO_THROW(BoutMesh mesh(new FakeGridDataSource, nullptr));
output_info.enable();
output_warn.enable();
}