30#include "neml2/misc/errors.h"
31#include "neml2/base/InputFile.h"
56std::unique_ptr<Factory>
load_input(
const std::filesystem::path & path,
57 const std::string & additional_input =
"");
79 bool has_object(
const std::string & section,
const std::string &
name);
98 std::shared_ptr<T>
get_object(
const std::string & section,
99 const std::string &
name,
101 bool force_create =
true);
104 template <
class T = Solver>
107 template <
class T = Data>
110 template <
class T = Model>
113 template <
class T = Driver>
116 template <
class T = WorkScheduler>
127 void print(std::ostream & os = std::cout);
140 bool options_compatible(
const std::shared_ptr<NEML2Object> & obj,
const OptionSet & opts)
const;
149 std::map<std::string, std::map<std::string, std::vector<std::shared_ptr<NEML2Object>>>> _objects;
155 const std::string &
name,
164 if (_objects.count(section) && _objects.at(section).count(
name))
165 for (
const auto & neml2_obj : _objects[section][
name])
168 if (!options_compatible(neml2_obj, additional_options))
172 auto obj = std::dynamic_pointer_cast<T>(neml2_obj);
175 "Found object named " +
name +
" under section " + section +
176 ". But dynamic cast failed. Did you specify the correct object type?");
182 for (
const auto & options : _input_file[section])
183 if (options.first ==
name)
185 auto new_options = options.second;
186 new_options.set<
Factory *>(
"_factory") =
this;
187 new_options.set<std::shared_ptr<Settings>>(
"_settings") =
settings();
188 new_options += additional_options;
193 if (!_objects.count(section) || !_objects.at(section).count(
name))
195 ". Check to make sure the object is defined in the input file.");
197 auto obj = std::dynamic_pointer_cast<T>(_objects[section][
name].back());
std::shared_ptr< T > get_object(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:154
std::shared_ptr< T > get_driver(const std::string &name)
Get a driver by its name.
Definition Factory.h:228
std::shared_ptr< T > get_data(const std::string &name)
Get a data by its name.
Definition Factory.h:214
void create_object(const std::string §ion, const OptionSet &options)
Manufacture a single NEML2Object.
Definition Factory.cxx:60
const std::shared_ptr< Settings > & settings() const
Global settings.
Definition Factory.h:76
Factory(InputFile)
Definition Factory.cxx:47
std::shared_ptr< T > get_model(const std::string &name)
Get a model by its name.
Definition Factory.h:221
std::shared_ptr< T > get_scheduler(const std::string &name)
Get a scheduler by its name.
Definition Factory.h:235
bool has_object(const std::string §ion, const std::string &name)
Check if an object with the given name exists under the given section.
Definition Factory.cxx:54
InputFile & input_file()
Get the input file.
Definition Factory.h:70
const InputFile & input_file() const
Get the input file.
Definition Factory.h:73
void clear()
Delete all factories and destruct all the objects.
Definition Factory.cxx:101
std::shared_ptr< T > get_solver(const std::string &name)
Get a solver by its name.
Definition Factory.h:207
void print(std::ostream &os=std::cout)
List all the manufactured objects.
Definition Factory.cxx:88
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:51
Definition DiagnosticsInterface.cxx:30
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
std::unique_ptr< Factory > 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:34