www.mooseframework.org
KernelBase.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "KernelBase.h"
16 #include "Assembly.h"
17 #include "MooseVariable.h"
18 #include "Problem.h"
19 #include "SubProblem.h"
20 #include "SystemBase.h"
21 #include "NonlinearSystem.h"
22 
23 #include "libmesh/threads.h"
24 
25 template <>
28 {
32  params += validParams<RandomInterface>();
35 
36  params.addRequiredParam<NonlinearVariableName>(
37  "variable", "The name of the variable that this Kernel operates on");
38  params.addParam<std::vector<AuxVariableName>>(
39  "save_in",
40  "The name of auxiliary variables to save this Kernel's residual contributions to. "
41  " Everything about that variable must match everything about this variable (the "
42  "type, what blocks it's on, etc.)");
43  params.addParam<std::vector<AuxVariableName>>(
44  "diag_save_in",
45  "The name of auxiliary variables to save this Kernel's diagonal Jacobian "
46  "contributions to. Everything about that variable must match everything "
47  "about this variable (the type, what blocks it's on, etc.)");
48  params.addParam<bool>(
49  "eigen_kernel", false, "Whether or not this kernel will be used as an eigen kernel");
50  params.addParam<bool>("use_displaced_mesh",
51  false,
52  "Whether or not this object should use the "
53  "displaced mesh for computation. Note that in "
54  "the case this is true but no displacements "
55  "are provided in the Mesh block the "
56  "undisplaced mesh will still be used.");
57  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
58 
59  params.addParamNamesToGroup("diag_save_in save_in", "Advanced");
60 
61  params.declareControllable("enable");
62  return params;
63 }
64 
66  : MooseObject(parameters),
67  BlockRestrictable(this),
68  SetupInterface(this),
70  FunctionInterface(this),
71  UserObjectInterface(this),
72  TransientInterface(this),
75  MaterialPropertyInterface(this, blockIDs()),
76  RandomInterface(parameters,
77  *parameters.get<FEProblemBase *>("_fe_problem_base"),
78  parameters.get<THREAD_ID>("_tid"),
79  false),
81  Restartable(parameters, "Kernels"),
82  ZeroInterface(parameters),
83  MeshChangedInterface(parameters),
84  _subproblem(*parameters.get<SubProblem *>("_subproblem")),
85  _fe_problem(*parameters.get<FEProblemBase *>("_fe_problem_base")),
86  _sys(*parameters.get<SystemBase *>("_sys")),
87  _tid(parameters.get<THREAD_ID>("_tid")),
88  _assembly(_subproblem.assembly(_tid)),
89  _var(_sys.getVariable(_tid, parameters.get<NonlinearVariableName>("variable"))),
90  _mesh(_subproblem.mesh()),
91  _current_elem(_var.currentElem()),
92  _current_elem_volume(_assembly.elemVolume()),
93  _q_point(_assembly.qPoints()),
94  _qrule(_assembly.qRule()),
95  _JxW(_assembly.JxW()),
96  _coord(_assembly.coordTransformation()),
97 
98  _test(_var.phi()),
99  _grad_test(_var.gradPhi()),
100 
101  _phi(_assembly.phi()),
102  _grad_phi(_assembly.gradPhi()),
103 
104  _save_in_strings(parameters.get<std::vector<AuxVariableName>>("save_in")),
105  _diag_save_in_strings(parameters.get<std::vector<AuxVariableName>>("diag_save_in")),
106 
107  _eigen_kernel(getParam<bool>("eigen_kernel"))
108 {
109  _save_in.resize(_save_in_strings.size());
110  _diag_save_in.resize(_diag_save_in_strings.size());
111 
112  for (unsigned int i = 0; i < _save_in_strings.size(); i++)
113  {
115 
117  mooseError("Trying to use solution variable " + _save_in_strings[i] +
118  " as a save_in variable in " + name());
119 
120  if (var->feType() != _var.feType())
121  mooseError("Error in " + name() + ". When saving residual values in an Auxiliary variable "
122  "the AuxVariable must be the same type as the nonlinear "
123  "variable the object is acting on.");
124 
125  _save_in[i] = var;
128  }
129 
130  _has_save_in = _save_in.size() > 0;
131 
132  for (unsigned int i = 0; i < _diag_save_in_strings.size(); i++)
133  {
135 
137  mooseError("Trying to use solution variable " + _diag_save_in_strings[i] +
138  " as a diag_save_in variable in " + name());
139 
140  if (var->feType() != _var.feType())
141  mooseError("Error in " + name() + ". When saving diagonal Jacobian values in an Auxiliary "
142  "variable the AuxVariable must be the same type as the "
143  "nonlinear variable the object is acting on.");
144 
145  _diag_save_in[i] = var;
148  }
149 
150  _has_diag_save_in = _diag_save_in.size() > 0;
151 }
152 
154 
157 {
158  return _var;
159 }
160 
161 SubProblem &
163 {
164  return _subproblem;
165 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
InputParameters validParams< MaterialPropertyInterface >()
Interface for objects that need parallel consistent random numbers without patterns over the course o...
FEProblemBase & _fe_problem
Reference to this kernel&#39;s FEProblemBase.
Definition: KernelBase.h:108
A class for creating restricted objects.
Definition: Restartable.h:31
std::vector< MooseVariable * > _diag_save_in
Definition: KernelBase.h:176
const FEType & feType() const
Get the type of finite element object.
Class for stuff related to variables.
Definition: MooseVariable.h:43
NonlinearSystemBase & getNonlinearSystemBase()
InputParameters validParams< BlockRestrictable >()
std::vector< AuxVariableName > _diag_save_in_strings
Definition: KernelBase.h:177
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested variable which may be in any system. ...
SubProblem & subProblem()
Returns a reference to the SubProblem for which this Kernel is active.
Definition: KernelBase.C:162
THREAD_ID _tid
The thread ID for this kernel.
Definition: KernelBase.h:114
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual ~KernelBase()
Definition: KernelBase.C:153
void addMooseVariableDependency(MooseVariable *var)
Call this function to add the passed in MooseVariable as a variable that this object depends on...
Base class for a system (of equations)
Definition: SystemBase.h:91
KernelBase(const InputParameters &parameters)
Definition: KernelBase.C:65
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
Definition: KernelBase.h:175
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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...
Interface for objects that needs transient capabilities.
Interface for notifications that the mesh has changed.
InputParameters validParams< RandomInterface >()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
std::vector< MooseVariable * > _save_in
Definition: KernelBase.h:171
bool _has_save_in
The aux variables to save the residual contributions to.
Definition: KernelBase.h:170
InputParameters validParams< MeshChangedInterface >()
Interface for objects that need to use UserObjects.
virtual bool hasVariable(const std::string &var_name)
Query a system for a variable.
Definition: SystemBase.C:556
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
std::vector< AuxVariableName > _save_in_strings
Definition: KernelBase.h:172
InputParameters validParams< KernelBase >()
Definition: KernelBase.C:27
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
SubProblem & _subproblem
Reference to this kernel&#39;s SubProblem.
Definition: KernelBase.h:105
Interface to bring zero values inside objects.
Definition: ZeroInterface.h:35
An interface for accessing Materials.
virtual void addVariableToZeroOnResidual(std::string var_name)
Adds this variable to the list of variables to be zeroed during each residual evaluation.
Definition: SystemBase.C:150
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
MooseVariable & variable()
Returns the variable number that this Kernel operates on.
Definition: KernelBase.C:156
virtual void addVariableToZeroOnJacobian(std::string var_name)
Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.
Definition: SystemBase.C:156
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
SystemBase & sys()
Get the system this variable is part of.
MooseVariable & _var
Reference to this Kernel&#39;s MooseVariable object.
Definition: KernelBase.h:120
Interface for objects that need to use functions.
InputParameters validParams< TransientInterface >()
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:79