LCOV - code coverage report
Current view: top level - ugbase/lib_grid/tools - subset_handler_grid_impl.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 17 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 32 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2010-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       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__SUBSET_HANDLER_GRID_IMPL__
      34              : #define __H__LIBGRID__SUBSET_HANDLER_GRID_IMPL__
      35              : 
      36              : #include <cassert>
      37              : 
      38              : namespace ug
      39              : {
      40              : 
      41              : template <class TElem>
      42              : typename geometry_traits<TElem>::iterator
      43            0 : GridSubsetHandler::
      44              : begin(int subsetIndex)
      45              : {
      46              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
      47              : 
      48            0 :         if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
      49              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      50              :                                         typename Grid::traits<TElem>::AttachedElementList::iterator());
      51              : 
      52              :         if(sectionInd < 0)
      53              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      54              :                                 section_container<TElem>(subsetIndex).begin());
      55              :         else
      56              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      57              :                                 section_container<TElem>(subsetIndex).section_begin(sectionInd));
      58              : }
      59              : 
      60              : template <class TElem>
      61              : typename geometry_traits<TElem>::iterator
      62            0 : GridSubsetHandler::
      63              : end(int subsetIndex)
      64              : {
      65              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
      66              : 
      67            0 :         if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
      68              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      69              :                                         typename Grid::traits<TElem>::AttachedElementList::iterator());
      70              : 
      71              :         if(sectionInd < 0)
      72              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      73              :                                 section_container<TElem>(subsetIndex).end());
      74              :         else
      75              :                 return iterator_cast<typename geometry_traits<TElem>::iterator>(
      76              :                                 section_container<TElem>(subsetIndex).section_end(sectionInd));
      77              : }
      78              : 
      79              : template <class TElem>
      80              : typename geometry_traits<TElem>::const_iterator
      81            0 : GridSubsetHandler::
      82              : begin(int subsetIndex) const
      83              : {
      84              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
      85              : 
      86            0 :         if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
      87              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
      88              :                                         typename Grid::traits<TElem>::AttachedElementList::iterator());
      89              : 
      90              :         if(sectionInd < 0)
      91              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
      92              :                                 section_container<TElem>(subsetIndex).begin());
      93              :         else
      94              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
      95              :                                 section_container<TElem>(subsetIndex).section_begin(sectionInd));
      96              : }
      97              : 
      98              : template <class TElem>
      99              : typename geometry_traits<TElem>::const_iterator
     100            0 : GridSubsetHandler::
     101              : end(int subsetIndex) const
     102              : {
     103              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
     104              : 
     105            0 :         if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
     106              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
     107              :                                         typename Grid::traits<TElem>::AttachedElementList::iterator());
     108              : 
     109              :         if(sectionInd < 0)
     110              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
     111              :                                 section_container<TElem>(subsetIndex).end());
     112              :         else
     113              :                 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
     114              :                                 section_container<TElem>(subsetIndex).section_end(sectionInd));
     115              : }
     116              : 
     117              : 
     118              : template <class TElem>
     119              : void
     120              : GridSubsetHandler::
     121              : clear_subset_elements(int subsetIndex)
     122              : {
     123              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
     124              : 
     125              :         if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
     126              :                 return;
     127              : 
     128              : //      iterate through the elements of type TElem and erase them from the subsets list.
     129              :         if(m_pGrid != NULL)
     130              :         {
     131              :                 typename Grid::traits<TElem>::SectionContainer& secCon =
     132              :                                                                                         section_container<TElem>(subsetIndex);
     133              : 
     134              :                 typename geometry_traits<TElem>::iterator iter = begin<TElem>(subsetIndex);
     135              :                 while(iter != end<TElem>(subsetIndex))
     136              :                 {
     137              :                         typename geometry_traits<TElem>::iterator iterErase = iter++;
     138              :                         alter_subset_index(*iterErase) = -1;
     139              :                         secCon.erase(iterErase, sectionInd);
     140              :                 }
     141              :         }
     142              : }
     143              : 
     144              : template <class TElem>
     145              : uint
     146              : GridSubsetHandler::
     147              : num_elements(int subsetIndex) const
     148              : {
     149              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
     150              : 
     151            0 :         if((subsetIndex < 0) || (subsetIndex >= (int)num_subsets_in_list()))
     152              :                 return 0;
     153              :                 
     154              :         if(sectionInd < 0)
     155              :                 return section_container<TElem>(subsetIndex).num_elements();
     156              :         else
     157              :                 return section_container<TElem>(subsetIndex).num_elements(sectionInd);
     158              : }
     159              : 
     160              : template <class TElem>
     161              : uint
     162              : GridSubsetHandler::
     163              : num(int subsetIndex) const
     164              : {
     165              :         const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
     166              : 
     167            0 :         if((subsetIndex < 0) || (subsetIndex >= (int)num_subsets_in_list()))
     168              :                 return 0;
     169              : 
     170              :         if(sectionInd < 0)
     171            0 :                 return section_container<TElem>(subsetIndex).num_elements();
     172              :         else
     173              :                 return section_container<TElem>(subsetIndex).num_elements(sectionInd);
     174              : }
     175              : 
     176              : template <class TElem>
     177              : uint
     178              : GridSubsetHandler::
     179              : num() const
     180              : {
     181              :         uint n = 0;
     182              :         for(uint i = 0; i < num_subsets_in_list(); ++i)
     183              :                 n += num<TElem>(i);
     184              :                 
     185              :         return n;
     186              : }
     187              : 
     188              : template <class TElem> inline
     189              : bool GridSubsetHandler::
     190              : empty() const
     191              : {
     192              :         return num<TElem>() == 0;
     193              : }
     194              : 
     195              : inline bool GridSubsetHandler::
     196              : empty() const
     197              : {
     198              :         return empty<Vertex>() && empty<Edge>()
     199              :                    && empty<Face>() && empty<Volume>();
     200              : }
     201              : 
     202              : template <class TElem> inline
     203              : bool GridSubsetHandler::
     204              : empty(int subsetIndex) const
     205              : {
     206              :         return num<TElem>(subsetIndex) == 0;
     207              : }
     208              : 
     209              : inline bool GridSubsetHandler::
     210              : empty(int subsetIndex) const
     211              : {
     212              :         return empty<Vertex>(subsetIndex) && empty<Edge>(subsetIndex)
     213              :                    && empty<Face>(subsetIndex) && empty<Volume>(subsetIndex);
     214              : }
     215              : 
     216              : template<class TElem>
     217            0 : void GridSubsetHandler::
     218              : change_elem_subset_indices(int indOld, int indNew)
     219              : {
     220              :         typedef typename geometry_traits<TElem>::iterator iterator;
     221              :         for(iterator iter = begin<TElem>(indOld);
     222            0 :                 iter != end<TElem>(indOld); iter++){
     223              :                 ISubsetHandler::alter_subset_index(*iter, indNew);
     224              :         }
     225            0 : }
     226              : 
     227              : template <class TElem>
     228              : bool GridSubsetHandler::perform_self_tests()
     229              : {
     230              :         typedef typename geometry_traits<TElem>::iterator iterator;
     231              :         
     232              :         bool bSuccess = true;
     233              :         
     234              :         LOG("performing self tests on GridSubsetHandler\n");
     235              :         LOG("  num subets: " << num_subsets_in_list() << std::endl);
     236              :         
     237              : //      iterate through the subsets and check whether the assigned
     238              : //      elements have the correct subset index
     239              :         LOG("  checking subset indices\n");
     240              :         for(size_t i = 0; i < num_subsets_in_list(); ++i){
     241              :                 LOG("  checking subset " << i);
     242              :                 for(iterator iter = begin<TElem>(i); iter != end<TElem>(i); ++iter)
     243              :                 {
     244              :                         if(get_subset_index(*iter) != i){
     245              :                                 LOG(" bad element subset index: "
     246              :                                         << get_subset_index(*iter));
     247              :                                 bSuccess = false;
     248              :                                 break;
     249              :                         }
     250              :                 }
     251              :                 LOG("\n");
     252              :         }
     253              :         
     254              :         return bSuccess;
     255              : }
     256              : 
     257              : template <class TElem>
     258              : typename Grid::traits<TElem>::SectionContainer&
     259              : GridSubsetHandler::
     260              : section_container(int si)
     261              : {
     262            0 :         Subset* sub = m_subsets[si];
     263              :         return SectionContainerSelector<typename geometry_traits<TElem>::grid_base_object>::
     264            0 :                         section_container(sub->m_vertices, sub->m_edges, sub->m_faces, sub->m_volumes);
     265              : }
     266              : 
     267              : 
     268              : template <class TElem>
     269              : const typename Grid::traits<TElem>::SectionContainer&
     270              : GridSubsetHandler::
     271              : section_container(int si) const
     272              : {
     273            0 :         const Subset* sub = m_subsets[si];
     274              :         return SectionContainerSelector<typename geometry_traits<TElem>::grid_base_object>::
     275              :                         section_container(sub->m_vertices, sub->m_edges, sub->m_faces, sub->m_volumes);
     276              : }
     277              : 
     278              : }//     end of namespace
     279              : 
     280              : #endif
     281              : 
        

Generated by: LCOV version 2.0-1