https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AuxiliarySystem.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 "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"
23#include "Parser.h"
24#include "TimeIntegrator.h"
25#include "Conversion.h"
26#include "MooseUtils.h"
27
28#include "libmesh/quadrature_gauss.h"
29#include "libmesh/node_range.h"
30#include "libmesh/numeric_vector.h"
31#include "libmesh/default_coupling.h"
32#include "libmesh/string_to_enum.h"
33#include "libmesh/fe_interface.h"
34
35// C++
36#include <cstring> // for "Jacobian" exception test
37
38// AuxiliarySystem ////////
39
40AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
41 : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
42 PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
44 _sys(subproblem.es().add_system<System>(name)),
45 _current_solution(_sys.current_local_solution.get()),
46 _aux_scalar_storage(_app.getExecuteOnEnum()),
47 _nodal_aux_storage(_app.getExecuteOnEnum()),
48 _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
49 _elemental_aux_storage(_app.getExecuteOnEnum()),
50 _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
51 _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
52 _nodal_array_aux_storage(_app.getExecuteOnEnum()),
53 _elemental_array_aux_storage(_app.getExecuteOnEnum())
54#ifdef MOOSE_KOKKOS_ENABLED
55 ,
56 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum()),
57 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum())
58#endif
59{
60 _nodal_vars.resize(libMesh::n_threads());
61 _elem_vars.resize(libMesh::n_threads());
62
63 if (!_fe_problem.defaultGhosting())
64 {
65 auto & dof_map = _sys.get_dof_map();
66 dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
67 dof_map.set_implicit_neighbor_dofs(false);
68 }
69}
70
72
73void
79
80void
82{
83 TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
84
88
89 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
90 {
93
94 _nodal_aux_storage.sort(tid);
95 _nodal_aux_storage.initialSetup(tid);
96
98 _mortar_nodal_aux_storage.initialSetup(tid);
99
100 _nodal_vec_aux_storage.sort(tid);
101 _nodal_vec_aux_storage.initialSetup(tid);
102
103 _nodal_array_aux_storage.sort(tid);
104 _nodal_array_aux_storage.initialSetup(tid);
105
106 _elemental_aux_storage.sort(tid);
107 _elemental_aux_storage.initialSetup(tid);
108
110 _elemental_vec_aux_storage.initialSetup(tid);
111
113 _elemental_array_aux_storage.initialSetup(tid);
114 }
115
116#ifdef MOOSE_KOKKOS_ENABLED
119
122#endif
123}
124
125void
131
132void
134 const bool skip_current_to_old)
135{
136 if (iteration_type == Moose::SolutionIterationType::Time)
137 LinearFVGradientManager::copyPreviousGradientStates(iteration_type, skip_current_to_old);
138}
139
140void
145
146void
148{
150
151 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
152 {
154 _nodal_aux_storage.timestepSetup(tid);
155 _mortar_nodal_aux_storage.timestepSetup(tid);
156 _nodal_vec_aux_storage.timestepSetup(tid);
157 _nodal_array_aux_storage.timestepSetup(tid);
158 _elemental_aux_storage.timestepSetup(tid);
159 _elemental_vec_aux_storage.timestepSetup(tid);
160 _elemental_array_aux_storage.timestepSetup(tid);
161 }
162
163#ifdef MOOSE_KOKKOS_ENABLED
166#endif
167}
168
169void
171{
172 SystemBase::customSetup(exec_type);
173
174 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
175 {
176 _aux_scalar_storage.customSetup(exec_type, tid);
177 _nodal_aux_storage.customSetup(exec_type, tid);
178 _mortar_nodal_aux_storage.customSetup(exec_type, tid);
179 _nodal_vec_aux_storage.customSetup(exec_type, tid);
180 _nodal_array_aux_storage.customSetup(exec_type, tid);
181 _elemental_aux_storage.customSetup(exec_type, tid);
182 _elemental_vec_aux_storage.customSetup(exec_type, tid);
183 _elemental_array_aux_storage.customSetup(exec_type, tid);
184 }
185
186#ifdef MOOSE_KOKKOS_ENABLED
187 _kokkos_nodal_aux_storage.customSetup(exec_type, /*tid=*/0);
188 _kokkos_elemental_aux_storage.customSetup(exec_type, /*tid=*/0);
189#endif
190}
191
192void
194{
196
197 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
198 {
200 _nodal_aux_storage.subdomainSetup(tid);
201 _mortar_nodal_aux_storage.subdomainSetup(tid);
202 _nodal_vec_aux_storage.subdomainSetup(tid);
203 _nodal_array_aux_storage.subdomainSetup(tid);
204 _elemental_aux_storage.subdomainSetup(tid);
205 _elemental_vec_aux_storage.subdomainSetup(tid);
206 _elemental_array_aux_storage.subdomainSetup(tid);
207 }
208}
209
210void
212{
214
215 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
216 {
218 _nodal_aux_storage.jacobianSetup(tid);
219 _mortar_nodal_aux_storage.jacobianSetup(tid);
220 _nodal_vec_aux_storage.jacobianSetup(tid);
221 _nodal_array_aux_storage.jacobianSetup(tid);
222 _elemental_aux_storage.jacobianSetup(tid);
223 _elemental_vec_aux_storage.jacobianSetup(tid);
224 _elemental_array_aux_storage.jacobianSetup(tid);
225 }
226
227#ifdef MOOSE_KOKKOS_ENABLED
230#endif
231}
232
233void
235{
237
238 for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
239 {
241 _nodal_aux_storage.residualSetup(tid);
242 _mortar_nodal_aux_storage.residualSetup(tid);
243 _nodal_vec_aux_storage.residualSetup(tid);
244 _nodal_array_aux_storage.residualSetup(tid);
245 _elemental_aux_storage.residualSetup(tid);
246 _elemental_vec_aux_storage.residualSetup(tid);
247 _elemental_array_aux_storage.residualSetup(tid);
248 }
249
250#ifdef MOOSE_KOKKOS_ENABLED
253#endif
254}
255
256void
258{
260 _nodal_aux_storage.updateActive(tid);
261 _mortar_nodal_aux_storage.updateActive(tid);
262 _nodal_vec_aux_storage.updateActive(tid);
263 _nodal_array_aux_storage.updateActive(tid);
264 _elemental_aux_storage.updateActive(tid);
265 _elemental_vec_aux_storage.updateActive(tid);
266 _elemental_array_aux_storage.updateActive(tid);
267
268#ifdef MOOSE_KOKKOS_ENABLED
269 if (tid == 0)
270 {
273 }
274#endif
275}
276
277void
278AuxiliarySystem::addVariable(const std::string & var_type,
279 const std::string & name,
280 InputParameters & parameters)
281{
282 SystemBase::addVariable(var_type, name, parameters);
283
284 const auto fe_type = MooseUtils::variableFEType(parameters);
285
286 if (var_type == "MooseVariableScalar")
287 return;
288
289 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
290 {
291 if (FEInterface::field_type(fe_type) == libMesh::TYPE_VECTOR)
292 {
293 auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
294 if (var)
295 {
296 if (var->feType().family == LAGRANGE_VEC)
297 _nodal_vars[tid].push_back(var);
298 else
299 _elem_vars[tid].push_back(var);
300 }
301 }
302
303 else
304 {
305 MooseVariableBase * var_base = _vars[tid].getVariable(name);
306
307 auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
308
309 if (var)
310 {
311 if (var->feType().family == LAGRANGE)
312 _nodal_vars[tid].push_back(var);
313 else
314 _elem_vars[tid].push_back(var);
315 }
316
317 auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
318
319 if (avar)
320 {
321 if (avar->feType().family == LAGRANGE)
322 _nodal_vars[tid].push_back(avar);
323 else
324 _elem_vars[tid].push_back(avar);
325 }
326 }
327 }
328}
329
330void
331AuxiliarySystem::addKernel(const std::string & kernel_name,
332 const std::string & name,
333 InputParameters & parameters)
334{
335 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
336 {
337 const auto & base = parameters.getBase();
338 if (base == "AuxKernel" || base == "Bounds")
339 {
340 std::shared_ptr<AuxKernel> kernel =
341 _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
342 if (kernel->isNodal())
343 {
344 if (kernel->isMortar())
345 _mortar_nodal_aux_storage.addObject(kernel, tid);
346 else
347 _nodal_aux_storage.addObject(kernel, tid);
348 }
349 else
350 _elemental_aux_storage.addObject(kernel, tid);
351 }
352
353 else if (base == "VectorAuxKernel")
354 {
355 std::shared_ptr<VectorAuxKernel> kernel =
356 _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
357 if (kernel->isNodal())
358 {
359 if (kernel->isMortar())
360 mooseError("Vector mortar aux kernels not yet implemented");
361 _nodal_vec_aux_storage.addObject(kernel, tid);
362 }
363 else
364 _elemental_vec_aux_storage.addObject(kernel, tid);
365 }
366
367 else if (base == "ArrayAuxKernel")
368 {
369 std::shared_ptr<ArrayAuxKernel> kernel =
370 _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
371 if (kernel->isNodal())
372 {
373 if (kernel->isMortar())
374 mooseError("Vector mortar aux kernels not yet implemented");
375 _nodal_array_aux_storage.addObject(kernel, tid);
376 }
377 else
378 _elemental_array_aux_storage.addObject(kernel, tid);
379 }
380 else
381 mooseAssert(false,
382 "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
383 "' to the auxiliary system with invalid _moose_base: " + base);
384 }
385}
386
387void
388AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
389 const std::string & name,
390 InputParameters & parameters)
391{
392 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
393 {
394 std::shared_ptr<AuxScalarKernel> kernel =
395 _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
396 _aux_scalar_storage.addObject(kernel, tid);
397 }
398}
399
400void
401AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
402{
403 for (auto * var : _nodal_vars[tid])
404 var->computeElemValues();
405
406 for (auto * var : _elem_vars[tid])
407 {
408 var->reinitAux();
409 var->computeElemValues();
410 }
411}
412
413void
414AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
415{
416 for (auto * var : _nodal_vars[tid])
417 var->computeElemValuesFace();
418
419 for (auto * var : _elem_vars[tid])
420 {
421 var->reinitAux();
422 var->reinitAuxNeighbor();
423 var->computeElemValuesFace();
424 }
425}
426
427void
429{
430 if (_serialized_solution.get() &&
431 _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
432 {
433 if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
434 {
435 _serialized_solution->clear();
436 _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
437 }
438
440 }
441}
442
443void
445{
446 // avoid division by dt which might be zero.
447 if (_fe_problem.dt() > 0.)
448 for (auto & ti : _time_integrators)
449 ti->preStep();
450
451 // We need to compute time derivatives every time each kind of the variables is finished, because:
452 //
453 // a) the user might want to use the aux variable value somewhere, thus we need to provide the
454 // up-to-date value
455 // b) time integration system works with the whole vectors of solutions, thus we cannot update
456 // only a part of the vector
457 //
458
459 if (_vars[0].scalars().size() > 0)
460 {
461 computeScalarVars(type);
462 // compute time derivatives of scalar aux variables _after_ the values were updated
463 if (_fe_problem.dt() > 0.)
464 for (auto & ti : _time_integrators)
465 ti->computeTimeDerivatives();
466 }
467
468 if (_vars[0].fieldVariables().size() > 0)
469 {
472 computeNodalVars(type);
477
478#ifdef MOOSE_KOKKOS_ENABLED
479 kokkosCompute(type);
480#endif
481
483 {
484 solution().close();
485 _sys.update();
487 }
488
489 // compute time derivatives of nodal aux variables _after_ the values were updated
490 if (_fe_problem.dt() > 0.)
491 for (auto & ti : _time_integrators)
492 ti->computeTimeDerivatives();
493 }
494
495 if (_serialized_solution.get())
497}
498
499std::set<std::string>
501{
502 std::set<std::string> depend_objects;
503
504 // Elemental AuxKernels
505 {
506 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
507 _elemental_aux_storage[type].getActiveObjects();
508 for (const auto & aux : auxs)
509 {
510 const std::set<UserObjectName> & uo = aux->getDependObjects();
511 depend_objects.insert(uo.begin(), uo.end());
512 }
513 }
514
515 // Elemental VectorAuxKernels
516 {
517 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
518 _elemental_vec_aux_storage[type].getActiveObjects();
519 for (const auto & aux : auxs)
520 {
521 const std::set<UserObjectName> & uo = aux->getDependObjects();
522 depend_objects.insert(uo.begin(), uo.end());
523 }
524 }
525
526 // Elemental ArrayAuxKernels
527 {
528 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
529 _elemental_array_aux_storage[type].getActiveObjects();
530 for (const auto & aux : auxs)
531 {
532 const std::set<UserObjectName> & uo = aux->getDependObjects();
533 depend_objects.insert(uo.begin(), uo.end());
534 }
535 }
536
537 // Nodal AuxKernels
538 {
539 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
540 _nodal_aux_storage[type].getActiveObjects();
541 for (const auto & aux : auxs)
542 {
543 const std::set<UserObjectName> & uo = aux->getDependObjects();
544 depend_objects.insert(uo.begin(), uo.end());
545 }
546 }
547
548 // Mortar Nodal AuxKernels
549 {
550 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
551 _mortar_nodal_aux_storage[type].getActiveObjects();
552 for (const auto & aux : auxs)
553 {
554 const std::set<UserObjectName> & uo = aux->getDependObjects();
555 depend_objects.insert(uo.begin(), uo.end());
556 }
557 }
558
559 // Nodal VectorAuxKernels
560 {
561 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
562 _nodal_vec_aux_storage[type].getActiveObjects();
563 for (const auto & aux : auxs)
564 {
565 const std::set<UserObjectName> & uo = aux->getDependObjects();
566 depend_objects.insert(uo.begin(), uo.end());
567 }
568 }
569
570 // Nodal ArrayAuxKernels
571 {
572 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
573 _nodal_array_aux_storage[type].getActiveObjects();
574 for (const auto & aux : auxs)
575 {
576 const std::set<UserObjectName> & uo = aux->getDependObjects();
577 depend_objects.insert(uo.begin(), uo.end());
578 }
579 }
580
581#ifdef MOOSE_KOKKOS_ENABLED
582 // Kokkos NodalAuxKernels
583 {
584 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
586 for (const auto & aux : auxs)
587 {
588 const std::set<UserObjectName> & uo = aux->getDependObjects();
589 depend_objects.insert(uo.begin(), uo.end());
590 }
591 }
592
593 // Kokkos ElementalAuxKernels
594 {
595 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
597 for (const auto & aux : auxs)
598 {
599 const std::set<UserObjectName> & uo = aux->getDependObjects();
600 depend_objects.insert(uo.begin(), uo.end());
601 }
602 }
603#endif
604
605 return depend_objects;
606}
607
608std::set<std::string>
610{
611 std::set<std::string> depend_objects;
612
613 // Elemental AuxKernels
614 {
615 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
616 _elemental_aux_storage.getActiveObjects();
617 for (const auto & aux : auxs)
618 {
619 const std::set<UserObjectName> & uo = aux->getDependObjects();
620 depend_objects.insert(uo.begin(), uo.end());
621 }
622 }
623
624 // Elemental VectorAuxKernels
625 {
626 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
627 _elemental_vec_aux_storage.getActiveObjects();
628 for (const auto & aux : auxs)
629 {
630 const std::set<UserObjectName> & uo = aux->getDependObjects();
631 depend_objects.insert(uo.begin(), uo.end());
632 }
633 }
634
635 // Elemental ArrayAuxKernels
636 {
637 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
638 _elemental_array_aux_storage.getActiveObjects();
639 for (const auto & aux : auxs)
640 {
641 const std::set<UserObjectName> & uo = aux->getDependObjects();
642 depend_objects.insert(uo.begin(), uo.end());
643 }
644 }
645
646 // Nodal AuxKernels
647 {
648 const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
649 for (const auto & aux : auxs)
650 {
651 const std::set<UserObjectName> & uo = aux->getDependObjects();
652 depend_objects.insert(uo.begin(), uo.end());
653 }
654 }
655
656 // Mortar Nodal AuxKernels
657 {
658 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
659 _mortar_nodal_aux_storage.getActiveObjects();
660 for (const auto & aux : auxs)
661 {
662 const std::set<UserObjectName> & uo = aux->getDependObjects();
663 depend_objects.insert(uo.begin(), uo.end());
664 }
665 }
666
667 // Nodal VectorAuxKernels
668 {
669 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
670 _nodal_vec_aux_storage.getActiveObjects();
671 for (const auto & aux : auxs)
672 {
673 const std::set<UserObjectName> & uo = aux->getDependObjects();
674 depend_objects.insert(uo.begin(), uo.end());
675 }
676 }
677
678 // Nodal ArrayAuxKernels
679 {
680 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
681 _nodal_array_aux_storage.getActiveObjects();
682 for (const auto & aux : auxs)
683 {
684 const std::set<UserObjectName> & uo = aux->getDependObjects();
685 depend_objects.insert(uo.begin(), uo.end());
686 }
687 }
688
689#ifdef MOOSE_KOKKOS_ENABLED
690 // Nodal KokkosAuxKernels
691 {
692 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
694 for (const auto & aux : auxs)
695 {
696 const std::set<UserObjectName> & uo = aux->getDependObjects();
697 depend_objects.insert(uo.begin(), uo.end());
698 }
699 }
700
701 // Elemental KokkosAuxKernels
702 {
703 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
705 for (const auto & aux : auxs)
706 {
707 const std::set<UserObjectName> & uo = aux->getDependObjects();
708 depend_objects.insert(uo.begin(), uo.end());
709 }
710 }
711#endif
712
713 return depend_objects;
714}
715
716void
718{
720 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
721
722 std::set<TagID> needed_sc_var_matrix_tags;
723 std::set<TagID> needed_sc_var_vector_tags;
724 for (const auto & obj : objects)
725 {
726 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
727 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
728
729 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
730 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
731 }
732
733 _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
734 _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
735}
736
737void
743
744void
746{
748
749 // Reference to the current storage container
751
752 if (storage.hasActiveObjects())
753 {
754 TIME_SECTION("computeScalarVars", 1);
755
756 PARALLEL_TRY
757 {
758 // FIXME: run multi-threaded
759 THREAD_ID tid = 0;
760 if (storage.hasActiveObjects())
761 {
763
764 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
765 storage.getActiveObjects(tid);
766
767 // Call compute() method on all active AuxScalarKernel objects
768 for (const auto & obj : objects)
769 obj->compute();
770
771 const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
772 for (const auto & var : scalar_vars)
773 var->insert(solution());
774 }
775 }
776 PARALLEL_CATCH;
777
778 solution().close();
779 _sys.update();
780 }
781
783}
784
785void
787{
788 TIME_SECTION("computeNodalVars", 3);
789
791 computeNodalVarsHelper<AuxKernel>(nodal);
792}
793
794void
796{
797 TIME_SECTION("computeNodalVecVars", 3);
798
800 computeNodalVarsHelper<VectorAuxKernel>(nodal);
801}
802
803void
805{
807 computeNodalVarsHelper<ArrayAuxKernel>(nodal);
808}
809
810void
812{
813 TIME_SECTION("computeMortarNodalVars", 3);
814
815 const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
816
817 mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
818 "We don't allow creation of block restricted mortar nodal aux kernels.");
819
820 if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
821 {
823 for (const auto & [bnd_id, mortar_nodal_auxes] :
824 mortar_nodal_warehouse.getActiveBoundaryObjects())
825 for (const auto index : index_range(mortar_nodal_auxes))
826 {
827 PARALLEL_TRY
828 {
829 try
830 {
832 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
833 Threads::parallel_reduce(bnd_nodes, mnabt);
834 }
835 catch (MooseException & e)
836 {
837 _fe_problem.setException("The following MooseException was raised during mortar nodal "
838 "Auxiliary variable computation:\n" +
839 std::string(e.what()));
840 }
841 catch (MetaPhysicL::LogicError & e)
842 {
844 }
845 catch (std::exception & e)
846 {
847 // Continue if we find a libMesh degenerate map exception, but
848 // just re-throw for any real error
849 if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
850 !strstr(e.what(), "det != 0"))
851 throw;
852
853 _fe_problem.setException("We caught a libMesh degeneracy exception during mortar "
854 "nodal Auxiliary variable computation:\n" +
855 std::string(e.what()));
856 }
857 }
858 PARALLEL_CATCH;
859
860 // We need to make sure we propagate exceptions to all processes before trying to close
861 // here, which is a parallel operation
862 solution().close();
863 _sys.update();
864 }
865 }
866}
867
868void
870{
871 TIME_SECTION("computeElementalVars", 3);
872
874 computeElementalVarsHelper<AuxKernel>(elemental);
875}
876
877void
879{
880 TIME_SECTION("computeElementalVecVars", 3);
881
883 computeElementalVarsHelper<VectorAuxKernel>(elemental);
884}
885
886void
888{
890 computeElementalVarsHelper<ArrayAuxKernel>(elemental);
891}
892
893void
895 std::vector<dof_id_type> & /*n_nz*/,
896 std::vector<dof_id_type> &
897 /*n_oz*/)
898{
899}
900
901Order
903{
904 Order order = CONSTANT;
905 std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
906 for (const auto & var : vars)
907 {
908 if (!var->isNodal()) // nodal aux variables do not need quadrature
909 {
910 FEType fe_type = var->feType();
911 if (fe_type.default_quadrature_order() > order)
912 order = fe_type.default_quadrature_order();
913 }
914 }
915
916 return order;
917}
918
919bool
921{
922 return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
923 _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
924}
925
926void
932
933template <typename AuxKernelType>
934void
936{
937 if (warehouse.hasActiveBlockObjects())
938 {
939 // Block Elemental AuxKernels
940 PARALLEL_TRY
941 {
942 const ConstElemRange & range = *_mesh.getActiveLocalElementRange();
944 try
945 {
946 Threads::parallel_reduce(range, eavt);
947 }
948 catch (MooseException & e)
949 {
950 _fe_problem.setException("The following MooseException was raised during elemental "
951 "Auxiliary variable computation:\n" +
952 std::string(e.what()));
953 }
954 }
955 PARALLEL_CATCH;
956
957 // We need to make sure we propagate exceptions to all processes before trying to close
958 // here, which is a parallel operation
959 solution().close();
960 _sys.update();
961 }
962
963 // Boundary Elemental AuxKernels
964 if (warehouse.hasActiveBoundaryObjects())
965 {
966 TIME_SECTION("computeElementalVecVars", 3);
967
968 PARALLEL_TRY
969 {
972 try
973 {
974 Threads::parallel_reduce(bnd_elems, eabt);
975 }
976 catch (MooseException & e)
977 {
978 _fe_problem.setException("The following MooseException was raised during boundary "
979 "elemental Auxiliary variable computation:\n" +
980 std::string(e.what()));
981 }
982 }
983 PARALLEL_CATCH;
984
985 // We need to make sure we propagate exceptions to all processes before trying to close
986 // here, which is a parallel operation
987 solution().close();
988 _sys.update();
989 }
990}
991
992template <typename AuxKernelType>
993void
995{
996 if (warehouse.hasActiveBlockObjects())
997 {
998 // Block Nodal AuxKernels
999 PARALLEL_TRY
1000 {
1001 ConstNodeRange & range = *_mesh.getLocalNodeRange();
1003 Threads::parallel_reduce(range, navt);
1004
1005 solution().close();
1006 _sys.update();
1007 }
1008 PARALLEL_CATCH;
1009 }
1010
1011 if (warehouse.hasActiveBoundaryObjects())
1012 {
1013 TIME_SECTION("computeBoundaryObjects", 3);
1014
1015 // Boundary Nodal AuxKernels
1016 PARALLEL_TRY
1017 {
1020 Threads::parallel_reduce(bnd_nodes, nabt);
1021
1022 solution().close();
1023 _sys.update();
1024 }
1025 PARALLEL_CATCH;
1026 }
1027}
1028
1029void
1031 std::vector<Number> & rel_diff_norms) const
1032{
1033 rel_diff_norms.resize(nVariables(), 0);
1034 // Get dof map from system
1035 const auto & dof_map = _sys.get_dof_map();
1036
1037 for (const auto n : make_range(nVariables()))
1038 {
1039 // Get local indices from dof map for each variable
1040 std::vector<dof_id_type> local_indices_n;
1041 dof_map.local_variable_indices(local_indices_n, _mesh, n);
1042 Number diff_norm_n = 0;
1043 Number norm_n = 0;
1044 // Get values from system, update norm
1045 for (const auto local_index : local_indices_n)
1046 {
1047 const Number & value = solution()(local_index);
1048 const Number & value_old = solutionOld()(local_index);
1049 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1050 norm_n += Utility::pow<2, Number>(value);
1051 }
1052 // Aggregate norm over proceccors
1053 _communicator.sum(diff_norm_n);
1054 _communicator.sum(norm_n);
1055 diff_norm_n = sqrt(diff_norm_n);
1056 norm_n = sqrt(norm_n);
1057 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1058 }
1059}
1060
1061template void
1062AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1063template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1065template void
1066AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1067template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
boundary_id_type BoundaryID
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
char ** vars
Base class for making kernels that work on auxiliary scalar variables.
virtual void copyCurrentIntoPreviousNL()
Copies the current solution into the previous nonlinear iteration solution.
bool needMaterialOnSide(BoundaryID bnd_id)
Indicated whether this system needs material properties on boundaries.
virtual void jacobianSetup() override
virtual void residualSetup() override
void computeScalarVars(ExecFlagType type)
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds an auxiliary kernel.
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _nodal_array_aux_storage
void clearScalarVariableCoupleableTags()
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
void kokkosCompute(ExecFlagType type)
virtual void copyAdditionalStateBackwards(Moose::SolutionIterationType iteration_type, bool skip_current_to_old) override
Copy system-owned state not represented by solution vectors.
void computeMortarNodalVars(ExecFlagType type)
void computeElementalVars(ExecFlagType type)
void computeElementalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
virtual void subdomainSetup() override
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_elemental_aux_storage
virtual libMesh::Order getMinQuadratureOrder() override
Get the minimum quadrature order for evaluating elemental auxiliary variables.
virtual void initSolutionState() override
Initializes the solution state.
ExecuteMooseObjectWarehouse< AuxKernel > _elemental_aux_storage
void computeNodalVecVars(ExecFlagType type)
void variableWiseRelativeSolutionDifferenceNorm(std::vector< Number > &var_diffs) const
Computes and stores ||current - old|| / ||current|| for each variable in the given vector.
void setScalarVariableCoupleableTags(ExecFlagType type)
std::set< std::string > getDependObjects()
virtual void customSetup(const ExecFlagType &exec_type) override
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _elemental_array_aux_storage
ExecuteMooseObjectWarehouse< VectorAuxKernel > _elemental_vec_aux_storage
ExecuteMooseObjectWarehouse< AuxKernel > _nodal_aux_storage
void computeElementalVecVars(ExecFlagType type)
ExecuteMooseObjectWarehouse< VectorAuxKernel > _nodal_vec_aux_storage
virtual void restoreAdditionalStates() override
Restore system-owned state not represented by solution vectors.
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a scalar kernel.
AuxiliarySystem(FEProblemBase &subproblem, const std::string &name)
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
Reinit an element assembly info.
ExecuteMooseObjectWarehouse< AuxKernel > _mortar_nodal_aux_storage
virtual ~AuxiliarySystem()
virtual void addVariable(const std::string &var_type, const std::string &name, InputParameters &parameters) override
Canonical method for adding a variable.
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_nodal_aux_storage
const NumericVector< Number > *const & currentSolution() const override
The solution vector that is currently being operated on.
void computeElementalArrayVars(ExecFlagType type)
void computeNodalVars(ExecFlagType type)
virtual void updateActive(THREAD_ID tid)
virtual void augmentSparsity(libMesh::SparsityPattern::Graph &, std::vector< dof_id_type > &, std::vector< dof_id_type > &) override
Will modify the sparsity pattern to add logical geometric connections.
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual void serializeSolution()
ExecuteMooseObjectWarehouse< AuxScalarKernel > _aux_scalar_storage
libMesh::System & _sys
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid) override
Reinit assembly info for a side of an element.
void computeNodalArrayVars(ExecFlagType type)
virtual void timestepSetup() override
virtual void initialSetup() override
Setup Functions.
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
void computeNodalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
This class evaluates a single mortar nodal aux kernel.
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
void residualSetup(THREAD_ID tid=0) const override
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
virtual void reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering=false) override
fills the VariableValue arrays for scalar variables from the solution vector
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
virtual Real & dt() const
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, const THREAD_ID tid) override
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition Factory.C:142
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const std::string & getBase() const
Registration, update, and allocation logic for linear finite-volume cell gradients.
void computeGradients()
Compute and finalize all registered linear FV gradient fields.
void rebuildLinearFVGradientStorage()
Rebuild cached gradient values and reusable scratch storage after mesh/DOF changes.
void copyPreviousGradientStates(Moose::SolutionIterationType iteration_type, bool skip_current_to_old)
Copy published gradient values into requested older states.
bool hasLinearFVGradients() const
Whether any linear finite-volume gradient fields have been registered to this object.
void restoreGradientStates()
Restore current gradients from state one after a failed timestep.
void initializeLinearFVGradientHistoryStorage()
Register named system vectors for requested historical gradient states.
void initializeLinearFVGradientStorage()
Initialize private current and replacement gradient storage.
Class for containing MooseEnum item information.
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
libMesh::ConstNodeRange * getLocalNodeRange()
Definition MooseMesh.C:1276
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition MooseMesh.C:1290
const libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
Definition MooseMesh.C:1247
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
Definition MooseMesh.C:1303
bool hasActiveObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
Base variable class.
Class for stuff related to variables.
Interface for objects interacting with the PerfGraph.
Base class for a system (of equations)
Definition SystemBase.h:87
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed.
FEProblemBase & _fe_problem
the governing finite element/volume problem
virtual void subdomainSetup()
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition SystemBase.C:888
Factory & _factory
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Canonical method for adding a variable.
Definition SystemBase.C:717
virtual void customSetup(const ExecFlagType &exec_type)
NumericVector< Number > & solutionOld()
Definition SystemBase.h:213
virtual void initialSetup()
Setup Functions.
virtual void initSolutionState()
Initializes the solution state.
virtual void timestepSetup()
virtual void jacobianSetup()
virtual void residualSetup()
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual const std::string & name() const
NumericVector< Number > & solution()
Definition SystemBase.h:212
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition SystemBase.h:786
MooseMesh & _mesh
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
virtual void close()=0
virtual void localize(std::vector< T > &v_local) const=0
const Parallel::Communicator & _communicator
std::unique_ptr< NumericVector< Number > > current_local_solution
dof_id_type n_dofs() const
virtual void update()
const DofMap & get_dof_map() const
libMesh::FEType variableFEType(const InputParameters &params)
Definition MooseUtils.C:98
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
SolutionIterationType
Definition MooseTypes.h:270
@ VAR_AUXILIARY
Definition MooseTypes.h:771
std::string name(const ElemQuality q)
const Elem & get(const ElemType type_in)
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Tnew cast_ref(Told &oldvar)
unsigned int n_threads()
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition MooseError.C:153