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
pointset.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Gilles Steiner <gilles.steiner@epfl.ch>
6  Date: 2005-11-10
7 
8  Copyright (C) 2005,2006 EPFL
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library 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
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
30 #ifndef __PointSet_H
31 #define __PointSet_H 1
32 
33 
36 
37 
38 namespace Feel
39 {
40 namespace ublas = boost::numeric::ublas;
41 
53 template<class Convex, typename T>
54 class PointSet : public VisitableBase<>
55 {
56  typedef VisitableBase<> super;
57 
58 public:
59 
60  typedef Convex convex_type;
61  typedef T value_type;
63 
65 
66  typedef typename node<value_type>::type node_type;
67  typedef ublas::matrix<value_type, ublas::column_major> nodes_type;
68 
69  PointSet()
70  :
71  super(),
72  M_npoints( 0 ),
73  M_points(),
74  M_points_face( Convex::numTopologicalFaces )
75  {}
76 
77  PointSet( const self_type& P )
78  :
79  super(),
80  M_npoints( P.nPoints() ),
81  M_points( P.points() ),
82  M_points_face( P.M_points_face )
83  {}
84 
85  PointSet( uint32_type Npoints )
86  :
87  super(),
88  M_npoints( Npoints ),
89  M_points( Convex::nDim, Npoints ),
90  M_points_face( Convex::numTopologicalFaces )
91  {}
92 
93  PointSet( uint32_type Npoints, uint16_type Dim )
94  :
95  super(),
96  M_npoints( Npoints ),
97  M_points( Dim, Npoints ),
98  M_points_face( Convex::numTopologicalFaces )
99  {}
100 
101  PointSet( nodes_type const& SomePoints )
102  :
103  super(),
104  M_npoints( SomePoints.size2() ),
105  M_points( SomePoints ),
106  M_points_face( Convex::numTopologicalFaces )
107  {}
108 
109  virtual ~PointSet()
110  {}
111 
112  self_type& operator=( self_type const& p )
113  {
114  if ( this != &p )
115  {
116  M_npoints = p.M_npoints;
117  M_points = p.M_points;
118  M_points_face = p.M_points_face;
119  }
120 
121  return *this;
122  }
123 
124 
125  uint32_type nPoints() const
126  {
127  return M_npoints;
128  }
129  nodes_type const& points() const
130  {
131  return M_points;
132  }
133  ublas::matrix_column<nodes_type const> point( uint32_type __i ) const
134  {
135  return ublas::column( M_points, __i );
136  }
137  ublas::matrix_column<nodes_type> point( uint32_type __i )
138  {
139  return ublas::column( M_points, __i );
140  }
141 
142 
143  nodes_type const& points( uint16_type f ) const
144  {
145  return M_points_face[f];
146  }
147  ublas::matrix_column<nodes_type const> point( uint16_type f, uint32_type __i ) const
148  {
149  return ublas::column( M_points_face[f], __i );
150  }
151  ublas::matrix_column<nodes_type> point( uint16_type f, uint32_type __i )
152  {
153  return ublas::column( M_points_face[f], __i );
154  }
155 
156  void setName( std::string name, uint32_type order )
157  {
158  std::ostringstream ostr;
159 
160  ostr << Convex::nDim
161  << "_" << order
162  << "_" << Convex::nRealDim;
163 
164  pointsInfo = ostr.str();
165 
166  pointsName = name;
167  }
168 
169  std::string getName()
170  {
171  return pointsName;
172  }
173 
174  std::string getPointsInfo()
175  {
176  return pointsInfo;
177  }
178 
179  void toPython()
180  {
181  RefElem RefConv;
182 
183  std::ostringstream ostr;
184 
185  ostr << getName() << "_" << getPointsInfo() << ".py";
186 
187  std::ofstream ofs( ostr.str().c_str() );
188 
189  ofs << "from pyx import *\n";
190 
191  ofs << "p=path.path(";
192 
193  for ( uint16_type i = 0; i < Convex::numEdges; ++i )
194  {
195  for ( uint16_type j = 0; j < 2; ++j )
196  {
197  node_type x( 2 );
198 
199  if ( Convex::nRealDim == 1 )
200  {
201  x( 0 ) = RefConv.edgeVertex( i,j )( 0 );
202  x( 1 ) = value_type( 0 );
203  }
204 
205  if ( Convex::nRealDim == 2 )
206  {
207  x = RefConv.edgeVertex( i, j );
208  }
209 
210  if ( Convex::nRealDim == 3 )
211  {
212  x( 0 ) = RefConv.edgeVertex( i, j )( 0 )+RefConv.edgeVertex( i, j )( 1 )*std::cos( M_PI/4 );
213  x( 1 ) = RefConv.edgeVertex( i, j )( 2 )+RefConv.edgeVertex( i, j )( 1 )*std::sin( M_PI/4 );
214  }
215 
216  if ( j == 0 )
217  ofs << "path.moveto(" << double( x( 0 ) )<< "," << double( x( 1 ) ) << "),\n";
218 
219  else if ( j == 1 )
220  ofs << "path.lineto(" << double( x( 0 ) )<< "," << double( x( 1 ) ) << "),\n";
221  }
222  }
223 
224  ofs << "path.closepath() )\n";
225 
226  ofs << "text.set(mode=\"latex\")\n"
227  << "c = canvas.canvas()\n"
228  << "c.stroke(p, [style.linewidth.Thin])\n";
229 
230  for ( uint16_type i = 0; i < nPoints(); ++i )
231  {
232  node_type x( 2 );
233 
234  if ( Convex::nRealDim == 1 )
235  {
236  x( 0 ) = this->point( i )( 0 );
237  x( 1 ) = value_type( 0 );
238  }
239 
240  if ( Convex::nRealDim == 2 )
241  {
242  x = this->point( i );
243  }
244 
245  if ( Convex::nRealDim == 3 )
246  {
247  x( 0 ) = this->point( i )( 0 ) + this->point( i )( 1 )*std::cos( M_PI/4 );
248  x( 1 ) = this->point( i )( 2 ) + this->point( i )( 1 )*std::sin( M_PI/4 );
249  }
250 
251 
252  ofs << "c.fill ( path.circle(" << double( x( 0 ) ) << "," << double( x( 1 ) )<< ", 0.02 ),[deco.filled([color.rgb.red])])\n";
253  ofs << "c.text( " << double( x( 0 )+0.025 ) << "," << double( x( 1 )+0.025 )<< ", r\"{\\scriptsize " << i << "}\")\n";
254  }
255 
256  ofs << "c.writeEPSfile(\"" << getName() << "_" << getPointsInfo()
257  << "\", document.paperformat.A4)\n";
258  }
259 
260  FEELPP_DEFINE_VISITABLE();
261 
262 protected:
263 
267  void setPoints( nodes_type const& pts )
268  {
269  M_points = pts;
270  M_npoints = pts.size2();
271  }
272 
276  void setPoints( uint16_type f, nodes_type const& n )
277  {
278  M_points_face[f] = n;
279  }
280 protected:
281 
282  uint32_type M_npoints;
283  nodes_type M_points;
284  std::vector<nodes_type> M_points_face;
285 
286  //Identifies if points are equispaced, warpblend, fekete
287  std::string pointsName;
288 
289  //Identifies the Order, dim and realdim
290  std::string pointsInfo;
291 
292 };
293 
294 } // Feel
295 
296 #endif /* _PointSet_H */

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