LifeV
NeighborMarker.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory UNiversity
7 
8  This file is part of the LifeV library
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief
31 
32  @date 10/2011
33  @author A. Cervone <ant.cervone@gmail.com>
34  */
35 
36 #ifndef _NEIGHBORMARKER_H_
37 #define _NEIGHBORMARKER_H_ 1
38 
39 #include <boost/unordered_set.hpp>
40 
41 #include <lifev/core/LifeV.hpp>
42 
43 #include <lifev/core/mesh/Marker.hpp>
44 #include <lifev/core/mesh/RegionMesh.hpp>
45 #include <unordered_set>
46 
47 // LifeV namespace
48 namespace LifeV
49 {
50 
53 
54 
55 //! @class NeighborMarker
56 /*! This class extends the default marker adding containers to store all adjacency informations.
57  */
58 
59 template <typename FlagPolicy = MarkerIDStandardPolicy>
60 class NeighborMarker: public Marker<FlagPolicy>
61 {
62 public:
63 
66 
67  NeighborMarker () : Marker<FlagPolicy>() {}
68 
69  explicit NeighborMarker ( markerID_Type& p ) : Marker<FlagPolicy> ( p ) {}
70 
71  NeighborMarker<FlagPolicy>& operator= ( NeighborMarker<FlagPolicy> const& marker )
72  {
73  setPointNeighbors ( marker.pointNeighbors() );
74  Marker<FlagPolicy>::operator= ( marker );
75  return *this;
76  }
77 
79  {
80  return M_pointNeighbors;
81  }
82 
84  {
85  return M_pointNeighbors;
86  }
87  // neighbors_Type & edgeNeighbors () { return M_edgeNeighbors; }
88  // neighbors_Type & faceNeighbors () { return M_faceNeighbors; }
89  // neighbors_Type & elementNeighbors () { return M_elementNeighbors; }
90 
91  void setPointNeighbors ( neighbors_Type const& pointNeighbors )
92  {
93  M_pointNeighbors = pointNeighbors;
94  }
95  // void setEdgeNeighbors ( neighbors_Type const & edgeNeighbors ) { M_edgeNeighbors = edgeNeighbors; }
96  // void setFaceNeighbors ( neighbors_Type const & faceNeighbors ) { M_faceNeighbors = faceNeighbors; }
97  // void setElementNeighbors ( neighbors_Type const & elementNeighbors ) { M_elementNeighbors = elementNeighbors; }
98 
99 protected:
101  // neighbors_Type M_edgeNeighbors;
102  // neighbors_Type M_faceNeighbors;
103  // neighbors_Type M_elementNeighbors;
104 };
105 
106 //! @class NeighborMarkerCommon
107 /*! Trait class to collect all mesh entity markers.
108  * The only difference with the default one is a NeighborMarker for points.
109  */
110 
111 template <class MT>
113 {
114 public:
115 
116  //! @name Public Types
117  //@{
118  //! The marker used for the Points
120  //! The marker used for the Edges
121  typedef Marker<MT> edgeMarker_Type;
122  //! The marker used for the Faces
123  typedef Marker<MT> faceMarker_Type;
124  //! The marker used for the Volumes
126  //! The marker used for the Regions
128  //@}
129 };
130 
131 //! The NeighborMarkerCommon: uses all defaults except for Points
133 
134 //! this routine generates point neighbors for the given mesh
135 /*! the routine assumes that the mesh is not yet partitioned or reordered
136  * (i.e. the local id and the global id are the same).
137  * if this is not true the method should be changed to use a more
138  * expensive STL find on the mesh points to get the correct point that has
139  * the given global id or construct a globalToLocal map beforehand.
140  */
141 template <typename MeshType>
142 void createPointNeighbors ( MeshType& mesh )
143 {
144  // TODO: ASSERT_COMPILE_TIME that MeshType::pointMarker == NeighborMarker
145  // this guarantees that the pointNeighbors structure is available.
146 
147  // generate point neighbors by watching edges
148  // note: this can be based also on faces or volumes
149  for ( UInt ie = 0; ie < mesh.numEdges(); ie++ )
150  {
151  ID id0 = mesh.edge ( ie ).point ( 0 ).id();
152  ID id1 = mesh.edge ( ie ).point ( 1 ).id();
153 
154  ASSERT ( mesh.point ( id0 ).id() == id0 , "the mesh has been reordered, the point must be found" );
155  ASSERT ( mesh.point ( id1 ).id() == id1 , "the mesh has been reordered, the point must be found" );
156 
157  mesh.point ( id0 ).pointNeighbors().insert ( id1 );
158  mesh.point ( id1 ).pointNeighbors().insert ( id0 );
159  }
160 }
161 
162 template <typename MeshType>
163 void createPointNeighbors ( MeshType const& mesh, neighborList_Type& neighborList )
164 {
165  neighborList.resize ( mesh.numGlobalPoints() );
166  // generate point neighbors by watching edges
167  // note: this can be based also on faces or volumes
168  for ( UInt ie = 0; ie < mesh.numEdges(); ie++ )
169  {
170  ID id0 = mesh.edge ( ie ).point ( 0 ).id();
171  ID id1 = mesh.edge ( ie ).point ( 1 ).id();
172 
173  ASSERT ( mesh.point ( id0 ).id() == id0 && mesh.point ( id1 ).id() == id1,
174  "the mesh has been reordered, the point must be found" );
175 
176  neighborList[ id0 ].insert ( id1 );
177  neighborList[ id1 ].insert ( id0 );
178  }
179 }
180 
181 } // namespace LifeV
182 
183 #endif // _NEIGHBORMARKER_H_
NeighborMarker< FlagPolicy > & operator=(NeighborMarker< FlagPolicy > const &marker)
void setPointNeighbors(neighbors_Type const &pointNeighbors)
neighbors_Type::iterator neighborIterator_Type
MarkerIDStandardPolicy - Class that defines the standard policies on Marker Ids.
Definition: Marker.hpp:89
void createPointNeighbors(MeshType &mesh)
this routine generates point neighbors for the given mesh
neighbors_Type const & pointNeighbors() const
Marker< MT > volumeMarker_Type
The marker used for the Volumes.
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
void updateInverseJacobian(const UInt &iQuadPt)
neighbors_Type M_pointNeighbors
NeighborMarkerCommon< MarkerIDStandardPolicy > neighborMarkerCommon_Type
The NeighborMarkerCommon: uses all defaults except for Points.
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
uint32_type ID
IDs.
Definition: LifeV.hpp:194
Marker< MT > faceMarker_Type
The marker used for the Faces.
neighbors_Type::const_iterator neighborConstIterator_Type
Marker< MT > edgeMarker_Type
The marker used for the Edges.
NeighborMarker< MT > pointMarker_Type
The marker used for the Points.
std::unordered_set< ID > neighbors_Type
Marker< MT > regionMarker_Type
The marker used for the Regions.
void createPointNeighbors(MeshType const &mesh, neighborList_Type &neighborList)
std::vector< neighbors_Type > neighborList_Type
Marker - Base marker class.
Definition: Marker.hpp:148
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
neighbors_Type & pointNeighbors()
NeighborMarker(markerID_Type &p)