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  if (parameters.get<std::string>("_moose_base") == "AuxKernel" ||
265  parameters.get<std::string>("_moose_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 (parameters.get<std::string>("_moose_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 (parameters.get<std::string>("_moose_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: " +
311  parameters.get<std::string>("_moose_base"));
312  }
313 }
314 
315 void
316 AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
317  const std::string & name,
318  InputParameters & parameters)
319 {
320  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
321  {
322  std::shared_ptr<AuxScalarKernel> kernel =
323  _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
324  _aux_scalar_storage.addObject(kernel, tid);
325  }
326 }
327 
328 void
330 {
331  for (auto * var : _nodal_vars[tid])
332  var->computeElemValues();
333 
334  for (auto * var : _elem_vars[tid])
335  {
336  var->reinitAux();
337  var->computeElemValues();
338  }
339 }
340 
341 void
342 AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
343 {
344  for (auto * var : _nodal_vars[tid])
345  var->computeElemValuesFace();
346 
347  for (auto * var : _elem_vars[tid])
348  {
349  var->reinitAux();
350  var->reinitAuxNeighbor();
351  var->computeElemValuesFace();
352  }
353 }
354 
355 void
357 {
358  if (_serialized_solution.get() &&
359  _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
360  {
361  if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
362  {
363  _serialized_solution->clear();
364  _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
365  }
366 
368  }
369 }
370 
371 void
373 {
374  // avoid division by dt which might be zero.
375  if (_fe_problem.dt() > 0.)
376  for (auto & ti : _time_integrators)
377  ti->preStep();
378 
379  // We need to compute time derivatives every time each kind of the variables is finished, because:
380  //
381  // a) the user might want to use the aux variable value somewhere, thus we need to provide the
382  // up-to-date value
383  // b) time integration system works with the whole vectors of solutions, thus we cannot update
384  // only a part of the vector
385  //
386 
387  if (_vars[0].scalars().size() > 0)
388  {
389  computeScalarVars(type);
390  // compute time derivatives of scalar aux variables _after_ the values were updated
391  if (_fe_problem.dt() > 0.)
392  for (auto & ti : _time_integrators)
393  ti->computeTimeDerivatives();
394  }
395 
396  if (_vars[0].fieldVariables().size() > 0)
397  {
398  computeNodalArrayVars(type);
399  computeNodalVecVars(type);
400  computeNodalVars(type);
404  computeElementalVars(type);
405 
406  // compute time derivatives of nodal aux variables _after_ the values were updated
407  if (_fe_problem.dt() > 0.)
408  for (auto & ti : _time_integrators)
409  ti->computeTimeDerivatives();
410  }
411 
412  if (_serialized_solution.get())
414 }
415 
416 std::set<std::string>
418 {
419  std::set<std::string> depend_objects;
420 
421  // Elemental AuxKernels
422  {
423  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
424  _elemental_aux_storage[type].getActiveObjects();
425  for (const auto & aux : auxs)
426  {
427  const std::set<UserObjectName> & uo = aux->getDependObjects();
428  depend_objects.insert(uo.begin(), uo.end());
429  }
430  }
431 
432  // Elemental VectorAuxKernels
433  {
434  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
435  _elemental_vec_aux_storage[type].getActiveObjects();
436  for (const auto & aux : auxs)
437  {
438  const std::set<UserObjectName> & uo = aux->getDependObjects();
439  depend_objects.insert(uo.begin(), uo.end());
440  }
441  }
442 
443  // Elemental ArrayAuxKernels
444  {
445  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
446  _elemental_array_aux_storage[type].getActiveObjects();
447  for (const auto & aux : auxs)
448  {
449  const std::set<UserObjectName> & uo = aux->getDependObjects();
450  depend_objects.insert(uo.begin(), uo.end());
451  }
452  }
453 
454  // Nodal AuxKernels
455  {
456  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
457  _nodal_aux_storage[type].getActiveObjects();
458  for (const auto & aux : auxs)
459  {
460  const std::set<UserObjectName> & uo = aux->getDependObjects();
461  depend_objects.insert(uo.begin(), uo.end());
462  }
463  }
464 
465  // Mortar Nodal AuxKernels
466  {
467  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
468  _mortar_nodal_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  // Nodal VectorAuxKernels
477  {
478  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
479  _nodal_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  // Nodal ArrayAuxKernels
488  {
489  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
490  _nodal_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  return depend_objects;
499 }
500 
501 std::set<std::string>
503 {
504  std::set<std::string> depend_objects;
505 
506  // Elemental AuxKernels
507  {
508  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
509  _elemental_aux_storage.getActiveObjects();
510  for (const auto & aux : auxs)
511  {
512  const std::set<UserObjectName> & uo = aux->getDependObjects();
513  depend_objects.insert(uo.begin(), uo.end());
514  }
515  }
516 
517  // Elemental VectorAuxKernels
518  {
519  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
520  _elemental_vec_aux_storage.getActiveObjects();
521  for (const auto & aux : auxs)
522  {
523  const std::set<UserObjectName> & uo = aux->getDependObjects();
524  depend_objects.insert(uo.begin(), uo.end());
525  }
526  }
527 
528  // Elemental ArrayAuxKernels
529  {
530  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
531  _elemental_array_aux_storage.getActiveObjects();
532  for (const auto & aux : auxs)
533  {
534  const std::set<UserObjectName> & uo = aux->getDependObjects();
535  depend_objects.insert(uo.begin(), uo.end());
536  }
537  }
538 
539  // Nodal AuxKernels
540  {
541  const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
542  for (const auto & aux : auxs)
543  {
544  const std::set<UserObjectName> & uo = aux->getDependObjects();
545  depend_objects.insert(uo.begin(), uo.end());
546  }
547  }
548 
549  // Mortar Nodal AuxKernels
550  {
551  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
552  _mortar_nodal_aux_storage.getActiveObjects();
553  for (const auto & aux : auxs)
554  {
555  const std::set<UserObjectName> & uo = aux->getDependObjects();
556  depend_objects.insert(uo.begin(), uo.end());
557  }
558  }
559 
560  // Nodal VectorAuxKernels
561  {
562  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
563  _nodal_vec_aux_storage.getActiveObjects();
564  for (const auto & aux : auxs)
565  {
566  const std::set<UserObjectName> & uo = aux->getDependObjects();
567  depend_objects.insert(uo.begin(), uo.end());
568  }
569  }
570 
571  // Nodal ArrayAuxKernels
572  {
573  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
574  _nodal_array_aux_storage.getActiveObjects();
575  for (const auto & aux : auxs)
576  {
577  const std::set<UserObjectName> & uo = aux->getDependObjects();
578  depend_objects.insert(uo.begin(), uo.end());
579  }
580  }
581 
582  return depend_objects;
583 }
584 
585 void
587 {
589  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
590 
591  std::set<TagID> needed_sc_var_matrix_tags;
592  std::set<TagID> needed_sc_var_vector_tags;
593  for (const auto & obj : objects)
594  {
595  auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
596  needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
597 
598  auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
599  needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
600  }
601 
602  _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
603  _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
604 }
605 
606 void
608 {
611 }
612 
613 void
615 {
617 
618  // Reference to the current storage container
620 
621  if (storage.hasActiveObjects())
622  {
623  TIME_SECTION("computeScalarVars", 1);
624 
625  PARALLEL_TRY
626  {
627  // FIXME: run multi-threaded
628  THREAD_ID tid = 0;
629  if (storage.hasActiveObjects())
630  {
632 
633  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
634  storage.getActiveObjects(tid);
635 
636  // Call compute() method on all active AuxScalarKernel objects
637  for (const auto & obj : objects)
638  obj->compute();
639 
640  const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
641  for (const auto & var : scalar_vars)
642  var->insert(solution());
643  }
644  }
645  PARALLEL_CATCH;
646 
647  solution().close();
648  _sys.update();
649  }
650 
652 }
653 
654 void
656 {
657  TIME_SECTION("computeNodalVars", 3);
658 
660  computeNodalVarsHelper<AuxKernel>(nodal);
661 }
662 
663 void
665 {
666  TIME_SECTION("computeNodalVecVars", 3);
667 
669  computeNodalVarsHelper<VectorAuxKernel>(nodal);
670 }
671 
672 void
674 {
676  computeNodalVarsHelper<ArrayAuxKernel>(nodal);
677 }
678 
679 void
681 {
682  TIME_SECTION("computeMortarNodalVars", 3);
683 
684  const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
685 
686  mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
687  "We don't allow creation of block restricted mortar nodal aux kernels.");
688 
689  if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
690  {
692  for (const auto & [bnd_id, mortar_nodal_auxes] :
693  mortar_nodal_warehouse.getActiveBoundaryObjects())
694  for (const auto index : index_range(mortar_nodal_auxes))
695  {
696  PARALLEL_TRY
697  {
698  try
699  {
701  _fe_problem, mortar_nodal_warehouse, bnd_id, index);
702  Threads::parallel_reduce(bnd_nodes, mnabt);
703  }
704  catch (libMesh::LogicError & e)
705  {
706  _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
707  "nodal Auxiliary variable computation:\n" +
708  std::string(e.what()));
709  }
710  catch (MooseException & e)
711  {
712  _fe_problem.setException("The following MooseException was raised during mortar nodal "
713  "Auxiliary variable computation:\n" +
714  std::string(e.what()));
715  }
716  catch (MetaPhysicL::LogicError & e)
717  {
719  }
720  }
721  PARALLEL_CATCH;
722 
723  // We need to make sure we propagate exceptions to all processes before trying to close
724  // here, which is a parallel operation
725  solution().close();
726  _sys.update();
727  }
728  }
729 }
730 
731 void
733 {
734  TIME_SECTION("computeElementalVars", 3);
735 
737  computeElementalVarsHelper<AuxKernel>(elemental);
738 }
739 
740 void
742 {
743  TIME_SECTION("computeElementalVecVars", 3);
744 
746  computeElementalVarsHelper<VectorAuxKernel>(elemental);
747 }
748 
749 void
751 {
753  computeElementalVarsHelper<ArrayAuxKernel>(elemental);
754 }
755 
756 void
758  std::vector<dof_id_type> & /*n_nz*/,
759  std::vector<dof_id_type> &
760  /*n_oz*/)
761 {
762 }
763 
764 Order
766 {
767  Order order = CONSTANT;
768  std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
769  for (const auto & var : vars)
770  {
771  if (!var->isNodal()) // nodal aux variables do not need quadrature
772  {
773  FEType fe_type = var->feType();
774  if (fe_type.default_quadrature_order() > order)
775  order = fe_type.default_quadrature_order();
776  }
777  }
778 
779  return order;
780 }
781 
782 bool
784 {
785  return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
786  _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
787 }
788 
789 void
791 {
794 }
795 
796 template <typename AuxKernelType>
797 void
799 {
800  if (warehouse.hasActiveBlockObjects())
801  {
802  // Block Elemental AuxKernels
803  PARALLEL_TRY
804  {
807  try
808  {
809  Threads::parallel_reduce(range, eavt);
810  }
811  catch (MooseException & e)
812  {
813  _fe_problem.setException("The following MooseException was raised during elemental "
814  "Auxiliary variable computation:\n" +
815  std::string(e.what()));
816  }
817  }
818  PARALLEL_CATCH;
819 
820  // We need to make sure we propagate exceptions to all processes before trying to close
821  // here, which is a parallel operation
822  solution().close();
823  _sys.update();
824  }
825 
826  // Boundary Elemental AuxKernels
827  if (warehouse.hasActiveBoundaryObjects())
828  {
829  TIME_SECTION("computeElementalVecVars", 3);
830 
831  PARALLEL_TRY
832  {
835  try
836  {
837  Threads::parallel_reduce(bnd_elems, eabt);
838  }
839  catch (MooseException & e)
840  {
841  _fe_problem.setException("The following MooseException was raised during boundary "
842  "elemental Auxiliary variable computation:\n" +
843  std::string(e.what()));
844  }
845  }
846  PARALLEL_CATCH;
847 
848  // We need to make sure we propagate exceptions to all processes before trying to close
849  // here, which is a parallel operation
850  solution().close();
851  _sys.update();
852  }
853 }
854 
855 template <typename AuxKernelType>
856 void
858 {
859  if (warehouse.hasActiveBlockObjects())
860  {
861  // Block Nodal AuxKernels
862  PARALLEL_TRY
863  {
866  Threads::parallel_reduce(range, navt);
867 
868  solution().close();
869  _sys.update();
870  }
871  PARALLEL_CATCH;
872  }
873 
874  if (warehouse.hasActiveBoundaryObjects())
875  {
876  TIME_SECTION("computeBoundaryObjects", 3);
877 
878  // Boundary Nodal AuxKernels
879  PARALLEL_TRY
880  {
883  Threads::parallel_reduce(bnd_nodes, nabt);
884 
885  solution().close();
886  _sys.update();
887  }
888  PARALLEL_CATCH;
889  }
890 }
891 
892 void
894  std::vector<Number> & rel_diff_norms) const
895 {
896  rel_diff_norms.resize(nVariables(), 0);
897  // Get dof map from system
898  const auto & dof_map = _sys.get_dof_map();
899 
900  for (const auto n : make_range(nVariables()))
901  {
902  // Get local indices from dof map for each variable
903  std::vector<dof_id_type> local_indices_n;
904  dof_map.local_variable_indices(local_indices_n, _mesh, n);
905  Number diff_norm_n = 0;
906  Number norm_n = 0;
907  // Get values from system, update norm
908  for (const auto local_index : local_indices_n)
909  {
910  const Number & value = solution()(local_index);
911  const Number & value_old = solutionOld()(local_index);
912  diff_norm_n += Utility::pow<2, Number>(value - value_old);
913  norm_n += Utility::pow<2, Number>(value);
914  }
915  // Aggregate norm over proceccors
916  _communicator.sum(diff_norm_n);
917  _communicator.sum(norm_n);
918  diff_norm_n = sqrt(diff_norm_n);
919  norm_n = sqrt(norm_n);
920  rel_diff_norms[n] = diff_norm_n / norm_n;
921  }
922 }
923 
924 template void
925 AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
926 template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
928 template void
929 AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
930 template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
std::string name(const ElemQuality q)
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
Definition: SystemBase.h:1041
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:1235
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:757
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:195
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Canonical method for adding a variable.
Definition: SystemBase.C:710
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:302
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:112
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:1155
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:983
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:1060
virtual void residualSetup() override
libMesh::ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:1272
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:874
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual const std::string & name() const
Definition: SystemBase.C:1330
virtual void jacobianSetup()
Definition: SystemBase.C:1573
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:980
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:990
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:1559
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:985
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:1345
virtual void customSetup(const ExecFlagType &exec_type)
Definition: SystemBase.C:1552
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:1300
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:196
virtual void initialSetup()
Setup Functions.
Definition: SystemBase.C:1525
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:1566
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:1286
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)
unsigned int THREAD_ID
Definition: MooseTypes.h:209
virtual void subdomainSetup() override
virtual void timestepSetup()
Definition: SystemBase.C:1545
virtual void localize(std::vector< T > &v_local) const=0