LCOV - code coverage report
Current view: top level - ugbase/lib_grid/grid - grid_util_impl.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 3.4 % 89 3
Test Date: 2025-09-21 23:31:46 Functions: 12.5 % 8 1

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2009-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__LIB_GRID__GRID_UTIL_IMPL__
      34              : #define __H__LIB_GRID__GRID_UTIL_IMPL__
      35              : 
      36              : #include <vector>
      37              : #include "grid_util.h"
      38              : #include "common/assert.h"
      39              : #include "common/common.h"
      40              : 
      41              : namespace ug
      42              : {
      43              : ////////////////////////////////////////////////////////////////////////
      44              : //      EdgeContains
      45            0 : inline bool EdgeContains(EdgeVertices* e, Vertex* vrt)
      46              : {
      47            0 :         return e->vertex(0) == vrt || e->vertex(1) == vrt;
      48              : }
      49              : 
      50              : inline bool EdgeContains(EdgeVertices* e, Vertex* vrt1, Vertex* vrt2)
      51              : {
      52              :         return ((e->vertex(0) == vrt1 && e->vertex(1) == vrt2)
      53              :                         || (e->vertex(1) == vrt1 && e->vertex(0) == vrt2));
      54              : }
      55              : 
      56              : ////////////////////////////////////////////////////////////////////////
      57              : ////////////////////////////////////////////////////////////////////////
      58              : //      new methods
      59              : 
      60              : ////////////////////////////////////////////////////////////////////////
      61              : template <class TVrtContainer1, class TVrtContainer2>
      62              : bool CompareVertexContainer(const TVrtContainer1& con1,
      63              :                                         const TVrtContainer2& con2)
      64              : {
      65              :         int con1Size = (int)con1.size();
      66              : 
      67              :         if(con1Size != con2.size())
      68              :                 return false;
      69              : 
      70              :         for(int i = 0; i < con1Size; ++i)
      71              :         {
      72              :                 int j;
      73              :                 for(j = 0; j < con1Size; ++j)
      74              :                 {
      75              :                         if(con1[i] == con2[j])
      76              :                                 break;
      77              :                 }
      78              : 
      79              :         //      check whether we found a matching vertex
      80              :                 if(j == con1Size)
      81              :                         return false;
      82              :         }
      83              : 
      84              :         return true;
      85              : }
      86              : 
      87              : 
      88            2 : inline bool CompareVertices(const EdgeVertices* ev1,
      89              :                                         const EdgeVertices* ev2)
      90              : {
      91            4 :         if((ev1->vertex(0) == ev2->vertex(0) && ev1->vertex(1) == ev2->vertex(1)) ||
      92            2 :                 (ev1->vertex(0) == ev2->vertex(1) && ev1->vertex(1) == ev2->vertex(0)))
      93            0 :                 return true;
      94              :         return false;
      95              : }
      96              : 
      97              : ////////////////////////////////////////////////////////////////////////
      98              : //      GetVertex
      99              : inline Vertex* GetVertex(Vertex* vrt, size_t i)
     100              : {
     101              :         UG_ASSERT(i < 1, "A Vertex has only one vertex");
     102              :         return vrt;
     103              : }
     104              : 
     105              : inline Vertex* GetVertex(Edge* edge, size_t i)
     106              : {
     107              :         UG_ASSERT(i < edge->num_vertices(), "Wrong number of vertex");
     108            0 :         return edge->vertex(i);
     109              : }
     110              : 
     111              : inline Vertex* GetVertex(Face* face, size_t i)
     112              : {
     113              :         UG_ASSERT(i < face->num_vertices(), "Wrong number of vertex");
     114            0 :         return face->vertex(i);
     115              : }
     116              : 
     117              : inline Vertex* GetVertex(Volume* vol, size_t i)
     118              : {
     119              :         UG_ASSERT(i < vol->num_vertices(), "Wrong number of vertex");
     120            0 :         return vol->vertex(i);
     121              : }
     122              : 
     123              : inline size_t NumVertices(Vertex* elem)
     124              : {
     125              :         return 1;
     126              : }
     127              : 
     128              : inline size_t NumVertices(Edge* elem)
     129              : {
     130            0 :         return elem->num_vertices();
     131              : }
     132              : 
     133              : inline size_t NumVertices(Face* elem)
     134              : {
     135            0 :         return elem->num_vertices();
     136              : }
     137              : 
     138              : inline size_t NumVertices(Volume* elem)
     139              : {
     140            0 :         return elem->num_vertices();
     141              : }
     142              : 
     143              : 
     144              : ////////////////////////////////////////////////////////////////////////
     145              : inline void CollectAssociated(std::vector<Vertex*>& vVertexOut,
     146              :                                           Grid& grid, Vertex* v, bool clearContainer)
     147              : {
     148            0 :         CollectVertices(vVertexOut, grid, v, clearContainer);
     149            0 : }
     150              : 
     151              : inline void CollectAssociated(std::vector<Vertex*>& vVertexOut,
     152              :                                            Grid& grid, Edge* e, bool clearContainer)
     153              : {
     154            0 :         CollectVertices(vVertexOut, grid, e, clearContainer);
     155            0 : }
     156              : 
     157              : inline void CollectAssociated(std::vector<Vertex*>& vVertexOut,
     158              :                                            Grid& grid, Face* f, bool clearContainer)
     159              : {
     160            0 :         CollectVertices(vVertexOut, grid, f, clearContainer);
     161            0 : }
     162              : 
     163              : inline void CollectAssociated(std::vector<Vertex*>& vVertexOut,
     164              :                                            Grid& grid, Volume* v, bool clearContainer)
     165              : {
     166            0 :         CollectVertices(vVertexOut, grid, v, clearContainer);
     167            0 : }
     168              : 
     169            0 : inline void CollectAssociated(std::vector<Vertex*>& vVertexOut,
     170              :                               Grid& grid, GridObject* obj, bool clearContainer)
     171              : {
     172            0 :         uint type = obj->base_object_id();
     173            0 :         switch(type)
     174              :         {
     175            0 :                 case VERTEX:CollectAssociated(vVertexOut, grid, reinterpret_cast<Vertex*>(obj), clearContainer); return;
     176            0 :                 case EDGE:      CollectAssociated(vVertexOut, grid, reinterpret_cast<Edge*>(obj), clearContainer); return;
     177            0 :                 case FACE:      CollectAssociated(vVertexOut, grid, reinterpret_cast<Face*>(obj), clearContainer); return;
     178            0 :                 case VOLUME:CollectAssociated(vVertexOut, grid, reinterpret_cast<Volume*>(obj), clearContainer); return;
     179              :         }
     180            0 :         throw(UGError("GeomObject type not known."));
     181              : }
     182              : 
     183              : 
     184              : ////////////////////////////////////////////////////////////////////////
     185              : inline void CollectAssociated(std::vector<Edge*>& vEdgesOut,
     186              :                                         Grid& grid, Vertex* vrt, bool clearContainer)
     187              : {
     188            0 :         CollectEdges(vEdgesOut, grid, vrt, clearContainer);
     189            0 : }
     190              : 
     191              : inline void CollectAssociated(std::vector<Edge*>& vEdgesOut,
     192              :                                         Grid& grid, Edge* e, bool clearContainer)
     193              : {
     194            0 :         CollectEdges(vEdgesOut, grid, e, clearContainer);
     195            0 : }
     196              : 
     197              : inline void CollectAssociated(std::vector<Edge*>& vEdgesOut,
     198              :                                         Grid& grid, Face* f, bool clearContainer)
     199              : {
     200            0 :         CollectEdges(vEdgesOut, grid, f, clearContainer);
     201            0 : }
     202              : 
     203              : inline void CollectAssociated(std::vector<Edge*>& vEdgesOut,
     204              :                                         Grid& grid, Volume* v, bool clearContainer)
     205              : {
     206            0 :         CollectEdges(vEdgesOut, grid, v, clearContainer);
     207            0 : }
     208              : 
     209            0 : inline void CollectAssociated(std::vector<Edge*>& vEdgesOut,
     210              :                               Grid& grid, GridObject* obj, bool clearContainer)
     211              : {
     212            0 :         uint type = obj->base_object_id();
     213            0 :         switch(type)
     214              :         {
     215            0 :                 case VERTEX:CollectAssociated(vEdgesOut, grid, reinterpret_cast<Vertex*>(obj), clearContainer); return;
     216            0 :                 case EDGE:      CollectAssociated(vEdgesOut, grid, reinterpret_cast<Edge*>(obj), clearContainer); return;
     217            0 :                 case FACE:      CollectAssociated(vEdgesOut, grid, reinterpret_cast<Face*>(obj), clearContainer); return;
     218            0 :                 case VOLUME:CollectAssociated(vEdgesOut, grid, reinterpret_cast<Volume*>(obj), clearContainer); return;
     219              :         }
     220            0 :         throw(UGError("GeomObject type not known."));
     221              : }
     222              : 
     223              : 
     224              : ////////////////////////////////////////////////////////////////////////
     225              : inline void CollectAssociated(std::vector<Face*>& vFacesOut,
     226              :                                         Grid& grid, Vertex* vrt, bool clearContainer)
     227              : {
     228            0 :         CollectFaces(vFacesOut, grid, vrt, clearContainer);
     229            0 : }
     230              : 
     231              : inline void CollectAssociated(std::vector<Face*>& vFacesOut,
     232              :                                         Grid& grid, Edge* e, bool clearContainer)
     233              : {
     234            0 :         CollectFaces(vFacesOut, grid, e, clearContainer);
     235            0 : }
     236              : 
     237              : inline void CollectAssociated(std::vector<Face*>& vFacesOut,
     238              :                                         Grid& grid, Face* f, bool clearContainer)
     239              : {
     240            0 :         CollectFaces(vFacesOut, grid, f, clearContainer);
     241            0 : }
     242              : 
     243              : inline void CollectAssociated(std::vector<Face*>& vFacesOut,
     244              :                                         Grid& grid, Volume* v, bool clearContainer)
     245              : {
     246            0 :         CollectFaces(vFacesOut, grid, v, clearContainer);
     247            0 : }
     248              : 
     249            0 : inline void CollectAssociated(std::vector<Face*>& vFacesOut,
     250              :                               Grid& grid, GridObject* obj, bool clearContainer)
     251              : {
     252            0 :         uint type = obj->base_object_id();
     253            0 :         switch(type)
     254              :         {
     255            0 :                 case VERTEX:CollectAssociated(vFacesOut, grid, reinterpret_cast<Vertex*>(obj), clearContainer); return;
     256            0 :                 case EDGE:      CollectAssociated(vFacesOut, grid, reinterpret_cast<Edge*>(obj), clearContainer); return;
     257            0 :                 case FACE:      CollectAssociated(vFacesOut, grid, reinterpret_cast<Face*>(obj), clearContainer); return;
     258            0 :                 case VOLUME:CollectAssociated(vFacesOut, grid, reinterpret_cast<Volume*>(obj), clearContainer); return;
     259              :         }
     260            0 :         throw(UGError("GeomObject type not known."));
     261              : }
     262              : 
     263              : 
     264              : ////////////////////////////////////////////////////////////////////////
     265              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     266              :                                         Grid& grid, Vertex* vrt, bool clearContainer)
     267              : {
     268            0 :         CollectVolumes(vVolumesOut, grid, vrt, clearContainer);
     269            0 : }
     270              : 
     271              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     272              :                                         Grid& grid, Edge* e, bool clearContainer)
     273              : {
     274            0 :         CollectVolumes(vVolumesOut, grid, e, clearContainer);
     275            0 : }
     276              : 
     277              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     278              :                                         Grid& grid, Face* f, bool clearContainer,
     279              :                                         bool ignoreAssociatedVolumes)
     280              : {
     281            0 :         CollectVolumes(vVolumesOut, grid, f, clearContainer, ignoreAssociatedVolumes);
     282            0 : }
     283              : 
     284              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     285              :                                         Grid& grid, Volume* vol, bool clearContainer)
     286              : {
     287            0 :         CollectVolumes(vVolumesOut, grid, vol, clearContainer);
     288            0 : }
     289              : 
     290              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     291              :                                         Grid& grid, FaceDescriptor& fd, bool clearContainer)
     292              : {
     293              :         CollectVolumes(vVolumesOut, grid, fd, clearContainer);
     294              : }
     295              : 
     296              : inline void CollectAssociated(std::vector<Volume*>& vVolumesOut,
     297              :                               Grid& grid, GridObject* obj, bool clearContainer)
     298              : {
     299              :         uint type = obj->base_object_id();
     300              :         switch(type)
     301              :         {
     302              :                 case VERTEX:CollectAssociated(vVolumesOut, grid, reinterpret_cast<Vertex*>(obj), clearContainer); return;
     303              :                 case EDGE:      CollectAssociated(vVolumesOut, grid, reinterpret_cast<Edge*>(obj), clearContainer); return;
     304              :                 case FACE:      CollectAssociated(vVolumesOut, grid, reinterpret_cast<Face*>(obj), clearContainer); return;
     305              :                 case VOLUME:CollectAssociated(vVolumesOut, grid, reinterpret_cast<Volume*>(obj), clearContainer); return;
     306              :         }
     307              :         throw(UGError("GeomObject type not known."));
     308              : }
     309              : 
     310              : ////////////////////////////////////////////////////////////////////////////////
     311              : ////////////////////////////////////////////////////////////////////////////////
     312              : 
     313            0 : inline void CollectVertices(std::vector<Vertex*>& vVertexOut, Grid& grid,
     314              :                                                         GridObject* obj, bool clearContainer)
     315              : {
     316            0 :         switch(obj->base_object_id())
     317              :         {
     318            0 :                 case VERTEX:CollectVertices(vVertexOut, grid, static_cast<Vertex*>(obj), clearContainer); return;
     319            0 :                 case EDGE:      CollectVertices(vVertexOut, grid, static_cast<Edge*>(obj), clearContainer); return;
     320            0 :                 case FACE:      CollectVertices(vVertexOut, grid, static_cast<Face*>(obj), clearContainer); return;
     321            0 :                 case VOLUME:CollectVertices(vVertexOut, grid, static_cast<Volume*>(obj), clearContainer); return;
     322              :         }
     323            0 :         throw(UGError("GeomObject type not known."));
     324              : }
     325              : 
     326            0 : inline void CollectEdgesSorted(std::vector<Edge*>& vEdgesOut, Grid& grid,
     327              :                                                         GridObject* obj, bool clearContainer)
     328              : {
     329            0 :         switch(obj->base_object_id())
     330              :         {
     331            0 :                 case VERTEX:CollectEdgesSorted(vEdgesOut, grid, static_cast<Vertex*>(obj), clearContainer); return;
     332            0 :                 case EDGE:      CollectEdgesSorted(vEdgesOut, grid, static_cast<Edge*>(obj), clearContainer); return;
     333            0 :                 case FACE:      CollectEdgesSorted(vEdgesOut, grid, static_cast<Face*>(obj), clearContainer); return;
     334            0 :                 case VOLUME:CollectEdgesSorted(vEdgesOut, grid, static_cast<Volume*>(obj), clearContainer); return;
     335              :         }
     336            0 :         throw(UGError("GeomObject type not known."));
     337              : }
     338              : 
     339            0 : inline void CollectFacesSorted(std::vector<Face*>& vFacesOut, Grid& grid,
     340              :                                                         GridObject* obj, bool clearContainer)
     341              : {
     342            0 :         switch(obj->base_object_id())
     343              :         {
     344            0 :                 case VERTEX:CollectFacesSorted(vFacesOut, grid, static_cast<Vertex*>(obj), clearContainer); return;
     345            0 :                 case EDGE:      CollectFacesSorted(vFacesOut, grid, static_cast<Edge*>(obj), clearContainer); return;
     346            0 :                 case FACE:      CollectFacesSorted(vFacesOut, grid, static_cast<Face*>(obj), clearContainer); return;
     347            0 :                 case VOLUME:CollectFacesSorted(vFacesOut, grid, static_cast<Volume*>(obj), clearContainer); return;
     348              :         }
     349            0 :         throw(UGError("GeomObject type not known."));
     350              : }
     351              : 
     352              : }//     end of namespace libGrid
     353              : 
     354              : #endif
        

Generated by: LCOV version 2.0-1