www.mooseframework.org
PorousFlowMassFraction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "PorousFlowMassFraction.h"
11 
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<PorousFlowMaterialVectorBase>();
19  params.addCoupledVar("mass_fraction_vars",
20  "List of variables that represent the mass fractions. Format is 'f_ph0^c0 "
21  "f_ph0^c1 f_ph0^c2 ... f_ph0^c(N-1) f_ph1^c0 f_ph1^c1 fph1^c2 ... "
22  "fph1^c(N-1) ... fphP^c0 f_phP^c1 fphP^c2 ... fphP^c(N-1)' where "
23  "N=num_components and P=num_phases, and it is assumed that "
24  "f_ph^cN=1-sum(f_ph^c,{c,0,N-1}) so that f_ph^cN need not be given. If no "
25  "variables are provided then num_phases=1=num_components.");
26  params.addPrivateParam<std::string>("pf_material_type", "mass_fraction");
27  params.addClassDescription("This Material forms a std::vector<std::vector ...> of mass-fractions "
28  "out of the individual mass fractions");
29  return params;
30 }
31 
32 PorousFlowMassFraction::PorousFlowMassFraction(const InputParameters & parameters)
33  : PorousFlowMaterialVectorBase(parameters),
34 
35  _mass_frac(_nodal_material
36  ? declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_nodal")
37  : declareProperty<std::vector<std::vector<Real>>>("PorousFlow_mass_frac_qp")),
38  _grad_mass_frac(_nodal_material ? nullptr
39  : &declareProperty<std::vector<std::vector<RealGradient>>>(
40  "PorousFlow_grad_mass_frac_qp")),
41  _dmass_frac_dvar(_nodal_material ? declareProperty<std::vector<std::vector<std::vector<Real>>>>(
42  "dPorousFlow_mass_frac_nodal_dvar")
43  : declareProperty<std::vector<std::vector<std::vector<Real>>>>(
44  "dPorousFlow_mass_frac_qp_dvar")),
45 
46  _num_passed_mf_vars(coupledComponents("mass_fraction_vars"))
47 {
48  if (_num_phases < 1 || _num_components < 1)
49  mooseError("PorousFlowMassFraction: The Dictator proclaims that the number of phases is ",
51  " and the number of components is ",
53  ", and stipulates that you should not use PorousFlowMassFraction in this case");
54 
56  paramError("mass_fraction_vars",
57  "This value must be equal to the Dictator's num_phases (",
59  ") multiplied by num_components-1 (",
60  _num_components - 1,
61  ")");
62 
66  for (unsigned i = 0; i < _num_passed_mf_vars; ++i)
67  {
68  _mf_vars_num[i] = coupled("mass_fraction_vars", i);
69  _mf_vars[i] = (_nodal_material ? &coupledDofValues("mass_fraction_vars", i)
70  : &coupledValue("mass_fraction_vars", i));
71  _grad_mf_vars[i] = &coupledGradient("mass_fraction_vars", i);
72  }
73 }
74 
75 void
77 {
78  // all we need to do is compute _mass_frac for _nodal_materials
79  // but the following avoids code duplication
81 }
82 
83 void
85 {
86  // size all properties correctly
87  _mass_frac[_qp].resize(_num_phases);
88  _dmass_frac_dvar[_qp].resize(_num_phases);
89  if (!_nodal_material)
90  (*_grad_mass_frac)[_qp].resize(_num_phases);
91  for (unsigned int ph = 0; ph < _num_phases; ++ph)
92  {
93  _mass_frac[_qp][ph].resize(_num_components);
94  _dmass_frac_dvar[_qp][ph].resize(_num_components);
95  for (unsigned int comp = 0; comp < _num_components; ++comp)
96  _dmass_frac_dvar[_qp][ph][comp].assign(_num_var, 0.0);
97  if (!_nodal_material)
98  (*_grad_mass_frac)[_qp][ph].resize(_num_components);
99  }
100 
101  // compute the values and derivatives
102  unsigned int i = 0;
103  for (unsigned int ph = 0; ph < _num_phases; ++ph)
104  {
105  Real total_mass_frac = 0;
106  if (!_nodal_material)
107  (*_grad_mass_frac)[_qp][ph][_num_components - 1] = 0.0;
108  for (unsigned int comp = 0; comp < _num_components - 1; ++comp)
109  {
110  _mass_frac[_qp][ph][comp] = (*_mf_vars[i])[_qp];
111  total_mass_frac += _mass_frac[_qp][ph][comp];
112  if (!_nodal_material)
113  {
114  (*_grad_mass_frac)[_qp][ph][comp] = (*_grad_mf_vars[i])[_qp];
115  (*_grad_mass_frac)[_qp][ph][_num_components - 1] -= (*_grad_mf_vars[i])[_qp];
116  }
117  if (_dictator.isPorousFlowVariable(_mf_vars_num[i]))
118  {
119  // _mf_vars[i] is a PorousFlow variable
120  const unsigned int pf_var_num = _dictator.porousFlowVariableNum(_mf_vars_num[i]);
121  _dmass_frac_dvar[_qp][ph][comp][pf_var_num] = 1.0;
122  _dmass_frac_dvar[_qp][ph][_num_components - 1][pf_var_num] = -1.0;
123  }
124  i++;
125  }
126  _mass_frac[_qp][ph][_num_components - 1] = 1.0 - total_mass_frac;
127  }
128 }
VectorValue< Real > RealGradient
virtual void computeQpProperties() override
const unsigned int _num_phases
Number of phases.
Material designed to form a std::vector<std::vector> of mass fractions from the individual mass fract...
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
registerMooseObject("PorousFlowApp", PorousFlowMassFraction)
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.