LifeV
Marker.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 Basic definition of markers
30 
31  @contributor Luca Bertagna <lbertag@emory.edu>
32  @date 00-00-0000
33 
34  Here we define the basic markers. Markers have two purposes:
35 
36  <ul>
37  <li> To add an indicator (markerID_Type) to all geometry entities. In the
38  base MarkerTrait this indicator is a long integer (aliased to
39  EntityFLAG). The main purpose of the marker ID is to associate
40  boundary conditions or material properties to the Geometry
41  entity. </li>
42 
43  <li> There is a mechanism, via the MarkerCommon class template, to
44  extend the mesh entities definitions by adding user defined data
45  and methods. It this case the user should create its own marker
46  class (maybe by inheriting from the Marker class, which
47  provides the same interfaces of Marker + the user defined
48  stuff.</li>
49  </ul>
50 
51  The marker ID in the base class+some utilities to select between two marker IDs
52  is provided by traits. In particular,
53 
54  <ul>
55  <li> The MarkerIDStandardPolicy define the basic (compulsory) interface of
56  any user defined Marker class.</li>
57 
58  <li> The Marker is a class template whose template argument is a
59  MarkerTrait, defaulted to MarkerIDStandardPolicy.</li>
60 
61  <li>A user may change some basic behavior of the Marker class by
62  providing a special Traits.</li>
63  </ul>
64  */
65 
66 #ifndef MARKER_H
67 #define MARKER_H 1
68 
69 #include <iostream>
70 #include <lifev/core/LifeV.hpp>
71 namespace LifeV
72 {
73 
74 //! markerID_Type is the type used to store the geometric entity marker IDs
75 /*!
76  * An entity marker ID is an integral type that is used to store information about each geometric entity
77  * belonging to a mesh. In particular, it is the number given by the mesh generator that has
78  * generated the mesh to identify different portion of the boundary. It must be convertible to
79  * an ID type.
80 */
81 typedef ID markerID_Type;
82 
83 //! MarkerIDStandardPolicy - Class that defines the standard policies on Marker Ids
84 /*!
85  This class defines NULLFLAG and how to handle ambiguities among markerIDs
86  In particular what to do if a geometric item has to inherit its Marker ID by adjacent items and
87  the marker Ids are different. The policy is passed as template argument to the Marker class.
88  */
90 {
91 public:
92 
93  /*! It is the value indicating a null marker ID, i.e am ID not yet
94  set to any usable value
95  */
97 
98  //! Selects the stronger Marker ID
99  /*!
100  * A dimensional geometric entity G_i may inherit the stronger Marker ID
101  * among adiacent geometric entities of greater dimensions. For
102  * example a boundary point Point with an unset Flag may inherit the
103  * strongerst Flag of the adjacent boundary faces.
104  * It returns a Null Marker ID if any of the entity a or b ha a null Marker ID
105  */
106  static markerID_Type strongerMarkerID ( markerID_Type const& a, markerID_Type const& b );
107 
108  //! Selects the weaker Marker ID between marker IDs
109  /*
110  ! A lower dimensional geometric entity G_i may inherit the weaker
111  Marker ID among the Vertices of the entity. For example a boundary
112  Face with an unset Marker ID may inherit the weakest Marker ID of its
113  Vertices. This method may also be used to attribute the Flag to
114  Nodes generated on high order elements.
115  It returns a null Marker ID if any of the entity a or b has a Null Marker ID.
116  */
117  static markerID_Type weakerMarkerID ( markerID_Type const& a, markerID_Type const& b );
118 
119  //! Equality operator.
120  /*
121  It is needed in order to select markers with the same Marker ID
122  */
123  static bool equalMarkerID (const markerID_Type& a, const markerID_Type& b);
124 
125 };
126 
127 //! Marker - Base marker class.
128 /*!
129  It stores an object of markerID_Type which may be used for marking a geometric entity.
130  The typical use is to specify boundary conditions or material properties associated with
131  the entity. The actual boundary conditions will be handled in the DOF
132  class. During the creation of a field, the markers are processed to furnish the
133  correct boundary conditions.
134  The template argument MarkerIDPolicy defaults to MarkerIDStandardPolicy and it defines the way
135  ambiguities in the Marker ID definition are treated.
136  The template argument FlagPolicy defaults to EntityFlagStandardPolicy and it defines the way
137  ambiguities in the flag definition are treated.
138 
139  Marker is a concrete base class which also implements basic tool to operate on the markerID.
140  All geometric entities stored in a mesh derives from it, thus
141  it may be used to extend the capabilities of a geometric entity, for any purpose.
142 
143  The default markers used by RegionMesh are contained in MarkerDefinitions.hpp
144 
145  */
146 
147 template <typename MarkerIDPolicy = MarkerIDStandardPolicy>
148 class Marker
149 {
150 public:
151 
152  //! @name Public Types
153  //@{
154  //! The policy used by this marker
155  typedef MarkerIDPolicy MarkerIDPolicy_Type;
156  //@}
157 
158  //! @name Constructor & Destructor
159  //@{
160 
161  //! Empty Constructor
162  Marker();
163 
164  //! Constructor given the marker ID
165  explicit Marker ( markerID_Type& p );
166 
167  //! Copy Constructor
168  Marker ( Marker<MarkerIDPolicy> const& markerBase );
169 
170  //! Destructor
171  virtual ~Marker()
172  {
173  }
174 
175  //@}
176 
177  //! @name Methods
178  //@{
179 
180  //! It enquires if marker ID is different than the null marker ID
181  inline bool isMarkerSet() const;
182 
183  //! It enquires if marker ID is different than the null marker ID
184  inline bool isMarkerUnset() const;
185 
186  //! Compares marker IDs
187  /*!
188  It returns true if the marker ID is equal to the argument
189  */
190  inline bool hasEqualMarkerID (markerID_Type const& markerID ) const;
191 
192  //! Display information about the marker object
193  virtual void showMe ( std::ostream& output = std::cout ) const;
194 
195  //@}
196 
197  //! @name Setters
198  //@{
199 
200  //! Set marker to the given value
201  inline markerID_Type setMarkerID ( markerID_Type const& markerID );
202 
203  //! Set marker to the given value only if unset
204  markerID_Type updateMarkerID ( markerID_Type const& markerID );
205 
206  //! Sets the marker ID to the stronger marker ID of two given markers
207  markerID_Type setStrongerMarkerID ( markerID_Type const& markerID1, markerID_Type const& markerID2 );
208 
209  //! Sets the marker ID to the weaker marker ID of two given markers
210  markerID_Type setWeakerMarkerID ( markerID_Type const& markerID1, markerID_Type const& markerID2 );
211 
212  //! Sets to the strongest marker ID
213  /*!
214  If marker ID is not set, is sets it to that of the argument, otherwise
215  it sets it to the stronger ID between the stored one
216  and the one provided by the argument.
217  */
218  markerID_Type setStrongerMarkerID ( markerID_Type const& markerID );
219 
220  //! Sets to the weaker marker ID
221  /*!
222  If marker ID is not set, is sets it to that of the argument, otherwise
223  it sets it to the weaker ID between the stored one
224  and the one provided by the argument.
225  */
226  markerID_Type setWeakerMarkerID ( markerID_Type const& markerID );
227 
228  //! Put marker to NULLFLAG
229  inline void unsetMarkerID(); //const;
230 
231  //@}
232 
233  //! @name Get Methods
234  //@{
235 
236  //! Extracts the entityFlag associated to the marked entity
237  /*!
238  * For historical reason this method is called marker, while it should be called
239  * markerID() instead. Refactoring however would involve changing too many files and it has been
240  * postponed. Just remember that markerID() does not return a Marker!
241  */
242  inline markerID_Type markerID() const;
243 
244  //! Returns the null marker ID
245 
246  static markerID_Type const& nullMarkerID();
247 
248  //@}
249 
250 protected:
252 };
253 
254 
255 
256 // ***********************************************************************************************************
257 // IMPLEMENTATION
258 // ***********************************************************************************************************
259 
260 template <typename MarkerIDPolicy>
261 Marker<MarkerIDPolicy>::Marker() : M_markerID ( MarkerIDPolicy::S_NULLMARKERID )
262 {
263  // nothing to be done here
264 }
265 
266 template <typename MarkerIDPolicy>
267 Marker<MarkerIDPolicy>::Marker ( markerID_Type& markerID ) : M_markerID ( markerID )
268 {
269  // nothing to be done here
270 }
271 
272 template <typename MarkerIDPolicy>
273 Marker<MarkerIDPolicy>::Marker ( Marker<MarkerIDPolicy> const& markerBase ) : M_markerID ( markerBase.markerID() )
274 {
275  // nothing to be done here
276 }
277 
278 template <typename MarkerIDPolicy>
279 markerID_Type Marker<MarkerIDPolicy>::markerID() const
280 {
281  return M_markerID;
282 }
283 
284 template <typename MarkerIDPolicy>
285 markerID_Type const& Marker<MarkerIDPolicy>::nullMarkerID()
286 {
287  return MarkerIDPolicy::S_NULLMARKERID;
288 }
289 
290 template <typename MarkerIDPolicy>
291 markerID_Type Marker<MarkerIDPolicy>::setMarkerID ( markerID_Type const& markerID )
292 {
293  return M_markerID = markerID;
294 }
295 
296 template <typename MarkerIDPolicy>
297 markerID_Type Marker<MarkerIDPolicy>::updateMarkerID ( markerID_Type const& markerID )
298 {
299  if ( M_markerID == nullMarkerID() )
300  {
301  return setMarkerID ( markerID );
302  }
303 }
304 
305 template <typename MarkerIDPolicy>
306 markerID_Type Marker<MarkerIDPolicy>::setStrongerMarkerID ( markerID_Type const& markerID1,
307  markerID_Type const& markerID2 )
308 {
309  return setMarkerID ( MarkerIDPolicy::strongerMarkerID ( markerID1, markerID2 ) );
310 }
311 
312 template <typename MarkerIDPolicy>
313 markerID_Type Marker<MarkerIDPolicy>::setWeakerMarkerID ( markerID_Type const& markerID1,
314  markerID_Type const& markerID2 )
315 {
316  return setMarkerID ( MarkerIDPolicy::weakerMarkerID ( markerID1, markerID2 ) );
317 }
318 
319 template <typename MarkerIDPolicy>
320 markerID_Type Marker<MarkerIDPolicy>::setStrongerMarkerID ( markerID_Type const& markerID )
321 {
322  if ( isMarkerUnset() )
323  {
324  return M_markerID = markerID;
325  }
326  return setMarkerID ( MarkerIDPolicy::strongerMarkerID ( this->markerID(), markerID ) );
327 }
328 
329 template <typename MarkerIDPolicy>
330 markerID_Type Marker<MarkerIDPolicy>::setWeakerMarkerID ( markerID_Type const& markerID )
331 {
332  if ( isMarkerUnset() )
333  {
334  return M_markerID = markerID;
335  }
336  return setMarkerID ( MarkerIDPolicy::weakerMarkerID ( this->markerID(), markerID ) );
337 }
338 
339 template <typename MarkerIDPolicy>
340 bool Marker<MarkerIDPolicy>::isMarkerSet() const
341 {
342  return M_markerID != nullMarkerID();
343 }
344 
345 template <typename MarkerIDPolicy>
346 bool Marker<MarkerIDPolicy>::isMarkerUnset() const
347 {
348  return M_markerID == nullMarkerID();
349 }
350 
351 template <typename MarkerIDPolicy>
352 void Marker<MarkerIDPolicy>::unsetMarkerID()
353 {
355 }
356 
357 template <typename MarkerIDPolicy>
358 bool Marker<MarkerIDPolicy>::hasEqualMarkerID (markerID_Type const& markerID) const
359 {
360  return MarkerIDPolicy::EqualFlags (markerID, M_markerID);
361 }
362 
363 template <typename MarkerIDPolicy>
364 void Marker<MarkerIDPolicy>::showMe ( std::ostream& output) const
365 {
366  if ( M_markerID == nullMarkerID() )
367  {
368  output << "UNSET";
369  }
370  else
371  {
372  output << M_markerID;
373  }
374 }
375 
376 } //Namespace LifeV
377 
378 #endif /* MARKER_H */
static bool equalMarkerID(const markerID_Type &a, const markerID_Type &b)
Equality operator.
Definition: Marker.cpp:82
MarkerIDPolicy MarkerIDPolicy_Type
The policy used by this marker.
Definition: Marker.hpp:155
markerID_Type setMarkerID(markerID_Type const &markerID)
Set marker to the given value.
Definition: Marker.hpp:291
Marker()
Empty Constructor.
Definition: Marker.hpp:261
bool hasEqualMarkerID(markerID_Type const &markerID) const
Compares marker IDs.
Definition: Marker.hpp:358
MarkerIDStandardPolicy - Class that defines the standard policies on Marker Ids.
Definition: Marker.hpp:89
void unsetMarkerID()
Put marker to NULLFLAG.
Definition: Marker.hpp:352
static const markerID_Type S_NULLMARKERID
Definition: Marker.hpp:96
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
markerID_Type setWeakerMarkerID(markerID_Type const &markerID)
Sets to the weaker marker ID.
Definition: Marker.hpp:330
void updateInverseJacobian(const UInt &iQuadPt)
bool isMarkerUnset() const
It enquires if marker ID is different than the null marker ID.
Definition: Marker.hpp:346
static markerID_Type const & nullMarkerID()
Returns the null marker ID.
Definition: Marker.hpp:285
static markerID_Type weakerMarkerID(markerID_Type const &a, markerID_Type const &b)
Selects the weaker Marker ID between marker IDs.
Definition: Marker.cpp:69
uint32_type ID
IDs.
Definition: LifeV.hpp:194
bool isMarkerSet() const
It enquires if marker ID is different than the null marker ID.
Definition: Marker.hpp:340
markerID_Type markerID() const
Extracts the entityFlag associated to the marked entity.
Definition: Marker.hpp:279
static markerID_Type strongerMarkerID(markerID_Type const &a, markerID_Type const &b)
Selects the stronger Marker ID.
Definition: Marker.cpp:56
markerID_Type updateMarkerID(markerID_Type const &markerID)
Set marker to the given value only if unset.
Definition: Marker.hpp:297
markerID_Type M_markerID
Definition: Marker.hpp:251
virtual ~Marker()
Destructor.
Definition: Marker.hpp:171
markerID_Type setWeakerMarkerID(markerID_Type const &markerID1, markerID_Type const &markerID2)
Sets the marker ID to the weaker marker ID of two given markers.
Definition: Marker.hpp:313
markerID_Type setStrongerMarkerID(markerID_Type const &markerID)
Sets to the strongest marker ID.
Definition: Marker.hpp:320
Marker(Marker< MarkerIDPolicy > const &markerBase)
Copy Constructor.
Definition: Marker.hpp:273
Marker(markerID_Type &p)
Constructor given the marker ID.
Definition: Marker.hpp:267
Marker - Base marker class.
Definition: Marker.hpp:148
markerID_Type setStrongerMarkerID(markerID_Type const &markerID1, markerID_Type const &markerID2)
Sets the marker ID to the stronger marker ID of two given markers.
Definition: Marker.hpp:306
virtual void showMe(std::ostream &output=std::cout) const
Display information about the marker object.
Definition: Marker.hpp:364