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 =
"");
69Model &
get_model(
const std::string & mname,
bool enable_ad =
true,
bool force_create =
true);
79load_model(
const std::filesystem::path & path,
const std::string & mname,
bool enable_ad =
true);
90reload_model(
const std::filesystem::path & path,
const std::string & mname,
bool enable_ad =
true);
129 static std::shared_ptr<T>
get_object_ptr(
const std::string & section,
130 const std::string & name,
151 static T &
get_object(
const std::string & section,
152 const std::string & name,
175 static void print(std::ostream &
os = std::cout);
194 std::map<std::string, std::map<std::string, std::vector<std::shared_ptr<NEML2Object>>>> _objects;
201inline std::shared_ptr<T>
203 const std::string & name,
211 if (
factory._objects.count(section) &&
factory._objects.at(section).count(name))
221 "Found object named ",
225 ". But dynamic cast failed. Did you specify the correct object type?");
231 for (
auto & options :
factory._all_options[section])
232 if (options.first == name)
241 "Failed to get object named ",
246 auto obj = std::dynamic_pointer_cast<T>(
factory._objects[section][name].back());
247 neml_assert(
obj !=
nullptr,
"Internal error: Factory failed to create object ", name);
254 const std::string & name,
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
void create_object(const std::string §ion, const OptionSet &options)
Manufacture a single NEML2Object.
Definition Factory.cxx:114
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:253
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:202
static const OptionCollection & loaded_options()
Get the loaded options.
Definition Factory.cxx:107
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:96
static void clear()
Destruct all the objects.
Definition Factory.cxx:140
static Factory & get()
Get the global Factory singleton.
Definition Factory.cxx:89
static void print(std::ostream &os=std::cout)
List all the manufactured objects.
Definition Factory.cxx:127
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:100
Definition CrossRef.cxx:30
Model & load_model(const std::filesystem::path &path, const std::string &mname, bool enable_ad)
A convenient function to load an input file and get a model.
Definition Factory.cxx:69
bool options_compatible(const OptionSet &opts, const OptionSet &additional_opts)
Definition OptionSet.cxx:31
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, bool enable_ad)
Similar to neml2::load_model, but additionally clear the Factory before loading the model,...
Definition Factory.cxx:76
Model & get_model(const std::string &mname, bool enable_ad, bool force_create)
A convenient function to manufacture a neml2::Model.
Definition Factory.cxx:59
Driver & get_driver(const std::string &dname)
A convenient function to manufacture a neml2::Driver.
Definition Factory.cxx:83
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