LCOV - code coverage report
Current view: top level - src/systems - AuxiliarySystem.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 420 457 91.9 %
Date: 2025-08-08 20:01:16 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       62553 : AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name)
      39             :   : SystemBase(subproblem, subproblem, name, Moose::VAR_AUXILIARY),
      40       62553 :     PerfGraphInterface(subproblem.getMooseApp().perfGraph(), "AuxiliarySystem"),
      41       62553 :     _sys(subproblem.es().add_system<System>(name)),
      42       62553 :     _current_solution(_sys.current_local_solution.get()),
      43       62553 :     _aux_scalar_storage(_app.getExecuteOnEnum()),
      44       62553 :     _nodal_aux_storage(_app.getExecuteOnEnum()),
      45       62553 :     _mortar_nodal_aux_storage(_app.getExecuteOnEnum()),
      46       62553 :     _elemental_aux_storage(_app.getExecuteOnEnum()),
      47       62553 :     _nodal_vec_aux_storage(_app.getExecuteOnEnum()),
      48       62553 :     _elemental_vec_aux_storage(_app.getExecuteOnEnum()),
      49       62553 :     _nodal_array_aux_storage(_app.getExecuteOnEnum()),
      50      250212 :     _elemental_array_aux_storage(_app.getExecuteOnEnum())
      51             : {
      52       62553 :   _nodal_vars.resize(libMesh::n_threads());
      53       62553 :   _elem_vars.resize(libMesh::n_threads());
      54             : 
      55       62553 :   if (!_fe_problem.defaultGhosting())
      56             :   {
      57       62471 :     auto & dof_map = _sys.get_dof_map();
      58       62471 :     dof_map.remove_algebraic_ghosting_functor(dof_map.default_algebraic_ghosting());
      59       62471 :     dof_map.set_implicit_neighbor_dofs(false);
      60             :   }
      61       62553 : }
      62             : 
      63       58253 : AuxiliarySystem::~AuxiliarySystem() = default;
      64             : 
      65             : void
      66       59733 : AuxiliarySystem::initialSetup()
      67             : {
      68       59733 :   TIME_SECTION("initialSetup", 3, "Initializing Auxiliary System");
      69             : 
      70       59733 :   SystemBase::initialSetup();
      71             : 
      72      124945 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
      73             :   {
      74       65216 :     _aux_scalar_storage.sort(tid);
      75       65216 :     _aux_scalar_storage.initialSetup(tid);
      76             : 
      77       65216 :     _nodal_aux_storage.sort(tid);
      78       65216 :     _nodal_aux_storage.initialSetup(tid);
      79             : 
      80       65212 :     _mortar_nodal_aux_storage.sort(tid);
      81       65212 :     _mortar_nodal_aux_storage.initialSetup(tid);
      82             : 
      83       65212 :     _nodal_vec_aux_storage.sort(tid);
      84       65212 :     _nodal_vec_aux_storage.initialSetup(tid);
      85             : 
      86       65212 :     _nodal_array_aux_storage.sort(tid);
      87       65212 :     _nodal_array_aux_storage.initialSetup(tid);
      88             : 
      89       65212 :     _elemental_aux_storage.sort(tid);
      90       65212 :     _elemental_aux_storage.initialSetup(tid);
      91             : 
      92       65212 :     _elemental_vec_aux_storage.sort(tid);
      93       65212 :     _elemental_vec_aux_storage.initialSetup(tid);
      94             : 
      95       65212 :     _elemental_array_aux_storage.sort(tid);
      96       65212 :     _elemental_array_aux_storage.initialSetup(tid);
      97             :   }
      98       59729 : }
      99             : 
     100             : void
     101      283095 : AuxiliarySystem::timestepSetup()
     102             : {
     103      283095 :   SystemBase::timestepSetup();
     104             : 
     105      591321 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     106             :   {
     107      308226 :     _aux_scalar_storage.timestepSetup(tid);
     108      308226 :     _nodal_aux_storage.timestepSetup(tid);
     109      308226 :     _mortar_nodal_aux_storage.timestepSetup(tid);
     110      308226 :     _nodal_vec_aux_storage.timestepSetup(tid);
     111      308226 :     _nodal_array_aux_storage.timestepSetup(tid);
     112      308226 :     _elemental_aux_storage.timestepSetup(tid);
     113      308226 :     _elemental_vec_aux_storage.timestepSetup(tid);
     114      308226 :     _elemental_array_aux_storage.timestepSetup(tid);
     115             :   }
     116      283095 : }
     117             : 
     118             : void
     119     1881224 : AuxiliarySystem::customSetup(const ExecFlagType & exec_type)
     120             : {
     121     1881224 :   SystemBase::customSetup(exec_type);
     122             : 
     123     3930934 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     124             :   {
     125     2049710 :     _aux_scalar_storage.customSetup(exec_type, tid);
     126     2049710 :     _nodal_aux_storage.customSetup(exec_type, tid);
     127     2049710 :     _mortar_nodal_aux_storage.customSetup(exec_type, tid);
     128     2049710 :     _nodal_vec_aux_storage.customSetup(exec_type, tid);
     129     2049710 :     _nodal_array_aux_storage.customSetup(exec_type, tid);
     130     2049710 :     _elemental_aux_storage.customSetup(exec_type, tid);
     131     2049710 :     _elemental_vec_aux_storage.customSetup(exec_type, tid);
     132     2049710 :     _elemental_array_aux_storage.customSetup(exec_type, tid);
     133             :   }
     134     1881224 : }
     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      522607 : AuxiliarySystem::jacobianSetup()
     156             : {
     157      522607 :   SystemBase::jacobianSetup();
     158             : 
     159     1093098 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     160             :   {
     161      570491 :     _aux_scalar_storage.jacobianSetup(tid);
     162      570491 :     _nodal_aux_storage.jacobianSetup(tid);
     163      570491 :     _mortar_nodal_aux_storage.jacobianSetup(tid);
     164      570491 :     _nodal_vec_aux_storage.jacobianSetup(tid);
     165      570491 :     _nodal_array_aux_storage.jacobianSetup(tid);
     166      570491 :     _elemental_aux_storage.jacobianSetup(tid);
     167      570491 :     _elemental_vec_aux_storage.jacobianSetup(tid);
     168      570491 :     _elemental_array_aux_storage.jacobianSetup(tid);
     169             :   }
     170      522607 : }
     171             : 
     172             : void
     173     3282129 : AuxiliarySystem::residualSetup()
     174             : {
     175     3282129 :   SystemBase::residualSetup();
     176             : 
     177     6859231 :   for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
     178             :   {
     179     3577102 :     _aux_scalar_storage.residualSetup(tid);
     180     3577102 :     _nodal_aux_storage.residualSetup(tid);
     181     3577102 :     _mortar_nodal_aux_storage.residualSetup(tid);
     182     3577102 :     _nodal_vec_aux_storage.residualSetup(tid);
     183     3577102 :     _nodal_array_aux_storage.residualSetup(tid);
     184     3577102 :     _elemental_aux_storage.residualSetup(tid);
     185     3577102 :     _elemental_vec_aux_storage.residualSetup(tid);
     186     3577102 :     _elemental_array_aux_storage.residualSetup(tid);
     187             :   }
     188     3282129 : }
     189             : 
     190             : void
     191      360831 : AuxiliarySystem::updateActive(THREAD_ID tid)
     192             : {
     193      360831 :   _aux_scalar_storage.updateActive(tid);
     194      360831 :   _nodal_aux_storage.updateActive(tid);
     195      360831 :   _mortar_nodal_aux_storage.updateActive(tid);
     196      360831 :   _nodal_vec_aux_storage.updateActive(tid);
     197      360831 :   _nodal_array_aux_storage.updateActive(tid);
     198      360831 :   _elemental_aux_storage.updateActive(tid);
     199      360831 :   _elemental_vec_aux_storage.updateActive(tid);
     200      360831 :   _elemental_array_aux_storage.updateActive(tid);
     201      360831 : }
     202             : 
     203             : void
     204       94972 : AuxiliarySystem::addVariable(const std::string & var_type,
     205             :                              const std::string & name,
     206             :                              InputParameters & parameters)
     207             : {
     208       94972 :   SystemBase::addVariable(var_type, name, parameters);
     209             : 
     210      189944 :   auto fe_type = FEType(Utility::string_to_enum<Order>(parameters.get<MooseEnum>("order")),
     211      284916 :                         Utility::string_to_enum<FEFamily>(parameters.get<MooseEnum>("family")));
     212             : 
     213       94972 :   if (var_type == "MooseVariableScalar")
     214        1805 :     return;
     215             : 
     216      194954 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     217             :   {
     218      101787 :     if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
     219             :     {
     220         394 :       auto * var = _vars[tid].getActualFieldVariable<RealVectorValue>(name);
     221         394 :       if (var)
     222             :       {
     223         394 :         if (var->feType().family == LAGRANGE_VEC)
     224         140 :           _nodal_vars[tid].push_back(var);
     225             :         else
     226         254 :           _elem_vars[tid].push_back(var);
     227             :       }
     228             :     }
     229             : 
     230             :     else
     231             :     {
     232      101393 :       MooseVariableBase * var_base = _vars[tid].getVariable(name);
     233             : 
     234      101393 :       auto * const var = dynamic_cast<MooseVariableField<Real> *>(var_base);
     235             : 
     236      101393 :       if (var)
     237             :       {
     238      100183 :         if (var->feType().family == LAGRANGE)
     239       35499 :           _nodal_vars[tid].push_back(var);
     240             :         else
     241       64684 :           _elem_vars[tid].push_back(var);
     242             :       }
     243             : 
     244      101393 :       auto * const avar = dynamic_cast<MooseVariableField<RealEigenVector> *>(var_base);
     245             : 
     246      101393 :       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       67671 : AuxiliarySystem::addKernel(const std::string & kernel_name,
     259             :                            const std::string & name,
     260             :                            InputParameters & parameters)
     261             : {
     262      141038 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     263             :   {
     264       74536 :     if (parameters.get<std::string>("_moose_base") == "AuxKernel" ||
     265       74536 :         parameters.get<std::string>("_moose_base") == "Bounds")
     266             :     {
     267             :       std::shared_ptr<AuxKernel> kernel =
     268       73106 :           _factory.create<AuxKernel>(kernel_name, name, parameters, tid);
     269       72982 :       if (kernel->isNodal())
     270             :       {
     271       23467 :         if (kernel->isMortar())
     272          84 :           _mortar_nodal_aux_storage.addObject(kernel, tid);
     273             :         else
     274       23383 :           _nodal_aux_storage.addObject(kernel, tid);
     275             :       }
     276             :       else
     277       49515 :         _elemental_aux_storage.addObject(kernel, tid);
     278       72978 :     }
     279             : 
     280         409 :     else if (parameters.get<std::string>("_moose_base") == "VectorAuxKernel")
     281             :     {
     282             :       std::shared_ptr<VectorAuxKernel> kernel =
     283         221 :           _factory.create<VectorAuxKernel>(kernel_name, name, parameters, tid);
     284         221 :       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         165 :         _elemental_vec_aux_storage.addObject(kernel, tid);
     292         221 :     }
     293             : 
     294         188 :     else if (parameters.get<std::string>("_moose_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: " +
     311             :                       parameters.get<std::string>("_moose_base"));
     312             :   }
     313       67523 : }
     314             : 
     315             : void
     316         537 : AuxiliarySystem::addScalarKernel(const std::string & kernel_name,
     317             :                                  const std::string & name,
     318             :                                  InputParameters & parameters)
     319             : {
     320        1113 :   for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
     321             :   {
     322             :     std::shared_ptr<AuxScalarKernel> kernel =
     323         580 :         _factory.create<AuxScalarKernel>(kernel_name, name, parameters, tid);
     324         576 :     _aux_scalar_storage.addObject(kernel, tid);
     325         576 :   }
     326         533 : }
     327             : 
     328             : void
     329   428613796 : AuxiliarySystem::reinitElem(const Elem * /*elem*/, THREAD_ID tid)
     330             : {
     331   587343880 :   for (auto * var : _nodal_vars[tid])
     332   158730084 :     var->computeElemValues();
     333             : 
     334   589061357 :   for (auto * var : _elem_vars[tid])
     335             :   {
     336   160447561 :     var->reinitAux();
     337   160447561 :     var->computeElemValues();
     338             :   }
     339   428613796 : }
     340             : 
     341             : void
     342    12723559 : AuxiliarySystem::reinitElemFace(const Elem * /*elem*/, unsigned int /*side*/, THREAD_ID tid)
     343             : {
     344    15344253 :   for (auto * var : _nodal_vars[tid])
     345     2620694 :     var->computeElemValuesFace();
     346             : 
     347    18846138 :   for (auto * var : _elem_vars[tid])
     348             :   {
     349     6122579 :     var->reinitAux();
     350     6122579 :     var->reinitAuxNeighbor();
     351     6122579 :     var->computeElemValuesFace();
     352             :   }
     353    12723559 : }
     354             : 
     355             : void
     356        2269 : AuxiliarySystem::serializeSolution()
     357             : {
     358        4538 :   if (_serialized_solution.get() &&
     359        2269 :       _sys.n_dofs() > 0) // libMesh does not like serializing of empty vectors
     360             :   {
     361        2269 :     if (!_serialized_solution->initialized() || _serialized_solution->size() != _sys.n_dofs())
     362             :     {
     363          63 :       _serialized_solution->clear();
     364          63 :       _serialized_solution->init(_sys.n_dofs(), false, SERIAL);
     365             :     }
     366             : 
     367        2269 :     solution().localize(*_serialized_solution);
     368             :   }
     369        2269 : }
     370             : 
     371             : void
     372     6237224 : AuxiliarySystem::compute(ExecFlagType type)
     373             : {
     374             :   // avoid division by dt which might be zero.
     375     6237224 :   if (_fe_problem.dt() > 0.)
     376    10778675 :     for (auto & ti : _time_integrators)
     377     5379109 :       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     6237224 :   if (_vars[0].scalars().size() > 0)
     388             :   {
     389       56031 :     computeScalarVars(type);
     390             :     // compute time derivatives of scalar aux variables _after_ the values were updated
     391       56031 :     if (_fe_problem.dt() > 0.)
     392       88162 :       for (auto & ti : _time_integrators)
     393       44081 :         ti->computeTimeDerivatives();
     394             :   }
     395             : 
     396     6237224 :   if (_vars[0].fieldVariables().size() > 0)
     397             :   {
     398     2144712 :     computeNodalArrayVars(type);
     399     2144712 :     computeNodalVecVars(type);
     400     2144712 :     computeNodalVars(type);
     401     2144708 :     computeMortarNodalVars(type);
     402     2144708 :     computeElementalArrayVars(type);
     403     2144708 :     computeElementalVecVars(type);
     404     2144708 :     computeElementalVars(type);
     405             : 
     406             :     // compute time derivatives of nodal aux variables _after_ the values were updated
     407     2144675 :     if (_fe_problem.dt() > 0.)
     408     3710926 :       for (auto & ti : _time_integrators)
     409     1837467 :         ti->computeTimeDerivatives();
     410             :   }
     411             : 
     412     6237187 :   if (_serialized_solution.get())
     413        2269 :     serializeSolution();
     414     6237187 : }
     415             : 
     416             : std::set<std::string>
     417     1617073 : AuxiliarySystem::getDependObjects(ExecFlagType type)
     418             : {
     419     1617073 :   std::set<std::string> depend_objects;
     420             : 
     421             :   // Elemental AuxKernels
     422             :   {
     423             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     424     1617073 :         _elemental_aux_storage[type].getActiveObjects();
     425     1699973 :     for (const auto & aux : auxs)
     426             :     {
     427       82900 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     428       82900 :       depend_objects.insert(uo.begin(), uo.end());
     429             :     }
     430             :   }
     431             : 
     432             :   // Elemental VectorAuxKernels
     433             :   {
     434             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     435     1617073 :         _elemental_vec_aux_storage[type].getActiveObjects();
     436     1617368 :     for (const auto & aux : auxs)
     437             :     {
     438         295 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     439         295 :       depend_objects.insert(uo.begin(), uo.end());
     440             :     }
     441             :   }
     442             : 
     443             :   // Elemental ArrayAuxKernels
     444             :   {
     445             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     446     1617073 :         _elemental_array_aux_storage[type].getActiveObjects();
     447     1617177 :     for (const auto & aux : auxs)
     448             :     {
     449         104 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     450         104 :       depend_objects.insert(uo.begin(), uo.end());
     451             :     }
     452             :   }
     453             : 
     454             :   // Nodal AuxKernels
     455             :   {
     456             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     457     1617073 :         _nodal_aux_storage[type].getActiveObjects();
     458     1658174 :     for (const auto & aux : auxs)
     459             :     {
     460       41101 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     461       41101 :       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     1617073 :         _mortar_nodal_aux_storage[type].getActiveObjects();
     469     1617229 :     for (const auto & aux : auxs)
     470             :     {
     471         156 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     472         156 :       depend_objects.insert(uo.begin(), uo.end());
     473             :     }
     474             :   }
     475             : 
     476             :   // Nodal VectorAuxKernels
     477             :   {
     478             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     479     1617073 :         _nodal_vec_aux_storage[type].getActiveObjects();
     480     1617164 :     for (const auto & aux : auxs)
     481             :     {
     482          91 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     483          91 :       depend_objects.insert(uo.begin(), uo.end());
     484             :     }
     485             :   }
     486             : 
     487             :   // Nodal ArrayAuxKernels
     488             :   {
     489             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     490     1617073 :         _nodal_array_aux_storage[type].getActiveObjects();
     491     1617229 :     for (const auto & aux : auxs)
     492             :     {
     493         156 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     494         156 :       depend_objects.insert(uo.begin(), uo.end());
     495             :     }
     496             :   }
     497             : 
     498     1617073 :   return depend_objects;
     499           0 : }
     500             : 
     501             : std::set<std::string>
     502       59892 : AuxiliarySystem::getDependObjects()
     503             : {
     504       59892 :   std::set<std::string> depend_objects;
     505             : 
     506             :   // Elemental AuxKernels
     507             :   {
     508             :     const std::vector<std::shared_ptr<AuxKernel>> & auxs =
     509       59892 :         _elemental_aux_storage.getActiveObjects();
     510      103517 :     for (const auto & aux : auxs)
     511             :     {
     512       43625 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     513       43625 :       depend_objects.insert(uo.begin(), uo.end());
     514             :     }
     515             :   }
     516             : 
     517             :   // Elemental VectorAuxKernels
     518             :   {
     519             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     520       59892 :         _elemental_vec_aux_storage.getActiveObjects();
     521       60046 :     for (const auto & aux : auxs)
     522             :     {
     523         154 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     524         154 :       depend_objects.insert(uo.begin(), uo.end());
     525             :     }
     526             :   }
     527             : 
     528             :   // Elemental ArrayAuxKernels
     529             :   {
     530             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     531       59892 :         _elemental_array_aux_storage.getActiveObjects();
     532       59957 :     for (const auto & aux : auxs)
     533             :     {
     534          65 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     535          65 :       depend_objects.insert(uo.begin(), uo.end());
     536             :     }
     537             :   }
     538             : 
     539             :   // Nodal AuxKernels
     540             :   {
     541       59892 :     const std::vector<std::shared_ptr<AuxKernel>> & auxs = _nodal_aux_storage.getActiveObjects();
     542       81449 :     for (const auto & aux : auxs)
     543             :     {
     544       21557 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     545       21557 :       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       59892 :         _mortar_nodal_aux_storage.getActiveObjects();
     553       59970 :     for (const auto & aux : auxs)
     554             :     {
     555          78 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     556          78 :       depend_objects.insert(uo.begin(), uo.end());
     557             :     }
     558             :   }
     559             : 
     560             :   // Nodal VectorAuxKernels
     561             :   {
     562             :     const std::vector<std::shared_ptr<VectorAuxKernel>> & auxs =
     563       59892 :         _nodal_vec_aux_storage.getActiveObjects();
     564       59944 :     for (const auto & aux : auxs)
     565             :     {
     566          52 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     567          52 :       depend_objects.insert(uo.begin(), uo.end());
     568             :     }
     569             :   }
     570             : 
     571             :   // Nodal ArrayAuxKernels
     572             :   {
     573             :     const std::vector<std::shared_ptr<ArrayAuxKernel>> & auxs =
     574       59892 :         _nodal_array_aux_storage.getActiveObjects();
     575       59983 :     for (const auto & aux : auxs)
     576             :     {
     577          91 :       const std::set<UserObjectName> & uo = aux->getDependObjects();
     578          91 :       depend_objects.insert(uo.begin(), uo.end());
     579             :     }
     580             :   }
     581             : 
     582       59892 :   return depend_objects;
     583           0 : }
     584             : 
     585             : void
     586       56031 : AuxiliarySystem::setScalarVariableCoupleableTags(ExecFlagType type)
     587             : {
     588       56031 :   const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
     589       56031 :   const std::vector<std::shared_ptr<AuxScalarKernel>> & objects = storage.getActiveObjects(0);
     590             : 
     591       56031 :   std::set<TagID> needed_sc_var_matrix_tags;
     592       56031 :   std::set<TagID> needed_sc_var_vector_tags;
     593       75911 :   for (const auto & obj : objects)
     594             :   {
     595       19880 :     auto & sc_var_coup_vtags = obj->getScalarVariableCoupleableVectorTags();
     596       19880 :     needed_sc_var_vector_tags.insert(sc_var_coup_vtags.begin(), sc_var_coup_vtags.end());
     597             : 
     598       19880 :     auto & sc_var_coup_mtags = obj->getScalarVariableCoupleableMatrixTags();
     599       19880 :     needed_sc_var_matrix_tags.insert(sc_var_coup_mtags.begin(), sc_var_coup_mtags.end());
     600             :   }
     601             : 
     602       56031 :   _fe_problem.setActiveScalarVariableCoupleableMatrixTags(needed_sc_var_matrix_tags, 0);
     603       56031 :   _fe_problem.setActiveScalarVariableCoupleableVectorTags(needed_sc_var_vector_tags, 0);
     604       56031 : }
     605             : 
     606             : void
     607       56031 : AuxiliarySystem::clearScalarVariableCoupleableTags()
     608             : {
     609       56031 :   _fe_problem.clearActiveScalarVariableCoupleableMatrixTags(0);
     610       56031 :   _fe_problem.clearActiveScalarVariableCoupleableVectorTags(0);
     611       56031 : }
     612             : 
     613             : void
     614       56031 : AuxiliarySystem::computeScalarVars(ExecFlagType type)
     615             : {
     616       56031 :   setScalarVariableCoupleableTags(type);
     617             : 
     618             :   // Reference to the current storage container
     619       56031 :   const MooseObjectWarehouse<AuxScalarKernel> & storage = _aux_scalar_storage[type];
     620             : 
     621       56031 :   if (storage.hasActiveObjects())
     622             :   {
     623       18163 :     TIME_SECTION("computeScalarVars", 1);
     624             : 
     625             :     PARALLEL_TRY
     626             :     {
     627             :       // FIXME: run multi-threaded
     628       18163 :       THREAD_ID tid = 0;
     629       18163 :       if (storage.hasActiveObjects())
     630             :       {
     631       18163 :         _fe_problem.reinitScalars(tid);
     632             : 
     633             :         const std::vector<std::shared_ptr<AuxScalarKernel>> & objects =
     634       18163 :             storage.getActiveObjects(tid);
     635             : 
     636             :         // Call compute() method on all active AuxScalarKernel objects
     637       38043 :         for (const auto & obj : objects)
     638       19880 :           obj->compute();
     639             : 
     640       18163 :         const std::vector<MooseVariableScalar *> & scalar_vars = getScalarVariables(tid);
     641       56490 :         for (const auto & var : scalar_vars)
     642       38327 :           var->insert(solution());
     643             :       }
     644             :     }
     645       18163 :     PARALLEL_CATCH;
     646             : 
     647       18163 :     solution().close();
     648       18163 :     _sys.update();
     649       18163 :   }
     650             : 
     651       56031 :   clearScalarVariableCoupleableTags();
     652       56031 : }
     653             : 
     654             : void
     655     2144712 : AuxiliarySystem::computeNodalVars(ExecFlagType type)
     656             : {
     657     2144712 :   TIME_SECTION("computeNodalVars", 3);
     658             : 
     659     2144712 :   const MooseObjectWarehouse<AuxKernel> & nodal = _nodal_aux_storage[type];
     660     2144712 :   computeNodalVarsHelper<AuxKernel>(nodal);
     661     2144708 : }
     662             : 
     663             : void
     664     2144712 : AuxiliarySystem::computeNodalVecVars(ExecFlagType type)
     665             : {
     666     2144712 :   TIME_SECTION("computeNodalVecVars", 3);
     667             : 
     668     2144712 :   const MooseObjectWarehouse<VectorAuxKernel> & nodal = _nodal_vec_aux_storage[type];
     669     2144712 :   computeNodalVarsHelper<VectorAuxKernel>(nodal);
     670     2144712 : }
     671             : 
     672             : void
     673     2144712 : AuxiliarySystem::computeNodalArrayVars(ExecFlagType type)
     674             : {
     675     2144712 :   const MooseObjectWarehouse<ArrayAuxKernel> & nodal = _nodal_array_aux_storage[type];
     676     2144712 :   computeNodalVarsHelper<ArrayAuxKernel>(nodal);
     677     2144712 : }
     678             : 
     679             : void
     680     2144708 : AuxiliarySystem::computeMortarNodalVars(const ExecFlagType type)
     681             : {
     682     2144708 :   TIME_SECTION("computeMortarNodalVars", 3);
     683             : 
     684     2144708 :   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     2144708 :   if (mortar_nodal_warehouse.hasActiveBoundaryObjects())
     690             :   {
     691         186 :     ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
     692         372 :     for (const auto & [bnd_id, mortar_nodal_auxes] :
     693         558 :          mortar_nodal_warehouse.getActiveBoundaryObjects())
     694         372 :       for (const auto index : index_range(mortar_nodal_auxes))
     695             :       {
     696             :         PARALLEL_TRY
     697             :         {
     698             :           try
     699             :           {
     700             :             ComputeMortarNodalAuxBndThread<AuxKernel> mnabt(
     701         186 :                 _fe_problem, mortar_nodal_warehouse, bnd_id, index);
     702         186 :             Threads::parallel_reduce(bnd_nodes, mnabt);
     703         186 :           }
     704           0 :           catch (libMesh::LogicError & e)
     705             :           {
     706           0 :             _fe_problem.setException("The following libMesh::LogicError was raised during mortar "
     707           0 :                                      "nodal Auxiliary variable computation:\n" +
     708           0 :                                      std::string(e.what()));
     709           0 :           }
     710           0 :           catch (MooseException & e)
     711             :           {
     712           0 :             _fe_problem.setException("The following MooseException was raised during mortar nodal "
     713           0 :                                      "Auxiliary variable computation:\n" +
     714           0 :                                      std::string(e.what()));
     715           0 :           }
     716           0 :           catch (MetaPhysicL::LogicError & e)
     717             :           {
     718           0 :             moose::translateMetaPhysicLError(e);
     719           0 :           }
     720             :         }
     721         186 :         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         186 :         solution().close();
     726         186 :         _sys.update();
     727             :       }
     728             :   }
     729     2144708 : }
     730             : 
     731             : void
     732     2144708 : AuxiliarySystem::computeElementalVars(ExecFlagType type)
     733             : {
     734     2144708 :   TIME_SECTION("computeElementalVars", 3);
     735             : 
     736     2144708 :   const MooseObjectWarehouse<AuxKernel> & elemental = _elemental_aux_storage[type];
     737     2144708 :   computeElementalVarsHelper<AuxKernel>(elemental);
     738     2144675 : }
     739             : 
     740             : void
     741     2144708 : AuxiliarySystem::computeElementalVecVars(ExecFlagType type)
     742             : {
     743     2144708 :   TIME_SECTION("computeElementalVecVars", 3);
     744             : 
     745     2144708 :   const MooseObjectWarehouse<VectorAuxKernel> & elemental = _elemental_vec_aux_storage[type];
     746     2144708 :   computeElementalVarsHelper<VectorAuxKernel>(elemental);
     747     2144708 : }
     748             : 
     749             : void
     750     2144708 : AuxiliarySystem::computeElementalArrayVars(ExecFlagType type)
     751             : {
     752     2144708 :   const MooseObjectWarehouse<ArrayAuxKernel> & elemental = _elemental_array_aux_storage[type];
     753     2144708 :   computeElementalVarsHelper<ArrayAuxKernel>(elemental);
     754     2144708 : }
     755             : 
     756             : void
     757           0 : AuxiliarySystem::augmentSparsity(SparsityPattern::Graph & /*sparsity*/,
     758             :                                  std::vector<dof_id_type> & /*n_nz*/,
     759             :                                  std::vector<dof_id_type> &
     760             :                                  /*n_oz*/)
     761             : {
     762           0 : }
     763             : 
     764             : Order
     765       67123 : AuxiliarySystem::getMinQuadratureOrder()
     766             : {
     767       67123 :   Order order = CONSTANT;
     768       67123 :   std::vector<MooseVariableFEBase *> vars = _vars[0].fieldVariables();
     769      147417 :   for (const auto & var : vars)
     770             :   {
     771       80294 :     if (!var->isNodal()) // nodal aux variables do not need quadrature
     772             :     {
     773       41108 :       FEType fe_type = var->feType();
     774       41108 :       if (fe_type.default_quadrature_order() > order)
     775       20951 :         order = fe_type.default_quadrature_order();
     776             :     }
     777             :   }
     778             : 
     779       67123 :   return order;
     780       67123 : }
     781             : 
     782             : bool
     783       28406 : AuxiliarySystem::needMaterialOnSide(BoundaryID bnd_id)
     784             : {
     785       56247 :   return _elemental_aux_storage.hasActiveBoundaryObjects(bnd_id) ||
     786       56247 :          _elemental_vec_aux_storage.hasActiveBoundaryObjects(bnd_id);
     787             : }
     788             : 
     789             : void
     790         532 : AuxiliarySystem::copyCurrentIntoPreviousNL()
     791             : {
     792         532 :   if (solutionPreviousNewton())
     793         532 :     *solutionPreviousNewton() = *currentSolution();
     794         532 : }
     795             : 
     796             : template <typename AuxKernelType>
     797             : void
     798     6434124 : AuxiliarySystem::computeElementalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
     799             : {
     800     6434124 :   if (warehouse.hasActiveBlockObjects())
     801             :   {
     802             :     // Block Elemental AuxKernels
     803             :     PARALLEL_TRY
     804             :     {
     805       80321 :       ConstElemRange & range = *_mesh.getActiveLocalElementRange();
     806       80321 :       ComputeElemAuxVarsThread<AuxKernelType> eavt(_fe_problem, warehouse, true);
     807             :       try
     808             :       {
     809       80321 :         Threads::parallel_reduce(range, eavt);
     810             :       }
     811           0 :       catch (MooseException & e)
     812             :       {
     813           0 :         _fe_problem.setException("The following MooseException was raised during elemental "
     814             :                                  "Auxiliary variable computation:\n" +
     815           0 :                                  std::string(e.what()));
     816             :       }
     817       80294 :     }
     818       80294 :     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       80294 :     solution().close();
     823       80294 :     _sys.update();
     824             :   }
     825             : 
     826             :   // Boundary Elemental AuxKernels
     827     6434097 :   if (warehouse.hasActiveBoundaryObjects())
     828             :   {
     829       27019 :     TIME_SECTION("computeElementalVecVars", 3);
     830             : 
     831             :     PARALLEL_TRY
     832             :     {
     833       27019 :       ConstBndElemRange & bnd_elems = *_mesh.getBoundaryElementRange();
     834       27019 :       ComputeElemAuxBcsThread<AuxKernelType> eabt(_fe_problem, warehouse, true);
     835             :       try
     836             :       {
     837       27019 :         Threads::parallel_reduce(bnd_elems, eabt);
     838             :       }
     839           0 :       catch (MooseException & e)
     840             :       {
     841           0 :         _fe_problem.setException("The following MooseException was raised during boundary "
     842             :                                  "elemental Auxiliary variable computation:\n" +
     843           0 :                                  std::string(e.what()));
     844             :       }
     845       27013 :     }
     846       27013 :     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       27013 :     solution().close();
     851       27013 :     _sys.update();
     852       27013 :   }
     853     6434091 : }
     854             : 
     855             : template <typename AuxKernelType>
     856             : void
     857     6434136 : AuxiliarySystem::computeNodalVarsHelper(const MooseObjectWarehouse<AuxKernelType> & warehouse)
     858             : {
     859     6434136 :   if (warehouse.hasActiveBlockObjects())
     860             :   {
     861             :     // Block Nodal AuxKernels
     862             :     PARALLEL_TRY
     863             :     {
     864      146860 :       ConstNodeRange & range = *_mesh.getLocalNodeRange();
     865      146860 :       ComputeNodalAuxVarsThread<AuxKernelType> navt(_fe_problem, warehouse);
     866      146860 :       Threads::parallel_reduce(range, navt);
     867             : 
     868      146856 :       solution().close();
     869      146856 :       _sys.update();
     870      146856 :     }
     871      146856 :     PARALLEL_CATCH;
     872             :   }
     873             : 
     874     6434132 :   if (warehouse.hasActiveBoundaryObjects())
     875             :   {
     876       91973 :     TIME_SECTION("computeBoundaryObjects", 3);
     877             : 
     878             :     // Boundary Nodal AuxKernels
     879             :     PARALLEL_TRY
     880             :     {
     881       91973 :       ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
     882       91973 :       ComputeNodalAuxBcsThread<AuxKernelType> nabt(_fe_problem, warehouse);
     883       91973 :       Threads::parallel_reduce(bnd_nodes, nabt);
     884             : 
     885       91973 :       solution().close();
     886       91973 :       _sys.update();
     887       91973 :     }
     888       91973 :     PARALLEL_CATCH;
     889       91973 :   }
     890     6434132 : }
     891             : 
     892             : void
     893         553 : AuxiliarySystem::variableWiseRelativeSolutionDifferenceNorm(
     894             :     std::vector<Number> & rel_diff_norms) const
     895             : {
     896         553 :   rel_diff_norms.resize(nVariables(), 0);
     897             :   // Get dof map from system
     898         553 :   const auto & dof_map = _sys.get_dof_map();
     899             : 
     900        1659 :   for (const auto n : make_range(nVariables()))
     901             :   {
     902             :     // Get local indices from dof map for each variable
     903        1106 :     std::vector<dof_id_type> local_indices_n;
     904        1106 :     dof_map.local_variable_indices(local_indices_n, _mesh, n);
     905        1106 :     Number diff_norm_n = 0;
     906        1106 :     Number norm_n = 0;
     907             :     // Get values from system, update norm
     908      101536 :     for (const auto local_index : local_indices_n)
     909             :     {
     910      100430 :       const Number & value = solution()(local_index);
     911      100430 :       const Number & value_old = solutionOld()(local_index);
     912      100430 :       diff_norm_n += Utility::pow<2, Number>(value - value_old);
     913      100430 :       norm_n += Utility::pow<2, Number>(value);
     914             :     }
     915             :     // Aggregate norm over proceccors
     916        1106 :     _communicator.sum(diff_norm_n);
     917        1106 :     _communicator.sum(norm_n);
     918        1106 :     diff_norm_n = sqrt(diff_norm_n);
     919        1106 :     norm_n = sqrt(norm_n);
     920        1106 :     rel_diff_norms[n] = diff_norm_n / norm_n;
     921        1106 :   }
     922         553 : }
     923             : 
     924             : template void
     925             : AuxiliarySystem::computeElementalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
     926             : template void AuxiliarySystem::computeElementalVarsHelper<VectorAuxKernel>(
     927             :     const MooseObjectWarehouse<VectorAuxKernel> &);
     928             : template void
     929             : AuxiliarySystem::computeNodalVarsHelper<AuxKernel>(const MooseObjectWarehouse<AuxKernel> &);
     930             : template void AuxiliarySystem::computeNodalVarsHelper<VectorAuxKernel>(
     931             :     const MooseObjectWarehouse<VectorAuxKernel> &);

Generated by: LCOV version 1.14