25#include "neml2/models/ParameterStore.h"
26#include "neml2/models/NonlinearParameter.h"
27#include "neml2/tensors/macros.h"
28#include "neml2/tensors/Variable.h"
42 "named_parameters() should only be called on the host model.");
49 neml_assert(_object->
host() == _object,
"This method should only be called on the host model.");
51 for (
auto && [name, param] : _param_values)
58 return _nl_params.count(name) ? _nl_params.at(name) :
nullptr;
61template <
typename T,
typename>
81 "Trying to declare a parameter named ",
83 ". It is not a plain tensor value nor a cross-referenced parameter "
84 "value. Hence I am guessing you are declaring a *nonlinear* parameter. "
85 "However, nonlinear parameter should only be declared by a model, and this "
86 "object does not appear to be a model.");
88 auto &
nl_param = Factory::get_object<NonlinearParameter<T>>(
90 _nl_params[name] = &
nl_param.param();
95 std::cerr <<
e1.what() << std::endl;
96 std::cerr <<
e2.what() << std::endl;
102 "Trying to register parameter named " + name +
" from input option named " +
104 ". Make sure you provided the correct parameter name, option name, and parameter type. Note "
105 "that the parameter type can either be a plain type, a cross-reference, or a nonlinear "
109#define PARAMETERSTORE_INTANTIATE_FIXEDDIMTENSOR(T) \
110 template const T & ParameterStore::declare_parameter<T>(const std::string &, const std::string &)
111FOR_ALL_FIXEDDIMTENSOR(PARAMETERSTORE_INTANTIATE_FIXEDDIMTENSOR);
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The base class for all constitutive models.
Definition Model.h:53
The base class of all "manufacturable" objects in the NEML2 library.
Definition NEML2Object.h:38
const T * host() const
Get a readonly pointer to the host.
Definition NEML2Object.h:90
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
virtual void send_parameters_to(const torch::TensorOptions &options)
Send parameters to options.
Definition ParameterStore.cxx:47
ParameterStore(const OptionSet &options, NEML2Object *object)
Definition ParameterStore.cxx:32
const Storage< std::string, TensorValueBase > & named_parameters() const
Definition ParameterStore.h:44
const T & declare_parameter(const std::string &name, const T &rawval)
Declare a parameter.
Definition ParameterStore.h:145
const VariableBase * nl_param(const std::string &) const
Query the existence of a nonlinear parameter.
Definition ParameterStore.cxx:56
std::string demangle(const char *name)
Definition parser_utils.cxx:46
Definition CrossRef.cxx:32
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73