Quinoa all test code coverage report
Current view: top level - Inciter/AMR - marked_refinements_store.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 10 10 100.0 %
Date: 2024-04-22 13:03:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 2 100.0 %

           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                 :            :             std::size_t size() const {
      29                 :            :               return marked_refinements.size();
      30                 :            :             }
      31                 :            : 
      32                 :            :             //! Non-const-ref access to state
      33                 :            :             //! \return Map of marked refinements
      34                 :            :             std::unordered_map<size_t, case_t>& data() {
      35                 :      48730 :               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                 :            :             bool exists(size_t id)
      47                 :            :             {
      48                 :            :                 auto f = marked_refinements.find(id);
      49                 :            :                 if (f != marked_refinements.end())
      50                 :            :                 {
      51                 :            :                     trace_out << "Marked element " << id << " has value " <<
      52                 :            :                         f->second << std::endl;
      53                 :            : 
      54                 :            :                     return true;
      55                 :            :                 }
      56                 :            :                 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                 :            :             case_t& get(size_t id)
      67                 :            :             {
      68                 :            :                 // TODO: is there any performance hit for at?
      69                 :            :                 return marked_refinements.at(id);
      70                 :            :             }
      71                 :            : 
      72                 :            :             void erase(size_t id)
      73                 :            :             {
      74                 :            :                 //marked_refinements[id] = case_t::none;
      75                 :            : 
      76                 :            :                 // Changing to actually erase
      77                 :            :                 marked_refinements.erase(id);
      78                 :            :             }
      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                 :     202396 :             void add(size_t id, case_t r)
      88                 :            :             {
      89                 :            :                 // Check if that active element already exists
      90                 :     404792 :                 if (exists(id))
      91                 :            :                 {
      92         [ +  + ]:     115885 :                     if (marked_refinements[id] != r)
      93                 :            :                     {
      94                 :            :                         trace_out << "Updating marked value to " << r <<
      95                 :            :                             " was " << marked_refinements[id] << std::endl;
      96                 :            : 
      97                 :       4769 :                         marked_refinements[id] = r;
      98                 :            : 
      99                 :            :                         // TODO :Find a better way to handle/update this global
     100                 :       4769 :                         state_changed = true;
     101                 :            :                     }
     102                 :            :                     else {
     103                 :            :                         trace_out << "Not setting marked refinement val as same val"<< std::endl;
     104                 :            :                     }
     105                 :            :                 }
     106                 :            :                 else {
     107                 :            :                     trace_out << "Adding new marked value " << id << " = " << r << std::endl;
     108                 :      86511 :                     marked_refinements.insert( std::pair<size_t, case_t>(id, r));
     109                 :      86511 :                     state_changed = true;
     110                 :            :                 }
     111                 :     202396 :             }
     112                 :            : 
     113                 :            :             /**
     114                 :            :              * @brief Accessor for variable which tracks state change
     115                 :            :              *
     116                 :            :              * @return Bool stating is the state has changed
     117                 :            :              */
     118                 :            :             bool& get_state_changed()
     119                 :            :             {
     120                 :      48730 :                 return state_changed;
     121                 :            :             }
     122                 :            :     };
     123                 :            : }
     124                 :            : 
     125                 :            : #endif // guard

Generated by: LCOV version 1.14