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