LCOV - code coverage report
Current view: top level - models/porous_flow - EffectiveSaturation.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.6 % 29 28
Test Date: 2025-10-02 16:03:03 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/EffectiveSaturation.h"
      26              : 
      27              : namespace neml2
      28              : {
      29              : register_NEML2_object(EffectiveSaturation);
      30              : OptionSet
      31            2 : EffectiveSaturation::expected_options()
      32              : {
      33            2 :   OptionSet options = Model::expected_options();
      34            2 :   options.doc() =
      35              :       "Calculate the effective saturation, taking the form of \\f$ S = "
      36              :       "\\frac{\\frac{\\phi}{\\phi_\\mathrm{max}} - S_r}{1-S_r} \\f$ where \\f$ \\phi \\f$ is the "
      37              :       "volume fraction of the flowing fluid, \\f$ \\phi_\\mathrm{max} \\f$ is the maximum "
      38            2 :       "allowable volume fraction and \\f$ S_r \\f$ is the residual saturation.";
      39              : 
      40            8 :   options.set_parameter<TensorName<Scalar>>("residual_saturation") = "0";
      41            2 :   options.set("residual_saturation").doc() = "Liquid's residual volume fraction";
      42              : 
      43            6 :   options.set_input("fluid_fraction") = VariableName(FORCES, "fluid_fraction");
      44            4 :   options.set("fluid_fraction").doc() = "Volume fraction of the fluid";
      45              : 
      46            8 :   options.set_parameter<TensorName<Scalar>>("max_fraction") = "1";
      47            2 :   options.set("max_fraction").doc() = "Maximum allowable volume fraction of the fluid";
      48              : 
      49            6 :   options.set_output("effective_saturation") = VariableName(STATE, "effective_saturation");
      50            2 :   options.set("effective_saturation").doc() = "Effective saturation";
      51              : 
      52            2 :   return options;
      53            0 : }
      54              : 
      55            1 : EffectiveSaturation::EffectiveSaturation(const OptionSet & options)
      56              :   : Model(options),
      57            3 :     _Sr(declare_parameter<Scalar>("Sr", "residual_saturation")),
      58            1 :     _phi(declare_input_variable<Scalar>("fluid_fraction")),
      59            4 :     _phimax(declare_parameter<Scalar>("phi_max", "max_fraction", /*allow_nonlinear=*/true)),
      60            2 :     _S(declare_output_variable<Scalar>("effective_saturation"))
      61              : {
      62            1 : }
      63              : 
      64              : void
      65            2 : EffectiveSaturation::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      66              : {
      67            2 :   if (out)
      68              :   {
      69            2 :     _S = (_phi / _phimax - _Sr) / (1.0 - _Sr);
      70              :   }
      71              : 
      72            2 :   if (dout_din)
      73              :   {
      74            1 :     if (_phi.is_dependent())
      75            1 :       _S.d(_phi) = 1.0 / (_phimax * (1 - _Sr));
      76              : 
      77            3 :     if (const auto * const phimax = nl_param("phi_max"))
      78            1 :       _S.d(*phimax) = -_phi / (_phimax * _phimax * (1 - _Sr));
      79              :   }
      80            2 : }
      81              : }
        

Generated by: LCOV version 2.0-1