LCOV - code coverage report
Current view: top level - src/materials - MollifiedLangmuirMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose chemical_reactions: #31405 (292dce) with base fef103 Lines: 45 46 97.8 %
Date: 2025-09-04 07:52:33 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "MollifiedLangmuirMaterial.h"
      11             : 
      12             : registerMooseObject("ChemicalReactionsApp", MollifiedLangmuirMaterial);
      13             : 
      14             : InputParameters
      15         290 : MollifiedLangmuirMaterial::validParams()
      16             : {
      17         290 :   InputParameters params = Material::validParams();
      18             : 
      19         580 :   params.addRequiredCoupledVar(
      20             :       "one_over_desorption_time_const",
      21             :       "Time constant for Langmuir desorption (gas moving from matrix to porespace).  Units [s]");
      22         580 :   params.addRequiredCoupledVar(
      23             :       "one_over_adsorption_time_const",
      24             :       "Time constant for Langmuir adsorption (gas moving from porespace to matrix).  Units [s].");
      25         580 :   params.addRequiredParam<Real>("langmuir_density",
      26             :                                 "This is (Langmuir volume)*(density of gas at standard temp and "
      27             :                                 "pressure).  Langmuir volume is measured in (gas volume)/(matrix "
      28             :                                 "volume).  (Methane density(101kPa, 20degC) = 0.655kg/m^3.  "
      29             :                                 "Methane density(101kPa, 0degC) = 0.715kg/m^3.)  Units [kg/m^3]");
      30         580 :   params.addRequiredParam<Real>("langmuir_pressure", "Langmuir pressure.  Units Pa");
      31         580 :   params.addRequiredCoupledVar("conc_var", "The concentration of gas variable");
      32         580 :   params.addRequiredCoupledVar("pressure_var", "The gas porepressure variable");
      33         870 :   params.addRangeCheckedParam<Real>("mollifier",
      34         580 :                                     0.1,
      35             :                                     "mollifier > 0",
      36             :                                     "The reciprocal of time constants will be "
      37             :                                     "one_over_time_const*tanh( |conc_var - "
      38             :                                     "equilib_conc|/(mollifier*langmuir_density)).  So for "
      39             :                                     "mollifier very small you will get a stepchange between "
      40             :                                     "desorption and adsorption, but for mollifier bigger you "
      41             :                                     "will be a gradual change");
      42         290 :   params.addClassDescription("Material type that holds info regarding MollifiedLangmuir desorption "
      43             :                              "from matrix to porespace and viceversa");
      44         290 :   return params;
      45           0 : }
      46             : 
      47         231 : MollifiedLangmuirMaterial::MollifiedLangmuirMaterial(const InputParameters & parameters)
      48             :   : Material(parameters),
      49             :     // coupledValue returns a reference (an alias) to a VariableValue, and the & turns it into a
      50             :     // pointer
      51         231 :     _one_over_de_time_const(coupledValue("one_over_desorption_time_const")),
      52         231 :     _one_over_ad_time_const(coupledValue("one_over_adsorption_time_const")),
      53             : 
      54         462 :     _langmuir_dens(getParam<Real>("langmuir_density")),
      55         462 :     _langmuir_p(getParam<Real>("langmuir_pressure")),
      56             : 
      57         231 :     _conc(coupledValue("conc_var")),
      58         231 :     _pressure(coupledValue("pressure_var")),
      59             : 
      60         462 :     _mollifier(getParam<Real>("mollifier")),
      61             : 
      62         231 :     _mass_rate_from_matrix(declareProperty<Real>("mass_rate_from_matrix")),
      63         231 :     _dmass_rate_from_matrix_dC(declareProperty<Real>("dmass_rate_from_matrix_dC")),
      64         462 :     _dmass_rate_from_matrix_dp(declareProperty<Real>("dmass_rate_from_matrix_dp"))
      65             : {
      66         231 : }
      67             : 
      68             : void
      69       19250 : MollifiedLangmuirMaterial::computeQpProperties()
      70             : {
      71       19250 :   Real equilib_conc = _langmuir_dens * (_pressure[_qp]) / (_langmuir_p + _pressure[_qp]);
      72             :   Real dequilib_conc_dp =
      73       19250 :       _langmuir_dens / (_langmuir_p + _pressure[_qp]) -
      74       19250 :       _langmuir_dens * (_pressure[_qp]) / std::pow(_langmuir_p + _pressure[_qp], 2);
      75             : 
      76       19250 :   Real mol = std::tanh(std::abs(_conc[_qp] - equilib_conc) / (_mollifier * _langmuir_dens));
      77             :   Real deriv_tanh =
      78       19250 :       1 - std::pow(std::tanh((_conc[_qp] - equilib_conc) / (_mollifier * _langmuir_dens)), 2);
      79       19250 :   if (_conc[_qp] < equilib_conc)
      80         538 :     deriv_tanh *= -1;
      81       19250 :   Real dmol_dC = deriv_tanh / (_mollifier * _langmuir_dens);
      82       19250 :   Real dmol_dp = -dmol_dC * dequilib_conc_dp;
      83             : 
      84             :   /*
      85             :   Real de_plus_ad = _one_over_de_time_const[_qp] + _one_over_ad_time_const[_qp];
      86             :   Real de_minus_ad = _one_over_de_time_const[_qp] - _one_over_ad_time_const[_qp];
      87             : 
      88             :   Real one_over_tau = 0.5*de_plus_ad + 0.5*de_minus_ad*std::tanh( (_conc[_qp] -
      89             :   equilib_conc)/(_mollifier*_langmuir_dens));
      90             :   Real deriv_tanh = 1 - std::pow(std::tanh((_conc[_qp] -
      91             :   equilib_conc)/(_mollifier*_langmuir_dens)), 2);
      92             :   Real d_one_over_tau_dC = 0.5*de_minus_ad*deriv_tanh/(_mollifier*_langmuir_dens);
      93             :   Real d_one_over_tau_dp = -0.5*de_minus_ad*dequilib_conc_dp*deriv_tanh/(_mollifier*_langmuir_dens);
      94             :   */
      95             : 
      96             :   // form the base rate and derivs without the appropriate time const
      97       19250 :   _mass_rate_from_matrix[_qp] = (_conc[_qp] - equilib_conc) * mol;
      98       19250 :   _dmass_rate_from_matrix_dC[_qp] = mol + (_conc[_qp] - equilib_conc) * dmol_dC;
      99       19250 :   _dmass_rate_from_matrix_dp[_qp] = -dequilib_conc_dp * mol + (_conc[_qp] - equilib_conc) * dmol_dp;
     100             : 
     101             :   // multiply by the appropriate time const
     102       19250 :   if (_conc[_qp] > equilib_conc)
     103             :   {
     104       18712 :     _mass_rate_from_matrix[_qp] *= _one_over_de_time_const[_qp];
     105       18712 :     _dmass_rate_from_matrix_dC[_qp] *= _one_over_de_time_const[_qp];
     106       18712 :     _dmass_rate_from_matrix_dp[_qp] *= _one_over_de_time_const[_qp];
     107             :   }
     108             :   else
     109             :   {
     110         538 :     _mass_rate_from_matrix[_qp] *= _one_over_ad_time_const[_qp];
     111         538 :     _dmass_rate_from_matrix_dC[_qp] *= _one_over_ad_time_const[_qp];
     112         538 :     _dmass_rate_from_matrix_dp[_qp] *= _one_over_ad_time_const[_qp];
     113             :   }
     114       19250 : }

Generated by: LCOV version 1.14