NEML2 1.4.0
Loading...
Searching...
No Matches
PlasticDeformationRate.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/PlasticDeformationRate.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(PlasticDeformationRate);
34
37{
39
40 options.doc() = "Caclulates the plastic deformation rate as \\f$ d^p = \\sum_{i=1}^{n_{slip}} "
41 "\\dot{\\gamma}_i Q \\operatorname{sym}{\\left(d_i \\otimes n_i \\right)} Q^T "
42 "\\f$ with \\f$ d^p \\f$ the plastic deformation rate, \\f$ \\dot{\\gamma}_i "
43 "\\f$ the slip rate on the ith slip system, \\f$Q \\f$ the orientation, \\f$ d_i "
44 "\\f$ the slip system direction, and \\f$ n_i \\f$ the slip system normal.";
45
46 options.set<VariableName>("plastic_deformation_rate") =
47 VariableName("state", "internal", "plastic_deformation_rate");
48 options.set("plastic_deformation_rate").doc() = "The name of the plastic deformation rate tensor";
49
50 options.set<VariableName>("orientation") = VariableName("state", "orientation_matrix");
51 options.set("orientation").doc() = "The name of the orientation matrix tensor";
52
53 options.set<VariableName>("slip_rates") = VariableName("state", "internal", "slip_rates");
54 options.set("slip_rates").doc() = "The name of the tensor containg the current slip rates";
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 containing the crystallographic information for the material";
59
60 return options;
61}
62
64 : Model(options),
65 _crystal_geometry(register_data<crystallography::CrystalGeometry>(
66 options.get<std::string>("crystal_geometry_name"))),
67 _dp(declare_output_variable<SR2>("plastic_deformation_rate")),
68 _R(declare_input_variable<R2>("orientation")),
69 _g(declare_input_variable_list<Scalar>(_crystal_geometry.nslip(), "slip_rates"))
70{
71}
72
73void
75{
76 neml_assert_dbg(!d2out_din2, "Second derivative not implemented.");
77
78 // Grab the input
79 const auto g = Scalar(_g, batch_dim() + 1);
80 const auto dp_crystal = (g * _crystal_geometry.M()).list_sum();
81
82 if (out)
83 _dp = dp_crystal.rotate(R2(_R));
84
85 if (dout_din)
86 {
87 _dp.d(_g) = BatchTensor(_crystal_geometry.M().rotate(R2(_R).batch_unsqueeze(-1)), batch_dim())
88 .base_transpose(-2, -1);
89 _dp.d(_R) = dp_crystal.drotate(R2(_R));
90 }
91}
92} // namespace neml2
BatchTensor base_transpose(TorchSize d1, TorchSize d2) const
Transpose two base dimensions.
Definition BatchTensorBase.cxx:299
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:33
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Plastic deformation rate with the default kinetics.
Definition PlasticDeformationRate.h:38
const Variable< R2 > & _R
Current orientation.
Definition PlasticDeformationRate.h:55
Variable< SR2 > & _dp
Plastic deformation rate.
Definition PlasticDeformationRate.h:52
const Variable< BatchTensor > & _g
Slip rates.
Definition PlasticDeformationRate.h:58
const crystallography::CrystalGeometry & _crystal_geometry
Crystal geometry class with slip geometry.
Definition PlasticDeformationRate.h:49
PlasticDeformationRate(const OptionSet &options)
Definition PlasticDeformationRate.cxx:63
static OptionSet expected_options()
Definition PlasticDeformationRate.cxx:36
void set_value(bool out, bool dout_din, bool d2out_din2) override
Set the plastic deformation rate and derivatives.
Definition PlasticDeformationRate.cxx:74
A basic R2.
Definition R2.h:42
The (logical) symmetric second order tensor.
Definition SR2.h:46
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