Factory< Base, Args > Struct Template Reference
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
|
#include <Factory.H>
Classes | |
struct | Register |
Class to handle registration of subclass for runtime selection. More... | |
Public Member Functions | |
virtual | ~Factory ()=default |
Static Public Member Functions | |
static std::unique_ptr< Base > | create (const std::string &key, Args... args) |
static void | print (std::ostream &os) |
Public Attributes | |
friend | Base |
Private Types | |
using | CreatorFunc = std::unique_ptr<Base> (*)(Args...) |
using | LookupTable = std::unordered_map<std::string, CreatorFunc> |
Private Member Functions | |
Factory ()=default | |
Static Private Member Functions | |
static void | key_exists_or_error (const std::string &key) |
static LookupTable & | table () |
Lookup table containing all registered instances. | |
Detailed Description
struct amr_wind::Factory< Base, Args >
Runtime selection of options based on string keyword lookup
Factory provides an automated way to register subclasses that can be instantiated during runtime using string based lookups. The facility mimics the runTimeSelectionTable in OpenFOAM and the current structure is adapted from http://www.nirfriedman.com/2018/04/29/unforgettable-factory/
The usage is described using the following example from code. We would like to support creation of a turbulence model based on user inputs that are read from a file. We will create a base class TurbulenceModel that defines the API for the turbulence model and how it interacts with the rest of the code. Then new models, e.g., Smagorinsky, k-Omega SST/SAS, etc., are added as subclasses to this instance.
- Template Parameters
-
Base base class (e.g., Physics) Args Arguments types to be passed to the constructor during instantiation
Member Typedef Documentation
◆ CreatorFunc
|
private |
◆ LookupTable
|
private |
Constructor & Destructor Documentation
◆ ~Factory()
|
virtualdefault |
◆ Factory()
|
privatedefault |
Member Function Documentation
◆ create()
|
inlinestatic |
Create an instance of the concrete subclass based on the runtime keyword
- Parameters
-
key Unique identifier used to lookup subclass instance args Arguments to the constructor of the subclass
◆ key_exists_or_error()
|
inlinestaticprivate |
Check if the keyword exists in table or print diagnostic message and abort
◆ print()
|
inlinestatic |
Print a list of the valid subclasses registered to this base instance
- Parameters
-
os Valid output stream
◆ table()
|
inlinestaticprivate |
Lookup table containing all registered instances.
Member Data Documentation
◆ Base
friend amr_wind::Factory< Base, Args >::Base |
The documentation for this struct was generated from the following file:
- /home/runner/work/amr-wind/amr-wind/amr-wind/core/Factory.H
Generated by 1.12.0