File component.hxx#

Defines

HERMES_COMPONENT_H#
TOSTRING_(x)#
TOSTRING(x)#
IS_SET(option)#
IS_SET_NOBOUNDARY(option)#
GET_VALUE(Type, option)#
GET_NOBOUNDARY(Type, option)#

Functions

template<typename T>
T getNonFinal(const Options &option)#

Faster non-printing getter for Options If this fails, it will throw BoutException

This version allows the value to be modified later i.e. the value returned is not the “final” value.

Template Parameters:

T – The type the option should be converted to

Parameters:

option – The Option whose value will be returned

template<typename T>
T getNonFinal(const GuardedOptions &option)#
template<typename T>
T get(const Options &option, [[maybe_unused]] const std::string &location = "")#

Faster non-printing getter for Options If this fails, it will throw BoutException

This marks the value as final, both in the domain and the boundary. Subsequent calls to “set” this option will raise an exception.

Template Parameters:

T – The type the option should be converted to

Parameters:
  • option – The Option whose value will be returned

  • location – An optional string to indicate where this value is used

template<typename T>
T get(const GuardedOptions &option, const std::string &location = "")#
bool isSetFinal(const Options &option, const std::string &location = "")

Check if an option can be fetched Sets the final flag so setting the value afterwards will lead to an error

bool isSetFinal(const GuardedOptions &option, const std::string &location = "")
bool isSetFinalNoBoundary(const Options &option, const std::string &location = "")

Check if an option can be fetched Sets the final flag so setting the value in the domain afterwards will lead to an error

bool isSetFinalNoBoundary(const GuardedOptions &option, const std::string &location = "")
template<typename T>
T getNoBoundary(const Options &option, [[maybe_unused]] const std::string &location = "")#

Faster non-printing getter for Options If this fails, it will throw BoutException

This marks the value as final in the domain. The caller is assuming that the boundary values are non-final or invalid. Subsequent calls to “set” this option will raise an exception, but calls to “setBoundary” will not.

Template Parameters:

T – The type the option should be converted to

Parameters:
  • option – The Option whose value will be returned

  • location – An optional string to indicate where this value is used

template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
T getNoBoundary(GO &&option, const std::string &location = "")#
template<typename T>
bool hermesDataInvalid([[maybe_unused]] const T &value)#

Check whether value is valid, returning true if invalid i.e contains non-finite values

template<>
inline bool hermesDataInvalid(const Field3D &value)#

Check Field3D values. Doesn’t check boundary cells

template<>
inline bool hermesDataInvalid(const Field2D &value)#

Check Field2D values. Doesn’t check boundary cells

template<typename T>
Options &set(Options &option, T value)#

Set values in an option. This could be optimised, but currently the is_value private variable would need to be modified.

If the value has been used then raise an exception (if CHECK >= 1) This is to prevent values being modified after use.

Template Parameters:

T – The type of the value to set. Usually this is inferred

template<typename ResT, typename L, typename R, typename Func>
inline decltype(auto) set(Options &option, const BinaryExpr<ResT, L, R, Func> &f)#
template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
decltype(auto) set(GO &&option, T value)#
template<typename T>
Options &setBoundary(Options &option, T value)#

Set values in an option. This could be optimised, but currently the is_value private variable would need to be modified.

This version only checks that the boundary cells have not already been used by a call to get, not a call to getNoBoundary or getNonFinal.

Template Parameters:

T – The type of the value to set. Usually this is inferred

template<typename ResT, typename L, typename R, typename Func>
inline decltype(auto) setBoundary(Options &option, const BinaryExpr<ResT, L, R, Func> &f)#
template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
decltype(auto) setBoundary(GO &&option, T value)#
template<typename T>
Options &add(Options &option, T value)#

Add value to a given option. If not already set, treats as zero and sets the option to the value.

Template Parameters:

T – The type of the value to add. The existing value will be casted to this type

Parameters:
  • option – The value to modify (or set if not already set)

  • value – The quantity to add.

template<typename ResT, typename L, typename R, typename Func>
inline decltype(auto) add(Options &option, const BinaryExpr<ResT, L, R, Func> &f)#
template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
decltype(auto) add(GO &&option, T value)#
template<typename T>
Options &subtract(Options &option, T value)#

Add value to a given option. If not already set, treats as zero and sets the option to the value.

Parameters:
  • option – The value to modify (or set if not already set)

  • value – The quantity to add.

template<typename ResT, typename L, typename R, typename Func>
inline decltype(auto) subtract(Options &option, const BinaryExpr<ResT, L, R, Func> &f)#
template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
decltype(auto) subtract(GO &&option, T value)#
template<typename T>
void set_with_attrs(Options &option, T value, std::initializer_list<std::pair<std::string, Options::AttributeType>> attrs)#
template<typename ResT, typename L, typename R, typename Func>
inline void set_with_attrs(Options &option, const BinaryExpr<ResT, L, R, Func> &f, std::initializer_list<std::pair<std::string, Options::AttributeType>> attrs)#
template<typename T, class GO, typename = hermes::EnableIfGuardedOption<GO>>
void set_with_attrs(GO &&option, T value, std::initializer_list<std::pair<std::string, Options::AttributeType>> attrs)#
struct SpeciesInformation#
#include <component.hxx>

Simple struct to store information on the different types of species present in a simulation.

Public Functions

inline SpeciesInformation(const std::vector<std::string> &electrons, const std::vector<std::string> &neutrals, const std::vector<std::string> &positive_ions, const std::vector<std::string> &negative_ions)#
inline SpeciesInformation(const std::initializer_list<std::string> species)#

Public Members

std::vector<std::string> electrons#
std::vector<std::string> neutrals#
std::vector<std::string> positive_ions#
std::vector<std::string> negative_ions#
std::vector<std::string> ions#
std::vector<std::string> charged#
std::vector<std::string> non_electrons#
std::vector<std::string> all_species#

Private Functions

inline void finish_construction()#
struct Component#
#include <component.hxx>

Interface for a component of a simulation model

The constructor of derived types should have signature (std::string name, Options &options, Solver *solver)

Subclassed by NamedComponent< SimplePump >, NamedComponent< SNBConduction >, NamedComponent< NeutralParallelDiffusion >, NamedComponent< ElectronForceBalance >, NamedComponent< NeutralBoundary >, NamedComponent< BraginskiiCollisions >, NamedComponent< SimpleConduction >, NamedComponent< DiamagneticDrift >, NamedComponent< DetachmentController >, NamedComponent< BraginskiiThermalForce >, NamedComponent< SoundSpeed >, NamedComponent< SheathBoundaryInsulating >, NamedComponent< RelaxPotential >, NamedComponent< Electromagnetic >, NamedComponent< BraginskiiHeatExchange >, NamedComponent< TemperatureFeedback >, NamedComponent< EvolveEnergy >, NamedComponent< BraginskiiElectronViscosity >, NamedComponent< FixedVelocity >, NamedComponent< SheathBoundary >, NamedComponent< Quasineutral >, NamedComponent< FixedTemperature >, NamedComponent< FixedDensity >, NamedComponent< BinormalSTPM >, NamedComponent< SheathClosure >, NamedComponent< NeutralFullVelocity >, NamedComponent< Ionisation >, NamedComponent< FixedFractionIons >, NamedComponent< EvolvePressure >, NamedComponent< Transform >, NamedComponent< Isothermal >, NamedComponent< ZeroCurrent >, NamedComponent< ScaleTimeDerivs >, NamedComponent< NoFlowBoundary >, NamedComponent< ExternalApar >, NamedComponent< AnomalousDiffusion >, NamedComponent< Vorticity >, NamedComponent< SheathBoundarySimple >, NamedComponent< SOLKITNeutralParallelDiffusion >, NamedComponent< UpstreamDensityFeedback >, NamedComponent< NeutralMixed >, NamedComponent< EvolveMomentum >, NamedComponent< EvolveDensity >, NamedComponent< BraginskiiConduction >, NamedComponent< SetTemperature >, NamedComponent< Recycling >, NamedComponent< PolarisationDrift >, NamedComponent< BraginskiiFriction >, NamedComponent< BraginskiiIonViscosity >, NamedComponent< ClassicalDiffusion >, FixedFractionRadiation< CoolingCurve >, NamedComponent< T >, hermes::ReactionBase

Public Functions

inline Component(const std::string &name, Permissions &&access_permissions)#

Initialise the state_variable_acceess permissions. Note that {all_species} in any variable names will be replaced with the names of all species being simulated (by calling declareAllSpecies(), which is done after all components are created by a ComponentSchedular).

inline virtual ~Component()#
void transform(Options &state)#

Modify the given simulation state. This method will wrap the state in a GuardedOptions object and pass that to the private implementation of transform provided by each component.

inline virtual void finally(const Options &state)#

Use the final simulation state to update internal state (e.g. time derivatives)

inline virtual void outputVars(Options &state)#

Add extra fields for output, or set attributes e.g docstrings.

inline virtual void restartVars(Options &state)#

Add extra fields to restart files.

