NEML2 1.4.0
Loading...
Searching...
No Matches
LargeDeformationIncrementalSolidMechanicsDriver.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/LargeDeformationIncrementalSolidMechanicsDriver.h"
26
27namespace neml2
28{
30
33{
35 options.doc() = "Driver for large deformation solid mechanics material model. The material model "
36 "is updated *incrementally*.";
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>("deformation_rate") = VariableName("forces", "deformation_rate");
43 options.set("deformation_rate").doc() = "Deformation rate";
44
45 options.set<VariableName>("cauchy_stress_rate") = VariableName("forces", "cauchy_stress_rate");
46 options.set("cauchy_stress_rate").doc() = "Cauchy stress rate";
47
48 options.set<VariableName>("vorticity") = VariableName("forces", "vorticity");
49 options.set("vorticity").doc() = "Vorticity";
50
51 options.set<CrossRef<torch::Tensor>>("prescribed_deformation_rate");
52 options.set("prescribed_deformation_rate").doc() =
53 "Prescribed deformation rate (when control = STRAIN)";
54
55 options.set<CrossRef<torch::Tensor>>("prescribed_cauchy_stress_rate");
56 options.set("prescribed_cauchy_stress_rate").doc() =
57 "Prescribed cauchy stress rate (when control = STRESS)";
58
59 options.set<CrossRef<torch::Tensor>>("prescribed_vorticity");
60 options.set("prescribed_vorticity").doc() = "Prescribed vorticity";
61
62 return options;
63}
64
66 const OptionSet & options)
67 : TransientDriver(options),
68 _control(options.get<std::string>("control")),
69 _vorticity_name(options.get<VariableName>("vorticity")),
70 _vorticity_prescribed(
71 !options.get<CrossRef<torch::Tensor>>("prescribed_vorticity").raw().empty()),
72 _vorticity(_vorticity_prescribed
73 ? WR2(options.get<CrossRef<torch::Tensor>>("prescribed_vorticity"))
74 : WR2::zeros(_driving_force.batch_sizes()))
75{
76 if (_control == "STRAIN")
77 {
78 _driving_force = SR2(options.get<CrossRef<torch::Tensor>>("prescribed_deformation_rate"), 2);
79 _driving_force_name = options.get<VariableName>("deformation_rate");
80 }
81 else if (_control == "STRESS")
82 {
83 _driving_force = SR2(options.get<CrossRef<torch::Tensor>>("prescribed_cauchy_stress_rate"), 2);
84 _driving_force_name = options.get<VariableName>("cauchy_stress_rate");
85 }
86 else
87 // LCOV_EXCL_START
88 throw NEMLException("Unsupported control type.");
89 // LCOV_EXCL_STOP
90
93
95}
96
97void
99{
102 _driving_force.dim() == 3,
103 "Input deformation rate/stress rate should have dimension 3 but instead has dimension",
104 _driving_force.dim());
105 neml_assert(_time.sizes()[0] == _driving_force.sizes()[0],
106 "Input deformation rate/stress rate and time should have the same number of time "
107 "steps. The input "
108 "time has ",
109 _time.sizes()[0],
110 " time steps, while the input deformation rate/stress rate has ",
111 _driving_force.sizes()[0],
112 " time steps");
113 neml_assert(_vorticity.sizes()[0] == _driving_force.sizes()[0],
114 "Input vorticity and deformation rate/stress rate should have the same number of "
115 "time steps. The input vorticity "
116 "has ",
117 _vorticity.sizes()[0],
118 " time steps, while the input deformation rate/stress rate has ",
119 _driving_force.sizes()[0],
120 " time steps");
121 neml_assert(_time.sizes()[1] == _driving_force.sizes()[1],
122 "Input deformation rate/stress rate and time should have the same batch size. The "
123 "input time has a "
124 "batch size of ",
125 _time.sizes()[1],
126 " while the input strain/stress has a batch size of ",
127 _driving_force.sizes()[1]);
128 neml_assert(_driving_force.sizes()[2] == 6,
129 "Input strain/stress should have final dimension 6 but instead has final dimension ",
130 _driving_force.sizes()[2]);
131 neml_assert(_vorticity.sizes()[2] == 3,
132 "Input vorticity should have final dimension 3, but instead has final dimension ",
133 _vorticity.sizes()[2]);
134}
135
136void
144}
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
The transient driver specialized for solid mechanics problems.
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:38
WR2 _vorticity
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:84
VariableName _vorticity_name
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:76
void check_integrity() const override
Check the integrity of the set up.
Definition LargeDeformationIncrementalSolidMechanicsDriver.cxx:98
virtual void update_forces() override
Update the driving forces for the current time step.
Definition LargeDeformationIncrementalSolidMechanicsDriver.cxx:137
VariableName _driving_force_name
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:71
std::string _control
The control method to drive the constitutive update.
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:59
static OptionSet expected_options()
Definition LargeDeformationIncrementalSolidMechanicsDriver.cxx:32
LargeDeformationIncrementalSolidMechanicsDriver(const OptionSet &options)
Construct a new LargeDeformationIncrementalSolidMechanicsDriver object.
Definition LargeDeformationIncrementalSolidMechanicsDriver.cxx:65
SR2 _driving_force
Definition LargeDeformationIncrementalSolidMechanicsDriver.h:65
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 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
A skew rank 2, represented as an axial vector.
Definition WR2.h:43
Definition CrossRef.cxx:32
LabeledAxisAccessor VariableName
Definition Variable.h:35
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73