File field_factory.hxx#

Functions

FieldGeneratorPtr generator(BoutReal value)

Helper function to create a FieldValue generator from a BoutReal.

FieldGeneratorPtr generator(BoutReal *ptr)

Helper function to create a FieldValuePtr from a pointer to BoutReal.

class FieldFactory : public ExpressionParser#

Public Functions

FieldFactory(Mesh *mesh = nullptr, Options *opt = nullptr)#
~FieldFactory() override = default#
Field2D create2D(const std::string &value, const Options *opt = nullptr, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a 2D field by parsing a string and evaluating the expression using the given options opt, over Mesh m at time t. The resulting field is at cell location loc.

Field3D create3D(const std::string &value, const Options *opt = nullptr, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a 3D field by parsing a string and evaluating the expression using the given options opt, over Mesh m at time t. The resulting field is at cell location loc.

FieldPerp createPerp(const std::string &value, const Options *opt = nullptr, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a FieldPerp by parsing a string and evaluating the expression using the given options opt, over Mesh m at time t. The resulting field is at cell location loc.

FieldGeneratorPtr parse(const std::string &input, const Options *opt = nullptr) const#

Parse a string into a tree of generators.

Field2D create2D(FieldGeneratorPtr generator, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a 2D field from a generator, over a given mesh at a given cell location and time.

Field3D create3D(FieldGeneratorPtr generator, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a 3D field from a generator, over a given mesh at a given cell location and time.

FieldPerp createPerp(FieldGeneratorPtr generator, Mesh *m = nullptr, CELL_LOC loc = CELL_CENTRE, BoutReal t = 0.0) const#

Create a FieldPerp from a generator, over a given mesh at a given cell location and time.

void cleanCache()#

clean the cache of parsed strings

Public Static Functions

static FieldFactory *get()#

Get the Singleton object.

Protected Functions

virtual FieldGeneratorPtr resolve(const std::string &name) const override#

These functions called by the parser to resolve unknown symbols. This is used to enable options to be referred to in expressions.

virtual std::multiset<ExpressionParser::FuzzyMatch> fuzzyFind(const std::string &name, std::string::size_type max_distance = 2) const override#

Find approximate matches for name in the known generators. max_distance controls the similarity of results.

Returns a set of possible matches ordered by similarity to name. A distance of 1 means: a single insertion, deletion, substitution, or transposition; that the case differs, for example, “key” and “KEY” match with distance 1

Private Functions

const Options *findOption(const Options *opt, const std::string &name, std::string &val) const#

Find an Options object which contains the given name.

Private Members

Mesh *fieldmesh#

The default mesh for create functions.

bool transform_from_field_aligned = {true}#

Should we transform input from field-aligned coordinates (if possible)?

int max_recursion_depth = {0}#
mutable const Options *options#

The default options used in resolve(), can be temporarily overridden in parse()/create2D()/create3D()

mutable std::list<std::string> lookup#

Names currently being parsed.

mutable std::map<std::string, FieldGeneratorPtr> cache#

Cache parsed strings so repeated evaluations don’t result in allocating more generators.

class FieldFunction : public FieldGenerator#

Public Functions

FieldFunction() = delete#
inline FieldFunction(FuncPtr userfunc)#
inline virtual BoutReal generate(const bout::generator::Context &pos) override#

Generate a value at the given coordinates (x,y,z,t) This should be deterministic, always returning the same value given the same inputs

Note: The default implementations of generate call each other; the implementor of a FieldGenerator type must implement one of them or an infinite recursion results. This is for backward compatibility for users and implementors. In a future version this function will be made pure virtual.

Private Members

FuncPtr func#
class FieldNull : public FieldGenerator#

Public Functions

FieldNull() = default#
inline virtual BoutReal generate(const bout::generator::Context&) override#

Generate a value at the given coordinates (x,y,z,t) This should be deterministic, always returning the same value given the same inputs

Note: The default implementations of generate call each other; the implementor of a FieldGenerator type must implement one of them or an infinite recursion results. This is for backward compatibility for users and implementors. In a future version this function will be made pure virtual.

inline virtual FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args) override#

Virtual constructor. Makes a copy of this FieldGenerator, initialised with the given list of arguments. It is up to the implementations to test whether the correct number of arguments is passed.

Parameters:

args[in] A (possibly empty) list of arguments to the generator function

Public Static Functions

static inline FieldGeneratorPtr get()#

Singeton.