LCOV - code coverage report
Current view: top level - src/postprocessors - PorousFlowHeatEnergy.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 53 55 96.4 %
Date: 2017-11-20 14:50:56 Functions: 5 6 83.3 %
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 "PorousFlowHeatEnergy.h"
       9             : 
      10             : // MOOSE includes
      11             : #include "MooseVariable.h"
      12             : 
      13             : #include "libmesh/quadrature.h"
      14             : 
      15             : template <>
      16             : InputParameters
      17          16 : validParams<PorousFlowHeatEnergy>()
      18             : {
      19          16 :   InputParameters params = validParams<ElementIntegralPostprocessor>();
      20          48 :   params.addRequiredParam<UserObjectName>(
      21          16 :       "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names.");
      22          48 :   params.addParam<bool>(
      23          16 :       "include_porous_skeleton", true, "Include the heat energy of the porous skeleton");
      24          48 :   params.addParam<std::vector<unsigned int>>("phase",
      25             :                                              "The index(es) of the fluid phase that this "
      26             :                                              "Postprocessor is restricted to.  Multiple "
      27          16 :                                              "indices can be entered.");
      28          32 :   params.set<bool>("use_displaced_mesh") = true;
      29          48 :   params.addParam<unsigned int>("kernel_variable_number",
      30             :                                 0,
      31             :                                 "The PorousFlow variable number (according to the dictatory) of "
      32             :                                 "the heat-energy kernel.  This is required only in the unusual "
      33             :                                 "situation where a variety of different finite-element "
      34          16 :                                 "interpolation schemes are employed in the simulation");
      35          32 :   params.addClassDescription("Calculates the sum of heat energy of fluid phase(s) and/or the "
      36          16 :                              "porous skeleton in a region");
      37          16 :   return params;
      38             : }
      39             : 
      40          12 : PorousFlowHeatEnergy::PorousFlowHeatEnergy(const InputParameters & parameters)
      41             :   : ElementIntegralPostprocessor(parameters),
      42          24 :     _dictator(getUserObject<PorousFlowDictator>("PorousFlowDictator")),
      43          12 :     _num_phases(_dictator.numPhases()),
      44          12 :     _fluid_present(_num_phases > 0),
      45          36 :     _include_porous_skeleton(getParam<bool>("include_porous_skeleton")),
      46             :     _phase_index(getParam<std::vector<unsigned int>>("phase")),
      47          24 :     _porosity(getMaterialProperty<Real>("PorousFlow_porosity_nodal")),
      48          24 :     _rock_energy_nodal(getMaterialProperty<Real>("PorousFlow_matrix_internal_energy_nodal")),
      49             :     _fluid_density(
      50          12 :         _fluid_present
      51          35 :             ? &getMaterialProperty<std::vector<Real>>("PorousFlow_fluid_phase_density_nodal")
      52             :             : nullptr),
      53             :     _fluid_saturation_nodal(
      54          35 :         _fluid_present ? &getMaterialProperty<std::vector<Real>>("PorousFlow_saturation_nodal")
      55             :                        : nullptr),
      56          12 :     _energy_nodal(_fluid_present
      57          23 :                       ? &getMaterialProperty<std::vector<Real>>(
      58          34 :                             "PorousFlow_fluid_phase_internal_energy_nodal")
      59             :                       : nullptr),
      60          36 :     _var(getParam<unsigned>("kernel_variable_number") < _dictator.numVariables()
      61          57 :              ? _dictator.getCoupledMooseVars()[getParam<unsigned>("kernel_variable_number")]
      62         168 :              : nullptr)
      63             : {
      64          12 :   if (!_phase_index.empty())
      65             :   {
      66             :     /// Check that the phase indices entered are not greater than the number of phases
      67           8 :     const unsigned int max_phase_num = *std::max_element(_phase_index.begin(), _phase_index.end());
      68           8 :     if (max_phase_num > _num_phases - 1)
      69             :       mooseError("The Dictator proclaims that the phase index ",
      70             :                  max_phase_num,
      71             :                  " in the Postprocessor ",
      72           1 :                  _name,
      73             :                  " is greater than the largest phase index possible, which is ",
      74           2 :                  _num_phases - 1);
      75             :   }
      76             : 
      77             :   /// Check that kernel_variable_number is OK
      78          33 :   if (getParam<unsigned>("kernel_variable_number") >= _dictator.numVariables())
      79           1 :     mooseError("PorousFlowHeatEnergy: The dictator pronounces that the number of porous-flow "
      80             :                "variables is ",
      81           1 :                _dictator.numVariables(),
      82             :                ", however you have used kernel_variable_number = ",
      83             :                getParam<unsigned>("kernel_variable_number"),
      84           1 :                ".  This is an error");
      85          10 : }
      86             : 
      87             : Real
      88          45 : PorousFlowHeatEnergy::computeIntegral()
      89             : {
      90             :   Real sum = 0;
      91             : 
      92             :   /** The use of _test in the loops below mean that the
      93             :    * integral is exactly the same as the one computed
      94             :    * by the PorousFlowMassTimeDerivative Kernel.  Because that
      95             :    * Kernel is lumped, this Postprocessor also needs to
      96             :    * be lumped.  Hence the use of the "nodal" Material
      97             :    * Properties
      98             :    */
      99          45 :   const VariableTestValue & test = _var->phi();
     100             : 
     101         621 :   for (unsigned node = 0; node < test.size(); ++node)
     102             :   {
     103             :     Real nodal_volume = 0.0;
     104        4896 :     for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
     105        8640 :       nodal_volume += _JxW[_qp] * _coord[_qp] * test[node][_qp];
     106             : 
     107             :     Real energy = 0.0;
     108         288 :     if (_include_porous_skeleton)
     109         702 :       energy += (1.0 - _porosity[node]) * _rock_energy_nodal[node];
     110             : 
     111         516 :     for (auto ph : _phase_index)
     112        1140 :       energy += (*_fluid_density)[node][ph] * (*_fluid_saturation_nodal)[node][ph] *
     113         684 :                 (*_energy_nodal)[node][ph] * _porosity[node];
     114             : 
     115         288 :     sum += nodal_volume * energy;
     116             :   }
     117             : 
     118          45 :   return sum;
     119             : }
     120             : 
     121             : Real
     122           0 : PorousFlowHeatEnergy::computeQpIntegral()
     123             : {
     124           0 :   return 0.0;
     125        2499 : }

Generated by: LCOV version 1.11