Xyst test code coverage report
Current view: top level - Inciter/AMR - marked_refinements_store.hpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 100.0 % 28 28
Test Date: 2025-08-13 22:46:33 Functions: 100.0 % 14 14
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 80.0 % 10 8

             Branch data     Line data    Source code
       1                 :             : #ifndef AMR_marked_refinements_store_h
       2                 :             : #define AMR_marked_refinements_store_h
       3                 :             : 
       4                 :             : #include <unordered_map>
       5                 :             : #include "Refinement_State.hpp"
       6                 :             : 
       7                 :             : namespace AMR {
       8                 :             : 
       9                 :             :     /**
      10                 :             :      * @brief This class stores the decisions made during the iterative AMR
      11                 :             :      * algorithm.
      12                 :             :      *
      13                 :             :      * The template parameter determines the internal enum type.
      14                 :             :      */
      15                 :             :     template<class case_t> class marked_refinements_store_t {
      16                 :             :         private:
      17                 :             :             // TODO: make this have a more generic name
      18                 :             :             std::unordered_map<size_t, case_t> marked_refinements;
      19                 :             : 
      20                 :             :             // TODO: This may not be right place for this
      21                 :             :             // We will use this variable to check if anything has changed
      22                 :             :             // during a round of refinement marking
      23                 :             :             bool state_changed = false;
      24                 :             : 
      25                 :             :         public:
      26                 :             :             //! Const-ref access to number of tets
      27                 :             :             //! \return Map of marked refinements
      28                 :         142 :             std::size_t size() const {
      29                 :         142 :               return marked_refinements.size();
      30                 :             :             }
      31                 :             : 
      32                 :             :             //! Non-const-ref access to state
      33                 :             :             //! \return Map of marked refinements
      34                 :       27232 :             std::unordered_map<size_t, case_t>& data() {
      35                 :       27232 :               return marked_refinements;
      36                 :             :             }
      37                 :             : 
      38                 :             :             /**
      39                 :             :              * @brief function to see if a given id has already had a
      40                 :             :              * refinement decision made
      41                 :             :              *
      42                 :             :              * @param id The tet_id to check
      43                 :             :              *
      44                 :             :              * @return A bool stating if a refinement decision/marking exists
      45                 :             :              */
      46                 :      211970 :             bool exists(size_t id)
      47                 :             :             {
      48         [ +  - ]:      211970 :                 auto f = marked_refinements.find(id);
      49         [ +  + ]:      211970 :                 if (f != marked_refinements.end())
      50                 :             :                 {
      51                 :       66512 :                     trace_out << "Marked element " << id << " has value " <<
      52                 :             :                         f->second << std::endl;
      53                 :             : 
      54                 :       66512 :                     return true;
      55                 :             :                 }
      56                 :      145458 :                 return false;
      57                 :             :             }
      58                 :             : 
      59                 :             :             /**
      60                 :             :              * @brief Accessor function to get a marked_refinement from the store
      61                 :             :              *
      62                 :             :              * @param id The id of the tet to fetch the marked_refinement for
      63                 :             :              *
      64                 :             :              * @return The marked refinement case for the given tet
      65                 :             :              */
      66                 :       29981 :             case_t& get(size_t id)
      67                 :             :             {
      68                 :             :                 // TODO: is there any performance hit for at?
      69                 :       29981 :                 return marked_refinements.at(id);
      70                 :             :             }
      71                 :             : 
      72                 :       29981 :             void erase(size_t id)
      73                 :             :             {
      74                 :             :                 //marked_refinements[id] = case_t::none;
      75                 :             : 
      76                 :             :                 // Changing to actually erase
      77                 :       29981 :                 marked_refinements.erase(id);
      78                 :       29981 :             }
      79                 :             : 
      80                 :             :             /**
      81                 :             :              * @brief Function to add a marked refinement to the store, which
      82                 :             :              * is context aware based on existing values
      83                 :             :              *
      84                 :             :              * @param id The id of the tet to mark
      85                 :             :              * @param r The refinement decision for the tet
      86                 :             :              */
      87                 :       66512 :             void add(size_t id, case_t r)
      88                 :             :             {
      89                 :             :                 // Check if that active element already exists
      90         [ +  + ]:       66512 :                 if (exists(id))
      91                 :             :                 {
      92         [ +  + ]:       36531 :                     if (marked_refinements[id] != r)
      93                 :             :                     {
      94                 :         250 :                         trace_out << "Updating marked value to " << r <<
      95                 :             :                             " was " << marked_refinements[id] << std::endl;
      96                 :             : 
      97                 :         250 :                         marked_refinements[id] = r;
      98                 :             : 
      99                 :             :                         // TODO :Find a better way to handle/update this global
     100                 :         250 :                         state_changed = true;
     101                 :             :                     }
     102                 :             :                     else {
     103                 :       36281 :                         trace_out << "Not setting marked refinement val as same val"<< std::endl;
     104                 :             :                     }
     105                 :             :                 }
     106                 :             :                 else {
     107                 :       29981 :                     trace_out << "Adding new marked value " << id << " = " << r << std::endl;
     108         [ +  - ]:       29981 :                     marked_refinements.insert( std::pair<size_t, case_t>(id, r));
     109                 :       29981 :                     state_changed = true;
     110                 :             :                 }
     111                 :       66512 :             }
     112                 :             : 
     113                 :             :             /**
     114                 :             :              * @brief Accessor for variable which tracks state change
     115                 :             :              *
     116                 :             :              * @return Bool stating is the state has changed
     117                 :             :              */
     118                 :       27576 :             bool& get_state_changed()
     119                 :             :             {
     120                 :       27576 :                 return state_changed;
     121                 :             :             }
     122                 :             :     };
     123                 :             : }
     124                 :             : 
     125                 :             : #endif // guard
        

Generated by: LCOV version 2.0-1