www.mooseframework.org
AuxiliarySystem.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
33 // AuxiliarySystem ////////
34 
35 AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
36  : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
37  PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
38  _sys(subproblem.es().add_system<System>(name)),
39  _current_solution(_sys.current_local_solution.get()),
40  _aux_scalar_storage(_app.getExecuteOnEnum()),
41  _nodal_aux_storage(_app.getExecuteOnEnum()),
42  _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
43  _elemental_aux_storage(_app.getExecuteOnEnum()),
44  _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
45  _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
46  _nodal_array_aux_storage(_app.getExecuteOnEnum()),
47  _elemental_array_aux_storage(_app.getExecuteOnEnum())
48 {
51 
53  {
54  auto & dof_map = _sys.get_dof_map();
55  dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
56  dof_map.set_implicit_neighbor_dofs(false);
57  }
58 }
59 
61 
62 void
64 {
65  TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
66 
68 
69  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
70  {
73 
74  _nodal_aux_storage.sort(tid);
75  _nodal_aux_storage.initialSetup(tid);
76 
77  _mortar_nodal_aux_storage.sort(tid);
78  _mortar_nodal_aux_storage.initialSetup(tid);
79 
80  _nodal_vec_aux_storage.sort(tid);
81  _nodal_vec_aux_storage.initialSetup(tid);
82 
83  _nodal_array_aux_storage.sort(tid);
84  _nodal_array_aux_storage.initialSetup(tid);
85 
86  _elemental_aux_storage.sort(tid);
87  _elemental_aux_storage.initialSetup(tid);
88 
90  _elemental_vec_aux_storage.initialSetup(tid);
91 
93  _elemental_array_aux_storage.initialSetup(tid);
94  }
95 }
96 
97 void
99 {
101 
102  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
103  {
105  _nodal_aux_storage.timestepSetup(tid);
106  _mortar_nodal_aux_storage.timestepSetup(tid);
107  _nodal_vec_aux_storage.timestepSetup(tid);
108  _nodal_array_aux_storage.timestepSetup(tid);
109  _elemental_aux_storage.timestepSetup(tid);
110  _elemental_vec_aux_storage.timestepSetup(tid);
111  _elemental_array_aux_storage.timestepSetup(tid);
112  }
113 }
114 
115 void
117 {
118  SystemBase::customSetup(exec_type);
119 
120  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
121  {
122  _aux_scalar_storage.customSetup(exec_type, tid);
123  _nodal_aux_storage.customSetup(exec_type, tid);
124  _mortar_nodal_aux_storage.customSetup(exec_type, tid);
125  _nodal_vec_aux_storage.customSetup(exec_type, tid);
126  _nodal_array_aux_storage.customSetup(exec_type, tid);
127  _elemental_aux_storage.customSetup(exec_type, tid);
128  _elemental_vec_aux_storage.customSetup(exec_type, tid);
129  _elemental_array_aux_storage.customSetup(exec_type, tid);
130  }
131 }
132 
133 void
135 {
137 
138  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
139  {
141  _nodal_aux_storage.subdomainSetup(tid);
142  _mortar_nodal_aux_storage.subdomainSetup(tid);
143  _nodal_vec_aux_storage.subdomainSetup(tid);
144  _nodal_array_aux_storage.subdomainSetup(tid);
145  _elemental_aux_storage.subdomainSetup(tid);
146  _elemental_vec_aux_storage.subdomainSetup(tid);
147  _elemental_array_aux_storage.subdomainSetup(tid);
148  }
149 }
150 
151 void
153 {
155 
156  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
157  {
159  _nodal_aux_storage.jacobianSetup(tid);
160  _mortar_nodal_aux_storage.jacobianSetup(tid);
161  _nodal_vec_aux_storage.jacobianSetup(tid);
162  _nodal_array_aux_storage.jacobianSetup(tid);
163  _elemental_aux_storage.jacobianSetup(tid);
164  _elemental_vec_aux_storage.jacobianSetup(tid);
165  _elemental_array_aux_storage.jacobianSetup(tid);
166  }
167 }
168 
169 void
171 {
173 
174  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
175  {
177  _nodal_aux_storage.residualSetup(tid);
178  _mortar_nodal_aux_storage.residualSetup(tid);
179  _nodal_vec_aux_storage.residualSetup(tid);
180  _nodal_array_aux_storage.residualSetup(tid);
181  _elemental_aux_storage.residualSetup(tid);
182  _elemental_vec_aux_storage.residualSetup(tid);
183  _elemental_array_aux_storage.residualSetup(tid);
184  }
185 }
186 
187 void
189 {
191  _nodal_aux_storage.updateActive(tid);
192  _mortar_nodal_aux_storage.updateActive(tid);
193  _nodal_vec_aux_storage.updateActive(tid);
194  _nodal_array_aux_storage.updateActive(tid);
195  _elemental_aux_storage.updateActive(tid);
196  _elemental_vec_aux_storage.updateActive(tid);
197  _elemental_array_aux_storage.updateActive(tid);
198 }
199 
200 void
201 AuxiliarySystem::addVariable(const std::string & var_type,
202  const std::string & name,
203  InputParameters & parameters)
204 {
205  SystemBase::addVariable(var_type, name, parameters);
206 
207  auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
208  Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
209 
210  if (var_type == "MooseVariableScalar")
211  return;
212 
213  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
214  {
215  if (fe_type.family == LAGRANGE_VEC || fe_type.family == NEDELEC_ONE ||
216  fe_type.family == MONOMIAL_VEC || fe_type.family == RAVIART_THOMAS)
217  {
218  auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
219  if (var)
220  {
221  if (var->feType().family == LAGRANGE_VEC)
222  _nodal_vars[tid].push_back(var);
223  else
224  _elem_vars[tid].push_back(var);
225  }
226  }
227 
228  else
229  {
230  MooseVariableBase * var_base = _vars[tid].getVariable(name);
231 
232  auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
233 
234  if (var)
235  {
236  if (var->feType().family == LAGRANGE)
237  _nodal_vars[tid].push_back(var);
238  else
239  _elem_vars[tid].push_back(var);
240  }
241 
242  auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
243 
244  if (avar)
245  {
246  if (avar->feType().family == LAGRANGE)
247  _nodal_vars[tid].push_back(avar);
248  else
249  _elem_vars[tid].push_back(avar);
250  }
251  }
252  }
253 }
254 
255 void
256 AuxiliarySystem::addTimeIntegrator(const std::string & type,
257  const std::string & name,
258  InputParameters & parameters)
259 {
260  parameters.set<SystemBase *>("_sys") = this;
261  std::shared_ptr<TimeIntegrator> ti = _factory.create<TimeIntegrator>(type, name, parameters);
262  _time_integrator = ti;
263 }
264 
265 void
266 AuxiliarySystem::addKernel(const std::string & kernel_name,
267  const std::string & name,
268  InputParameters & parameters)
269 {
270  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
271  {
272  if (parameters.get<std::string>("_moose_base") == "AuxKernel" ||
273  parameters.get<std::string>("_moose_base") == "Bounds")
274  {
275  std::shared_ptr<AuxKernel> kernel =
276  _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
277  if (kernel->isNodal())
278  {
279  if (kernel->isMortar())
280  _mortar_nodal_aux_storage.addObject(kernel, tid);
281  else
282  _nodal_aux_storage.addObject(kernel, tid);
283  }
284  else
285  _elemental_aux_storage.addObject(kernel, tid);
286  }
287 
288  else if (parameters.get<std::string>("_moose_base") == "VectorAuxKernel")
289  {
290  std::shared_ptr<VectorAuxKernel> kernel =
291  _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
292  if (kernel->isNodal())
293  {
294  if (kernel->isMortar())
295  mooseError("Vector mortar aux kernels not yet implemented");
296  _nodal_vec_aux_storage.addObject(kernel, tid);
297  }
298  else
299  _elemental_vec_aux_storage.addObject(kernel, tid);
300  }
301 
302  else if (parameters.get<std::string>("_moose_base") == "ArrayAuxKernel")
303  {
304  std::shared_ptr<ArrayAuxKernel> kernel =
305  _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
306  if (kernel->isNodal())
307  {
308  if (kernel->isMortar())
309  mooseError("Vector mortar aux kernels not yet implemented");
310  _nodal_array_aux_storage.addObject(kernel, tid);
311  }
312  else
313  _elemental_array_aux_storage.addObject(kernel, tid);
314  }
315  else
316  mooseAssert(false,
317  "Attempting to add AuxKernel of type '" + kernel_name + "' and name '" + name +
318  "' to the auxiliary system with invalid _moose_base: " +
319  parameters.get<std::string>("_moose_base"));
320  }
321 }
322 
323 void
324 AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
325  const std::string & name,
326  InputParameters & parameters)
327 {
328  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
329  {
330  std::shared_ptr<AuxScalarKernel> kernel =
331  _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
332  _aux_scalar_storage.addObject(kernel, tid);
333  }
334 }
335 
336 void
337 AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
338 {
339  for (auto * var : _nodal_vars[tid])
340  var->computeElemValues();
341 
342  for (auto * var : _elem_vars[tid])
343  {
344  var->reinitAux();
345  var->computeElemValues();
346  }
347 }
348 
349 void
350 AuxiliarySystem::reinitElemFace(const Elem * /*elem*/,
351  unsigned int /*side*/,
352  BoundaryID /*bnd_id*/,
353  THREAD_ID tid)
354 {
355  for (auto * var : _nodal_vars[tid])
356  var->computeElemValuesFace();
357 
358  for (auto * var : _elem_vars[tid])
359  {
360  var->reinitAux();
361  var->reinitAuxNeighbor();
362  var->computeElemValuesFace();
363  }
364 }
365 
366 void
368 {
369  if (_serialized_solution.get() &&
370  _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
371  {
372  if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
373  {
374  _serialized_solution->clear();
375  _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
376  }
377 
379  }
380 }
381 
382 void
384 {
385  // avoid division by dt which might be zero.
386  if (_fe_problem.dt() > 0. && _time_integrator)
387  _time_integrator->preStep();
388 
389  // We need to compute time derivatives every time each kind of the variables is finished, because:
390  //
391  // a) the user might want to use the aux variable value somewhere, thus we need to provide the
392  // up-to-date value
393  // b) time integration system works with the whole vectors of solutions, thus we cannot update
394  // only a part of the vector
395  //
396 
397  if (_vars[0].scalars().size() > 0)
398  {
399  computeScalarVars(type);
400  // compute time derivatives of scalar aux variables _after_ the values were updated
401  if (_fe_problem.dt() > 0. && _time_integrator)
402  _time_integrator->computeTimeDerivatives();
403  }
404 
405  if (_vars[0].fieldVariables().size() > 0)
406  {
407  computeNodalArrayVars(type);
408  computeNodalVecVars(type);
409  computeNodalVars(type);
413  computeElementalVars(type);
414 
415  // compute time derivatives of nodal aux variables _after_ the values were updated
416  if (_fe_problem.dt() > 0. && _time_integrator)
417  _time_integrator->computeTimeDerivatives();
418  }
419 
420  if (_serialized_solution.get())
422 }
423 
424 std::set<std::string>
426 {
427  std::set<std::string> depend_objects;
428 
429  // Elemental AuxKernels
430  {
431  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
432  _elemental_aux_storage[type].getActiveObjects();
433  for (const auto & aux : auxs)
434  {
435  const std::set<UserObjectName> & uo = aux->getDependObjects();
436  depend_objects.insert(uo.begin(), uo.end());
437  }
438  }
439 
440  // Elemental VectorAuxKernels
441  {
442  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
443  _elemental_vec_aux_storage[type].getActiveObjects();
444  for (const auto & aux : auxs)
445  {
446  const std::set<UserObjectName> & uo = aux->getDependObjects();
447  depend_objects.insert(uo.begin(), uo.end());
448  }
449  }
450 
451  // Elemental ArrayAuxKernels
452  {
453  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
454  _elemental_array_aux_storage[type].getActiveObjects();
455  for (const auto & aux : auxs)
456  {
457  const std::set<UserObjectName> & uo = aux->getDependObjects();
458  depend_objects.insert(uo.begin(), uo.end());
459  }
460  }
461 
462  // Nodal AuxKernels
463  {
464  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
465  _nodal_aux_storage[type].getActiveObjects();
466  for (const auto & aux : auxs)
467  {
468  const std::set<UserObjectName> & uo = aux->getDependObjects();
469  depend_objects.insert(uo.begin(), uo.end());
470  }
471  }
472 
473  // Mortar Nodal AuxKernels
474  {
475  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
476  _mortar_nodal_aux_storage[type].getActiveObjects();
477  for (const auto & aux : auxs)
478  {
479  const std::set<UserObjectName> & uo = aux->getDependObjects();
480  depend_objects.insert(uo.begin(), uo.end());
481  }
482  }
483 
484  // Nodal VectorAuxKernels
485  {
486  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
487  _nodal_vec_aux_storage[type].getActiveObjects();
488  for (const auto & aux : auxs)
489  {
490  const std::set<UserObjectName> & uo = aux->getDependObjects();
491  depend_objects.insert(uo.begin(), uo.end());
492  }
493  }
494 
495  // Nodal ArrayAuxKernels
496  {
497  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
498  _nodal_array_aux_storage[type].getActiveObjects();
499  for (const auto & aux : auxs)
500  {
501  const std::set<UserObjectName> & uo = aux->getDependObjects();
502  depend_objects.insert(uo.begin(), uo.end());
503  }
504  }
505 
506  return depend_objects;
507 }
508 
509 std::set<std::string>
511 {
512  std::set<std::string> depend_objects;
513 
514  // Elemental AuxKernels
515  {
516  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
517  _elemental_aux_storage.getActiveObjects();
518  for (const auto & aux : auxs)
519  {
520  const std::set<UserObjectName> & uo = aux->getDependObjects();
521  depend_objects.insert(uo.begin(), uo.end());
522  }
523  }
524 
525  // Elemental VectorAuxKernels
526  {
527  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
528  _elemental_vec_aux_storage.getActiveObjects();
529  for (const auto & aux : auxs)
530  {
531  const std::set<UserObjectName> & uo = aux->getDependObjects();
532  depend_objects.insert(uo.begin(), uo.end());
533  }
534  }
535 
536  // Elemental ArrayAuxKernels
537  {
538  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
539  _elemental_array_aux_storage.getActiveObjects();
540  for (const auto & aux : auxs)
541  {
542  const std::set<UserObjectName> & uo = aux->getDependObjects();
543  depend_objects.insert(uo.begin(), uo.end());
544  }
545  }
546 
547  // Nodal AuxKernels
548  {
549  const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
550  for (const auto & aux : auxs)
551  {
552  const std::set<UserObjectName> & uo = aux->getDependObjects();
553  depend_objects.insert(uo.begin(), uo.end());
554  }
555  }
556 
557  // Mortar Nodal AuxKernels
558  {
559  const std::vector<std::shared_ptr<AuxKernel>> & auxs =
560  _mortar_nodal_aux_storage.getActiveObjects();
561  for (const auto & aux : auxs)
562  {
563  const std::set<UserObjectName> & uo = aux->getDependObjects();
564  depend_objects.insert(uo.begin(), uo.end());
565  }
566  }
567 
568  // Nodal VectorAuxKernels
569  {
570  const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
571  _nodal_vec_aux_storage.getActiveObjects();
572  for (const auto & aux : auxs)
573  {
574  const std::set<UserObjectName> & uo = aux->getDependObjects();
575  depend_objects.insert(uo.begin(), uo.end());
576  }
577  }
578 
579  // Nodal ArrayAuxKernels
580  {
581  const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
582  _nodal_array_aux_storage.getActiveObjects();
583  for (const auto & aux : auxs)
584  {
585  const std::set<UserObjectName> & uo = aux->getDependObjects();
586  depend_objects.insert(uo.begin(), uo.end());
587  }
588  }
589 
590  return depend_objects;
591 }
592 
593 void
595 {
597  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
598 
599  std::set<TagID> needed_sc_var_matrix_tags;
600  std::set<TagID> needed_sc_var_vector_tags;
601  for (const auto & obj : objects)
602  {
603  auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
604  needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
605 
606  auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
607  needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
608  }
609 
610  _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
611  _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
612 }
613 
614 void
616 {
619 }
620 
621 void
623 {
625 
626  // Reference to the current storage container
628 
629  if (storage.hasActiveObjects())
630  {
631  TIME_SECTION("computeScalarVars", 1);
632 
633  PARALLEL_TRY
634  {
635  // FIXME: run multi-threaded
636  THREAD_ID tid = 0;
637  if (storage.hasActiveObjects())
638  {
640 
641  const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
642  storage.getActiveObjects(tid);
643 
644  // Call compute() method on all active AuxScalarKernel objects
645  for (const auto & obj : objects)
646  obj->compute();
647 
648  const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
649  for (const auto & var : scalar_vars)
650  var->insert(solution());
651  }
652  }
653  PARALLEL_CATCH;
654 
655  solution().close();
656  _sys.update();
657  }
658 
660 }
661 
662 void
664 {
665  TIME_SECTION("computeNodalVars", 3);
666 
668  computeNodalVarsHelper<AuxKernel>(nodal);
669 }
670 
671 void
673 {
674  TIME_SECTION("computeNodalVecVars", 3);
675 
677  computeNodalVarsHelper<VectorAuxKernel>(nodal);
678 }
679 
680 void
682 {
684  computeNodalVarsHelper<ArrayAuxKernel>(nodal);
685 }
686 
687 void
689 {
690  TIME_SECTION("computeMortarNodalVars", 3);
691 
692  const MooseObjectWarehouse<AuxKernel> & mortar_nodal_warehouse = _mortar_nodal_aux_storage[type];
693 
694  mooseAssert(!mortar_nodal_warehouse.hasActiveBlockObjects(),
695  "We don't allow creation of block restricted mortar nodal aux kernels.");
696 
697  if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
698  {
700  for (const auto & [bnd_id, mortar_nodal_auxes] :
701  mortar_nodal_warehouse.getActiveBoundaryObjects())
702  for (const auto index : index_range(mortar_nodal_auxes))
703  {
704  PARALLEL_TRY
705  {
706  try
707  {
709  _fe_problem, mortar_nodal_warehouse, bnd_id, index);
710  Threads::parallel_reduce(bnd_nodes, mnabt);
711  }
712  catch (libMesh::LogicError & e)
713  {
714  _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
715  "nodal Auxiliary variable computation:\n" +
716  std::string(e.what()));
717  }
718  catch (MooseException & e)
719  {
720  _fe_problem.setException("The following MooseException was raised during mortar nodal "
721  "Auxiliary variable computation:\n" +
722  std::string(e.what()));
723  }
724  catch (MetaPhysicL::LogicError & e)
725  {
727  }
728  }
729  PARALLEL_CATCH;
730 
731  // We need to make sure we propagate exceptions to all processes before trying to close
732  // here, which is a parallel operation
733  solution().close();
734  _sys.update();
735  }
736  }
737 }
738 
739 void
741 {
742  TIME_SECTION("computeElementalVars", 3);
743 
745  computeElementalVarsHelper<AuxKernel>(elemental);
746 }
747 
748 void
750 {
751  TIME_SECTION("computeElementalVecVars", 3);
752 
754  computeElementalVarsHelper<VectorAuxKernel>(elemental);
755 }
756 
757 void
759 {
761  computeElementalVarsHelper<ArrayAuxKernel>(elemental);
762 }
763 
764 void
765 AuxiliarySystem::augmentSparsity(SparsityPattern::Graph & /*sparsity*/,
766  std::vector<dof_id_type> & /*n_nz*/,
767  std::vector<dof_id_type> &
768  /*n_oz*/)
769 {
770 }
771 
772 Order
774 {
775  Order order = CONSTANT;
776  std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
777  for (const auto & var : vars)
778  {
779  if (!var->isNodal()) // nodal aux variables do not need quadrature
780  {
781  FEType fe_type = var->feType();
782  if (fe_type.default_quadrature_order() > order)
783  order = fe_type.default_quadrature_order();
784  }
785  }
786 
787  return order;
788 }
789 
790 bool
792 {
793  return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
794  _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
795 }
796 
797 void
799 {
800  // Evaluate aux variables to get the solution vector
802 }
803 
804 template <typename AuxKernelType>
805 void
807 {
808  if (warehouse.hasActiveBlockObjects())
809  {
810  // Block Elemental AuxKernels
811  PARALLEL_TRY
812  {
815  try
816  {
817  Threads::parallel_reduce(range, eavt);
818  }
819  catch (MooseException & e)
820  {
821  _fe_problem.setException("The following MooseException was raised during elemental "
822  "Auxiliary variable computation:\n" +
823  std::string(e.what()));
824  }
825  }
826  PARALLEL_CATCH;
827 
828  // We need to make sure we propagate exceptions to all processes before trying to close
829  // here, which is a parallel operation
830  solution().close();
831  _sys.update();
832  }
833 
834  // Boundary Elemental AuxKernels
835  if (warehouse.hasActiveBoundaryObjects())
836  {
837  TIME_SECTION("computeElementalVecVars", 3);
838 
839  PARALLEL_TRY
840  {
843  try
844  {
845  Threads::parallel_reduce(bnd_elems, eabt);
846  }
847  catch (MooseException & e)
848  {
849  _fe_problem.setException("The following MooseException was raised during boundary "
850  "elemental Auxiliary variable computation:\n" +
851  std::string(e.what()));
852  }
853  }
854  PARALLEL_CATCH;
855 
856  // We need to make sure we propagate exceptions to all processes before trying to close
857  // here, which is a parallel operation
858  solution().close();
859  _sys.update();
860  }
861 }
862 
863 template <typename AuxKernelType>
864 void
866 {
867  if (warehouse.hasActiveBlockObjects())
868  {
869  // Block Nodal AuxKernels
870  PARALLEL_TRY
871  {
874  Threads::parallel_reduce(range, navt);
875 
876  solution().close();
877  _sys.update();
878  }
879  PARALLEL_CATCH;
880  }
881 
882  if (warehouse.hasActiveBoundaryObjects())
883  {
884  TIME_SECTION("computeBoundaryObjects", 3);
885 
886  // Boundary Nodal AuxKernels
887  PARALLEL_TRY
888  {
891  Threads::parallel_reduce(bnd_nodes, nabt);
892 
893  solution().close();
894  _sys.update();
895  }
896  PARALLEL_CATCH;
897  }
898 }
899 
900 void
902  std::vector<Number> & rel_diff_norms) const
903 {
904  rel_diff_norms.resize(nVariables(), 0);
905  // Get dof map from system
906  const auto & dof_map = _sys.get_dof_map();
907 
908  for (const auto n : make_range(nVariables()))
909  {
910  // Get local indices from dof map for each variable
911  std::vector<dof_id_type> local_indices_n;
912  dof_map.local_variable_indices(local_indices_n, _mesh, n);
913  Number diff_norm_n = 0;
914  Number norm_n = 0;
915  // Get values from system, update norm
916  for (const auto local_index : local_indices_n)
917  {
918  const Number & value = solution()(local_index);
919  const Number & value_old = solutionOld()(local_index);
920  diff_norm_n += Utility::pow<2, Number>(value - value_old);
921  norm_n += Utility::pow<2, Number>(value);
922  }
923  // Aggregate norm over proceccors
924  _communicator.sum(diff_norm_n);
925  _communicator.sum(norm_n);
926  diff_norm_n = sqrt(diff_norm_n);
927  norm_n = sqrt(norm_n);
928  rel_diff_norms[n] = diff_norm_n / norm_n;
929  }
930 }
931 
932 template void
933 AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
934 template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
936 template void
937 AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
938 template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
std::string name(const ElemQuality q)
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
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:1041
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:747
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:182
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Canonical method for adding a variable.
Definition: SystemBase.C:715
virtual void augmentSparsity(SparsityPattern::Graph &, std::vector< dof_id_type > &, std::vector< dof_id_type > &) override
Will modify the sparsity pattern to add logical geometric connections.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
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 translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:110
StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > ConstBndElemRange
Definition: MooseMesh.h:2027
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:1147
AuxiliarySystem(FEProblemBase &subproblem, const std::string &name)
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
ExecuteMooseObjectWarehouse< ArrayAuxKernel > _nodal_array_aux_storage
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition: Factory.C:110
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:957
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void computeElementalVarsHelper(const MooseObjectWarehouse< AuxKernelType > &warehouse)
const Parallel::Communicator & _communicator
Base class for a system (of equations)
Definition: SystemBase.h:85
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:1032
virtual void residualSetup() override
ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:1078
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void computeMortarNodalVars(ExecFlagType type)
MONOMIAL_VEC
MetaPhysicL::DualNumber< V, D, asd > sqrt(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: ADReal.h:35
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition: SystemBase.C:847
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual const std::string & name() const
Definition: SystemBase.C:1293
virtual void jacobianSetup()
Definition: SystemBase.C:1531
void setScalarVariableCoupleableTags(ExecFlagType type)
void addTimeIntegrator(const std::string &type, const std::string &name, InputParameters &parameters) override
Add a time integrator.
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)
void computeElementalVars(ExecFlagType type)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual void setPreviousNewtonSolution()
Base class for making kernels that work on auxiliary scalar variables.
boundary_id_type BoundaryID
virtual void timestepSetup(THREAD_ID tid=0) const
virtual 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:31
StoredRange< MeshBase::const_node_iterator, const Node *> ConstNodeRange
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
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
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:954
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:964
Provides a way for users to bail out of the current solve.
virtual void initialSetup() override
Setup Functions.
RAVIART_THOMAS
Base class for time integrators.
virtual void subdomainSetup()
Definition: SystemBase.C:1517
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:959
bool hasActiveObjects(THREAD_ID tid=0) const
virtual void compute(ExecFlagType type) override
Compute auxiliary variables.
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
Definition: SystemBase.h:1013
IntRange< T > make_range(T beg, T end)
void computeNodalVars(ExecFlagType type)
virtual void customSetup(const ExecFlagType &exec_type)
Definition: SystemBase.C:1510
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a scalar kernel.
virtual void reinitElemFace(const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid) override
Reinit assembly info for a side of an element.
ExecuteMooseObjectWarehouse< AuxKernel > _elemental_aux_storage
virtual void customSetup(const ExecFlagType &exec_type) override
StoredRange< MooseMesh::const_bnd_elem_iterator, const BndElement * > * getBoundaryElementRange()
Definition: MooseMesh.C:1106
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)
NEDELEC_ONE
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:2026
Real Number
void computeElementalArrayVars(ExecFlagType type)
ExecuteMooseObjectWarehouse< VectorAuxKernel > _elemental_vec_aux_storage
NumericVector< Number > & solutionOld()
Definition: SystemBase.h:183
virtual void initialSetup()
Setup Functions.
Definition: SystemBase.C:1483
bool defaultGhosting()
Whether or not the user has requested default ghosting ot be on.
Definition: SubProblem.h:132
virtual Real & dt() const
virtual void residualSetup()
Definition: SystemBase.C:1524
virtual ~AuxiliarySystem()
void residualSetup(THREAD_ID tid=0) const override
virtual void subdomainSetup(THREAD_ID tid=0) const
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:1092
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:198
virtual void subdomainSetup() override
virtual void timestepSetup()
Definition: SystemBase.C:1503
virtual void localize(std::vector< Number > &v_local) const =0