www.mooseframework.org
AuxKernel.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 "AuxKernel.h"
11 
12 // local includes
13 #include "FEProblem.h"
14 #include "SubProblem.h"
15 #include "AuxiliarySystem.h"
16 #include "MooseTypes.h"
17 #include "Assembly.h"
18 
19 #include "libmesh/numeric_vector.h"
20 #include "libmesh/dof_map.h"
21 #include "libmesh/quadrature.h"
22 
23 template <>
26 {
30  params += validParams<RandomInterface>();
33 
34  // Add the SetupInterface parameter 'execute_on' with 'linear' and 'timestep_end'
35  params += validParams<SetupInterface>();
36  ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
38  exec_enum = {EXEC_LINEAR, EXEC_TIMESTEP_END};
39  params.setDocString("execute_on", exec_enum.getDocString());
40 
41  params.addRequiredParam<AuxVariableName>("variable",
42  "The name of the variable that this object applies to");
43 
44  params.addParam<bool>("use_displaced_mesh",
45  false,
46  "Whether or not this object should use the "
47  "displaced mesh for computation. Note that "
48  "in the case this is true but no "
49  "displacements are provided in the Mesh block "
50  "the undisplaced mesh will still be used.");
51  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
52 
53  // This flag is set to true if the AuxKernelTempl is being used on a boundary
54  params.addPrivateParam<bool>("_on_boundary", false);
55 
56  params.declareControllable("enable"); // allows Control to enable/disable this type of object
57  params.registerBase("AuxKernel");
58  return params;
59 }
60 
61 template <>
64 {
66  params.registerBase("VectorAuxKernel");
67  return params;
68 }
69 
70 template <typename ComputeValueType>
72  : MooseObject(parameters),
73  MooseVariableInterface<ComputeValueType>(
74  this,
75  parameters.getCheckedPointerParam<AuxiliarySystem *>("_aux_sys")
76  ->getVariable(parameters.get<THREAD_ID>("_tid"),
77  parameters.get<AuxVariableName>("variable"))
78  .isNodal(),
79  "variable",
81  std::is_same<Real, ComputeValueType>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD
83  BlockRestrictable(this),
84  BoundaryRestrictable(this, mooseVariable()->isNodal()),
85  SetupInterface(this),
86  CoupleableMooseVariableDependencyIntermediateInterface(this, mooseVariable()->isNodal()),
87  FunctionInterface(this),
88  UserObjectInterface(this),
89  TransientInterface(this),
90  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
93  RandomInterface(parameters,
94  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
95  parameters.get<THREAD_ID>("_tid"),
96  mooseVariable()->isNodal()),
98  Restartable(this, "AuxKernels"),
99  MeshChangedInterface(parameters),
101  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
102  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
103  _nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
104  _aux_sys(*getCheckedPointerParam<AuxiliarySystem *>("_aux_sys")),
105  _tid(parameters.get<THREAD_ID>("_tid")),
106  _var(_aux_sys.getFieldVariable<ComputeValueType>(_tid,
107  parameters.get<AuxVariableName>("variable"))),
108  _nodal(_var.isNodal()),
109  _u(_nodal ? _var.nodalValueArray() : _var.sln()),
110  _u_old(_nodal ? _var.nodalValueOldArray() : _var.slnOld()),
111  _u_older(_nodal ? _var.nodalValueOlderArray() : _var.slnOlder()),
112 
113  _test(_var.phi()),
114  _assembly(_subproblem.assembly(_tid)),
115  _bnd(boundaryRestricted()),
116  _mesh(_subproblem.mesh()),
117 
118  _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
119  _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
120  _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
121  _coord(_assembly.coordTransformation()),
122 
123  _current_elem(_assembly.elem()),
124  _current_side(_assembly.side()),
125  _current_elem_volume(_assembly.elemVolume()),
126  _current_side_volume(_assembly.sideElemVolume()),
127 
128  _current_node(_assembly.node()),
129 
130  _solution(_aux_sys.solution())
131 {
133  _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
134 
135  std::map<std::string, std::vector<MooseVariableFEBase *>> coupled_vars = getCoupledVars();
136  for (const auto & it : coupled_vars)
137  for (const auto & var : it.second)
138  _depend_vars.insert(var->name());
139 }
140 
141 template <typename ComputeValueType>
142 const std::set<std::string> &
144 {
145  return _depend_vars;
146 }
147 
148 template <typename ComputeValueType>
149 const std::set<std::string> &
151 {
152  return _supplied_vars;
153 }
154 
155 template <typename ComputeValueType>
156 const UserObject &
158 {
159  _depend_uo.insert(_pars.get<UserObjectName>(name));
161 }
162 
163 template <typename ComputeValueType>
164 const PostprocessorValue &
166 {
167  _depend_uo.insert(_pars.get<PostprocessorName>(name));
169 }
170 
171 template <typename ComputeValueType>
172 const PostprocessorValue &
174 {
175  _depend_uo.insert(name);
177 }
178 
179 template <typename ComputeValueType>
182  const std::string & vector_name)
183 {
184  _depend_uo.insert(_pars.get<VectorPostprocessorName>(name));
186 }
187 
188 template <typename ComputeValueType>
191  const VectorPostprocessorName & name, const std::string & vector_name)
192 {
193  _depend_uo.insert(name);
195 }
196 
197 template <typename ComputeValueType>
200  const std::string & vector_name,
201  bool needs_broadcast)
202 {
203  _depend_uo.insert(_pars.get<VectorPostprocessorName>(name));
205  name, vector_name, needs_broadcast);
206 }
207 
208 template <typename ComputeValueType>
211  const VectorPostprocessorName & name, const std::string & vector_name, bool needs_broadcast)
212 {
213  _depend_uo.insert(name);
215  name, vector_name, needs_broadcast);
216 }
217 
218 template <typename ComputeValueType>
221  const std::string & name, const std::string & vector_name)
222 {
223  _depend_uo.insert(_pars.get<VectorPostprocessorName>(name));
225 }
226 
227 template <typename ComputeValueType>
230  const std::string & name, const std::string & vector_name)
231 {
232  _depend_uo.insert(name);
234 }
235 
236 template <typename ComputeValueType>
237 void
238 AuxKernelTempl<ComputeValueType>::coupledCallback(const std::string & var_name, bool is_old)
239 {
240  if (is_old)
241  {
242  std::vector<VariableName> var_names = getParam<std::vector<VariableName>>(var_name);
243  for (const auto & name : var_names)
244  _depend_vars.erase(name);
245  }
246 }
247 
248 template <typename ComputeValueType>
249 const VariableValue &
250 AuxKernelTempl<ComputeValueType>::coupledDot(const std::string & var_name, unsigned int comp)
251 {
252  MooseVariableFEBase * var = getVar(var_name, comp);
253  if (var->kind() == Moose::VAR_AUXILIARY)
254  mooseError(
255  name(),
256  ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
257 
258  return Coupleable::coupledDot(var_name, comp);
259 }
260 
261 template <typename ComputeValueType>
262 const VariableValue &
263 AuxKernelTempl<ComputeValueType>::coupledDotDu(const std::string & var_name, unsigned int comp)
264 {
265  MooseVariableFEBase * var = getVar(var_name, comp);
266  if (var->kind() == Moose::VAR_AUXILIARY)
267  mooseError(
268  name(),
269  ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
270 
271  return Coupleable::coupledDotDu(var_name, comp);
272 }
273 
274 template <typename ComputeValueType>
275 void
277 {
278  precalculateValue();
279 
280  if (isNodal()) /* nodal variables */
281  {
282  if (_var.isNodalDefined())
283  {
284  _qp = 0;
285  ComputeValueType value = computeValue();
286  // update variable data, which is referenced by other kernels, so the value is up-to-date
287  _var.setNodalValue(value);
288  }
289  }
290  else /* elemental variables */
291  {
292  _n_local_dofs = _var.numberOfDofs();
293  if (_n_local_dofs == 1) /* p0 */
294  {
295  ComputeValueType value = 0;
296  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
297  value += _JxW[_qp] * _coord[_qp] * computeValue();
298  value /= (_bnd ? _current_side_volume : _current_elem_volume);
299  // update the variable data referenced by other kernels.
300  // Note that this will update the values at the quadrature points too
301  // (because this is an Elemental variable)
302  _var.setNodalValue(value);
303  }
304  else /* high-order */
305  {
306  _local_re.resize(_n_local_dofs);
307  _local_re.zero();
308  _local_ke.resize(_n_local_dofs, _n_local_dofs);
309  _local_ke.zero();
310 
311  // assemble the local mass matrix and the load
312  for (unsigned int i = 0; i < _test.size(); i++)
313  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
314  {
315  ComputeValueType t = _JxW[_qp] * _coord[_qp] * _test[i][_qp];
316  _local_re(i) += t * computeValue();
317  for (unsigned int j = 0; j < _test.size(); j++)
318  _local_ke(i, j) += t * _test[j][_qp];
319  }
320 
321  // mass matrix is always SPD
322  _local_sol.resize(_n_local_dofs);
323  _local_ke.cholesky_solve(_local_re, _local_sol);
324 
325  _var.setDofValues(_local_sol);
326  }
327  }
328 }
329 
330 // Explicitly instantiates the two versions of the AuxKernelTempl class
331 template class AuxKernelTempl<Real>;
332 template class AuxKernelTempl<RealVectorValue>;
InputParameters validParams< MaterialPropertyInterface >()
Interface for objects that need parallel consistent random numbers without patterns over the course o...
VarFieldType
Definition: MooseTypes.h:488
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
virtual const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValue(const std::string &name, const std::string &vector_name)
Return the scatter value for the post processor.
A class for creating restricted objects.
Definition: Restartable.h:29
InputParameters validParams< BlockRestrictable >()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Retrieve the value of the Postprocessor.
virtual const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name)
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:84
InputParameters validParams< SetupInterface >()
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:25
const ExecFlagType EXEC_TIMESTEP_END
virtual const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string &name, const std::string &vector_name) override
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
Definition: AuxKernel.C:181
Base class for a system (of equations)
Definition: SystemBase.h:92
InputParameters validParams< VectorAuxKernel >()
Definition: AuxKernel.C:63
virtual const VariableValue & coupledDotDu(const std::string &var_name, unsigned int comp=0) override
Time derivative of a coupled variable with respect to the coefficients.
Definition: AuxKernel.C:263
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
const PostprocessorValue & getPostprocessorValue(const std::string &name)
Retrieve the value of a Postprocessor or one of it&#39;s old or older values.
virtual const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValue(const std::string &name, const std::string &vector_name) override
Return the scatter value for the post processor.
Definition: AuxKernel.C:220
virtual const PostprocessorValue & getPostprocessorValue(const std::string &name)
Definition: AuxKernel.C:165
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) override
Time derivative of a coupled variable.
Definition: AuxKernel.C:250
void coupledCallback(const std::string &var_name, bool is_old) override
Definition: AuxKernel.C:238
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual void compute()
Computes the value and stores it in the solution vector.
Definition: AuxKernel.C:276
MooseVariableFE< ComputeValueType > * mooseVariable() const
Get the variable that this object is using.
Interface for objects that needs transient capabilities.
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Definition: AuxKernel.C:173
Interface for notifications that the mesh has changed.
virtual const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
Definition: AuxKernel.C:143
InputParameters validParams< RandomInterface >()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
virtual const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueByName(const std::string &name, const std::string &vector_name) override
Return the scatter value for the post processor.
Definition: AuxKernel.C:229
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:154
InputParameters validParams< MeshChangedInterface >()
AuxKernelTempl(const InputParameters &parameters)
Definition: AuxKernel.C:71
Interface for objects that need to use UserObjects.
const ExecFlagType EXEC_LINEAR
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
Definition: AuxKernel.C:150
virtual const ScatterVectorPostprocessorValue & getScatterVectorPostprocessorValueByName(const std::string &name, const std::string &vector_name)
Return the scatter value for the post processor.
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:197
const ExecFlagType EXEC_PRE_DISPLACE
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:155
Real ScatterVectorPostprocessorValue
Definition: MooseTypes.h:156
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
An interface for accessing Materials.
const UserObject & getUserObjectBase(const std::string &name)
Definition: AuxKernel.C:157
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
InputParameters validParams< BoundaryRestrictable >()
virtual const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &, const std::string &vector_name) override
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
Definition: AuxKernel.C:190
Intermediate base class that ties together all the interfaces for getting MooseVariableFEBases with t...
Interface for objects that need to get values of MooseVariables.
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string &name, const std::string &vector_name)
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
Interface for sorting dependent vectors of objects.
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:33
Definition: Moose.h:112
std::set< std::string > _depend_vars
Depend AuxKernelTempls.
Definition: AuxKernel.h:222
virtual const VariableValue & coupledDotDu(const std::string &var_name, unsigned int comp=0)
Time derivative of a coupled variable with respect to the coefficients.
Definition: Coupleable.C:840
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0)
Time derivative of a coupled variable.
Definition: Coupleable.C:624
std::set< std::string > _supplied_vars
Definition: AuxKernel.h:223
const UserObject & getUserObjectBase(const std::string &name)
Get an user object with a given parameter name.
Interface for objects that need to use functions.
A system that holds auxiliary variables.
const std::map< std::string, std::vector< MooseVariableFEBase * > > & getCoupledVars()
Get the list of coupled variables.
Definition: Coupleable.h:81
Base class for user-specific data.
Definition: UserObject.h:37
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:161