NEML2 1.4.0
Loading...
Searching...
No Matches
MixedControlSetup.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/models/solid_mechanics/MixedControlSetup.h"
26#include "neml2/misc/math.h"
27
28namespace neml2
29{
30register_NEML2_object(MixedControlSetup);
31
34{
36 options.doc() =
37 "Object to setup a model for mixed stress/strain control. Copies the values of the "
38 "fixed_values (the input strain or stress) and the mixed_state (the conjugate stress or "
39 "strain values) into the stress and strain tensors used by the model.";
40
41 options.set<VariableName>("control") = VariableName("forces", "control");
42 options.set("control").doc() =
43 "The name of the control signal. Values less than the threshold are "
44 "strain control, greater are stress control";
45
46 options.set<CrossRef<BatchTensor>>("threshold") = "0.5";
47 options.set("threshold").doc() = "The threshold to switch between strain and stress control";
48
49 options.set<VariableName>("mixed_state") = VariableName("state", "mixed_state");
50 options.set("mixed_state").doc() = "The name of the mixed state tensor. This holds the conjugate "
51 "values to those being controlled";
52
53 options.set<VariableName>("fixed_values") = VariableName("forces", "fixed_values");
54 options.set("fixed_values").doc() = "The name of the fixed values, i.e. the actual strain or "
55 "stress values being imposed on the model";
56
57 options.set<VariableName>("cauchy_stress") = VariableName("state", "S");
58 options.set("cauchy_stress").doc() = "The name of the Cauchy stress tensor";
59
60 options.set<VariableName>("strain") = VariableName("forces", "E");
61 options.set("strain").doc() = "The name of the strain tensor";
62
63 return options;
64}
65
67 : Model(options),
68 _threshold(options.get<CrossRef<BatchTensor>>("threshold")),
69 _control(declare_input_variable<SR2>("control")),
70 _fixed_values(declare_input_variable<SR2>("fixed_values")),
71 _mixed_state(declare_input_variable<SR2>("mixed_state")),
72 _stress(declare_output_variable<SR2>("cauchy_stress")),
73 _strain(declare_output_variable<SR2>("strain"))
74{
75}
76
77void
79{
80 auto [dstrain, dstress] = make_operators(_control.tensor());
81
82 if (out)
83 {
84 // Even benign in place operations get errors
87 }
88
89 if (dout_din)
90 {
93
96 }
97
98 // All zero
100}
101
102std::pair<SSR4, SSR4>
103MixedControlSetup::make_operators(const SR2 & control) const
104{
107
108 // This also converts these to floats
109 auto ones_stress = BatchTensor(strain_select.to(_stress.tensor().options()), control.batch_dim());
111
112 // auto dstrain = SSR4(BatchTensor(torch::diag_embed(ones_stress), batch_dim()));
115
116 return {dstrain, dstress};
117}
118
119} // namespace neml2
static BatchTensor ones_like(const BatchTensor &other)
Unit tensor like another, i.e. same batch and base shapes, same tensor options, etc.
Definition BatchTensorBase.cxx:66
Definition BatchTensor.h:32
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
Definition MixedControlSetup.h:32
const BatchTensor _threshold
The threshold for the control signal.
Definition MixedControlSetup.h:47
const Variable< SR2 > & _control
Actual input control signal.
Definition MixedControlSetup.h:50
MixedControlSetup(const OptionSet &options)
Definition MixedControlSetup.cxx:66
const Variable< SR2 > & _mixed_state
Conjugate state containing the mixed, unknown stresses and strains.
Definition MixedControlSetup.h:55
Variable< SR2 > & _strain
Strain tensor to target.
Definition MixedControlSetup.h:60
static OptionSet expected_options()
Definition MixedControlSetup.cxx:33
Variable< SR2 > & _stress
Stress tensor to target.
Definition MixedControlSetup.h:58
const Variable< SR2 > & _fixed_values
Driving forces to pull the "controled" entries from.
Definition MixedControlSetup.h:53
void set_value(bool out, bool dout_din, bool d2out_din2) override
The map between input -> output, and optionally its derivatives.
Definition MixedControlSetup.cxx:78
The base class for all constitutive models.
Definition Model.h:53
const torch::TensorOptions & options() const
This model's tensor options.
Definition Model.h:116
static OptionSet expected_options()
Definition Model.cxx:33
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
The (logical) symmetric second order tensor.
Definition SR2.h:46
BatchTensor base_diag_embed(const BatchTensor &a, TorchSize offset, TorchSize d1, TorchSize d2)
Definition math.cxx:251
Definition CrossRef.cxx:32
LabeledAxisAccessor VariableName
Definition Variable.h:35