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 "AuxiliarySystem.h"
11 : #include "FEProblem.h"
12 : #include "Factory.h"
13 : #include "AuxKernel.h"
14 : #include "AuxScalarKernel.h"
15 : #include "MaterialData.h"
16 : #include "Assembly.h"
17 : #include "GeometricSearchData.h"
18 : #include "ComputeNodalAuxVarsThread.h"
19 : #include "ComputeNodalAuxBcsThread.h"
20 : #include "ComputeElemAuxVarsThread.h"
21 : #include "ComputeElemAuxBcsThread.h"
22 : #include "ComputeMortarNodalAuxBndThread.h"
23 : #include "Parser.h"
24 : #include "TimeIntegrator.h"
25 : #include "Conversion.h"
26 :
27 : #include "libmesh/quadrature_gauss.h"
28 : #include "libmesh/node_range.h"
29 : #include "libmesh/numeric_vector.h"
30 : #include "libmesh/default_coupling.h"
31 : #include "libmesh/string_to_enum.h"
32 : #include "libmesh/fe_interface.h"
33 :
34 : // C++
35 : #include <cstring> // for "Jacobian" exception test
36 :
37 : using namespace libMesh;
38 :
39 : // AuxiliarySystem ////////
40 :
41 64930 : AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
42 : : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
43 64930 : PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
44 64930 : _sys(subproblem.es().add_system<System>(name)),
45 64930 : _current_solution(_sys.current_local_solution.get()),
46 64930 : _aux_scalar_storage(_app.getExecuteOnEnum()),
47 64930 : _nodal_aux_storage(_app.getExecuteOnEnum()),
48 64930 : _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
49 64930 : _elemental_aux_storage(_app.getExecuteOnEnum()),
50 64930 : _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
51 64930 : _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
52 64930 : _nodal_array_aux_storage(_app.getExecuteOnEnum()),
53 173015 : _elemental_array_aux_storage(_app.getExecuteOnEnum())
54 : #ifdef MOOSE_KOKKOS_ENABLED
55 : ,
56 43313 : _kokkos_nodal_aux_storage(_app.getExecuteOnEnum()),
57 259878 : _kokkos_elemental_aux_storage(_app.getExecuteOnEnum())
58 : #endif
59 : {
60 64930 : _nodal_vars.resize(libMesh::n_threads());
61 64930 : _elem_vars.resize(libMesh::n_threads());
62 :
63 64930 : if (!_fe_problem.defaultGhosting())
64 : {
65 64848 : auto & dof_map = _sys.get_dof_map();
66 64848 : dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
67 64848 : dof_map.set_implicit_neighbor_dofs(false);
68 : }
69 64930 : }
70 :
71 60468 : AuxiliarySystem::~AuxiliarySystem() = default;
72 :
73 : void
74 61910 : AuxiliarySystem::initialSetup()
75 : {
76 309550 : TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
77 :
78 61910 : SystemBase::initialSetup();
79 :
80 129471 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
81 : {
82 67565 : _aux_scalar_storage.sort(tid);
83 67565 : _aux_scalar_storage.initialSetup(tid);
84 :
85 67565 : _nodal_aux_storage.sort(tid);
86 67565 : _nodal_aux_storage.initialSetup(tid);
87 :
88 67561 : _mortar_nodal_aux_storage.sort(tid);
89 67561 : _mortar_nodal_aux_storage.initialSetup(tid);
90 :
91 67561 : _nodal_vec_aux_storage.sort(tid);
92 67561 : _nodal_vec_aux_storage.initialSetup(tid);
93 :
94 67561 : _nodal_array_aux_storage.sort(tid);
95 67561 : _nodal_array_aux_storage.initialSetup(tid);
96 :
97 67561 : _elemental_aux_storage.sort(tid);
98 67561 : _elemental_aux_storage.initialSetup(tid);
99 :
100 67561 : _elemental_vec_aux_storage.sort(tid);
101 67561 : _elemental_vec_aux_storage.initialSetup(tid);
102 :
103 67561 : _elemental_array_aux_storage.sort(tid);
104 67561 : _elemental_array_aux_storage.initialSetup(tid);
105 : }
106 :
107 : #ifdef MOOSE_KOKKOS_ENABLED
108 41602 : _kokkos_nodal_aux_storage.sort(/*tid=*/0);
109 41602 : _kokkos_nodal_aux_storage.initialSetup(/*tid=*/0);
110 :
111 41602 : _kokkos_elemental_aux_storage.sort(/*tid=*/0);
112 41602 : _kokkos_elemental_aux_storage.initialSetup(/*tid=*/0);
113 : #endif
114 61906 : }
115 :
116 : void
117 290353 : AuxiliarySystem::timestepSetup()
118 : {
119 290353 : SystemBase::timestepSetup();
120 :
121 606429 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
122 : {
123 316076 : _aux_scalar_storage.timestepSetup(tid);
124 316076 : _nodal_aux_storage.timestepSetup(tid);
125 316076 : _mortar_nodal_aux_storage.timestepSetup(tid);
126 316076 : _nodal_vec_aux_storage.timestepSetup(tid);
127 316076 : _nodal_array_aux_storage.timestepSetup(tid);
128 316076 : _elemental_aux_storage.timestepSetup(tid);
129 316076 : _elemental_vec_aux_storage.timestepSetup(tid);
130 316076 : _elemental_array_aux_storage.timestepSetup(tid);
131 : }
132 :
133 : #ifdef MOOSE_KOKKOS_ENABLED
134 191442 : _kokkos_nodal_aux_storage.timestepSetup(/*tid=*/0);
135 191442 : _kokkos_elemental_aux_storage.timestepSetup(/*tid=*/0);
136 : #endif
137 290353 : }
138 :
139 : void
140 1925166 : AuxiliarySystem::customSetup(const ExecFlagType & exec_type)
141 : {
142 1925166 : SystemBase::customSetup(exec_type);
143 :
144 4022501 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
145 : {
146 2097335 : _aux_scalar_storage.customSetup(exec_type, tid);
147 2097335 : _nodal_aux_storage.customSetup(exec_type, tid);
148 2097335 : _mortar_nodal_aux_storage.customSetup(exec_type, tid);
149 2097335 : _nodal_vec_aux_storage.customSetup(exec_type, tid);
150 2097335 : _nodal_array_aux_storage.customSetup(exec_type, tid);
151 2097335 : _elemental_aux_storage.customSetup(exec_type, tid);
152 2097335 : _elemental_vec_aux_storage.customSetup(exec_type, tid);
153 2097335 : _elemental_array_aux_storage.customSetup(exec_type, tid);
154 : }
155 :
156 : #ifdef MOOSE_KOKKOS_ENABLED
157 1268452 : _kokkos_nodal_aux_storage.customSetup(exec_type, /*tid=*/0);
158 1268452 : _kokkos_elemental_aux_storage.customSetup(exec_type, /*tid=*/0);
159 : #endif
160 1925166 : }
161 :
162 : void
163 0 : AuxiliarySystem::subdomainSetup()
164 : {
165 0 : SystemBase::subdomainSetup();
166 :
167 0 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
168 : {
169 0 : _aux_scalar_storage.subdomainSetup(tid);
170 0 : _nodal_aux_storage.subdomainSetup(tid);
171 0 : _mortar_nodal_aux_storage.subdomainSetup(tid);
172 0 : _nodal_vec_aux_storage.subdomainSetup(tid);
173 0 : _nodal_array_aux_storage.subdomainSetup(tid);
174 0 : _elemental_aux_storage.subdomainSetup(tid);
175 0 : _elemental_vec_aux_storage.subdomainSetup(tid);
176 0 : _elemental_array_aux_storage.subdomainSetup(tid);
177 : }
178 0 : }
179 :
180 : void
181 534969 : AuxiliarySystem::jacobianSetup()
182 : {
183 534969 : SystemBase::jacobianSetup();
184 :
185 1118903 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
186 : {
187 583934 : _aux_scalar_storage.jacobianSetup(tid);
188 583934 : _nodal_aux_storage.jacobianSetup(tid);
189 583934 : _mortar_nodal_aux_storage.jacobianSetup(tid);
190 583934 : _nodal_vec_aux_storage.jacobianSetup(tid);
191 583934 : _nodal_array_aux_storage.jacobianSetup(tid);
192 583934 : _elemental_aux_storage.jacobianSetup(tid);
193 583934 : _elemental_vec_aux_storage.jacobianSetup(tid);
194 583934 : _elemental_array_aux_storage.jacobianSetup(tid);
195 : }
196 :
197 : #ifdef MOOSE_KOKKOS_ENABLED
198 349835 : _kokkos_nodal_aux_storage.jacobianSetup(/*tid=*/0);
199 349835 : _kokkos_elemental_aux_storage.jacobianSetup(/*tid=*/0);
200 : #endif
201 534969 : }
202 :
203 : void
204 3351900 : AuxiliarySystem::residualSetup()
205 : {
206 3351900 : SystemBase::residualSetup();
207 :
208 7004865 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
209 : {
210 3652965 : _aux_scalar_storage.residualSetup(tid);
211 3652965 : _nodal_aux_storage.residualSetup(tid);
212 3652965 : _mortar_nodal_aux_storage.residualSetup(tid);
213 3652965 : _nodal_vec_aux_storage.residualSetup(tid);
214 3652965 : _nodal_array_aux_storage.residualSetup(tid);
215 3652965 : _elemental_aux_storage.residualSetup(tid);
216 3652965 : _elemental_vec_aux_storage.residualSetup(tid);
217 3652965 : _elemental_array_aux_storage.residualSetup(tid);
218 : }
219 :
220 : #ifdef MOOSE_KOKKOS_ENABLED
221 2202394 : _kokkos_nodal_aux_storage.residualSetup(/*tid=*/0);
222 2202394 : _kokkos_elemental_aux_storage.residualSetup(/*tid=*/0);
223 : #endif
224 3351900 : }
225 :
226 : void
227 368966 : AuxiliarySystem::updateActive(THREAD_ID tid)
228 : {
229 368966 : _aux_scalar_storage.updateActive(tid);
230 368966 : _nodal_aux_storage.updateActive(tid);
231 368966 : _mortar_nodal_aux_storage.updateActive(tid);
232 368966 : _nodal_vec_aux_storage.updateActive(tid);
233 368966 : _nodal_array_aux_storage.updateActive(tid);
234 368966 : _elemental_aux_storage.updateActive(tid);
235 368966 : _elemental_vec_aux_storage.updateActive(tid);
236 368966 : _elemental_array_aux_storage.updateActive(tid);
237 :
238 : #ifdef MOOSE_KOKKOS_ENABLED
239 253056 : if (tid == 0)
240 : {
241 223673 : _kokkos_nodal_aux_storage.updateActive(/*tid=*/0);
242 223673 : _kokkos_elemental_aux_storage.updateActive(/*tid=*/0);
243 : }
244 : #endif
245 368966 : }
246 :
247 : void
248 98158 : AuxiliarySystem::addVariable(const std::string & var_type,
249 : const std::string & name,
250 : InputParameters & parameters)
251 : {
252 98158 : SystemBase::addVariable(var_type, name, parameters);
253 :
254 196316 : auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
255 294474 : Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
256 :
257 98158 : if (var_type == "MooseVariableScalar")
258 1805 : return;
259 :
260 201672 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
261 : {
262 105319 : if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
263 : {
264 393 : auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
265 393 : if (var)
266 : {
267 393 : if (var->feType().family == LAGRANGE_VEC)
268 140 : _nodal_vars[tid].push_back(var);
269 : else
270 253 : _elem_vars[tid].push_back(var);
271 : }
272 : }
273 :
274 : else
275 : {
276 104926 : MooseVariableBase * var_base = _vars[tid].getVariable(name);
277 :
278 104926 : auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
279 :
280 104926 : if (var)
281 : {
282 103716 : if (var->feType().family == LAGRANGE)
283 36556 : _nodal_vars[tid].push_back(var);
284 : else
285 67160 : _elem_vars[tid].push_back(var);
286 : }
287 :
288 104926 : auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
289 :
290 104926 : if (avar)
291 : {
292 1210 : if (avar->feType().family == LAGRANGE)
293 546 : _nodal_vars[tid].push_back(avar);
294 : else
295 664 : _elem_vars[tid].push_back(avar);
296 : }
297 : }
298 : }
299 : }
300 :
301 : void
302 70035 : AuxiliarySystem::addKernel(const std::string & kernel_name,
303 : const std::string & name,
304 : InputParameters & parameters)
305 : {
306 145991 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
307 : {
308 76108 : const auto & base = parameters.getBase();
309 76108 : if (base == "AuxKernel" || base == "Bounds")
310 : {
311 : std::shared_ptr<AuxKernel> kernel =
312 75700 : _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
313 75572 : if (kernel->isNodal())
314 : {
315 23961 : if (kernel->isMortar())
316 84 : _mortar_nodal_aux_storage.addObject(kernel, tid);
317 : else
318 23877 : _nodal_aux_storage.addObject(kernel, tid);
319 : }
320 : else
321 51611 : _elemental_aux_storage.addObject(kernel, tid);
322 75568 : }
323 :
324 408 : else if (base == "VectorAuxKernel")
325 : {
326 : std::shared_ptr<VectorAuxKernel> kernel =
327 220 : _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
328 220 : if (kernel->isNodal())
329 : {
330 56 : if (kernel->isMortar())
331 0 : mooseError("Vector mortar aux kernels not yet implemented");
332 56 : _nodal_vec_aux_storage.addObject(kernel, tid);
333 : }
334 : else
335 164 : _elemental_vec_aux_storage.addObject(kernel, tid);
336 220 : }
337 :
338 188 : else if (base == "ArrayAuxKernel")
339 : {
340 : std::shared_ptr<ArrayAuxKernel> kernel =
341 188 : _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
342 168 : if (kernel->isNodal())
343 : {
344 98 : if (kernel->isMortar())
345 0 : mooseError("Vector mortar aux kernels not yet implemented");
346 98 : _nodal_array_aux_storage.addObject(kernel, tid);
347 : }
348 : else
349 70 : _elemental_array_aux_storage.addObject(kernel, tid);
350 168 : }
351 : else
352 : mooseAssert(false,
353 : "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
354 : "' to the auxiliary system with invalid _moose_base: " + base);
355 : }
356 69883 : }
357 :
358 : void
359 537 : AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
360 : const std::string & name,
361 : InputParameters & parameters)
362 : {
363 1113 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
364 : {
365 : std::shared_ptr<AuxScalarKernel> kernel =
366 580 : _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
367 576 : _aux_scalar_storage.addObject(kernel, tid);
368 576 : }
369 533 : }
370 :
371 : void
372 431617138 : AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
373 : {
374 592195952 : for (auto * var : _nodal_vars[tid])
375 160578814 : var->computeElemValues();
376 :
377 595753351 : for (auto * var : _elem_vars[tid])
378 : {
379 164136213 : var->reinitAux();
380 164136213 : var->computeElemValues();
381 : }
382 431617138 : }
383 :
384 : void
385 13069275 : AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
386 : {
387 15693236 : for (auto * var : _nodal_vars[tid])
388 2623961 : var->computeElemValuesFace();
389 :
390 19204937 : for (auto * var : _elem_vars[tid])
391 : {
392 6135662 : var->reinitAux();
393 6135662 : var->reinitAuxNeighbor();
394 6135662 : var->computeElemValuesFace();
395 : }
396 13069275 : }
397 :
398 : void
399 2269 : AuxiliarySystem::serializeSolution()
400 : {
401 4538 : if (_serialized_solution.get() &&
402 2269 : _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
403 : {
404 2269 : if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
405 : {
406 63 : _serialized_solution->clear();
407 63 : _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
408 : }
409 :
410 2269 : solution().localize(*_serialized_solution);
411 : }
412 2269 : }
413 :
414 : void
415 6372951 : AuxiliarySystem::compute(ExecFlagType type)
416 : {
417 : // avoid division by dt which might be zero.
418 6372951 : if (_fe_problem.dt() > 0.)
419 11011815 : for (auto & ti : _time_integrators)
420 5495679 : ti->preStep();
421 :
422 : // We need to compute time derivatives every time each kind of the variables is finished, because:
423 : //
424 : // a) the user might want to use the aux variable value somewhere, thus we need to provide the
425 : // up-to-date value
426 : // b) time integration system works with the whole vectors of solutions, thus we cannot update
427 : // only a part of the vector
428 : //
429 :
430 6372951 : if (_vars[0].scalars().size() > 0)
431 : {
432 56031 : computeScalarVars(type);
433 : // compute time derivatives of scalar aux variables _after_ the values were updated
434 56031 : if (_fe_problem.dt() > 0.)
435 88162 : for (auto & ti : _time_integrators)
436 44081 : ti->computeTimeDerivatives();
437 : }
438 :
439 6372951 : if (_vars[0].fieldVariables().size() > 0)
440 : {
441 2198355 : computeNodalArrayVars(type);
442 2198355 : computeNodalVecVars(type);
443 2198355 : computeNodalVars(type);
444 2198351 : computeMortarNodalVars(type);
445 2198351 : computeElementalArrayVars(type);
446 2198351 : computeElementalVecVars(type);
447 2198351 : computeElementalVars(type);
448 :
449 : #ifdef MOOSE_KOKKOS_ENABLED
450 1461939 : kokkosCompute(type);
451 : #endif
452 :
453 : // compute time derivatives of nodal aux variables _after_ the values were updated
454 2198310 : if (_fe_problem.dt() > 0.)
455 3804730 : for (auto & ti : _time_integrators)
456 1884369 : ti->computeTimeDerivatives();
457 : }
458 :
459 6372906 : if (_serialized_solution.get())
460 2269 : serializeSolution();
461 6372906 : }
462 :
463 : std::set<std::string>
464 1676366 : AuxiliarySystem::getDependObjects(ExecFlagType type)
465 : {
466 1676366 : std::set<std::string> depend_objects;
467 :
468 : // Elemental AuxKernels
469 : {
470 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
471 1676366 : _elemental_aux_storage[type].getActiveObjects();
472 1763023 : for (const auto & aux : auxs)
473 : {
474 86657 : const std::set<UserObjectName> & uo = aux->getDependObjects();
475 86657 : depend_objects.insert(uo.begin(), uo.end());
476 : }
477 : }
478 :
479 : // Elemental VectorAuxKernels
480 : {
481 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
482 1676366 : _elemental_vec_aux_storage[type].getActiveObjects();
483 1676661 : for (const auto & aux : auxs)
484 : {
485 295 : const std::set<UserObjectName> & uo = aux->getDependObjects();
486 295 : depend_objects.insert(uo.begin(), uo.end());
487 : }
488 : }
489 :
490 : // Elemental ArrayAuxKernels
491 : {
492 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
493 1676366 : _elemental_array_aux_storage[type].getActiveObjects();
494 1676470 : for (const auto & aux : auxs)
495 : {
496 104 : const std::set<UserObjectName> & uo = aux->getDependObjects();
497 104 : depend_objects.insert(uo.begin(), uo.end());
498 : }
499 : }
500 :
501 : // Nodal AuxKernels
502 : {
503 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
504 1676366 : _nodal_aux_storage[type].getActiveObjects();
505 1718280 : for (const auto & aux : auxs)
506 : {
507 41914 : const std::set<UserObjectName> & uo = aux->getDependObjects();
508 41914 : depend_objects.insert(uo.begin(), uo.end());
509 : }
510 : }
511 :
512 : // Mortar Nodal AuxKernels
513 : {
514 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
515 1676366 : _mortar_nodal_aux_storage[type].getActiveObjects();
516 1676522 : for (const auto & aux : auxs)
517 : {
518 156 : const std::set<UserObjectName> & uo = aux->getDependObjects();
519 156 : depend_objects.insert(uo.begin(), uo.end());
520 : }
521 : }
522 :
523 : // Nodal VectorAuxKernels
524 : {
525 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
526 1676366 : _nodal_vec_aux_storage[type].getActiveObjects();
527 1676457 : for (const auto & aux : auxs)
528 : {
529 91 : const std::set<UserObjectName> & uo = aux->getDependObjects();
530 91 : depend_objects.insert(uo.begin(), uo.end());
531 : }
532 : }
533 :
534 : // Nodal ArrayAuxKernels
535 : {
536 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
537 1676366 : _nodal_array_aux_storage[type].getActiveObjects();
538 1676522 : for (const auto & aux : auxs)
539 : {
540 156 : const std::set<UserObjectName> & uo = aux->getDependObjects();
541 156 : depend_objects.insert(uo.begin(), uo.end());
542 : }
543 : }
544 :
545 : #ifdef MOOSE_KOKKOS_ENABLED
546 : // Nodal KokkosAuxKernels
547 : {
548 : const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
549 1125728 : _kokkos_nodal_aux_storage[type].getActiveObjects();
550 1126040 : for (const auto & aux : auxs)
551 : {
552 312 : const std::set<UserObjectName> & uo = aux->getDependObjects();
553 312 : depend_objects.insert(uo.begin(), uo.end());
554 : }
555 : }
556 :
557 : // Nodal ElementalAuxKernels
558 : {
559 : const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
560 1125728 : _kokkos_elemental_aux_storage[type].getActiveObjects();
561 1125932 : for (const auto & aux : auxs)
562 : {
563 204 : const std::set<UserObjectName> & uo = aux->getDependObjects();
564 204 : depend_objects.insert(uo.begin(), uo.end());
565 : }
566 : }
567 : #endif
568 :
569 1676366 : return depend_objects;
570 0 : }
571 :
572 : std::set<std::string>
573 62088 : AuxiliarySystem::getDependObjects()
574 : {
575 62088 : std::set<std::string> depend_objects;
576 :
577 : // Elemental AuxKernels
578 : {
579 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
580 62088 : _elemental_aux_storage.getActiveObjects();
581 107618 : for (const auto & aux : auxs)
582 : {
583 45530 : const std::set<UserObjectName> & uo = aux->getDependObjects();
584 45530 : depend_objects.insert(uo.begin(), uo.end());
585 : }
586 : }
587 :
588 : // Elemental VectorAuxKernels
589 : {
590 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
591 62088 : _elemental_vec_aux_storage.getActiveObjects();
592 62242 : for (const auto & aux : auxs)
593 : {
594 154 : const std::set<UserObjectName> & uo = aux->getDependObjects();
595 154 : depend_objects.insert(uo.begin(), uo.end());
596 : }
597 : }
598 :
599 : // Elemental ArrayAuxKernels
600 : {
601 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
602 62088 : _elemental_array_aux_storage.getActiveObjects();
603 62153 : for (const auto & aux : auxs)
604 : {
605 65 : const std::set<UserObjectName> & uo = aux->getDependObjects();
606 65 : depend_objects.insert(uo.begin(), uo.end());
607 : }
608 : }
609 :
610 : // Nodal AuxKernels
611 : {
612 62088 : const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
613 84100 : for (const auto & aux : auxs)
614 : {
615 22012 : const std::set<UserObjectName> & uo = aux->getDependObjects();
616 22012 : depend_objects.insert(uo.begin(), uo.end());
617 : }
618 : }
619 :
620 : // Mortar Nodal AuxKernels
621 : {
622 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
623 62088 : _mortar_nodal_aux_storage.getActiveObjects();
624 62166 : for (const auto & aux : auxs)
625 : {
626 78 : const std::set<UserObjectName> & uo = aux->getDependObjects();
627 78 : depend_objects.insert(uo.begin(), uo.end());
628 : }
629 : }
630 :
631 : // Nodal VectorAuxKernels
632 : {
633 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
634 62088 : _nodal_vec_aux_storage.getActiveObjects();
635 62140 : for (const auto & aux : auxs)
636 : {
637 52 : const std::set<UserObjectName> & uo = aux->getDependObjects();
638 52 : depend_objects.insert(uo.begin(), uo.end());
639 : }
640 : }
641 :
642 : // Nodal ArrayAuxKernels
643 : {
644 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
645 62088 : _nodal_array_aux_storage.getActiveObjects();
646 62179 : for (const auto & aux : auxs)
647 : {
648 91 : const std::set<UserObjectName> & uo = aux->getDependObjects();
649 91 : depend_objects.insert(uo.begin(), uo.end());
650 : }
651 : }
652 :
653 : #ifdef MOOSE_KOKKOS_ENABLED
654 : // Nodal KokkosAuxKernels
655 : {
656 : const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
657 41694 : _kokkos_nodal_aux_storage.getActiveObjects();
658 41886 : for (const auto & aux : auxs)
659 : {
660 192 : const std::set<UserObjectName> & uo = aux->getDependObjects();
661 192 : depend_objects.insert(uo.begin(), uo.end());
662 : }
663 : }
664 :
665 : // Elemental KokkosAuxKernels
666 : {
667 : const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
668 41694 : _kokkos_elemental_aux_storage.getActiveObjects();
669 41814 : for (const auto & aux : auxs)
670 : {
671 120 : const std::set<UserObjectName> & uo = aux->getDependObjects();
672 120 : depend_objects.insert(uo.begin(), uo.end());
673 : }
674 : }
675 : #endif
676 :
677 62088 : return depend_objects;
678 0 : }
679 :
680 : void
681 56031 : AuxiliarySystem::setScalarVariableCoupleableTags(ExecFlagType type)
682 : {
683 56031 : const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
684 56031 : const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
685 :
686 56031 : std::set<TagID> needed_sc_var_matrix_tags;
687 56031 : std::set<TagID> needed_sc_var_vector_tags;
688 75911 : for (const auto & obj : objects)
689 : {
690 19880 : auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
691 19880 : needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
692 :
693 19880 : auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
694 19880 : needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
695 : }
696 :
697 56031 : _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
698 56031 : _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
699 56031 : }
700 :
701 : void
702 56031 : AuxiliarySystem::clearScalarVariableCoupleableTags()
703 : {
704 56031 : _fe_problem.clearActiveScalarVariableCoupleableMatrixTags(0);
705 56031 : _fe_problem.clearActiveScalarVariableCoupleableVectorTags(0);
706 56031 : }
707 :
708 : void
709 56031 : AuxiliarySystem::computeScalarVars(ExecFlagType type)
710 : {
711 56031 : setScalarVariableCoupleableTags(type);
712 :
713 : // Reference to the current storage container
714 56031 : const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
715 :
716 56031 : if (storage.hasActiveObjects())
717 : {
718 54489 : TIME_SECTION("computeScalarVars", 1);
719 :
720 : PARALLEL_TRY
721 : {
722 : // FIXME: run multi-threaded
723 18163 : THREAD_ID tid = 0;
724 18163 : if (storage.hasActiveObjects())
725 : {
726 18163 : _fe_problem.reinitScalars(tid);
727 :
728 : const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
729 18163 : storage.getActiveObjects(tid);
730 :
731 : // Call compute() method on all active AuxScalarKernel objects
732 38043 : for (const auto & obj : objects)
733 19880 : obj->compute();
734 :
735 18163 : const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
736 56490 : for (const auto & var : scalar_vars)
737 38327 : var->insert(solution());
738 : }
739 : }
740 18163 : PARALLEL_CATCH;
741 :
742 18163 : solution().close();
743 18163 : _sys.update();
744 18163 : }
745 :
746 56031 : clearScalarVariableCoupleableTags();
747 56031 : }
748 :
749 : void
750 2198355 : AuxiliarySystem::computeNodalVars(ExecFlagType type)
751 : {
752 6595065 : TIME_SECTION("computeNodalVars", 3);
753 :
754 2198355 : const MooseObjectWarehouse<AuxKernel> & nodal = _nodal_aux_storage[type];
755 2198355 : computeNodalVarsHelper<AuxKernel>(nodal);
756 2198351 : }
757 :
758 : void
759 2198355 : AuxiliarySystem::computeNodalVecVars(ExecFlagType type)
760 : {
761 6595065 : TIME_SECTION("computeNodalVecVars", 3);
762 :
763 2198355 : const MooseObjectWarehouse<VectorAuxKernel> & nodal = _nodal_vec_aux_storage[type];
764 2198355 : computeNodalVarsHelper<VectorAuxKernel>(nodal);
765 2198355 : }
766 :
767 : void
768 2198355 : AuxiliarySystem::computeNodalArrayVars(ExecFlagType type)
769 : {
770 2198355 : const MooseObjectWarehouse<ArrayAuxKernel> & nodal = _nodal_array_aux_storage[type];
771 2198355 : computeNodalVarsHelper<ArrayAuxKernel>(nodal);
772 2198355 : }
773 :
774 : void
775 2198351 : AuxiliarySystem::computeMortarNodalVars(const ExecFlagType type)
776 : {
777 6595053 : TIME_SECTION("computeMortarNodalVars", 3);
778 :
779 2198351 : const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
780 :
781 : mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
782 : "We don't allow creation of block restricted mortar nodal aux kernels.");
783 :
784 2198351 : if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
785 : {
786 186 : ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
787 372 : for (const auto & [bnd_id, mortar_nodal_auxes] :
788 558 : mortar_nodal_warehouse.getActiveBoundaryObjects())
789 372 : for (const auto index : index_range(mortar_nodal_auxes))
790 : {
791 : PARALLEL_TRY
792 : {
793 : try
794 : {
795 : ComputeMortarNodalAuxBndThread<AuxKernel> mnabt(
796 186 : _fe_problem, mortar_nodal_warehouse, bnd_id, index);
797 186 : Threads::parallel_reduce(bnd_nodes, mnabt);
798 186 : }
799 0 : catch (MooseException & e)
800 : {
801 0 : _fe_problem.setException("The following MooseException was raised during mortar nodal "
802 0 : "Auxiliary variable computation:\n" +
803 0 : std::string(e.what()));
804 0 : }
805 0 : catch (MetaPhysicL::LogicError & e)
806 : {
807 0 : moose::translateMetaPhysicLError(e);
808 0 : }
809 0 : catch (std::exception & e)
810 : {
811 : // Continue if we find a libMesh degenerate map exception, but
812 : // just re-throw for any real error
813 0 : if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
814 0 : !strstr(e.what(), "det != 0"))
815 0 : throw;
816 :
817 0 : _fe_problem.setException("We caught a libMesh degeneracy exception during mortar "
818 0 : "nodal Auxiliary variable computation:\n" +
819 0 : std::string(e.what()));
820 0 : }
821 : }
822 186 : PARALLEL_CATCH;
823 :
824 : // We need to make sure we propagate exceptions to all processes before trying to close
825 : // here, which is a parallel operation
826 186 : solution().close();
827 186 : _sys.update();
828 : }
829 : }
830 2198351 : }
831 :
832 : void
833 2198351 : AuxiliarySystem::computeElementalVars(ExecFlagType type)
834 : {
835 6595053 : TIME_SECTION("computeElementalVars", 3);
836 :
837 2198351 : const MooseObjectWarehouse<AuxKernel> & elemental = _elemental_aux_storage[type];
838 2198351 : computeElementalVarsHelper<AuxKernel>(elemental);
839 2198310 : }
840 :
841 : void
842 2198351 : AuxiliarySystem::computeElementalVecVars(ExecFlagType type)
843 : {
844 6595053 : TIME_SECTION("computeElementalVecVars", 3);
845 :
846 2198351 : const MooseObjectWarehouse<VectorAuxKernel> & elemental = _elemental_vec_aux_storage[type];
847 2198351 : computeElementalVarsHelper<VectorAuxKernel>(elemental);
848 2198351 : }
849 :
850 : void
851 2198351 : AuxiliarySystem::computeElementalArrayVars(ExecFlagType type)
852 : {
853 2198351 : const MooseObjectWarehouse<ArrayAuxKernel> & elemental = _elemental_array_aux_storage[type];
854 2198351 : computeElementalVarsHelper<ArrayAuxKernel>(elemental);
855 2198351 : }
856 :
857 : void
858 0 : AuxiliarySystem::augmentSparsity(SparsityPattern::Graph & /*sparsity*/,
859 : std::vector<dof_id_type> & /*n_nz*/,
860 : std::vector<dof_id_type> &
861 : /*n_oz*/)
862 : {
863 0 : }
864 :
865 : Order
866 69495 : AuxiliarySystem::getMinQuadratureOrder()
867 : {
868 69495 : Order order = CONSTANT;
869 69495 : std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
870 151639 : for (const auto & var : vars)
871 : {
872 82144 : if (!var->isNodal()) // nodal aux variables do not need quadrature
873 : {
874 41875 : FEType fe_type = var->feType();
875 41875 : if (fe_type.default_quadrature_order() > order)
876 21434 : order = fe_type.default_quadrature_order();
877 : }
878 : }
879 :
880 69495 : return order;
881 69495 : }
882 :
883 : bool
884 31327 : AuxiliarySystem::needMaterialOnSide(BoundaryID bnd_id)
885 : {
886 62076 : return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
887 62076 : _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
888 : }
889 :
890 : void
891 556 : AuxiliarySystem::copyCurrentIntoPreviousNL()
892 : {
893 556 : if (solutionPreviousNewton())
894 556 : *solutionPreviousNewton() = *currentSolution();
895 556 : }
896 :
897 : template <typename AuxKernelType>
898 : void
899 6595053 : AuxiliarySystem::computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
900 : {
901 6595053 : if (warehouse.hasActiveBlockObjects())
902 : {
903 : // Block Elemental AuxKernels
904 : PARALLEL_TRY
905 : {
906 81145 : ConstElemRange & range = *_mesh.getActiveLocalElementRange();
907 81145 : ComputeElemAuxVarsThread<AuxKernelType> eavt(_fe_problem, warehouse, true);
908 : try
909 : {
910 81145 : Threads::parallel_reduce(range, eavt);
911 : }
912 0 : catch (MooseException & e)
913 : {
914 0 : _fe_problem.setException("The following MooseException was raised during elemental "
915 : "Auxiliary variable computation:\n" +
916 0 : std::string(e.what()));
917 : }
918 81112 : }
919 81112 : PARALLEL_CATCH;
920 :
921 : // We need to make sure we propagate exceptions to all processes before trying to close
922 : // here, which is a parallel operation
923 81112 : solution().close();
924 81112 : _sys.update();
925 : }
926 :
927 : // Boundary Elemental AuxKernels
928 6595020 : if (warehouse.hasActiveBoundaryObjects())
929 : {
930 82011 : TIME_SECTION("computeElementalVecVars", 3);
931 :
932 : PARALLEL_TRY
933 : {
934 27337 : ConstBndElemRange & bnd_elems = *_mesh.getBoundaryElementRange();
935 27337 : ComputeElemAuxBcsThread<AuxKernelType> eabt(_fe_problem, warehouse, true);
936 : try
937 : {
938 27337 : Threads::parallel_reduce(bnd_elems, eabt);
939 : }
940 0 : catch (MooseException & e)
941 : {
942 0 : _fe_problem.setException("The following MooseException was raised during boundary "
943 : "elemental Auxiliary variable computation:\n" +
944 0 : std::string(e.what()));
945 : }
946 27329 : }
947 27329 : PARALLEL_CATCH;
948 :
949 : // We need to make sure we propagate exceptions to all processes before trying to close
950 : // here, which is a parallel operation
951 27329 : solution().close();
952 27329 : _sys.update();
953 27329 : }
954 6595012 : }
955 :
956 : template <typename AuxKernelType>
957 : void
958 6595065 : AuxiliarySystem::computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
959 : {
960 6595065 : if (warehouse.hasActiveBlockObjects())
961 : {
962 : // Block Nodal AuxKernels
963 : PARALLEL_TRY
964 : {
965 148545 : ConstNodeRange & range = *_mesh.getLocalNodeRange();
966 148545 : ComputeNodalAuxVarsThread<AuxKernelType> navt(_fe_problem, warehouse);
967 148545 : Threads::parallel_reduce(range, navt);
968 :
969 148541 : solution().close();
970 148541 : _sys.update();
971 148541 : }
972 148541 : PARALLEL_CATCH;
973 : }
974 :
975 6595061 : if (warehouse.hasActiveBoundaryObjects())
976 : {
977 276711 : TIME_SECTION("computeBoundaryObjects", 3);
978 :
979 : // Boundary Nodal AuxKernels
980 : PARALLEL_TRY
981 : {
982 92237 : ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
983 92237 : ComputeNodalAuxBcsThread<AuxKernelType> nabt(_fe_problem, warehouse);
984 92237 : Threads::parallel_reduce(bnd_nodes, nabt);
985 :
986 92237 : solution().close();
987 92237 : _sys.update();
988 92237 : }
989 92237 : PARALLEL_CATCH;
990 92237 : }
991 6595061 : }
992 :
993 : void
994 553 : AuxiliarySystem::variableWiseRelativeSolutionDifferenceNorm(
995 : std::vector<Number> & rel_diff_norms) const
996 : {
997 553 : rel_diff_norms.resize(nVariables(), 0);
998 : // Get dof map from system
999 553 : const auto & dof_map = _sys.get_dof_map();
1000 :
1001 1659 : for (const auto n : make_range(nVariables()))
1002 : {
1003 : // Get local indices from dof map for each variable
1004 1106 : std::vector<dof_id_type> local_indices_n;
1005 1106 : dof_map.local_variable_indices(local_indices_n, _mesh, n);
1006 1106 : Number diff_norm_n = 0;
1007 1106 : Number norm_n = 0;
1008 : // Get values from system, update norm
1009 101536 : for (const auto local_index : local_indices_n)
1010 : {
1011 100430 : const Number & value = solution()(local_index);
1012 100430 : const Number & value_old = solutionOld()(local_index);
1013 100430 : diff_norm_n += Utility::pow<2, Number>(value - value_old);
1014 100430 : norm_n += Utility::pow<2, Number>(value);
1015 : }
1016 : // Aggregate norm over proceccors
1017 1106 : _communicator.sum(diff_norm_n);
1018 1106 : _communicator.sum(norm_n);
1019 1106 : diff_norm_n = sqrt(diff_norm_n);
1020 1106 : norm_n = sqrt(norm_n);
1021 1106 : rel_diff_norms[n] = diff_norm_n / norm_n;
1022 1106 : }
1023 553 : }
1024 :
1025 : template void
1026 : AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1027 : template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1028 : const MooseObjectWarehouse<VectorAuxKernel> &);
1029 : template void
1030 : AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1031 : template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
1032 : const MooseObjectWarehouse<VectorAuxKernel> &);
|