inline virtual void precon(const Options &state, BoutReal gamma)#

Preconditioning.

void declareAllSpecies(const SpeciesInformation &info)#

Tell the component the name of all species in the simulation, by type. It will use this information to substitute the following placeholders in state_variable_access:

  • electrons (any electron species)

  • electrons2 (same as above, used for Cartesian product)

  • neutrals (species with no charge)

  • neutrals2 (same as above, used for Cartesian product)

  • positive_ions (ions with a positive charge)

  • positive_ions2 (same as above, used for Cartesian product)

  • negative_ions (ions with a negative charge)

  • negative_ions2 (same as above, used for Cartesian product)

  • ions (all ions, regardless of sign of charge)

  • ions2 (same as above, used for Cartesian product)

  • charged (ions and electrons)

  • charged2 (same as above, used for Cartesian product)

  • non_electrons (ions and neutrals)

  • non_electrons2 (same as above, used for Cartesian product)

  • all_species (ions, neutrals, and electrons)

  • all_species2 (same as above, used for Cartesian product)

At the end of this function there is a call to Permissions::checkNoRemainingSubstitutions. All substitutions must be completed or else an exception will be thrown.

inline const Permissions &getPermissions() const#
virtual std::string typeName() const = 0#
inline std::string objectName() const#

Public Static Functions

static std::unique_ptr<Component> create(const std::string &type, const std::string &name, Options &options, Solver *solver)#

Create a Component

Parameters:
  • type – The name of the component type to create (e.g. “evolve_density”)

  • name – The species/name for this instance.

  • optionsComponent settings: options[name] are specific to this component

  • solver – Time-integration solver

Protected Functions

inline void setPermissions(const std::string &variable, const Permissions::AccessRights &rights)#

Set the level of access needed by this component for a particular variable.

inline void setPermissions(const Permissions::VarRights &info)#
inline void substitutePermissions(const std::string &label, const std::vector<std::string> &substitution)#

Replace a placeholder in the name of variables stored in the access control information for this component.

Private Functions

virtual void transform_impl(GuardedOptions &state) = 0#

The implementation of the transform method. Modify the given simulation state. All components must implement this function. It will only allow the reading from/writing to state variables with the appropriate permissiosn in state_variable_access.

Private Members

std::string name#
Permissions state_variable_access#

Information on which state variables the transform method will read and write.

template<typename T>
struct NamedComponent : public Component#
#include <component.hxx>

Subclass of Component that implements the typeName method via CRTP.

Public Functions

inline virtual std::string typeName() const final#
inline Component(const std::string &name, Permissions &&access_permissions)#

Initialise the state_variable_acceess permissions. Note that {all_species} in any variable names will be replaced with the names of all species being simulated (by calling declareAllSpecies(), which is done after all components are created by a ComponentSchedular).

class ComponentFactory : public Factory<Component, ComponentFactory, const std::string&, Options&, Solver*>#
#include <component.hxx>

A factory for creating Components on demand, based on a string type name The template arguments after ComponentFactory are the types of the arguments to the Component constructor.

Public Static Attributes

static constexpr auto type_name = "Component"#
static constexpr auto section_name = "component"#
static constexpr auto option_name = "type"#
static constexpr auto default_type = "none"#
template<typename DerivedType>
struct RegisterComponent : public ComponentFactory::RegisterInFactory<DerivedType>#
#include <component.hxx>

Simpler name for Factory registration helper class

Usage:

#include "component.hxx"
namespace {
RegisterComponent<MyComponent> registercomponentmine;
}
In order for this to work, the component class must have a static constexpr component called type containing the name for the component. This component will need to be convertible to a string.

Public Functions

inline RegisterComponent()#
template<>
struct formatter<Component> : public formatter<string_view>#
#include <component.hxx>

Public Functions

inline constexpr auto parse(format_parse_context &ctx) -> format_parse_context::iterator#

Formatter for Components

By default it will use the format OBJECT_NAME (COMPONENT_TYPE_NAME), if the two names are different. If they are the same then it will just show the object name. This behaviour can be overriden using the format specifiers below:

  • ~n: Don’t show object name

  • ~t: Don’t show type name

  • T: Always show type name

auto format(const Component &component, format_context &ctx) const -> format_context::iterator#

Private Members

fmt::formatter<string_view> underlying#
bool hide_name = false#
bool hide_type = false#
bool show_type = false#
namespace hermes

Typedefs

template<class T>
using EnableIfGuardedOption = std::enable_if_t<std::is_base_of_v<GuardedOptions, T>>#

Enable a function if and only if T is a (subclass of) GuardedOptions