NEML2 1.4.0
Loading...
Searching...
No Matches
SolidMechanicsDriver.cxx
1// Copyright 2023, 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#include "neml2/drivers/solid_mechanics/SolidMechanicsDriver.h"
26
27namespace neml2
28{
29register_NEML2_object(SolidMechanicsDriver);
30
33{
35 options.doc() =
36 "Driver for small deformation solid mechanics material model with optional thermal coupling.";
37
38 options.set<std::string>("control") = "STRAIN";
39 options.set("control").doc() = "External control of the material update. Options are STRAIN and "
40 "STRESS, for strain control and stress control, respectively.";
41
42 options.set<VariableName>("total_strain") = VariableName("forces", "E");
43 options.set("total_strain").doc() = "Total strain";
44
45 options.set<VariableName>("cauchy_stress") = VariableName("forces", "S");
46 options.set("cauchy_stress").doc() = "Cauchy stress";
47
48 options.set<VariableName>("temperature") = VariableName("forces", "T");
49 options.set("temperature").doc() = "Name of temperature";
50
51 options.set<VariableName>("fixed_values") = VariableName("forces", "fixed_values");
52 options.set("fixed_values").doc() = "Name of fixed values (when control = MIXED)";
53
54 options.set<CrossRef<torch::Tensor>>("prescribed_strains");
55 options.set("prescribed_strains").doc() = "Prescribed strain (when control = STRAIN)";
56
57 options.set<CrossRef<torch::Tensor>>("prescribed_stresses");
58 options.set("prescribed_stresses").doc() = "Prescribed stress (when control = STRESS)";
59
60 options.set<CrossRef<torch::Tensor>>("prescribed_temperatures");
61 options.set("prescribed_temperatures").doc() =
62 "Actual prescibed temperature values, when providing temperatures to the model";
63
64 options.set<CrossRef<torch::Tensor>>("prescribed_mixed_conditions");
65 options.set("prescribed_mixed_conditions").doc() =
66 "The fixed, controlled values provided as user input for the mixed control case. Where the "
67 "control signal is 0 these are strain values, where it is 1 these are stress values";
68
69 options.set<VariableName>("control_name") = VariableName("forces", "control");
70 options.set("control_name").doc() = "The name of the control signal on the input axis";
71
72 options.set<CrossRef<torch::Tensor>>("prescribed_control");
73 options.set("prescribed_control").doc() = "The actual values of the control signal. 0 implies "
74 "strain control, 1 implies stress control";
75
76 return options;
77}
78
80 : TransientDriver(options),
81 _control(options.get<std::string>("control")),
82 _control_name(options.get<VariableName>("control_name")),
83 _temperature_name(options.get<VariableName>("temperature")),
84 _temperature_prescribed(
85 !options.get<CrossRef<torch::Tensor>>("prescribed_temperatures").raw().empty()),
86 _temperature(_temperature_prescribed
87 ? Scalar(options.get<CrossRef<torch::Tensor>>("prescribed_temperatures"), 2)
88 : Scalar()),
89 _control_signal(_control == "MIXED"
90 ? SR2(options.get<CrossRef<torch::Tensor>>("prescribed_control"), 2)
91 : SR2())
92
93{
94 if (_control == "STRAIN")
95 {
96 _driving_force = SR2(options.get<CrossRef<torch::Tensor>>("prescribed_strains"), 2);
97 _driving_force_name = options.get<VariableName>("total_strain");
98 }
99 else if (_control == "STRESS")
100 {
101 _driving_force = SR2(options.get<CrossRef<torch::Tensor>>("prescribed_stresses"), 2);
102 _driving_force_name = options.get<VariableName>("cauchy_stress");
103 }
104 else if (_control == "MIXED")
105 {
106 _driving_force = SR2(options.get<CrossRef<torch::Tensor>>("prescribed_mixed_conditions"), 2);
107 _driving_force_name = options.get<VariableName>("fixed_values");
108 }
109 else
110 // LCOV_EXCL_START
111 throw NEMLException("Unsupported control type.");
112 // LCOV_EXCL_STOP
113
115
118
120}
121
122void
124{
126 neml_assert(_driving_force.dim() == 3,
127 "Input strain/stress should have dimension 3 but instead has dimension",
128 _driving_force.dim());
129 neml_assert(_time.sizes()[0] == _driving_force.sizes()[0],
130 "Input strain/stress and time should have the same number of time steps. The input "
131 "time has ",
132 _time.sizes()[0],
133 " time steps, while the input strain/stress has ",
134 _driving_force.sizes()[0],
135 " time steps");
136 neml_assert(_time.sizes()[1] == _driving_force.sizes()[1],
137 "Input strain/stress and time should have the same batch size. The input time has a "
138 "batch size of ",
139 _time.sizes()[1],
140 " while the input strain/stress has a batch size of ",
141 _driving_force.sizes()[1]);
142 neml_assert(_driving_force.sizes()[2] == 6,
143 "Input strain/stress should have final dimension 6 but instead has final dimension ",
144 _driving_force.sizes()[2]);
145
147 {
149 "Input temperature should have 2 batch dimensions but instead has batch dimension",
151 neml_assert(_time.sizes()[0] == _temperature.sizes()[0],
152 "Input temperature and time should have the same number of time steps. The input "
153 "time has ",
154 _time.sizes()[0],
155 " time steps, while the input temperature has ",
156 _temperature.sizes()[0],
157 " time steps");
158 neml_assert(_time.sizes()[1] == _temperature.sizes()[1],
159 "Input temperature and time should have the same batch size. The input time has a "
160 "batch size of ",
161 _time.sizes()[1],
162 " while the input temperature has a batch size of ",
163 _temperature.sizes()[1]);
164 }
165
166 if (_control == "MIXED")
167 {
170 "Input control signal should have 2 batch dimensions but instead has batch dimension",
173 _control_signal.sizes()[0] == _time.sizes()[0],
174 "Input control signal should have the same number of steps steps as time, but instead has",
175 _control_signal.sizes()[0],
176 "time steps");
178 _control_signal.sizes()[1] == _time.sizes()[1],
179 "Input control signal should have the same batch size as time, but instead has batch size",
180 _control_signal.sizes()[1]);
181 }
182}
183
184void
204}
TorchSize batch_dim() const
Return the number of batch dimensions.
Definition BatchTensorBase.cxx:128
Derived batch_index(TorchSlice indices) const
Get a batch.
Definition BatchTensorBase.cxx:184
Derived to(const torch::TensorOptions &options) const
Send to options.
Definition BatchTensorBase.cxx:331
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:44
void set(const BatchTensorBase< T > &value, S &&... names)
Set and interpret the input as an object.
Definition LabeledTensor.h:193
Definition error.h:33
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
const T & get(const std::string &) const
Definition OptionSet.h:422
T & set(const std::string &)
Definition OptionSet.h:436
The (logical) symmetric second order tensor.
Definition SR2.h:46
The (logical) scalar.
Definition Scalar.h:38
The transient driver specialized for solid mechanics problems.
Definition SolidMechanicsDriver.h:36
SR2 _control_signal
Actual control signal, when used for control == "MIXED".
Definition SolidMechanicsDriver.h:85
const std::string _control
The control method to drive the constitutive update.
Definition SolidMechanicsDriver.h:58
SolidMechanicsDriver(const OptionSet &options)
Construct a new SolidMechanicsDriver object.
Definition SolidMechanicsDriver.cxx:79
Scalar _temperature
Temperature.
Definition SolidMechanicsDriver.h:82
const VariableName _control_name
Name of the control signal for mixed stress/strain control.
Definition SolidMechanicsDriver.h:73
void check_integrity() const override
Check the integrity of the set up.
Definition SolidMechanicsDriver.cxx:123
virtual void update_forces() override
Update the driving forces for the current time step.
Definition SolidMechanicsDriver.cxx:185
VariableName _driving_force_name
Definition SolidMechanicsDriver.h:70
const VariableName _temperature_name
Name of the temperature variable.
Definition SolidMechanicsDriver.h:76
static OptionSet expected_options()
Definition SolidMechanicsDriver.cxx:32
const bool _temperature_prescribed
Whether temperature is prescribed.
Definition SolidMechanicsDriver.h:79
SR2 _driving_force
Definition SolidMechanicsDriver.h:64
The driver for a transient initial-value problem.
Definition TransientDriver.h:39
const torch::Device _device
The device on which to evaluate the model.
Definition TransientDriver.h:92
virtual void update_forces()
Update the driving forces for the current time step.
Definition TransientDriver.cxx:218
Scalar _time
The current time.
Definition TransientDriver.h:95
virtual void check_integrity() const override
Check the integrity of the set up.
Definition TransientDriver.cxx:135
LabeledVector & _in
The input to the constitutive model.
Definition TransientDriver.h:105
static OptionSet expected_options()
Definition TransientDriver.cxx:34
TorchSize _step_count
The current step count.
Definition TransientDriver.h:97
Definition CrossRef.cxx:32
LabeledAxisAccessor VariableName
Definition Variable.h:35
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73