LCOV - code coverage report
Current view: top level - src/kernels - PorousFlowMassVolumetricExpansion.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 72 75 96.0 %
Date: 2017-11-18 13:30:36 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************/
       2             : /* MOOSE - Multiphysics Object Oriented Simulation Environment  */
       3             : /*                                                              */
       4             : /*          All contents are licensed under LGPL V2.1           */
       5             : /*             See LICENSE for full restrictions                */
       6             : /****************************************************************/
       7             : 
       8             : #include "PorousFlowMassVolumetricExpansion.h"
       9             : 
      10             : // MOOSE includes
      11             : #include "MooseVariable.h"
      12             : 
      13             : template <>
      14             : InputParameters
      15          19 : validParams<PorousFlowMassVolumetricExpansion>()
      16             : {
      17          19 :   InputParameters params = validParams<TimeKernel>();
      18          57 :   params.addParam<bool>("strain_at_nearest_qp",
      19             :                         false,
      20             :                         "When calculating nodal porosity that depends on strain, use the strain at "
      21             :                         "the nearest quadpoint.  This adds a small extra computational burden, and "
      22             :                         "is not necessary for simulations involving only linear lagrange elements. "
      23             :                         " If you set this to true, you will also want to set the same parameter to "
      24          19 :                         "true for related Kernels and Materials");
      25          57 :   params.addParam<unsigned int>(
      26          19 :       "fluid_component", 0, "The index corresponding to the component for this kernel");
      27          57 :   params.addRequiredParam<UserObjectName>(
      28          19 :       "PorousFlowDictator", "The UserObject that holds the list of Porous-Flow variable names.");
      29          38 :   params.addClassDescription("Component_mass*rate_of_solid_volumetric_expansion");
      30          19 :   return params;
      31             : }
      32             : 
      33          19 : PorousFlowMassVolumetricExpansion::PorousFlowMassVolumetricExpansion(
      34          19 :     const InputParameters & parameters)
      35             :   : TimeKernel(parameters),
      36          57 :     _fluid_component(getParam<unsigned int>("fluid_component")),
      37          38 :     _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
      38          19 :     _var_is_porflow_var(!_dictator.notPorousFlowVariable(_var.number())),
      39          57 :     _strain_at_nearest_qp(getParam<bool>("strain_at_nearest_qp")),
      40          38 :     _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
      41          38 :     _dporosity_dvar(getMaterialProperty<std::vector<Real>>("dPorousFlow_porosity_nodal_dvar")),
      42             :     _dporosity_dgradvar(
      43          38 :         getMaterialProperty<std::vector<RealGradient>>("dPorousFlow_porosity_nodal_dgradvar")),
      44          19 :     _nearest_qp(_strain_at_nearest_qp
      45          38 :                     ? &getMaterialProperty<unsigned int>("PorousFlow_nearestqp_nodal")
      46             :                     : nullptr),
      47          38 :     _fluid_density(getMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")),
      48             :     _dfluid_density_dvar(getMaterialProperty<std::vector<std::vector<Real>>>(
      49          38 :         "dPorousFlow_fluid_phase_density_nodal_dvar")),
      50          38 :     _fluid_saturation(getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")),
      51             :     _dfluid_saturation_dvar(
      52          38 :         getMaterialProperty<std::vector<std::vector<Real>>>("dPorousFlow_saturation_nodal_dvar")),
      53          38 :     _mass_frac(getMaterialProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")),
      54             :     _dmass_frac_dvar(getMaterialProperty<std::vector<std::vector<std::vector<Real>>>>(
      55          38 :         "dPorousFlow_mass_frac_nodal_dvar")),
      56          38 :     _strain_rate_qp(getMaterialProperty<Real>("PorousFlow_volumetric_strain_rate_qp")),
      57             :     _dstrain_rate_qp_dvar(getMaterialProperty<std::vector<RealGradient>>(
      58         342 :         "dPorousFlow_volumetric_strain_rate_qp_dvar"))
      59             : {
      60          19 :   if (_fluid_component >= _dictator.numComponents())
      61           0 :     mooseError("The Dictator proclaims that the number of components in this simulation is ",
      62           0 :                _dictator.numComponents(),
      63             :                " whereas you have used the Kernel PorousFlowComponetMassVolumetricExpansion with "
      64             :                "component = ",
      65             :                _fluid_component,
      66           0 :                ".  The Dictator is watching you");
      67          19 : }
      68             : 
      69             : Real
      70     1330688 : PorousFlowMassVolumetricExpansion::computeQpResidual()
      71             : {
      72             :   mooseAssert(_fluid_component < _mass_frac[_i][0].size(),
      73             :               "PorousFlowMassVolumetricExpansion: fluid_component is given as "
      74             :                   << _fluid_component
      75             :                   << " which must be less than the number of fluid components described by the "
      76             :                      "mass-fraction matrix, which is "
      77             :                   << _mass_frac[_i][0].size());
      78     2661376 :   unsigned int num_phases = _fluid_density[_i].size();
      79             :   mooseAssert(num_phases == _fluid_saturation[_i].size(),
      80             :               "PorousFlowMassVolumetricExpansion: Size of fluid density = "
      81             :                   << num_phases
      82             :                   << " size of fluid saturation = "
      83             :                   << _fluid_saturation[_i].size()
      84             :                   << " but both these must be equal to the number of phases in the system");
      85             : 
      86             :   Real mass = 0.0;
      87     3992064 :   for (unsigned ph = 0; ph < num_phases; ++ph)
      88     1330688 :     mass +=
      89     5322752 :         _fluid_density[_i][ph] * _fluid_saturation[_i][ph] * _mass_frac[_i][ph][_fluid_component];
      90             : 
      91     5322752 :   return _test[_i][_qp] * mass * _porosity[_i] * _strain_rate_qp[_qp];
      92             : }
      93             : 
      94             : Real
      95     5968384 : PorousFlowMassVolumetricExpansion::computeQpJacobian()
      96             : {
      97     5968384 :   return computedMassQpJac(_var.number()) + computedVolQpJac(_var.number());
      98             : }
      99             : 
     100             : Real
     101    17943744 : PorousFlowMassVolumetricExpansion::computeQpOffDiagJacobian(unsigned int jvar)
     102             : {
     103    17943744 :   return computedMassQpJac(jvar) + computedVolQpJac(jvar);
     104             : }
     105             : 
     106             : Real
     107    23912128 : PorousFlowMassVolumetricExpansion::computedVolQpJac(unsigned int jvar) const
     108             : {
     109    23912128 :   if (_dictator.notPorousFlowVariable(jvar))
     110             :     return 0.0;
     111             : 
     112    23912128 :   const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
     113             : 
     114    47824256 :   unsigned int num_phases = _fluid_density[_i].size();
     115             :   Real mass = 0.0;
     116    71736384 :   for (unsigned ph = 0; ph < num_phases; ++ph)
     117    23912128 :     mass +=
     118    95648512 :         _fluid_density[_i][ph] * _fluid_saturation[_i][ph] * _mass_frac[_i][ph][_fluid_component];
     119             : 
     120    47824256 :   Real dvol = _dstrain_rate_qp_dvar[_qp][pvar] * _grad_phi[_j][_qp];
     121             : 
     122    71736384 :   return _test[_i][_qp] * mass * _porosity[_i] * dvol;
     123             : }
     124             : Real
     125    23912128 : PorousFlowMassVolumetricExpansion::computedMassQpJac(unsigned int jvar) const
     126             : {
     127    23912128 :   if (_dictator.notPorousFlowVariable(jvar))
     128             :     return 0.0;
     129             : 
     130    23912128 :   const unsigned int pvar = _dictator.porousFlowVariableNum(jvar);
     131    23912128 :   const unsigned nearest_qp = (_strain_at_nearest_qp ? (*_nearest_qp)[_i] : _i);
     132             : 
     133    47824256 :   const unsigned int num_phases = _fluid_density[_i].size();
     134             :   Real dmass = 0.0;
     135    71736384 :   for (unsigned ph = 0; ph < num_phases; ++ph)
     136    95648512 :     dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
     137    71736384 :              _mass_frac[_i][ph][_fluid_component] * _dporosity_dgradvar[_i][pvar] *
     138    23912128 :              _grad_phi[_j][nearest_qp];
     139             : 
     140    23912128 :   if (_i != _j)
     141    62769336 :     return _test[_i][_qp] * dmass * _strain_rate_qp[_qp];
     142             : 
     143     8967048 :   for (unsigned ph = 0; ph < num_phases; ++ph)
     144             :   {
     145    14945080 :     dmass += _dfluid_density_dvar[_i][ph][pvar] * _fluid_saturation[_i][ph] *
     146     8967048 :              _mass_frac[_i][ph][_fluid_component] * _porosity[_i];
     147     8967048 :     dmass += _fluid_density[_i][ph] * _dfluid_saturation_dvar[_i][ph][pvar] *
     148     2989016 :              _mass_frac[_i][ph][_fluid_component] * _porosity[_i];
     149     8967048 :     dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
     150     5978032 :              _dmass_frac_dvar[_i][ph][_fluid_component][pvar] * _porosity[_i];
     151     5978032 :     dmass += _fluid_density[_i][ph] * _fluid_saturation[_i][ph] *
     152     5978032 :              _mass_frac[_i][ph][_fluid_component] * _dporosity_dvar[_i][pvar];
     153             :   }
     154             : 
     155     8967048 :   return _test[_i][_qp] * dmass * _strain_rate_qp[_qp];
     156        2499 : }

Generated by: LCOV version 1.11