www.mooseframework.org
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
CoupledDiffusionReactionSub Class Reference

Diffusion of primary species in given equilibrium species. More...

#include <CoupledDiffusionReactionSub.h>

Inheritance diagram for CoupledDiffusionReactionSub:
[legend]

Public Member Functions

 CoupledDiffusionReactionSub (const InputParameters &parameters)
 

Protected Member Functions

virtual Real computeQpResidual () override
 
virtual Real computeQpJacobian () override
 
virtual Real computeQpOffDiagJacobian (unsigned int jvar) override
 

Private Attributes

const MaterialProperty< Real > & _diffusivity
 Material property of dispersion-diffusion coefficient. More...
 
const Real _weight
 Weight of the equilibrium species concentration in the total primary species concentration. More...
 
const VariableValue & _log_k
 Equilibrium constant for the equilibrium species in association form. More...
 
const Real _sto_u
 Stoichiometric coefficient of the primary species. More...
 
const std::vector< Real > _sto_v
 Stoichiometric coefficients of the coupled primary species. More...
 
std::vector< unsigned int > _vars
 Coupled primary species variable numbers. More...
 
std::vector< const VariableValue * > _vals
 Coupled primary species concentrations. More...
 
std::vector< const VariableGradient * > _grad_vals
 Coupled gradients of primary species concentrations. More...
 
const VariableValue & _gamma_u
 Activity coefficient of primary species in the equilibrium species. More...
 
std::vector< const VariableValue * > _gamma_v
 Activity coefficients of coupled primary species in the equilibrium species. More...
 
const VariableValue & _gamma_eq
 Activity coefficient of equilibrium species. More...
 

Detailed Description

Diffusion of primary species in given equilibrium species.

Definition at line 23 of file CoupledDiffusionReactionSub.h.

Constructor & Destructor Documentation

◆ CoupledDiffusionReactionSub()

CoupledDiffusionReactionSub::CoupledDiffusionReactionSub ( const InputParameters &  parameters)

Definition at line 40 of file CoupledDiffusionReactionSub.C.

41  : Kernel(parameters),
42  _diffusivity(getMaterialProperty<Real>("diffusivity")),
43  _weight(getParam<Real>("weight")),
44  _log_k(coupledValue("log_k")),
45  _sto_u(getParam<Real>("sto_u")),
46  _sto_v(getParam<std::vector<Real>>("sto_v")),
47  _gamma_u(coupledValue("gamma_u")),
48  _gamma_eq(coupledValue("gamma_eq"))
49 {
50  const unsigned int n = coupledComponents("v");
51 
52  // Check that the correct number of coupled values have been provided
53  if (_sto_v.size() != n)
54  mooseError("The number of stoichiometric coefficients in sto_v is not equal to the number of "
55  "coupled species in ",
56  _name);
57 
58  if (isCoupled("gamma_v"))
59  if (coupledComponents("gamma_v") != n)
60  mooseError("The number of activity coefficients in gamma_v is not equal to the number of "
61  "coupled species in ",
62  _name);
63 
64  _vars.resize(n);
65  _vals.resize(n);
66  _grad_vals.resize(n);
67  _gamma_v.resize(n);
68 
69  for (unsigned int i = 0; i < n; ++i)
70  {
71  _vars[i] = coupled("v", i);
72  _vals[i] = &coupledValue("v", i);
73  _grad_vals[i] = &coupledGradient("v", i);
74  // If gamma_v has been supplied, use those values, but if not, use the default value
75  _gamma_v[i] = (isCoupled("gamma_v") ? &coupledValue("gamma_v", i) : &coupledValue("gamma_v"));
76  }
77 }
std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species in association form.
std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const Real _sto_u
Stoichiometric coefficient of the primary species.
const MaterialProperty< Real > & _diffusivity
Material property of dispersion-diffusion coefficient.
std::vector< unsigned int > _vars
Coupled primary species variable numbers.

Member Function Documentation

◆ computeQpJacobian()

Real CoupledDiffusionReactionSub::computeQpJacobian ( )
overrideprotectedvirtual

Definition at line 109 of file CoupledDiffusionReactionSub.C.

