ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_FloodEngineRegistry.H File Reference

The flood engines compiled into this executable. More...

#include <ERF_FloodCouplingParams.H>
#include <ERF_FloodEngine.H>
#include <AMReX.H>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
Include dependency graph for ERF_FloodEngineRegistry.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ERF_FLOOD_ENGINE_CONCAT_(a, b)   a##b
 
#define ERF_FLOOD_ENGINE_CONCAT(a, b)   ERF_FLOOD_ENGINE_CONCAT_(a, b)
 
#define ERF_REGISTER_FLOOD_ENGINE(Class, name)
 Register engine class Class under name: erf.flood.engine = name selects it. Class is constructed from the coupling inputs, Class(const FloodCouplingParams&), or default-constructed when it has no such constructor. More...
 

Typedefs

using FloodEngineCreator = std::function< std::unique_ptr< FloodEngine >(const FloodCouplingParams &)>
 Creates an engine from the coupling inputs. More...
 

Functions

bool register_flood_engine (const std::string &name, FloodEngineCreator creator)
 Add an engine to the registry; aborts on a name registered twice. More...
 
std::vector< std::string > flood_engine_names ()
 Names erf.flood.engine accepts, sorted; empty when no engine is compiled in. More...
 
std::unique_ptr< FloodEngine > make_flood_engine (const std::string &name, const FloodCouplingParams &params)
 The engine erf.flood.engine names, or nullptr when no engine has that name. More...
 

Detailed Description

The flood engines compiled into this executable.

ERF lists no engine itself. Each engine registers itself from its own .cpp with

ERF_REGISTER_FLOOD_ENGINE(MyEngine, "myengine")

at namespace scope, and erf.flood.engine then selects it by that name. The engine's directory (FLOOD_HOME in GNU make, ERF_FLOOD_ENGINE_DIRS in CMake) adds that .cpp to the build, so adding an engine changes no file of ERF.

The registration runs during static initialization, so the .cpp that holds it must be linked as an object file: inside a static archive (.a) that nothing else references, the linker drops it and the engine is missing. ERF's CMake build compiles engines into its OBJECT library, and GNU make links every object, so both keep it; an engine that ships a prebuilt library keeps its registering .cpp as source.

The registry follows the fire-engine registry (ERF_FireEngineRegistry.H) and is independent of it: a build may hold fire engines, flood engines, both or neither.

Macro Definition Documentation

◆ ERF_FLOOD_ENGINE_CONCAT

#define ERF_FLOOD_ENGINE_CONCAT (   a,
  b 
)    ERF_FLOOD_ENGINE_CONCAT_(a, b)

◆ ERF_FLOOD_ENGINE_CONCAT_

#define ERF_FLOOD_ENGINE_CONCAT_ (   a,
  b 
)    a##b

◆ ERF_REGISTER_FLOOD_ENGINE

#define ERF_REGISTER_FLOOD_ENGINE (   Class,
  name 
)
Value:
namespace { \
[[maybe_unused]] const bool ERF_FLOOD_ENGINE_CONCAT(erf_flood_engine_registered_, __LINE__) = \
register_flood_engine((name), [](const FloodCouplingParams& p) -> std::unique_ptr<FloodEngine> { \
if constexpr (std::is_constructible_v<Class, const FloodCouplingParams&>) { \
return std::make_unique<Class>(p); \
} else { \
amrex::ignore_unused(p); \
return std::make_unique<Class>(); \
} \
}); \
}
#define ERF_FLOOD_ENGINE_CONCAT(a, b)
Definition: ERF_FloodEngineRegistry.H:57
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_FloodCouplingParams.H:20

Register engine class Class under name: erf.flood.engine = name selects it. Class is constructed from the coupling inputs, Class(const FloodCouplingParams&), or default-constructed when it has no such constructor.

Typedef Documentation

◆ FloodEngineCreator

using FloodEngineCreator = std::function<std::unique_ptr<FloodEngine>(const FloodCouplingParams&)>

Creates an engine from the coupling inputs.

Function Documentation

◆ flood_engine_names()

std::vector<std::string> flood_engine_names ( )

Names erf.flood.engine accepts, sorted; empty when no engine is compiled in.

16 {
17  return FloodRegistry::names();
18 }
static std::vector< std::string > names()
The registered names, sorted.
Definition: ERF_SurfaceEngineRegistry.H:49

Referenced by FloodCouplingParams::read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_flood_engine()

std::unique_ptr<FloodEngine> make_flood_engine ( const std::string &  name,
const FloodCouplingParams &  params 
)

The engine erf.flood.engine names, or nullptr when no engine has that name.

22 {
23  return FloodRegistry::make(name, params);
24 }
static std::unique_ptr< Engine > make(const std::string &name, const Params &params)
The engine registered under name, or nullptr.
Definition: ERF_SurfaceEngineRegistry.H:57

Referenced by ERF::initializeFlood().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_flood_engine()

bool register_flood_engine ( const std::string &  name,
FloodEngineCreator  creator 
)

Add an engine to the registry; aborts on a name registered twice.

Called by ERF_REGISTER_FLOOD_ENGINE; returns true so the macro can hold the result in a static variable.

10 {
11  return FloodRegistry::add(flood_coupling_names(), name, std::move(creator));
12 }
const SurfaceCouplingNames & flood_coupling_names()
The flood coupling's names: erf.flood.<key>, "[FLOOD]", "flood grid".
Definition: ERF_FloodGrid.H:26
static bool add(const SurfaceCouplingNames &names, const std::string &name, Creator creator)
Add an engine; aborts on an empty name or a name registered twice.
Definition: ERF_SurfaceEngineRegistry.H:33
Here is the call graph for this function: