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 : using namespace libMesh;
35 :
36 : // AuxiliarySystem ////////
37 :
38 58026 : AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
39 : : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
40 58026 : PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
41 58026 : _sys(subproblem.es().add_system<System>(name)),
42 58026 : _current_solution(_sys.current_local_solution.get()),
43 58026 : _aux_scalar_storage(_app.getExecuteOnEnum()),
44 58026 : _nodal_aux_storage(_app.getExecuteOnEnum()),
45 58026 : _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
46 58026 : _elemental_aux_storage(_app.getExecuteOnEnum()),
47 58026 : _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
48 58026 : _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
49 58026 : _nodal_array_aux_storage(_app.getExecuteOnEnum()),
50 232104 : _elemental_array_aux_storage(_app.getExecuteOnEnum())
51 : {
52 58026 : _nodal_vars.resize(libMesh::n_threads());
53 58026 : _elem_vars.resize(libMesh::n_threads());
54 :
55 58026 : if (!_fe_problem.defaultGhosting())
56 : {
57 57952 : auto & dof_map = _sys.get_dof_map();
58 57952 : dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
59 57952 : dof_map.set_implicit_neighbor_dofs(false);
60 : }
61 58026 : }
62 :
63 53761 : AuxiliarySystem::~AuxiliarySystem() = default;
64 :
65 : void
66 55221 : AuxiliarySystem::initialSetup()
67 : {
68 55221 : TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
69 :
70 55221 : SystemBase::initialSetup();
71 :
72 115875 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
73 : {
74 60658 : _aux_scalar_storage.sort(tid);
75 60658 : _aux_scalar_storage.initialSetup(tid);
76 :
77 60658 : _nodal_aux_storage.sort(tid);
78 60658 : _nodal_aux_storage.initialSetup(tid);
79 :
80 60654 : _mortar_nodal_aux_storage.sort(tid);
81 60654 : _mortar_nodal_aux_storage.initialSetup(tid);
82 :
83 60654 : _nodal_vec_aux_storage.sort(tid);
84 60654 : _nodal_vec_aux_storage.initialSetup(tid);
85 :
86 60654 : _nodal_array_aux_storage.sort(tid);
87 60654 : _nodal_array_aux_storage.initialSetup(tid);
88 :
89 60654 : _elemental_aux_storage.sort(tid);
90 60654 : _elemental_aux_storage.initialSetup(tid);
91 :
92 60654 : _elemental_vec_aux_storage.sort(tid);
93 60654 : _elemental_vec_aux_storage.initialSetup(tid);
94 :
95 60654 : _elemental_array_aux_storage.sort(tid);
96 60654 : _elemental_array_aux_storage.initialSetup(tid);
97 : }
98 55217 : }
99 :
100 : void
101 259232 : AuxiliarySystem::timestepSetup()
102 : {
103 259232 : SystemBase::timestepSetup();
104 :
105 543543 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
106 : {
107 284311 : _aux_scalar_storage.timestepSetup(tid);
108 284311 : _nodal_aux_storage.timestepSetup(tid);
109 284311 : _mortar_nodal_aux_storage.timestepSetup(tid);
110 284311 : _nodal_vec_aux_storage.timestepSetup(tid);
111 284311 : _nodal_array_aux_storage.timestepSetup(tid);
112 284311 : _elemental_aux_storage.timestepSetup(tid);
113 284311 : _elemental_vec_aux_storage.timestepSetup(tid);
114 284311 : _elemental_array_aux_storage.timestepSetup(tid);
115 : }
116 259232 : }
117 :
118 : void
119 1724449 : AuxiliarySystem::customSetup(const ExecFlagType & exec_type)
120 : {
121 1724449 : SystemBase::customSetup(exec_type);
122 :
123 3617277 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
124 : {
125 1892828 : _aux_scalar_storage.customSetup(exec_type, tid);
126 1892828 : _nodal_aux_storage.customSetup(exec_type, tid);
127 1892828 : _mortar_nodal_aux_storage.customSetup(exec_type, tid);
128 1892828 : _nodal_vec_aux_storage.customSetup(exec_type, tid);
129 1892828 : _nodal_array_aux_storage.customSetup(exec_type, tid);
130 1892828 : _elemental_aux_storage.customSetup(exec_type, tid);
131 1892828 : _elemental_vec_aux_storage.customSetup(exec_type, tid);
132 1892828 : _elemental_array_aux_storage.customSetup(exec_type, tid);
133 : }
134 1724449 : }
135 :
136 : void
137 0 : AuxiliarySystem::subdomainSetup()
138 : {
139 0 : SystemBase::subdomainSetup();
140 :
141 0 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
142 : {
143 0 : _aux_scalar_storage.subdomainSetup(tid);
144 0 : _nodal_aux_storage.subdomainSetup(tid);
145 0 : _mortar_nodal_aux_storage.subdomainSetup(tid);
146 0 : _nodal_vec_aux_storage.subdomainSetup(tid);
147 0 : _nodal_array_aux_storage.subdomainSetup(tid);
148 0 : _elemental_aux_storage.subdomainSetup(tid);
149 0 : _elemental_vec_aux_storage.subdomainSetup(tid);
150 0 : _elemental_array_aux_storage.subdomainSetup(tid);
151 : }
152 0 : }
153 :
154 : void
155 481926 : AuxiliarySystem::jacobianSetup()
156 : {
157 481926 : SystemBase::jacobianSetup();
158 :
159 1011859 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
160 : {
161 529933 : _aux_scalar_storage.jacobianSetup(tid);
162 529933 : _nodal_aux_storage.jacobianSetup(tid);
163 529933 : _mortar_nodal_aux_storage.jacobianSetup(tid);
164 529933 : _nodal_vec_aux_storage.jacobianSetup(tid);
165 529933 : _nodal_array_aux_storage.jacobianSetup(tid);
166 529933 : _elemental_aux_storage.jacobianSetup(tid);
167 529933 : _elemental_vec_aux_storage.jacobianSetup(tid);
168 529933 : _elemental_array_aux_storage.jacobianSetup(tid);
169 : }
170 481926 : }
171 :
172 : void
173 3044481 : AuxiliarySystem::residualSetup()
174 : {
175 3044481 : SystemBase::residualSetup();
176 :
177 6384306 : for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
178 : {
179 3339825 : _aux_scalar_storage.residualSetup(tid);
180 3339825 : _nodal_aux_storage.residualSetup(tid);
181 3339825 : _mortar_nodal_aux_storage.residualSetup(tid);
182 3339825 : _nodal_vec_aux_storage.residualSetup(tid);
183 3339825 : _nodal_array_aux_storage.residualSetup(tid);
184 3339825 : _elemental_aux_storage.residualSetup(tid);
185 3339825 : _elemental_vec_aux_storage.residualSetup(tid);
186 3339825 : _elemental_array_aux_storage.residualSetup(tid);
187 : }
188 3044481 : }
189 :
190 : void
191 333129 : AuxiliarySystem::updateActive(THREAD_ID tid)
192 : {
193 333129 : _aux_scalar_storage.updateActive(tid);
194 333129 : _nodal_aux_storage.updateActive(tid);
195 333129 : _mortar_nodal_aux_storage.updateActive(tid);
196 333129 : _nodal_vec_aux_storage.updateActive(tid);
197 333129 : _nodal_array_aux_storage.updateActive(tid);
198 333129 : _elemental_aux_storage.updateActive(tid);
199 333129 : _elemental_vec_aux_storage.updateActive(tid);
200 333129 : _elemental_array_aux_storage.updateActive(tid);
201 333129 : }
202 :
203 : void
204 87943 : AuxiliarySystem::addVariable(const std::string & var_type,
205 : const std::string & name,
206 : InputParameters & parameters)
207 : {
208 87943 : SystemBase::addVariable(var_type, name, parameters);
209 :
210 175886 : auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
211 263829 : Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
212 :
213 87943 : if (var_type == "MooseVariableScalar")
214 1668 : return;
215 :
216 181150 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
217 : {
218 94875 : if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
219 : {
220 366 : auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
221 366 : if (var)
222 : {
223 366 : if (var->feType().family == LAGRANGE_VEC)
224 130 : _nodal_vars[tid].push_back(var);
225 : else
226 236 : _elem_vars[tid].push_back(var);
227 : }
228 : }
229 :
230 : else
231 : {
232 94509 : MooseVariableBase * var_base = _vars[tid].getVariable(name);
233 :
234 94509 : auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
235 :
236 94509 : if (var)
237 : {
238 93362 : if (var->feType().family == LAGRANGE)
239 32896 : _nodal_vars[tid].push_back(var);
240 : else
241 60466 : _elem_vars[tid].push_back(var);
242 : }
243 :
244 94509 : auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
245 :
246 94509 : if (avar)
247 : {
248 1147 : if (avar->feType().family == LAGRANGE)
249 518 : _nodal_vars[tid].push_back(avar);
250 : else
251 629 : _elem_vars[tid].push_back(avar);
252 : }
253 : }
254 : }
255 : }
256 :
257 : void
258 62830 : AuxiliarySystem::addKernel(const std::string & kernel_name,
259 : const std::string & name,
260 : InputParameters & parameters)
261 : {
262 131346 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
263 : {
264 69617 : if (parameters.get<std::string>("_moose_base") == "AuxKernel" ||
265 69617 : parameters.get<std::string>("_moose_base") == "Bounds")
266 : {
267 : std::shared_ptr<AuxKernel> kernel =
268 68283 : _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
269 68159 : if (kernel->isNodal())
270 : {
271 21789 : if (kernel->isMortar())
272 78 : _mortar_nodal_aux_storage.addObject(kernel, tid);
273 : else
274 21711 : _nodal_aux_storage.addObject(kernel, tid);
275 : }
276 : else
277 46370 : _elemental_aux_storage.addObject(kernel, tid);
278 68155 : }
279 :
280 381 : else if (parameters.get<std::string>("_moose_base") == "VectorAuxKernel")
281 : {
282 : std::shared_ptr<VectorAuxKernel> kernel =
283 205 : _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
284 205 : if (kernel->isNodal())
285 : {
286 52 : if (kernel->isMortar())
287 0 : mooseError("Vector mortar aux kernels not yet implemented");
288 52 : _nodal_vec_aux_storage.addObject(kernel, tid);
289 : }
290 : else
291 153 : _elemental_vec_aux_storage.addObject(kernel, tid);
292 205 : }
293 :
294 176 : else if (parameters.get<std::string>("_moose_base") == "ArrayAuxKernel")
295 : {
296 : std::shared_ptr<ArrayAuxKernel> kernel =
297 176 : _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
298 156 : if (kernel->isNodal())
299 : {
300 91 : if (kernel->isMortar())
301 0 : mooseError("Vector mortar aux kernels not yet implemented");
302 91 : _nodal_array_aux_storage.addObject(kernel, tid);
303 : }
304 : else
305 65 : _elemental_array_aux_storage.addObject(kernel, tid);
306 156 : }
307 : else
308 : mooseAssert(false,
309 : "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
310 : "' to the auxiliary system with invalid _moose_base: " +
311 : parameters.get<std::string>("_moose_base"));
312 : }
313 62682 : }
314 :
315 : void
316 482 : AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
317 : const std::string & name,
318 : InputParameters & parameters)
319 : {
320 1002 : for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
321 : {
322 : std::shared_ptr<AuxScalarKernel> kernel =
323 524 : _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
324 520 : _aux_scalar_storage.addObject(kernel, tid);
325 520 : }
326 478 : }
327 :
328 : void
329 384109795 : AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
330 : {
331 525903573 : for (auto * var : _nodal_vars[tid])
332 141793778 : var->computeElemValues();
333 :
334 525811364 : for (auto * var : _elem_vars[tid])
335 : {
336 141701569 : var->reinitAux();
337 141701569 : var->computeElemValues();
338 : }
339 384109795 : }
340 :
341 : void
342 11957123 : AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
343 : {
344 14369689 : for (auto * var : _nodal_vars[tid])
345 2412566 : var->computeElemValuesFace();
346 :
347 17570184 : for (auto * var : _elem_vars[tid])
348 : {
349 5613061 : var->reinitAux();
350 5613061 : var->reinitAuxNeighbor();
351 5613061 : var->computeElemValuesFace();
352 : }
353 11957123 : }
354 :
355 : void
356 2052 : AuxiliarySystem::serializeSolution()
357 : {
358 4104 : if (_serialized_solution.get() &&
359 2052 : _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
360 : {
361 2052 : if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
362 : {
363 58 : _serialized_solution->clear();
364 58 : _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
365 : }
366 :
367 2052 : solution().localize(*_serialized_solution);
368 : }
369 2052 : }
370 :
371 : void
372 5757064 : AuxiliarySystem::compute(ExecFlagType type)
373 : {
374 : // avoid division by dt which might be zero.
375 5757064 : if (_fe_problem.dt() > 0.)
376 9928293 : for (auto & ti : _time_integrators)
377 4955544 : ti->preStep();
378 :
379 : // We need to compute time derivatives every time each kind of the variables is finished, because:
380 : //
381 : // a) the user might want to use the aux variable value somewhere, thus we need to provide the
382 : // up-to-date value
383 : // b) time integration system works with the whole vectors of solutions, thus we cannot update
384 : // only a part of the vector
385 : //
386 :
387 5757064 : if (_vars[0].scalars().size() > 0)
388 : {
389 49884 : computeScalarVars(type);
390 : // compute time derivatives of scalar aux variables _after_ the values were updated
391 49884 : if (_fe_problem.dt() > 0.)
392 78550 : for (auto & ti : _time_integrators)
393 39275 : ti->computeTimeDerivatives();
394 : }
395 :
396 5757064 : if (_vars[0].fieldVariables().size() > 0)
397 : {
398 1988791 : computeNodalArrayVars(type);
399 1988791 : computeNodalVecVars(type);
400 1988791 : computeNodalVars(type);
401 1988787 : computeMortarNodalVars(type);
402 1988787 : computeElementalArrayVars(type);
403 1988787 : computeElementalVecVars(type);
404 1988787 : computeElementalVars(type);
405 :
406 : // compute time derivatives of nodal aux variables _after_ the values were updated
407 1988754 : if (_fe_problem.dt() > 0.)
408 3444741 : for (auto & ti : _time_integrators)
409 1705685 : ti->computeTimeDerivatives();
410 : }
411 :
412 5757027 : if (_serialized_solution.get())
413 2052 : serializeSolution();
414 5757027 : }
415 :
416 : std::set<std::string>
417 1439869 : AuxiliarySystem::getDependObjects(ExecFlagType type)
418 : {
419 1439869 : std::set<std::string> depend_objects;
420 :
421 : // Elemental AuxKernels
422 : {
423 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
424 1439869 : _elemental_aux_storage[type].getActiveObjects();
425 1516890 : for (const auto & aux : auxs)
426 : {
427 77021 : const std::set<UserObjectName> & uo = aux->getDependObjects();
428 77021 : depend_objects.insert(uo.begin(), uo.end());
429 : }
430 : }
431 :
432 : // Elemental VectorAuxKernels
433 : {
434 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
435 1439869 : _elemental_vec_aux_storage[type].getActiveObjects();
436 1440141 : for (const auto & aux : auxs)
437 : {
438 272 : const std::set<UserObjectName> & uo = aux->getDependObjects();
439 272 : depend_objects.insert(uo.begin(), uo.end());
440 : }
441 : }
442 :
443 : // Elemental ArrayAuxKernels
444 : {
445 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
446 1439869 : _elemental_array_aux_storage[type].getActiveObjects();
447 1439965 : for (const auto & aux : auxs)
448 : {
449 96 : const std::set<UserObjectName> & uo = aux->getDependObjects();
450 96 : depend_objects.insert(uo.begin(), uo.end());
451 : }
452 : }
453 :
454 : // Nodal AuxKernels
455 : {
456 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
457 1439869 : _nodal_aux_storage[type].getActiveObjects();
458 1477787 : for (const auto & aux : auxs)
459 : {
460 37918 : const std::set<UserObjectName> & uo = aux->getDependObjects();
461 37918 : depend_objects.insert(uo.begin(), uo.end());
462 : }
463 : }
464 :
465 : // Mortar Nodal AuxKernels
466 : {
467 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
468 1439869 : _mortar_nodal_aux_storage[type].getActiveObjects();
469 1440013 : for (const auto & aux : auxs)
470 : {
471 144 : const std::set<UserObjectName> & uo = aux->getDependObjects();
472 144 : depend_objects.insert(uo.begin(), uo.end());
473 : }
474 : }
475 :
476 : // Nodal VectorAuxKernels
477 : {
478 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
479 1439869 : _nodal_vec_aux_storage[type].getActiveObjects();
480 1439953 : for (const auto & aux : auxs)
481 : {
482 84 : const std::set<UserObjectName> & uo = aux->getDependObjects();
483 84 : depend_objects.insert(uo.begin(), uo.end());
484 : }
485 : }
486 :
487 : // Nodal ArrayAuxKernels
488 : {
489 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
490 1439869 : _nodal_array_aux_storage[type].getActiveObjects();
491 1440013 : for (const auto & aux : auxs)
492 : {
493 144 : const std::set<UserObjectName> & uo = aux->getDependObjects();
494 144 : depend_objects.insert(uo.begin(), uo.end());
495 : }
496 : }
497 :
498 1439869 : return depend_objects;
499 0 : }
500 :
501 : std::set<std::string>
502 55380 : AuxiliarySystem::getDependObjects()
503 : {
504 55380 : std::set<std::string> depend_objects;
505 :
506 : // Elemental AuxKernels
507 : {
508 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
509 55380 : _elemental_aux_storage.getActiveObjects();
510 95865 : for (const auto & aux : auxs)
511 : {
512 40485 : const std::set<UserObjectName> & uo = aux->getDependObjects();
513 40485 : depend_objects.insert(uo.begin(), uo.end());
514 : }
515 : }
516 :
517 : // Elemental VectorAuxKernels
518 : {
519 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
520 55380 : _elemental_vec_aux_storage.getActiveObjects();
521 55522 : for (const auto & aux : auxs)
522 : {
523 142 : const std::set<UserObjectName> & uo = aux->getDependObjects();
524 142 : depend_objects.insert(uo.begin(), uo.end());
525 : }
526 : }
527 :
528 : // Elemental ArrayAuxKernels
529 : {
530 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
531 55380 : _elemental_array_aux_storage.getActiveObjects();
532 55440 : for (const auto & aux : auxs)
533 : {
534 60 : const std::set<UserObjectName> & uo = aux->getDependObjects();
535 60 : depend_objects.insert(uo.begin(), uo.end());
536 : }
537 : }
538 :
539 : // Nodal AuxKernels
540 : {
541 55380 : const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
542 75275 : for (const auto & aux : auxs)
543 : {
544 19895 : const std::set<UserObjectName> & uo = aux->getDependObjects();
545 19895 : depend_objects.insert(uo.begin(), uo.end());
546 : }
547 : }
548 :
549 : // Mortar Nodal AuxKernels
550 : {
551 : const std::vector<std::shared_ptr<AuxKernel>> & auxs =
552 55380 : _mortar_nodal_aux_storage.getActiveObjects();
553 55452 : for (const auto & aux : auxs)
554 : {
555 72 : const std::set<UserObjectName> & uo = aux->getDependObjects();
556 72 : depend_objects.insert(uo.begin(), uo.end());
557 : }
558 : }
559 :
560 : // Nodal VectorAuxKernels
561 : {
562 : const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
563 55380 : _nodal_vec_aux_storage.getActiveObjects();
564 55428 : for (const auto & aux : auxs)
565 : {
566 48 : const std::set<UserObjectName> & uo = aux->getDependObjects();
567 48 : depend_objects.insert(uo.begin(), uo.end());
568 : }
569 : }
570 :
571 : // Nodal ArrayAuxKernels
572 : {
573 : const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
574 55380 : _nodal_array_aux_storage.getActiveObjects();
575 55464 : for (const auto & aux : auxs)
576 : {
577 84 : const std::set<UserObjectName> & uo = aux->getDependObjects();
578 84 : depend_objects.insert(uo.begin(), uo.end());
579 : }
580 : }
581 :
582 55380 : return depend_objects;
583 0 : }
584 :
585 : void
586 49884 : AuxiliarySystem::setScalarVariableCoupleableTags(ExecFlagType type)
587 : {
588 49884 : const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
589 49884 : const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
590 :
591 49884 : std::set<TagID> needed_sc_var_matrix_tags;
592 49884 : std::set<TagID> needed_sc_var_vector_tags;
593 67769 : for (const auto & obj : objects)
594 : {
595 17885 : auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
596 17885 : needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
597 :
598 17885 : auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
599 17885 : needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
600 : }
601 :
602 49884 : _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
603 49884 : _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
604 49884 : }
605 :
606 : void
607 49884 : AuxiliarySystem::clearScalarVariableCoupleableTags()
608 : {
609 49884 : _fe_problem.clearActiveScalarVariableCoupleableMatrixTags(0);
610 49884 : _fe_problem.clearActiveScalarVariableCoupleableVectorTags(0);
611 49884 : }
612 :
613 : void
614 49884 : AuxiliarySystem::computeScalarVars(ExecFlagType type)
615 : {
616 49884 : setScalarVariableCoupleableTags(type);
617 :
618 : // Reference to the current storage container
619 49884 : const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
620 :
621 49884 : if (storage.hasActiveObjects())
622 : {
623 16328 : TIME_SECTION("computeScalarVars", 1);
624 :
625 : PARALLEL_TRY
626 : {
627 : // FIXME: run multi-threaded
628 16328 : THREAD_ID tid = 0;
629 16328 : if (storage.hasActiveObjects())
630 : {
631 16328 : _fe_problem.reinitScalars(tid);
632 :
633 : const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
634 16328 : storage.getActiveObjects(tid);
635 :
636 : // Call compute() method on all active AuxScalarKernel objects
637 34213 : for (const auto & obj : objects)
638 17885 : obj->compute();
639 :
640 16328 : const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
641 50537 : for (const auto & var : scalar_vars)
642 34209 : var->insert(solution());
643 : }
644 : }
645 16328 : PARALLEL_CATCH;
646 :
647 16328 : solution().close();
648 16328 : _sys.update();
649 16328 : }
650 :
651 49884 : clearScalarVariableCoupleableTags();
652 49884 : }
653 :
654 : void
655 1988791 : AuxiliarySystem::computeNodalVars(ExecFlagType type)
656 : {
657 1988791 : TIME_SECTION("computeNodalVars", 3);
658 :
659 1988791 : const MooseObjectWarehouse<AuxKernel> & nodal = _nodal_aux_storage[type];
660 1988791 : computeNodalVarsHelper<AuxKernel>(nodal);
661 1988787 : }
662 :
663 : void
664 1988791 : AuxiliarySystem::computeNodalVecVars(ExecFlagType type)
665 : {
666 1988791 : TIME_SECTION("computeNodalVecVars", 3);
667 :
668 1988791 : const MooseObjectWarehouse<VectorAuxKernel> & nodal = _nodal_vec_aux_storage[type];
669 1988791 : computeNodalVarsHelper<VectorAuxKernel>(nodal);
670 1988791 : }
671 :
672 : void
673 1988791 : AuxiliarySystem::computeNodalArrayVars(ExecFlagType type)
674 : {
675 1988791 : const MooseObjectWarehouse<ArrayAuxKernel> & nodal = _nodal_array_aux_storage[type];
676 1988791 : computeNodalVarsHelper<ArrayAuxKernel>(nodal);
677 1988791 : }
678 :
679 : void
680 1988787 : AuxiliarySystem::computeMortarNodalVars(const ExecFlagType type)
681 : {
682 1988787 : TIME_SECTION("computeMortarNodalVars", 3);
683 :
684 1988787 : const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
685 :
686 : mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
687 : "We don't allow creation of block restricted mortar nodal aux kernels.");
688 :
689 1988787 : if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
690 : {
691 169 : ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
692 338 : for (const auto & [bnd_id, mortar_nodal_auxes] :
693 507 : mortar_nodal_warehouse.getActiveBoundaryObjects())
694 338 : for (const auto index : index_range(mortar_nodal_auxes))
695 : {
696 : PARALLEL_TRY
697 : {
698 : try
699 : {
700 : ComputeMortarNodalAuxBndThread<AuxKernel> mnabt(
701 169 : _fe_problem, mortar_nodal_warehouse, bnd_id, index);
702 169 : Threads::parallel_reduce(bnd_nodes, mnabt);
703 169 : }
704 0 : catch (libMesh::LogicError & e)
705 : {
706 0 : _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
707 0 : "nodal Auxiliary variable computation:\n" +
708 0 : std::string(e.what()));
709 0 : }
710 0 : catch (MooseException & e)
711 : {
712 0 : _fe_problem.setException("The following MooseException was raised during mortar nodal "
713 0 : "Auxiliary variable computation:\n" +
714 0 : std::string(e.what()));
715 0 : }
716 0 : catch (MetaPhysicL::LogicError & e)
717 : {
718 0 : moose::translateMetaPhysicLError(e);
719 0 : }
720 : }
721 169 : PARALLEL_CATCH;
722 :
723 : // We need to make sure we propagate exceptions to all processes before trying to close
724 : // here, which is a parallel operation
725 169 : solution().close();
726 169 : _sys.update();
727 : }
728 : }
729 1988787 : }
730 :
731 : void
732 1988787 : AuxiliarySystem::computeElementalVars(ExecFlagType type)
733 : {
734 1988787 : TIME_SECTION("computeElementalVars", 3);
735 :
736 1988787 : const MooseObjectWarehouse<AuxKernel> & elemental = _elemental_aux_storage[type];
737 1988787 : computeElementalVarsHelper<AuxKernel>(elemental);
738 1988754 : }
739 :
740 : void
741 1988787 : AuxiliarySystem::computeElementalVecVars(ExecFlagType type)
742 : {
743 1988787 : TIME_SECTION("computeElementalVecVars", 3);
744 :
745 1988787 : const MooseObjectWarehouse<VectorAuxKernel> & elemental = _elemental_vec_aux_storage[type];
746 1988787 : computeElementalVarsHelper<VectorAuxKernel>(elemental);
747 1988787 : }
748 :
749 : void
750 1988787 : AuxiliarySystem::computeElementalArrayVars(ExecFlagType type)
751 : {
752 1988787 : const MooseObjectWarehouse<ArrayAuxKernel> & elemental = _elemental_array_aux_storage[type];
753 1988787 : computeElementalVarsHelper<ArrayAuxKernel>(elemental);
754 1988787 : }
755 :
756 : void
757 0 : AuxiliarySystem::augmentSparsity(SparsityPattern::Graph & /*sparsity*/,
758 : std::vector<dof_id_type> & /*n_nz*/,
759 : std::vector<dof_id_type> &
760 : /*n_oz*/)
761 : {
762 0 : }
763 :
764 : Order
765 62197 : AuxiliarySystem::getMinQuadratureOrder()
766 : {
767 62197 : Order order = CONSTANT;
768 62197 : std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
769 136090 : for (const auto & var : vars)
770 : {
771 73893 : if (!var->isNodal()) // nodal aux variables do not need quadrature
772 : {
773 37823 : FEType fe_type = var->feType();
774 37823 : if (fe_type.default_quadrature_order() > order)
775 19247 : order = fe_type.default_quadrature_order();
776 : }
777 : }
778 :
779 62197 : return order;
780 62197 : }
781 :
782 : bool
783 26182 : AuxiliarySystem::needMaterialOnSide(BoundaryID bnd_id)
784 : {
785 51844 : return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
786 51844 : _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
787 : }
788 :
789 : void
790 506 : AuxiliarySystem::copyCurrentIntoPreviousNL()
791 : {
792 506 : if (solutionPreviousNewton())
793 506 : *solutionPreviousNewton() = *currentSolution();
794 506 : }
795 :
796 : template <typename AuxKernelType>
797 : void
798 5966361 : AuxiliarySystem::computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
799 : {
800 5966361 : if (warehouse.hasActiveBlockObjects())
801 : {
802 : // Block Elemental AuxKernels
803 : PARALLEL_TRY
804 : {
805 72922 : ConstElemRange & range = *_mesh.getActiveLocalElementRange();
806 72922 : ComputeElemAuxVarsThread<AuxKernelType> eavt(_fe_problem, warehouse, true);
807 : try
808 : {
809 72922 : Threads::parallel_reduce(range, eavt);
810 : }
811 0 : catch (MooseException & e)
812 : {
813 0 : _fe_problem.setException("The following MooseException was raised during elemental "
814 : "Auxiliary variable computation:\n" +
815 0 : std::string(e.what()));
816 : }
817 72895 : }
818 72895 : PARALLEL_CATCH;
819 :
820 : // We need to make sure we propagate exceptions to all processes before trying to close
821 : // here, which is a parallel operation
822 72895 : solution().close();
823 72895 : _sys.update();
824 : }
825 :
826 : // Boundary Elemental AuxKernels
827 5966334 : if (warehouse.hasActiveBoundaryObjects())
828 : {
829 24799 : TIME_SECTION("computeElementalVecVars", 3);
830 :
831 : PARALLEL_TRY
832 : {
833 24799 : ConstBndElemRange & bnd_elems = *_mesh.getBoundaryElementRange();
834 24799 : ComputeElemAuxBcsThread<AuxKernelType> eabt(_fe_problem, warehouse, true);
835 : try
836 : {
837 24799 : Threads::parallel_reduce(bnd_elems, eabt);
838 : }
839 0 : catch (MooseException & e)
840 : {
841 0 : _fe_problem.setException("The following MooseException was raised during boundary "
842 : "elemental Auxiliary variable computation:\n" +
843 0 : std::string(e.what()));
844 : }
845 24793 : }
846 24793 : PARALLEL_CATCH;
847 :
848 : // We need to make sure we propagate exceptions to all processes before trying to close
849 : // here, which is a parallel operation
850 24793 : solution().close();
851 24793 : _sys.update();
852 24793 : }
853 5966328 : }
854 :
855 : template <typename AuxKernelType>
856 : void
857 5966373 : AuxiliarySystem::computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
858 : {
859 5966373 : if (warehouse.hasActiveBlockObjects())
860 : {
861 : // Block Nodal AuxKernels
862 : PARALLEL_TRY
863 : {
864 133439 : ConstNodeRange & range = *_mesh.getLocalNodeRange();
865 133439 : ComputeNodalAuxVarsThread<AuxKernelType> navt(_fe_problem, warehouse);
866 133439 : Threads::parallel_reduce(range, navt);
867 :
868 133435 : solution().close();
869 133435 : _sys.update();
870 133435 : }
871 133435 : PARALLEL_CATCH;
872 : }
873 :
874 5966369 : if (warehouse.hasActiveBoundaryObjects())
875 : {
876 84051 : TIME_SECTION("computeBoundaryObjects", 3);
877 :
878 : // Boundary Nodal AuxKernels
879 : PARALLEL_TRY
880 : {
881 84051 : ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
882 84051 : ComputeNodalAuxBcsThread<AuxKernelType> nabt(_fe_problem, warehouse);
883 84051 : Threads::parallel_reduce(bnd_nodes, nabt);
884 :
885 84051 : solution().close();
886 84051 : _sys.update();
887 84051 : }
888 84051 : PARALLEL_CATCH;
889 84051 : }
890 5966369 : }
891 :
892 : void
893 507 : AuxiliarySystem::variableWiseRelativeSolutionDifferenceNorm(
894 : std::vector<Number> & rel_diff_norms) const
895 : {
896 507 : rel_diff_norms.resize(nVariables(), 0);
897 : // Get dof map from system
898 507 : const auto & dof_map = _sys.get_dof_map();
899 :
900 1521 : for (const auto n : make_range(nVariables()))
901 : {
902 : // Get local indices from dof map for each variable
903 1014 : std::vector<dof_id_type> local_indices_n;
904 1014 : dof_map.local_variable_indices(local_indices_n, _mesh, n);
905 1014 : Number diff_norm_n = 0;
906 1014 : Number norm_n = 0;
907 : // Get values from system, update norm
908 90312 : for (const auto local_index : local_indices_n)
909 : {
910 89298 : const Number & value = solution()(local_index);
911 89298 : const Number & value_old = solutionOld()(local_index);
912 89298 : diff_norm_n += Utility::pow<2, Number>(value - value_old);
913 89298 : norm_n += Utility::pow<2, Number>(value);
914 : }
915 : // Aggregate norm over proceccors
916 1014 : _communicator.sum(diff_norm_n);
917 1014 : _communicator.sum(norm_n);
918 1014 : diff_norm_n = sqrt(diff_norm_n);
919 1014 : norm_n = sqrt(norm_n);
920 1014 : rel_diff_norms[n] = diff_norm_n / norm_n;
921 1014 : }
922 507 : }
923 :
924 : template void
925 : AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
926 : template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
927 : const MooseObjectWarehouse<VectorAuxKernel> &);
928 : template void
929 : AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
930 : template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
931 : const MooseObjectWarehouse<VectorAuxKernel> &);
|