include/meltpooldg/core/case_factory.hpp Source File

Developer Documentation: include/meltpooldg/core/case_factory.hpp Source File
Developer Documentation
case_factory.hpp
Go to the documentation of this file.
1#pragma once
2#include <deal.II/base/exceptions.h>
3#include <deal.II/base/mpi.h>
4
5#include <map>
6#include <memory>
7#include <string>
8
17template <typename CaseType>
19{
20public:
28 std::function<std::unique_ptr<CaseType>(const std::string, const MPI_Comm)>;
29
40 static bool
41 register_simulation(const std::string name, SimulationCreator creator)
42 {
43 AssertThrow(not creators.contains(name),
44 dealii::ExcMessage("Requested simulation case already registered: " + name));
45 creators[name] = creator;
46 return true;
47 }
48
61 static std::unique_ptr<CaseType>
62 create_simulation(const std::string name,
63 const std::string parameter_file,
64 const MPI_Comm mpi_communicator)
65 {
66 auto it = creators.find(name);
67 AssertThrow(it != creators.end(),
68 dealii::ExcMessage(
69 "Requested simulation case not registered: " + name +
70 " Did you forget to create a *.cpp file for your simulation case, " +
71 "where you explicitly instantiate your case?"));
72 return it->second(parameter_file, mpi_communicator);
73 }
74
75private:
82 static inline std::map<std::string, SimulationCreator> creators;
83};
Factory class for registering and creating simulation cases.
Definition case_factory.hpp:19
std::function< std::unique_ptr< CaseType >(const std::string, const MPI_Comm)> SimulationCreator
Type definition for a function that creates a simulation case.
Definition case_factory.hpp:28
static bool register_simulation(const std::string name, SimulationCreator creator)
Registers a simulation case with a unique name.
Definition case_factory.hpp:41
static std::map< std::string, SimulationCreator > creators
Stores registered simulation case creators.
Definition case_factory.hpp:82
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.
Definition case_factory.hpp:62