https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CoupledForce.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 "CoupledForce.h"
11#include "MooseVariableFE.h"
12#include "SystemBase.h"
13
16
17template <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
32template <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
45template <bool is_ad>
48{
49 return -_coef * _v[_qp] * _test[_i][_qp];
50}
51
52template <bool is_ad>
53Real
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
67template class CoupledForceTempl<false>;
68template class CoupledForceTempl<true>;
registerMooseObject("MooseApp", CoupledForce)
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
Implements a source term proportional to the value of a coupled variable.
CoupledForceTempl(const InputParameters &parameters)
unsigned int _v_var
Coupled variable number.
virtual GenericReal< is_ad > computeQpResidual() override
Compute this Kernel's contribution to the residual at the current quadrature point.
static InputParameters validParams()
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
For coupling standard variables.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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.
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.
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:457
unsigned int number() const
Get variable number coming from libMesh.