# File fieldgenerators.hxx¶

These classes are used by FieldFactory

Typedefs

using single_arg_op = BoutReal (*)(BoutReal)

Template class to define generators around a C function.

using double_arg_op = BoutReal (*)(BoutReal, BoutReal)

Template for a FieldGenerator with two input arguments.

class FieldValuePtr : public FieldGenerator
#include <fieldgenerators.hxx>

Creates a Field Generator using a pointer to value WARNING: The value pointed to must remain in scope until this generator is finished

Public Functions

FieldValuePtr(BoutReal *val)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

BoutReal *ptr
template<single_arg_op Op>
class FieldGenOneArg : public FieldGenerator

Public Functions

FieldGenOneArg(FieldGeneratorPtr g, const std::string &name = "function")

< Template for single-argument function

FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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.

std::string str() const

Create a string representation of the generator, for debugging output.

Private Members

FieldGeneratorPtr gen
std::string name

A string describing the function, to be printed in error messages.

template<double_arg_op Op>
class FieldGenTwoArg : public FieldGenerator

Public Functions

FieldGenTwoArg(FieldGeneratorPtr a, FieldGeneratorPtr b, const std::string &name = "function")

< Template for two-argument function

FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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.

std::string str() const

Create a string representation of the generator, for debugging output.

Private Members

FieldGeneratorPtr A
FieldGeneratorPtr B
std::string name

The name of the function, to be printed in error messages.

class FieldATan : public FieldGenerator
#include <fieldgenerators.hxx>

Arc (Inverse) tangent. Either one or two argument versions.

Public Functions

FieldATan(FieldGeneratorPtr a, FieldGeneratorPtr b = nullptr)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

FieldGeneratorPtr A
FieldGeneratorPtr B
class FieldGaussian : public FieldGenerator
#include <fieldgenerators.hxx>

Gaussian distribution, taking mean and width arguments.

Public Functions

FieldGaussian(FieldGeneratorPtr xin, FieldGeneratorPtr sin)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

FieldGeneratorPtr X
FieldGeneratorPtr s
class FieldHeaviside : public FieldGenerator
#include <fieldgenerators.hxx>

Heaviside function, switches between 0 and 1.

Public Functions

FieldHeaviside(FieldGeneratorPtr g)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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.

std::string str() const

Create a string representation of the generator, for debugging output.

Private Members

FieldGeneratorPtr gen
class FieldMin : public FieldGenerator
#include <fieldgenerators.hxx>

Minimum.

Public Functions

FieldMin()
FieldMin(const std::list<FieldGeneratorPtr> args)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

std::list<FieldGeneratorPtr> input
class FieldMax : public FieldGenerator
#include <fieldgenerators.hxx>

Maximum.

Public Functions

FieldMax()
FieldMax(const std::list<FieldGeneratorPtr> args)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

std::list<FieldGeneratorPtr> input
class FieldClamp : public FieldGenerator
#include <fieldgenerators.hxx>

Clamp

Force a value to be in specified range Also called clip e.g. in NumPy, but in C++17 std::clamp is in <algorithm>

Note that the result is not well defined if low > high

Public Functions

FieldClamp()
FieldClamp(FieldGeneratorPtr value, FieldGeneratorPtr low, FieldGeneratorPtr high)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

FieldGeneratorPtr value

The value to be clamped.

FieldGeneratorPtr low
FieldGeneratorPtr high

The range within which the result will be.

class FieldRound : public FieldGenerator
#include <fieldgenerators.hxx>

Generator to round to the nearest integer.

Public Functions

FieldRound(FieldGeneratorPtr g)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

FieldGeneratorPtr gen
class FieldBallooning : public FieldGenerator

Public Functions

FieldBallooning(Mesh *m, FieldGeneratorPtr a = nullptr, int n = 3)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

Mesh *mesh
FieldGeneratorPtr arg
int ball_n
class FieldMixmode : public FieldGenerator

Public Functions

FieldMixmode(FieldGeneratorPtr a = nullptr, BoutReal seed = 0.5)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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 Functions

BoutReal genRand(BoutReal seed)

Generate a random number between 0 and 1 (exclusive) given an arbitrary seed value

This PRNG has no memory, i.e. you need to call it with a different seed each time.

Private Members

FieldGeneratorPtr arg
BoutReal phase[14]
class FieldTanhHat : public FieldGenerator

Public Functions

FieldTanhHat(FieldGeneratorPtr xin, FieldGeneratorPtr widthin, FieldGeneratorPtr centerin, FieldGeneratorPtr steepnessin)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

BoutReal generate(const bout::generator::Context &ctx)

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

FieldGeneratorPtr X
FieldGeneratorPtr width
FieldGeneratorPtr center
FieldGeneratorPtr steepness
class FieldWhere : public FieldGenerator

Public Functions

FieldWhere(FieldGeneratorPtr test, FieldGeneratorPtr gt0, FieldGeneratorPtr lt0)
FieldGeneratorPtr clone(const std::list<FieldGeneratorPtr> args)

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: A (possibly empty) list of arguments to the generator function

double generate(const bout::generator::Context &ctx)

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.

std::string str() const

Create a string representation of the generator, for debugging output.

Private Members

FieldGeneratorPtr test
FieldGeneratorPtr gt0
FieldGeneratorPtr lt0