https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
30
31 // Add the SetupInterface parameter 'execute_on' with 'linear' and 'timestep_end'
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
64 params.registerBase("AuxKernel");
65
66 return params;
67}
68
70 : MooseObject(parameters),
72 BoundaryRestrictable(this, getVariableHelper(parameters).isNodal()),
73 SetupInterface(this),
75 getVariableHelper(parameters).isNodal()),
79 MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
82 RandomInterface(parameters,
83 *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
84 parameters.get<THREAD_ID>("_tid"),
85 getVariableHelper(parameters).isNodal()),
87 Restartable(this, "AuxKernels"),
88 MeshChangedInterface(parameters),
92
93 _var(getVariableHelper(parameters)),
94 _bnd(boundaryRestricted()),
95 _check_boundary_restricted(getParam<bool>("check_boundary_restricted")),
96 _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
97 _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
98 _nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
99 _aux_sys(static_cast<AuxiliarySystem &>(_sys)),
100 _tid(parameters.get<THREAD_ID>("_tid")),
101 _assembly(_subproblem.assembly(_tid, 0)),
102 _mesh(_subproblem.mesh())
103{
104 // Propagation of the aux kernel value into the auxiliary system must go through a presized
105 // MooseArray that is only properfly sized for FV variables if we're doing "qp" calculations. I'm
106 // quoting "qp" because it's a briefer metaphorical representation (perhaps not a good one) of the
107 // more precise requirement that variable data be pre-sized/operator[] indexable
109
111 _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
112
113 // Check for supported variable types
114 // Any 'nodal' family that actually has DoFs outside of nodes, or gradient dofs at nodes is
115 // not properly set by AuxKernelTempl::compute
116 // NOTE: We could add a few exceptions, lower order from certain unsupported families and on
117 // certain element types only have value-DoFs on nodes
118 const auto type = _var.feType();
119 if (_var.isNodal() && !((type.family == LAGRANGE) || (type.order <= FIRST)))
120 paramError("variable",
121 "Variable family " + Moose::stringify(type.family) + " is not supported at order " +
122 Moose::stringify(type.order) + " by the AuxKernel system.");
123}
124
125#ifdef MOOSE_KOKKOS_ENABLED
127 : MooseObject(object, key),
128 BlockRestrictable(object, key),
129 BoundaryRestrictable(object, key),
130 SetupInterface(object, key),
132 FunctionInterface(object, key),
133 UserObjectInterface(object, key),
134 TransientInterface(object, key),
135 MaterialPropertyInterface(object, key),
136 PostprocessorInterface(object, key),
137 DependencyResolverInterface(object, key),
138 RandomInterface(object, key),
139 GeometricSearchInterface(object, key),
140 Restartable(object, key),
141 MeshChangedInterface(object, key),
142 VectorPostprocessorInterface(object, key),
143 ElementIDInterface(object, key),
144 NonADFunctorInterface(object, key),
145
146 _var(object._var),
147 _bnd(object._bnd),
148 _check_boundary_restricted(object._check_boundary_restricted),
149 _subproblem(object._subproblem),
150 _sys(object._sys),
151 _nl_sys(object._nl_sys),
152 _aux_sys(object._aux_sys),
153 _tid(object._tid),
154 _assembly(object._assembly),
155 _mesh(object._mesh)
156{
157}
158#endif
159
160void
162{
163 // This check must occur after the EquationSystems object has been init'd (due to calls to
164 // Elem::n_dofs()) so we can't do it in the constructor
166 {
167 // when the variable is elemental and this aux kernel operates on boundaries,
168 // we need to check that no elements are visited more than once through visiting
169 // all the sides on the boundaries
170 auto boundaries = _mesh.getMesh().get_boundary_info().build_side_list();
171 std::set<dof_id_type> element_ids;
172 for (const auto & [elem_id, _, boundary_id] : boundaries)
173 {
174 if (hasBoundary(boundary_id) && _mesh.elemPtr(elem_id)->n_dofs(_sys.number(), _var.number()))
175 {
176 const auto [_, inserted] = element_ids.insert(elem_id);
177 if (!inserted) // already existed in the set
179 "Boundary restricted auxiliary kernel '",
180 name(),
181 "' has element (id=",
182 elem_id,
183 ") connected with more than one boundary sides.\nTo skip this error check, "
184 "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel "
185 "documentation on boundary restricted aux kernels for understanding this error.");
186 }
187 }
188 }
189}
190
191const std::set<std::string> &
196
197const std::set<std::string> &
202
203void
204AuxKernelBase::coupledCallback(const std::string & var_name, bool is_old) const
205{
206 if (!is_old)
207 {
208 const auto & var_names = getParam<std::vector<VariableName>>(var_name);
209 _depend_vars.insert(var_names.begin(), var_names.end());
210 }
211}
212
213void
215{
216 _depend_uo.insert(uo.name());
217 for (const auto & indirect_dependent : uo.getDependObjects())
218 _depend_uo.insert(indirect_dependent);
219}
220
221void
222AuxKernelBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
223{
224 getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
225}
226
227void
228AuxKernelBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
229{
230 getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
231}
232
235{
236 return parameters.getCheckedPointerParam<SystemBase *>("_sys")->getVariable(
237 parameters.get<THREAD_ID>("_tid"), parameters.get<AuxVariableName>("variable"));
238}
unsigned int THREAD_ID
Definition MooseTypes.h:237
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
const ExecFlagType EXEC_PRE_DISPLACE
Definition Moose.C:54
Base class for auxiliary kernels.
MooseVariableFieldBase & getVariableHelper(const InputParameters &parameters)
Get MooseVariable of base type from parameter.
std::set< UserObjectName > _depend_uo
Depend UserObjects.
std::set< std::string > _supplied_vars
AuxKernelBase(const InputParameters &parameters)
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...
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...
void addPostprocessorDependencyHelper(const PostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a Postprocessor is requested.
SystemBase & _sys
System this kernel is part of.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
const bool _bnd
true if the kernel is boundary kernel, false if it is interior kernels
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
virtual const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested.
void addUserObjectDependencyHelper(const UserObjectBase &uo) const override final
Helper for deriving classes to override to add dependencies when a UserObject is requested.
MooseVariableFieldBase & _var
Base MooseVariable.
MooseMesh & _mesh
Mesh this kernel is active on.
std::set< std::string > _depend_vars
Depend AuxKernelTempls.
A system that holds auxiliary variables.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
static InputParameters validParams()
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
bool hasBoundary(const BoundaryName &name) const
Test if the supplied boundary name is valid for this object.
static InputParameters validParams()
Intermediate base class that ties together all the interfaces for getting MooseVariableFEBases with t...
Interface for sorting dependent vectors of objects.
A MultiMooseEnum object to hold "execute_on" flags.
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Interface for objects that need to use functions.
static InputParameters validParams()
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
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...
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.
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...
void setDocString(const std::string &name, const std::string &doc)
Set the doc string of a parameter.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
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.
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.
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.
An interface for accessing Materials.
static InputParameters validParams()
Interface for notifications that the mesh has changed.
static InputParameters validParams()
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:457
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
virtual Elem * elemPtr(const dof_id_type i)
Definition MooseMesh.C:3214
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
static InputParameters validParams()
Definition MooseObject.C:25
const libMesh::FEType & feType() const
Get the type of finite element object.
virtual bool isNodal() const
Is this variable nodal.
unsigned int number() const
Get variable number coming from libMesh.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void requireQpComputations() const
Request that quadrature point data be (pre)computed.
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
Interface class for classes which interact with Postprocessors.
Interface for objects that need parallel consistent random numbers without patterns over the course o...
static InputParameters validParams()
A class for creating restricted objects.
Definition Restartable.h:29
static InputParameters validParams()
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
Base class for a system (of equations)
Definition SystemBase.h:87
unsigned int number() const
Gets the number of this system.
Interface for objects that needs transient capabilities.
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
Interface for objects that need to use UserObjects.
const UserObjectBase & getUserObjectBaseByName(const UserObjectName &object_name, bool is_dependency=true) const
Get an user object with the name object_name.
MeshBase & mesh
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64