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#ifdef MOOSE_KOKKOS_ENABLED
48 ,
49 _kokkos_nodal_aux_storage(_app.getExecuteOnEnum(), 1),
50 _kokkos_elemental_aux_storage(_app.getExecuteOnEnum(), 1)
51#endif
52{
53 _nodal_vars.resize(this->numThreads());
54 _elem_vars.resize(this->numThreads());
55
56 if (!_fe_problem.defaultGhosting())
57 {
58 auto & dof_map = _sys.get_dof_map();
59 dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
60 dof_map.set_implicit_neighbor_dofs(false);
61 }
62}
63
65
66void
72
73void
75{
76 TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
77
81
82 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
83 {
86
87 // Called on every kernel, enabled or not, since a disabled kernel may be enabled later
88 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/false))
89 aux->initialSetup();
90 }
91
92#ifdef MOOSE_KOKKOS_ENABLED
95
98
100#endif
101}
102
103std::vector<AuxKernelBase *>
104AuxiliarySystem::sortedAuxKernels(const THREAD_ID tid, const bool active_only)
105{
106 std::vector<AuxKernelBase *> sorted;
107 std::set<AuxKernelBase *> seen;
108 for (const auto & flag : _app.getExecuteOnEnum().items())
109 {
110 // EXEC_ALL matches every kernel, which would sort across flags again
111 if (flag == AttribExecOns::EXEC_ALL)
112 continue;
113
114 // Sort with an explicit AttribSorted rather than queryInto so that disabled kernels can be
115 // kept: initialSetup must reach every kernel, since a disabled one may be enabled later
116 auto attribs = _fe_problem.theWarehouse()
117 .query()
118 .condition<AttribSystem>("AuxKernel")
119 .condition<AttribThread>(tid)
120 .condition<AttribExecOns>(flag)
121 .condition<AttribSorted>(true)
122 .attributes();
123 std::vector<AuxKernelBase *> flag_kernels;
125 _fe_problem.theWarehouse().queryID(attribs), flag_kernels, /*show_all=*/!active_only);
126 for (auto * const aux : flag_kernels)
127 if (seen.insert(aux).second)
128 sorted.push_back(aux);
129 }
130
131 // A kernel with an empty execute_on has no flag to be sorted under, but still needs its setup
132 const auto all_attribs = _fe_problem.theWarehouse()
133 .query()
134 .condition<AttribSystem>("AuxKernel")
135 .condition<AttribThread>(tid)
136 .attributes();
137 std::vector<AuxKernelBase *> all_kernels;
139 _fe_problem.theWarehouse().queryID(all_attribs), all_kernels, /*show_all=*/!active_only);
140 for (auto * const aux : all_kernels)
141 if (seen.insert(aux).second)
142 sorted.push_back(aux);
143 return sorted;
144}
145
146void
152
153void
155 const bool skip_current_to_old)
156{
157 if (iteration_type == Moose::SolutionIterationType::Time)
158 LinearFVGradientManager::copyPreviousGradientStates(iteration_type, skip_current_to_old);
159}
160
161void
166
167void
169{
171
172 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
173 {
175 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/true))
176 aux->timestepSetup();
177 }
178
179#ifdef MOOSE_KOKKOS_ENABLED
182#endif
183}
184
185void
187{
188 SystemBase::customSetup(exec_type);
189
190 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
191 {
192 _aux_scalar_storage.customSetup(exec_type, tid);
193 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/true))
194 aux->customSetup(exec_type);
195 }
196
197#ifdef MOOSE_KOKKOS_ENABLED
198 _kokkos_nodal_aux_storage.customSetup(exec_type, /*tid=*/0);
199 _kokkos_elemental_aux_storage.customSetup(exec_type, /*tid=*/0);
200#endif
201}
202
203void
205{
207
208 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
209 {
211 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/true))
212 aux->subdomainSetup();
213 }
214}
215
216void
218{
220
221 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
222 {
224 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/true))
225 aux->jacobianSetup();
226 }
227
228#ifdef MOOSE_KOKKOS_ENABLED
231#endif
232}
233
234void
236{
238
239 for (unsigned int tid = 0; tid < this->numThreads(); tid++)
240 {
242 for (auto * const aux : sortedAuxKernels(tid, /*active_only=*/true))
243 aux->residualSetup();
244 }
245
246#ifdef MOOSE_KOKKOS_ENABLED
249#endif
250}
251
252void
254{
256 // AuxKernels (nodal, mortar, and elemental) are queried from theWarehouse(), which filters out
257 // disabled objects on every query, so there is no cached active list to refresh here.
258
259#ifdef MOOSE_KOKKOS_ENABLED
260 if (tid == 0)
261 {
264
266 }
267#endif
268}
269
270void
271AuxiliarySystem::addVariable(const std::string & var_type,
272 const std::string & name,
273 InputParameters & parameters)
274{
275 SystemBase::addVariable(var_type, name, parameters);
276
277 const auto fe_type = MooseUtils::variableFEType(parameters);
278
279 if (var_type == "MooseVariableScalar")
280 return;
281
282 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
283 {
284 if (FEInterface::field_type(fe_type) == libMesh::TYPE_VECTOR)
285 {
286 auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
287 if (var)
288 {
289 if (var->feType().family == LAGRANGE_VEC)
290 _nodal_vars[tid].push_back(var);
291 else
292 _elem_vars[tid].push_back(var);
293 }
294 }
295
296 else
297 {
298 MooseVariableBase * var_base = _vars[tid].getVariable(name);
299
300 auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
301
302 if (var)
303 {
304 if (var->feType().family == LAGRANGE)
305 _nodal_vars[tid].push_back(var);
306 else
307 _elem_vars[tid].push_back(var);
308 }
309
310 auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
311
312 if (avar)
313 {
314 if (avar->feType().family == LAGRANGE)
315 _nodal_vars[tid].push_back(avar);
316 else
317 _elem_vars[tid].push_back(avar);
318 }
319 }
320 }
321}
322
323void
324AuxiliarySystem::addKernel(const std::string & kernel_name,
325 const std::string & name,
326 InputParameters & parameters)
327{
328 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
329 {
330 const auto & base = parameters.getBase();
331 if (base == "AuxKernel" || base == "Bounds")
332 {
333 std::shared_ptr<AuxKernel> kernel =
334 _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
335 _fe_problem.theWarehouse().add(kernel);
336 }
337
338 else if (base == "VectorAuxKernel")
339 {
340 std::shared_ptr<VectorAuxKernel> kernel =
341 _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
342 if (kernel->isNodal() && kernel->isMortar())
343 mooseError("Vector mortar aux kernels not yet implemented");
344 _fe_problem.theWarehouse().add(kernel);
345 }
346
347 else if (base == "ArrayAuxKernel")
348 {
349 std::shared_ptr<ArrayAuxKernel> kernel =
350 _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
351 if (kernel->isNodal() && kernel->isMortar())
352 mooseError("Vector mortar aux kernels not yet implemented");
353 _fe_problem.theWarehouse().add(kernel);
354 }
355 else
356 mooseAssert(false,
357 "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
358 "' to the auxiliary system with invalid _moose_base: " + base);
359 }
360 if (parameters.isParamValid("execution_order_group"))
361 _execution_order_groups.insert(parameters.get<int>("execution_order_group"));
362}
363
364void
365AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
366 const std::string & name,
367 InputParameters & parameters)
368{
369 for (THREAD_ID tid = 0; tid < this->numThreads(); tid++)
370 {
371 std::shared_ptr<AuxScalarKernel> kernel =
372 _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
373 _aux_scalar_storage.addObject(kernel, tid);
374 }
375}
376
377void
378AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
379{
380 for (auto * var : _nodal_vars[tid])
381 var->computeElemValues();
382
383 for (auto * var : _elem_vars[tid])
384 {
385 var->reinitAux();
386 var->computeElemValues();
387 }
388}
389
390void
391AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
392{
393 for (auto * var : _nodal_vars[tid])
394 var->computeElemValuesFace();
395
396 for (auto * var : _elem_vars[tid])
397 {
398 var->reinitAux();
399 var->reinitAuxNeighbor();
400 var->computeElemValuesFace();
401 }
402}
403
404void
406{
407 if (_serialized_solution.get() &&
408 _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
409 {
410 if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
411 {
412 _serialized_solution->clear();
413 _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
414 }
415
417 }
418}
419
420void
422{
423 // avoid division by dt which might be zero.
424 if (_fe_problem.dt() > 0.)
425 for (auto & ti : _time_integrators)
426 ti->preStep();
427
428 // We need to compute time derivatives every time each kind of the variables is finished, because:
429 //
430 // a) the user might want to use the aux variable value somewhere, thus we need to provide the
431 // up-to-date value
432 // b) time integration system works with the whole vectors of solutions, thus we cannot update
433 // only a part of the vector
434 //
435
436 if (_vars[0].scalars().size() > 0)
437 {
438 computeScalarVars(type);
439 // compute time derivatives of scalar aux variables _after_ the values were updated
440 if (_fe_problem.dt() > 0.)
441 for (auto & ti : _time_integrators)
442 ti->computeTimeDerivatives();
443 }
444
445 if (_vars[0].fieldVariables().size() > 0)
446 {
447 for (const auto group : _execution_order_groups)
448 {
449 computeNodalVars(type, group);
450 computeNodalVecVars(type, group);
451 computeNodalArrayVars(type, group);
452 computeMortarNodalVars(type, group);
453 computeElementalVars(type, group);
454 computeElementalVecVars(type, group);
455 computeElementalArrayVars(type, group);
456
457#ifdef MOOSE_KOKKOS_ENABLED
458 kokkosCompute(type, group);
459#endif
460 }
461
463 {
464 solution().close();
465 _sys.update();
467 }
468
469 // compute time derivatives of nodal aux variables _after_ the values were updated
470 // NOTE: don't rely on time derivatives within auxkernels to be updated
471 if (_fe_problem.dt() > 0.)
472 for (auto & ti : _time_integrators)
473 ti->computeTimeDerivatives();
474 }
475
476 if (_serialized_solution.get())
478}
479
480std::set<std::string>
482{
483 std::set<std::string> depend_objects;
484
485 // AuxKernels (nodal, mortar, and elemental)
486 {
487 std::vector<AuxKernel *> auxkernels;
489 .query()
490 .condition<AttribSystem>("AuxKernel")
491 .condition<AttribAuxKernelType>(AuxKernelType::Real)
492 .condition<AttribExecOns>(type)
493 .condition<AttribThread>(0)
494 .queryIntoUnsorted(auxkernels);
495 for (const auto & aux : auxkernels)
496 {
497 const std::set<UserObjectName> & uo = aux->getDependObjects();
498 depend_objects.insert(uo.begin(), uo.end());
499 }
500 }
501
502 // VectorAuxKernels (nodal and elemental)
503 {
504 std::vector<VectorAuxKernel *> vec_auxkernels;
506 .query()
507 .condition<AttribSystem>("AuxKernel")
508 .condition<AttribAuxKernelType>(AuxKernelType::Vector)
509 .condition<AttribExecOns>(type)
510 .condition<AttribThread>(0)
511 .queryIntoUnsorted(vec_auxkernels);
512 for (const auto & aux : vec_auxkernels)
513 {
514 const std::set<UserObjectName> & uo = aux->getDependObjects();
515 depend_objects.insert(uo.begin(), uo.end());
516 }
517 }
518
519 // ArrayAuxKernels (nodal and elemental)
520 {
521 std::vector<ArrayAuxKernel *> array_auxkernels;
523 .query()
524 .condition<AttribSystem>("AuxKernel")
525 .condition<AttribAuxKernelType>(AuxKernelType::Array)
526 .condition<AttribExecOns>(type)
527 .condition<AttribThread>(0)
528 .queryIntoUnsorted(array_auxkernels);
529 for (const auto & aux : array_auxkernels)
530 {
531 const std::set<UserObjectName> & uo = aux->getDependObjects();
532 depend_objects.insert(uo.begin(), uo.end());
533 }
534 }
535
536#ifdef MOOSE_KOKKOS_ENABLED
537 // Kokkos NodalAuxKernels
538 {
539 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
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 // Kokkos ElementalAuxKernels
549 {
550 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
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#endif
559
560 return depend_objects;
561}
562
563std::set<std::string>
565{
566 std::set<std::string> depend_objects;
567
568 // AuxKernels (nodal, mortar, and elemental)
569 {
570 std::vector<AuxKernel *> auxkernels;
572 .query()
573 .condition<AttribSystem>("AuxKernel")
574 .condition<AttribAuxKernelType>(AuxKernelType::Real)
575 .condition<AttribThread>(0)
576 .queryIntoUnsorted(auxkernels);
577 for (const auto & aux : auxkernels)
578 {
579 const std::set<UserObjectName> & uo = aux->getDependObjects();
580 depend_objects.insert(uo.begin(), uo.end());
581 }
582 }
583
584 // VectorAuxKernels (nodal and elemental)
585 {
586 std::vector<VectorAuxKernel *> vec_auxkernels;
588 .query()
589 .condition<AttribSystem>("AuxKernel")
590 .condition<AttribAuxKernelType>(AuxKernelType::Vector)
591 .condition<AttribThread>(0)
592 .queryIntoUnsorted(vec_auxkernels);
593 for (const auto & aux : vec_auxkernels)
594 {
595 const std::set<UserObjectName> & uo = aux->getDependObjects();
596 depend_objects.insert(uo.begin(), uo.end());
597 }
598 }
599
600 // ArrayAuxKernels (nodal and elemental)
601 {
602 std::vector<ArrayAuxKernel *> array_auxkernels;
604 .query()
605 .condition<AttribSystem>("AuxKernel")
606 .condition<AttribAuxKernelType>(AuxKernelType::Array)
607 .condition<AttribThread>(0)
608 .queryIntoUnsorted(array_auxkernels);
609 for (const auto & aux : array_auxkernels)
610 {
611 const std::set<UserObjectName> & uo = aux->getDependObjects();
612 depend_objects.insert(uo.begin(), uo.end());
613 }
614 }
615
616#ifdef MOOSE_KOKKOS_ENABLED
617 // Nodal KokkosAuxKernels
618 {
619 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
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 KokkosAuxKernels
629 {
630 const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
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#endif
639
640 return depend_objects;
641}
642
643void
645{
647 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
648
649 std::set<TagID> needed_sc_var_matrix_tags;
650 std::set<TagID> needed_sc_var_vector_tags;
651 for (const auto & obj : objects)
652 {
653 auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
654 needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
655
656 auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
657 needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
658 }
659
660 _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
661 _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
662}
663
664void
670
671void
673{
675
676 // Reference to the current storage container
678
679 if (storage.hasActiveObjects())
680 {
681 TIME_SECTION("computeScalarVars", 1);
682
683 PARALLEL_TRY
684 {
685 // FIXME: run multi-threaded
686 THREAD_ID tid = 0;
687 if (storage.hasActiveObjects())
688 {
690
691 const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
692 storage.getActiveObjects(tid);
693
694 // Call compute() method on all active AuxScalarKernel objects
695 for (const auto & obj : objects)
696 obj->compute();
697
698 const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
699 for (const auto & var : scalar_vars)
700 var->insert(solution());
701 }
702 }
703 PARALLEL_CATCH;
704
705 solution().close();
706 _sys.update();
707 }
708
710}
711
712void
714{
715 TIME_SECTION("computeNodalVars", 3);
716
719 .query()
720 .condition<AttribSystem>("AuxKernel")
721 .condition<AttribAuxKernelType>(AuxKernelType::Real | AuxKernelType::Nodal)
722 .condition<AttribExecOns>(type)
723 .condition<AttribExecutionOrderGroup>(group);
724 computeNodalVarsHelper<AuxKernel>(query);
725}
726
727void
729{
730 TIME_SECTION("computeNodalVecVars", 3);
731
734 .query()
735 .condition<AttribSystem>("AuxKernel")
736 .condition<AttribAuxKernelType>(AuxKernelType::Vector | AuxKernelType::Nodal)
737 .condition<AttribExecOns>(type)
738 .condition<AttribExecutionOrderGroup>(group);
739 computeNodalVarsHelper<VectorAuxKernel>(query);
740}
741
742void
744{
745 TIME_SECTION("computeNodalArrayVars", 3);
746
749 .query()
750 .condition<AttribSystem>("AuxKernel")
751 .condition<AttribAuxKernelType>(AuxKernelType::Array | AuxKernelType::Nodal)
752 .condition<AttribExecOns>(type)
753 .condition<AttribExecutionOrderGroup>(group);
754 computeNodalVarsHelper<ArrayAuxKernel>(query);
755}
756
757void
759{
760 TIME_SECTION("computeMortarNodalVars", 3);
761
764 .query()
765 .condition<AttribSystem>("AuxKernel")
766 .condition<AttribAuxKernelType>(AuxKernelType::Real | AuxKernelType::Mortar)
767 .condition<AttribExecOns>(type)
768 .condition<AttribExecutionOrderGroup>(group);
769
770 // Use thread 0's dependency-sorted list to determine which boundaries have mortar nodal aux
771 // kernels and how many. The sort order does not depend on the thread, so
772 // ComputeMortarNodalAuxBndThread re-resolves the same (boundary, index) pair against its own
773 // thread's copy of the kernels.
774 std::vector<AuxKernel *> mortar_nodal_auxs;
775 query.clone().condition<AttribThread>(0).queryInto(mortar_nodal_auxs);
776
777 if (mortar_nodal_auxs.empty())
778 return;
779
780 std::map<BoundaryID, std::size_t> num_kernels_by_boundary;
781 for (auto * aux : mortar_nodal_auxs)
782 for (const auto bnd_id : aux->boundaryIDs())
783 ++num_kernels_by_boundary[bnd_id];
784
786 for (const auto & [bnd_id, num_kernels] : num_kernels_by_boundary)
787 for (const auto index : make_range(num_kernels))
788 {
789 PARALLEL_TRY
790 {
791 try
792 {
794 Threads::parallel_reduce(bnd_nodes, mnabt, this->numThreads());
795 }
796 catch (MooseException & e)
797 {
798 _fe_problem.setException("The following MooseException was raised during mortar nodal "
799 "Auxiliary variable computation:\n" +
800 std::string(e.what()));
801 }
802 catch (MetaPhysicL::LogicError & e)
803 {
805 }
806 catch (std::exception & e)
807 {
808 // Continue if we find a libMesh degenerate map exception, but
809 // just re-throw for any real error
810 if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
811 !strstr(e.what(), "det != 0"))
812 throw;
813
814 _fe_problem.setException("We caught a libMesh degeneracy exception during mortar "
815 "nodal Auxiliary variable computation:\n" +
816 std::string(e.what()));
817 }
818 }
819 PARALLEL_CATCH;
820
821 // We need to make sure we propagate exceptions to all processes before trying to close
822 // here, which is a parallel operation
823 solution().close();
824 _sys.update();
825 }
826}
827
828void
830{
831 TIME_SECTION("computeElementalVars", 3);
832
835 .query()
836 .condition<AttribSystem>("AuxKernel")
837 .condition<AttribAuxKernelType>(AuxKernelType::Real | AuxKernelType::Elemental)
838 .condition<AttribExecOns>(type)
839 .condition<AttribExecutionOrderGroup>(group);
840 computeElementalVarsHelper<AuxKernel>(query);
841}
842
843void
845{
846 TIME_SECTION("computeElementalVecVars", 3);
847
850 .query()
851 .condition<AttribSystem>("AuxKernel")
852 .condition<AttribAuxKernelType>(AuxKernelType::Vector | AuxKernelType::Elemental)
853 .condition<AttribExecOns>(type)
854 .condition<AttribExecutionOrderGroup>(group);
855 computeElementalVarsHelper<VectorAuxKernel>(query);
856}
857
858void
860{
863 .query()
864 .condition<AttribSystem>("AuxKernel")
865 .condition<AttribAuxKernelType>(AuxKernelType::Array | AuxKernelType::Elemental)
866 .condition<AttribExecOns>(type)
867 .condition<AttribExecutionOrderGroup>(group);
868 computeElementalVarsHelper<ArrayAuxKernel>(query);
869}
870
871void
873 std::vector<dof_id_type> & /*n_nz*/,
874 std::vector<dof_id_type> &
875 /*n_oz*/)
876{
877}
878
879Order
881{
882 Order order = CONSTANT;
883 std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
884 for (const auto & var : vars)
885 {
886 if (!var->isNodal()) // nodal aux variables do not need quadrature
887 {
888 FEType fe_type = var->feType();
889 if (fe_type.default_quadrature_order() > order)
890 order = fe_type.default_quadrature_order();
891 }
892 }
893
894 return order;
895}
896
897bool
899{
900 std::vector<AuxKernel *> elem_auxkernels;
902 .query()
903 .condition<AttribSystem>("AuxKernel")
904 .condition<AttribAuxKernelType>(AuxKernelType::Real | AuxKernelType::Elemental)
905 .condition<AttribThread>(0)
906 .condition<AttribBoundaries>(bnd_id, true)
907 .queryIntoUnsorted(elem_auxkernels);
908 if (!elem_auxkernels.empty())
909 return true;
910
911 std::vector<VectorAuxKernel *> elem_vec_auxkernels;
913 .query()
914 .condition<AttribSystem>("AuxKernel")
915 .condition<AttribAuxKernelType>(AuxKernelType::Vector | AuxKernelType::Elemental)
916 .condition<AttribThread>(0)
917 .condition<AttribBoundaries>(bnd_id, true)
918 .queryIntoUnsorted(elem_vec_auxkernels);
919 return !elem_vec_auxkernels.empty();
920}
921
922void
928
929template <typename AuxKernelType>
930void
932{
933 // Block Elemental AuxKernels. Boundary-restricted kernels are excluded here - even if they are
934 // not also block-restricted (and would otherwise match every block) - since they are handled
935 // entirely by the boundary-element loop below, matching the old warehouse's mutually exclusive
936 // block/boundary dispatch.
937 // The non-emptiness checks span every thread's copy of each kernel (no AttribThread condition),
938 // so they must stay unsorted: sorting would run dependency resolution across per-thread
939 // duplicates of the same kernel, which can falsely detect a cycle.
940 const TheWarehouse::Query block_query = query.clone().condition<AttribBoundaries>(
942 std::vector<AuxKernelType *> block_auxs;
943 block_query.clone().queryIntoUnsorted(block_auxs);
944
945 if (block_auxs.size())
946 {
947 PARALLEL_TRY
948 {
949 const ConstElemRange & range = *_mesh.getActiveLocalElementRange();
951 try
952 {
953 Threads::parallel_reduce(range, eavt, this->numThreads());
954 }
955 catch (MooseException & e)
956 {
957 _fe_problem.setException("The following MooseException was raised during elemental "
958 "Auxiliary variable computation:\n" +
959 std::string(e.what()));
960 }
961 }
962 PARALLEL_CATCH;
963
964 // We need to make sure we propagate exceptions to all processes before trying to close
965 // here, which is a parallel operation
966 solution().close();
967 _sys.update();
968 }
969
970 // Boundary Elemental AuxKernels
971 std::vector<AuxKernelType *> boundary_auxs;
972 query.clone()
975 .queryIntoUnsorted(boundary_auxs);
976
977 if (boundary_auxs.size())
978 {
979 TIME_SECTION("computeElementalVecVars", 3);
980
981 PARALLEL_TRY
982 {
985 try
986 {
987 Threads::parallel_reduce(bnd_elems, eabt, this->numThreads());
988 }
989 catch (MooseException & e)
990 {
991 _fe_problem.setException("The following MooseException was raised during boundary "
992 "elemental Auxiliary variable computation:\n" +
993 std::string(e.what()));
994 }
995 }
996 PARALLEL_CATCH;
997
998 // We need to make sure we propagate exceptions to all processes before trying to close
999 // here, which is a parallel operation
1000 solution().close();
1001 _sys.update();
1002 }
1003}
1004
1005template <typename AuxKernelType>
1006void
1008{
1009 // Block Nodal AuxKernels. Boundary-restricted kernels are excluded here - even if they are not
1010 // also block-restricted (and would otherwise match every block) - since they are handled entirely
1011 // by the boundary-node loop below, matching the old warehouse's mutually exclusive block/boundary
1012 // dispatch.
1013 // The non-emptiness checks span every thread's copy of each kernel (no AttribThread condition),
1014 // so they must stay unsorted: sorting would run dependency resolution across per-thread
1015 // duplicates of the same kernel, which can falsely detect a cycle.
1016 const TheWarehouse::Query block_query = query.clone().condition<AttribBoundaries>(
1018 std::vector<AuxKernelType *> block_auxs;
1019 block_query.clone().queryIntoUnsorted(block_auxs);
1020
1021 if (block_auxs.size())
1022 {
1023 PARALLEL_TRY
1024 {
1025 ConstNodeRange & range = *_mesh.getLocalNodeRange();
1027 Threads::parallel_reduce(range, navt, this->numThreads());
1028
1029 solution().close();
1030 _sys.update();
1031 }
1032 PARALLEL_CATCH;
1033 }
1034
1035 // Boundary Nodal AuxKernels
1036 std::vector<AuxKernelType *> boundary_auxs;
1037 query.clone()
1040 .queryIntoUnsorted(boundary_auxs);
1041
1042 if (boundary_auxs.size())
1043 {
1044 TIME_SECTION("computeBoundaryObjects", 3);
1045
1046 PARALLEL_TRY
1047 {
1050 Threads::parallel_reduce(bnd_nodes, nabt, this->numThreads());
1051
1052 solution().close();
1053 _sys.update();
1054 }
1055 PARALLEL_CATCH;
1056 }
1057}
1058
1059void
1061 std::vector<Number> & rel_diff_norms) const
1062{
1063 rel_diff_norms.resize(nVariables(), 0);
1064 // Get dof map from system
1065 const auto & dof_map = _sys.get_dof_map();
1066
1067 for (const auto n : make_range(nVariables()))
1068 {
1069 // Get local indices from dof map for each variable
1070 std::vector<dof_id_type> local_indices_n;
1071 dof_map.local_variable_indices(local_indices_n, _mesh, n);
1072 Number diff_norm_n = 0;
1073 Number norm_n = 0;
1074 // Get values from system, update norm
1075 for (const auto local_index : local_indices_n)
1076 {
1077 const Number & value = solution()(local_index);
1078 const Number & value_old = solutionOld()(local_index);
1079 diff_norm_n += Utility::pow<2, Number>(value - value_old);
1080 norm_n += Utility::pow<2, Number>(value);
1081 }
1082 // Aggregate norm over proceccors
1083 _communicator.sum(diff_norm_n);
1084 _communicator.sum(norm_n);
1085 diff_norm_n = sqrt(diff_norm_n);
1086 norm_n = sqrt(norm_n);
1087 rel_diff_norms[n] = diff_norm_n > 0 ? diff_norm_n / norm_n : 0.0;
1088 }
1089}
1090
1091template void AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const TheWarehouse::Query &);
1092template void
1093AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(const TheWarehouse::Query &);
1094template void AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const TheWarehouse::Query &);
1095template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(const TheWarehouse::Query &);
@ Nodal
Execution categories.
@ Real
Value types.
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
AttribBoundaries tracks all boundary IDs associated with an object.
Definition Attributes.h:223
@ UnrestrictedOnly
Only objects that are not boundary restricted, whatever the query boundaries.
@ RestrictedOnly
Only objects restricted to one of the query boundaries.
static const ExecFlagType EXEC_ALL
Execute flag that is used to represent all flags when querying AttribExecOns.
Definition Attributes.h:169
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
void computeElementalVars(ExecFlagType type, int group)
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.
void clearScalarVariableCoupleableTags()
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
virtual void copyAdditionalStateBackwards(Moose::SolutionIterationType iteration_type, bool skip_current_to_old) override
Copy system-owned state not represented by solution vectors.
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.
std::vector< AuxKernelBase * > sortedAuxKernels(THREAD_ID tid, bool active_only)
Get every AuxKernel, of any value type, on a thread, in dependency order.
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
void computeNodalVecVars(ExecFlagType type, int group)
void computeElementalVecVars(ExecFlagType type, int group)
void computeMortarNodalVars(ExecFlagType type, int group)
void buildKokkosAuxStages()
Group the active Kokkos auxiliary kernels of each execution flag into stages that can each be compute...
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.
virtual ~AuxiliarySystem()
std::set< int > _execution_order_groups
Execution order groups present within the simulation.
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.
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.
void computeNodalVarsHelper(const TheWarehouse::Query &query)
std::vector< std::vector< MooseVariableFEBase * > > _nodal_vars
virtual void serializeSolution()
void computeNodalVars(ExecFlagType type, int group)
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 computeElementalArrayVars(ExecFlagType type, int group)
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 kokkosCompute(ExecFlagType type, int group)
void computeElementalVarsHelper(const TheWarehouse::Query &query)
void computeNodalArrayVars(ExecFlagType type, int group)
This class evaluates a single mortar nodal aux kernel.
const std::set< ExecFlagType > & items() const
Reference the all the available items.
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
TheWarehouse & theWarehouse() const
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.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const std::string & getBase() const
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another,...
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.
const ExecFlagEnum & getExecuteOnEnum() const
Return the app level ExecFlagEnum, this contains all the available flags for the app.
Definition MooseApp.h:1049
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:1286
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition MooseMesh.C:1300
const libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
Definition MooseMesh.C:1257
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
Definition MooseMesh.C:1313
bool hasActiveObjects(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.
MooseApp & _app
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
QueryCache is a convenient way to construct and pass around (possible partially constructed) warehous...
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
std::vector< T * > & queryIntoUnsorted(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
void add(std::shared_ptr< MooseObject > obj)
add adds a new object to the warehouse and stores attributes/metadata about it for running queries/fi...
std::vector< T * > & queryInto(const std::vector< std::unique_ptr< Attribute > > &conds, std::vector< T * > &results)
queryInto takes the given conditions (i.e.
std::size_t queryID(const std::vector< std::unique_ptr< Attribute > > &conds)
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
query_obj query
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:776
const BoundaryID ANY_BOUNDARY_ID
Definition MooseTypes.C:21
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