LCOV - code coverage report
Current view: top level - include/loops - ThreadedNodeLoop.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 35 37 94.6 %
Date: 2025-07-17 01:28:37 Functions: 28 36 77.8 %
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             : #pragma once
      11             : 
      12             : #include "FEProblemBase.h"
      13             : #include "ParallelUniqueId.h"
      14             : 
      15             : static Threads::spin_mutex threaded_node_mutex;
      16             : 
      17             : template <typename RangeType, typename IteratorType>
      18             : class ThreadedNodeLoop
      19             : {
      20             : public:
      21             :   ThreadedNodeLoop(FEProblemBase & fe_problem);
      22             : 
      23             :   // Splitting Constructor
      24             :   ThreadedNodeLoop(ThreadedNodeLoop & x, Threads::split split);
      25             : 
      26      795852 :   virtual ~ThreadedNodeLoop(){};
      27             : 
      28             :   void operator()(const RangeType & range);
      29             : 
      30             :   /**
      31             :    * Called before the node range loop
      32             :    */
      33             :   virtual void pre();
      34             : 
      35             :   /**
      36             :    * Called after the node range loop
      37             :    */
      38             :   virtual void post();
      39             : 
      40             :   /**
      41             :    * Called for each node
      42             :    */
      43             :   virtual void onNode(IteratorType & node_it);
      44             : 
      45             :   /**
      46             :    * Called after the node assembly is done (including surface assembling)
      47             :    *
      48             :    * @param node - active node
      49             :    */
      50             :   virtual void postNode(IteratorType & node_it);
      51             : 
      52             :   /**
      53             :    * Called if a MooseException is caught anywhere during the computation.
      54             :    * The single input parameter taken is a MooseException object.
      55             :    */
      56          32 :   virtual void caughtMooseException(MooseException & e)
      57             :   {
      58          32 :     Threads::spin_mutex::scoped_lock lock(threaded_node_mutex);
      59             : 
      60          32 :     std::string what(e.what());
      61          32 :     _fe_problem.setException(what);
      62          32 :   };
      63             : 
      64             :   /**
      65             :    * Whether or not the loop should continue.
      66             :    *
      67             :    * @return true to keep going, false to stop.
      68             :    */
      69    89960846 :   virtual bool keepGoing() { return !_fe_problem.hasException(); }
      70             : 
      71             : protected:
      72             :   FEProblemBase & _fe_problem;
      73             :   THREAD_ID _tid;
      74             : 
      75             :   /// Print information about the loop, mostly order of execution of objects
      76      513860 :   virtual void printGeneralExecutionInformation() const {}
      77             : };
      78             : 
      79             : template <typename RangeType, typename IteratorType>
      80      721013 : ThreadedNodeLoop<RangeType, IteratorType>::ThreadedNodeLoop(FEProblemBase & fe_problem)
      81      721013 :   : _fe_problem(fe_problem)
      82             : {
      83      721013 : }
      84             : 
      85             : template <typename RangeType, typename IteratorType>
      86       74874 : ThreadedNodeLoop<RangeType, IteratorType>::ThreadedNodeLoop(ThreadedNodeLoop & x,
      87             :                                                             Threads::split /*split*/)
      88       74874 :   : _fe_problem(x._fe_problem)
      89             : {
      90       74874 : }
      91             : 
      92             : template <typename RangeType, typename IteratorType>
      93             : void
      94      795887 : ThreadedNodeLoop<RangeType, IteratorType>::operator()(const RangeType & range)
      95             : {
      96             :   try
      97             :   {
      98      795887 :     ParallelUniqueId puid;
      99      795887 :     _tid = puid.id;
     100             : 
     101      795887 :     pre();
     102      795887 :     printGeneralExecutionInformation();
     103             : 
     104    90756684 :     for (IteratorType nd = range.begin(); nd != range.end(); ++nd)
     105             :     {
     106    89960846 :       if (!keepGoing())
     107           1 :         break;
     108             : 
     109    89960845 :       onNode(nd);
     110             : 
     111    89960797 :       postNode(nd);
     112             :     }
     113             : 
     114      795839 :     post();
     115      795871 :   }
     116          64 :   catch (MooseException & e)
     117             :   {
     118          32 :     caughtMooseException(e);
     119             :   }
     120      795871 : }
     121             : 
     122             : template <typename RangeType, typename IteratorType>
     123             : void
     124      768642 : ThreadedNodeLoop<RangeType, IteratorType>::pre()
     125             : {
     126      768642 : }
     127             : 
     128             : template <typename RangeType, typename IteratorType>
     129             : void
     130      649897 : ThreadedNodeLoop<RangeType, IteratorType>::post()
     131             : {
     132      649897 : }
     133             : 
     134             : template <typename RangeType, typename IteratorType>
     135             : void
     136           0 : ThreadedNodeLoop<RangeType, IteratorType>::onNode(IteratorType & /*node_it*/)
     137             : {
     138           0 : }
     139             : 
     140             : template <typename RangeType, typename IteratorType>
     141             : void
     142    89960797 : ThreadedNodeLoop<RangeType, IteratorType>::postNode(IteratorType & /*node_it*/)
     143             : {
     144    89960797 : }

Generated by: LCOV version 1.14