LCOV - code coverage report
Current view: top level - models/porous_flow - AdvectiveStress.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.3 % 37 36
Test Date: 2025-06-29 01:25:44 Functions: 100.0 % 3 3

            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/AdvectiveStress.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : #include "neml2/tensors/R2.h"
      28              : 
      29              : namespace neml2
      30              : {
      31              : register_NEML2_object(AdvectiveStress);
      32              : OptionSet
      33            2 : AdvectiveStress::expected_options()
      34              : {
      35            2 :   OptionSet options = Model::expected_options();
      36            2 :   options.doc() =
      37              :       "Calculate the advective stress, \\f$ p_s \\f$, taking the form of \\f$ p_s = \\frac{c}{3J} "
      38              :       "P_{ij}F_{ij} \\f$. Here, \\f$ J, P, F \\f$ are the the deformation gradient Jacobian, the "
      39              :       "1st Piola-Kirchhoff stress and the defomration gradient. \\f$ c \\f$ is the volume change "
      40            2 :       "coefficient.";
      41              : 
      42            4 :   options.set_parameter<TensorName<Scalar>>("coefficient");
      43            2 :   options.set("coefficient").doc() = "Coefficient c";
      44              : 
      45            6 :   options.set_input("jacobian") = VariableName(STATE, "J");
      46            4 :   options.set("jacobian").doc() =
      47            2 :       "The Jacobian of the deformation gradient associated with the volume change";
      48              : 
      49            6 :   options.set_input("deformation_gradient") = VariableName(FORCES, "F");
      50            2 :   options.set("deformation_gradient").doc() = "The deformation gradient";
      51              : 
      52            6 :   options.set_input("pk1_stress") = VariableName(STATE, "P");
      53            2 :   options.set("pk1_stress").doc() = "1st Piola-Kirchhoff stress";
      54              : 
      55            6 :   options.set_output("advective_stress") = VariableName(STATE, "advective_stress");
      56            2 :   options.set("advective_stress").doc() = "The average advective stress";
      57              : 
      58            2 :   return options;
      59            0 : }
      60              : 
      61            1 : AdvectiveStress::AdvectiveStress(const OptionSet & options)
      62              :   : Model(options),
      63            3 :     _coeff(declare_parameter<Scalar>("coeff", "coefficient")),
      64            1 :     _J(declare_input_variable<Scalar>("jacobian")),
      65            1 :     _P(declare_input_variable<R2>("pk1_stress")),
      66            1 :     _F(declare_input_variable<R2>("deformation_gradient")),
      67            2 :     _ps(declare_output_variable<Scalar>("advective_stress"))
      68              : {
      69            1 : }
      70              : 
      71              : void
      72            2 : AdvectiveStress::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      73              : {
      74            2 :   if (out)
      75              :   {
      76            1 :     _ps = _coeff / 3.0 / _J * R2(_P).inner(R2(_F));
      77              :   }
      78              : 
      79            2 :   if (dout_din)
      80              :   {
      81            1 :     const auto I = R2::identity(_J.options());
      82              : 
      83            1 :     if (_J.is_dependent())
      84            1 :       _ps.d(_J) = -_coeff / 3.0 / (_J * _J) * R2(_P).inner(R2(_F));
      85              : 
      86            1 :     if (_P.is_dependent())
      87            1 :       _ps.d(_P) = _coeff / 3.0 / _J * _F;
      88              : 
      89            1 :     if (_F.is_dependent())
      90            1 :       _ps.d(_F) = _coeff / 3.0 / _J * _P;
      91            1 :   }
      92            2 : }
      93              : } // namespace neml2
        

Generated by: LCOV version 2.0-1