Line data Source code
1 : // Copyright 2024, 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/chemical_reactions/CylindricalChannelGeometry.h"
26 : #include "neml2/tensors/functions/sqrt.h"
27 : #include "neml2/tensors/functions/clamp.h"
28 : #include "neml2/tensors/functions/where.h"
29 : #include "neml2/misc/assertions.h"
30 :
31 : namespace neml2
32 : {
33 : register_NEML2_object(CylindricalChannelGeometry);
34 :
35 : OptionSet
36 2 : CylindricalChannelGeometry::expected_options()
37 : {
38 2 : OptionSet options = Model::expected_options();
39 2 : options.doc() = "Calculate the dimensionless inner and outer radii of the reaction product";
40 :
41 6 : options.set_input("solid_fraction") = VariableName{"state", "phi_s"};
42 2 : options.set("solid_fraction").doc() = "Volume fraction of the solid phase";
43 6 : options.set_input("product_fraction") = VariableName{"state", "phi_p"};
44 2 : options.set("product_fraction").doc() = "Volume fraction of the product phase";
45 :
46 6 : options.set_output("inner_radius") = VariableName{"state", "ri"};
47 2 : options.set("inner_radius").doc() = "Dimensionless inner radius of the product phase";
48 6 : options.set_output("outer_radius") = VariableName{"state", "ro"};
49 2 : options.set("outer_radius").doc() = "Dimensionless outer radius of the product phase";
50 :
51 2 : return options;
52 0 : }
53 :
54 1 : CylindricalChannelGeometry::CylindricalChannelGeometry(const OptionSet & options)
55 : : Model(options),
56 1 : _phi_s(declare_input_variable<Scalar>("solid_fraction")),
57 1 : _phi_p(declare_input_variable<Scalar>("product_fraction")),
58 1 : _ri(declare_output_variable<Scalar>("inner_radius")),
59 2 : _ro(declare_output_variable<Scalar>("outer_radius"))
60 : {
61 1 : }
62 :
63 : void
64 2 : CylindricalChannelGeometry::set_value(bool out, bool dout_din, bool d2out_din2)
65 : {
66 2 : neml_assert_dbg(!d2out_din2, "Second derivatives not implemented");
67 2 : neml_assert_dbg(_phi_s.scalar_type() == _phi_p.scalar_type(),
68 : "Solid and product fractions must have the same scalar type");
69 :
70 2 : const auto eps = machine_precision(_phi_s.scalar_type()).toDouble();
71 2 : const auto cap = 1 - _phi_s - _phi_p;
72 2 : const auto ri = sqrt(clamp(cap, eps, 1.0 - eps));
73 2 : const auto ro = sqrt(1 - _phi_s);
74 :
75 2 : if (out)
76 : {
77 1 : _ri = ri;
78 1 : _ro = ro;
79 : }
80 :
81 2 : if (dout_din)
82 : {
83 1 : _ri.d(_phi_s) = where(cap <= eps, Scalar::zeros_like(ri), -0.5 / ri);
84 1 : _ri.d(_phi_p) = where(cap <= eps, Scalar::zeros_like(ri), -0.5 / ri);
85 1 : _ro.d(_phi_s) = -0.5 / ro;
86 : }
87 2 : }
88 : } // namespace neml2
|