110 {
111  RealGradient diff1_1 =
112  _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_phi[_j][_qp];
113  RealGradient diff1_2 = _phi[_j][_qp] * _sto_u * (_sto_u - 1.0) * _gamma_u[_qp] * _gamma_u[_qp] *
114  std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 2.0) * _grad_u[_qp];
115  for (unsigned int i = 0; i < _vals.size(); ++i)
116  {
117  diff1_1 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
118  diff1_2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
119  }
120 
121  RealGradient diff1 = diff1_1 + diff1_2;
122  Real d_val =
123  _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _phi[_j][_qp];
124  RealGradient diff2_sum(0.0, 0.0, 0.0);
125  for (unsigned int i = 0; i < _vals.size(); ++i)
126  {
127  RealGradient diff2 = d_val * _sto_v[i] * (*_gamma_v[i])[_qp] *
128  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
129  (*_grad_vals[i])[_qp];
130  for (unsigned int j = 0; j < _vals.size(); ++j)
131  if (j != i)
132  diff2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
133 
134  diff2_sum += diff2;
135  }
136 
137  return _weight * std::pow(10.0, _log_k[_qp]) * _diffusivity[_qp] * _grad_test[_i][_qp] *
138  (diff1 + diff2_sum) / _gamma_eq[_qp];
139 }
std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species in association form.
std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const Real _sto_u
Stoichiometric coefficient of the primary species.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const MaterialProperty< Real > & _diffusivity
Material property of dispersion-diffusion coefficient.

◆ computeQpOffDiagJacobian()

Real CoupledDiffusionReactionSub::computeQpOffDiagJacobian ( unsigned int  jvar)
overrideprotectedvirtual

Definition at line 142 of file CoupledDiffusionReactionSub.C.

143 {
144  // If no coupled species, return 0
145  if (_vals.size() == 0)
146  return 0.0;
147 
148  // If jvar is not one of the coupled species, return 0
149  if (std::find(_vars.begin(), _vars.end(), jvar) == _vars.end())
150  return 0.0;
151 
152  RealGradient diff1 =
153  _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_u[_qp];
154  for (unsigned int i = 0; i < _vals.size(); ++i)
155  {
156  if (jvar == _vars[i])
157  diff1 *= _sto_v[i] * (*_gamma_v[i])[_qp] *
158  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
159  else
160  diff1 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
161  }
162 
163  Real val_u = std::pow(_gamma_u[_qp] * _u[_qp], _sto_u);
164 
165  RealGradient diff2_1(1.0, 1.0, 1.0);
166  RealGradient diff2_2(1.0, 1.0, 1.0);
167 
168  for (unsigned int i = 0; i < _vals.size(); ++i)
169  if (jvar == _vars[i])
170  {
171  diff2_1 = _sto_v[i] * (_sto_v[i] - 1.0) * (*_gamma_v[i])[_qp] * (*_gamma_v[i])[_qp] *
172  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 2.0) * _phi[_j][_qp] *
173  (*_grad_vals[i])[_qp];
174  diff2_2 = _sto_v[i] * (*_gamma_v[i])[_qp] *
175  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
176  _grad_phi[_j][_qp];
177  }
178 
179  RealGradient diff2 = val_u * (diff2_1 + diff2_2);
180 
181  for (unsigned int i = 0; i < _vals.size(); ++i)
182  if (jvar != _vars[i])
183  diff2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
184 
185  RealGradient diff3;
186  RealGradient diff3_sum(0.0, 0.0, 0.0);
187  Real val_jvar = 0.0;
188  unsigned int var = 0;
189 
190  for (unsigned int i = 0; i < _vals.size(); ++i)
191  if (jvar == _vars[i])
192  {
193  var = i;
194  val_jvar = val_u * _sto_v[i] * (*_gamma_v[i])[_qp] *
195  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) * _phi[_j][_qp];
196  }
197 
198  for (unsigned int i = 0; i < _vals.size(); ++i)
199  if (i != var)
200  {
201  diff3 = val_jvar * _sto_v[i] * (*_gamma_v[i])[_qp] *
202  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
203  (*_grad_vals[i])[_qp];
204 
205  for (unsigned int j = 0; j < _vals.size(); ++j)
206  if (j != var && j != i)
207  diff3 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
208 
209  diff3_sum += diff3;
210  }
211 
212  return _weight * std::pow(10.0, _log_k[_qp]) * _diffusivity[_qp] * _grad_test[_i][_qp] *
213  (diff1 + diff2 + diff3_sum) / _gamma_eq[_qp];
214 }
std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species in association form.
std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const Real _sto_u
Stoichiometric coefficient of the primary species.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const MaterialProperty< Real > & _diffusivity
Material property of dispersion-diffusion coefficient.
std::vector< unsigned int > _vars
Coupled primary species variable numbers.

◆ computeQpResidual()

Real CoupledDiffusionReactionSub::computeQpResidual ( )
overrideprotectedvirtual

Definition at line 80 of file CoupledDiffusionReactionSub.C.

