https://mooseframework.inl.gov
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 
27 #include "libmesh/quadrature_gauss.h"
28 #include "libmesh/node_range.h"
29 #include "libmesh/numeric_vector.h"
30 #include "libmesh/default_coupling.h"
31 #include "libmesh/string_to_enum.h"
32 #include "libmesh/fe_interface.h"
33 
34 using namespace libMesh;
35 
36 // AuxiliarySystem ////////
37 
38 AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
39  : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
40  PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
41  _sys(subproblem.es().add_system<System>(name)),
42  _current_solution(_sys.current_local_solution.get()),
43  _aux_scalar_storage(_app.getExecuteOnEnum()),
44  _nodal_aux_storage(_app.getExecuteOnEnum()),
45  _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
46  _elemental_aux_storage(_app.getExecuteOnEnum()),
47  _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
48  _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
49  _nodal_array_aux_storage(_app.getExecuteOnEnum()),
50  _elemental_array_aux_storage(_app.getExecuteOnEnum())
51 #ifdef MOOSE_KOKKOS_ENABLED
52  ,
53  _kokkos_nodal_aux_storage(_app.getExecuteOnEnum()),
54  _kokkos_elemental_aux_storage(_app.getExecuteOnEnum())
55 #endif
56 {
57  _nodal_vars.resize(libMesh::n_threads());
58  _elem_vars.resize(libMesh::n_threads());
59 
61  {
62  auto & dof_map = _sys.get_dof_map();
63  dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
64  dof_map.set_implicit_neighbor_dofs(false);
65  }
66 }
67 
69 
70 void
72 {
73  TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
74 
76 
77  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
78  {
81 
82  _nodal_aux_storage.sort(tid);
83  _nodal_aux_storage.initialSetup(tid);
84 
85  _mortar_nodal_aux_storage.sort(tid);
86  _mortar_nodal_aux_storage.initialSetup(tid);
87 
88  _nodal_vec_aux_storage.sort(tid);
89  _nodal_vec_aux_storage.initialSetup(tid);
90 
91  _nodal_array_aux_storage.sort(tid);
92  _nodal_array_aux_storage.initialSetup(tid);
93 
94  _elemental_aux_storage.sort(tid);
95  _elemental_aux_storage.initialSetup(tid);
96 
98  _elemental_vec_aux_storage.initialSetup(tid);
99 
101  _elemental_array_aux_storage.initialSetup(tid);
102  }
103 
104 #ifdef MOOSE_KOKKOS_ENABLED
105  _kokkos_nodal_aux_storage.sort(/*tid=*/0);
107 
110 #endif
111 }
112 
113 void
115 {
117 
118  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
119  {
121  _nodal_aux_storage.timestepSetup(tid);
122  _mortar_nodal_aux_storage.timestepSetup(tid);
123  _nodal_vec_aux_storage.timestepSetup(tid);
124  _nodal_array_aux_storage.timestepSetup(tid);
125  _elemental_aux_storage.timestepSetup(tid);
126  _elemental_vec_aux_storage.timestepSetup(tid);
127  _elemental_array_aux_storage.timestepSetup(tid);
128  }
129 
130 #ifdef MOOSE_KOKKOS_ENABLED
133 #endif
134 }
135 
136 void
138 {
139  SystemBase::customSetup(exec_type);
140 
141  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
142  {
143  _aux_scalar_storage.customSetup(exec_type, tid);
144  _nodal_aux_storage.customSetup(exec_type, tid);
145  _mortar_nodal_aux_storage.customSetup(exec_type, tid);
146  _nodal_vec_aux_storage.customSetup(exec_type, tid);
147  _nodal_array_aux_storage.customSetup(exec_type, tid);
148  _elemental_aux_storage.customSetup(exec_type, tid);
149  _elemental_vec_aux_storage.customSetup(exec_type, tid);
150  _elemental_array_aux_storage.customSetup(exec_type, tid);
151  }
152 
153 #ifdef MOOSE_KOKKOS_ENABLED
154  _kokkos_nodal_aux_storage.customSetup(exec_type, /*tid=*/0);
155  _kokkos_elemental_aux_storage.customSetup(exec_type, /*tid=*/0);
156 #endif
157 }
158 
159 void
161 {
163 
164  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
165  {
167  _nodal_aux_storage.subdomainSetup(tid);
168  _mortar_nodal_aux_storage.subdomainSetup(tid);
169  _nodal_vec_aux_storage.subdomainSetup(tid);
170  _nodal_array_aux_storage.subdomainSetup(tid);
171  _elemental_aux_storage.subdomainSetup(tid);
172  _elemental_vec_aux_storage.subdomainSetup(tid);
173  _elemental_array_aux_storage.subdomainSetup(tid);
174  }
175 }
176 
177 void
179 {
181 
182  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
183  {
185  _nodal_aux_storage.jacobianSetup(tid);
186  _mortar_nodal_aux_storage.jacobianSetup(tid);
187  _nodal_vec_aux_storage.jacobianSetup(tid);
188  _nodal_array_aux_storage.jacobianSetup(tid);
189  _elemental_aux_storage.jacobianSetup(tid);
190  _elemental_vec_aux_storage.jacobianSetup(tid);
191  _elemental_array_aux_storage.jacobianSetup(tid);
192  }
193 
194 #ifdef MOOSE_KOKKOS_ENABLED
197 #endif
198 }
199 
200 void
202 {
204 
205  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
206  {
208  _nodal_aux_storage.residualSetup(tid);
209  _mortar_nodal_aux_storage.residualSetup(tid);
210  _nodal_vec_aux_storage.residualSetup(tid);
211  _nodal_array_aux_storage.residualSetup(tid);
212  _elemental_aux_storage.residualSetup(tid);
213  _elemental_vec_aux_storage.residualSetup(tid);
214  _elemental_array_aux_storage.residualSetup(tid);
215  }
216 
217 #ifdef MOOSE_KOKKOS_ENABLED
220 #endif
221 }
222 
223 void
225 {
227  _nodal_aux_storage.updateActive(tid);
228  _mortar_nodal_aux_storage.updateActive(tid);
229  _nodal_vec_aux_storage.updateActive(tid);
230  _nodal_array_aux_storage.updateActive(tid);
231  _elemental_aux_storage.updateActive(tid);
232  _elemental_vec_aux_storage.updateActive(tid);
233  _elemental_array_aux_storage.updateActive(tid);
234 
235 #ifdef MOOSE_KOKKOS_ENABLED
236  if (tid == 0)
237  {
240  }
241 #endif
242 }
243 
244 void
245 AuxiliarySystem::addVariable(const std::string & var_type,
246  const std::string & name,
247  InputParameters & parameters)
248 {
249  SystemBase::addVariable(var_type, name, parameters);
250 
251  auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
252  Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
253 
254  if (var_type == "MooseVariableScalar")
255  return;
256 
257  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
258  {
259  if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
260  {
261  auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
262  if (var)
263  {
264  if (var->feType().family == LAGRANGE_VEC)
265  _nodal_vars[tid].push_back(var);
266  else
267  _elem_vars[tid].push_back(var);
268  }
269  }
270 
271  else
272  {
273  MooseVariableBase * var_base = _vars[tid].getVariable(name);
274 
275  auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
276 
277  if (var)
278  {
279  if (var->feType().family == LAGRANGE)
280  _nodal_vars[tid].push_back(var);
281  else
282  _elem_vars[tid].push_back(var);
283  }
284 
285  auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
286 
287  if (avar)
288  {
289  if (avar->feType().family == LAGRANGE)
290  _nodal_vars[tid].push_back(avar);
291  else
292  _elem_vars[tid].push_back(avar);
293  }
294  }
295  }
296 }
297 
298 void
299 AuxiliarySystem::addKernel(const std::string & kernel_name,
300  const std::string & name,
301  InputParameters & parameters)
302 {
303  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
304  {
305  const auto & base = parameters.getBase();
306  if (base == "AuxKernel" || base == "Bounds")
307  {
308  std::shared_ptr<AuxKernel> kernel =
309  _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
310  if (kernel->isNodal())
311  {
312  if (kernel->isMortar())
313  _mortar_nodal_aux_storage.addObject(kernel, tid);
314  else
315  _nodal_aux_storage.addObject(kernel, tid);
316  }
317  else
318  _elemental_aux_storage.addObject(kernel, tid);
319  }
320 
321  else if (base == "VectorAuxKernel")
322  {
323  std::shared_ptr<VectorAuxKernel> kernel =
324  _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
325  if (kernel->isNodal())
326  {
327  if (kernel->isMortar())
328  mooseError("Vector mortar aux kernels not yet implemented");
329  _nodal_vec_aux_storage.addObject(kernel, tid);
330  }
331  else
332  _elemental_vec_aux_storage.addObject(kernel, tid);
333  }
334 
335  else if (base == "ArrayAuxKernel")
336  {
337  std::shared_ptr<ArrayAuxKernel> kernel =
338  _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
339  if (kernel->isNodal())
340  {
341  if (kernel->isMortar())
342  mooseError("Vector mortar aux kernels not yet implemented");
343  _nodal_array_aux_storage.addObject(kernel, tid);
344  }
345  else
346  _elemental_array_aux_storage.addObject(kernel, tid);
347  }
348  else
349  mooseAssert(false,
350  "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
351  "' to the auxiliary system with invalid _moose_base: " + base);
352  }
353 }
354 
355 void
356 AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
357  const std::string & name,
358  InputParameters & parameters)
359 {
360  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
361  {
362  std::shared_ptr<AuxScalarKernel> kernel =
363  _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
364  _aux_scalar_storage.addObject(kernel, tid);
365  }
366 }
367 
368 void
370 {
371  for (auto * var : _nodal_vars[tid])
372  var->computeElemValues();
373 
374  for (auto * var : _elem_vars[tid])
375  {
376  var->reinitAux();
377  var->computeElemValues();
378  }
379 }
380 
381 void
382 AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
383 {
384  for (auto * var : _nodal_vars[tid])
385  var->computeElemValuesFace();
386 
387  for (auto * var : _elem_vars[tid])
388  {
389  var->reinitAux();
390  var->reinitAuxNeighbor();
391  var->computeElemValuesFace();
392  }
393 }
394 
395 void
397 {
398  if (_serialized_solution.get() &&
399  _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
400  {
401  if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
402  {
403  _serialized_solution->clear();
404  _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
405  }
406 
408  }
409 }
410 
411 void
413 {
414  // avoid division by dt which might be zero.
415  if (_fe_problem.dt() > 0.)
416  for (auto & ti : _time_integrators)
417  ti->preStep();
418 
419  // We need to compute time derivatives every time each kind of the variables is finished, because:
420  //
421  // a) the user might want to use the aux variable value somewhere, thus we need to provide the
422  // up-to-date value
423  // b) time integration system works with the whole vectors of solutions, thus we cannot update
424  // only a part of the vector
425  //
426 
427  if (_vars[0].scalars().size() > 0)
428  {
429  computeScalarVars(type);
430  // compute time derivatives of scalar aux variables _after_ the values were updated
431  if (_fe_problem.dt() > 0.)
432  for (auto & ti : _time_integrators)
433  ti->computeTimeDerivatives();
434  }
435 
436  if (_vars[0].fieldVariables().size() > 0)
437  {
438  computeNodalArrayVars(type);
439  computeNodalVecVars(type);
440  computeNodalVars(type);
444  computeElementalVars(type);
445 
446 #ifdef MOOSE_KOKKOS_ENABLED
447  kokkosCompute(type);
448 #endif
449 
450  // compute time derivatives of nodal aux variables _after_ the values were updated
451  if (_fe_problem.dt() > 0.)
452  for (auto & ti : _time_integrators)
453  ti->computeTimeDerivatives();
454  }
455 
456  if (_serialized_solution.get())
458 }
459 
460 std::set<std::string>
462 {
463  std::set<std::string> depend_objects;
464 
465  // Elemental AuxKernels
466  {
467  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
468  _elemental_aux_storage[type].getActiveObjects();
469  for (const auto & aux : auxs)
470  {
471  const std::set<UserObjectName> & uo = aux->getDependObjects();
472  depend_objects.insert(uo.begin(), uo.end());
473  }
474  }
475 
476  // Elemental VectorAuxKernels
477  {
478  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
479  _elemental_vec_aux_storage[type].getActiveObjects();
480  for (const auto & aux : auxs)
481  {
482  const std::set<UserObjectName> & uo = aux->getDependObjects();
483  depend_objects.insert(uo.begin(), uo.end());
484  }
485  }
486 
487  // Elemental ArrayAuxKernels
488  {
489  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
490  _elemental_array_aux_storage[type].getActiveObjects();
491  for (const auto & aux : auxs)
492  {
493  const std::set<UserObjectName> & uo = aux->getDependObjects();
494  depend_objects.insert(uo.begin(), uo.end());
495  }
496  }
497 
498  // Nodal AuxKernels
499  {
500  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
501  _nodal_aux_storage[type].getActiveObjects();
502  for (const auto & aux : auxs)
503  {
504  const std::set<UserObjectName> & uo = aux->getDependObjects();
505  depend_objects.insert(uo.begin(), uo.end());
506  }
507  }
508 
509  // Mortar Nodal AuxKernels
510  {
511  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
512  _mortar_nodal_aux_storage[type].getActiveObjects();
513  for (const auto & aux : auxs)
514  {
515  const std::set<UserObjectName> & uo = aux->getDependObjects();
516  depend_objects.insert(uo.begin(), uo.end());
517  }
518  }
519 
520  // Nodal VectorAuxKernels
521  {
522  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
523  _nodal_vec_aux_storage[type].getActiveObjects();
524  for (const auto & aux : auxs)
525  {
526  const std::set<UserObjectName> & uo = aux->getDependObjects();
527  depend_objects.insert(uo.begin(), uo.end());
528  }
529  }
530 
531  // Nodal ArrayAuxKernels
532  {
533  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
534  _nodal_array_aux_storage[type].getActiveObjects();
535  for (const auto & aux : auxs)
536  {
537  const std::set<UserObjectName> & uo = aux->getDependObjects();
538  depend_objects.insert(uo.begin(), uo.end());
539  }
540  }
541 
542 #ifdef MOOSE_KOKKOS_ENABLED
543  // Nodal KokkosAuxKernels
544  {
545  const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
547  for (const auto & aux : auxs)
548  {
549  const std::set<UserObjectName> & uo = aux->getDependObjects();
550  depend_objects.insert(uo.begin(), uo.end());
551  }
552  }
553 
554  // Nodal ElementalAuxKernels
555  {
556  const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
558  for (const auto & aux : auxs)
559  {
560  const std::set<UserObjectName> & uo = aux->getDependObjects();
561  depend_objects.insert(uo.begin(), uo.end());
562  }
563  }
564 #endif
565 
566  return depend_objects;
567 }
568 
569 std::set<std::string>
571 {
572  std::set<std::string> depend_objects;
573 
574  // Elemental AuxKernels
575  {
576  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
577  _elemental_aux_storage.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  // Elemental VectorAuxKernels
586  {
587  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
588  _elemental_vec_aux_storage.getActiveObjects();
589  for (const auto & aux : auxs)
590  {
591  const std::set<UserObjectName> & uo = aux->getDependObjects();
592  depend_objects.insert(uo.begin(), uo.end());
593  }
594  }
595 
596  // Elemental ArrayAuxKernels
597  {
598  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
599  _elemental_array_aux_storage.getActiveObjects();
600  for (const auto & aux : auxs)
601  {
602  const std::set<UserObjectName> & uo = aux->getDependObjects();
603  depend_objects.insert(uo.begin(), uo.end());
604  }
605  }
606 
607  // Nodal AuxKernels
608  {
609  const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
610  for (const auto & aux : auxs)
611  {
612  const std::set<UserObjectName> & uo = aux->getDependObjects();
613  depend_objects.insert(uo.begin(), uo.end());
614  }
615  }
616 
617  // Mortar Nodal AuxKernels
618  {
619  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
620  _mortar_nodal_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  // Nodal VectorAuxKernels
629  {
630  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
631  _nodal_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  // Nodal ArrayAuxKernels
640  {
641  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
642  _nodal_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 #ifdef MOOSE_KOKKOS_ENABLED
651  // Nodal KokkosAuxKernels
652  {
653  const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
655  for (const auto & aux : auxs)
656  {
657  const std::set<UserObjectName> & uo = aux->getDependObjects();
658  depend_objects.insert(uo.begin(), uo.end());
659  }
660  }
661 
662  // Nodal ElementalAuxKernels
663  {
664  const std::vector<std::shared_ptr<AuxKernelBase>> & auxs =
666  for (const auto & aux : auxs)
667  {
668  const std::set<UserObjectName> & uo = aux->getDependObjects();
669  depend_objects.insert(uo.begin(), uo.end());
670  }
671  }
672 #endif
673 
674  return depend_objects;
675 }
676 
677 void
679 {
681  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
682 
683  std::set<TagID> needed_sc_var_matrix_tags;
684  std::set<TagID> needed_sc_var_vector_tags;
685  for (const auto & obj : objects)
686  {
687  auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
688  needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
689 
690  auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
691  needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
692  }
693 
694  _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
695  _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
696 }
697 
698 void
700 {
703 }
704 
705 void
707 {
709 
710  // Reference to the current storage container
712 
713  if (storage.hasActiveObjects())
714  {
715  TIME_SECTION("computeScalarVars", 1);
716 
717  PARALLEL_TRY
718  {
719  // FIXME: run multi-threaded
720  THREAD_ID tid = 0;
721  if (storage.hasActiveObjects())
722  {
724 
725  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
726  storage.getActiveObjects(tid);
727 
728  // Call compute() method on all active AuxScalarKernel objects
729  for (const auto & obj : objects)
730  obj->compute();
731 
732  const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
733  for (const auto & var : scalar_vars)
734  var->insert(solution());
735  }
736  }
737  PARALLEL_CATCH;
738 
739  solution().close();
740  _sys.update();
741  }
742 
744 }
745 
746 void
748 {
749  TIME_SECTION("computeNodalVars", 3);
750 
752  computeNodalVarsHelper<AuxKernel>(nodal);
753 }
754 
755 void
757 {
758  TIME_SECTION("computeNodalVecVars", 3);
759 
761  computeNodalVarsHelper<VectorAuxKernel>(nodal);
762 }
763 
764 void
766 {
768  computeNodalVarsHelper<ArrayAuxKernel>(nodal);
769 }
770 
771 void
773 {
774  TIME_SECTION("computeMortarNodalVars", 3);
775 
776  const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
777 
778  mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
779  "We don't allow creation of block restricted mortar nodal aux kernels.");
780 
781  if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
782  {
784  for (const auto & [bnd_id, mortar_nodal_auxes] :
785  mortar_nodal_warehouse.getActiveBoundaryObjects())
786  for (const auto index : index_range(mortar_nodal_auxes))
787  {
788  PARALLEL_TRY
789  {
790  try
791  {
793  _fe_problem, mortar_nodal_warehouse, bnd_id, index);
794  Threads::parallel_reduce(bnd_nodes, mnabt);
795  }
796  catch (libMesh::LogicError & e)
797  {
798  _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
799  "nodal Auxiliary variable computation:\n" +
800  std::string(e.what()));
801  }
802  catch (MooseException & e)
803  {
804  _fe_problem.setException("The following MooseException was raised during mortar nodal "
805  "Auxiliary variable computation:\n" +
806  std::string(e.what()));
807  }
808  catch (MetaPhysicL::LogicError & e)
809  {
811  }
812  }
813  PARALLEL_CATCH;
814 
815  // We need to make sure we propagate exceptions to all processes before trying to close
816  // here, which is a parallel operation
817  solution().close();
818  _sys.update();
819  }
820  }
821 }
822 
823 void
825 {
826  TIME_SECTION("computeElementalVars", 3);
827 
829  computeElementalVarsHelper<AuxKernel>(elemental);
830 }
831 
832 void
834 {
835  TIME_SECTION("computeElementalVecVars", 3);
836 
838  computeElementalVarsHelper<VectorAuxKernel>(elemental);
839 }
840 
841 void
843 {
845  computeElementalVarsHelper<ArrayAuxKernel>(elemental);
846 }
847 
848 void
850  std::vector<dof_id_type> & /*n_nz*/,
851  std::vector<dof_id_type> &
852  /*n_oz*/)
853 {
854 }
855 
856 Order
858 {
859  Order order = CONSTANT;
860  std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
861  for (const auto & var : vars)
862  {
863  if (!var->isNodal()) // nodal aux variables do not need quadrature
864  {
865  FEType fe_type = var->feType();
866  if (fe_type.default_quadrature_order() > order)
867  order = fe_type.default_quadrature_order();
868  }
869  }
870 
871  return order;
872 }
873 
874 bool
876 {
877  return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
878  _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
879 }
880 
881 void
883 {
886 }
887 
888 template <typename AuxKernelType>
889 void
891 {
892  if (warehouse.hasActiveBlockObjects())
893  {
894  // Block Elemental AuxKernels
895  PARALLEL_TRY
896  {
899  try
900  {
901  Threads::parallel_reduce(range, eavt);
902  }
903  catch (MooseException & e)
904  {
905  _fe_problem.setException("The following MooseException was raised during elemental "
906  "Auxiliary variable computation:\n" +
907  std::string(e.what()));
908  }
909  }
910  PARALLEL_CATCH;
911 
912  // We need to make sure we propagate exceptions to all processes before trying to close
913  // here, which is a parallel operation
914  solution().close();
915  _sys.update();
916  }
917 
918  // Boundary Elemental AuxKernels
919  if (warehouse.hasActiveBoundaryObjects())
920  {
921  TIME_SECTION("computeElementalVecVars", 3);
922 
923  PARALLEL_TRY
924  {
927  try
928  {
929  Threads::parallel_reduce(bnd_elems, eabt);
930  }
931  catch (MooseException & e)
932  {
933  _fe_problem.setException("The following MooseException was raised during boundary "
934  "elemental Auxiliary variable computation:\n" +
935  std::string(e.what()));
936  }
937  }
938  PARALLEL_CATCH;
939 
940  // We need to make sure we propagate exceptions to all processes before trying to close
941  // here, which is a parallel operation
942  solution().close();
943  _sys.update();
944  }
945 }
946 
947 template <typename AuxKernelType>
948 void
950 {
951  if (warehouse.hasActiveBlockObjects())
952  {
953  // Block Nodal AuxKernels
954  PARALLEL_TRY
955  {
958  Threads::parallel_reduce(range, navt);
959 
960  solution().close();
961  _sys.update();
962  }
963  PARALLEL_CATCH;
964  }
965 
966  if (warehouse.hasActiveBoundaryObjects())
967  {
968  TIME_SECTION("computeBoundaryObjects", 3);
969 
970  // Boundary Nodal AuxKernels
971  PARALLEL_TRY
972  {
975  Threads::parallel_reduce(bnd_nodes, nabt);
976 
977  solution().close();
978  _sys.update();
979  }
980  PARALLEL_CATCH;
981  }
982 }
983 
984 void
986  std::vector<Number> & rel_diff_norms) const
987 {
988  rel_diff_norms.resize(nVariables(), 0);
989  // Get dof map from system
990  const auto & dof_map = _sys.get_dof_map();
991 
992  for (const auto n : make_range(nVariables()))
993  {
994  // Get local indices from dof map for each variable
995  std::vector<dof_id_type> local_indices_n;
996  dof_map.local_variable_indices(local_indices_n, _mesh, n);
997  Number diff_norm_n = 0;
998  Number norm_n = 0;
999  // Get values from system, update norm
1000  for (const auto local_index : local_indices_n)
1001  {
1002  const Number & value = solution()(local_index);
1003  const Number & value_old = solutionOld()(local_index);
1004  diff_norm_n += Utility::pow<2, Number>(value - value_old);
1005  norm_n += Utility::pow<2, Number>(value);
1006  }
1007  // Aggregate norm over proceccors
1008  _communicator.sum(diff_norm_n);
1009  _communicator.sum(norm_n);
1010  diff_norm_n = sqrt(diff_norm_n);
1011  norm_n = sqrt(norm_n);
1012  rel_diff_norms[n] = diff_norm_n / norm_n;
1013  }
1014 }
1015 
1016 template void
1017 AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1018 template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
1020 template void
1021 AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
1022 template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
std::string name(const ElemQuality q)
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
Definition: SystemBase.h:1049
void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
LAGRANGE
ExecuteMooseObjectWarehouse< AuxKernel > _nodal_aux_storage
ExecuteMooseObjectWarehouse< AuxKernel > _mortar_nodal_aux_storage
virtual void timestepSetup() override
libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:1276
Order
virtual void clearActiveScalarVariableCoupleableVectorTags(const THREAD_ID tid) override
void computeNodalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
virtual const char * what() const
Get out the error message.
unsigned int n_threads()
const std::vector< MooseVariableScalar * > & getScalarVariables(THREAD_ID tid)
Definition: SystemBase.h:756
bool hasActiveBlockObjects(THREAD_ID tid=0) const
void computeScalarVars(ExecFlagType type)
void sort(THREAD_ID tid=0)
Performs a sort using the DependencyResolver.
LAGRANGE_VEC
This class evaluates a single mortar nodal aux kernel.
NumericVector< Number > & solution()
Definition: SystemBase.h:196
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Canonical method for adding a variable.
Definition: SystemBase.C:718
virtual void copyCurrentIntoPreviousNL()
Copies the current solution into the previous nonlinear iteration solution.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
virtual void clearActiveScalarVariableCoupleableMatrixTags(const THREAD_ID tid) override
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.
void updateActive(THREAD_ID tid=0) override
Updates the active objects storage.
virtual void setActiveScalarVariableCoupleableMatrixTags(std::set< TagID > &mtags, 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
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:141
char ** vars
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1135
AuxiliarySystem(FEProblemBase &subproblem, const std::string &name)
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _nodal_array_aux_storage
virtual void updateActive(THREAD_ID tid)
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 void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
Factory & _factory
Definition: SystemBase.h:989
const NumericVector< Number > *const & currentSolution() const override
The solution vector that is currently being operated on.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Order default_quadrature_order() const
void computeElementalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
const Parallel::Communicator & _communicator
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Base class for a system (of equations)
Definition: SystemBase.h:84
ExecuteMooseObjectWarehouse< AuxScalarKernel > _aux_scalar_storage
bool needMaterialOnSide(BoundaryID bnd_id)
Indicated whether this system needs material properties on boundaries.
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
Reinit an element assembly info.
std::unique_ptr< NumericVector< Number > > _serialized_solution
Serialized version of the solution vector, or nullptr if a serialized solution is not needed...
Definition: SystemBase.h:1068
virtual void residualSetup() override
libMesh::ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:1313
const std::string & getBase() const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
FEProblemBase & _fe_problem
Definition: Split.h:45
void computeMortarNodalVars(ExecFlagType type)
dof_id_type n_dofs() const
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition: SystemBase.C:891
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual const std::string & name() const
Definition: SystemBase.C:1340
virtual void jacobianSetup()
Definition: SystemBase.C:1606
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_elemental_aux_storage
void setScalarVariableCoupleableTags(ExecFlagType type)
void clearScalarVariableCoupleableTags()
std::set< std::string > getDependObjects()
virtual void jacobianSetup() override
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _elemental_array_aux_storage
CONSTANT
SERIAL
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...
void computeNodalArrayVars(ExecFlagType type)
virtual std::unique_ptr< Base > create()=0
void computeElementalVars(ExecFlagType type)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Base class for making kernels that work on auxiliary scalar variables.
boundary_id_type BoundaryID
virtual void timestepSetup(THREAD_ID tid=0) const
virtual libMesh::Order getMinQuadratureOrder() override
Get the minimum quadrature order for evaluating elemental auxiliary variables.
virtual void setActiveScalarVariableCoupleableVectorTags(std::set< TagID > &vtags, const THREAD_ID tid) override
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
void kokkosCompute(ExecFlagType type)
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void addVariable(const std::string &var_type, const std::string &name, InputParameters &parameters) override
Canonical method for adding a variable.
Interface for objects interacting with the PerfGraph.
virtual void close()=0
void jacobianSetup(THREAD_ID tid=0) const override
Convenience methods for calling object setup methods.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void reinitElemFace(const Elem *elem, unsigned int side, THREAD_ID tid) override
Reinit assembly info for a side of an element.
virtual ~AuxiliarySystem()
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< MooseVariableFEBase * > > _nodal_vars
virtual void initialSetup() override
Setup Functions.
ExecuteMooseObjectWarehouse< VectorAuxKernel > _nodal_vec_aux_storage
std::vector< std::vector< MooseVariableFieldBase * > > _elem_vars
Elemental variables.
ExecuteMooseObjectWarehouse< AuxKernelBase > _kokkos_nodal_aux_storage
FEProblemBase & _fe_problem
the governing finite element/volume problem
Definition: SystemBase.h:986
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:996
Provides a way for users to bail out of the current solve.
virtual void update()
virtual void subdomainSetup()
Definition: SystemBase.C:1592
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds an auxiliary kernel.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
MooseMesh & _mesh
Definition: SystemBase.h:991
bool hasActiveObjects(THREAD_ID tid=0) const
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
IntRange< T > make_range(T beg, T end)
void computeNodalVars(ExecFlagType type)
virtual const NumericVector< Number > * solutionPreviousNewton() const
Definition: SystemBase.C:1355
virtual void customSetup(const ExecFlagType &exec_type)
Definition: SystemBase.C:1585
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a scalar kernel.
ExecuteMooseObjectWarehouse< AuxKernel > _elemental_aux_storage
virtual void customSetup(const ExecFlagType &exec_type) override
libMesh::StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
Definition: MooseMesh.C:1341
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void serializeSolution()
void computeNodalVecVars(ExecFlagType type)
Real Number
void computeElementalArrayVars(ExecFlagType type)
ExecuteMooseObjectWarehouse< VectorAuxKernel > _elemental_vec_aux_storage
NumericVector< Number > & solutionOld()
Definition: SystemBase.h:197
virtual void initialSetup()
Setup Functions.
Definition: SystemBase.C:1558
bool defaultGhosting()
Whether or not the user has requested default ghosting ot be on.
Definition: SubProblem.h:144
TYPE_VECTOR
virtual Real & dt() const
libMesh::System & _sys
const DofMap & get_dof_map() const
virtual void residualSetup()
Definition: SystemBase.C:1599
void residualSetup(THREAD_ID tid=0) const override
virtual void subdomainSetup(THREAD_ID tid=0) const
libMesh::StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:1327
auto index_range(const T &sizable)
void variableWiseRelativeSolutionDifferenceNorm(std::vector< Number > &var_diffs) const
Computes and stores ||current - old|| / ||current|| for each variable in the given vector...
void computeElementalVecVars(ExecFlagType type)
Base variable class.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
virtual void subdomainSetup() override
virtual void timestepSetup()
Definition: SystemBase.C:1578
virtual void localize(std::vector< T > &v_local) const=0