LifeV
MeshElement.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 Zero dimensional entity
30 
31  @author Luca Formaggia <luca.formaggia@polimi.it>
32  @contributor Marta D'Elia <mdelia2@mathcs.emory.edu>
33  @maintainer Marta D'Elia <mdelia2@mathcs.emory.edu>
34 
35  @date 00-00-0000
36 
37 */
38 #ifndef MESHELEMENT_H
39 #define MESHELEMENT_H
40 
41 #include <lifev/core/mesh/MeshVertex.hpp>
42 #include <lifev/core/mesh/MeshEntity.hpp>
43 #include <lifev/core/array/VectorSmall.hpp>
44 #include <algorithm>
45 
46 namespace LifeV
47 {
48 
49 //! MeshVertex - Zero dimensional entity.
50 /*!
51  @author Luca Formaggia
52 
53  Base class for Multidimensional basis Geometric Entities.
54 
55  @warning It has no boundary information, in fact GeoXD boundary items are stored in the corresponding RegionMesh List.
56 
57  */
58 template <typename GeoShape, typename PointType = MeshVertex>
59 class MeshElement :
60  public MeshEntity,
61  public GeoShape
62 {
63 public:
64 
65  //! @name Public Types
66  //@{
67 
68  //! Number of points associated to the entity
69  static const UInt S_numLocalPoints = GeoShape::S_numPoints;
70  //! Number of Vertices associated to the entity
71  static const UInt S_numLocalVertices = GeoShape::S_numVertices;
72 
73  typedef GeoShape geoShape_Type;
74  typedef PointType point_Type;
75  //@}
76 
77  //! @name Constructor & Destructor
78  //@{
79 
80  //! Empty Constructor
81  MeshElement();
82  //! Declares item identity
83  /*!
84  @param Identity Element identity
85  */
86  explicit MeshElement ( ID identity );
87 
88  //! Copy constructor
89  /*!
90  @param Element MeshElement to be copied
91  */
92  MeshElement ( const MeshElement<GeoShape, PointType>& element);
93 
94  //! Destructor
95  ~MeshElement();
96 
97  //@}
98 
99  //! @name Operators
100  //@{
101 
102  //! The equivalence operator
103  /*!
104  @param Element Equivalent MeshElementMarked0D
105  @return Reference to a new MeshElementMarked0D with the same content of MeshElementMarked0D Element
106  */
107  MeshElement& operator= ( MeshElement const& element );
108 
109  //@}
110 
111  //! @name Methods
112  //@{
113 
114  //! Display general information about the content of the class
115  /*!
116  List of things displayed in the class
117  @param verbose If true more information is displayed
118  @param c Output
119  */
120  std::ostream& showMe ( bool verbose = false, std::ostream& c = std::cout ) const;
121 
122  //! Swap Points
123  /*!
124  @param firstIdentity Identity of the first point to be swapped
125  @param secondIdentity Identity of the second point to be swapped
126  @warning Function to be used only by routines for checking or amending meshes
127  */
128  void swapPoints ( const ID& firstIdentity, const ID& secondIdentity );
129 
130  //! Reverses the points of the element.
131  /*!
132  Useful in the phase of building a mesh if you want to change the orientation of
133  the element. First point becomes last etc.etc
134 
135  \note Beware that the some adjacency list may be invalidated. If you revert the point
136  of a 3D element, for instance, the local faces change and a elementToFace list may be
137  now incorrect. So this method must be used with care and only when building the basic entities
138  of a mesh.
139  */
140  void reversePoints();
141  //! Exchange points
142  /*!
143  Exchanges points according to a list of old-to-new local identity numbering
144  @param oldToNew New local identity of a point
145  @warning Function to be used only by routines for checking or amending meshes
146  */
147  void exchangePoints ( const ID oldToNew[ GeoShape::S_numPoints ] );
148 
149  //! Returns the point of identity indicated in the argument
150  /*!
151  @param identity Identity of the point
152  @return reference to a point object, possibly derived from point_Type
153  */
154  point_Type const& point ( ID const identity ) const;
155  //! Returns the point of identity indicated in the argument
156  /*!
157  It starts from the last point and it follows the rule: vertices first.
158  It may be used to access the points of a Geometry Element in a reverse way
159  (i.e. with the opposite MeshElementMarked orientation)
160  @param identity Identity of the point
161  @return reference to a point object, possibly derived from point_Type
162  */
163  point_Type const& reversepoint ( ID const identity ) const;
164 
165  //@}
166 
167  //! @name Set Methods
168  //@{
169 
170  //! Inserts a point using point references
171  /*!
172  @param identity Identity of the point to be inserted
173  @param point Point to be inserted
174  */
175  void setPoint ( ID const identity, point_Type const& point );
176  //!Inserts a point using point references with forced boundary check
177  /*!
178  @param identity Identity of the point to be inserted
179  @param point Point to be inserted
180  @return TRUE if the point is set
181  */
182  bool setPointWithBoundaryCheck ( ID const identity, point_Type const& point );
183 
184  //!Inserts a point using pointers
185  /*!
186  @param identity Identity of the point to be inserted
187  @param point Point to be inserted
188  */
189  void setPoint ( ID const identity, point_Type const* point );
190  //!Inserts a point using pointers with forced boundary check
191  /*!
192  @param identity Identity of the point to be inserted
193  @param point Point to be inserted
194  @return %%%%
195  */
196  bool setPointWithBoundaryCheck ( ID const identity, point_Type const* point );
197 
198  //! Sets the Marker ID of a point
199  /*!
200  Sets the Marker ID the stronger between the stored one and the one provided by the argument
201  @param identity Elemental numbering of the point to be inserted
202  @param point Point to be inserted
203  @return TRUE if the point is set
204  @warning A const_cast to M_points is done
205  */
206  markerID_Type setStrongerMarkerIDAtPoint ( const ID& identity, markerID_Type const& flag ) const;
207 
208  //@}
209 
210  //! @name Get Methods
211  //@{
212 
213  //! Returns the points vector
214  /*!
215  The method allows to access coordinates but not modify them
216  @return Points vector
217  */
218  point_Type const* points () const
219  {
220  return M_points;
221  }
222 
223  //@}
224 
225 private:
226  point_Type const* M_points[ GeoShape::S_numPoints ];
227 };
228 
229 
230 /*--------------------------------------------------------------
231  MeshElement
232 ---------------------------------------------------------------*/
233 template <typename GeoShape, typename PointType>
234 const UInt MeshElement<GeoShape, PointType>::S_numLocalPoints;
235 
236 template <typename GeoShape, typename PointType>
237 const UInt MeshElement<GeoShape, PointType>::S_numLocalVertices;
238 
239 template <typename GeoShape, typename PointType>
240 MeshElement<GeoShape, PointType>::MeshElement() :
241  MeshEntity ( NotAnId )
242 {
243 
244 }
245 
246 template <typename GeoShape, typename PointType>
247 MeshElement<GeoShape, PointType>::MeshElement ( ID identity ) :
248  MeshEntity ( identity )
249 {
250 
251 }
252 
253 template <typename GeoShape, typename PointType>
254 MeshElement<GeoShape, PointType>::MeshElement ( MeshElement<GeoShape, PointType> const& element ) :
255  MeshEntity ( element )
256 {
257  setLocalId ( element.localId() );
258  for ( UInt i = 0; i < MeshElement<GeoShape, PointType>::S_numLocalPoints; ++i )
259  {
260  M_points[ i ] = element.M_points[ i ];
261  }
262 }
263 
264 template <typename GeoShape, typename PointType>
265 MeshElement<GeoShape, PointType>::~MeshElement()
266 {
267 
268 }
269 
270 template <typename GeoShape, typename PointType>
271 MeshElement<GeoShape, PointType>&
272 MeshElement<GeoShape, PointType>::operator= ( MeshElement<GeoShape, PointType> const& element )
273 {
274  if ( this != &element )
275  {
276  MeshEntity::operator= ( element );
277  for ( UInt i = 0; i < MeshElement<GeoShape, PointType>::S_numLocalPoints; ++i )
278  {
279  M_points[ i ] = element.M_points[ i ];
280  }
281  }
282  return *this;
283 }
284 
285 template <typename GeoShape, typename PointType>
286 std::ostream& MeshElement<GeoShape, PointType>::
287 showMe ( bool verbose, std::ostream& out ) const
288 {
289  out << "----- MeshElement object -----" << std::endl;
290  out << " Number of Vertices = " << GeoShape::S_numVertices << std::endl;
291  out << " Number of Points = " << GeoShape::S_numPoints << std::endl;
292  out << " ID = " << id() << std::endl;
293  out << " local ID = " << localId() << std::endl;
294  if ( verbose )
295  {
296  out << " POINTS INFORMATION" << std::endl << std::endl;
297  for ( UInt i = 0 ; i < GeoShape::S_numVertices; i++ )
298  {
299  out << "POINT ID. " << i << std::endl;
300  out << point ( i ).showMe ( verbose, out );
301  }
302  }
303  out << "----- END OF MeshElement data ---" << std::endl << std::endl;
304  return out;
305 }
306 
307 template <typename GeoShape, typename PointType>
308 void MeshElement<GeoShape, PointType>::swapPoints ( const ID& firstIdentity, const ID& secondIdentity )
309 {
310  std::swap (M_points[ firstIdentity ], M_points[ secondIdentity ]);
311 }
312 
313 template <typename GeoShape, typename PointType>
314 void MeshElement<GeoShape, PointType>::reversePoints()
315 {
316  static bool first (true);
317  static ID oldToNew[ GeoShape::S_numPoints ];
318  if (first)
319  {
320  for (ID i = 0; i < GeoShape::S_numPoints; ++i)
321  {
322  oldToNew[i] = reversePoint<GeoShape> (i);
323  }
324  first = false;
325  }
326  this->exchangePoints (oldToNew);
327 }
328 
329 
330 template <typename GeoShape, typename PointType>
331 void MeshElement<GeoShape, PointType>::exchangePoints ( const ID oldToNew[ GeoShape::S_numPoints ] )
332 {
333  point_Type const* tmp[ GeoShape::S_numPoints ];
334  for ( UInt i = 0; i < GeoShape::S_numPoints; ++i )
335  {
336  tmp[ i ] = M_points[ i ];
337  }
338  for ( UInt i = 0; i < GeoShape::S_numPoints; ++i )
339  {
340  M_points[ i ] = tmp[ oldToNew[ i ] ];
341  }
342 }
343 
344 template <typename GeoShape, typename PointType>
345 inline
346 PointType const& MeshElement<GeoShape, PointType>::point ( ID const identity ) const
347 {
348  ASSERT_BD ( ( identity < MeshElement<GeoShape, PointType>::S_numLocalPoints ) );
349  return * ( static_cast<PointType const*> ( M_points[ identity ] ) );
350 }
351 
352 template <typename GeoShape, typename PointType>
353 inline
354 PointType const& MeshElement<GeoShape, PointType>::reversepoint ( ID const identity ) const
355 {
356  ASSERT_BD ( ( identity < MeshElement<GeoShape, PointType>::S_numLocalPoints ) );
357  return * ( static_cast<PointType const*> ( M_points[ reversePoint<GeoShape> ( identity ) ] ) );
358 }
359 
360 template <typename GeoShape, typename PointType>
361 inline
362 void MeshElement<GeoShape, PointType>::setPoint ( ID const identity, point_Type const& point )
363 {
364  ASSERT_BD ( ( identity < MeshElement<GeoShape, PointType>::S_numLocalPoints ) ) ;
365  M_points[ identity ] = ( &point );
366 }
367 
368 template <typename GeoShape, typename PointType>
369 bool MeshElement<GeoShape, PointType>::setPointWithBoundaryCheck ( ID const identity, point_Type const& point )
370 {
372  if ( identity >= MeshElement<GeoShape, PointType>::S_numLocalVertices )
373  {
374  return false;
375  }
376  M_points[ identity ] = ( &point );
377  return true;
378 }
379 
380 template <typename GeoShape, typename PointType>
381 inline
382 void MeshElement<GeoShape, PointType>::setPoint ( ID const identity, point_Type const* point )
383 {
384  ASSERT_BD ( ( identity < MeshElement<GeoShape, PointType>::S_numLocalPoints ) ) ;
385  M_points[ identity ] = ( point );
386 }
387 
388 template <typename GeoShape, typename PointType>
389 bool MeshElement<GeoShape, PointType>::setPointWithBoundaryCheck ( ID const identity, point_Type const* point )
390 {
392  if ( identity >= MeshElement<GeoShape, PointType>::S_numLocalVertices )
393  {
394  return false;
395  }
396  M_points[ identity ] = ( point );
397  return true;
398 }
399 
400 template <typename GeoShape, typename PointType>
401 markerID_Type MeshElement<GeoShape, PointType>::setStrongerMarkerIDAtPoint ( const ID& identity, markerID_Type const& flag )
402 const
403 {
404  return (const_cast<PointType*> ( M_points[identity]) ) -> setStrongerMarkerID (flag);
405 }
406 
407 template <typename PointType>
408 Real edgeLength ( const MeshElement<LinearLine, PointType>& edge )
409 {
410  // Real deltaX, deltaY, deltaZ;
411  //
412  // deltaX = ( edge.point( 1 ) ).x() - ( edge.point( 0 ) ).x();
413  // deltaY = ( edge.point( 1 ) ).y() - ( edge.point( 0 ) ).y();
414  // deltaZ = ( edge.point( 1 ) ).z() - ( edge.point( 0 ) ).z();
415  //
416  // return std::sqrt( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ );
417 
418  Vector3D dVec = castToVector3D (edge.point ( 1 ).coordinates() );
419  dVec -= castToVector3D (edge.point ( 0 ).coordinates() );
420 
421  return dVec.norm();
422 }
423 
424 }
425 #endif
This is the base class to store basic properties of any mesh entity.
Definition: MeshEntity.hpp:97
MeshElement & operator=(MeshElement const &element)
The equivalence operator.
static const UInt S_numLocalVertices
Number of Vertices associated to the entity.
Definition: MeshElement.hpp:71
markerID_Type setStrongerMarkerIDAtPoint(const ID &identity, markerID_Type const &flag) const
Sets the Marker ID of a point.
MeshElement()
Empty Constructor.
#define ASSERT_BD(X)
Definition: LifeAssert.hpp:114
#define ASSERT_BD0(X)
Definition: LifeAssert.hpp:75
A Geometric Shape.
bool setPointWithBoundaryCheck(ID const identity, point_Type const &point)
Inserts a point using point references with forced boundary check.
GeoShape geoShape_Type
Definition: MeshElement.hpp:73
void swapPoints(const ID &firstIdentity, const ID &secondIdentity)
Swap Points.
MeshVertex - Zero dimensional entity.
Definition: MeshVertex.hpp:59
MeshVertex - Zero dimensional entity.
Definition: MeshElement.hpp:59
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
MeshElement(const MeshElement< GeoShape, PointType > &element)
Copy constructor.
void updateInverseJacobian(const UInt &iQuadPt)
void setLocalId(const ID &id)
Method to set the local identifier.
Definition: MeshEntity.hpp:187
static const UInt S_numLocalPoints
Number of points associated to the entity.
Definition: MeshElement.hpp:69
point_Type const & point(ID const identity) const
Returns the point of identity indicated in the argument.
void setPoint(ID const identity, point_Type const *point)
Inserts a point using pointers.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
MeshElement(ID identity)
Declares item identity.
void exchangePoints(const ID oldToNew[GeoShape::S_numPoints])
Exchange points.
Real norm() const
norm
Real edgeLength(const MeshElement< LinearLine, PointType > &edge)
double Real
Generic real data.
Definition: LifeV.hpp:175
point_Type const * points() const
Returns the points vector.
void setPoint(ID const identity, point_Type const &point)
Inserts a point using point references.
point_Type const & reversepoint(ID const identity) const
Returns the point of identity indicated in the argument.
const ID NotAnId
Definition: LifeV.hpp:264
VectorSmall< 3 > Vector3D
PointType point_Type
Definition: MeshElement.hpp:74
std::ostream & showMe(bool verbose=false, std::ostream &c=std::cout) const
Display general information about the content of the class.
point_Type const * M_points[GeoShape::S_numPoints]
Assert & error(const char *strMsg=0)
void reversePoints()
Reverses the points of the element.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
bool setPointWithBoundaryCheck(ID const identity, point_Type const *point)
Inserts a point using pointers with forced boundary check.
~MeshElement()
Destructor.