Skip to content

Commit

Permalink
Removing coefficient_type parameter from ArrayDiffusion and ArrayReac…
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmprince committed Sep 19, 2019
1 parent 27c57da commit 513996f
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 46 deletions.
2 changes: 0 additions & 2 deletions framework/include/kernels/ArrayDiffusion.h
Expand Up @@ -26,8 +26,6 @@ class ArrayDiffusion : public ArrayKernel
virtual RealEigenVector computeQpJacobian() override;
virtual RealEigenMatrix computeQpOffDiagJacobian(MooseVariableFEBase & jvar) override;

/// diffusion coefficient type
unsigned int _dc_type;
/// scalar diffusion coefficient
const MaterialProperty<Real> * _d;
/// array diffusion coefficient
Expand Down
2 changes: 0 additions & 2 deletions framework/include/kernels/ArrayReaction.h
Expand Up @@ -26,8 +26,6 @@ class ArrayReaction : public ArrayKernel
virtual RealEigenVector computeQpJacobian() override;
virtual RealEigenMatrix computeQpOffDiagJacobian(MooseVariableFEBase & jvar) override;

/// diffusion coefficient type
unsigned int _r_type;
/// scalar diffusion coefficient
const MaterialProperty<Real> * _r;
/// array diffusion coefficient
Expand Down
40 changes: 20 additions & 20 deletions framework/src/kernels/ArrayDiffusion.C
Expand Up @@ -16,42 +16,42 @@ InputParameters
validParams<ArrayDiffusion>()
{
InputParameters params = validParams<ArrayKernel>();
params.addParam<MaterialPropertyName>("diffusion_coefficient", "The name of the diffusivity");
MooseEnum opt("scalar=0 array=1 full=2", "array");
params.addParam<MooseEnum>("diffusion_coefficient_type", opt, "Diffusion coefficient type");
params.addParam<MaterialPropertyName>("diffusion_coefficient", "The name of the diffusivity, "
"can be scalar, vector, or matrix.");
params.addClassDescription(
"The array Laplacian operator ($-\\nabla \\cdot \\nabla u$), with the weak "
"form of $(\\nabla \\phi_i, \\nabla u_h)$.");
return params;
}

ArrayDiffusion::ArrayDiffusion(const InputParameters & parameters)
: ArrayKernel(parameters), _dc_type(getParam<MooseEnum>("diffusion_coefficient_type"))
: ArrayKernel(parameters),
_d(hasMaterialProperty<Real>("diffusion_coefficient") ?
&getMaterialProperty<Real>("diffusion_coefficient") : nullptr),
_d_array(hasMaterialProperty<RealEigenVector>("diffusion_coefficient") ?
&getMaterialProperty<RealEigenVector>("diffusion_coefficient") : nullptr),
_d_2d_array(hasMaterialProperty<RealEigenMatrix>("diffusion_coefficient") ?
&getMaterialProperty<RealEigenMatrix>("diffusion_coefficient") : nullptr)
{
if (_dc_type == 0)
_d = &getMaterialProperty<Real>("diffusion_coefficient");
else if (_dc_type == 1)
_d_array = &getMaterialProperty<RealEigenVector>("diffusion_coefficient");
else if (_dc_type == 2)
_d_2d_array = &getMaterialProperty<RealEigenMatrix>("diffusion_coefficient");
if (!_d && !_d_array && !_d_2d_array)
{
MaterialPropertyName mat = getParam<MaterialPropertyName>("diffusion_coefficient");
mooseError("Property " + mat + " is of unsupported type for ArrayDiffusion");
}
}

