www.mooseframework.org
CoupledForce.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "CoupledForce.h"
11 #include "MooseVariableFE.h"
12 #include "SystemBase.h"
13 
16 
17 template <bool is_ad>
20 {
22 
23  params.addClassDescription("Implements a source term proportional to the value of a coupled "
24  "variable. Weak form: $(\\psi_i, -\\sigma v)$.");
25  params.addRequiredCoupledVar("v", "The coupled variable which provides the force");
26  params.addParam<Real>(
27  "coef", 1.0, "Coefficent ($\\sigma$) multiplier for the coupled force term.");
28 
29  return params;
30 }
31 
32 template <bool is_ad>
34  : GenericKernel<is_ad>(parameters),
35  _v_var(coupled("v")),
36  _v(this->template coupledGenericValue<is_ad>("v")),
37  _coef(this->template getParam<Real>("coef"))
38 {
39  if (_var.number() == _v_var)
40  paramError("v",
41  "Coupled variable 'v' needs to be different from 'variable' with CoupledForce / "
42  "ADCoupledForce, consider using the CoefReaction kernel or something similar");
43 }
44 
45 template <bool is_ad>
48 {
49  return -_coef * _v[_qp] * _test[_i][_qp];
50 }
51 
52 template <bool is_ad>
53 Real
55 {
56  // This function will never be called for the AD version. But because C++ does
57  // not support an optional function declaration based on a template parameter,
58  // we must keep this template for all cases.
59  mooseAssert(!is_ad,
60  "In ADCoupledForce, computeQpJacobian should not be called. Check computeJacobian "
61  "implementation.");
62  if (jvar == _v_var)
63  return -_coef * _phi[_j][_qp] * _test[_i][_qp];
64  return 0.0;
65 }
66 
67 template class CoupledForceTempl<false>;
68 template class CoupledForceTempl<true>;
registerMooseObject("MooseApp", CoupledForce)
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: Kernel.h:72
static InputParameters validParams()
Definition: CoupledForce.C:19
unsigned int number() const
Get variable number coming from libMesh.
static InputParameters validParams()
Definition: GenericKernel.h:19
unsigned int _v_var
Coupled variable number.
Definition: CoupledForce.h:35
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
For coupling standard variables.
Definition: CoupledForce.C:54
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 ...
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual GenericReal< is_ad > computeQpResidual() override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
Definition: CoupledForce.C:47
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 option parameter and a documentation string to the InputParameters object...
typename Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:559
Implements a source term proportional to the value of a coupled variable.
Definition: CoupledForce.h:19
CoupledForceTempl(const InputParameters &parameters)
Definition: CoupledForce.C:33