Skip to content

Commit cd31e42

Browse files
committed
GridVariable: Check mesh->get return
Not strictly necessary because variables are checked before creating a GridVariable, but doesn't hurt.
1 parent 4ab3578 commit cd31e42

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/field/fieldgenerators.hxx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public:
311311
// Constructor
312312
FieldTanhHat(FieldGeneratorPtr xin, FieldGeneratorPtr widthin,
313313
FieldGeneratorPtr centerin, FieldGeneratorPtr steepnessin)
314-
: X(xin), width(widthin), center(centerin), steepness(steepnessin){};
314+
: X(xin), width(widthin), center(centerin), steepness(steepnessin) {};
315315
// Clone containing the list of arguments
316316
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args) override;
317317
BoutReal generate(const bout::generator::Context& pos) override;
@@ -326,7 +326,7 @@ private:
326326
class FieldWhere : public FieldGenerator {
327327
public:
328328
FieldWhere(FieldGeneratorPtr test, FieldGeneratorPtr gt0, FieldGeneratorPtr lt0)
329-
: test(test), gt0(gt0), lt0(lt0){};
329+
: test(test), gt0(gt0), lt0(lt0) {};
330330

331331
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args) override {
332332
if (args.size() != 3) {
@@ -368,23 +368,26 @@ private:
368368

369369
Field3D get() {
370370
if (!var.isAllocated()) {
371-
this->mesh->get(this->var, this->name);
371+
// Read variable from mesh
372+
if (this->mesh->get(this->var, this->name) != 0) {
373+
throw BoutException("Couldn't read GridVariable '{}'", this->name);
374+
}
372375
}
373376
return this->var;
374377
}
375378

376379
Mesh* mesh;
377380
std::string name;
378-
T var {};
381+
T var{};
379382
};
380383

381384
std::shared_ptr<LazyLoaded> variable;
385+
382386
public:
383387
GridVariable(Mesh* mesh, std::string name)
384-
: variable(std::make_shared<LazyLoaded>(mesh, std::move(name))) {}
388+
: variable(std::make_shared<LazyLoaded>(mesh, std::move(name))) {}
385389

386-
GridVariable(std::shared_ptr<LazyLoaded> variable)
387-
: variable(std::move(variable)) {}
390+
GridVariable(std::shared_ptr<LazyLoaded> variable) : variable(std::move(variable)) {}
388391

389392
double generate(const bout::generator::Context& ctx) override {
390393
return variable->get()(ctx.ix(), ctx.jy(), ctx.kz());
@@ -398,7 +401,6 @@ public:
398401
}
399402

400403
std::string str() const override { return variable->name; }
401-
402404
};
403405

404406
#endif // BOUT_FIELDGENERATORS_H

0 commit comments

Comments
 (0)