LCOV - code coverage report
Current view: top level - src/loops - ComputeNodalAuxVarsThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 59 59 100.0 %
Date: 2025-07-17 01:28:37 Functions: 21 21 100.0 %
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 "ComputeNodalAuxVarsThread.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "AuxiliarySystem.h"
      14             : #include "AuxKernel.h"
      15             : #include "FEProblem.h"
      16             : #include "MooseMesh.h"
      17             : 
      18             : #include "libmesh/threads.h"
      19             : 
      20             : template <typename AuxKernelType>
      21             : Threads::spin_mutex ComputeNodalAuxVarsThread<AuxKernelType>::writable_variable_mutex;
      22             : 
      23             : template <typename AuxKernelType>
      24      133439 : ComputeNodalAuxVarsThread<AuxKernelType>::ComputeNodalAuxVarsThread(
      25             :     FEProblemBase & fe_problem, const MooseObjectWarehouse<AuxKernelType> & storage)
      26             :   : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(fe_problem),
      27      266878 :     _aux_sys(fe_problem.getAuxiliarySystem()),
      28      133439 :     _storage(storage)
      29             : {
      30      133439 : }
      31             : 
      32             : // Splitting Constructor
      33             : template <typename AuxKernelType>
      34       12507 : ComputeNodalAuxVarsThread<AuxKernelType>::ComputeNodalAuxVarsThread(ComputeNodalAuxVarsThread & x,
      35             :                                                                     Threads::split split)
      36             :   : ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(x, split),
      37       12507 :     _aux_sys(x._aux_sys),
      38       12507 :     _storage(x._storage)
      39             : {
      40       12507 : }
      41             : 
      42             : template <typename AuxKernelType>
      43             : void
      44      328522 : ComputeNodalAuxVarsThread<AuxKernelType>::subdomainChanged()
      45             : {
      46      328522 :   std::set<TagID> needed_vector_tags;
      47      328522 :   std::set<TagID> needed_matrix_tags;
      48             : 
      49      328522 :   const auto & block_kernels = _storage.getActiveBlockObjects(_tid);
      50             : 
      51      732888 :   for (const auto & block : _block_ids)
      52             :   {
      53      404366 :     const auto iter = block_kernels.find(block);
      54             : 
      55      404366 :     if (iter != block_kernels.end())
      56      793482 :       for (const auto & aux : iter->second)
      57             :       {
      58      453200 :         auto & matrix_tags = aux->getFEVariableCoupleableMatrixTags();
      59      453200 :         needed_matrix_tags.insert(matrix_tags.begin(), matrix_tags.end());
      60      453200 :         auto & vector_tags = aux->getFEVariableCoupleableVectorTags();
      61      453200 :         needed_vector_tags.insert(vector_tags.begin(), vector_tags.end());
      62             :       }
      63             :   }
      64             : 
      65      328522 :   _fe_problem.setActiveFEVariableCoupleableMatrixTags(needed_matrix_tags, _tid);
      66      328522 :   _fe_problem.setActiveFEVariableCoupleableVectorTags(needed_vector_tags, _tid);
      67      328522 : }
      68             : 
      69             : template <typename AuxKernelType>
      70             : void
      71    22468600 : ComputeNodalAuxVarsThread<AuxKernelType>::onNode(ConstNodeRange::const_iterator & node_it)
      72             : {
      73    22468600 :   const Node * node = *node_it;
      74             : 
      75    22468600 :   const auto & block_ids = _aux_sys.mesh().getNodeBlockIds(*node);
      76             : 
      77    22468600 :   if (_block_ids != block_ids)
      78             :   {
      79      328522 :     _block_ids.clear();
      80      328522 :     _block_ids.insert(block_ids.begin(), block_ids.end());
      81      328522 :     subdomainChanged();
      82             :   }
      83             : 
      84    22468600 :   _fe_problem.reinitNode(node, _tid);
      85             : 
      86             :   // Get a map of all active block restricted AuxKernel objects
      87    22468600 :   const auto & block_kernels = _storage.getActiveBlockObjects(_tid);
      88             : 
      89             :   // Loop over all SubdomainIDs for the current node, if an AuxKernel is active on this block then
      90             :   // compute it.
      91    45049039 :   for (const auto & block : block_ids)
      92             :   {
      93    22580443 :     const auto iter = block_kernels.find(block);
      94             : 
      95    22580443 :     if (iter != block_kernels.end())
      96    39723357 :       for (const auto & aux : iter->second)
      97             :       {
      98    22641640 :         aux->compute();
      99             :         // This is the same conditional check that the aux kernel performs internally before calling
     100             :         // computeValue and _var.setNodalValue. We don't want to attempt to insert into the solution
     101             :         // if we don't actually have any dofs on this node
     102    22641636 :         if (aux->variable().isNodalDefined())
     103    20234812 :           aux->variable().insert(_aux_sys.solution());
     104             : 
     105             :         // update the aux solution vector if writable coupled variables are used
     106    22641636 :         if (aux->hasWritableCoupledVariables())
     107             :         {
     108        2160 :           for (auto * var : aux->getWritableCoupledVariables())
     109        1440 :             if (var->isNodalDefined())
     110             :               // insert into the global solution vector
     111        1440 :               var->insert(_aux_sys.solution());
     112             : 
     113             :           // make solution values available for dependent AuxKernels
     114         720 :           _fe_problem.reinitNode(node, _tid);
     115             :         }
     116             :       }
     117             :   }
     118    22468596 : }
     119             : 
     120             : template <typename AuxKernelType>
     121             : void
     122      145942 : ComputeNodalAuxVarsThread<AuxKernelType>::post()
     123             : {
     124      145942 :   _fe_problem.clearActiveFEVariableCoupleableVectorTags(_tid);
     125      145942 :   _fe_problem.clearActiveFEVariableCoupleableMatrixTags(_tid);
     126      145942 : }
     127             : 
     128             : template <typename AuxKernelType>
     129             : void
     130       12507 : ComputeNodalAuxVarsThread<AuxKernelType>::join(const ComputeNodalAuxVarsThread & /*y*/)
     131             : {
     132       12507 : }
     133             : 
     134             : template <typename AuxKernelType>
     135             : void
     136      145946 : ComputeNodalAuxVarsThread<AuxKernelType>::printGeneralExecutionInformation() const
     137             : {
     138      145946 :   if (!_fe_problem.shouldPrintExecution(_tid) || !_storage.hasActiveObjects())
     139      145440 :     return;
     140             : 
     141         506 :   const auto & console = _fe_problem.console();
     142         506 :   const auto & execute_on = _fe_problem.getCurrentExecuteOnFlag();
     143         506 :   console << "[DBG] Beginning nodal loop of nodal auxiliary kernels on " << execute_on << std::endl;
     144         506 :   console << "[DBG] Ordering of the kernels on each block they are defined on:" << std::endl;
     145             :   // TODO Check that all objects are active at this point
     146         506 :   console << _storage.activeObjectsToFormattedString() << std::endl;
     147             : }
     148             : 
     149             : template class ComputeNodalAuxVarsThread<AuxKernel>;
     150             : template class ComputeNodalAuxVarsThread<VectorAuxKernel>;
     151             : template class ComputeNodalAuxVarsThread<ArrayAuxKernel>;

Generated by: LCOV version 1.14