LCOV - code coverage report
Current view: top level - src/materials - PorousFlowMassFraction.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 59 64 92.2 %
Date: 2017-11-20 14:50:56 Functions: 6 6 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 "PorousFlowMassFraction.h"
       9             : 
      10             : template <>
      11             : InputParameters
      12         188 : validParams<PorousFlowMassFraction>()
      13             : {
      14         188 :   InputParameters params = validParams<PorousFlowMaterialVectorBase>();
      15         564 :   params.addCoupledVar("mass_fraction_vars",
      16             :                        "List of variables that represent the mass fractions.  Format is 'f_ph0^c0 "
      17             :                        "f_ph0^c1 f_ph0^c2 ... f_ph0^c(N-1) f_ph1^c0 f_ph1^c1 fph1^c2 ... "
      18             :                        "fph1^c(N-1) ... fphP^c0 f_phP^c1 fphP^c2 ... fphP^c(N-1)' where "
      19             :                        "N=num_components and P=num_phases, and it is assumed that "
      20             :                        "f_ph^cN=1-sum(f_ph^c,{c,0,N-1}) so that f_ph^cN need not be given.  If no "
      21         188 :                        "variables are provided then num_phases=1=num_components.");
      22         376 :   params.addClassDescription("This Material forms a std::vector<std::vector ...> of mass-fractions "
      23         188 :                              "out of the individual mass fractions");
      24         188 :   return params;
      25             : }
      26             : 
      27         564 : PorousFlowMassFraction::PorousFlowMassFraction(const InputParameters & parameters)
      28             :   : PorousFlowMaterialVectorBase(parameters),
      29             : 
      30         564 :     _mass_frac(_nodal_material
      31        1692 :                    ? declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")
      32         720 :                    : declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_qp")),
      33         642 :     _grad_mass_frac(_nodal_material ? nullptr
      34             :                                     : &declareProperty<std::vector<std::vector<RealGradient>>>(
      35         720 :                                           "PorousFlow_grad_mass_frac_qp")),
      36        1128 :     _dmass_frac_dvar(_nodal_material ? declareProperty<std::vector<std::vector<std::vector<Real>>>>(
      37        1536 :                                            "dPorousFlow_mass_frac_nodal_dvar")
      38             :                                      : declareProperty<std::vector<std::vector<std::vector<Real>>>>(
      39         720 :                                            "dPorousFlow_mass_frac_qp_dvar")),
      40             : 
      41        4512 :     _num_passed_mf_vars(coupledComponents("mass_fraction_vars"))
      42             : {
      43         564 :   if (_num_phases < 1 || _num_components < 1)
      44           0 :     mooseError("PorousFlowMassFraction: The Dictator proclaims that the number of phases is ",
      45             :                _num_phases,
      46             :                " and the number of components is ",
      47             :                _num_components,
      48           0 :                ", and stipulates that you should not use PorousFlowMassFraction in this case");
      49         564 :   if (_num_passed_mf_vars != _num_phases * (_num_components - 1))
      50           0 :     mooseError("PorousFlowMassFraction: The number of mass_fraction_vars is ",
      51             :                _num_passed_mf_vars,
      52             :                " which must be equal to the Dictator's num_phases (",
      53             :                _num_phases,
      54             :                ") multiplied by num_components-1 (",
      55           0 :                _num_components - 1,
      56           0 :                ")");
      57             : 
      58         564 :   _mf_vars_num.resize(_num_passed_mf_vars);
      59         564 :   _mf_vars.resize(_num_passed_mf_vars);
      60         564 :   _grad_mf_vars.resize(_num_passed_mf_vars);
      61        1422 :   for (unsigned i = 0; i < _num_passed_mf_vars; ++i)
      62             :   {
      63        1287 :     _mf_vars_num[i] = coupled("mass_fraction_vars", i);
      64        1287 :     _mf_vars[i] = (_nodal_material ? &coupledNodalValue("mass_fraction_vars", i)
      65         561 :                                    : &coupledValue("mass_fraction_vars", i));
      66         858 :     _grad_mf_vars[i] = &coupledGradient("mass_fraction_vars", i);
      67             :   }
      68         564 : }
      69             : 
      70             : void
      71       72968 : PorousFlowMassFraction::initQpStatefulProperties()
      72             : {
      73             :   // all we need to do is compute _mass_frac for _nodal_materials
      74             :   // but the following avoids code duplication
      75       72968 :   computeQpProperties();
      76       72968 : }
      77             : 
      78             : void
      79     4317628 : PorousFlowMassFraction::computeQpProperties()
      80             : {
      81             :   // size all properties correctly
      82     8635256 :   _mass_frac[_qp].resize(_num_phases);
      83     8635256 :   _dmass_frac_dvar[_qp].resize(_num_phases);
      84     4317628 :   if (!_nodal_material)
      85      894888 :     (*_grad_mass_frac)[_qp].resize(_num_phases);
      86    13753660 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
      87             :   {
      88     9436032 :     _mass_frac[_qp][ph].resize(_num_components);
      89     9436032 :     _dmass_frac_dvar[_qp][ph].resize(_num_components);
      90    16898804 :     for (unsigned int comp = 0; comp < _num_components; ++comp)
      91    12180788 :       _dmass_frac_dvar[_qp][ph][comp].assign(_num_var, 0.0);
      92     4718016 :     if (!_nodal_material)
      93      897712 :       (*_grad_mass_frac)[_qp][ph].resize(_num_components);
      94             :   }
      95             : 
      96             :   // compute the values and derivatives
      97             :   unsigned int i = 0;
      98    13753660 :   for (unsigned int ph = 0; ph < _num_phases; ++ph)
      99             :   {
     100             :     Real total_mass_frac = 0;
     101     4718016 :     if (!_nodal_material)
     102      448856 :       (*_grad_mass_frac)[_qp][ph][_num_components - 1] = 0.0;
     103     7462772 :     for (unsigned int comp = 0; comp < _num_components - 1; ++comp)
     104             :     {
     105     5489512 :       _mass_frac[_qp][ph][comp] = (*_mf_vars[i])[_qp];
     106     1372378 :       total_mass_frac += _mass_frac[_qp][ph][comp];
     107     1372378 :       if (!_nodal_material)
     108             :       {
     109      685872 :         (*_grad_mass_frac)[_qp][ph][comp] = (*_grad_mf_vars[i])[_qp];
     110      228624 :         (*_grad_mass_frac)[_qp][ph][_num_components - 1] -= (*_grad_mf_vars[i])[_qp];
     111             :       }
     112     1372378 :       if (_dictator.isPorousFlowVariable(_mf_vars_num[i]))
     113             :       {
     114             :         // _mf_vars[i] is a PorousFlow variable
     115      776770 :         const unsigned int pf_var_num = _dictator.porousFlowVariableNum(_mf_vars_num[i]);
     116     1553540 :         _dmass_frac_dvar[_qp][ph][comp][pf_var_num] = 1.0;
     117     1553540 :         _dmass_frac_dvar[_qp][ph][_num_components - 1][pf_var_num] = -1.0;
     118             :       }
     119     1372378 :       i++;
     120             :     }
     121     9436032 :     _mass_frac[_qp][ph][_num_components - 1] = 1.0 - total_mass_frac;
     122             :   }
     123     4320127 : }

Generated by: LCOV version 1.11