https://mooseframework.inl.gov
AuxKernelBase.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 "AuxKernelBase.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 
21 {
25  params += RandomInterface::validParams();
30 
31  // Add the SetupInterface parameter 'execute_on' with 'linear' and 'timestep_end'
32  params += SetupInterface::validParams();
33  ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
35  exec_enum = {EXEC_LINEAR, EXEC_TIMESTEP_END};
36  params.setDocString("execute_on", exec_enum.getDocString());
37 
38  params.addRequiredParam<AuxVariableName>("variable",
39  "The name of the variable that this object applies to");
40 
41  params.addParam<bool>("use_displaced_mesh",
42  false,
43  "Whether or not this object should use the "
44  "displaced mesh for computation. Note that "
45  "in the case this is true but no "
46  "displacements are provided in the Mesh block "
47  "the undisplaced mesh will still be used.");
48  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
49  params.addParam<bool>("check_boundary_restricted",
50  true,
51  "Whether to check for multiple element sides on the boundary "
52  "in the case of a boundary restricted, element aux variable. "
53  "Setting this to false will allow contribution to a single element's "
54  "elemental value(s) from multiple boundary sides on the same element "
55  "(example: when the restricted boundary exists on two or more sides "
56  "of an element, such as at a corner of a mesh");
57 
58  params.addRelationshipManager("GhostLowerDElems",
61 
62  params.declareControllable("enable"); // allows Control to enable/disable this type of object
63  params.registerSystemAttributeName("AuxKernel");
64 
65  params.registerBase("AuxKernel");
66 
67  return params;
68 }
69 
71  : MooseObject(parameters),
72  BlockRestrictable(this),
73  BoundaryRestrictable(this, getVariableHelper(parameters).isNodal()),
74  SetupInterface(this),
76  getVariableHelper(parameters).isNodal()),
77  FunctionInterface(this),
78  UserObjectInterface(this),
79  TransientInterface(this),
80  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
83  RandomInterface(parameters,
84  *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
85  parameters.get<THREAD_ID>("_tid"),
86  getVariableHelper(parameters).isNodal()),
88  Restartable(this, "AuxKernels"),
89  MeshChangedInterface(parameters),
91  ElementIDInterface(this),
93 
94  _var(getVariableHelper(parameters)),
95  _bnd(boundaryRestricted()),
96  _check_boundary_restricted(getParam<bool>("check_boundary_restricted")),
97  _coincident_lower_d_calc(_bnd && !_var.isNodal() && _var.isLowerD()),
98  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
99  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
100  _nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
101  _aux_sys(static_cast<AuxiliarySystem &>(_sys)),
102  _tid(parameters.get<THREAD_ID>("_tid")),
103  _assembly(_subproblem.assembly(_tid, 0)),
104  _mesh(_subproblem.mesh())
105 {
107  _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
108 
110  {
111  // when the variable is elemental and this aux kernel operates on boundaries,
112  // we need to check that no elements are visited more than once through visiting
113  // all the sides on the boundaries
114  auto boundaries = _mesh.getMesh().get_boundary_info().build_side_list();
115  std::set<dof_id_type> elements;
116  for (const auto & t : boundaries)
117  {
118  if (hasBoundary(std::get<2>(t)))
119  {
120  const auto eid = std::get<0>(t);
121  const auto stat = elements.insert(eid);
122  if (!stat.second) // already existed in the set
123  mooseError(
124  "Boundary restricted auxiliary kernel '",
125  name(),
126  "' has element (id=",
127  eid,
128  ") connected with more than one boundary sides.\nTo skip this error check, "
129  "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel "
130  "documentation on boundary restricted aux kernels for understanding this error.");
131  }
132  }
133  }
134 
135  // Check for supported variable types
136  // Any 'nodal' family that actually has DoFs outside of nodes, or gradient dofs at nodes is
137  // not properly set by AuxKernelTempl::compute
138  // NOTE: We could add a few exceptions, lower order from certain unsupported families and on
139  // certain element types only have value-DoFs on nodes
140  const auto type = _var.feType();
141  if (_var.isNodal() && !((type.family == LAGRANGE) || (type.order <= FIRST)))
142  paramError("variable",
143  "Variable family " + Moose::stringify(type.family) + " is not supported at order " +
144  Moose::stringify(type.order) + " by the AuxKernel system.");
145 }
146 
147 #ifdef MOOSE_KOKKOS_ENABLED
149  : MooseObject(object, key),
150  BlockRestrictable(object, key),
151  BoundaryRestrictable(object, key),
152  SetupInterface(object, key),
154  FunctionInterface(object, key),
155  UserObjectInterface(object, key),
156  TransientInterface(object, key),
157  MaterialPropertyInterface(object, key),
158  PostprocessorInterface(object, key),
159  DependencyResolverInterface(object, key),
160  RandomInterface(object, key),
161  GeometricSearchInterface(object, key),
162  Restartable(object, key),
163  MeshChangedInterface(object, key),
164  VectorPostprocessorInterface(object, key),
165  ElementIDInterface(object, key),
166  NonADFunctorInterface(object, key),
167 
168  _var(object._var),
169  _bnd(object._bnd),
170  _check_boundary_restricted(object._check_boundary_restricted),
171  _coincident_lower_d_calc(object._coincident_lower_d_calc),
172  _subproblem(object._subproblem),
173  _sys(object._sys),
174  _nl_sys(object._nl_sys),
175  _aux_sys(object._aux_sys),
176  _tid(object._tid),
177  _assembly(object._assembly),
178  _mesh(object._mesh)
179 {
180 }
181 #endif
182 
183 const std::set<std::string> &
185 {
186  return _depend_vars;
187 }
188 
189 const std::set<std::string> &
191 {
192  return _supplied_vars;
193 }
194 
195 void
196 AuxKernelBase::coupledCallback(const std::string & var_name, bool is_old) const
197 {
198  if (!is_old)
199  {
200  const auto & var_names = getParam<std::vector<VariableName>>(var_name);
201  _depend_vars.insert(var_names.begin(), var_names.end());
202  }
203 }
204 
205 void
207 {
208  _depend_uo.insert(uo.name());
209  for (const auto & indirect_dependent : uo.getDependObjects())
210  _depend_uo.insert(indirect_dependent);
211 }
212 
213 void
214 AuxKernelBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
215 {
216  getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
217 }
218 
219 void
220 AuxKernelBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
221 {
222  getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
223 }
224 
227 {
228  return parameters.getCheckedPointerParam<SystemBase *>("_sys")->getVariable(
229  parameters.get<THREAD_ID>("_tid"), parameters.get<AuxVariableName>("variable"));
230 }
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
Interface for objects that need parallel consistent random numbers without patterns over the course o...
LAGRANGE
virtual bool isNodal() const
Is this variable nodal.
const libMesh::FEType & feType() const
Get the type of finite element object.
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
A class for creating restricted objects.
Definition: Restartable.h:28
Base class for auxiliary kernels.
Definition: AuxKernelBase.h:42
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
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:439
MooseVariableFieldBase & _var
Base MooseVariable.
Definition: AuxKernelBase.h:85
void setDocString(const std::string &name, const std::string &doc)
Set the doc string of a parameter.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
AuxKernelBase(const InputParameters &parameters)
Definition: AuxKernelBase.C:70
FIRST
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
void coupledCallback(const std::string &var_name, bool is_old) const override
A call-back function provided by the derived object for actions before coupling a variable with funct...
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
MeshBase & mesh
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::set< std::string > _supplied_vars
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
static InputParameters validParams()
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Definition: ExecFlagEnum.h:82
static InputParameters validParams()
This class provides an interface for common operations on field variables of both FE and FV types wit...
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
Base class for a system (of equations)
Definition: SystemBase.h:84
MooseMesh & _mesh
Mesh this kernel is active on.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const bool _bnd
true if the kernel is boundary kernel, false if it is interior kernels
Definition: AuxKernelBase.h:88
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...
static InputParameters validParams()
void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
Interface for objects that needs transient capabilities.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
static InputParameters validParams()
const bool _check_boundary_restricted
Whether or not to check for repeated element sides on the sideset to which the auxkernel is restricte...
Definition: AuxKernelBase.h:98
Interface for notifications that the mesh has changed.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3528
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
static InputParameters validParams()
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
Definition: ExecFlagEnum.C:40
Interface for objects that need to use UserObjects.
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
Definition: UserObject.C:100
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:31
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
void addPostprocessorDependencyHelper(const PostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a Postprocessor is requested...
static InputParameters validParams()
static InputParameters validParams()
static InputParameters validParams()
Definition: AuxKernelBase.C:20
bool hasBoundary(const BoundaryName &name) const
Test if the supplied boundary name is valid for this object.
const ExecFlagType EXEC_PRE_DISPLACE
Definition: Moose.C:52
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
An interface for accessing Materials.
void addUserObjectDependencyHelper(const UserObject &uo) const override final
Helper for deriving classes to override to add dependencies when a UserObject is requested.
Intermediate base class that ties together all the interfaces for getting MooseVariableFEBases with t...
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
Interface for sorting dependent vectors of objects.
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...
const UserObject & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
static InputParameters validParams()
Definition: MooseObject.C:25
std::set< UserObjectName > _depend_uo
Depend UserObjects.
static InputParameters validParams()
std::set< std::string > _depend_vars
Depend AuxKernelTempls.
bool boundaryRestricted(const std::set< BoundaryID > &boundary_ids)
Interface for objects that need to use functions.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
A system that holds auxiliary variables.
Base class for user-specific data.
Definition: UserObject.h:40
const Elem & get(const ElemType type_in)
MooseVariableFieldBase & getVariableHelper(const InputParameters &parameters)
Get MooseVariable of base type from parameter.
Interface class for classes which interact with Postprocessors.
const bool _coincident_lower_d_calc
Whether we are computing for a lower dimensional variable using boundary restriction, e.g.
unsigned int THREAD_ID
Definition: MooseTypes.h:237
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...