LifeV
MeshEntity.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 LifeV.
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 License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief This file contains the MeshEntity class.
30 
31  @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32  @contributor Antonio Cervone <ant.cervone@gmail.com>
33  @maintainer Tiziano Passerini <tiziano@mathcs.emory.edu>
34 
35  The classes included in this file are useful to store the identifiers of
36  the different structures stored in the meshes.
37  */
38 
39 #ifndef MESHENTITY_H
40 #define MESHENTITY_H 1
41 
42 #include <lifev/core/LifeV.hpp>
43 
44 namespace LifeV
45 {
46 
47 //! available bit-flags for different geometric properties
48 namespace EntityFlags
49 {
50 const flag_Type DEFAULT ( 0x00 );
51 const flag_Type PHYSICAL_BOUNDARY ( 0x01 );
52 const flag_Type INTERNAL_INTERFACE ( 0x02 );
53 const flag_Type SUBDOMAIN_INTERFACE ( 0x04 );
54 const flag_Type OVERLAP ( 0x08 );
55 const flag_Type CUTTED ( 0x10 );
56 const flag_Type VERTEX ( 0x20 );
57 const flag_Type GHOST ( 0x40 );
58 // @note remember to update ALL value in order to encompass all flags
59 const flag_Type ALL ( 0x7F );
60 
61 const UInt number ( 7 );
62 
63 std::string name ( const flag_Type& flag );
64 
65 }// namespace EntityFlags
66 
67 //! This is the base class to store basic properties of any mesh entity
68 /*!
69  * The basic properties of a mesh entity is to have identifiers and flags.
70  * Identifiers give information about the numbering of the entity (typically in a mesh)
71  * flags are attributes af the entity, like being on the boundary.
72  *
73  In this class, there are two identifiers stored:
74  <ol>
75  <li> The global identifier, normally used to uniquely identify the
76  entity in the whole mesh.
77  <li> The local identifier, which is usually unique to the entity on a given
78  partition. If the entity is stored into a
79  meshEntityContainer, then localId must be the position
80  of the entity in the container.
81  </ol>
82 
83  When running the code in serial (1 processor), the identifiers
84  are then the same (but this is not necessary)
85 
86  This class provides the method and operators to handle local and global
87  identifiers easily.
88 
89  Note: Documentation by Samuel Quinodoz, implementation anterior
90  to the documentation: Luca Formaggia
91 
92  The additional fag that is stored is used to specify geometrical properties of the entity
93  such as the ones specified above in the EntityFlags namespace.
94  @todo The marker ID should be taken away form marker class and added to the MeshEntity directly
95  */
96 
98 {
99 public:
100  //! Indicator for local or global id
101  /*!
102  * This enum helps to develop methods to operate on local or globalID
103  *
104  */
105  enum SwitchId {LOCALID = 0, GLOBALID = 1};
106  //! @name Constructors & Destructor
107  //@{
108 
109  //! Empty Constructor
110  /*!
111  Using this constructor, both identifiers are set to NotAnId.
112  */
114  M_id ( NotAnId ),
115  M_localId ( NotAnId ),
117  {}
118 
119  //! Constructor with a single value for both identifiers.
120  /*!
121  @param id The value for both identifers.
122  @param flag The value of the flag to assign (optional)
123  */
124  MeshEntity ( const ID& id, const flag_Type& flag = EntityFlags::DEFAULT ) :
125  M_id ( id ),
126  M_localId ( id ),
127  M_flag ( flag )
128  {}
129 
130  //! Full constructor, where both identifiers are specified.
131  /*!
132  @param id The value for the global ID.
133  @param lid The value for the local ID.
134  @param flag The value of the flag to assign (optional)
135  */
136  MeshEntity ( const ID& id, const ID& lid, const flag_Type& flag = EntityFlags::DEFAULT ) :
137  M_id ( id ),
138  M_localId ( lid ),
139  M_flag ( flag )
140  {}
141 
142  //! backward-compatible constructor
143  /*!
144  @param id The identifier to be set for both (global and local) identifiers. Use
145  a set method if you want different identifiers.
146  @param boundary The value of the boundary indicator.
147  */
148  MeshEntity ( const ID& id, const bool& boundary ) :
149  M_id ( id ),
150  M_localId ( id )
151  {
152  // NOTE: this is conservative, if PHYSICAL_BOUNDARY = 0x01
153  // this can be done as
154  // M_flag = static_cast<flag_Type> boundary;
156  }
157 
158  //! Destructor
159  virtual ~MeshEntity() {}
160 
161  //@}
162 
163  //! @name Methods
164  //@{
165  //! Displays the informations stored by this class
166  void showMe ( std::ostream& output = std::cout ) const;
167  //@}
168 
169 
170  //! @name Set Methods
171  //@{
172 
173  //! Method to set the global identifier.
174  /*!
175  * @todo change the name in setGlobalId
176  @param id The new global identifier.
177  */
178  inline void setId ( const ID& id)
179  {
180  M_id = id;
181  }
182 
183  //! Method to set the local identifier.
184  /*!
185  @param id The new local identifier.
186  */
187  inline void setLocalId ( const ID& id)
188  {
189  M_localId = id;
190  }
191 
192  //! Set method for the boundary indicator
193  /*!
194  @param boundary The value to be set for the boundary indicator.
195  */
196  void setBoundary (const bool& boundary)
197  {
198  if ( boundary )
199  {
201  }
202  else
203  {
205  }
206  }
207 
208  //! Replace method for the entity flag
209  /*!
210  @param flag The value to be set for the entity flag.
211  @note Beware, it sets the entire flag; if you want to add a flag use | or setFlag
212  */
213  void replaceFlag ( const flag_Type& flag )
214  {
215  M_flag = flag;
216  }
217 
218  //! Sets a flag
219  /**
220  * @param flag The flag to be added
221  */
222  void setFlag ( const flag_Type& flag )
223  {
225  }
226  //! Remove a flag
227  /**
228  * @param flag The flag to be removed
229  */
230  void unSetFlag ( const flag_Type& flag )
231  {
233  }
234 
235  //@}
236 
237 
238  //! @name Get Methods
239  //@{
240 
241  //! Method to get the global identifier.
242  /*!
243  @return The global identifier.
244  */
245  inline const ID& id() const
246  {
247  return M_id;
248  }
249 
250  //! Method to get the local identifier.
251  /*!
252  @return The local identifier.
253  */
254  inline const ID& localId() const
255  {
256  return M_localId;
257  }
258 
259  //! Tells if it is on the boundary
260  bool boundary() const
261  {
263  }
264 
265  //! Tells if the entity is owned by current process
266  bool isOwned() const
267  {
269  }
270 
271  //! returns the entity flag
272  const flag_Type& flag() const
273  {
274  return M_flag;
275  }
276 
277  //@}
278 
279 private:
283 };
284 
286 {
287 /*! @defgroup MeshEntityUtilities
288  * Utilities to get local or global ID according to a switch
289  * The template parameter is in fact a MeshEntity::SwitchId
290  * enumerator which takes values MeshEntity::LOCALID or
291  * MeshEntity::GLOBALID.
292  * Getters are also implemented as functors for efficiency reason
293  * (allow inlining)
294  * @todo Go to a separate file
295  * @{
296  */
297 template<int Selector>
298 inline ID getID (MeshEntity const&);
299 //! Generic definition of setter
300 template<int Selector>
301 inline void setID (MeshEntity&, const ID);
302 
303 //! Specialization for global id
304 template<>
305 inline ID getID<MeshEntity::GLOBALID> (MeshEntity const& entity)
306 {
307  return entity.id();
308 }
309 
310 //! Specialization for local id
311 template<>
312 inline ID getID<MeshEntity::LOCALID> (MeshEntity const& entity)
313 {
314  return entity.localId();
315 }
316 
317 //! Specialization for global id
318 template<>
319 inline void setID<MeshEntity::GLOBALID> (MeshEntity& entity, const ID id)
320 {
321  entity.setId (id);
322 }
323 
324 //! Specialization for local id
325 template<>
326 inline void setID<MeshEntity::LOCALID> (MeshEntity& entity, const ID id)
327 {
328  entity.setLocalId (id);
329 }
330 //! Generic definition of the functor to extract the local or global ID
331 /*
332  * The functor is useful for allowing inlining and use it with
333  * std compliant containers.
334  */
335 template<int Selector>
336 struct IdGetter
337 {
338  inline ID operator() (MeshEntity const& entity) const
339  {
340  return getID<Selector> (entity);
341  };
342 };
343 
344 
345 
346 /** @} */ // end of MeshEntityUtilities
347 } // end of namespace MeshEntityUtility
348 
349 //! Mesh Entity with an orientation
350 /*! \note Not Used so far! */
351 /*class OrientedMeshEntity: public MeshEntity
352 {
353 public:
354  OrientedMeshEntity() :
355  MeshEntity(),
356  _orient( true )
357  {}
358  ;
359  OrientedMeshEntity(const OrientedMeshEntity& orientedMeshEntity) :
360  MeshEntity( orientedMeshEntity ),
361  _orient(orientedMeshEntity._orient )
362  {}
363  ;
364  OrientedMeshEntity( ID i, bool o = true ) :
365  MeshEntity( i ),
366  _orient( o )
367  {}
368  //! Return entity orientation
369  bool orientation() const
370  {
371  return _orient;
372  }
373  //! Assigns entity orientation
374  bool & orientation()
375  {
376  return _orient;
377  }
378 protected:
379  bool _orient;
380  }; */
381 
382 
383 } // End of namespace LifeV
384 
385 #endif /* MESHENTITY_H */
This is the base class to store basic properties of any mesh entity.
Definition: MeshEntity.hpp:97
void unSetFlag(const flag_Type &flag)
Remove a flag.
Definition: MeshEntity.hpp:230
ID getID(MeshEntity const &)
void replaceFlag(const flag_Type &flag)
Replace method for the entity flag.
Definition: MeshEntity.hpp:213
MeshEntity()
Empty Constructor.
Definition: MeshEntity.hpp:113
uint32_type flag_Type
bit-flag with up to 32 different flags
Definition: LifeV.hpp:197
MeshEntity(const ID &id, const flag_Type &flag=EntityFlags::DEFAULT)
Constructor with a single value for both identifiers.
Definition: MeshEntity.hpp:124
const UInt number(7)
flag_Type turnOn(flag_Type const &inputFlag, flag_Type const &refFlag)
turns on the refFlag active bits in inputFlag
Definition: LifeV.hpp:228
virtual ~MeshEntity()
Destructor.
Definition: MeshEntity.hpp:159
const flag_Type & flag() const
returns the entity flag
Definition: MeshEntity.hpp:272
const flag_Type ALL(0x7F)
void setFlag(const flag_Type &flag)
Sets a flag.
Definition: MeshEntity.hpp:222
void setID< MeshEntity::LOCALID >(MeshEntity &entity, const ID id)
Specialization for local id.
Definition: MeshEntity.hpp:326
MeshEntity(const ID &id, const bool &boundary)
backward-compatible constructor
Definition: MeshEntity.hpp:148
flag_Type turnOff(flag_Type const &inputFlag, flag_Type const &refFlag)
turns off the refFlag active bits in inputFlag
Definition: LifeV.hpp:234
MeshEntity(const ID &id, const ID &lid, const flag_Type &flag=EntityFlags::DEFAULT)
Full constructor, where both identifiers are specified.
Definition: MeshEntity.hpp:136
Generic definition of the functor to extract the local or global ID.
Definition: MeshEntity.hpp:336
void updateInverseJacobian(const UInt &iQuadPt)
bool testOneSet(flag_Type const &inputFlag, flag_Type const &refFlag)
returns true if at least one flag set in refFlag is set in inputFlag
Definition: LifeV.hpp:216
void setLocalId(const ID &id)
Method to set the local identifier.
Definition: MeshEntity.hpp:187
ID operator()(MeshEntity const &entity) const
Definition: MeshEntity.hpp:338
const flag_Type VERTEX(0x20)
const flag_Type OVERLAP(0x08)
const flag_Type SUBDOMAIN_INTERFACE(0x04)
void showMe(std::ostream &output=std::cout) const
Displays the informations stored by this class.
Definition: MeshEntity.cpp:39
uint32_type ID
IDs.
Definition: LifeV.hpp:194
bool isOwned() const
Tells if the entity is owned by current process.
Definition: MeshEntity.hpp:266
const flag_Type PHYSICAL_BOUNDARY(0x01)
const flag_Type DEFAULT(0x00)
bool boundary() const
Tells if it is on the boundary.
Definition: MeshEntity.hpp:260
void setID(MeshEntity &, const ID)
Generic definition of setter.
const flag_Type GHOST(0x40)
const ID & localId() const
Method to get the local identifier.
Definition: MeshEntity.hpp:254
void setId(const ID &id)
Method to set the global identifier.
Definition: MeshEntity.hpp:178
flag related free functions and functors
Definition: LifeV.hpp:203
const flag_Type INTERNAL_INTERFACE(0x02)
available bit-flags for different geometric properties
Definition: MeshEntity.hpp:48
SwitchId
Indicator for local or global id.
Definition: MeshEntity.hpp:105
std::string name(const flag_Type &flag)
Definition: MeshEntity.cpp:16
const ID NotAnId
Definition: LifeV.hpp:264
bool testOneNotSet(flag_Type const &inputFlag, flag_Type const &refFlag)
returns false if at least one flag set in refFlag is set in inputFlag
Definition: LifeV.hpp:222
void setBoundary(const bool &boundary)
Set method for the boundary indicator.
Definition: MeshEntity.hpp:196
const flag_Type CUTTED(0x10)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
const ID & id() const
Method to get the global identifier.
Definition: MeshEntity.hpp:245