LCOV - code coverage report
Current view: top level - ugbase/lib_grid - grid_debug.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 6 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2009-2021:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Dmitry Logashenko
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__LIBGRID__GRID_DEBUG__
      34              : #define __H__LIBGRID__GRID_DEBUG__
      35              : 
      36              : #include <vector>
      37              : #include <memory>
      38              : 
      39              : // ug4 headers:
      40              : #include "grid/grid.h"
      41              : #include "subset_handler.h"
      42              : 
      43              : namespace ug
      44              : {
      45              : 
      46              : /// Debugging tool for function that do have no direct access to the grid
      47              : /**
      48              :  * This class provides access to grid data in functions that have no
      49              :  * direct access to the grid (e.g. get only a pointer to an element but
      50              :  * need the subsets of the corners etc.).
      51              :  * 
      52              :  * This is the class for the base Grid class.
      53              :  * 
      54              :  * REMARK: THIS IS A PURELY DEBUGGING TOOL! IT MAY NOT BE USED IN THE
      55              :  * NORMAL ROUTINES FOR THE "EVERY-DAY" USE! THIS CLASS CAN BE PATCHED AND
      56              :  * CHANGED ANY TIME, THERE NO STABLE IMPLEMENTATION MAY BE ASSUMED!
      57              :  * 
      58              :  * This class provides a global pointer (which is static in the class)
      59              :  * referencing its single object (only if it is created - otherwise the
      60              :  * pointer is NULL).
      61              :  */
      62              : class grid_global_debug_info_provider
      63              : {
      64              :         typedef grid_global_debug_info_provider this_type;
      65              :         typedef Grid grid_type;
      66              :         
      67              : public:
      68              : 
      69              : ///     creates the object (if it did not exist)
      70              : /**
      71              :  * This function creates the single object of the class.
      72              :  * If the object exists, this function throws and exception
      73              :  * (to prevent the undesired reinitialization during the debugging process).
      74              :  */
      75            0 :         static void create
      76              :         (
      77              :                 grid_type& rGrid, ///< the grid to use
      78              :                 ISubsetHandler& rSH ///< the subset handler to use
      79              :         )
      80              :         {
      81            0 :                 if (the_object == nullptr)
      82            0 :                         the_object.reset (new grid_global_debug_info_provider (rGrid, rSH));
      83              :                 else
      84            0 :                         UG_THROW ("Reinitialization of the grid debugging info provider is not allowed!");
      85            0 :         };
      86              : 
      87              : ///     checks if an element is in a subset
      88              :         static bool elem_in_subset
      89              :         (
      90              :                 GridObject * elem, ///< the element to check
      91              :                 int si ///< subset index to check
      92              :         )
      93              :         {
      94              :                 if (! the_object)
      95              :                         return false;
      96              :                 return the_object->m_pSH->get_subset_index (elem) == si;
      97              :         };
      98              :         
      99              : ///     checks if an element is in subsets from a list
     100              :         static bool elem_in_subsets
     101              :         (
     102              :                 GridObject * elem, ///< the element to check
     103              :                 std::vector<int> si_ar ///< subset indices to check
     104              :         )
     105              :         {
     106              :                 if (! the_object)
     107              :                         return false;
     108              :                 int si = the_object->m_pSH->get_subset_index (elem);
     109              :                 for (size_t i = 0; i < si_ar.size (); i++) if (si == si_ar[i]) return true;
     110              :                 return false;
     111              :         };
     112              : 
     113              : ///     checks if one of the associated elements is in a given subset
     114              :         template <typename TAssElem>
     115              :         static bool ass_elem_in_subset
     116              :         (
     117              :                 GridObject * elem, ///< the element to check
     118              :                 int si ///< subset index to check
     119              :         )
     120              :         {
     121              :                 if (! the_object)
     122              :                         return false;
     123              :                 
     124              :                 typename Grid::traits<TAssElem>::secure_container ass_elem_list;
     125              :                 the_object->m_pGrid->associated_elements (ass_elem_list, elem);
     126              :                 for (size_t i = 0; i < ass_elem_list.size (); i++)
     127              :                         if (the_object->m_pSH->get_subset_index (ass_elem_list [i]) == si)
     128              :                                 return true;
     129              :                 return false;
     130              :         };
     131              :         
     132              : ///     checks if one of the associated elements is in (all or some of the) given subsets
     133              :         template <typename TAssElem>
     134              :         static bool ass_elem_in_subsets
     135              :         (
     136              :                 GridObject * elem, ///< the element to check
     137              :                 std::vector<int> si_ar, ///< subset indices to check
     138              :                 bool in_all = false ///< if to check all the subsets of the list
     139              :         )
     140              :         {
     141              :                 if (! the_object)
     142              :                         return false;
     143              :                 if (si_ar.size () == 0)
     144              :                         return in_all; // dummy value ("sum or product over the empty set")
     145              :                 
     146              :                 typedef unsigned long flags_t;
     147              :                 
     148              :                 flags_t flags = 0, all_flags = 1;
     149              :                 if (in_all)
     150              :                 {
     151              :                         if (si_ar.size () > sizeof (flags_t))
     152              :                                 UG_THROW ("Grid debugging info provider: too many subsets for the in_all flag");
     153              :                         all_flags = (all_flags << si_ar.size ()) - 1; // 1s at the positions of the subset indices
     154              :                 }
     155              :                 
     156              :                 typename Grid::traits<TAssElem>::secure_container ass_elem_list;
     157              :                 int si;
     158              :                 the_object->m_pGrid->associated_elements (ass_elem_list, elem);
     159              :                 for (size_t i = 0; i < ass_elem_list.size (); i++)
     160              :                 {
     161              :                         si = the_object->m_pSH->get_subset_index (ass_elem_list [i]);
     162              :                         for (size_t j = 0; j < si_ar.size (); j++)
     163              :                                 if (si == si_ar [j])
     164              :                                 {
     165              :                                         if (! in_all) return true;
     166              :                                         flags |= ((flags_t) 1) << j;
     167              :                                 }
     168              :                 }
     169              :                 return flags == all_flags;
     170              :         };
     171              :         
     172              : protected:
     173              :         
     174              : /// (protected) constructor
     175              :         grid_global_debug_info_provider
     176              :         (
     177              :                 grid_type& rGrid,
     178              :                 ISubsetHandler& rSH
     179              :         )
     180            0 :         : m_pGrid (&rGrid), m_pSH (&rSH)
     181              :         {
     182              :         };
     183              :         
     184              : private:
     185              : //      Data:
     186              : 
     187              :         static std::unique_ptr<grid_global_debug_info_provider> the_object;
     188              : 
     189              :         grid_type * m_pGrid; ///< current grid
     190              :         ISubsetHandler * m_pSH; ///< current SubsetHandler to use
     191              : };
     192              : 
     193              : } // namespace ug
     194              : 
     195              : #endif // __H__LIBGRID__GRID_DEBUG__
     196              : 
     197              : /* End of File */
        

Generated by: LCOV version 2.0-1