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
9b3f932
commit e74bfad
Showing
4 changed files
with
169 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,37 @@ | ||
//* 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 div(u) where u is a vector | ||
*/ | ||
class DivField : public Kernel | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
DivField(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual Real computeQpResidual() override; | ||
virtual Real computeQpOffDiagJacobian(unsigned jvar) override; | ||
|
||
VectorMooseVariable & _u_var; | ||
|
||
/// div of the shape function | ||
const VectorVariablePhiDivergence & _div_phi; | ||
|
||
/// holds the solution div at the current quadrature points | ||
const VectorVariableDivergence & _div_u; | ||
|
||
unsigned int _u_var_num; | ||
}; |
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,39 @@ | ||
//* 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 -grad(p) where p is a scalar | ||
*/ | ||
class GradField : public VectorKernel | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
GradField(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual Real computeQpResidual() override; | ||
virtual Real computeQpOffDiagJacobian(unsigned jvar) override; | ||
|
||
const VariableValue & _p; | ||
|
||
MooseVariable & _p_var; | ||
|
||
/// shape function | ||
const VariablePhiValue & _p_phi; | ||
|
||
/// div of the test function | ||
const VectorVariableTestDivergence & _div_test; | ||
|
||
unsigned int _p_var_num; | ||
}; |
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,46 @@ | ||
//* 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("ElectromagneticsApp", DivField); | ||
|
||
InputParameters | ||
DivField::validParams() | ||
{ | ||
InputParameters params = Kernel::validParams(); | ||
params.addClassDescription("Weak form term for $\\nabla \\cdot \\vec{u}$."); | ||
params.addRequiredCoupledVar("u", "vector field"); | ||
return params; | ||
} | ||
|
||
DivField::DivField(const InputParameters & parameters) | ||
: Kernel(parameters), | ||
_u_var(*getVectorVar("u", 0)), | ||
_div_phi(_assembly.divPhi(_u_var)), | ||
_div_u(_u_var.divSln()), | ||
_u_var_num(coupled("u")) | ||
{ | ||
} | ||
|
||
Real | ||
DivField::computeQpResidual() | ||
{ | ||
return _div_u[_qp] * _test[_i][_qp]; | ||
} | ||
|
||
Real | ||
DivField::computeQpOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (_u_var_num == jvar) | ||
return _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,47 @@ | ||
//* 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("ElectromagneticsApp", GradField); | ||
|
||
InputParameters | ||
GradField::validParams() | ||
{ | ||
InputParameters params = VectorKernel::validParams(); | ||
params.addClassDescription("Weak form term for $-\\nabla p$."); | ||
params.addRequiredCoupledVar("p", "scalar field"); | ||
return params; | ||
} | ||
|
||
GradField::GradField(const InputParameters & parameters) | ||
: VectorKernel(parameters), | ||
_p(coupledValue("p")), | ||
_p_var(*getVar("p", 0)), | ||
_p_phi(_assembly.phi(_p_var)), | ||
_div_test(_var.divPhi()), | ||
_p_var_num(coupled("p")) | ||
{ | ||
} | ||
|
||
Real | ||
GradField::computeQpResidual() | ||
{ | ||
return _p[_qp] * _div_test[_i][_qp]; | ||
} | ||
|
||
Real | ||
GradField::computeQpOffDiagJacobian(unsigned int jvar) | ||
{ | ||
if (_p_var_num == jvar) | ||
return _p_phi[_j][_qp] * _div_test[_i][_qp]; | ||
|
||
return 0.0; | ||
} |