LCOV - code coverage report
Current view: top level - src/kernels - PorousFlowEnergyTimeDerivative.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 82 82 100.0 %
Date: 2017-11-21 14:47:27 Functions: 8 8 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 "PorousFlowEnergyTimeDerivative.h"
       9             : 
      10             : // MOOSE includes
      11             : #include "MooseVariable.h"
      12             : 
      13             : template <>
      14             : InputParameters
      15          19 : validParams<PorousFlowEnergyTimeDerivative>()
      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.addRequiredParam<UserObjectName>(
      26          19 :       "PorousFlowDictator", "The UserObject that holds the list of Porous-Flow variable names.");
      27          38 :   params.addClassDescription("Derivative of heat-energy-density wrt time");
      28          19 :   return params;
      29             : }
      30             : 
      31          19 : PorousFlowEnergyTimeDerivative::PorousFlowEnergyTimeDerivative(const InputParameters & parameters)
      32             :   : TimeKernel(parameters),
      33          38 :     _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
      34          19 :     _var_is_porflow_var(_dictator.isPorousFlowVariable(_var.number())),
      35          19 :     _num_phases(_dictator.numPhases()),
      36          19 :     _fluid_present(_num_phases > 0),
      37          57 :     _strain_at_nearest_qp(getParam<bool>("strain_at_nearest_qp")),
      38          38 :     _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
      39          38 :     _porosity_old(getMaterialPropertyOld<Real>("PorousFlow_porosity_nodal")),
      40          38 :     _dporosity_dvar(getMaterialProperty<std::vector<Real>>("dPorousFlow_porosity_nodal_dvar")),
      41             :     _dporosity_dgradvar(
      42          38 :         getMaterialProperty<std::vector<RealGradient>>("dPorousFlow_porosity_nodal_dgradvar")),
      43          19 :     _nearest_qp(_strain_at_nearest_qp
      44          38 :                     ? &getMaterialProperty<unsigned int>("PorousFlow_nearestqp_nodal")
      45             :                     : nullptr),
      46          38 :     _rock_energy_nodal(getMaterialProperty<Real>("PorousFlow_matrix_internal_energy_nodal")),
      47          38 :     _rock_energy_nodal_old(getMaterialPropertyOld<Real>("PorousFlow_matrix_internal_energy_nodal")),
      48             :     _drock_energy_nodal_dvar(
      49          38 :         getMaterialProperty<std::vector<Real>>("dPorousFlow_matrix_internal_energy_nodal_dvar")),
      50             :     _fluid_density(
      51          19 :         _fluid_present
      52          52 :             ? &getMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")
      53             :             : nullptr),
      54             :     _fluid_density_old(
      55          19 :         _fluid_present
      56          52 :             ? &getMaterialPropertyOld<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")
      57             :             : nullptr),
      58          19 :     _dfluid_density_dvar(_fluid_present
      59          33 :                              ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      60          47 :                                    "dPorousFlow_fluid_phase_density_nodal_dvar")
      61             :                              : nullptr),
      62             :     _fluid_saturation_nodal(
      63          52 :         _fluid_present ? &getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")
      64             :                        : nullptr),
      65             :     _fluid_saturation_nodal_old(
      66          52 :         _fluid_present ? &getMaterialPropertyOld<std::vector<Real>>("PorousFlow_saturation_nodal")
      67             :                        : nullptr),
      68          19 :     _dfluid_saturation_nodal_dvar(_fluid_present
      69          33 :                                       ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      70          47 :                                             "dPorousFlow_saturation_nodal_dvar")
      71             :                                       : nullptr),
      72          19 :     _energy_nodal(_fluid_present
      73          33 :                       ? &getMaterialProperty<std::vector<Real>>(
      74          47 :                             "PorousFlow_fluid_phase_internal_energy_nodal")
      75             :                       : nullptr),
      76          19 :     _energy_nodal_old(_fluid_present
      77          33 :                           ? &getMaterialPropertyOld<std::vector<Real>>(
      78          47 :                                 "PorousFlow_fluid_phase_internal_energy_nodal")
      79             :                           : nullptr),
      80          19 :     _denergy_nodal_dvar(_fluid_present
      81          33 :                             ? &getMaterialProperty<std::vector<std::vector<Real>>>(
      82          47 :                                   "dPorousFlow_fluid_phase_internal_energy_nodal_dvar")
      83         437 :                             : nullptr)
      84             : {
      85          19 : }
      86             : 
      87             : Real
      88      205080 : PorousFlowEnergyTimeDerivative::computeQpResidual()
      89             : {
      90      615240 :   Real energy = (1.0 - _porosity[_i]) * _rock_energy_nodal[_i];
      91      615240 :   Real energy_old = (1.0 - _porosity_old[_i]) * _rock_energy_nodal_old[_i];
      92      831304 :   for (unsigned ph = 0; ph < _num_phases; ++ph)
      93             :   {
      94     1565560 :     energy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
      95      626224 :               (*_energy_nodal)[_i][ph] * _porosity[_i];
      96     1565560 :     energy_old += (*_fluid_density_old)[_i][ph] * (*_fluid_saturation_nodal_old)[_i][ph] *
      97      626224 :                   (*_energy_nodal_old)[_i][ph] * _porosity_old[_i];
      98             :   }
      99             : 
     100      410160 :   return _test[_i][_qp] * (energy - energy_old) / _dt;
     101             : }
     102             : 
     103             : Real
     104      118560 : PorousFlowEnergyTimeDerivative::computeQpJacobian()
     105             : {
     106             :   /// If the variable is not a PorousFlow variable (very unusual), the diag Jacobian terms are 0
     107      118560 :   if (!_var_is_porflow_var)
     108             :     return 0.0;
     109      118560 :   return computeQpJac(_dictator.porousFlowVariableNum(_var.number()));
     110             : }
     111             : 
     112             : Real
     113      270240 : PorousFlowEnergyTimeDerivative::computeQpOffDiagJacobian(unsigned int jvar)
     114             : {
     115             :   /// If the variable is not a PorousFlow variable, the OffDiag Jacobian terms are 0
     116      270240 :   if (_dictator.notPorousFlowVariable(jvar))
     117             :     return 0.0;
     118      270240 :   return computeQpJac(_dictator.porousFlowVariableNum(jvar));
     119             : }
     120             : 
     121             : Real
     122      388800 : PorousFlowEnergyTimeDerivative::computeQpJac(unsigned int pvar) const
     123             : {
     124      388800 :   const unsigned nearest_qp = (_strain_at_nearest_qp ? (*_nearest_qp)[_i] : _i);
     125             : 
     126             :   // porosity is dependent on variables that are lumped to the nodes,
     127             :   // but it can depend on the gradient
     128             :   // of variables, which are NOT lumped to the nodes, hence:
     129     1555200 :   Real denergy = -_dporosity_dgradvar[_i][pvar] * _grad_phi[_j][_i] * _rock_energy_nodal[_i];
     130     1291712 :   for (unsigned ph = 0; ph < _num_phases; ++ph)
     131     1805824 :     denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
     132     1354368 :                (*_energy_nodal)[_i][ph] * _dporosity_dgradvar[_i][pvar] * _grad_phi[_j][nearest_qp];
     133             : 
     134      388800 :   if (_i != _j)
     135      597504 :     return _test[_i][_qp] * denergy / _dt;
     136             : 
     137             :   /// As the fluid energy is lumped to the nodes, only non-zero terms are for _i==_j
     138      180096 :   denergy += -_dporosity_dvar[_i][pvar] * _rock_energy_nodal[_i];
     139      270144 :   denergy += (1.0 - _porosity[_i]) * _drock_energy_nodal_dvar[_i][pvar];
     140      286912 :   for (unsigned ph = 0; ph < _num_phases; ++ph)
     141             :   {
     142      492160 :     denergy += (*_dfluid_density_dvar)[_i][ph][pvar] * (*_fluid_saturation_nodal)[_i][ph] *
     143      196864 :                (*_energy_nodal)[_i][ph] * _porosity[_i];
     144      393728 :     denergy += (*_fluid_density)[_i][ph] * (*_dfluid_saturation_nodal_dvar)[_i][ph][pvar] *
     145       98432 :                (*_energy_nodal)[_i][ph] * _porosity[_i];
     146      295296 :     denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
     147      196864 :                (*_denergy_nodal_dvar)[_i][ph][pvar] * _porosity[_i];
     148      196864 :     denergy += (*_fluid_density)[_i][ph] * (*_fluid_saturation_nodal)[_i][ph] *
     149       98432 :                (*_energy_nodal)[_i][ph] * _dporosity_dvar[_i][pvar];
     150             :   }
     151      180096 :   return _test[_i][_qp] * denergy / _dt;
     152        2499 : }

Generated by: LCOV version 1.11