LCOV - code coverage report
Current view: top level - src/systems - AuxiliarySystem.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 420 457 91.9 %
Date: 2025-09-03 20:01:23 Functions: 37 40 92.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      18             : #include "ComputeNodalAuxVarsThread.h"
      19             : #include "ComputeNodalAuxBcsThread.h"
      20             : #include "ComputeElemAuxVarsThread.h"
      21             : #include "ComputeElemAuxBcsThread.h"
      22             : #include "ComputeMortarNodalAuxBndThread.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       63286 : AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
      39             :   : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
      40       63286 :     PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
      41       63286 :     _sys(subproblem.es().add_system<System>(name)),
      42       63286 :     _current_solution(_sys.current_local_solution.get()),
      43       63286 :     _aux_scalar_storage(_app.getExecuteOnEnum()),
      44       63286 :     _nodal_aux_storage(_app.getExecuteOnEnum()),
      45       63286 :     _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
      46       63286 :     _elemental_aux_storage(_app.getExecuteOnEnum()),
      47       63286 :     _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
      48       63286 :     _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
      49       63286 :     _nodal_array_aux_storage(_app.getExecuteOnEnum()),
      50      379716 :     _elemental_array_aux_storage(_app.getExecuteOnEnum())
      51             : {
      52       63286 :   _nodal_vars.resize(libMesh::n_threads());
      53       63286 :   _elem_vars.resize(libMesh::n_threads());
      54             : 
      55       63286 :   if (!_fe_problem.defaultGhosting())
      56             :   {
      57       63204 :     auto & dof_map = _sys.get_dof_map();
      58       63204 :     dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
      59       63204 :     dof_map.set_implicit_neighbor_dofs(false);
      60             :   }
      61       63286 : }
      62             : 
      63       58944 : AuxiliarySystem::~AuxiliarySystem() = default;
      64             : 
      65             : void
      66       60445 : AuxiliarySystem::initialSetup()
      67             : {
      68      302225 :   TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
      69             : 
      70       60445 :   SystemBase::initialSetup();
      71             : 
      72      126437 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
      73             :   {
      74       65996 :     _aux_scalar_storage.sort(tid);
      75       65996 :     _aux_scalar_storage.initialSetup(tid);
      76             : 
      77       65996 :     _nodal_aux_storage.sort(tid);
      78       65996 :     _nodal_aux_storage.initialSetup(tid);
      79             : 
      80       65992 :     _mortar_nodal_aux_storage.sort(tid);
      81       65992 :     _mortar_nodal_aux_storage.initialSetup(tid);
      82             : 
      83       65992 :     _nodal_vec_aux_storage.sort(tid);
      84       65992 :     _nodal_vec_aux_storage.initialSetup(tid);
      85             : 
      86       65992 :     _nodal_array_aux_storage.sort(tid);
      87       65992 :     _nodal_array_aux_storage.initialSetup(tid);
      88             : 
      89       65992 :     _elemental_aux_storage.sort(tid);
      90       65992 :     _elemental_aux_storage.initialSetup(tid);
      91             : 
      92       65992 :     _elemental_vec_aux_storage.sort(tid);
      93       65992 :     _elemental_vec_aux_storage.initialSetup(tid);
      94             : 
      95       65992 :     _elemental_array_aux_storage.sort(tid);
      96       65992 :     _elemental_array_aux_storage.initialSetup(tid);
      97             :   }
      98       60441 : }
      99             : 
     100             : void
     101      285210 : AuxiliarySystem::timestepSetup()
     102             : {
     103      285210 :   SystemBase::timestepSetup();
     104             : 
     105      595763 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     106             :   {
     107      310553 :     _aux_scalar_storage.timestepSetup(tid);
     108      310553 :     _nodal_aux_storage.timestepSetup(tid);
     109      310553 :     _mortar_nodal_aux_storage.timestepSetup(tid);
     110      310553 :     _nodal_vec_aux_storage.timestepSetup(tid);
     111      310553 :     _nodal_array_aux_storage.timestepSetup(tid);
     112      310553 :     _elemental_aux_storage.timestepSetup(tid);
     113      310553 :     _elemental_vec_aux_storage.timestepSetup(tid);
     114      310553 :     _elemental_array_aux_storage.timestepSetup(tid);
     115             :   }
     116      285210 : }
     117             : 
     118             : void
     119     1893227 : AuxiliarySystem::customSetup(const ExecFlagType & exec_type)
     120             : {
     121     1893227 :   SystemBase::customSetup(exec_type);
     122             : 
     123     3956005 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     124             :   {
     125     2062778 :     _aux_scalar_storage.customSetup(exec_type, tid);
     126     2062778 :     _nodal_aux_storage.customSetup(exec_type, tid);
     127     2062778 :     _mortar_nodal_aux_storage.customSetup(exec_type, tid);
     128     2062778 :     _nodal_vec_aux_storage.customSetup(exec_type, tid);
     129     2062778 :     _nodal_array_aux_storage.customSetup(exec_type, tid);
     130     2062778 :     _elemental_aux_storage.customSetup(exec_type, tid);
     131     2062778 :     _elemental_vec_aux_storage.customSetup(exec_type, tid);
     132     2062778 :     _elemental_array_aux_storage.customSetup(exec_type, tid);
     133             :   }
     134     1893227 : }
     135             : 
     136             : void
     137           0 : AuxiliarySystem::subdomainSetup()
     138             : {
     139           0 :   SystemBase::subdomainSetup();
     140             : 
     141           0 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     142             :   {
     143           0 :     _aux_scalar_storage.subdomainSetup(tid);
     144           0 :     _nodal_aux_storage.subdomainSetup(tid);
     145           0 :     _mortar_nodal_aux_storage.subdomainSetup(tid);
     146           0 :     _nodal_vec_aux_storage.subdomainSetup(tid);
     147           0 :     _nodal_array_aux_storage.subdomainSetup(tid);
     148           0 :     _elemental_aux_storage.subdomainSetup(tid);
     149           0 :     _elemental_vec_aux_storage.subdomainSetup(tid);
     150           0 :     _elemental_array_aux_storage.subdomainSetup(tid);
     151             :   }
     152           0 : }
     153             : 
     154             : void
     155      525431 : AuxiliarySystem::jacobianSetup()
     156             : {
     157      525431 :   SystemBase::jacobianSetup();
     158             : 
     159     1098936 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     160             :   {
     161      573505 :     _aux_scalar_storage.jacobianSetup(tid);
     162      573505 :     _nodal_aux_storage.jacobianSetup(tid);
     163      573505 :     _mortar_nodal_aux_storage.jacobianSetup(tid);
     164      573505 :     _nodal_vec_aux_storage.jacobianSetup(tid);
     165      573505 :     _nodal_array_aux_storage.jacobianSetup(tid);
     166      573505 :     _elemental_aux_storage.jacobianSetup(tid);
     167      573505 :     _elemental_vec_aux_storage.jacobianSetup(tid);
     168      573505 :     _elemental_array_aux_storage.jacobianSetup(tid);
     169             :   }
     170      525431 : }
     171             : 
     172             : void
     173     3297552 : AuxiliarySystem::residualSetup()
     174             : {
     175     3297552 :   SystemBase::residualSetup();
     176             : 
     177     6891216 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     178             :   {
     179     3593664 :     _aux_scalar_storage.residualSetup(tid);
     180     3593664 :     _nodal_aux_storage.residualSetup(tid);
     181     3593664 :     _mortar_nodal_aux_storage.residualSetup(tid);
     182     3593664 :     _nodal_vec_aux_storage.residualSetup(tid);
     183     3593664 :     _nodal_array_aux_storage.residualSetup(tid);
     184     3593664 :     _elemental_aux_storage.residualSetup(tid);
     185     3593664 :     _elemental_vec_aux_storage.residualSetup(tid);
     186     3593664 :     _elemental_array_aux_storage.residualSetup(tid);
     187             :   }
     188     3297552 : }
     189             : 
     190             : void
     191      363443 : AuxiliarySystem::updateActive(THREAD_ID tid)
     192             : {
     193      363443 :   _aux_scalar_storage.updateActive(tid);
     194      363443 :   _nodal_aux_storage.updateActive(tid);
     195      363443 :   _mortar_nodal_aux_storage.updateActive(tid);
     196      363443 :   _nodal_vec_aux_storage.updateActive(tid);
     197      363443 :   _nodal_array_aux_storage.updateActive(tid);
     198      363443 :   _elemental_aux_storage.updateActive(tid);
     199      363443 :   _elemental_vec_aux_storage.updateActive(tid);
     200      363443 :   _elemental_array_aux_storage.updateActive(tid);
     201      363443 : }
     202             : 
     203             : void
     204       95421 : AuxiliarySystem::addVariable(const std::string & var_type,
     205             :                              const std::string & name,
     206             :                              InputParameters & parameters)
     207             : {
     208       95421 :   SystemBase::addVariable(var_type, name, parameters);
     209             : 
     210      190842 :   auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
     211      286263 :                         Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
     212             : 
     213       95421 :   if (var_type == "MooseVariableScalar")
     214        1805 :     return;
     215             : 
     216      195901 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     217             :   {
     218      102285 :     if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
     219             :     {
     220         393 :       auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
     221         393 :       if (var)
     222             :       {
     223         393 :         if (var->feType().family == LAGRANGE_VEC)
     224         140 :           _nodal_vars[tid].push_back(var);
     225             :         else
     226         253 :           _elem_vars[tid].push_back(var);
     227             :       }
     228             :     }
     229             : 
     230             :     else
     231             :     {
     232      101892 :       MooseVariableBase * var_base = _vars[tid].getVariable(name);
     233             : 
     234      101892 :       auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
     235             : 
     236      101892 :       if (var)
     237             :       {
     238      100682 :         if (var->feType().family == LAGRANGE)
     239       35857 :           _nodal_vars[tid].push_back(var);
     240             :         else
     241       64825 :           _elem_vars[tid].push_back(var);
     242             :       }
     243             : 
     244      101892 :       auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
     245             : 
     246      101892 :       if (avar)
     247             :       {
     248        1210 :         if (avar->feType().family == LAGRANGE)
     249         546 :           _nodal_vars[tid].push_back(avar);
     250             :         else
     251         664 :           _elem_vars[tid].push_back(avar);
     252             :       }
     253             :     }
     254             :   }
     255             : }
     256             : 
     257             : void
     258       67999 : AuxiliarySystem::addKernel(const std::string & kernel_name,
     259             :                            const std::string & name,
     260             :                            InputParameters & parameters)
     261             : {
     262      141732 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     263             :   {
     264       73881 :     const auto & base = parameters.getBase();
     265       73881 :     if (base == "AuxKernel" || base == "Bounds")
     266             :     {
     267             :       std::shared_ptr<AuxKernel> kernel =
     268       73473 :           _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
     269       73349 :       if (kernel->isNodal())
     270             :       {
     271       23739 :         if (kernel->isMortar())
     272          84 :           _mortar_nodal_aux_storage.addObject(kernel, tid);
     273             :         else
     274       23655 :           _nodal_aux_storage.addObject(kernel, tid);
     275             :       }
     276             :       else
     277       49610 :         _elemental_aux_storage.addObject(kernel, tid);
     278       73345 :     }
     279             : 
     280         408 :     else if (base == "VectorAuxKernel")
     281             :     {
     282             :       std::shared_ptr<VectorAuxKernel> kernel =
     283         220 :           _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
     284         220 :       if (kernel->isNodal())
     285             :       {
     286          56 :         if (kernel->isMortar())
     287           0 :           mooseError("Vector mortar aux kernels not yet implemented");
     288          56 :         _nodal_vec_aux_storage.addObject(kernel, tid);
     289             :       }
     290             :       else
     291         164 :         _elemental_vec_aux_storage.addObject(kernel, tid);
     292         220 :     }
     293             : 
     294         188 :     else if (base == "ArrayAuxKernel")
     295             :     {
     296             :       std::shared_ptr<ArrayAuxKernel> kernel =
     297         188 :           _factory.create<ArrayAuxKernel>(kernel_name, name, parameters, tid);
     298         168 :       if (kernel->isNodal())
     299             :       {
     300          98 :         if (kernel->isMortar())
     301           0 :           mooseError("Vector mortar aux kernels not yet implemented");
     302          98 :         _nodal_array_aux_storage.addObject(kernel, tid);
     303             :       }
     304             :       else
     305          70 :         _elemental_array_aux_storage.addObject(kernel, tid);
     306         168 :     }
     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       67851 : }
     313             : 
     314             : void
     315         537 : AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
     316             :                                  const std::string & name,
     317             :                                  InputParameters & parameters)
     318             : {
     319        1113 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     320             :   {
     321             :     std::shared_ptr<AuxScalarKernel> kernel =
     322         580 :         _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
     323         576 :     _aux_scalar_storage.addObject(kernel, tid);
     324         576 :   }
     325         533 : }
     326             : 
     327             : void
     328   429443542 : AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
     329             : {
     330   589071435 :   for (auto * var : _nodal_vars[tid])
     331   159627893 :     var->computeElemValues();
     332             : 
     333   589944419 :   for (auto * var : _elem_vars[tid])
     334             :   {
     335   160500877 :     var->reinitAux();
     336   160500877 :     var->computeElemValues();
     337             :   }
     338   429443542 : }
     339             : 
     340             : void
     341    12737000 : AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
     342             : {
     343    15359694 :   for (auto * var : _nodal_vars[tid])
     344     2622694 :     var->computeElemValuesFace();
     345             : 
     346    18867476 :   for (auto * var : _elem_vars[tid])
     347             :   {
     348     6130476 :     var->reinitAux();
     349     6130476 :     var->reinitAuxNeighbor();
     350     6130476 :     var->computeElemValuesFace();
     351             :   }
     352    12737000 : }
     353             : 
     354             : void
     355        2269 : AuxiliarySystem::serializeSolution()
     356             : {
     357        4538 :   if (_serialized_solution.get() &&
     358        2269 :       _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
     359             :   {
     360        2269 :     if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
     361             :     {
     362          63 :       _serialized_solution->clear();
     363          63 :       _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
     364             :     }
     365             : 
     366        2269 :     solution().localize(*_serialized_solution);
     367             :   }
     368        2269 : }
     369             : 
     370             : void
     371     6270607 : AuxiliarySystem::compute(ExecFlagType type)
     372             : {
     373             :   // avoid division by dt which might be zero.
     374     6270607 :   if (_fe_problem.dt() > 0.)
     375    10833735 :     for (auto & ti : _time_integrators)
     376     5406639 :       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     6270607 :   if (_vars[0].scalars().size() > 0)
     387             :   {
     388       56031 :     computeScalarVars(type);
     389             :     // compute time derivatives of scalar aux variables _after_ the values were updated
     390       56031 :     if (_fe_problem.dt() > 0.)
     391       88162 :       for (auto & ti : _time_integrators)
     392       44081 :         ti->computeTimeDerivatives();
     393             :   }
     394             : 
     395     6270607 :   if (_vars[0].fieldVariables().size() > 0)
     396             :   {
     397     2167792 :     computeNodalArrayVars(type);
     398     2167792 :     computeNodalVecVars(type);
     399     2167792 :     computeNodalVars(type);
     400     2167788 :     computeMortarNodalVars(type);
     401     2167788 :     computeElementalArrayVars(type);
     402     2167788 :     computeElementalVecVars(type);
     403     2167788 :     computeElementalVars(type);
     404             : 
     405             :     // compute time derivatives of nodal aux variables _after_ the values were updated
     406     2167747 :     if (_fe_problem.dt() > 0.)
     407     3751224 :       for (auto & ti : _time_integrators)
     408     1857616 :         ti->computeTimeDerivatives();
     409             :   }
     410             : 
     411     6270562 :   if (_serialized_solution.get())
     412        2269 :     serializeSolution();
     413     6270562 : }
     414             : 
     415             : std::set<std::string>
     416     1636756 : AuxiliarySystem::getDependObjects(ExecFlagType type)
     417             : {
     418     1636756 :   std::set<std::string> depend_objects;
     419             : 
     420             :   // Elemental AuxKernels
     421             :   {
     422             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     423     1636756 :         _elemental_aux_storage[type].getActiveObjects();
     424     1719772 :     for (const auto & aux : auxs)
     425             :     {
     426       83016 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     427       83016 :       depend_objects.insert(uo.begin(), uo.end());
     428             :     }
     429             :   }
     430             : 
     431             :   // Elemental VectorAuxKernels
     432             :   {
     433             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     434     1636756 :         _elemental_vec_aux_storage[type].getActiveObjects();
     435     1637051 :     for (const auto & aux : auxs)
     436             :     {
     437         295 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     438         295 :       depend_objects.insert(uo.begin(), uo.end());
     439             :     }
     440             :   }
     441             : 
     442             :   // Elemental ArrayAuxKernels
     443             :   {
     444             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     445     1636756 :         _elemental_array_aux_storage[type].getActiveObjects();
     446     1636860 :     for (const auto & aux : auxs)
     447             :     {
     448         104 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     449         104 :       depend_objects.insert(uo.begin(), uo.end());
     450             :     }
     451             :   }
     452             : 
     453             :   // Nodal AuxKernels
     454             :   {
     455             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     456     1636756 :         _nodal_aux_storage[type].getActiveObjects();
     457     1678344 :     for (const auto & aux : auxs)
     458             :     {
     459       41588 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     460       41588 :       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     1636756 :         _mortar_nodal_aux_storage[type].getActiveObjects();
     468     1636912 :     for (const auto & aux : auxs)
     469             :     {
     470         156 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     471         156 :       depend_objects.insert(uo.begin(), uo.end());
     472             :     }
     473             :   }
     474             : 
     475             :   // Nodal VectorAuxKernels
     476             :   {
     477             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     478     1636756 :         _nodal_vec_aux_storage[type].getActiveObjects();
     479     1636847 :     for (const auto & aux : auxs)
     480             :     {
     481          91 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     482          91 :       depend_objects.insert(uo.begin(), uo.end());
     483             :     }
     484             :   }
     485             : 
     486             :   // Nodal ArrayAuxKernels
     487             :   {
     488             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     489     1636756 :         _nodal_array_aux_storage[type].getActiveObjects();
     490     1636912 :     for (const auto & aux : auxs)
     491             :     {
     492         156 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     493         156 :       depend_objects.insert(uo.begin(), uo.end());
     494             :     }
     495             :   }
     496             : 
     497     1636756 :   return depend_objects;
     498           0 : }
     499             : 
     500             : std::set<std::string>
     501       60621 : AuxiliarySystem::getDependObjects()
     502             : {
     503       60621 :   std::set<std::string> depend_objects;
     504             : 
     505             :   // Elemental AuxKernels
     506             :   {
     507             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     508       60621 :         _elemental_aux_storage.getActiveObjects();
     509      104324 :     for (const auto & aux : auxs)
     510             :     {
     511       43703 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     512       43703 :       depend_objects.insert(uo.begin(), uo.end());
     513             :     }
     514             :   }
     515             : 
     516             :   // Elemental VectorAuxKernels
     517             :   {
     518             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     519       60621 :         _elemental_vec_aux_storage.getActiveObjects();
     520       60775 :     for (const auto & aux : auxs)
     521             :     {
     522         154 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     523         154 :       depend_objects.insert(uo.begin(), uo.end());
     524             :     }
     525             :   }
     526             : 
     527             :   // Elemental ArrayAuxKernels
     528             :   {
     529             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     530       60621 :         _elemental_array_aux_storage.getActiveObjects();
     531       60686 :     for (const auto & aux : auxs)
     532             :     {
     533          65 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     534          65 :       depend_objects.insert(uo.begin(), uo.end());
     535             :     }
     536             :   }
     537             : 
     538             :   // Nodal AuxKernels
     539             :   {
     540       60621 :     const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
     541       82428 :     for (const auto & aux : auxs)
     542             :     {
     543       21807 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     544       21807 :       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       60621 :         _mortar_nodal_aux_storage.getActiveObjects();
     552       60699 :     for (const auto & aux : auxs)
     553             :     {
     554          78 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     555          78 :       depend_objects.insert(uo.begin(), uo.end());
     556             :     }
     557             :   }
     558             : 
     559             :   // Nodal VectorAuxKernels
     560             :   {
     561             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     562       60621 :         _nodal_vec_aux_storage.getActiveObjects();
     563       60673 :     for (const auto & aux : auxs)
     564             :     {
     565          52 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     566          52 :       depend_objects.insert(uo.begin(), uo.end());
     567             :     }
     568             :   }
     569             : 
     570             :   // Nodal ArrayAuxKernels
     571             :   {
     572             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     573       60621 :         _nodal_array_aux_storage.getActiveObjects();
     574       60712 :     for (const auto & aux : auxs)
     575             :     {
     576          91 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     577          91 :       depend_objects.insert(uo.begin(), uo.end());
     578             :     }
     579             :   }
     580             : 
     581       60621 :   return depend_objects;
     582           0 : }
     583             : 
     584             : void
     585       56031 : AuxiliarySystem::setScalarVariableCoupleableTags(ExecFlagType type)
     586             : {
     587       56031 :   const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
     588       56031 :   const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
     589             : 
     590       56031 :   std::set<TagID> needed_sc_var_matrix_tags;
     591       56031 :   std::set<TagID> needed_sc_var_vector_tags;
     592       75911 :   for (const auto & obj : objects)
     593             :   {
     594       19880 :     auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
     595       19880 :     needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
     596             : 
     597       19880 :     auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
     598       19880 :     needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
     599             :   }
     600             : 
     601       56031 :   _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
     602       56031 :   _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
     603       56031 : }
     604             : 
     605             : void
     606       56031 : AuxiliarySystem::clearScalarVariableCoupleableTags()
     607             : {
     608       56031 :   _fe_problem.clearActiveScalarVariableCoupleableMatrixTags(0);
     609       56031 :   _fe_problem.clearActiveScalarVariableCoupleableVectorTags(0);
     610       56031 : }
     611             : 
     612             : void
     613       56031 : AuxiliarySystem::computeScalarVars(ExecFlagType type)
     614             : {
     615       56031 :   setScalarVariableCoupleableTags(type);
     616             : 
     617             :   // Reference to the current storage container
     618       56031 :   const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
     619             : 
     620       56031 :   if (storage.hasActiveObjects())
     621             :   {
     622       54489 :     TIME_SECTION("computeScalarVars", 1);
     623             : 
     624             :     PARALLEL_TRY
     625             :     {
     626             :       // FIXME: run multi-threaded
     627       18163 :       THREAD_ID tid = 0;
     628       18163 :       if (storage.hasActiveObjects())
     629             :       {
     630       18163 :         _fe_problem.reinitScalars(tid);
     631             : 
     632             :         const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
     633       18163 :             storage.getActiveObjects(tid);
     634             : 
     635             :         // Call compute() method on all active AuxScalarKernel objects
     636       38043 :         for (const auto & obj : objects)
     637       19880 :           obj->compute();
     638             : 
     639       18163 :         const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
     640       56490 :         for (const auto & var : scalar_vars)
     641       38327 :           var->insert(solution());
     642             :       }
     643             :     }
     644       18163 :     PARALLEL_CATCH;
     645             : 
     646       18163 :     solution().close();
     647       18163 :     _sys.update();
     648       18163 :   }
     649             : 
     650       56031 :   clearScalarVariableCoupleableTags();
     651       56031 : }
     652             : 
     653             : void
     654     2167792 : AuxiliarySystem::computeNodalVars(ExecFlagType type)
     655             : {
     656     6503376 :   TIME_SECTION("computeNodalVars", 3);
     657             : 
     658     2167792 :   const MooseObjectWarehouse<AuxKernel> & nodal = _nodal_aux_storage[type];
     659     2167792 :   computeNodalVarsHelper<AuxKernel>(nodal);
     660     2167788 : }
     661             : 
     662             : void
     663     2167792 : AuxiliarySystem::computeNodalVecVars(ExecFlagType type)
     664             : {
     665     6503376 :   TIME_SECTION("computeNodalVecVars", 3);
     666             : 
     667     2167792 :   const MooseObjectWarehouse<VectorAuxKernel> & nodal = _nodal_vec_aux_storage[type];
     668     2167792 :   computeNodalVarsHelper<VectorAuxKernel>(nodal);
     669     2167792 : }
     670             : 
     671             : void
     672     2167792 : AuxiliarySystem::computeNodalArrayVars(ExecFlagType type)
     673             : {
     674     2167792 :   const MooseObjectWarehouse<ArrayAuxKernel> & nodal = _nodal_array_aux_storage[type];
     675     2167792 :   computeNodalVarsHelper<ArrayAuxKernel>(nodal);
     676     2167792 : }
     677             : 
     678             : void
     679     2167788 : AuxiliarySystem::computeMortarNodalVars(const ExecFlagType type)
     680             : {
     681     6503364 :   TIME_SECTION("computeMortarNodalVars", 3);
     682             : 
     683     2167788 :   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     2167788 :   if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
     689             :   {
     690         186 :     ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
     691         372 :     for (const auto & [bnd_id, mortar_nodal_auxes] :
     692         558 :          mortar_nodal_warehouse.getActiveBoundaryObjects())
     693         372 :       for (const auto index : index_range(mortar_nodal_auxes))
     694             :       {
     695             :         PARALLEL_TRY
     696             :         {
     697             :           try
     698             :           {
     699             :             ComputeMortarNodalAuxBndThread<AuxKernel> mnabt(
     700         186 :                 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
     701         186 :             Threads::parallel_reduce(bnd_nodes, mnabt);
     702         186 :           }
     703           0 :           catch (libMesh::LogicError & e)
     704             :           {
     705           0 :             _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
     706           0 :                                      "nodal Auxiliary variable computation:\n" +
     707           0 :                                      std::string(e.what()));
     708           0 :           }
     709           0 :           catch (MooseException & e)
     710             :           {
     711           0 :             _fe_problem.setException("The following MooseException was raised during mortar nodal "
     712           0 :                                      "Auxiliary variable computation:\n" +
     713           0 :                                      std::string(e.what()));
     714           0 :           }
     715           0 :           catch (MetaPhysicL::LogicError & e)
     716             :           {
     717           0 :             moose::translateMetaPhysicLError(e);
     718           0 :           }
     719             :         }
     720         186 :         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         186 :         solution().close();
     725         186 :         _sys.update();
     726             :       }
     727             :   }
     728     2167788 : }
     729             : 
     730             : void
     731     2167788 : AuxiliarySystem::computeElementalVars(ExecFlagType type)
     732             : {
     733     6503364 :   TIME_SECTION("computeElementalVars", 3);
     734             : 
     735     2167788 :   const MooseObjectWarehouse<AuxKernel> & elemental = _elemental_aux_storage[type];
     736     2167788 :   computeElementalVarsHelper<AuxKernel>(elemental);
     737     2167747 : }
     738             : 
     739             : void
     740     2167788 : AuxiliarySystem::computeElementalVecVars(ExecFlagType type)
     741             : {
     742     6503364 :   TIME_SECTION("computeElementalVecVars", 3);
     743             : 
     744     2167788 :   const MooseObjectWarehouse<VectorAuxKernel> & elemental = _elemental_vec_aux_storage[type];
     745     2167788 :   computeElementalVarsHelper<VectorAuxKernel>(elemental);
     746     2167788 : }
     747             : 
     748             : void
     749     2167788 : AuxiliarySystem::computeElementalArrayVars(ExecFlagType type)
     750             : {
     751     2167788 :   const MooseObjectWarehouse<ArrayAuxKernel> & elemental = _elemental_array_aux_storage[type];
     752     2167788 :   computeElementalVarsHelper<ArrayAuxKernel>(elemental);
     753     2167788 : }
     754             : 
     755             : void
     756           0 : AuxiliarySystem::augmentSparsity(SparsityPattern::Graph & /*sparsity*/,
     757             :                                  std::vector<dof_id_type> & /*n_nz*/,
     758             :                                  std::vector<dof_id_type> &
     759             :                                  /*n_oz*/)
     760             : {
     761           0 : }
     762             : 
     763             : Order
     764       67886 : AuxiliarySystem::getMinQuadratureOrder()
     765             : {
     766       67886 :   Order order = CONSTANT;
     767       67886 :   std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
     768      148671 :   for (const auto & var : vars)
     769             :   {
     770       80785 :     if (!var->isNodal()) // nodal aux variables do not need quadrature
     771             :     {
     772       41269 :       FEType fe_type = var->feType();
     773       41269 :       if (fe_type.default_quadrature_order() > order)
     774       21085 :         order = fe_type.default_quadrature_order();
     775             :     }
     776             :   }
     777             : 
     778       67886 :   return order;
     779       67886 : }
     780             : 
     781             : bool
     782       29800 : AuxiliarySystem::needMaterialOnSide(BoundaryID bnd_id)
     783             : {
     784       59023 :   return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
     785       59023 :          _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
     786             : }
     787             : 
     788             : void
     789         556 : AuxiliarySystem::copyCurrentIntoPreviousNL()
     790             : {
     791         556 :   if (solutionPreviousNewton())
     792         556 :     *solutionPreviousNewton() = *currentSolution();
     793         556 : }
     794             : 
     795             : template <typename AuxKernelType>
     796             : void
     797     6503364 : AuxiliarySystem::computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
     798             : {
     799     6503364 :   if (warehouse.hasActiveBlockObjects())
     800             :   {
     801             :     // Block Elemental AuxKernels
     802             :     PARALLEL_TRY
     803             :     {
     804       80488 :       ConstElemRange & range = *_mesh.getActiveLocalElementRange();
     805       80488 :       ComputeElemAuxVarsThread<AuxKernelType> eavt(_fe_problem, warehouse, true);
     806             :       try
     807             :       {
     808       80488 :         Threads::parallel_reduce(range, eavt);
     809             :       }
     810           0 :       catch (MooseException & e)
     811             :       {
     812           0 :         _fe_problem.setException("The following MooseException was raised during elemental "
     813             :                                  "Auxiliary variable computation:\n" +
     814           0 :                                  std::string(e.what()));
     815             :       }
     816       80455 :     }
     817       80455 :     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       80455 :     solution().close();
     822       80455 :     _sys.update();
     823             :   }
     824             : 
     825             :   // Boundary Elemental AuxKernels
     826     6503331 :   if (warehouse.hasActiveBoundaryObjects())
     827             :   {
     828       81069 :     TIME_SECTION("computeElementalVecVars", 3);
     829             : 
     830             :     PARALLEL_TRY
     831             :     {
     832       27023 :       ConstBndElemRange & bnd_elems = *_mesh.getBoundaryElementRange();
     833       27023 :       ComputeElemAuxBcsThread<AuxKernelType> eabt(_fe_problem, warehouse, true);
     834             :       try
     835             :       {
     836       27023 :         Threads::parallel_reduce(bnd_elems, eabt);
     837             :       }
     838           0 :       catch (MooseException & e)
     839             :       {
     840           0 :         _fe_problem.setException("The following MooseException was raised during boundary "
     841             :                                  "elemental Auxiliary variable computation:\n" +
     842           0 :                                  std::string(e.what()));
     843             :       }
     844       27015 :     }
     845       27015 :     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       27015 :     solution().close();
     850       27015 :     _sys.update();
     851       27015 :   }
     852     6503323 : }
     853             : 
     854             : template <typename AuxKernelType>
     855             : void
     856     6503376 : AuxiliarySystem::computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
     857             : {
     858     6503376 :   if (warehouse.hasActiveBlockObjects())
     859             :   {
     860             :     // Block Nodal AuxKernels
     861             :     PARALLEL_TRY
     862             :     {
     863      147645 :       ConstNodeRange & range = *_mesh.getLocalNodeRange();
     864      147645 :       ComputeNodalAuxVarsThread<AuxKernelType> navt(_fe_problem, warehouse);
     865      147645 :       Threads::parallel_reduce(range, navt);
     866             : 
     867      147641 :       solution().close();
     868      147641 :       _sys.update();
     869      147641 :     }
     870      147641 :     PARALLEL_CATCH;
     871             :   }
     872             : 
     873     6503372 :   if (warehouse.hasActiveBoundaryObjects())
     874             :   {
     875      275919 :     TIME_SECTION("computeBoundaryObjects", 3);
     876             : 
     877             :     // Boundary Nodal AuxKernels
     878             :     PARALLEL_TRY
     879             :     {
     880       91973 :       ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
     881       91973 :       ComputeNodalAuxBcsThread<AuxKernelType> nabt(_fe_problem, warehouse);
     882       91973 :       Threads::parallel_reduce(bnd_nodes, nabt);
     883             : 
     884       91973 :       solution().close();
     885       91973 :       _sys.update();
     886       91973 :     }
     887       91973 :     PARALLEL_CATCH;
     888       91973 :   }
     889     6503372 : }
     890             : 
     891             : void
     892         553 : AuxiliarySystem::variableWiseRelativeSolutionDifferenceNorm(
     893             :     std::vector<Number> & rel_diff_norms) const
     894             : {
     895         553 :   rel_diff_norms.resize(nVariables(), 0);
     896             :   // Get dof map from system
     897         553 :   const auto & dof_map = _sys.get_dof_map();
     898             : 
     899        1659 :   for (const auto n : make_range(nVariables()))
     900             :   {
     901             :     // Get local indices from dof map for each variable
     902        1106 :     std::vector<dof_id_type> local_indices_n;
     903        1106 :     dof_map.local_variable_indices(local_indices_n, _mesh, n);
     904        1106 :     Number diff_norm_n = 0;
     905        1106 :     Number norm_n = 0;
     906             :     // Get values from system, update norm
     907      101536 :     for (const auto local_index : local_indices_n)
     908             :     {
     909      100430 :       const Number & value = solution()(local_index);
     910      100430 :       const Number & value_old = solutionOld()(local_index);
     911      100430 :       diff_norm_n += Utility::pow<2, Number>(value - value_old);
     912      100430 :       norm_n += Utility::pow<2, Number>(value);
     913             :     }
     914             :     // Aggregate norm over proceccors
     915        1106 :     _communicator.sum(diff_norm_n);
     916        1106 :     _communicator.sum(norm_n);
     917        1106 :     diff_norm_n = sqrt(diff_norm_n);
     918        1106 :     norm_n = sqrt(norm_n);
     919        1106 :     rel_diff_norms[n] = diff_norm_n / norm_n;
     920        1106 :   }
     921         553 : }
     922             : 
     923             : template void
     924             : AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
     925             : template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
     926             :     const MooseObjectWarehouse<VectorAuxKernel> &);
     927             : template void
     928             : AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
     929             : template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
     930             :     const MooseObjectWarehouse<VectorAuxKernel> &);

Generated by: LCOV version 1.14