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