LCOV - code coverage report
Current view: top level - models/chemical_reactions - DiffusionLimitedReaction.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.8 % 46 45
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/chemical_reactions/DiffusionLimitedReaction.h"
      26              : #include "neml2/misc/assertions.h"
      27              : 
      28              : namespace neml2
      29              : {
      30              : register_NEML2_object(DiffusionLimitedReaction);
      31              : 
      32              : OptionSet
      33            2 : DiffusionLimitedReaction::expected_options()
      34              : {
      35            2 :   OptionSet options = Model::expected_options();
      36            2 :   options.doc() = "Calculate the void fraction rate of change";
      37              : 
      38            6 :   options.set_input("product_inner_radius") = VariableName{"state", "ri"};
      39            2 :   options.set("product_inner_radius").doc() = "Inner radius of the product phase";
      40            6 :   options.set_input("solid_inner_radius") = VariableName{"state", "ro"};
      41            4 :   options.set("solid_inner_radius").doc() = "Inner raidus of the solid phase";
      42            4 :   options.set<double>("product_dummy_thickness") = 0.01;
      43            2 :   options.set("product_dummy_thickness").doc() = "Minimum product thickness to avoid division by 0";
      44              : 
      45            6 :   options.set_input("liquid_reactivity") = VariableName{"state", "R_l"};
      46            2 :   options.set("liquid_reactivity").doc() = "Reactivity of the liquid phase, between 0 and 1";
      47            6 :   options.set_input("solid_reactivity") = VariableName{"state", "R_s"};
      48            2 :   options.set("solid_reactivity").doc() = "Reactivity of the solid phase, between 0 and 1";
      49              : 
      50            6 :   options.set_output("reaction_rate") = VariableName{"state", "alpha_rate"};
      51            4 :   options.set("reaction_rate").doc() = "Product phase substance (mol/V) rate of change";
      52              : 
      53            4 :   options.set_parameter<TensorName<Scalar>>("diffusion_coefficient");
      54            6 :   options.set("diffusion_coefficient").doc() =
      55            2 :       "Diffusion coefficient of the rate-limiting species in the product phase";
      56              : 
      57            4 :   options.set<double>("molar_volume");
      58            2 :   options.set("molar_volume").doc() = "Molar volume of the rate-limiting (liquid) species";
      59              : 
      60            2 :   return options;
      61            0 : }
      62              : 
      63            1 : DiffusionLimitedReaction::DiffusionLimitedReaction(const OptionSet & options)
      64              :   : Model(options),
      65            1 :     _ri(declare_input_variable<Scalar>("product_inner_radius")),
      66            1 :     _ro(declare_input_variable<Scalar>("solid_inner_radius")),
      67            1 :     _delta(options.get<double>("product_dummy_thickness")),
      68            1 :     _R_l(declare_input_variable<Scalar>("liquid_reactivity")),
      69            1 :     _R_s(declare_input_variable<Scalar>("solid_reactivity")),
      70            1 :     _rate(declare_output_variable<Scalar>("reaction_rate")),
      71            5 :     _D(declare_parameter<Scalar>("D", "diffusion_coefficient")),
      72            2 :     _omega(options.get<double>("molar_volume"))
      73              : {
      74            1 : }
      75              : 
      76              : void
      77            2 : DiffusionLimitedReaction::set_value(bool out, bool dout_din, bool d2out_din2)
      78              : {
      79            2 :   neml_assert_dbg(!d2out_din2, "Second derivatives not implemented");
      80              : 
      81            2 :   const auto factor = 2 * _D * _R_l * _R_s / _omega;
      82            2 :   const auto ratio = _ro / (_ro - _ri + _delta);
      83              : 
      84            2 :   if (out)
      85              :   {
      86            1 :     _rate = factor * ratio;
      87              :   }
      88              : 
      89            2 :   if (dout_din)
      90              :   {
      91            1 :     const auto drate = factor / (_ro - _ri + _delta) / (_ro - _ri + _delta);
      92              : 
      93            1 :     _rate.d(_ri) = drate * _ro;
      94            1 :     _rate.d(_ro) = drate * (-_ri + _delta);
      95            1 :     _rate.d(_R_l) = 2 * _D * _R_s / _omega * ratio;
      96            1 :     _rate.d(_R_s) = 2 * _D * _R_l / _omega * ratio;
      97            1 :   }
      98            2 : }
      99              : } // namespace neml2
        

Generated by: LCOV version 2.0-1