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
block.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): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2005-01-26
7 
8  Copyright (C) 2005,2006 EPFL
9  Copyright (C) 2006-2012 Universite Joseph Fourier (Grenoble I)
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef __Block_H
31 #define __Block_H 1
32 
33 #include <sstream>
34 #include <list>
35 
36 #include <feel/feelcore/feel.hpp>
37 
38 namespace Feel
39 {
40 
41  //template<typename T> class MatrixSparse;
42 
43 namespace vf
44 {
46 
53 class Block
54 {
55 public:
56 
57 
61 
62 
64 
68 
69  Block( uint16_type __ic = 0, uint16_type __jc = 0, size_type __gic = 0, size_type __gjc = 0 )
70  :
71  M_lr( __ic ),
72  M_lc( __jc ),
73  M_gr( __gic ),
74  M_gc( __gjc )
75  {}
76  Block( Block const & __b )
77  :
78  M_lr( __b.M_lr ),
79  M_lc( __b.M_lc ),
80  M_gr( __b.M_gr ),
81  M_gc( __b.M_gc )
82  {}
83  ~Block()
84  {}
85 
87 
91 
92  Block& operator=( Block const& __b )
93  {
94  if ( FEELPP_ISLIKELY( this != &__b ) )
95  {
96  M_lr = __b.M_lr;
97  M_lc = __b.M_lc;
98  M_gr = __b.M_gr;
99  M_gc = __b.M_gc;
100  }
101 
102  return *this;
103  }
104 
105 
107 
111 
112  uint16_type localRow() const
113  {
114  return M_lr;
115  }
116  uint16_type localColumn() const
117  {
118  return M_lc;
119  }
120 
121  size_type globalRowStart() const
122  {
123  return M_gr;
124  }
125  size_type globalColumnStart() const
126  {
127  return M_gc;
128  }
129 
131 
135 
136  void setLocalRow( uint16_type __lr )
137  {
138  M_lr = __lr;
139  }
140  void setLocalColumn( uint16_type __lc )
141  {
142  M_lc = __lc;
143  }
144 
145  void setGlobalRowStart( size_type __r )
146  {
147  M_gr = __r;
148  }
149  void setGlobalColumnStart( size_type __c )
150  {
151  M_gc = __c;
152  }
153 
155 
159 
160 
162 
163 protected:
164 
165 private:
166 
167  uint16_type M_lr;
168  uint16_type M_lc;
169  size_type M_gr;
170  size_type M_gc;
171 };
172 typedef std::list<Block> list_block_type;
173 
174 inline
175 std::ostream&
176 operator<<( std::ostream& __os, Block const& __b )
177 {
178  __os << "Block [ "
179  << __b.localRow() << ","
180  << __b.localColumn() << ","
181  << __b.globalRowStart() << ","
182  << __b.globalColumnStart() << "]";
183 
184  return __os;
185 }
187 
188 
189 template <typename T>
190 struct BlocksBase
191 {
192  typedef T block_type;
193 
194  BlocksBase()
195  :
196  M_nRow( 0 ),
197  M_nCol( 0 ),
198  M_vec( 1 ),
199  M_cptToBuild( 0 )
200  {}
201 
202  BlocksBase( uint16_type nr,uint16_type nc )
203  :
204  M_nRow( nr ),
205  M_nCol( nc ),
206  M_vec( nr*nc ),
207  M_cptToBuild( 0 )
208  {}
209 
210  BlocksBase( uint16_type nr,uint16_type nc,block_type const& a )
211  :
212  M_nRow( nr ),
213  M_nCol( nc ),
214  M_vec( nr*nc, a ),
215  M_cptToBuild( 0 )
216  {}
217 
218  BlocksBase( BlocksBase<T> const& b )
219  :
220  M_nRow( b.M_nRow ),
221  M_nCol( b.M_nCol ),
222  M_vec( b.M_vec ),
223  M_cptToBuild( b.M_cptToBuild )
224  {}
225 
226  BlocksBase<T>
227  operator<<( block_type const& m ) const
228  {
229  BlocksBase<T> newBlock( *this );
230  newBlock.M_vec[M_cptToBuild]=m;
231  ++( newBlock.M_cptToBuild );
232  return newBlock;
233  }
234 
235  void
236  push_back( block_type const& m )
237  {
238  M_vec[M_cptToBuild]=m;
239  ++M_cptToBuild;
240  }
241 #if 0
242  void
243  operator<<( block_type const& m )
244  {
245  M_vec[M_cptToBuild]=m;
246  ++M_cptToBuild;
247  //return *this;
248  }
249 #endif
250 
251  block_type &
252  operator()( uint16_type c1,uint16_type c2 )
253  {
254  return M_vec[c1*M_nCol+c2];
255  }
256 
257  block_type
258  operator()( uint16_type c1,uint16_type c2 ) const
259  {
260  return M_vec[c1*M_nCol+c2];
261  }
262 
263  std::vector<block_type> const&
264  getSetOfBlocks() const
265  {
266  return M_vec;
267  }
268 
269  uint16_type nRow() const
270  {
271  return M_nRow;
272  }
273  uint16_type nCol() const
274  {
275  return M_nCol;
276  }
277 
278  void reset()
279  {
280  M_cptToBuild=0;
281  M_vec.clear();
282  M_vec.resize( this->nRow()*this->nCol() );
283  }
284 
285  void merge( uint16_type c1,uint16_type c2,BlocksBase<T> const& b )
286  {
287  const uint16_type nRb = b.nRow(), nCb = b.nCol();
288  for ( uint16_type i=0; i<nRb; ++i )
289  for ( uint16_type j=0; j<nCb; ++j )
290  this->operator()( c1+i,c2+j ) = b( i,j );
291  }
292 
293  BlocksBase<T> subBlock(uint16_type x1r,uint16_type x1c,uint16_type x2r,uint16_type x2c) const
294  {
295  const uint16_type nrow = x2r-x1r+1;
296  const uint16_type ncol = x2c-x1c+1;
297  BlocksBase<T> res(nrow,ncol);
298  for (uint16_type kr=0;kr<nrow;++kr)
299  for (uint16_type kc=0;kc<ncol;++kc)
300  res(kr,kc)=this->operator()(x1r+kr,x1c+kc);
301  return res;
302  }
303 
304  BlocksBase<T> transpose() const
305  {
306  BlocksBase<T> res(this->nCol(),this->nRow());
307  for (uint16_type i=0;i<res.nRow();++i)
308  for (uint16_type j=0;j<res.nCol();++j)
309  res(i,j) = this->operator()(j,i);
310  return res;
311  }
312 
313 private :
314  uint16_type M_nRow,M_nCol;
315  std::vector<block_type> M_vec;
316  uint16_type M_cptToBuild;
317 };
318 
319 
320 
321 template <int NR, int NC, typename T>
322 struct Blocks : public BlocksBase<T>
323 {
324  static const uint16_type NBLOCKROWS = NR;
325  static const uint16_type NBLOCKCOLS = NC;
326 
327  typedef BlocksBase<T> super_type;
328  typedef T block_type;
329 
330  Blocks()
331  :
332  super_type( NR,NC )
333  {}
334 
335  Blocks( block_type const& a )
336  :
337  super_type( NR,NC, a )
338  {}
339 
340  Blocks( super_type const& a )
341  :
342  super_type( a )
343  {}
344 
345  Blocks<NR,NC,T>
346  operator<<( block_type const& m ) const
347  {
348  Blocks<NR,NC,T> newBlock = super_type::operator<<( m ) ;
349  return newBlock;
350  }
351 
352  void
353  push_back( block_type const& m )
354  {
355  super_type::push_back( m );
356  }
357 
358 #if 0
359  void
360  operator<<( block_type const& m )
361  {
362  super_type::operator<<( m );
363  }
364 #endif
365 
366 };
367 
368 } // vf
369 
370 class BlocksStencilPattern : public vf::BlocksBase<size_type>
371 {
372  typedef vf::BlocksBase<size_type> super_type;
373  typedef BlocksStencilPattern self_type;
374 public :
375 
376  BlocksStencilPattern(uint16_type nr,uint16_type nc)
377  :
378  super_type(nr,nc)
379  {}
380 
381  BlocksStencilPattern(uint16_type nr,uint16_type nc, size_type pat)
382  :
383  super_type(nr,nc,pat)
384  {}
385 
386  BlocksStencilPattern(super_type const & b)
387  :
388  super_type(b)
389  {}
390 
391  self_type
392  operator<<( size_type const& m ) const
393  {
394  return super_type::operator<<( m );
395  }
396 
397 };
398 
399 
400 } // feel
401 #endif /* __Block_H */

Generated on Sun Oct 20 2013 08:24:54 for Feel++ by doxygen 1.8.4