www.mooseframework.org
PorousFlowMassFraction.C
Go to the documentation of this file.
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 
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<PorousFlowMaterialVectorBase>();
15  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  "variables are provided then num_phases=1=num_components.");
22  params.addClassDescription("This Material forms a std::vector<std::vector ...> of mass-fractions "
23  "out of the individual mass fractions");
24  return params;
25 }
26 
27 PorousFlowMassFraction::PorousFlowMassFraction(const InputParameters & parameters)
28  : PorousFlowMaterialVectorBase(parameters),
29 
30  _mass_frac(_nodal_material
31  ? declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")
32  : declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_qp")),
33  _grad_mass_frac(_nodal_material ? nullptr
34  : &declareProperty<std::vector<std::vector<RealGradient>>>(
35  "PorousFlow_grad_mass_frac_qp")),
36  _dmass_frac_dvar(_nodal_material ? declareProperty<std::vector<std::vector<std::vector<Real>>>>(
37  "dPorousFlow_mass_frac_nodal_dvar")
38  : declareProperty<std::vector<std::vector<std::vector<Real>>>>(
39  "dPorousFlow_mass_frac_qp_dvar")),
40 
41  _num_passed_mf_vars(coupledComponents("mass_fraction_vars"))
42 {
43  if (_num_phases < 1 || _num_components < 1)
44  mooseError("PorousFlowMassFraction: The Dictator proclaims that the number of phases is ",
46  " and the number of components is ",
48  ", and stipulates that you should not use PorousFlowMassFraction in this case");
50  mooseError("PorousFlowMassFraction: The number of mass_fraction_vars is ",
52  " which must be equal to the Dictator's num_phases (",
54  ") multiplied by num_components-1 (",
55  _num_components - 1,
56  ")");
57 
61  for (unsigned i = 0; i < _num_passed_mf_vars; ++i)
62  {
63  _mf_vars_num[i] = coupled("mass_fraction_vars", i);
64  _mf_vars[i] = (_nodal_material ? &coupledNodalValue("mass_fraction_vars", i)
65  : &coupledValue("mass_fraction_vars", i));
66  _grad_mf_vars[i] = &coupledGradient("mass_fraction_vars", i);
67  }
68 }
69 
70 void
72 {
73  // all we need to do is compute _mass_frac for _nodal_materials
74  // but the following avoids code duplication
76 }
77 
78 void
80 {
81  // size all properties correctly
82  _mass_frac[_qp].resize(_num_phases);
83  _dmass_frac_dvar[_qp].resize(_num_phases);
84  if (!_nodal_material)
85  (*_grad_mass_frac)[_qp].resize(_num_phases);
86  for (unsigned int ph = 0; ph < _num_phases; ++ph)
87  {
88  _mass_frac[_qp][ph].resize(_num_components);
89  _dmass_frac_dvar[_qp][ph].resize(_num_components);
90  for (unsigned int comp = 0; comp < _num_components; ++comp)
91  _dmass_frac_dvar[_qp][ph][comp].assign(_num_var, 0.0);
92  if (!_nodal_material)
93  (*_grad_mass_frac)[_qp][ph].resize(_num_components);
94  }
95 
96  // compute the values and derivatives
97  unsigned int i = 0;
98  for (unsigned int ph = 0; ph < _num_phases; ++ph)
99  {
100  Real total_mass_frac = 0;
101  if (!_nodal_material)
102  (*_grad_mass_frac)[_qp][ph][_num_components - 1] = 0.0;
103  for (unsigned int comp = 0; comp < _num_components - 1; ++comp)
104  {
105  _mass_frac[_qp][ph][comp] = (*_mf_vars[i])[_qp];
106  total_mass_frac += _mass_frac[_qp][ph][comp];
107  if (!_nodal_material)
108  {
109  (*_grad_mass_frac)[_qp][ph][comp] = (*_grad_mf_vars[i])[_qp];
110  (*_grad_mass_frac)[_qp][ph][_num_components - 1] -= (*_grad_mf_vars[i])[_qp];
111  }
112  if (_dictator.isPorousFlowVariable(_mf_vars_num[i]))
113  {
114  // _mf_vars[i] is a PorousFlow variable
115  const unsigned int pf_var_num = _dictator.porousFlowVariableNum(_mf_vars_num[i]);
116  _dmass_frac_dvar[_qp][ph][comp][pf_var_num] = 1.0;
117  _dmass_frac_dvar[_qp][ph][_num_components - 1][pf_var_num] = -1.0;
118  }
119  i++;
120  }
121  _mass_frac[_qp][ph][_num_components - 1] = 1.0 - total_mass_frac;
122  }
123 }
virtual void computeQpProperties() override
const unsigned int _num_phases
Number of phases.
MaterialProperty< std::vector< std::vector< std::vector< Real > > > > & _dmass_frac_dvar
Derivative of the mass fraction matrix with respect to the porous flow variables. ...
InputParameters validParams< PorousFlowMassFraction >()
virtual void initQpStatefulProperties() override
InputParameters validParams< PorousFlowMaterialVectorBase >()
std::vector< unsigned int > _mf_vars_num
the variable number of the mass-fraction variables
Base class for all PorousFlow vector materials.
const unsigned int _num_components
Number of fluid components.
const unsigned int _num_var
Number of PorousFlow variables.
std::vector< const VariableValue * > _mf_vars
the mass-fraction variables
PorousFlowMassFraction(const InputParameters &parameters)
std::vector< const VariableGradient * > _grad_mf_vars
the gradient of the mass-fraction variables
const unsigned int _num_passed_mf_vars
Number of mass-fraction variables provided by the user This needs to be num_phases*(_num_components -...
MaterialProperty< std::vector< std::vector< Real > > > & _mass_frac
Mass fraction matrix at quadpoint or nodes.