https://mooseframework.inl.gov
ArrayCoupledForce.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "ArrayCoupledForce.h"
11 
12 #include "MooseVariable.h"
13 
15 
18 {
20  params.addRequiredCoupledVar("v", "The coupled variable which provides the force");
21  params.addParam<bool>("is_v_array", false, "Whether v is an array variable or not");
23  "coef", "Coefficient ($\\sigma$) multiplier for the coupled force term.");
24  params.addClassDescription(
25  "Implements a source term proportional to the value of a coupled standard or array "
26  "variable. Weak form: $(\\vec{u}^\\ast, -\\vec{\\sigma} v)$.");
27  return params;
28 }
29 
31  : ArrayKernel(parameters),
32  _is_v_array(getParam<bool>("is_v_array")),
33  _v_var(coupled("v")),
34  _v(_is_v_array ? nullptr : &coupledValue("v")),
35  _v_array(_is_v_array ? &coupledArrayValue("v") : nullptr),
36  _coef(getParam<RealEigenVector>("coef"))
37 {
38  if (_var.number() == _v_var)
39  paramError("v",
40  "Coupled variable 'v' needs to be different from 'variable' with "
41  "ArrayCoupledForce, consider using ArrayReaction or something similar");
42  if (_is_v_array && getArrayVar("v", 0)->count() != _count)
43  paramError("v",
44  "Needs to be either a standard variable or an array variable with the same "
45  "number of components as 'variable'");
46 }
47 
48 void
50 {
51  if (_is_v_array)
52  residual = -_coef.cwiseProduct((*_v_array)[_qp]) * _test[_i][_qp];
53  else
54  residual = -_coef * (*_v)[_qp] * _test[_i][_qp];
55 }
56 
59 {
60  if (jvar.number() == _v_var)
61  {
62  RealEigenVector v = _coef * (-_phi[_j][_qp] * _test[_i][_qp]);
63  if (_is_v_array)
64  {
65  RealEigenMatrix t = RealEigenMatrix::Zero(_var.count(), _var.count());
66  t.diagonal() = v;
67  return t;
68  }
69  else
70  return v;
71  }
72  else
73  return RealEigenMatrix::Zero(_var.count(), jvar.count());
74 }
const RealEigenVector _coef
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
registerMooseObject("MooseApp", ArrayCoupledForce)
unsigned int number() const
Get variable number coming from libMesh.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class provides an interface for common operations on field variables of both FE and FV types wit...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
static InputParameters validParams()
Definition: ArrayKernel.C:23
ArrayCoupledForce(const InputParameters &parameters)
const unsigned int _v_var
const ArrayVariableValue *const _v_array
const ArrayVariableTestValue & _test
the current test function
Definition: ArrayKernel.h:88
unsigned int _i
current index for the test function
Definition: KernelBase.h:58
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
Definition: MooseTypes.h:151
const unsigned int _count
Number of components of the array variable.
Definition: ArrayKernel.h:107
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
unsigned int _j
current index for the shape function
Definition: KernelBase.h:61
const ArrayVariablePhiValue & _phi
the current shape functions
Definition: ArrayKernel.h:95
ArrayMooseVariable * getArrayVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled array variable.
Definition: Coupleable.C:336
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:147
ArrayMooseVariable & _var
This is an array kernel so we cast to a ArrayMooseVariable.
Definition: ArrayKernel.h:85
virtual RealEigenMatrix computeQpOffDiagJacobian(const MooseVariableFEBase &jvar) override
This is the virtual that derived classes should override for computing a full Jacobian component...
virtual void computeQpResidual(RealEigenVector &residual) override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point, to be filled in residual.
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:43