27#include "neml2/models/solid_mechanics/elasticity/ElasticityConverter.h"
28#include "neml2/base/MultiEnumSelection.h"
37template <
class Derived, std::
size_t N>
60 const std::vector<CrossRef<Scalar>> _coefs;
63 const std::vector<ElasticConstant> _coef_types;
66 std::vector<bool> _coef_as_param;
69 std::size_t _counter = 0;
80template <
class Derived, std::
size_t N>
84 OptionSet options = Derived::expected_options();
102 options.
set(
"coefficient_types").doc() =
103 "Types for each parameter, options are: " +
type_selection.candidates_str();
105 options.
set_parameter<std::vector<CrossRef<Scalar>>>(
"coefficients");
106 options.
set(
"coefficients").doc() =
"Coefficients used to define the elasticity tensor";
108 options.
set<std::vector<bool>>(
"coefficient_as_parameter") = {
true};
109 options.
set(
"coefficient_as_parameter").doc() =
110 "Whether to treat the coefficients as (trainable) parameters. Default is true. Setting this "
111 "option to false will treat the coefficients as buffers.";
116template <
class Derived, std::
size_t N>
121 _coef_as_param(options.get<std::
vector<
bool>>(
"coefficient_as_parameter"))
123 neml_assert(_coefs.size() ==
N,
"Expected ",
N,
" coefficients, got ", _coefs.size(),
".");
127 " entries in coefficient_types, got ",
130 neml_assert(_coef_as_param.size() == 1 || _coef_as_param.size() ==
N,
133 " entrie(s) in coefficient_as_parameter, got ",
134 _coef_as_param.size(),
137 if (_coef_as_param.size() == 1)
138 _coef_as_param.resize(
N, _coef_as_param[0]);
154template <
class Derived, std::
size_t N>
158 for (std::size_t
i = 0;
i < _coefs.size();
i++)
161 "Invalid coefficient type provided for coefficient ",
165 if (_coef_types[
i] !=
ptype)
169 std::next(_constant_types.begin(), _counter),
170 ptype) == std::next(_constant_types.begin(), _counter),
171 "Duplicate coefficient type provided for coefficient ",
177 _coef_as_param[
i] ? &Derived::declare_parameter(
pname, _coefs[
i],
true)
178 : &Derived::declare_buffer(
pname, _coefs[
i]);
180 neml_assert(_counter <
N,
"Too many coefficients provided.");
181 _constant_types[_counter] =
ptype;
182 _constants[_counter] =
pval;
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
Interface for objects defining elasticity tensors in terms of other parameters.
Definition ElasticityInterface.h:39
std::array< const Scalar *, N > _constants
Input elastic constants (ordered according to ElasticConstant)
Definition ElasticityInterface.h:53
ElasticityInterface(const OptionSet &options)
Definition ElasticityInterface.h:117
std::array< bool, N > _need_derivs
Whether we need to calculate the derivative of the constants.
Definition ElasticityInterface.h:56
static OptionSet expected_options()
Definition ElasticityInterface.h:82
void declare_elastic_constant(ElasticConstant)
Declare elastic constants (by resolving cross-references)
Definition ElasticityInterface.h:156
std::array< ElasticConstant, N > _constant_types
Input elastic constant types (ordered according to ElasticConstant)
Definition ElasticityInterface.h:50
Selection of multiple enum value from a list of candidates.
Definition MultiEnumSelection.h:41
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:85
T & set_parameter(const std::string &)
Convenient method to request a parameter.
Definition OptionSet.h:534
T & set(const std::string &)
Definition OptionSet.h:523
Scalar.
Definition Scalar.h:38
Definition CrossRef.cxx:31
ElasticConstant
Definition ElasticityConverter.h:38
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
void neml_assert(bool assertion, Args &&... args)
Definition error.h:64