LCOV - code coverage report
Current view: top level - include/mesh - sync_refinement_flags.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 19 19 100.0 %
Date: 2025-08-19 19:27:09 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : 
      20             : #ifndef LIBMESH_SYNC_REFINEMENT_FLAGS_H
      21             : #define LIBMESH_SYNC_REFINEMENT_FLAGS_H
      22             : 
      23             : // Local includes
      24             : #include "libmesh/libmesh_config.h"
      25             : 
      26             : // Only compile these functions if the user requests AMR support
      27             : #ifdef LIBMESH_ENABLE_AMR
      28             : 
      29             : // libMesh includes
      30             : #include "libmesh/elem.h"
      31             : #include "libmesh/int_range.h"
      32             : #include "libmesh/mesh_base.h"
      33             : 
      34             : // C++ includes
      35             : #include <vector>
      36             : 
      37             : namespace libMesh {
      38             : 
      39             : struct SyncRefinementFlags
      40             : {
      41             :   typedef unsigned char datum;
      42             :   typedef Elem::RefinementState (Elem::*get_a_flag)() const;
      43             :   typedef void (Elem::*set_a_flag)(const Elem::RefinementState);
      44             : 
      45        4264 :   SyncRefinementFlags(MeshBase & _mesh,
      46             :                       get_a_flag _getter,
      47      209553 :                       set_a_flag _setter) :
      48      202137 :     mesh(_mesh), parallel_consistent(true),
      49      209553 :     get_flag(_getter), set_flag(_setter) {}
      50             : 
      51             :   MeshBase & mesh;
      52             :   bool parallel_consistent;
      53             :   get_a_flag get_flag;
      54             :   set_a_flag set_flag;
      55             :   // References to pointers to member functions segfault?
      56             :   // get_a_flag & get_flag;
      57             :   // set_a_flag & set_flag;
      58             : 
      59             :   // Find the refinement flag on each requested element
      60      788072 :   void gather_data (const std::vector<dof_id_type> & ids,
      61             :                     std::vector<datum> & flags) const
      62             :   {
      63      791128 :     flags.resize(ids.size());
      64             : 
      65    27220217 :     for (auto i : index_range(ids))
      66             :       {
      67             :         // Look for this element in the mesh
      68             :         // We'd better find every element we're asked for
      69    27373661 :         Elem & elem = mesh.elem_ref(ids[i]);
      70             : 
      71             :         // Return the element's refinement flag
      72    26432145 :         flags[i] = (elem.*get_flag)();
      73             :       }
      74      788072 :   }
      75             : 
      76      788072 :   void act_on_data (const std::vector<dof_id_type> & ids,
      77             :                     const std::vector<datum> & flags)
      78             :   {
      79    27220217 :     for (auto i : index_range(ids))
      80             :       {
      81    27373661 :         Elem & elem = mesh.elem_ref(ids[i]);
      82             : 
      83    26432145 :         datum old_flag = (elem.*get_flag)();
      84    26432145 :         datum new_flag = flags[i];
      85             : 
      86    26432145 :         if (old_flag != new_flag)
      87             :           {
      88             :             // It's possible for foreign flags to be (temporarily) more
      89             :             // conservative than our own, such as when a refinement in
      90             :             // one of the foreign processor's elements is mandated by a
      91             :             // refinement in one of our neighboring elements it can see
      92             :             // which was mandated by a refinement in one of our
      93             :             // neighboring elements it can't see
      94             :             // libmesh_assert (!(new_flag != Elem::REFINE &&
      95             :             //                   old_flag == Elem::REFINE));
      96             :             //
      97             :             (elem.*set_flag)
      98        8620 :               (static_cast<Elem::RefinementState>(new_flag));
      99        8620 :             parallel_consistent = false;
     100             :           }
     101             :       }
     102      788072 :   }
     103             : };
     104             : 
     105             : 
     106             : 
     107             : } // namespace libMesh
     108             : 
     109             : 
     110             : #endif // LIBMESH_ENABLE_AMR
     111             : 
     112             : #endif // LIBMESH_SYNC_REFINEMENT_FLAGS_H

Generated by: LCOV version 1.14