LCOV - code coverage report
Current view: top level - src/loops - CacheChangedListsThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 37 38 97.4 %
Date: 2025-07-17 01:28:37 Functions: 6 6 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 "CacheChangedListsThread.h"
      11             : 
      12             : #include "libmesh/elem.h"
      13             : 
      14         212 : CacheChangedListsThread::CacheChangedListsThread(MooseMesh & mesh)
      15         212 :   : ThreadedElementLoopBase<ConstElemRange>(mesh)
      16             : {
      17         212 : }
      18             : 
      19             : // Splitting Constructor
      20          16 : CacheChangedListsThread::CacheChangedListsThread(CacheChangedListsThread & x, Threads::split split)
      21          16 :   : ThreadedElementLoopBase<ConstElemRange>(x, split)
      22             : {
      23          16 : }
      24             : 
      25         244 : CacheChangedListsThread::~CacheChangedListsThread() {}
      26             : 
      27             : void
      28       62452 : CacheChangedListsThread::onElement(const Elem * elem)
      29             : {
      30       62452 :   if (_mesh.doingPRefinement())
      31             :   {
      32             :     // When we p-refine an active child element this can lead to p-refinement of the parent as well.
      33             :     // We don't care about inactive parents
      34       22176 :     if (elem->active())
      35             :     {
      36       18432 :       if (elem->p_refinement_flag() == Elem::JUST_REFINED)
      37         800 :         _refined_elements.push_back(elem);
      38       17632 :       else if (elem->p_refinement_flag() == Elem::JUST_COARSENED)
      39           0 :         _coarsened_elements.push_back(elem);
      40             :     }
      41             :   }
      42             :   else
      43             :   {
      44             :     // Cache any parents of local elements that have just been refined
      45             :     // away.
      46             :     //
      47             :     // The parent itself might *not* be local, because only some of its
      48             :     // new children are.  Make sure to cache every such case exactly once.
      49       40276 :     if (elem->refinement_flag() == Elem::JUST_REFINED)
      50             :     {
      51       16202 :       const Elem * const parent = elem->parent();
      52       16202 :       const unsigned int child_num = parent->which_child_am_i(elem);
      53             : 
      54       16202 :       bool im_the_lowest_local_child = true;
      55       56539 :       for (const auto c : make_range(child_num))
      56       80674 :         if (parent->child_ptr(c) && parent->child_ptr(c) != remote_elem &&
      57       40337 :             parent->child_ptr(c)->processor_id() == elem->processor_id())
      58       39562 :           im_the_lowest_local_child = false;
      59             : 
      60       16202 :       if (im_the_lowest_local_child)
      61        3200 :         _refined_elements.push_back(parent);
      62             :     }
      63             : 
      64       24074 :     else if (elem->refinement_flag() == Elem::JUST_COARSENED)
      65             :     {
      66        1210 :       if (elem->has_children())
      67             :       {
      68        1210 :         _coarsened_elements.push_back(elem);
      69             : 
      70        1210 :         std::vector<const Elem *> & children = _coarsened_element_children[elem];
      71             : 
      72        7862 :         for (unsigned int child = 0; child < elem->n_children(); child++)
      73        6652 :           children.push_back(elem->child_ptr(child));
      74             :       }
      75             :     }
      76             :   }
      77       62452 : }
      78             : 
      79             : void
      80          16 : CacheChangedListsThread::join(const CacheChangedListsThread & y)
      81             : {
      82          32 :   _refined_elements.insert(
      83          16 :       _refined_elements.end(), y._refined_elements.begin(), y._refined_elements.end());
      84          32 :   _coarsened_elements.insert(
      85          16 :       _coarsened_elements.end(), y._coarsened_elements.begin(), y._coarsened_elements.end());
      86          16 :   _coarsened_element_children.insert(y._coarsened_element_children.begin(),
      87             :                                      y._coarsened_element_children.end());
      88          16 : }

Generated by: LCOV version 1.14