forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DivField and GradField kernels (idaholab#26105)
Co-authored-by: karthichockalingam <karthikeyan.chockalingam@stfc.ac.uk>
- Loading branch information
1 parent
91ee5f2
commit d810382
Showing
4 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "Kernel.h" | ||
|
||
/** | ||
* Weak form contribution corresponding to k*div(u) | ||
*/ | ||
class DivField : public Kernel | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
DivField(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual Real computeQpResidual() override; | ||
virtual Real computeQpOffDiagJacobian(unsigned jvar) override; | ||
|
||
/// coupled vector variable | ||
VectorMooseVariable & _u_var; | ||
unsigned int _u_var_num; | ||
|
||
/// div of the coupled vector variable | ||
const VectorVariableDivergence & _div_u; | ||
|
||
/// div of the shape function of the coupled vector variable | ||
const VectorVariablePhiDivergence & _div_phi; | ||
|
||
/// scalar coefficient | ||
Real _coeff; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "VectorKernel.h" | ||
|
||
/** | ||
* Weak form contribution corresponding to -k*grad(p) | ||
*/ | ||
class GradField : public VectorKernel | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
GradField(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual Real computeQpResidual() override; | ||
virtual Real computeQpOffDiagJacobian(unsigned jvar) override; | ||
|
||
/// coupled scalar variable | ||
MooseVariable & _p_var; | ||
unsigned int _p_var_num; | ||
|
||
/// value of the coupled scalar variable | ||
const VariableValue & _p; | ||
|
||
/// shape function of the coupled scalar variable | ||
const VariablePhiValue & _p_phi; | ||
|
||
/// div of the test function | ||
const VectorVariableTestDivergence & _div_test; | ||
|
||
/// scalar coefficient | ||
Real _coeff; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "DivField.h" | ||
#include "Assembly.h" | ||
|
||
registerMooseObject("MooseApp", DivField); | ||
|
||
InputParameters | ||
DivField::validParams() | ||
{ | ||
InputParameters params = Kernel::validParams(); | ||
params.addClassDescription("Takes the divergence of a vector field, optionally" | ||
"scaled by a constant scalar coefficient."); | ||
params.addRequiredCoupledVar("coupled_vector_variable", "The vector field"); | ||
params.addParam<Real>("coeff", 1.0, "The constant coefficient"); | ||
return params; | ||
} | ||
|
||
DivField::DivField(const InputParameters & parameters) | ||
: Kernel(parameters), | ||
_u_var(*getVectorVar("coupled_vector_variable", 0)), | ||
_u_var_num(coupled("coupled_vector_variable")), | ||
_div_u(_u_var.divSln()), | ||
_div_phi(_assembly.divPhi(_u_var)), | ||
_coeff(getParam<Real>("coeff")) | ||
{ | ||
} | ||
|
||
Real | ||
DivField::computeQpResidual() | ||
{ | ||
return _coeff * _div_u[_qp] * _test[_i][_qp]; | ||
} | ||
|
||
Real | ||
DivField::computeQpOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (_u_var_num == jvar) | ||
return _coeff * _div_phi[_j][_qp] * _test[_i][_qp]; | ||
|
||
return 0.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "GradField.h" | ||
#include "Assembly.h" | ||
|
||
registerMooseObject("MooseApp", GradField); | ||
|
||
InputParameters | ||
GradField::validParams() | ||
{ | ||
InputParameters params = VectorKernel::validParams(); | ||
params.addClassDescription("Takes the gradient of a scalar field, optionally" | ||
"scaled by a constant scalar coefficient."); | ||
params.addRequiredCoupledVar("coupled_scalar_variable", "The scalar field"); | ||
params.addParam<Real>("coeff", 1.0, "The constant coefficient"); | ||
return params; | ||
} | ||
|
||
GradField::GradField(const InputParameters & parameters) | ||
: VectorKernel(parameters), | ||
_p_var(*getVar("coupled_scalar_variable", 0)), | ||
_p_var_num(coupled("coupled_scalar_variable")), | ||
_p(coupledValue("coupled_scalar_variable")), | ||
_p_phi(_assembly.phi(_p_var)), | ||
_div_test(_var.divPhi()), | ||
_coeff(getParam<Real>("coeff")) | ||
{ | ||
} | ||
|
||
Real | ||
GradField::computeQpResidual() | ||
{ | ||
return _coeff * _p[_qp] * _div_test[_i][_qp]; | ||
} | ||
|
||
Real | ||
GradField::computeQpOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (_p_var_num == jvar) | ||
return _coeff * _p_phi[_j][_qp] * _div_test[_i][_qp]; | ||
|
||
return 0.0; | ||
} |