81 {
82  RealGradient diff1 =
83  _sto_u * _gamma_u[_qp] * std::pow(_gamma_u[_qp] * _u[_qp], _sto_u - 1.0) * _grad_u[_qp];
84  for (unsigned int i = 0; i < _vals.size(); ++i)
85  diff1 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i]);
86 
87  RealGradient diff2_sum(0.0, 0.0, 0.0);
88  const Real d_val = std::pow(_gamma_u[_qp] * _u[_qp], _sto_u);
89  for (unsigned int i = 0; i < _vals.size(); ++i)
90  {
91  RealGradient diff2 = d_val * _sto_v[i] * (*_gamma_v[i])[_qp] *
92  std::pow((*_gamma_v[i])[_qp] * (*_vals[i])[_qp], _sto_v[i] - 1.0) *
93  (*_grad_vals[i])[_qp];
94 
95  for (unsigned int j = 0; j < _vals.size(); ++j)
96  if (j != i)
97  diff2 *= std::pow((*_gamma_v[i])[_qp] * (*_vals[j])[_qp], _sto_v[j]);
98 
99  diff2_sum += diff2;
100  }
101 
102  mooseAssert(_gamma_eq[_qp] > 0.0, "Activity coefficient must be greater than zero");
103  return _weight * std::pow(10.0, _log_k[_qp]) * _diffusivity[_qp] * _grad_test[_i][_qp] *
104  (diff1 + diff2_sum) / _gamma_eq[_qp];
105  ;
106 }
std::vector< const VariableGradient * > _grad_vals
Coupled gradients of primary species concentrations.
const VariableValue & _gamma_eq
Activity coefficient of equilibrium species.
const Real _weight
Weight of the equilibrium species concentration in the total primary species concentration.
const VariableValue & _log_k
Equilibrium constant for the equilibrium species in association form.
std::vector< const VariableValue * > _gamma_v
Activity coefficients of coupled primary species in the equilibrium species.
std::vector< const VariableValue * > _vals
Coupled primary species concentrations.
const VariableValue & _gamma_u
Activity coefficient of primary species in the equilibrium species.
const std::vector< Real > _sto_v
Stoichiometric coefficients of the coupled primary species.
const Real _sto_u
Stoichiometric coefficient of the primary species.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const MaterialProperty< Real > & _diffusivity
Material property of dispersion-diffusion coefficient.

Member Data Documentation

◆ _diffusivity

const MaterialProperty<Real>& CoupledDiffusionReactionSub::_diffusivity
private

Material property of dispersion-diffusion coefficient.

Definition at line 35 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().

◆ _gamma_eq

const VariableValue& CoupledDiffusionReactionSub::_gamma_eq
private

Activity coefficient of equilibrium species.

Definition at line 55 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().

◆ _gamma_u

const VariableValue& CoupledDiffusionReactionSub::_gamma_u
private

Activity coefficient of primary species in the equilibrium species.

Definition at line 51 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().

◆ _gamma_v

std::vector<const VariableValue *> CoupledDiffusionReactionSub::_gamma_v
private

Activity coefficients of coupled primary species in the equilibrium species.

Definition at line 53 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), computeQpResidual(), and CoupledDiffusionReactionSub().

◆ _grad_vals

std::vector<const VariableGradient *> CoupledDiffusionReactionSub::_grad_vals
private

Coupled gradients of primary species concentrations.

Definition at line 49 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), computeQpResidual(), and CoupledDiffusionReactionSub().

◆ _log_k

const VariableValue& CoupledDiffusionReactionSub::_log_k
private

Equilibrium constant for the equilibrium species in association form.

Definition at line 39 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().

◆ _sto_u

const Real CoupledDiffusionReactionSub::_sto_u
private

Stoichiometric coefficient of the primary species.

Definition at line 41 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().

◆ _sto_v

const std::vector<Real> CoupledDiffusionReactionSub::_sto_v
private

Stoichiometric coefficients of the coupled primary species.

Definition at line 43 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), computeQpResidual(), and CoupledDiffusionReactionSub().

◆ _vals

std::vector<const VariableValue *> CoupledDiffusionReactionSub::_vals
private

Coupled primary species concentrations.

Definition at line 47 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), computeQpResidual(), and CoupledDiffusionReactionSub().

◆ _vars

std::vector<unsigned int> CoupledDiffusionReactionSub::_vars
private

Coupled primary species variable numbers.

Definition at line 45 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpOffDiagJacobian(), and CoupledDiffusionReactionSub().

◆ _weight

const Real CoupledDiffusionReactionSub::_weight
private

Weight of the equilibrium species concentration in the total primary species concentration.

Definition at line 37 of file CoupledDiffusionReactionSub.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().


The documentation for this class was generated from the following files: