27#include "neml2/models/solid_mechanics/elasticity/ElasticityConverter.h"
28#include "neml2/base/MultiEnumSelection.h"
29#include "neml2/tensors/Scalar.h"
38template <
class Derived, std::
size_t N>
61 std::vector<TensorName<Scalar>> _coefs;
64 const std::vector<ElasticConstant> _coef_types;
67 std::vector<bool> _coef_as_param;
70 std::size_t _counter = 0;
81template <
class Derived, std::
size_t N>
85 OptionSet options = Derived::expected_options();
103 options.
set(
"coefficient_types").doc() =
104 "Types for each parameter, options are: " + type_selection.candidates_str();
106 options.
set_parameter<std::vector<TensorName<Scalar>>>(
"coefficients");
107 options.
set(
"coefficients").doc() =
"Coefficients used to define the elasticity tensor";
109 options.
set<std::vector<bool>>(
"coefficient_as_parameter") = {
true};
110 options.
set(
"coefficient_as_parameter").doc() =
111 "Whether to treat the coefficients as (trainable) parameters. Default is true. Setting this "
112 "option to false will treat the coefficients as buffers.";
117template <
class Derived, std::
size_t N>
122 _coef_as_param(options.get<std::vector<bool>>(
"coefficient_as_parameter"))
124 if (_coefs.size() != N)
125 throw NEMLException(
"Expected " + std::to_string(N) +
" coefficients, got " +
126 std::to_string(_coefs.size()) +
".");
127 if (_coef_types.size() != N)
128 throw NEMLException(
"Expected " + std::to_string(N) +
" coefficient types, got " +
129 std::to_string(_coef_types.size()) +
".");
130 if (_coef_as_param.size() != 1 && _coef_as_param.size() != N)
132 " entries in coefficient_as_parameter, got " +
133 std::to_string(_coef_as_param.size()) +
".");
135 if (_coef_as_param.size() == 1)
136 _coef_as_param.resize(N, _coef_as_param[0]);
152template <
class Derived, std::
size_t N>
156 for (std::size_t i = 0; i < _coefs.size(); i++)
159 throw NEMLException(
"Invalid coefficient type provided for coefficient " + std::to_string(i) +
162 if (_coef_types[i] != ptype)
167 throw NEMLException(
"Duplicate coefficient type provided for coefficient " +
168 std::to_string(i) +
".");
171 const auto * pval = _coef_as_param[i]
172 ? &Derived::template declare_parameter<Scalar>(
173 pname, _coefs[i],
true)
174 : &Derived::template declare_buffer<Scalar>(pname, _coefs[i]);
std::array< const Scalar *, N > _constants
Input elastic constants (ordered according to ElasticConstant)
Definition ElasticityInterface.h:54
ElasticityInterface(const OptionSet &options)
Definition ElasticityInterface.h:118
std::array< bool, N > _need_derivs
Whether we need to calculate the derivative of the constants.
Definition ElasticityInterface.h:57
static OptionSet expected_options()
Definition ElasticityInterface.h:83
void declare_elastic_constant(ElasticConstant)
Declare elastic constants (by resolving cross-references)
Definition ElasticityInterface.h:154
std::array< ElasticConstant, N > _constant_types
Input elastic constant types (ordered according to ElasticConstant)
Definition ElasticityInterface.h:51
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:52
T & set_parameter(const std::string &)
Convenient method to request a parameter.
Definition OptionSet.h:284
T & set(const std::string &)
Definition OptionSet.h:273
Scalar.
Definition Scalar.h:38
Definition DiagnosticsInterface.cxx:30
ElasticConstant
Definition ElasticityConverter.h:38
@ P_WAVE_MODULUS
Definition ElasticityConverter.h:46
@ SHEAR_MODULUS
Definition ElasticityConverter.h:43
@ POISSONS_RATIO
Definition ElasticityConverter.h:45
@ BULK_MODULUS
Definition ElasticityConverter.h:42
@ YOUNGS_MODULUS
Definition ElasticityConverter.h:44
@ LAME_LAMBDA
Definition ElasticityConverter.h:41
@ INVALID
Definition ElasticityConverter.h:39
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
The name of a tensor object that can be referenced in the input files.
Definition TensorName.h:46