https://mooseframework.inl.gov
MatCoupledForce.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 "MatCoupledForce.h"
11 
12 #include "MooseVariable.h"
13 
15 
18 {
20 
21  params.addClassDescription(
22  "Implements a forcing term RHS of the form PDE = RHS, where RHS = Sum_j c_j * m_j * v_j. "
23  "c_j, m_j, and v_j are provided as real coefficients, material properties, and coupled "
24  "variables, respectively.");
25  params.addRequiredCoupledVar("v", "The coupled variables which provide the force");
26  params.addParam<std::vector<Real>>(
27  "coef", "Coefficents ($\\sigma$) multiplier for the coupled force term.");
28  params.addParam<std::vector<MaterialPropertyName>>("material_properties",
29  "The coupled material properties.");
30  return params;
31 }
32 
34  : Kernel(parameters),
35  _n_coupled(coupledComponents("v")),
36  _coupled_props(isParamValid("material_properties")),
37  _v_var(coupledIndices("v")),
38  _v(coupledValues("v")),
39  _coef(isParamValid("coef") ? getParam<std::vector<Real>>("coef")
40  : std::vector<Real>(_n_coupled, 1))
41 {
42  for (MooseIndex(_n_coupled) j = 0; j < _n_coupled; ++j)
43  {
44  _v_var_to_index[_v_var[j]] = j;
45 
46  if (_var.number() == _v_var[j])
47  paramError("v",
48  "Coupled variable 'v' needs to be different from 'variable' with MatCoupledForce, "
49  "consider using Reaction or somethig similar");
50  }
51 
52  if (isParamValid("coef") && _coef.size() != _n_coupled)
53  paramError("coef", "Size of coef must be equal to size of v");
54 
55  if (_coupled_props)
56  {
57  _mat_props.resize(_n_coupled);
58  std::vector<MaterialPropertyName> names =
59  getParam<std::vector<MaterialPropertyName>>("material_properties");
60  if (names.size() != _n_coupled)
61  paramError("material_properties", "Size must be equal to number of coupled variables");
62  for (unsigned int j = 0; j < _n_coupled; ++j)
63  _mat_props[j] = &getMaterialPropertyByName<Real>(names[j]);
64  }
65 }
66 
67 Real
69 {
70  Real r = 0;
71  if (_coupled_props)
72  for (unsigned int j = 0; j < _n_coupled; ++j)
73  r += -_coef[j] * (*_mat_props[j])[_qp] * (*_v[j])[_qp];
74  else
75  for (unsigned int j = 0; j < _n_coupled; ++j)
76  r += -_coef[j] * (*_v[j])[_qp];
77  return r * _test[_i][_qp];
78 }
79 
80 Real
82 {
83  return 0;
84 }
85 
86 Real
88 {
89  auto p = _v_var_to_index.find(jvar);
90  if (p == _v_var_to_index.end())
91  return 0;
92 
93  if (_coupled_props)
94  return -_coef[p->second] * (*_mat_props[p->second])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
95  return -_coef[p->second] * _phi[_j][_qp] * _test[_i][_qp];
96 }
static InputParameters validParams()
Definition: Kernel.C:24
const unsigned int _n_coupled
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: Kernel.h:72
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:435
unsigned int number() const
Get variable number coming from libMesh.
const std::vector< Real > _coef
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< unsigned int > _v_var
virtual Real computeQpJacobian() override
Compute this Kernel&#39;s contribution to the Jacobian at the current quadrature point.
const VariableTestValue & _test
the current test function
Definition: Kernel.h:75
Represents a right hand side force term of the form Sum_j c_j * m_j * v_j, where c is a vector of rea...
unsigned int _i
current index for the test function
Definition: KernelBase.h:58
registerMooseObject("MooseApp", MatCoupledForce)
MatCoupledForce(const InputParameters &parameters)
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
static InputParameters validParams()
const std::vector< const VariableValue * > _v
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
For coupling standard variables.
std::vector< const MaterialProperty< Real > * > _mat_props
Definition: Kernel.h:15
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
const VariablePhiValue & _phi
the current shape functions
Definition: Kernel.h:81
const bool _coupled_props
virtual Real computeQpResidual() override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:43
std::map< unsigned int, unsigned int > _v_var_to_index