msbGrid  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
block.hh
Go to the documentation of this file.
1 /*****************************************************************************
2 * This program is part of the msbGrid software *
3 * *
4 * msbGrid stands for multi-structured block Grid generator *
5 * *
6 * msbGrid is a free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * msbGrid is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * See the file COPYING for full copying permissions. *
17 *****************************************************************************/
23 #ifndef _BLOCK_HH_
24 #define _BLOCK_HH_
25 
26 namespace msbGrid
27 {
28 template< typename EntityT >
29 class Block;
30 }
31 
32 template< typename EntityT >
33 class msbGrid :: Block
34 {
35 public:
36  typedef EntityT Entity;
38 
39  enum { dim = Entity :: dim };
40  typedef typename Entity :: Scalar Scalar;
41  typedef typename Entity :: Color Color;
42 
43 private:
44  int Id_;
45  bool mark_;
47 
48  std :: vector< Entity > vEnt_;
49 
50 public:
52  {
53  Id_ = 0;
54  mark_ = false;
55  declination_ = 0.0;
56 
57  vEnt_.clear();
58  }
59 
60  ~Block() {}
61 
62  const std :: vector< Entity > &vEnt() const
63  { return vEnt_; }
64 
65  std :: vector< Entity > &vEnt()
66  { return vEnt_; }
67 
68  const int size() const
69  { return vEnt_.size(); }
70 
71  const bool empty() const
72  { return ( vEnt_.size() == 0 ); }
73 
74  const int &Id() const
75  { return Id_; }
76 
77  int &Id()
78  { return Id_; }
79 
80  const int putId(const int &Id0 = 1)
81  {
82  int Id1 = Id0;
83  for ( unsigned int iEnt = 0; iEnt < size(); ++iEnt ) {
84  if ( !vEnt_ [ iEnt ].mark() ) {
85  vEnt_ [ iEnt ].Id() = Id1;
86  ++Id1;
87  }
88  }
89 
90  return Id1;
91  }
92 
93  const int entId(const int &Id0 = 1)
94  {
95  int Id1 = Id0;
96  for ( int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
97  if ( !vEnt_ [ iEnt ].marked() ) {
98  vEnt_ [ iEnt ].Id() = Id1;
99  ++Id1;
100  }
101  }
102 
103  return Id1;
104  }
105 
106  const bool hasId() const
107  { return ( Id_ != 0 ); }
108 
109  const bool &mark() const
110  { return mark_; }
111 
112  bool &mark()
113  { return mark_; }
114 
115  const Scalar &declination() const
116  { return declination_; }
117 
119  { return declination_; }
120 
121  void add(const Entity &ent0)
122  { vEnt_.push_back(ent0); }
123 
124  void add(const std :: vector< Entity > &vEnt0)
125  {
126  for ( int iEnt = 0; iEnt < vEnt0.size(); ++iEnt ) {
127  add(vEnt0 [ iEnt ]);
128  }
129  }
130 
131  void add(const ThisT &bl0)
132  { add( bl0.vEnt() ); }
133 
134  void cleanUp()
135  {
136  std :: vector< Entity > vEnt0;
137  vEnt0.clear();
138  for ( int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
139  if ( !vEnt_ [ iEnt ].mark() ) {
140  vEnt0.push_back(vEnt_ [ iEnt ]);
141  }
142  }
143 
144  vEnt_.clear();
145  for ( int iEnt = 0; iEnt < vEnt0.size(); ++iEnt ) {
146  vEnt_.push_back(vEnt0 [ iEnt ]);
147  }
148  }
149 
150  void clear()
151  { vEnt_.clear(); }
152 
153  void translate(const std :: vector< Scalar > &dx)
154  {
155  assert(dx.size() == dim);
156 
157  for ( int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
158  vEnt_ [ iEnt ].translate(dx);
159  }
160  }
161 
162  template< typename PointT >
163  void rotate(const Scalar &_angle, const PointT &mc)
164  {
165  for ( unsigned int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
166  vEnt_ [ iEnt ].rotate(_angle, mc);
167  }
168  }
169 
170  void rotate(const Scalar &_angle)
171  {
172  for ( int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
173  vEnt_ [ iEnt ].rotate( _angle, vEnt_ [ iEnt ].pos() );
174  }
175  }
176 
177  void infos(const std :: string &name0 = "")
178  {
179  std :: cout << "# block " << name0 << " ";
180 
181  std :: cout << ": size = " << size()
182  << " , Id = " << Id_
183  << " , mark = " << mark_
184  << " , declination = " << declination_ << "\n";
185 
186  for ( int iEnt = 0; iEnt < vEnt_.size(); ++iEnt ) {
187  vEnt_ [ iEnt ].infos();
188  }
189 
190  std :: cout << "\n";
191  }
192 }; /* class msbGrid::Block */
193 
194 #endif /* #ifndef _BLOCK_HH_ */
195 
196 #ifndef _POINTS_BLOCK_HH_
197 #define _POINTS_BLOCK_HH_
198 
199 namespace msbGrid
200 {
201 class PointsBlock;
202 }
203 
204 class msbGrid :: PointsBlock : public msbGrid :: Block< msbGrid :: Point >
205 {
206 public:
209 
211 
212 private:
213  /* data for *.m output files */
215 
216  /* data for *.geo output files */
217  Scalar cl_; /* Characteristic length */
218 
219 public:
221  {
222  marker_.symbol = "'o'";
223  marker_.size = 4;
224  marker_.edgeColor = Black;
225  marker_.faceColor = White;
226 
227  cl_ = Scalar(1.0);
228  }
229 
230  const msbGrid :: Marker &marker() const
231  { return marker_; }
232 
233  void putMarkerSymbol(const std :: string &value)
234  {
235  this->marker_.symbol = value;
236 
237  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
238  this->vEnt() [ iEnt ].marker().symbol = this->marker_.symbol;
239  }
240  }
241 
242  void putMarkerSize(const double &value)
243  {
244  this->marker_.size = value;
245 
246  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
247  this->vEnt() [ iEnt ].marker().size = this->marker_.size;
248  }
249  }
250 
251  void putMarkerEdgeColor(const Color &value)
252  {
253  this->marker_.edgeColor = value;
254 
255  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
256  this->vEnt() [ iEnt ].marker().edgeColor = this->marker_.edgeColor;
257  }
258  }
259 
260  void putMarkerFaceColor(const Color &value)
261  {
262  this->marker_.faceColor = value;
263 
264  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
265  this->vEnt() [ iEnt ].marker().faceColor = this->marker_.faceColor;
266  }
267  }
268 
269  void putMarkerProperties(const std :: string &mSymbol
270  , const double &mSize
271  , const Color &mEdgeColor
272  , const Color &mFaceColor)
273  {
274  putMarkerSymbol(mSymbol);
275  putMarkerSize(mSize);
276  putMarkerEdgeColor(mEdgeColor);
277  putMarkerFaceColor(mFaceColor);
278  }
279 
280  const Scalar &cl() const
281  { return cl_; }
282 
284  { return cl_; }
285 
286  void putCl(const Scalar &cl0)
287  {
288  for ( int ip = 0; ip < size(); ++ip ) {
289  if ( !this->vEnt() [ ip ].mark() ) {
290  this->vEnt() [ ip ].cl() = cl0;
291  }
292  }
293  }
294 }; /* class msbGrid::PointsBlock */
295 
296 #endif /* #ifndef _POINTS_BLOCK_HH_ */
297 
298 #ifndef _EDGES_BLOCK_HH_
299 #define _EDGES_BLOCK_HH_
300 
301 namespace msbGrid
302 {
303 class EdgesBlock;
304 }
305 
306 class msbGrid :: EdgesBlock : public msbGrid :: Block< msbGrid :: Edge >
307 {
308 public:
311 
312 private:
314 
315 public:
317  {
318  color_ = Black;
319  }
320 
322 
323  const Color &color() const
324  { return color_; }
325 
326  void putColor(const Color &color0)
327  {
328  color_ = color0;
329 
330  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
331  this->vEnt() [ iEnt ].color() = color_;
332  }
333  }
334 }; /* class msbGrid::EdgesBlock */
335 
336 #endif /* #ifndef _EDGES_BLOCK_HH_ */
337 
338 #ifndef _CELLS_BLOCK_HH_
339 #define _CELLS_BLOCK_HH_
340 
341 namespace msbGrid
342 {
343 template< typename CellT >
345 }
346 
347 template< typename CellT >
348 class msbGrid :: CellsBlock : public msbGrid :: Block< CellT >
349 {
350 public:
351  typedef CellT Cell;
353  typedef typename ParentT :: Color Color;
354 
355 private:
357 
358 public:
360  {
361  color_ = Black;
362  }
363 
365 
366  const Color &color() const
367  { return color_; }
368 
369  void putColor(const Color &color0)
370  {
371  color_ = color0;
372 
373  for ( int iEnt = 0; iEnt < this->size(); ++iEnt ) {
374  this->vEnt() [ iEnt ].color() = color_;
375  }
376  }
377 }; /* class msbGrid::CellsBlock */
378 
379 #endif /* #ifndef _CELLS_BLOCK_HH_ */
380 
381 #include <growthcohesion.hh>
382 
383 #ifndef _POINTS_MULTI_BLOCK_HH_
384 #define _POINTS_MULTI_BLOCK_HH_
385 
386 namespace msbGrid
387 {
388 class PointsMultiBlock;
389 }
390 
391 class msbGrid :: PointsMultiBlock : public std :: vector< msbGrid :: PointsBlock >
392 {
393 public:
394  typedef std :: vector< msbGrid :: PointsBlock > ParentT;
395 
398 
399 private:
402 
403 public:
405  {}
406 
408 
409  void init(const InputData *inData0, const Color &color0)
410  {
411  inData_ = inData0;
412  color_ = color0;
413  ( * this ).resize( inData_->blockNumber() );
414  }
415 
416  const Color &color() const
417  { return color_; }
418 
419  template< typename StepperT >
420  void fill(StepperT &stepper)
421  {
422  for ( int iStep = 0; iStep < stepper.iStepMax(); ++iStep ) {
423  if ( !stepper.otherStep() ) {
424  continue;
425  }
426 
427  #if VERBOSE_LEVEL >= 1
428  std :: cout << "## step = " << ( iStep + 1 ) << "\n";
429  #endif
430  step2_(stepper);
431  }
432  }
433 
434 private:
435  template< typename StepperT >
436  const bool step_(StepperT &stepper)
437  {
438  Scalar distRef = inData_->dr() / sqrt(2.0);
439 
440  std :: vector< PointsBlock > mpscNew;
441  stepper.otherStep() = false;
442  int Jnd = 0;
443  for ( int Ind = 0; Ind < size(); ++Ind ) {
444  if ( stepper.newStep() [ Ind ] ) {
445  Point ptRef( ( * this ) [ Ind ].vEnt() [ 0 ] );
446  PointsBlock ps( msbGrid :: growth(ptRef, inData_, & stepper, Ind) );
447  if ( !ps.empty() ) {
448  mpscNew.push_back(ps);
449  stepper.newStep() [ Ind ] = update_(mpscNew, Jnd, Ind);
450  ++Jnd;
451  ( * this ) [ Ind ].add(mpscNew [ Jnd - 1 ]);
452 
453  if ( stepper.newStep() [ Ind ] == true ) {
454  stepper.otherStep() = true;
455  }
456  }
457  }
458  }
459 
460  stepper.Id() += 1;
461  stepper.firstStep() = false;
462  return stepper.otherStep();
463  }
464 
465  template< typename StepperT >
466  const bool step2_(StepperT &stepper)
467  {
468  Scalar distRef = inData_->dr() / sqrt(2.0);
469 
470  std :: vector< PointsBlock > mpscNew;
471  mpscNew.clear();
472  stepper.otherStep() = false;
473  int jBl1 = 0;
474  for ( int iBl1 = 0; iBl1 < inData_->blockNumber(); ++iBl1 ) {
475  if ( stepper.newStep() [ iBl1 ] ) {
476  const Point ptRef(inData_->blockCenter() [ iBl1 ].first, inData_->blockCenter() [ iBl1 ].second);
477  PointsBlock ps( msbGrid :: growth2( ptRef, inData_, & stepper, iBl1, ( * this ).color() ) );
478  if ( !ps.empty() ) {
479  mpscNew.push_back(ps);
480  stepper.newStep() [ iBl1 ] = update2_(mpscNew, jBl1, iBl1);
481  ( * this ) [ iBl1 ].add(mpscNew [ jBl1 ]);
482  ++jBl1;
483 
484  if ( stepper.newStep() [ iBl1 ] == true ) {
485  stepper.otherStep() = true;
486  }
487  }
488  }
489  }
490 
491  stepper.Id() += 1;
492  stepper.firstStep() = false;
493  return stepper.otherStep();
494  }
495 
496  const bool update_(std :: vector< PointsBlock > &mpscNew, const int &Jnd, const int &Ind)
497  {
498  for ( int iBl1 = 0; iBl1 < size(); ++iBl1 ) {
499  if ( iBl1 != Ind ) {
500  msbGrid :: cohesion(mpscNew [ Jnd ], ( * this ) [ iBl1 ], inData_);
501  }
502 
503  if ( size() == 1 ) {
504  msbGrid :: cohesion(mpscNew [ Jnd ], ( * this ) [ iBl1 ], inData_);
505  }
506  }
507 
508  mpscNew [ Jnd ].cleanUp();
509  return ( mpscNew [ Jnd ].size() != 0 );
510  }
511 
512  const bool update2_(std :: vector< PointsBlock > &mpscNew, const int &Jnd, const int &Ind)
513  {
514  if ( size() == 1 ) {
515  msbGrid :: cohesion(mpscNew [ Jnd ], inData_);
516  }
517 
518  for ( int iBl1 = 0; iBl1 < size(); ++iBl1 ) {
519  if ( iBl1 != Ind ) {
520  msbGrid :: cohesion(mpscNew [ Jnd ], ( * this ) [ iBl1 ], inData_);
521  }
522  }
523 
524  mpscNew [ Jnd ].cleanUp();
525  return ( mpscNew [ Jnd ].size() != 0 );
526  }
527 }; /* class msbGrid::PointsMultiBlock */
528 
529 #endif /* #ifndef _POINTS_MULTI_BLOCK_HH_ */