www.mooseframework.org
AuxKernel.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 "AuxKernel.h"
16 
17 // local includes
18 #include "FEProblem.h"
19 #include "SubProblem.h"
20 #include "AuxiliarySystem.h"
21 #include "MooseTypes.h"
22 #include "Assembly.h"
23 
24 #include "libmesh/numeric_vector.h"
25 #include "libmesh/dof_map.h"
26 #include "libmesh/quadrature.h"
27 
28 template <>
31 {
35  params += validParams<RandomInterface>();
38 
39  // Add the SetupInterface parameter, 'execute_on', the default is 'linear'
40  params += validParams<SetupInterface>();
41 
42  params.addRequiredParam<AuxVariableName>("variable",
43  "The name of the variable that this object applies to");
44 
45  params.addParam<bool>("use_displaced_mesh",
46  false,
47  "Whether or not this object should use the "
48  "displaced mesh for computation. Note that "
49  "in the case this is true but no "
50  "displacements are provided in the Mesh block "
51  "the undisplaced mesh will still be used.");
52  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
53 
54  // This flag is set to true if the AuxKernel is being used on a boundary
55  params.addPrivateParam<bool>("_on_boundary", false);
56 
57  params.declareControllable("enable"); // allows Control to enable/disable this type of object
58  params.registerBase("AuxKernel");
59 
60  return params;
61 }
62 
64  : MooseObject(parameters),
65  BlockRestrictable(this),
67  parameters.get<AuxiliarySystem *>("_aux_sys")
68  ->getVariable(parameters.get<THREAD_ID>("_tid"),
69  parameters.get<AuxVariableName>("variable"))
70  .isNodal()),
71  SetupInterface(this),
73  this,
74  parameters.get<AuxiliarySystem *>("_aux_sys")
75  ->getVariable(parameters.get<THREAD_ID>("_tid"),
76  parameters.get<AuxVariableName>("variable"))
77  .isNodal()),
78  FunctionInterface(this),
79  UserObjectInterface(this),
80  TransientInterface(this),
81  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
84  RandomInterface(parameters,
85  *parameters.get<FEProblemBase *>("_fe_problem_base"),
86  parameters.get<THREAD_ID>("_tid"),
87  parameters.get<AuxiliarySystem *>("_aux_sys")
88  ->getVariable(parameters.get<THREAD_ID>("_tid"),
89  parameters.get<AuxVariableName>("variable"))
90  .isNodal()),
92  Restartable(parameters, "AuxKernels"),
93  ZeroInterface(parameters),
94  MeshChangedInterface(parameters),
96  _subproblem(*parameters.get<SubProblem *>("_subproblem")),
97  _sys(*parameters.get<SystemBase *>("_sys")),
98  _nl_sys(*parameters.get<SystemBase *>("_nl_sys")),
99  _aux_sys(*parameters.get<AuxiliarySystem *>("_aux_sys")),
100  _tid(parameters.get<THREAD_ID>("_tid")),
101  _assembly(_subproblem.assembly(_tid)),
102 
103  _var(_aux_sys.getVariable(_tid, parameters.get<AuxVariableName>("variable"))),
104  _nodal(_var.isNodal()),
105  _bnd(boundaryRestricted()),
106 
107  _mesh(_subproblem.mesh()),
108 
109  _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
110  _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
111  _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
112  _coord(_assembly.coordTransformation()),
113 
114  _u(_nodal ? _var.nodalSln() : _var.sln()),
115  _u_old(_nodal ? _var.nodalSlnOld() : _var.slnOld()),
116  _u_older(_nodal ? _var.nodalSlnOlder() : _var.slnOlder()),
117  _test(_var.phi()),
118 
119  _current_elem(_var.currentElem()),
120  _current_side(_var.currentSide()),
121  _current_elem_volume(_assembly.elemVolume()),
122  _current_side_volume(_assembly.sideElemVolume()),
123 
124  _current_node(_assembly.node()),
125 
126  _solution(_aux_sys.solution())
127 {
128  _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
129 
130  std::map<std::string, std::vector<MooseVariable *>> coupled_vars = getCoupledVars();
131  for (const auto & it : coupled_vars)
132  for (const auto & var : it.second)
133  _depend_vars.insert(var->name());
134 }
135 
137 
138 const std::set<std::string> &
140 {
141  return _depend_vars;
142 }
143 
144 const std::set<std::string> &
146 {
147  return _supplied_vars;
148 }
149 
150 const UserObject &
151 AuxKernel::getUserObjectBase(const std::string & name)
152 {
153  _depend_uo.insert(_pars.get<UserObjectName>(name));
155 }
156 
157 const PostprocessorValue &
159 {
160  _depend_uo.insert(_pars.get<PostprocessorName>(name));
162 }
163 
164 const PostprocessorValue &
166 {
167  _depend_uo.insert(name);
169 }
170 
172 AuxKernel::getVectorPostprocessorValue(const std::string & name, const std::string & vector_name)
173 {
174  _depend_uo.insert(_pars.get<VectorPostprocessorName>(name));
176 }
177 
179 AuxKernel::getVectorPostprocessorValueByName(const VectorPostprocessorName & name,
180  const std::string & vector_name)
181 {
182  _depend_uo.insert(name);
184 }
185 
186 void
187 AuxKernel::coupledCallback(const std::string & var_name, bool is_old)
188 {
189  if (is_old)
190  {
191  std::vector<VariableName> var_names = getParam<std::vector<VariableName>>(var_name);
192  for (const auto & name : var_names)
193  _depend_vars.erase(name);
194  }
195 }
196 
197 void
199 {
201 
202  if (isNodal()) /* nodal variables */
203  {
204  if (_var.isNodalDefined())
205  {
206  _qp = 0;
207  Real value = computeValue();
208  // update variable data, which is referenced by other kernels, so the value is up-to-date
209  _var.setNodalValue(value);
210  }
211  }
212  else /* elemental variables */
213  {
215 
216  if (_n_local_dofs == 1) /* p0 */
217  {
218  Real value = 0;
219  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
220  value += _JxW[_qp] * _coord[_qp] * computeValue();
222  // update the variable data refernced by other kernels.
223  // Note that this will update the values at the quadrature points too
224  // (because this is an Elemental variable)
225  _var.setNodalValue(value);
226  }
227  else /* high-order */
228  {
229  _local_re.resize(_n_local_dofs);
230  _local_re.zero();
232  _local_ke.zero();
233 
234  // assemble the local mass matrix and the load
235  for (unsigned int i = 0; i < _test.size(); i++)
236  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
237  {
238  Real t = _JxW[_qp] * _coord[_qp] * _test[i][_qp];
239  _local_re(i) += t * computeValue();
240  for (unsigned int j = 0; j < _test.size(); j++)
241  _local_ke(i, j) += t * _test[j][_qp];
242  }
243 
244  // mass matrix is always SPD
245  _local_sol.resize(_n_local_dofs);
246  _local_ke.cholesky_solve(_local_re, _local_sol);
247 
249  }
250  }
251 }
252 
253 const VariableValue &
254 AuxKernel::coupledDot(const std::string & var_name, unsigned int comp)
255 {
256  MooseVariable * var = getVar(var_name, comp);
257  if (var->kind() == Moose::VAR_AUXILIARY)
258  mooseError(
259  name(),
260  ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
261 
262  return Coupleable::coupledDot(var_name, comp);
263 }
264 
265 const VariableValue &
266 AuxKernel::coupledDotDu(const std::string & var_name, unsigned int comp)
267 {
268  MooseVariable * var = getVar(var_name, comp);
269  if (var->kind() == Moose::VAR_AUXILIARY)
270  mooseError(
271  name(),
272  ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
273 
274  return Coupleable::coupledDotDu(var_name, comp);
275 }
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...
virtual Real computeValue()=0
A class for creating restricted objects.
Definition: Restartable.h:31
DenseMatrix< Number > _local_ke
for holding local mass matrix
Definition: AuxKernel.h:209
const MooseArray< Real > & _coord
Definition: AuxKernel.h:164
Class for stuff related to variables.
Definition: MooseVariable.h:43
InputParameters validParams< BlockRestrictable >()
DenseVector< Number > _local_re
for holding local load
Definition: AuxKernel.h:205
virtual void precalculateValue()
This callback is used for AuxKernels that need to perform a per-element calculation.
Definition: AuxKernel.h:135
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:266
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Retrieve the value of the Postprocessor.
unsigned int numberOfDofs()
virtual const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name)
Retrieve the value of the VectorPostprocessor.
QBase *& _qrule
Quadrature rule being used.
Definition: AuxKernel.h:161
unsigned int _n_local_dofs
number of local dofs for elemental variables
Definition: AuxKernel.h:202
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...
const UserObject & getUserObjectBase(const std::string &name)
Definition: AuxKernel.C:151
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled variable.
Definition: Coupleable.C:117
virtual const PostprocessorValue & getPostprocessorValue(const std::string &name)
Definition: AuxKernel.C:158
InputParameters validParams< SetupInterface >()
InputParameters validParams< AuxKernel >()
Definition: AuxKernel.C:30
virtual const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &, const std::string &vector_name) override
Retrieve the value of the VectorPostprocessor.
Definition: AuxKernel.C:179
void coupledCallback(const std::string &var_name, bool is_old) override
Definition: AuxKernel.C:187
Base class for a system (of equations)
Definition: SystemBase.h:91
const Real & _current_elem_volume
Volume of the current element.
Definition: AuxKernel.h:181
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...
DenseVector< Number > _local_sol
for holding local solution
Definition: AuxKernel.h:207
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 std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
Definition: AuxKernel.C:139
bool _bnd
true if the kernel is boundary kernel, false if it is interior kernels
Definition: AuxKernel.h:152
const std::map< std::string, std::vector< MooseVariable * > > & getCoupledVars()
Get the list of coupled variables.
Definition: Coupleable.h:54
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
void setNodalValue(Number value, unsigned int idx=0)
Set the nodal value for this variable to keep everything up to date.
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:73
InputParameters validParams< MeshChangedInterface >()
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name)
Definition: AuxKernel.C:165
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
Definition: AuxKernel.C:145
bool isNodal()
Nodal or elemental kernel?
Definition: AuxKernel.h:89
unsigned int _qp
Quadrature point index.
Definition: AuxKernel.h:192
Interface for objects that need to use UserObjects.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:111
const Real & _current_side_volume
Volume of the current side.
Definition: AuxKernel.h:183
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
Definition: AuxKernel.h:163
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:22
const VariableTestValue & _test
holds the the test functions
Definition: AuxKernel.h:173
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:74
virtual ~AuxKernel()
Definition: AuxKernel.C:136
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
Interface to bring zero values inside objects.
Definition: ZeroInterface.h:35
An interface for accessing Materials.
virtual const VariableValue & value()
The value of the variable this object is operating on.
InputParameters validParams< BoundaryRestrictable >()
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.
virtual const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string &name, const std::string &vector_name)
Retrieve the value of a VectorPostprocessor.
Interface for sorting dependent vectors of objects.
virtual const VectorPostprocessorValue & getVectorPostprocessorValue(const std::string &name, const std::string &vector_name) override
Retrieve the value of a VectorPostprocessor.
Definition: AuxKernel.C:172
std::set< std::string > _depend_vars
Depend AuxKernels.
Definition: AuxKernel.h:195
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
AuxKernel(const InputParameters &parameters)
Definition: AuxKernel.C:63
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:320
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0)
Time derivative of a coupled variable.
Definition: Coupleable.C:296
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) override
Time derivative of a coupled variable.
Definition: AuxKernel.C:254
const UserObject & getUserObjectBase(const std::string &name)
Get an user object with a given parameter name.
MooseVariable & _var
Variable this kernel is acting on.
Definition: AuxKernel.h:148
Interface for objects that need to use functions.
std::set< std::string > _depend_uo
Depend UserObjects.
Definition: AuxKernel.h:199
A system that holds auxiliary variables.
virtual void compute()
Computes the value and stores it in the solution vector.
Definition: AuxKernel.C:198
std::set< std::string > _supplied_vars
Definition: AuxKernel.h:196
Base class for user-specific data.
Definition: UserObject.h:42
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
bool isNodalDefined()