LCOV - code coverage report
Current view: top level - src/loops - CacheChangedListsThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 37 38 97.4 %
Date: 2025-08-08 20:01:16 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         232 : CacheChangedListsThread::CacheChangedListsThread(MooseMesh & mesh)
      15         232 :   : ThreadedElementLoopBase<ConstElemRange>(mesh)
      16             : {
      17         232 : }
      18             : 
      19             : // Splitting Constructor
      20          16 : CacheChangedListsThread::CacheChangedListsThread(CacheChangedListsThread & x, Threads::split split)
      21          16 :   : ThreadedElementLoopBase<ConstElemRange>(x, split)
      22             : {
      23          16 : }
      24             : 
      25         264 : CacheChangedListsThread::~CacheChangedListsThread() {}
      26             : 
      27             : void
      28       70316 : CacheChangedListsThread::onElement(const Elem * elem)
      29             : {
      30       70316 :   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       24948 :     if (elem->active())
      35             :     {
      36       20736 :       if (elem->p_refinement_flag() == Elem::JUST_REFINED)
      37         900 :         _refined_elements.push_back(elem);
      38       19836 :       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       45368 :     if (elem->refinement_flag() == Elem::JUST_REFINED)
      50             :     {
      51       18256 :       const Elem * const parent = elem->parent();
      52       18256 :       const unsigned int child_num = parent->which_child_am_i(elem);
      53             : 
      54       18256 :       bool im_the_lowest_local_child = true;
      55       63672 :       for (const auto c : make_range(child_num))
      56       90832 :         if (parent->child_ptr(c) && parent->child_ptr(c) != remote_elem &&
      57       45416 :             parent->child_ptr(c)->processor_id() == elem->processor_id())
      58       44641 :           im_the_lowest_local_child = false;
      59             : 
      60       18256 :       if (im_the_lowest_local_child)
      61        3598 :         _refined_elements.push_back(parent);
      62             :     }
      63             : 
      64       27112 :     else if (elem->refinement_flag() == Elem::JUST_COARSENED)
      65             :     {
      66        1365 :       if (elem->has_children())
      67             :       {
      68        1365 :         _coarsened_elements.push_back(elem);
      69             : 
      70        1365 :         std::vector<const Elem *> & children = _coarsened_element_children[elem];
      71             : 
      72        8861 :         for (unsigned int child = 0; child < elem->n_children(); child++)
      73        7496 :           children.push_back(elem->child_ptr(child));
      74             :       }
      75             :     }
      76             :   }
      77       70316 : }
      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