NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ParameterStore.h
1// Copyright 2024, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include <memory>
28
29#include "neml2/jit/types.h"
30
31namespace neml2
32{
33// Forward decl
34class NEML2Object;
35class VariableBase;
36class Model;
37template <typename T>
38struct TensorName;
39class TensorValueBase;
40template <typename T>
41class TensorBase;
42class Tensor;
43
46{
47public:
48 ParameterStore(Model * object);
49
50 ParameterStore(const ParameterStore &) = delete;
54 virtual ~ParameterStore() = default;
55
58 const std::map<std::string, std::unique_ptr<TensorValueBase>> & named_parameters() const
59 {
60 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
61 return const_cast<ParameterStore *>(this)->named_parameters();
62 }
63 std::map<std::string, std::unique_ptr<TensorValueBase>> & named_parameters();
65
67 const TensorValueBase & get_parameter(const std::string & name) const
68 {
69 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
70 return const_cast<ParameterStore *>(this)->get_parameter(name);
71 }
72
73 TensorValueBase & get_parameter(const std::string & name);
74
76 void set_parameter(const std::string &, const Tensor &);
78 void set_parameters(const std::map<std::string, Tensor> &);
79
80protected:
86 virtual void send_parameters_to(const TensorOptions & options);
87
101 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
102 const T & declare_parameter(const std::string & name, const T & rawval);
103
116 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
117 const T & declare_parameter(const std::string & name,
118 const TensorName<T> & tensorname,
119 bool allow_nonlinear);
120
134 template <typename T, typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
135 const T & declare_parameter(const std::string & name,
136 const std::string & input_option_name,
137 bool allow_nonlinear = false);
138
140 void assign_parameter_stack(jit::Stack & stack);
141
143 jit::Stack collect_parameter_stack() const;
144
145private:
146 Model * _object;
147
149 std::map<std::string, std::unique_ptr<TensorValueBase>> _param_values;
150};
151
152} // namespace neml2
The base class for all constitutive models.
Definition Model.h:97
The base class of all "manufacturable" objects in the NEML2 library.
Definition NEML2Object.h:42
ParameterStore & operator=(const ParameterStore &)=delete
void set_parameter(const std::string &, const Tensor &)
Set the value for a parameter.
Definition ParameterStore.cxx:49
jit::Stack collect_parameter_stack() const
Collect stack from parameters.
Definition ParameterStore.cxx:344
void set_parameters(const std::map< std::string, Tensor > &)
Set values for parameters.
Definition ParameterStore.cxx:65
void assign_parameter_stack(jit::Stack &stack)
Assign stack to parameters.
Definition ParameterStore.cxx:320
ParameterStore & operator=(ParameterStore &&)=delete
const std::map< std::string, std::unique_ptr< TensorValueBase > > & named_parameters() const
Definition ParameterStore.h:58
const TensorValueBase & get_parameter(const std::string &name) const
}@
Definition ParameterStore.h:67
ParameterStore(const ParameterStore &)=delete
virtual ~ParameterStore()=default
virtual void send_parameters_to(const TensorOptions &options)
Send parameters to options.
Definition ParameterStore.cxx:42
const T & declare_parameter(const std::string &name, const T &rawval)
Declare a parameter.
Definition ParameterStore.cxx:81
ParameterStore(Model *object)
Definition ParameterStore.cxx:36
ParameterStore(ParameterStore &&)=delete
NEML2's enhanced tensor type.
Definition TensorBase.h:49
The base class to allow us to set up a polymorphic container of Tensors. The concrete definitions wil...
Definition TensorValue.h:39
Definition Tensor.h:46
Base class of variable.
Definition Variable.h:52
Definition DiagnosticsInterface.cxx:30
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
c10::TensorOptions TensorOptions
Definition types.h:63
The name of a tensor object that can be referenced in the input files.
Definition TensorName.h:46