RealEigenVector
ArrayDiffusion::computeQpResidual()
{
if (_dc_type == 0)
if (_d)
return _grad_u[_qp] * _array_grad_test[_i][_qp] * (*_d)[_qp];

else if (_dc_type == 1)
else if (_d_array)
{
mooseAssert((*_d_array)[_qp].size() == _var.count(),
"diffusion_coefficient size is inconsistent with the number of components of array "
"variable");
mooseAssert((*_d_array)[_qp].size() == _var.count(), "");
RealEigenVector v = _grad_u[_qp] * _array_grad_test[_i][_qp];
for (unsigned int i = 0; i < _var.count(); ++i)
v(i) *= (*_d_array)[_qp](i);
return v;
return (*_d_array)[_qp].cwiseProduct(_grad_u[_qp] * _array_grad_test[_i][_qp]);
}

else
Expand All @@ -69,10 +69,10 @@ ArrayDiffusion::computeQpResidual()
RealEigenVector
ArrayDiffusion::computeQpJacobian()
{
if (_dc_type == 0)
if (_d)
return RealEigenVector::Constant(_var.count(),
_grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d)[_qp]);
else if (_dc_type == 1)
else if (_d_array)
return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_array)[_qp];
else
return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp].diagonal();
Expand All @@ -81,7 +81,7 @@ ArrayDiffusion::computeQpJacobian()
RealEigenMatrix
ArrayDiffusion::computeQpOffDiagJacobian(MooseVariableFEBase & jvar)
{
if (jvar.number() == _var.number() && _dc_type == 2)
if (jvar.number() == _var.number() && _d_2d_array)
return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp];
else
return ArrayKernel::computeQpOffDiagJacobian(jvar);
Expand Down
34 changes: 19 additions & 15 deletions framework/src/kernels/ArrayReaction.C
Expand Up @@ -16,32 +16,36 @@ InputParameters
validParams<ArrayReaction>()
{
InputParameters params = validParams<ArrayKernel>();
params.addParam<MaterialPropertyName>("reaction_coefficient", "The name of the reactivity");
MooseEnum opt("scalar=0 array=1 full=2", "array");
params.addParam<MooseEnum>("reaction_coefficient_type", opt, "Reaction coefficient type");
params.addParam<MaterialPropertyName>("reaction_coefficient", "The name of the reactivity, "
"can be scalar, vector, or matrix.");
params.addClassDescription("The array reaction operator with the weak "
"form of $(\\psi_i, u_h)$.");
return params;
}

ArrayReaction::ArrayReaction(const InputParameters & parameters)
: ArrayKernel(parameters), _r_type(getParam<MooseEnum>("reaction_coefficient_type"))
: ArrayKernel(parameters),
_r(hasMaterialProperty<Real>("reaction_coefficient") ?
&getMaterialProperty<Real>("reaction_coefficient") : nullptr),
_r_array(hasMaterialProperty<RealEigenVector>("reaction_coefficient") ?
&getMaterialProperty<RealEigenVector>("reaction_coefficient") : nullptr),
_r_2d_array(hasMaterialProperty<RealEigenMatrix>("reaction_coefficient") ?
&getMaterialProperty<RealEigenMatrix>("reaction_coefficient") : nullptr)
{
if (_r_type == 0)
_r = &getMaterialProperty<Real>("reaction_coefficient");
else if (_r_type == 1)
_r_array = &getMaterialProperty<RealEigenVector>("reaction_coefficient");
else if (_r_type == 2)
_r_2d_array = &getMaterialProperty<RealEigenMatrix>("reaction_coefficient");
if (!_r && !_r_array && !_r_2d_array)
{
MaterialPropertyName mat = getParam<MaterialPropertyName>("reaction_coefficient");
mooseError("Property " + mat + " is of unsupported type for ArrayReaction");
}
}

RealEigenVector
ArrayReaction::computeQpResidual()
{
if (_r_type == 0)
if (_r)
return (*_r)[_qp] * _u[_qp] * _test[_i][_qp];

else if (_r_type == 1)
else if (_r_array)
{
mooseAssert((*_r_array)[_qp].size() == _var.count(),
"reaction_coefficient size is inconsistent with the number of components of array "
Expand All @@ -64,9 +68,9 @@ ArrayReaction::computeQpResidual()
RealEigenVector
ArrayReaction::computeQpJacobian()
{
if (_r_type == 0)
if (_r)
return RealEigenVector::Constant(_var.count(), _phi[_j][_qp] * _test[_i][_qp] * (*_r)[_qp]);
else if (_r_type == 1)
else if (_r_array)
return _phi[_j][_qp] * _test[_i][_qp] * (*_r_array)[_qp];

else
Expand All @@ -76,7 +80,7 @@ ArrayReaction::computeQpJacobian()
RealEigenMatrix
ArrayReaction::computeQpOffDiagJacobian(MooseVariableFEBase & jvar)
{
if (jvar.number() == _var.number() && _r_type == 2)
if (jvar.number() == _var.number() && _r_2d_array)
return _phi[_j][_qp] * _test[_i][_qp] * (*_r_2d_array)[_qp];
else
return ArrayKernel::computeQpOffDiagJacobian(jvar);
Expand Down
1 change: 0 additions & 1 deletion test/tests/bcs/array_vacuum/array_vacuum.i
Expand Up @@ -22,7 +22,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[]
Expand Down
Expand Up @@ -22,7 +22,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[]
Expand Down
Expand Up @@ -24,7 +24,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[diffv]
Expand Down
Expand Up @@ -31,7 +31,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[]
Expand Down
Expand Up @@ -24,7 +24,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[diffv]
Expand Down
Expand Up @@ -27,7 +27,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[]
Expand Down
1 change: 0 additions & 1 deletion test/tests/kernels/array_kernels/array_save_in.i
Expand Up @@ -67,7 +67,6 @@
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient_type = full
reaction_coefficient = rc
[]
[]
Expand Down

0 comments on commit 513996f

Please sign in to comment.