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

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2013-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__UG__multi_grid_child_info__
      34              : #define __H__UG__multi_grid_child_info__
      35              : 
      36              : #include <vector>
      37              : #include "common/error.h"
      38              : #include "common/assert.h"
      39              : #include "lib_grid/grid/grid_base_objects.h"
      40              : namespace ug{
      41              : 
      42              : 
      43              : //      Predeclaration
      44              : class MultiGrid;
      45              : 
      46              : //      The following constants define the maximum number of children
      47              : //      for edges amd faces.
      48              : //      Note that no constants are defined for volumes since the range of
      49              : //      possible children is too high (especially during adaptive refinement)
      50              : const int MG_EDGE_MAX_EDGE_CHILDREN = 2;///< maximal number of edges that can be children of an edge.
      51              : const int MG_FACE_MAX_EDGE_CHILDREN = 4;///< maximal number of edges that can be children of a face.
      52              : const int MG_FACE_MAX_FACE_CHILDREN = 4;///< maximal number of faces that can be children of a face.
      53              : 
      54              : ///     Holds information about vertex relations. Used internally.
      55              : /**
      56              :  * a vertex can have one of the following states:
      57              :  * MGES_NORMAL, MGES_CONSTRAINED, MGES_FIXED
      58              :  * the following should always hold true:
      59              :  * children of a constrained node are constrained, too.
      60              :  * children of a fixed node are fixed, too.
      61              :  */
      62              : struct MGVertexInfo
      63              : {
      64            0 :         MGVertexInfo() : m_pParent(NULL), m_pVrtChild(NULL)             {}
      65            0 :         inline void clear_children()    {m_pVrtChild = NULL;}
      66            0 :         inline bool has_children() const {return m_pVrtChild != NULL;}
      67            0 :         inline void add_child(Vertex* elem)             {assert(!m_pVrtChild); m_pVrtChild = elem;}
      68            0 :         inline void add_child(Edge*)                    {UG_THROW("INVALID OPERATION!");}//dummy...
      69            0 :         inline void add_child(Face*)                            {UG_THROW("INVALID OPERATION!");}//dummy...
      70            0 :         inline void add_child(Volume*)                          {UG_THROW("INVALID OPERATION!");}//dummy...
      71            0 :         inline void remove_child(Vertex* elem)  {m_pVrtChild = NULL;}
      72            0 :         inline void remove_child(Edge*)                 {UG_THROW("INVALID OPERATION!");}//dummy...
      73            0 :         inline void remove_child(Face*)                         {UG_THROW("INVALID OPERATION!");}//dummy...
      74            0 :         inline void remove_child(Volume*)                       {UG_THROW("INVALID OPERATION!");}//dummy...
      75            0 :         inline void replace_child(Vertex* elem, Vertex* child)  {assert(child == m_pVrtChild); m_pVrtChild = elem;}
      76              :         void unregister_from_children(MultiGrid& mg);
      77            0 :         size_t num_child_vertices() const       {return m_pVrtChild ? 1 : 0;}
      78              : 
      79            0 :         Vertex* child_vertex() const {return m_pVrtChild;}
      80              : 
      81              :         GridObject*     m_pParent;
      82              : private:
      83              :         Vertex*                 m_pVrtChild;
      84              : };
      85              : 
      86              : ///     Holds information about edge relations. Used internally.
      87              : /**
      88              :  * an edge can have one of the following states:
      89              :  * MGES_NORMAL, MGES_CONSTRAINING, MGES_CONSTRAINED
      90              :  * the following should always hold true:
      91              :  * children of a constraining edge are constrained.
      92              :  * children of a constrained edge are constrained.
      93              :  */
      94              : struct MGEdgeInfo
      95              : {
      96            0 :         MGEdgeInfo() : m_pParent(NULL), m_pVrtChild(NULL), m_numEdgeChildren(0)         {}
      97            0 :         inline void clear_children()    {m_pVrtChild = NULL; m_numEdgeChildren = 0;}
      98            0 :         inline bool has_children() const {return m_pVrtChild || m_numEdgeChildren;}
      99            0 :         inline void add_child(Vertex* elem)     {assert(!m_pVrtChild); m_pVrtChild = elem;}
     100            0 :         inline void add_child(Edge* elem)       {assert(m_numEdgeChildren < MG_EDGE_MAX_EDGE_CHILDREN); m_pEdgeChild[m_numEdgeChildren++] = elem;}
     101            0 :         inline void add_child(Face*)                    {UG_THROW("INVALID OPERATION!");}//dummy...
     102            0 :         inline void add_child(Volume*)                  {UG_THROW("INVALID OPERATION!");}//dummy...
     103            0 :         inline void remove_child(Vertex* elem)  {m_pVrtChild = NULL;}
     104            0 :         inline void remove_child(Edge* elem)    {m_numEdgeChildren = ArrayEraseEntry(m_pEdgeChild, elem, m_numEdgeChildren);}
     105            0 :         inline void remove_child(Face*)                         {UG_THROW("INVALID OPERATION!");}//dummy...
     106            0 :         inline void remove_child(Volume*)                       {UG_THROW("INVALID OPERATION!");}//dummy...
     107            0 :         inline void replace_child(Vertex* elem, Vertex* child)  {assert(child == m_pVrtChild); m_pVrtChild = elem;}
     108            0 :         inline void replace_child(Edge* elem, Edge* child)              {ArrayReplaceEntry(m_pEdgeChild, elem, child, m_numEdgeChildren);}
     109              :         void unregister_from_children(MultiGrid& mg);
     110            0 :         size_t num_child_vertices() const       {return m_pVrtChild ? 1 : 0;}
     111            0 :         size_t num_child_edges() const          {return m_numEdgeChildren;}
     112              : 
     113            0 :         Vertex* child_vertex() const            {return m_pVrtChild;}
     114            0 :         Edge* child_edge(size_t i) const        {assert(i < num_child_edges()); return m_pEdgeChild[i];}
     115              : 
     116              :         GridObject*     m_pParent;
     117              : private:
     118              :         Vertex*                 m_pVrtChild;
     119              :         Edge*                   m_pEdgeChild[MG_EDGE_MAX_EDGE_CHILDREN];
     120              :         byte                            m_numEdgeChildren;
     121              : };
     122              : 
     123              : ///     Holds information about face relations. Used internally.
     124              : /**     No parent included, since MGFaceInfos are not stored for surface elements.*/
     125              : struct MGFaceInfo
     126              : {
     127            0 :         MGFaceInfo() : m_pVrtChild(NULL), m_numEdgeChildren(0), m_numFaceChildren(0)    {}
     128            0 :         inline void clear_children()    {m_pVrtChild = NULL; m_numEdgeChildren = m_numFaceChildren = 0;}
     129            0 :         inline bool has_children() const {return m_pVrtChild || m_numEdgeChildren || m_numFaceChildren;}
     130            0 :         inline void add_child(Vertex* elem)     {assert(!m_pVrtChild); m_pVrtChild = elem;}
     131            0 :         inline void add_child(Edge* elem)       {assert(m_numEdgeChildren < MG_FACE_MAX_EDGE_CHILDREN); m_pEdgeChild[m_numEdgeChildren++] = elem;}
     132            0 :         inline void add_child(Face* elem)               {assert(m_numFaceChildren < MG_FACE_MAX_FACE_CHILDREN); m_pFaceChild[m_numFaceChildren++] = elem;}
     133            0 :         inline void add_child(Volume*)                  {UG_THROW("INVALID OPERATION!");}//dummy...
     134            0 :         inline void remove_child(Vertex* elem)  {m_pVrtChild = NULL;}
     135            0 :         inline void remove_child(Edge* elem)    {m_numEdgeChildren = ArrayEraseEntry(m_pEdgeChild, elem, m_numEdgeChildren);}
     136            0 :         inline void remove_child(Face* elem)            {m_numFaceChildren = ArrayEraseEntry(m_pFaceChild, elem, m_numFaceChildren);}
     137            0 :         inline void remove_child(Volume*)                       {UG_THROW("INVALID OPERATION!");}//dummy...
     138            0 :         inline void replace_child(Vertex* elem, Vertex* child)  {assert(child == m_pVrtChild); m_pVrtChild = elem;}
     139            0 :         inline void replace_child(Edge* elem, Edge* child)              {ArrayReplaceEntry(m_pEdgeChild, elem, child, m_numEdgeChildren);}
     140            0 :         inline void replace_child(Face* elem, Face* child)                              {ArrayReplaceEntry(m_pFaceChild, elem, child, m_numFaceChildren);}
     141              :         void unregister_from_children(MultiGrid& mg);
     142              : 
     143            0 :         size_t num_child_vertices() const       {return m_pVrtChild ? 1 : 0;}
     144            0 :         size_t num_child_edges() const          {return m_numEdgeChildren;}
     145            0 :         size_t num_child_faces() const          {return m_numFaceChildren;}
     146              : 
     147            0 :         Vertex* child_vertex() const {return m_pVrtChild;}
     148            0 :         Edge* child_edge(size_t i) const        {assert(i < num_child_edges()); return m_pEdgeChild[i];}
     149            0 :         Face* child_face(size_t i) const                {assert(i < num_child_faces()); return m_pFaceChild[i];}
     150              : 
     151              : private:
     152              :         Vertex*                 m_pVrtChild;
     153              :         Edge*                   m_pEdgeChild[MG_FACE_MAX_EDGE_CHILDREN];
     154              :         Face*                           m_pFaceChild[MG_FACE_MAX_FACE_CHILDREN];
     155              :         byte                            m_numEdgeChildren;
     156              :         byte                            m_numFaceChildren;
     157              : };
     158              : 
     159              : ///     Holds information about volume relations. Used internally.
     160              : /**     No parent included, since MGFaceInfos are not stored for surface elements.*/
     161              : struct MGVolumeInfo
     162              : {
     163            0 :         MGVolumeInfo() : m_pVrtChild(NULL)              {}
     164            0 :         inline void clear_children()    {m_pVrtChild = NULL; m_edgeChildren.clear(); m_faceChildren.clear(); m_volumeChildren.clear();}
     165            0 :         inline bool has_children()      const {return m_pVrtChild || !(m_edgeChildren.empty() && m_faceChildren.empty() && m_volumeChildren.empty());}
     166            0 :         inline void add_child(Vertex* elem)     {assert(!m_pVrtChild); m_pVrtChild = elem;}
     167            0 :         inline void add_child(Edge* elem)       {m_edgeChildren.push_back(elem);}
     168            0 :         inline void add_child(Face* elem)               {m_faceChildren.push_back(elem);}
     169            0 :         inline void add_child(Volume* elem)             {m_volumeChildren.push_back(elem);}
     170            0 :         inline void remove_child(Vertex* elem)  {m_pVrtChild = NULL;}
     171            0 :         inline void remove_child(Edge* elem)    {ArraySwapWithLast(&m_edgeChildren.front(), elem, m_edgeChildren.size()); m_edgeChildren.pop_back();}
     172              :         //{m_numEdgeChildren = ArrayEraseEntry(m_pEdgeChild, elem, m_numEdgeChildren);}
     173            0 :         inline void remove_child(Face* elem)            {ArraySwapWithLast(&m_faceChildren.front(), elem, m_faceChildren.size()); m_faceChildren.pop_back();}
     174              :         //{m_numFaceChildren = ArrayEraseEntry(m_pFaceChild, elem, m_numFaceChildren);}
     175            0 :         inline void remove_child(Volume* elem)          {ArraySwapWithLast(&m_volumeChildren.front(), elem, m_volumeChildren.size()); m_volumeChildren.pop_back();}
     176              :         //{m_numVolChildren = ArrayEraseEntry(m_pVolChild, elem, m_numVolChildren);}
     177            0 :         inline void replace_child(Vertex* elem, Vertex* child)  {assert(child == m_pVrtChild); m_pVrtChild = elem;}
     178              :         inline void replace_child(Edge* elem, Edge* child)              {ArrayReplaceEntry(&m_edgeChildren.front(), elem, child, m_edgeChildren.size());}
     179              :         inline void replace_child(Face* elem, Face* child)                              {ArrayReplaceEntry(&m_faceChildren.front(), elem, child, m_faceChildren.size());}
     180              :         inline void replace_child(Volume* elem, Volume* child)                  {ArrayReplaceEntry(&m_volumeChildren.front(), elem, child, m_volumeChildren.size());}
     181              :         void unregister_from_children(MultiGrid& mg);
     182              : 
     183            0 :         size_t num_child_vertices() const       {return m_pVrtChild ? 1 : 0;}
     184              :         size_t num_child_edges() const          {return m_edgeChildren.size();}
     185              :         size_t num_child_faces() const          {return m_faceChildren.size();}
     186              :         size_t num_child_volumes() const        {return m_volumeChildren.size();}
     187              : 
     188            0 :         Vertex* child_vertex() const            {return m_pVrtChild;}
     189            0 :         Edge* child_edge(size_t i) const        {assert(i < num_child_edges()); return m_edgeChildren[i];}
     190            0 :         Face* child_face(size_t i) const                {assert(i < num_child_faces()); return m_faceChildren[i];}
     191            0 :         Volume* child_volume(size_t i) const    {assert(i < num_child_volumes()); return m_volumeChildren[i];}
     192              : 
     193              : private:
     194              :         Vertex*                         m_pVrtChild;
     195              :         std::vector<Edge*>        m_edgeChildren;
     196              :         std::vector<Face*>                m_faceChildren;
     197              :         std::vector<Volume*>      m_volumeChildren;
     198              : };
     199              : 
     200              : ///     access to connected types. used internally
     201              : /**
     202              :  * has to contain:
     203              :  *      - typedef info_type
     204              :  */
     205              : template <class TElem> class mginfo_traits{};
     206              : 
     207              : ///     vertex info traits. used internally.
     208              : template <> class mginfo_traits<Vertex>
     209              : {
     210              :         public:
     211              :                 typedef MGVertexInfo    info_type;
     212              : };
     213              : 
     214              : ///     edge info traits. used internally.
     215              : template <> class mginfo_traits<Edge>
     216              : {
     217              :         public:
     218              :                 typedef MGEdgeInfo      info_type;
     219              : };
     220              : 
     221              : ///     face info traits. used internally.
     222              : template <> class mginfo_traits<Face>
     223              : {
     224              :         public:
     225              :                 typedef MGFaceInfo      info_type;
     226              : };
     227              : 
     228              : ///     volume info traits. used internally.
     229              : template <> class mginfo_traits<Volume>
     230              : {
     231              :         public:
     232              :                 typedef MGVolumeInfo    info_type;
     233              : };
     234              : 
     235              : }// end of namespace
     236              : 
     237              : #endif
        

Generated by: LCOV version 2.0-1