www.mooseframework.org
BodyForce.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 "BodyForce.h"
11 
12 // MOOSE
13 #include "Function.h"
14 #include "Assembly.h"
15 
16 registerMooseObject("MooseApp", BodyForce);
17 registerMooseObject("MooseApp", ADBodyForce);
18 
19 template <bool is_ad>
22 {
24  params.addClassDescription("Demonstrates the multiple ways that scalar values can be introduced "
25  "into kernels, e.g. (controllable) constants, functions, and "
26  "postprocessors. Implements the weak form $(\\psi_i, -f)$.");
27  params.addParam<Real>("value", 1.0, "Coefficient to multiply by the body force term");
28  params.addParam<FunctionName>("function", "1", "A function that describes the body force");
29  params.addParam<PostprocessorName>(
30  "postprocessor", 1, "A postprocessor whose value is multiplied by the body force");
31  params.declareControllable("value");
32  return params;
33 }
34 
35 template <bool is_ad>
37  : GenericKernel<is_ad>(parameters),
38  _scale(this->template getParam<Real>("value")),
39  _function(getFunction("function")),
40  _postprocessor(getPostprocessorValue("postprocessor")),
41  _generic_q_point(this->_use_displaced_mesh ? &this->_assembly.template genericQPoints<is_ad>()
42  : nullptr)
43 {
44 }
45 
46 template <bool is_ad>
49 {
50  if (_generic_q_point)
51  return -_test[_i][_qp] * _scale * _postprocessor *
52  _function.value(_t, (*_generic_q_point)[_qp]);
53  else
54  return -_test[_i][_qp] * _scale * _postprocessor * _function.value(_t, _q_point[_qp]);
55 }
56 
57 template class BodyForceTempl<false>;
58 template class BodyForceTempl<true>;
BodyForceTempl(const InputParameters &parameters)
Definition: BodyForce.C:36
registerMooseObject("MooseApp", BodyForce)
static InputParameters validParams()
Definition: BodyForce.C:21
static InputParameters validParams()
Definition: GenericKernel.h:19
virtual GenericReal< is_ad > computeQpResidual() override
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
Definition: BodyForce.C:48
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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
This kernel implements a generic functional body force term: $ - c f $.
Definition: BodyForce.h:25
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.