27#include "neml2/base/NEML2Object.h"
28#include "neml2/misc/error.h"
29#include "neml2/base/OptionCollection.h"
30#include "neml2/base/DiagnosticsInterface.h"
47void load_input(
const std::filesystem::path & path,
const std::string & additional_input =
"");
58void reload_input(
const std::filesystem::path & path,
const std::string & additional_input =
"");
68Model &
get_model(
const std::string & mname,
bool force_create =
true);
76Model &
load_model(
const std::filesystem::path & path,
const std::string & mname);
85Model &
reload_model(
const std::filesystem::path & path,
const std::string & mname);
124 static std::shared_ptr<T>
get_object_ptr(
const std::string & section,
125 const std::string &
name,
146 static T &
get_object(
const std::string & section,
147 const std::string &
name,
170 static void print(std::ostream &
os = std::cout);
189 std::map<std::string, std::map<std::string, std::vector<std::shared_ptr<NEML2Object>>>> _objects;
196inline std::shared_ptr<T>
198 const std::string &
name,
216 "Found object named ",
220 ". But dynamic cast failed. Did you specify the correct object type?");
226 for (
auto & options :
factory._all_options[section])
227 if (options.first ==
name)
236 "Failed to get object named ",
241 auto obj = std::dynamic_pointer_cast<T>(
factory._objects[section][
name].back());
242 neml_assert(
obj !=
nullptr,
"Internal error: Factory failed to create object ",
name);
249 const std::string &
name,
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
void create_object(const std::string §ion, const OptionSet &options)
Manufacture a single NEML2Object.
Definition Factory.cxx:111
static T & get_object(const std::string §ion, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=true)
Retrive an object reference under the given section with the given object name.
Definition Factory.h:248
static std::shared_ptr< T > get_object_ptr(const std::string §ion, const std::string &name, const OptionSet &additional_options=OptionSet(), bool force_create=true)
Retrive an object pointer under the given section with the given object name.
Definition Factory.h:197
static const OptionCollection & loaded_options()
Get the loaded options.
Definition Factory.cxx:104
static void load_options(const OptionCollection &all_options)
Provide all objects' options to the factory. The factory is ready to manufacture objects after this c...
Definition Factory.cxx:93
static void clear()
Destruct all the objects.
Definition Factory.cxx:146
static Factory & get()
Get the global Factory singleton.
Definition Factory.cxx:86
static void print(std::ostream &os=std::cout)
List all the manufactured objects.
Definition Factory.cxx:133
A data structure that holds options of multiple objects.
Definition OptionCollection.h:39
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:85
Definition CrossRef.cxx:31
Model & load_model(const std::filesystem::path &path, const std::string &mname)
A convenient function to load an input file and get a model.
Definition Factory.cxx:66
Model & get_model(const std::string &mname, bool force_create)
A convenient function to manufacture a neml2::Model.
Definition Factory.cxx:59
bool options_compatible(const OptionSet &opts, const OptionSet &additional_opts)
Definition OptionSet.cxx:31
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
void reload_input(const std::filesystem::path &path, const std::string &additional_input)
Similar to neml2::load_input, but additionally clear the Factory before loading the options,...
Definition Factory.cxx:52
Model & reload_model(const std::filesystem::path &path, const std::string &mname)
Similar to neml2::load_model, but additionally clear the Factory before loading the model,...
Definition Factory.cxx:73
Driver & get_driver(const std::string &dname)
A convenient function to manufacture a neml2::Driver.
Definition Factory.cxx:80
void load_input(const std::filesystem::path &path, const std::string &additional_input)
A convenient function to parse all options from an input file.
Definition Factory.cxx:35
void neml_assert(bool assertion, Args &&... args)
Definition error.h:64