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
geo0d.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 */
22 #ifndef _GEO0D_HH_
23 #define _GEO0D_HH_
24 
25 #include <boost/operators.hpp>
26 
27 #include <feel/feelcore/feel.hpp>
28 #include <feel/feelalg/glas.hpp>
31 #include <feel/feelmesh/marker.hpp>
32 
33 namespace Feel
34 {
35 class MeshBase;
36 
48 
56 template<uint16_type Dim, typename T = double>
57 class Geo0D
58  :
59 public boost::equality_comparable<Geo0D<Dim,T> >,
60 public boost::less_than_comparable<Geo0D<Dim,T> >,
61 public boost::less_than_comparable<Geo0D<Dim,T>, size_type>,
62 public GeoEntity<Simplex<0, 1, Dim> >,
63 public node<T, Dim>::type
64 {
66  typedef typename node<T, Dim>::type super2;
67 public:
68 
69  typedef Geo0D<Dim,T> self_type;
70  static const uint16_type nDim = Dim;
71  typedef T value_type;
72  typedef typename matrix_node<value_type>::type matrix_node_type;
73  typedef super2 node_type;
74  typedef typename node<T, 2>::type parametric_node_type;
79  Geo0D();
80 
91  explicit Geo0D( size_type id, bool boundary = false, bool is_vertex = false );
92 
105  explicit Geo0D( size_type id, value_type x, value_type y, value_type z, bool boundary = false, bool is_vertex = false );
106 
114  Geo0D( value_type x, value_type y, value_type z )
115  :
117  super2( Dim ),
118  M_is_vertex( false )
119  {
120  this->operator[]( 0 ) = x;
121 
122  if ( Dim >= 2 )
123  this->operator[]( 1 ) = y;
124 
125  if ( Dim == 3 )
126  this->operator[]( 2 ) = z;
127  }
128 
129 
140  Geo0D( size_type id, node_type const& __x, bool boundary = false, bool is_vertex = false );
141 
148  Geo0D( node_type const& __x )
149  :
151  super2( __x ),
152  M_is_vertex( false )
153  {
154  }
155 
162  template<typename AE>
163  Geo0D( ublas::vector_expression<AE> const& __expr )
164  :
166  super2( __expr ),
167  M_is_vertex( false )
168  {
169  }
170 
175  Geo0D( Geo0D const & G );
176 
184  Geo0D & operator=( Geo0D const & G );
185 
186  template<typename AE>
187  Geo0D & operator=( ublas::vector_expression<AE> const& expr )
188  {
189  super2::operator=( expr );
190  return *this;
191  }
192  template<typename AE>
193  Geo0D & operator+=( ublas::vector_expression<AE> const& expr )
194  {
195  super2::operator+=( expr );
196  return *this;
197  }
198 
199  value_type& operator()( int i )
200  {
201  return this->operator[]( i );
202  }
203 
204  value_type operator()( int i ) const
205  {
206  return this->operator[]( i );
207  }
208 
213  bool isVertex() const
214  {
215  return M_is_vertex;
216  }
217 
221  void setAsVertex( bool v )
222  {
223  M_is_vertex = v;
224  }
225 
229  void setMesh( MeshBase const* m )
230  {
231  M_mesh = m;
232  }
233 
237  MeshBase const* mesh() const
238  {
239  return M_mesh;
240  }
241 
245  Geo0D const& node() const
246  {
247  return *this;
248  }
249 
253  matrix_node_type G() const
254  {
255  matrix_node_type __G( Dim, 1 );
256  ublas::column( __G, 0 ) = *this;
257  return __G;
258  }
259 
263  matrix_node_type vertices() const
264  {
265  return this->G();
266  }
267 
271  value_type measure() const
272  {
273  return 0;
274  }
275 
279  bool isParametric() const
280  {
281  return M_is_parametric;
282  }
283 
287  int gDim() const
288  {
289  return M_gdim;
290  }
291 
295  int gTag() const
296  {
297  return M_gtag;
298  }
299 
303  parametric_node_type const& parametricCoordinates() const
304  {
305  return M_uv;
306  }
307 
311  value_type u() const
312  {
313  return M_uv[0];
314  }
315 
319  value_type v() const
320  {
321  return M_uv[1];
322  }
323 
329  void setNode( node_type const& __n )
330  {
331  *this = __n;
332  }
333 
337  bool operator==( Geo0D const& geo0d ) const
338  {
339  return this->id() == geo0d.id();
340  }
341 
342  bool operator<( Geo0D const& e ) const
343  {
344  return this->id() < e.id();
345  };
346 
347  bool operator<( size_type __i ) const
348  {
349  return this->id() < __i;
350  };
351 
360  std::ostream & showMe( bool verbose = false, std::ostream & c = std::cout ) const;
361 
366  void setPoint( uint16_type const /*i*/, self_type const & p )
367  {
368  *this = p;
369  }
370 
374  self_type& translate( node_type const& trans )
375  {
376  *this += trans;
377  return *this;
378  }
379 
380  Marker1 const& marker() const
381  {
382  return M_marker1;
383  }
384  Marker1& marker()
385  {
386  return M_marker1;
387  }
388  void setMarker( flag_type v )
389  {
390  return M_marker1.assign( v );
391  }
392 
393  Marker2 const& marker2() const
394  {
395  return M_marker2;
396  }
397  Marker2& marker2()
398  {
399  return M_marker2;
400  }
401  void setMarker2( flag_type v )
402  {
403  return M_marker2.assign( v );
404  }
405 
406  Marker3 const& marker3() const
407  {
408  return M_marker3;
409  }
410  Marker3& marker3()
411  {
412  return M_marker3;
413  }
414  void setMarker3( flag_type v )
415  {
416  return M_marker3.assign( v );
417  }
418 
425  void setTags( std::vector<int> const& tags )
426  {
427  this->setMarker( tags[0] );
428 
429  if ( tags.size() > 1 )
430  this->setMarker2( tags[1] );
431 
432  if ( tags.size() > 2 )
433  this->setProcessId( tags[2] );
434  }
435 
436  std::vector<int> tags() const
437  {
438  std::vector<int> thetags(3);
439  thetags[0] = M_marker1.value();
440  thetags[1] = M_marker2.value();
441  thetags[2] = this->processId();
442  return thetags;
443  }
447  void setGDim( int gdim )
448  {
449  M_gdim = gdim;
450  M_is_parametric = true;
451  }
452 
456  void setGTag( int gtag )
457  {
458  M_gtag = gtag;
459  M_is_parametric = true;
460  }
461 
466  void setParametricCoordinates( parametric_node_type const& x )
467  {
468  M_uv = x;
469  M_is_parametric = true;
470  }
471 
476  void setParametricCoordinates( value_type u, value_type v )
477  {
478  M_uv[0] = u;
479  M_uv[1] = v;
480  M_is_parametric = true;
481  }
482 
483 private:
484 
485  friend class boost::serialization::access;
486  template<class Archive>
487  void serialize( Archive & ar, const unsigned int version )
488  {
489  ar & boost::serialization::base_object<super>( *this );
490  ar & boost::serialization::base_object<super2>( *this );
491  //ar & M_is_vertex;
492  //ar & M_is_parametric;
493  ar & M_marker1;
494  ar & M_marker2;
495  ar & M_marker3;
496  /*
497  ar & M_gdim;
498  ar & M_gtag;
499  ar & M_uv;
500  */
501  }
502 
503 private:
504  bool M_is_vertex;
505  bool M_is_parametric;
506 
507  // mesh to which the geond element belongs to
508  MeshBase const* M_mesh;
509 
510 
511  Marker1 M_marker1;
512  Marker2 M_marker2;
513  Marker3 M_marker3;
514 
515  int M_gdim;
516  int M_gtag;
517  parametric_node_type M_uv;
518 };
519 
520 // Alias for Geo0D<3>
521 typedef Geo0D<3> Point;
522 
523 
524 /*--------------------------------------------------------------
525  Geo0D
526  ---------------------------------------------------------------*/
527 template<uint16_type Dim, typename T>
529  :
530  super( 0, MESH_ENTITY_INTERNAL ),
531  super2( Dim ),
532  M_is_vertex( false ),
533  M_is_parametric( false ),
534  M_marker1(),
535  M_marker2(),
536  M_marker3(),
537  M_gdim( 0 ),
538  M_gtag( 0 ),
539  M_uv( 2 )
540 {
541  this->clear();
542 }
543 
544 template<uint16_type Dim, typename T>
545 Geo0D<Dim, T>::Geo0D( size_type id, bool boundary, bool is_vertex )
546  :
548  super2( Dim ),
549  M_is_vertex( is_vertex ),
550  M_marker1(),
551  M_marker2(),
552  M_marker3(),
553  M_gdim( 0 ),
554  M_gtag( 0 ),
555  M_uv( 2 )
556 {
557  this->clear();
558  this->setOnBoundary( boundary );
559 }
560 
561 template<uint16_type Dim, typename T>
562 Geo0D<Dim, T>::Geo0D( size_type id, value_type x, value_type y, value_type z, bool boundary, bool is_vertex )
563  :
565  super2( Dim ),
566  M_is_vertex( is_vertex ),
567  M_is_parametric( false ),
568  M_marker1(),
569  M_marker2(),
570  M_marker3(),
571  M_gdim( 0 ),
572  M_gtag( 0 ),
573  M_uv( 2 )
574 {
575  this->operator[]( 0 ) = x;
576 
577  if ( Dim >= 2 )
578  this->operator[]( 1 ) = y;
579 
580  if ( Dim == 3 )
581  this->operator[]( 2 ) = z;
582 
583  this->setOnBoundary( boundary );
584 }
585 
586 template<uint16_type Dim, typename T>
587 Geo0D<Dim, T>::Geo0D( size_type id, node_type const& __p, bool boundary, bool is_vertex )
588  :
590  super2( __p ),
591  M_is_vertex( is_vertex ),
592  M_is_parametric( false ),
593  M_marker1(),
594  M_marker2(),
595  M_marker3(),
596  M_gdim( 0 ),
597  M_gtag( 0 ),
598  M_uv( 2 )
599 {
600  FEELPP_ASSERT( __p.size() == Dim )( __p )( Dim ).error( "invalid node" );
601 
602  this->setOnBoundary( boundary );
603 }
604 
605 template<uint16_type Dim, typename T>
606 Geo0D<Dim, T>::Geo0D( Geo0D const & G )
607  :
608  super( G ),
609  super2( G ),
610  M_is_vertex( G.M_is_vertex ),
611  M_is_parametric( G.M_is_parametric ),
612  M_marker1( G.M_marker1 ),
613  M_marker2( G.M_marker2 ),
614  M_marker3( G.M_marker3 ),
615  M_gdim( G.M_gdim ),
616  M_gtag( G.M_gtag ),
617  M_uv( G.M_uv )
618 {
619 }
620 
621 template<uint16_type Dim, typename T>
622 Geo0D<Dim, T> &
624 {
625  if ( this == &G )
626  return *this;
627 
628  super::operator=( G );
629  super2::operator=( G );
630  M_is_vertex = G.M_is_vertex;
631  M_is_parametric = G.M_is_parametric;
632  M_marker1 = G.M_marker1;
633  M_marker2 = G.M_marker2;
634  M_marker3 = G.M_marker3;
635  M_gdim = G.M_gdim;
636  M_gtag = G.M_gtag;
637  M_uv = G.M_uv;
638  return *this;
639 }
640 
641 template<uint16_type Dim, typename T>
642 std::ostream &
643 Geo0D<Dim, T>::showMe( bool /*verbose*/, std::ostream & out ) const
644 {
645  out.setf( std::ios::scientific, std::ios::floatfield );
646  out << "----- BEGIN of Geo0D ---\n";
647  out << "id = " << this->id() << " node:" << this->node() << "\n";
648  out << "is a vertex = " << isVertex() << "\n";
649  out << "----- END OF Geo0D ---\n";
650  return out;
651 }
652 
653 template<uint16_type Dim, typename T>
654 inline
655 DebugStream&
656 operator<<( DebugStream& __os, Geo0D<Dim, T> const& __n )
657 {
658  if ( __os.doPrint() )
659  {
660  std::ostringstream __str;
661 
662  __str << __n.showMe( true, __str );
663 
664  __os << __str.str() << "\n";
665  }
666 
667  return __os;
668 }
669 template<uint16_type Dim, typename T>
670 inline
671 NdebugStream&
672 operator<<( NdebugStream& __os, Geo0D<Dim, T> const& __n )
673 {
674  return __os;
675 }
676 
677 
678 template<typename T>
679 inline
680 T
681 distance( Geo0D<1,T> const& p1, Geo0D<1,T> const& p2 )
682 {
683  return ublas::norm_2( p1-p2 );
684 }
685 
686 template<typename T>
687 inline
688 T
689 distance( Geo0D<2,T> const& p1, Geo0D<2,T> const& p2 )
690 {
691  return ublas::norm_2( p1-p2 );
692 }
693 
694 template<typename T>
695 inline
696 T
697 distance( Geo0D<3,T> const& p1, Geo0D<3,T> const& p2 )
698 {
699  return ublas::norm_2( p1-p2 );
700 }
701 template<typename T>
702 inline
703 Geo0D<1,T>
704 middle( Geo0D<1,T> const& p1, Geo0D<1,T> const& p2 )
705 {
706  return ( p1+p2 )/2;
707 }
708 
709 template<typename T>
710 inline
711 Geo0D<2,T>
712 middle( Geo0D<2,T> const& p1, Geo0D<2,T> const& p2 )
713 {
714  return ( p1+p2 )/2;
715 }
716 
717 template<typename T>
718 inline
719 Geo0D<3,T>
720 middle( Geo0D<3,T> const& p1, Geo0D<3,T> const& p2 )
721 {
722  return ( p1+p2 )/2;
723 }
724 
725 template<typename E1,typename E2>
726 inline
727 ublas::vector<double>
728 cross( ublas::vector_expression<E1> _p1,
729  ublas::vector_expression<E2> _p2 )
730 {
731  ublas::vector<double> v( 3 );
732  ublas::vector<double> p1( _p1 );
733  ublas::vector<double> p2( _p2 );
734  v( 0 ) = p1( 1 )*p2( 2 )-p1( 2 )*p2( 1 );
735  v( 1 ) = p1( 2 )*p2( 0 )-p1( 0 )*p2( 2 );
736  v( 2 ) = p1( 0 )*p2( 1 )-p1( 1 )*p2( 0 );
737  return v;
738 }
739 
740 template<typename T>
741 inline
742 ublas::vector<double>
743 cross( Geo0D<3,T> p1,
744  Geo0D<3,T> p2 )
745 {
746  ublas::vector<double> v( 3 );
747  v( 0 ) = p1( 1 )*p2( 2 ) - p1( 2 )*p2( 1 );
748  v( 1 ) = p1( 2 )*p2( 0 ) - p1( 0 )*p2( 2 );
749  v( 2 ) = p1( 0 )*p2( 1 ) - p1( 1 )*p2( 0 );
750  return v;
751 }
752 
753 
754 } // Feel
755 
756 #endif
757 

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