Line data Source code
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 :
19 : InputParameters
20 601116 : AuxKernelBase::validParams()
21 : {
22 601116 : InputParameters params = MooseObject::validParams();
23 601116 : params += BlockRestrictable::validParams();
24 601116 : params += BoundaryRestrictable::validParams();
25 601116 : params += RandomInterface::validParams();
26 601116 : params += MeshChangedInterface::validParams();
27 601116 : params += MaterialPropertyInterface::validParams();
28 601116 : params += FunctorInterface::validParams();
29 601116 : params += GeometricSearchInterface::validParams();
30 :
31 : // Add the SetupInterface parameter 'execute_on' with 'linear' and 'timestep_end'
32 601116 : params += SetupInterface::validParams();
33 601116 : ExecFlagEnum & exec_enum = params.set<ExecFlagEnum>("execute_on", true);
34 601116 : exec_enum.addAvailableFlags(EXEC_PRE_DISPLACE);
35 1803348 : exec_enum = {EXEC_LINEAR, EXEC_TIMESTEP_END};
36 1803348 : params.setDocString("execute_on", exec_enum.getDocString());
37 :
38 2404464 : params.addRequiredParam<AuxVariableName>("variable",
39 : "The name of the variable that this object applies to");
40 :
41 1803348 : params.addParam<bool>("use_displaced_mesh",
42 1202232 : 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 2404464 : params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
49 1202232 : params.addParam<bool>("check_boundary_restricted",
50 1202232 : 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 1803348 : params.addRelationshipManager("GhostLowerDElems",
59 : Moose::RelationshipManagerType::GEOMETRIC |
60 : Moose::RelationshipManagerType::ALGEBRAIC);
61 :
62 1803348 : params.declareControllable("enable"); // allows Control to enable/disable this type of object
63 :
64 601116 : params.registerBase("AuxKernel");
65 :
66 601116 : return params;
67 601116 : }
68 :
69 71180 : AuxKernelBase::AuxKernelBase(const InputParameters & parameters)
70 : : MooseObject(parameters),
71 : BlockRestrictable(this),
72 71177 : BoundaryRestrictable(this, getVariableHelper(parameters).isNodal()),
73 : SetupInterface(this),
74 : CoupleableMooseVariableDependencyIntermediateInterface(this,
75 71177 : getVariableHelper(parameters).isNodal()),
76 : FunctionInterface(this),
77 : UserObjectInterface(this),
78 : TransientInterface(this),
79 : MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
80 : PostprocessorInterface(this),
81 : DependencyResolverInterface(),
82 : RandomInterface(parameters,
83 284708 : *parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"),
84 71177 : parameters.get<THREAD_ID>("_tid"),
85 71177 : getVariableHelper(parameters).isNodal()),
86 : GeometricSearchInterface(this),
87 : Restartable(this, "AuxKernels"),
88 : MeshChangedInterface(parameters),
89 : VectorPostprocessorInterface(this),
90 : ElementIDInterface(this),
91 : NonADFunctorInterface(this),
92 :
93 142354 : _var(getVariableHelper(parameters)),
94 71177 : _bnd(boundaryRestricted()),
95 142354 : _check_boundary_restricted(getParam<bool>("check_boundary_restricted")),
96 284708 : _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
97 284708 : _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
98 284708 : _nl_sys(*getCheckedPointerParam<SystemBase *>("_nl_sys")),
99 71177 : _aux_sys(static_cast<AuxiliarySystem &>(_sys)),
100 71177 : _tid(parameters.get<THREAD_ID>("_tid")),
101 71177 : _assembly(_subproblem.assembly(_tid, 0)),
102 711773 : _mesh(_subproblem.mesh())
103 : {
104 71177 : addMooseVariableDependency(&_var);
105 71177 : _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
106 :
107 : // Check for supported variable types
108 : // Any 'nodal' family that actually has DoFs outside of nodes, or gradient dofs at nodes is
109 : // not properly set by AuxKernelTempl::compute
110 : // NOTE: We could add a few exceptions, lower order from certain unsupported families and on
111 : // certain element types only have value-DoFs on nodes
112 71177 : const auto type = _var.feType();
113 71177 : if (_var.isNodal() && !((type.family == LAGRANGE) || (type.order <= FIRST)))
114 0 : paramError("variable",
115 0 : "Variable family " + Moose::stringify(type.family) + " is not supported at order " +
116 0 : Moose::stringify(type.order) + " by the AuxKernel system.");
117 71177 : }
118 :
119 : #ifdef MOOSE_KOKKOS_ENABLED
120 25510 : AuxKernelBase::AuxKernelBase(const AuxKernelBase & object, const Moose::Kokkos::FunctorCopy & key)
121 : : MooseObject(object, key),
122 : BlockRestrictable(object, key),
123 : BoundaryRestrictable(object, key),
124 : SetupInterface(object, key),
125 : CoupleableMooseVariableDependencyIntermediateInterface(object, key),
126 : FunctionInterface(object, key),
127 : UserObjectInterface(object, key),
128 : TransientInterface(object, key),
129 : MaterialPropertyInterface(object, key),
130 : PostprocessorInterface(object, key),
131 : DependencyResolverInterface(object, key),
132 : RandomInterface(object, key),
133 : GeometricSearchInterface(object, key),
134 : Restartable(object, key),
135 : MeshChangedInterface(object, key),
136 : VectorPostprocessorInterface(object, key),
137 : ElementIDInterface(object, key),
138 : NonADFunctorInterface(object, key),
139 :
140 25510 : _var(object._var),
141 25510 : _bnd(object._bnd),
142 25510 : _check_boundary_restricted(object._check_boundary_restricted),
143 25510 : _subproblem(object._subproblem),
144 25510 : _sys(object._sys),
145 25510 : _nl_sys(object._nl_sys),
146 25510 : _aux_sys(object._aux_sys),
147 25510 : _tid(object._tid),
148 25510 : _assembly(object._assembly),
149 25510 : _mesh(object._mesh)
150 : {
151 25510 : }
152 : #endif
153 :
154 : void
155 68531 : AuxKernelBase::initialSetup()
156 : {
157 : // This check must occur after the EquationSystems object has been init'd (due to calls to
158 : // Elem::n_dofs()) so we can't do it in the constructor
159 68531 : if (_bnd && !_var.isNodal() && _check_boundary_restricted)
160 : {
161 : // when the variable is elemental and this aux kernel operates on boundaries,
162 : // we need to check that no elements are visited more than once through visiting
163 : // all the sides on the boundaries
164 1339 : auto boundaries = _mesh.getMesh().get_boundary_info().build_side_list();
165 1339 : std::set<dof_id_type> element_ids;
166 173462 : for (const auto & [elem_id, _, boundary_id] : boundaries)
167 : {
168 172126 : if (hasBoundary(boundary_id) && _mesh.elemPtr(elem_id)->n_dofs(_sys.number(), _var.number()))
169 : {
170 63169 : const auto [_, inserted] = element_ids.insert(elem_id);
171 63169 : if (!inserted) // already existed in the set
172 3 : mooseError(
173 : "Boundary restricted auxiliary kernel '",
174 3 : name(),
175 : "' has element (id=",
176 : elem_id,
177 : ") connected with more than one boundary sides.\nTo skip this error check, "
178 : "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel "
179 : "documentation on boundary restricted aux kernels for understanding this error.");
180 : }
181 : }
182 1336 : }
183 68528 : }
184 :
185 : const std::set<std::string> &
186 231797 : AuxKernelBase::getRequestedItems()
187 : {
188 231797 : return _depend_vars;
189 : }
190 :
191 : const std::set<std::string> &
192 231797 : AuxKernelBase::getSuppliedItems()
193 : {
194 231797 : return _supplied_vars;
195 : }
196 :
197 : void
198 8618 : AuxKernelBase::coupledCallback(const std::string & var_name, bool is_old) const
199 : {
200 8618 : if (!is_old)
201 : {
202 8403 : const auto & var_names = getParam<std::vector<VariableName>>(var_name);
203 8403 : _depend_vars.insert(var_names.begin(), var_names.end());
204 : }
205 8618 : }
206 :
207 : void
208 5046 : AuxKernelBase::addUserObjectDependencyHelper(const UserObjectBase & uo) const
209 : {
210 5046 : _depend_uo.insert(uo.name());
211 5119 : for (const auto & indirect_dependent : uo.getDependObjects())
212 5119 : _depend_uo.insert(indirect_dependent);
213 5046 : }
214 :
215 : void
216 222 : AuxKernelBase::addPostprocessorDependencyHelper(const PostprocessorName & name) const
217 : {
218 222 : getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
219 222 : }
220 :
221 : void
222 227 : AuxKernelBase::addVectorPostprocessorDependencyHelper(const VectorPostprocessorName & name) const
223 : {
224 227 : getUserObjectBaseByName(name); // getting the UO will call addUserObjectDependencyHelper()
225 227 : }
226 :
227 : MooseVariableFieldBase &
228 284711 : AuxKernelBase::getVariableHelper(const InputParameters & parameters)
229 : {
230 1138838 : return parameters.getCheckedPointerParam<SystemBase *>("_sys")->getVariable(
231 569419 : parameters.get<THREAD_ID>("_tid"), parameters.get<AuxVariableName>("variable"));
232 : }
|