NEML2 1.4.0
Loading...
Searching...
No Matches
ResolvedShear.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/crystal_plasticity/ResolvedShear.h"
26#include "neml2/models/crystallography/CrystalGeometry.h"
27
28#include "neml2/tensors/tensors.h"
29#include "neml2/tensors/list_tensors.h"
30
31namespace neml2
32{
33register_NEML2_object(ResolvedShear);
34
37{
39
40 options.doc() = "Calculates the resolved shears as \\f$ \\tau_i = \\sigma : Q "
41 "\\operatorname{sym}\\left(d_i \\otimes n_i \\right) Q^T \\f$ where \\f$ \\tau_i "
42 "\\f$ is the resolved shear on slip system i, \\f$ \\sigma \\f$ is the Cauchy "
43 "stress \\f$ Q \\f$ is the orientation matrix, \\f$ d_i \\f$ is the slip "
44 "direction, and \\f$ n_i \\f$ is the slip system normal.";
45
46 options.set<VariableName>("resolved_shears") =
47 VariableName("state", "internal", "resolved_shears");
48 options.set("resolved_shears").doc() = "The name of the resolved shears";
49
50 options.set<VariableName>("stress") = VariableName("state", "internal", "cauchy_stress");
51 options.set("stress").doc() = "The name of the Cauchy stress tensor";
52
53 options.set<VariableName>("orientation") = VariableName("state", "orientation_matrix");
54 options.set("orientation").doc() = "The name of the orientation matrix";
55
56 options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
57 options.set("crystal_geometry_name").doc() =
58 "The name of the data object with the crystallographic information";
59 return options;
60}
61
63 : Model(options),
64 _crystal_geometry(register_data<crystallography::CrystalGeometry>(
65 options.get<std::string>("crystal_geometry_name"))),
66 _rss(declare_output_variable_list<Scalar>(_crystal_geometry.nslip(), "resolved_shears")),
67 _S(declare_input_variable<SR2>("stress")),
68 _R(declare_input_variable<R2>("orientation"))
69{
70}
71
72void
74{
75 neml_assert_dbg(!d2out_din2, "Second derivative not implemented.");
76
77 const auto S = SR2(_S).list_unsqueeze();
78 const auto R = R2(_R).list_unsqueeze();
79
80 if (out)
81 _rss = BatchTensor(_crystal_geometry.M().rotate(R).inner(S), batch_dim());
82
83 if (dout_din)
84 {
85 _rss.d(_S) = BatchTensor(_crystal_geometry.M().rotate(R), batch_dim());
86 _rss.d(_R) =
87 BatchTensor(SR2(_crystal_geometry.M().drotate(R).movedim(-3, -1))
88 .inner(SR2(_S).batch_unsqueeze(-1).batch_unsqueeze(-1).batch_unsqueeze(-1)),
89 batch_dim());
90 }
91}
92
93} // namespace neml2
Derived list_unsqueeze() const
Unsqueeze on the special list batch dimension.
Definition BatchTensorBase.cxx:275
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
The base class for all constitutive models.
Definition Model.h:53
TorchSize batch_dim() const
This model's batch dim.
Definition Model.h:110
const torch::TensorOptions & options() const
This model's tensor options.
Definition Model.h:116
static OptionSet expected_options()
Definition Model.cxx:32
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
A basic R2.
Definition R2.h:42
Calculate the resolved shears.
Definition ResolvedShear.h:38
const Variable< R2 > & _R
Orientation.
Definition ResolvedShear.h:58
const Variable< SR2 > & _S
Stress.
Definition ResolvedShear.h:55
Variable< BatchTensor > & _rss
Resolved shear stresses.
Definition ResolvedShear.h:52
const crystallography::CrystalGeometry & _crystal_geometry
Crystal geometry class with slip geometry.
Definition ResolvedShear.h:49
ResolvedShear(const OptionSet &options)
Definition ResolvedShear.cxx:62
static OptionSet expected_options()
Definition ResolvedShear.cxx:36
void set_value(bool out, bool dout_din, bool d2out_din2) override
Set the resolved shears and associated derivatives.
Definition ResolvedShear.cxx:73
The (logical) symmetric second order tensor.
Definition SR2.h:46
Scalar inner(const SR2 &other) const
Double contraction ij,ij.
Definition SR2.cxx:186
The (logical) scalar.
Definition Scalar.h:38
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
LabeledAxisAccessor VariableName
Definition Variable.h:35