SimulationCaseFactory< CaseType > Class Template Reference

Developer Documentation: SimulationCaseFactory< CaseType > Class Template Reference
Developer Documentation
SimulationCaseFactory< CaseType > Class Template Reference

Factory class for registering and creating simulation cases. More...

#include <case_factory.hpp>

Public Types

using SimulationCreator = std::function< std::unique_ptr< CaseType >(const std::string, const MPI_Comm)>
 Type definition for a function that creates a simulation case.
 

Static Public Member Functions

static bool register_simulation (const std::string name, SimulationCreator creator)
 Registers a simulation case with a unique name.
 
static std::unique_ptr< CaseType > create_simulation (const std::string name, const std::string parameter_file, const MPI_Comm mpi_communicator)
 Creates an instance of a registered simulation case.
 

Static Private Attributes

static std::map< std::string, SimulationCreatorcreators
 Stores registered simulation case creators.
 

Detailed Description

template<typename CaseType>
class SimulationCaseFactory< CaseType >

Factory class for registering and creating simulation cases.

This class provides a mechanism for dynamically registering and creating instances of simulation case classes based on a string identifier.

Template Parameters
CaseTypeThe base class type for simulation cases.

Member Typedef Documentation

◆ SimulationCreator

template<typename CaseType >
using SimulationCaseFactory< CaseType >::SimulationCreator = std::function<std::unique_ptr<CaseType>(const std::string, const MPI_Comm)>

Type definition for a function that creates a simulation case.

The function takes a parameter file and an MPI communicator as input and returns a unique pointer to an instance of the simulation case.

Member Function Documentation

◆ create_simulation()

template<typename CaseType >
static std::unique_ptr< CaseType > SimulationCaseFactory< CaseType >::create_simulation ( const std::string  name,
const std::string  parameter_file,
const MPI_Comm  mpi_communicator 
)
inlinestatic

Creates an instance of a registered simulation case.

Parameters
nameThe unique identifier of the simulation case to create.
parameter_fileThe parameter file used for initialization.
mpi_communicatorThe MPI communicator for parallel execution.
Returns
A unique pointer to the created simulation case instance.
Exceptions
Exceptionif the requested case is not registered.

This function retrieves the corresponding creator function from the factory and uses it to instantiate the requested simulation case.

◆ register_simulation()

template<typename CaseType >
static bool SimulationCaseFactory< CaseType >::register_simulation ( const std::string  name,
SimulationCreator  creator 
)
inlinestatic

Registers a simulation case with a unique name.

Parameters
nameThe unique identifier for the simulation case.
creatorA function that creates an instance of the simulation case.
Returns
True if the registration was successful.
Exceptions
Exceptionif a case with the same name is already registered.

This function ensures that each simulation case is registered only once.

Member Data Documentation

◆ creators

template<typename CaseType >
std::map<std::string, SimulationCreator> SimulationCaseFactory< CaseType >::creators
inlinestaticprivate

Stores registered simulation case creators.

A static map that associates simulation case names with their corresponding creator functions.


The documentation for this class was generated from the following file: