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/porous_flow/VanGenuchtenCapillaryPressure.h"
26 : #include "neml2/tensors/functions/clamp.h"
27 : #include "neml2/tensors/functions/pow.h"
28 : #include "neml2/tensors/functions/log10.h"
29 : #include "neml2/tensors/functions/where.h"
30 : #include "neml2/tensors/assertions.h"
31 :
32 : namespace neml2
33 : {
34 : register_NEML2_object(VanGenuchtenCapillaryPressure);
35 : OptionSet
36 2 : VanGenuchtenCapillaryPressure::expected_options()
37 : {
38 2 : OptionSet options = CapillaryPressure::expected_options();
39 2 : options.doc() +=
40 : " using the van Genuchten correlation for capillary pressure, taking the form of \\f$ "
41 : "a \\left( S_e^{-\\frac{1}{m}} - 1 \\right)^{1-m} \\f$. Here \\f$ S_e \\f$ is the "
42 2 : "effective saturation,\\f$ a \\f$ and \\f$ m \\f$ are shape parameters";
43 :
44 4 : options.set<bool>("define_second_derivatives") = true;
45 :
46 4 : options.set_parameter<TensorName<Scalar>>("a");
47 4 : options.set("a").doc() = "Shape parameter a";
48 :
49 4 : options.set_parameter<TensorName<Scalar>>("m");
50 2 : options.set("m").doc() = "Shape parameter m";
51 :
52 2 : return options;
53 0 : }
54 :
55 1 : VanGenuchtenCapillaryPressure::VanGenuchtenCapillaryPressure(const OptionSet & options)
56 : : CapillaryPressure(options),
57 3 : _a(declare_parameter<Scalar>("a", "a")),
58 5 : _m(declare_parameter<Scalar>("m", "m"))
59 : {
60 1 : }
61 :
62 : std::tuple<Scalar, Scalar, Scalar>
63 6 : VanGenuchtenCapillaryPressure::calculate_pressure(const Scalar & S,
64 : bool out,
65 : bool dout_din,
66 : bool d2out_din2) const
67 : {
68 6 : const auto eps = machine_precision(S.scalar_type()).toDouble();
69 6 : auto Sc = where(S > (1.0 - eps), Scalar::ones_like(S) - eps, S);
70 :
71 6 : auto f_s = _a * pow((pow(Sc, -1.0 / _m) - 1.0), 1 - _m);
72 6 : auto dfds_s = -_a / _m * (1 - _m) * pow(pow(Sc, -1 / _m) - 1, -_m) * pow(Sc, -1 / _m - 1);
73 12 : auto d2fds2_s = -_a * ((_m - 1) * (_m * pow(Sc, (1 / _m)) + pow(Sc, (1 / _m)) - 1)) /
74 12 : (_m * _m * pow(Sc, (1 / _m + 2)) * pow((1 / pow(Sc, (1 / _m)) - 1), _m) *
75 18 : (pow(Sc, (1 / _m)) - 1));
76 :
77 : return std::make_tuple(
78 12 : out ? f_s : Scalar(), dout_din ? dfds_s : Scalar(), d2out_din2 ? d2fds2_s : Scalar());
79 6 : }
80 : }
|