Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bareitems.hpp
1 /*
2 This file is part of the Feel library
3 Copyright (C) 2001,2002,2003,2004 EPFL, INRIA and Politechnico di Milano
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3.0 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
104 #ifndef _MESHBAREITEMS_HH_
105 #define _MESHBAREITEMS_HH_
106 
115 #include<utility>
116 #include<vector>
117 #include<map>
118 #include<algorithm>
119 #include<iostream>
120 
121 #include <feel/feelcore/feel.hpp>
122 
123 namespace Feel
124 {
131 struct BarePoint
132 {
134  BarePoint() : first( 0 )
135  {}
136 
139  {}
140 
143 
144 };
145 
154 struct BareEdge
155 {
157  BareEdge() : first( 0 ), second( 0 )
158  {}
159 
161  BareEdge( size_type i, size_type j ) : first( i ), second( j )
162  {}
163 
166 
169 };
170 
181 struct BareFace
182 {
184  BareFace() : first( 0 ), second( 0 ), third( 0 )
185  {}
186 
188  BareFace( size_type i, size_type j, size_type k ) : first( i ), second( j ), third( k )
189  {}
190 
196  BareFace( size_type i, const BareEdge & e ) : first( i ), second( e.first ), third( e.second )
197  {}
198 
205 };
206 
207 
210 inline
211 std::pair<BarePoint, bool>
212 makeBarePoint( size_type const i )
213 {
214  return std::make_pair( BarePoint( i ), true );
215 }
232 inline
233 std::pair<BareEdge, bool>
234 makeBareEdge( size_type const i, size_type const j )
235 {
236  if ( i < j )
237  {
238  return std::make_pair( BareEdge( i, j ), true );
239  }
240 
241  else
242  {
243  return std::make_pair( BareEdge( j, i ), false );
244  ;
245  }
246 }
247 inline
248 std::pair<BareEdge, bool>
249 makeBareItem( size_type i, size_type j )
250 {
251  return makeBareEdge( i, j );
252 }
253 
266 inline
267 BareEdge
268 setBareEdge( size_type const i, size_type const j )
269 {
270  BareEdge be;
271  be.first = i < j ? i : j;
272  be.second = ( i - be.first ) + j;
273  return be;
274 }
275 
292 inline
293 BareEdge
294 setBareEdgeNo( size_type const i, size_type const j )
295 {
296  return BareEdge( i, j );
297 }
298 
299 
311 std::pair<BareFace, bool> makeBareFace( size_type i, size_type j, size_type k );
312 inline
313 std::pair<BareFace, bool>
314 makeBareItem( size_type i, size_type j, size_type k )
315 {
316  return makeBareFace( i, j, k );
317 }
318 
331 std::pair<BareFace, bool> makeBareFace( size_type i, size_type j, size_type k, size_type l );
332 
333 inline
334 std::pair<BareFace, bool>
335 makeBareItem( size_type i, size_type j, size_type k, size_type l )
336 {
337  return makeBareFace( i, j, k, l );
338 }
339 
348 inline
349 bool
350 operator!=( const BareEdge & p1 , const BareEdge & p2 )
351 {
352  return p1.first != p2.first || p1.second != p2.second;
353 }
354 
358 inline
359 bool
360 operator==( const BareEdge & p1 , const BareEdge & p2 )
361 {
362  return p1.first == p2.first && p1.second == p2.second;
363 }
364 
368 inline
369 bool
370 operator>( const BareEdge & e1 , const BareEdge & e2 )
371 {
372  return e2.first > e1.first || ( e2.first == e1.first && e2.second > e1.second );
373 }
374 
378 inline
379 bool
380 operator>=( const BareEdge & e1 , const BareEdge & e2 )
381 {
382  return e1 == e2 || e1 > e2;
383 }
384 
388 inline
389 bool
390 operator<( const BareEdge & e1 , const BareEdge & e2 )
391 {
392  return e2.first < e1.first || ( e2.first == e1.first && e2.second < e1.second );
393 }
394 
398 inline
399 bool
400 operator<=( const BareEdge & e1 , const BareEdge & e2 )
401 {
402  return e1 == e2 || e1 < e2;
403  ;
404 }
405 
407 inline
408 bool
409 operator!=( const BareFace & p1 , const BareFace & p2 )
410 {
411  return p1.first != p2.first || p1.second != p2.second || p1.third != p2.third;
412 }
413 
414 
416 inline
417 bool
418 operator==( const BareFace & p1 , const BareFace & p2 )
419 {
420  return p1.first == p2.first && p1.second == p2.second && p1.third == p2.third;
421 }
422 
426 template <typename T>
427 struct cmpBareItem;
428 
432 // Specialisations
433 template <>
435 {
436  bool operator() ( const BarePoint & e1, const BarePoint & e2 ) const
437  {
438  return e2.first > e1.first;
439  }
440 };
441 
442 // Specialisations
443 template <>
445 {
446  bool operator() ( const BareEdge & e1, const BareEdge & e2 ) const
447  {
448  return e2.first > e1.first || ( e2.first == e1.first && e2.second > e1.second );
449  }
450 };
451 
455 template <>
457 {
458  bool operator() ( const BareFace & e1, const BareFace & e2 ) const
459  {
460  if ( e2.first > e1.first )
461  return true;
462 
463  if ( e2.first == e1.first )
464  {
465  if ( e2.second > e1.second )
466  return true;
467 
468  if ( e2.second == e1.second )
469  return e2.third > e1.third;
470  }
471 
472  return false;
473  }
474 };
475 
486 template <typename BareItem>
487 class BareItemsHandler: public std::map<BareItem, Feel::size_type, cmpBareItem<BareItem> >
488 {
489 public:
490  typedef std::map<BareItem, Feel::size_type, cmpBareItem<BareItem> > container;
491  typedef typename container::size_type size_type;
492  typedef typename container::iterator iterator;
493  typedef typename container::const_iterator const_iterator;
494  typedef std::pair<const BareItem, size_type> value_type;
495 
497 
499  bool isThere( BareItem const & ) const;
500 
502  size_type id( BareItem const & ) const;
503 
505  bool setId( BareItem const & item, size_type const i );
506 
508  std::pair<size_type, bool> addIfNotThere( BareItem const & );
509 
511  std::pair<size_type, bool> addIfNotThere( BareItem const &, const size_type id );
512 
514  bool isThereDel( BareItem const & );
515 
517  size_type howMany() const
518  {
519  return container::size();
520  }
521 
523  size_type maxId() const
524  {
525  return M_id_count;
526  }
527 
529  void showMe() const;
530 
531 private:
532  size_type M_id_count;
533 };
534 
535 /*********************************************************************************
536  IMPLEMENTATIONS
537 *********************************************************************************/
538 //
542 template <typename BareItem>
544 inline
545 size_type getId( std::pair<BareItem, size_type> const & i )
546 {
547  return i.second;
548 }
549 
551 template <typename BareItem>
552 inline
553 BareItem getItem( std::pair<BareItem, size_type> const & i )
554 {
555  return i.first;
556 }
557 
558 
559 // BareItemsHandler
560 template <class BareItem>
562  :
563  M_id_count( 0 )
564 { }
565 
566 
567 template <class BareItem>
568 inline
569 bool
570 BareItemsHandler<BareItem>::isThere( const BareItem & s ) const
571 {
572  return find( s ) != container::end();
573 }
574 
575 template <class BareItem>
576 inline
577 bool
578 BareItemsHandler<BareItem>::setId( const BareItem & s, size_type const id )
579 {
580  const_iterator i = find( s );
581 
582  if ( i != container::end() )
583  {
584  i->second = id;
585  return true;
586  }
587 
588  else
589  {
590  return false;
591  }
592 
593 }
594 
595 template <class BareItem>
596 inline
597 typename BareItemsHandler<BareItem>::size_type
598 BareItemsHandler<BareItem>::id( const BareItem & s ) const
599 {
600  const_iterator i = find( s );
601 
602  if ( i != container::end() )
603  return i->second;
604 
605  else
606  return 0;
607 }
608 
609 template <class BareItem>
610 inline
611 std::pair<typename BareItemsHandler<BareItem>::size_type, bool>
613 {
614  std::pair<typename BareItemsHandler<BareItem>::iterator, bool> i( insert( std::make_pair( s, M_id_count ) ) );
615 
616  if ( i.second )
617  ++M_id_count;
618 
619  return std::make_pair( ( i.first ) ->second, i.second );
620 }
621 
622 template <class BareItem>
623 inline
624 std::pair<typename BareItemsHandler<BareItem>::size_type, bool>
625 BareItemsHandler<BareItem>::addIfNotThere( const BareItem & s, const size_type id )
626 {
627  std::pair<typename BareItemsHandler<BareItem>::iterator, bool> i( insert( std::make_pair( s, id ) ) );
628  // Set new id in any case.
629  ( i.first ) ->second = id;
630 
631  // id count should grow +1
632  //FEELPP_ASSERT( M_id_count == id )( M_id_count )( id ).error ( "invalid item id" );
633  if ( i.second )
634  {
635  M_id_count = id;
636  ++M_id_count;
637  }
638 
639  // for consistency with other version.
640  return std::make_pair( id, i.second );
641 }
642 
643 template <class BareItem>
644 bool
646 {
647  return erase( s ) != 0;
648 }
649 
650 template <typename BareItem>
651 inline
653 {
654  std::cout << "BareItemsHandler: " << std::endl;
655  std::cout << "Number of Items stored: " << this->size() << std::endl;
656  std::cout << "Max Id stored : " << this->maxId() << std::endl;
657  std::cout << "End of Information";
658 }
659 }
660 #endif

Generated on Fri Oct 25 2013 14:24:04 for Feel++ by doxygen 1.8.4