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(), numThreads()),
47 _nodal_aux_storage(_app.getExecuteOnEnum(), numThreads()),
48 _mortar_nodal_aux_storage(_app.getExecuteOnEnum(), numThreads()),
49 _elemental_aux_storage(_app.getExecuteOnEnum(), numThreads()),
50 _nodal_vec_aux_storage(_app.getExecuteOnEnum(), numThreads()),
51 _elemental_vec_aux_storage(_app.getExecuteOnEnum(), numThreads()),
52 _nodal_array_aux_storage(_app.getExecuteOnEnum(), numThreads()),
53 _elemental_array_aux_storage(_app.getExecuteOnEnum(), numThreads())
54#ifdef MOOSE_KOKKOS_ENABLED
55 ,
56 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum(), 1),
57 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum(), 1)
58#endif
59{
60 _nodal_vars.resize(this->numThreads());
61 _elem_vars.resize(this->numThreads());
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 < this->numThreads(); 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
124#endif
125}
126
127void
133
134void
136 const bool skip_current_to_old)
137{
138 if (iteration_type == Moose::SolutionIterationType::Time)
139 LinearFVGradientManager::copyPreviousGradientStates(iteration_type, skip_current_to_old);
140}
141
142void
147
148void
150{
152
153 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
154 {
156 _nodal_aux_storage.timestepSetup(tid);
157 _mortar_nodal_aux_storage.timestepSetup(tid);
158 _nodal_vec_aux_storage.timestepSetup(tid);
159 _nodal_array_aux_storage.timestepSetup(tid);
160 _elemental_aux_storage.timestepSetup(tid);
161 _elemental_vec_aux_storage.timestepSetup(tid);
162 _elemental_array_aux_storage.timestepSetup(tid);
163 }
164
165#ifdef MOOSE_KOKKOS_ENABLED
168#endif
169}
170
171void
173{
174 SystemBase::customSetup(exec_type);
175
176 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
177 {
178 _aux_scalar_storage.customSetup(exec_type, tid);
179 _nodal_aux_storage.customSetup(exec_type, tid);
180 _mortar_nodal_aux_storage.customSetup(exec_type, tid);
181 _nodal_vec_aux_storage.customSetup(exec_type, tid);
182 _nodal_array_aux_storage.customSetup(exec_type, tid);
183 _elemental_aux_storage.customSetup(exec_type, tid);
184 _elemental_vec_aux_storage.customSetup(exec_type, tid);
185 _elemental_array_aux_storage.customSetup(exec_type, tid);
186 }
187
188#ifdef MOOSE_KOKKOS_ENABLED
189 _kokkos_nodal_aux_storage.customSetup(exec_type, /*tid=*/0);
190 _kokkos_elemental_aux_storage.customSetup(exec_type, /*tid=*/0);
191#endif
192}
193
194void
196{
198
199 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
200 {
202 _nodal_aux_storage.subdomainSetup(tid);
203 _mortar_nodal_aux_storage.subdomainSetup(tid);
204 _nodal_vec_aux_storage.subdomainSetup(tid);
205 _nodal_array_aux_storage.subdomainSetup(tid);
206 _elemental_aux_storage.subdomainSetup(tid);
207 _elemental_vec_aux_storage.subdomainSetup(tid);
208 _elemental_array_aux_storage.subdomainSetup(tid);
209 }
210}
211
212void
214{
216
217 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
218 {
220 _nodal_aux_storage.jacobianSetup(tid);
221 _mortar_nodal_aux_storage.jacobianSetup(tid);
222 _nodal_vec_aux_storage.jacobianSetup(tid);
223 _nodal_array_aux_storage.jacobianSetup(tid);
224 _elemental_aux_storage.jacobianSetup(tid);
225 _elemental_vec_aux_storage.jacobianSetup(tid);
226 _elemental_array_aux_storage.jacobianSetup(tid);
227 }
228
229#ifdef MOOSE_KOKKOS_ENABLED
232#endif
233}
234
235void
237{
239
240 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
241 {
243 _nodal_aux_storage.residualSetup(tid);
244 _mortar_nodal_aux_storage.residualSetup(tid);
245 _nodal_vec_aux_storage.residualSetup(tid);
246 _nodal_array_aux_storage.residualSetup(tid);
247 _elemental_aux_storage.residualSetup(tid);
248 _elemental_vec_aux_storage.residualSetup(tid);
249 _elemental_array_aux_storage.residualSetup(tid);
250 }
251
252#ifdef MOOSE_KOKKOS_ENABLED
255#endif
256}
257
258void
260{
262 _nodal_aux_storage.updateActive(tid);
263 _mortar_nodal_aux_storage.updateActive(tid);
264 _nodal_vec_aux_storage.updateActive(tid);
265 _nodal_array_aux_storage.updateActive(tid);
266 _elemental_aux_storage.updateActive(tid);
267 _elemental_vec_aux_storage.updateActive(tid);
268 _elemental_array_aux_storage.updateActive(tid);
269
270#ifdef MOOSE_KOKKOS_ENABLED
271 if (tid == 0)
272 {
275
277 }
278#endif
279}
280
281void
282AuxiliarySystem::addVariable(const std::string & var_type,
283 const std::string & name,
284 InputParameters & parameters)
285{
286 SystemBase::addVariable(var_type, name, parameters);
287
288 const auto fe_type = MooseUtils::variableFEType(parameters);
289
290 if (var_type == "MooseVariableScalar")
291 return;
292
293 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
294 {
295 if (FEInterface::field_type(fe_type) == libMesh::TYPE_VECTOR)
296 {
297 auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
298 if (var)
299 {
300 if (var->feType().family == LAGRANGE_VEC)
301 _nodal_vars[tid].push_back(var);
302 else
303 _elem_vars[tid].push_back(var);
304 }
305 }
306
307 else
308 {
309 MooseVariableBase * var_base = _vars[tid].getVariable(name);
310
311 auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
312
313 if (var)
314 {
315 if (var->feType().family == LAGRANGE)
316 _nodal_vars[tid].push_back(var);
317 else
318 _elem_vars[tid].push_back(var);
319 }
320
321 auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
322
323 if (avar)
324 {
325 if (avar->feType().family == LAGRANGE)
326 _nodal_vars[tid].push_back(avar);
327 else
328 _elem_vars[tid].push_back(avar);
329 }
330 }
331 }
332}
333
334void
335AuxiliarySystem::addKernel(const std::string & kernel_name,
336 const std::string & name,
337 InputParameters & parameters)
338{
339 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
340 {
341 const auto & base = parameters.getBase();
342 if (base == "AuxKernel" || base == "Bounds")
343 {
344 std::shared_ptr<AuxKernel> kernel =
345 _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
346 if (kernel->isNodal())
347 {
348 if (kernel->isMortar())
349 _mortar_nodal_aux_storage.addObject(kernel, tid);
350 else
351 _nodal_aux_storage.addObject(kernel, tid);
352 }
353 else
354 _elemental_aux_storage.addObject(kernel, tid);
355 }
356
357 else if (base == "VectorAuxKernel")
358 {
359 std::shared_ptr<VectorAuxKernel> kernel =
360 _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
361 if (kernel->isNodal())
362 {
363 if (kernel->isMortar())
364 mooseError("Vector mortar aux kernels not yet implemented");
365 _nodal_vec_aux_storage.addObject(kernel, tid);
366 }
367 else
368 _elemental_vec_aux_storage.addObject(kernel, tid);
369 }
370
371 else if (base == "ArrayAuxKernel")
372 {
373 std::shared_ptr<ArrayAuxKernel> kernel =
374 _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
375 if (kernel->isNodal())
376 {
377 if (kernel->isMortar())
378 mooseError("Vector mortar aux kernels not yet implemented");
379 _nodal_array_aux_storage.addObject(kernel, tid);
380 }
381 else
382 _elemental_array_aux_storage.addObject(kernel, tid);
383 }
384 else
385 mooseAssert(false,
386 "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
387 "' to the auxiliary system with invalid _moose_base: " + base);
388 }
389}
390
391void
392AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
393 const std::string & name,
394 InputParameters & parameters)
395{
396 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
397 {
398 std::shared_ptr<AuxScalarKernel> kernel =
399 _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
400 _aux_scalar_storage.addObject(kernel, tid);
401 }
402}
403
404void
405AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
406{
407 for (auto * var : _nodal_vars[tid])
408 var->computeElemValues();
409
410 for (auto * var : _elem_vars[tid])
411 {
412 var->reinitAux();
413 var->computeElemValues();
414 }
415}
416
417void
418AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
419{
420 for (auto * var : _nodal_vars[tid])
421 var->computeElemValuesFace();
422
423 for (auto * var : _elem_vars[tid])
424 {
425 var->reinitAux();
426 var->reinitAuxNeighbor();
427 var->computeElemValuesFace();
428 }
429}
430
431void
433{
434 if (_serialized_solution.get() &&
435 _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
436 {
437 if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
438 {
439 _serialized_solution->clear();
440 _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
441 }
442
444 }
445}
446
447void
449{
450 // avoid division by dt which might be zero.
451 if (_fe_problem.dt() > 0.)
452 for (auto & ti : _time_integrators)
453 ti->preStep();
454
455 // We need to compute time derivatives every time each kind of the variables is finished, because:
456 //
457 // a) the user might want to use the aux variable value somewhere, thus we need to provide the
458 // up-to-date value
459 // b) time integration system works with the whole vectors of solutions, thus we cannot update
460 // only a part of the vector
461 //
462
463 if (_vars[0].scalars().size() > 0)
464 {
465 computeScalarVars(type);
466 // compute time derivatives of scalar aux variables _after_ the values were updated
467 if (_fe_problem.dt() > 0.)
468 for (auto & ti : _time_integrators)
469 ti->computeTimeDerivatives();
470 }
471
472 if (_vars[0].fieldVariables().size() > 0)
473 {
476 computeNodalVars(type);
481
482#ifdef MOOSE_KOKKOS_ENABLED
483 kokkosCompute(type);
484#endif
485
487 {
488 solution().close();
489 _sys.update();
491 }
492
493 // compute time derivatives of nodal aux variables _after_ the values were updated
494 if (_fe_problem.dt() > 0.)
495 for (auto & ti : _time_integrators)
496 ti->computeTimeDerivatives();
497 }
498
499 if (_serialized_solution.get())
501}
502
503std::set<std::string>
505{
506 std::set<std::string> depend_objects;
507
508 // Elemental AuxKernels
509 {
510 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
511 _elemental_aux_storage[type].getActiveObjects();
512 for (const auto & aux : auxs)
513 {
514 const std::set<UserObjectName> & uo = aux->getDependObjects();
515 depend_objects.insert(uo.begin(), uo.end());
516 }
517 }
518
519 // Elemental VectorAuxKernels
520 {
521 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
522 _elemental_vec_aux_storage[type].getActiveObjects();
523 for (const auto & aux : auxs)
524 {
525 const std::set<UserObjectName> & uo = aux->getDependObjects();
526 depend_objects.insert(uo.begin(), uo.end());
527 }
528 }
529
530 // Elemental ArrayAuxKernels
531 {
532 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
533 _elemental_array_aux_storage[type].getActiveObjects();
534 for (const auto & aux : auxs)
535 {
536 const std::set<UserObjectName> & uo = aux->getDependObjects();
537 depend_objects.insert(uo.begin(), uo.end());
538 }
539 }
540
541 // Nodal AuxKernels
542 {
543 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
544 _nodal_aux_storage[type].getActiveObjects();
545 for (const auto & aux : auxs)
546 {
547 const std::set<UserObjectName> & uo = aux->getDependObjects();
548 depend_objects.insert(uo.begin(), uo.end());
549 }
550 }
551
552 // Mortar Nodal AuxKernels
553 {
554 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
555 _mortar_nodal_aux_storage[type].getActiveObjects();
556 for (const auto & aux : auxs)
557 {
558 const std::set<UserObjectName> & uo = aux->getDependObjects();
559 depend_objects.insert(uo.begin(), uo.end());
560 }
561 }
562
563 // Nodal VectorAuxKernels
564 {
565 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
566 _nodal_vec_aux_storage[type].getActiveObjects();
567 for (const auto & aux : auxs)
568 {
569 const std::set<UserObjectName> & uo = aux->getDependObjects();
570 depend_objects.insert(uo.begin(), uo.end());
571 }
572 }
573
574 // Nodal ArrayAuxKernels
575 {
576 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
577 _nodal_array_aux_storage[type].getActiveObjects();
578 for (const auto & aux : auxs)
579 {
580 const std::set<UserObjectName> & uo = aux->getDependObjects();
581 depend_objects.insert(uo.begin(), uo.end());
582 }
583 }
584
585#ifdef MOOSE_KOKKOS_ENABLED
586 // Kokkos NodalAuxKernels
587 {
588 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
590 for (const auto & aux : auxs)
591 {
592 const std::set<UserObjectName> & uo = aux->getDependObjects();
593 depend_objects.insert(uo.begin(), uo.end());
594 }
595 }
596
597 // Kokkos ElementalAuxKernels
598 {
599 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
601 for (const auto & aux : auxs)
602 {
603 const std::set<UserObjectName> & uo = aux->getDependObjects();
604 depend_objects.insert(uo.begin(), uo.end());
605 }
606 }
607#endif
608
609 return depend_objects;
610}
611
612std::set<std::string>
614{
615 std::set<std::string> depend_objects;
616
617 // Elemental AuxKernels
618 {
619 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
620 _elemental_aux_storage.getActiveObjects();
621 for (const auto & aux : auxs)
622 {
623 const std::set<UserObjectName> & uo = aux->getDependObjects();
624 depend_objects.insert(uo.begin(), uo.end());
625 }
626 }
627
628 // Elemental VectorAuxKernels
629 {
630 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
631 _elemental_vec_aux_storage.getActiveObjects();
632 for (const auto & aux : auxs)
633 {
634 const std::set<UserObjectName> & uo = aux->getDependObjects();
635 depend_objects.insert(uo.begin(), uo.end());
636 }
637 }
638
639 // Elemental ArrayAuxKernels
640 {
641 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
642 _elemental_array_aux_storage.getActiveObjects();
643 for (const auto & aux : auxs)
644 {
645 const std::set<UserObjectName> & uo = aux->getDependObjects();
646 depend_objects.insert(uo.begin(), uo.end());
647 }
648 }
649
650 // Nodal AuxKernels
651 {
652 const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
653 for (const auto & aux : auxs)
654 {
655 const std::set<UserObjectName> & uo = aux->getDependObjects();
656 depend_objects.insert(uo.begin(), uo.end());
657 }
658 }
659
660 // Mortar Nodal AuxKernels
661 {
662 const std::vector<std::shared_ptr<AuxKernel>> & auxs =
663 _mortar_nodal_aux_storage.getActiveObjects();
664 for (const auto & aux : auxs)
665 {
666 const std::set<UserObjectName> & uo = aux->getDependObjects();
667 depend_objects.insert(uo.begin(), uo.end());
668 }
669 }
670
671 // Nodal VectorAuxKernels
672 {
673 const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
674 _nodal_vec_aux_storage.getActiveObjects();
675 for (const auto & aux : auxs)
676 {
677 const std::set<UserObjectName> & uo = aux->getDependObjects();
678 depend_objects.insert(uo.begin(), uo.end());
679 }
680 }
681
682 // Nodal ArrayAuxKernels
683 {
684 const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
685 _nodal_array_aux_storage.getActiveObjects();
686 for (const auto & aux : auxs)
687 {
688 const std::set<UserObjectName> & uo = aux->getDependObjects();
689 depend_objects.insert(uo.begin(), uo.end());
690 }
691 }
692
693#ifdef MOOSE_KOKKOS_ENABLED
694 // Nodal KokkosAuxKernels
695 {
696 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
698 for (const auto & aux : auxs)
699 {
700 const std::set<UserObjectName> & uo = aux->getDependObjects();
701 depend_objects.insert(uo.begin(), uo.end());
702 }
703 }
704
705 // Elemental KokkosAuxKernels
706 {
707 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
709 for (const auto & aux : auxs)
710 {
711 const std::set<UserObjectName> & uo = aux->getDependObjects();
712 depend_objects.insert(uo.begin(), uo.end());
713 }
714 }
715#endif
716
717 return depend_objects;
718}
719
720void
722{
724 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
725
726 std::set<TagID> needed_sc_var_matrix_tags;
727 std::set<TagID> needed_sc_var_vector_tags;
728 for (const auto & obj : objects)
729 {
730 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
731 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
732
733 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
734 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
735 }
736
737 _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
738 _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
739}
740
741void
747
748void
750{
752
753 // Reference to the current storage container
755
756 if (storage.hasActiveObjects())
757 {
758 TIME_SECTION("computeScalarVars", 1);
759
760 PARALLEL_TRY
761 {
762 // FIXME: run multi-threaded
763 THREAD_ID tid = 0;
764 if (storage.hasActiveObjects())
765 {
767
768 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
769 storage.getActiveObjects(tid);
770
771 // Call compute() method on all active AuxScalarKernel objects
772 for (const auto & obj : objects)
773 obj->compute();
774
775 const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
776 for (const auto & var : scalar_vars)
777 var->insert(solution());
778 }
779 }
780 PARALLEL_CATCH;
781
782 solution().close();
783 _sys.update();
784 }
785
787}
788
789void
791{
792 TIME_SECTION("computeNodalVars", 3);
793
795 computeNodalVarsHelper<AuxKernel>(nodal);
796}
797
798void
800{
801 TIME_SECTION("computeNodalVecVars", 3);
802
804 computeNodalVarsHelper<VectorAuxKernel>(nodal);
805}
806
807void
809{
811 computeNodalVarsHelper<ArrayAuxKernel>(nodal);
812}
813
814void
816{
817 TIME_SECTION("computeMortarNodalVars", 3);
818
819 const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
820
821 mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
822 "We don't allow creation of block restricted mortar nodal aux kernels.");
823
824 if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
825 {
827 for (const auto & [bnd_id, mortar_nodal_auxes] :
828 mortar_nodal_warehouse.getActiveBoundaryObjects())
829 for (const auto index : index_range(mortar_nodal_auxes))
830 {
831 PARALLEL_TRY
832 {
833 try
834 {
836 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
837 Threads::parallel_reduce(bnd_nodes, mnabt, this->numThreads());
838 }
839 catch (MooseException & e)
840 {
841 _fe_problem.setException("The following MooseException was raised during mortar nodal "
842 "Auxiliary variable computation:\n" +
843 std::string(e.what()));
844 }
845 catch (MetaPhysicL::LogicError & e)
846 {
848 }
849 catch (std::exception & e)
850 {
851 // Continue if we find a libMesh degenerate map exception, but
852 // just re-throw for any real error
853 if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
854 !strstr(e.what(), "det != 0"))
855 throw;
856
857 _fe_problem.setException("We caught a libMesh degeneracy exception during mortar "
858 "nodal Auxiliary variable computation:\n" +
859 std::string(e.what()));
860 }
861 }
862 PARALLEL_CATCH;
863
864 // We need to make sure we propagate exceptions to all processes before trying to close
865 // here, which is a parallel operation
866 solution().close();
867 _sys.update();
868 }
869 }
870}
871
872void
874{
875 TIME_SECTION("computeElementalVars", 3);
876
878 computeElementalVarsHelper<AuxKernel>(elemental);
879}
880
881void
883{
884 TIME_SECTION("computeElementalVecVars", 3);
885
887 computeElementalVarsHelper<VectorAuxKernel>(elemental);
888}
889
890void
892{
894 computeElementalVarsHelper<ArrayAuxKernel>(elemental);
895}
896
897void
899 std::vector<dof_id_type> & /*n_nz*/,
900 std::vector<dof_id_type> &
901 /*n_oz*/)
902{
903}
904
905Order
907{
908 Order order = CONSTANT;
909 std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
910 for (const auto & var : vars)
911 {
912 if (!var->isNodal()) // nodal aux variables do not need quadrature
913 {
914 FEType fe_type = var->feType();
915 if (fe_type.default_quadrature_order() > order)
916 order = fe_type.default_quadrature_order();
917 }
918 }
919
920 return order;
921}
922
923bool
925{
926 return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
927 _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
928}
929
930void
936
937template <typename AuxKernelType>
938void
940{
941 if (warehouse.hasActiveBlockObjects())
942 {
943 // Block Elemental AuxKernels
944 PARALLEL_TRY
945 {
946 const ConstElemRange & range = *_mesh.getActiveLocalElementRange();
948 try
949 {
950 Threads::parallel_reduce(range, eavt, this->numThreads());
951 }
952 catch (MooseException & e)
953 {
954 _fe_problem.setException("The following MooseException was raised during elemental "
955 "Auxiliary variable computation:\n" +
956 std::string(e.what()));
957 }
958 }
959 PARALLEL_CATCH;
960
961 // We need to make sure we propagate exceptions to all processes before trying to close
962 // here, which is a parallel operation
963 solution().close();
964 _sys.update();
965 }
966
967 // Boundary Elemental AuxKernels
968 if (warehouse.hasActiveBoundaryObjects())
969 {
970 TIME_SECTION("computeElementalVecVars", 3);
971
972 PARALLEL_TRY
973 {
976 try
977 {
978 Threads::parallel_reduce(bnd_elems, eabt, this->numThreads());
979 }
980 catch (MooseException & e)
981 {
982 _fe_problem.setException("The following MooseException was raised during boundary "
983 "elemental Auxiliary variable computation:\n" +
984 std::string(e.what()));
985 }
986 }
987 PARALLEL_CATCH;
988
989 // We need to make sure we propagate exceptions to all processes before trying to close
990 // here, which is a parallel operation
991 solution().close();
992 _sys.update();
993 }
994}
995
996template <typename AuxKernelType>
997void
999{
1000 if (warehouse.hasActiveBlockObjects())
1001 {
1002 // Block Nodal AuxKernels
1003 PARALLEL_TRY
1004 {
1005 ConstNodeRange & range = *_mesh.getLocalNodeRange();
1007 Threads::parallel_reduce(range, navt, this->numThreads());
1008
1009 solution().close();
1010 _sys.update();
1011 }
1012 PARALLEL_CATCH;
1013 }
1014
1015 if (warehouse.hasActiveBoundaryObjects())
1016 {
1017 TIME_SECTION("computeBoundaryObjects", 3);
1018
1019 // Boundary Nodal AuxKernels
1020 PARALLEL_TRY
1021 {
1024 Threads::parallel_reduce(bnd_nodes, nabt, this->numThreads());
1025
1026 solution().close();
1027 _sys.update();
1028 }
1029 PARALLEL_CATCH;
1030 }
1031}
1032
1033void
1035 std::vector<Number> & rel_diff_norms) const
1036{
1037 rel_diff_norms.resize(nVariables(), 0);
1038 // Get dof map from system
1039 const auto & dof_map = _sys.get_dof_map();
1040
1041 for (const auto n : make_range(nVariables()))
1042 {
1043 // Get local indices from dof map for each variable
1044 std::vector<dof_id_type> local_indices_n;
1045 dof_map.local_variable_indices(local_indices_n, _mesh, n);
1046 Number diff_norm_n = 0;
1047 Number norm_n = 0;
1048 // Get values from system, update norm
1049 for (const auto local_index : local_indices_n)
1050 {
1051 const Number & value = solution()(local_index);
1052 const Number & value_old = solutionOld()(local_index);
1053 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1054 norm_n += Utility::pow<2, Number>(value);
1055 }
1056 // Aggregate norm over proceccors
1057 _communicator.sum(diff_norm_n);
1058 _communicator.sum(norm_n);
1059 diff_norm_n = sqrt(diff_norm_n);
1060 norm_n = sqrt(norm_n);
1061 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1062 }
1063}
1064
1065template void
1066AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1067template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1069template void
1070AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1071template 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)
void buildKokkosAuxStages()
Group the active Kokkos auxiliary kernels of each execution flag into stages that can each be compute...
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:891
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:720
virtual void customSetup(const ExecFlagType &exec_type)
NumericVector< Number > & solutionOld()
Definition SystemBase.h:216
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)
THREAD_ID numThreads() const
Definition SystemBase.C:89
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual const std::string & name() const
NumericVector< Number > & solution()
Definition SystemBase.h:215
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition SystemBase.h:789
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:775
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)
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition MooseError.C:153