msbGrid  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
growthcohesion.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 _GROWTH_COHESION_HH_
24 #define _GROWTH_COHESION_HH_
25 
26 #include <vector>
27 
28 namespace msbGrid
29 {
30 template< typename StepperT >
32  , const msbGrid :: InputData *inData0
33  , const StepperT *stepper0
34  , const int &blIdx0);
35 
36 template< typename StepperT >
38  , const msbGrid :: InputData *inData0
39  , const StepperT *stepper0
40  , const int &blIdx0
41  , const msbGrid :: Color &color0);
42 
44  , const msbGrid :: PointsBlock &bl1
45  , const msbGrid :: InputData *inData0);
46 
48  , const msbGrid :: InputData *inData0);
49 }
50 
51 template< typename StepperT >
53  , const msbGrid :: InputData *inData0
54  , const StepperT *stepper0
55  , const int &blIdx0)
56 {
57  assert(inData0->blockNumber() != 0);
58 
59  typedef msbGrid :: Point Point;
61 
62  typedef msbGrid :: Scalar Scalar;
63  enum { dim = msbGrid :: dim };
64 
66 
67 #if 0
68  ptRef.infos();
69 #endif
70  const Scalar dr = inData0->dr(), Rmin = stepper0->Id() * stepper0->velocity() [ blIdx0 ] * dr, R = Rmin + stepper0->velocity() [ blIdx0 ] * dr;
71  std :: vector< Scalar > xmin(dim, 0.0), xmax(dim, 0.0), dx(dim, 0.0);
72  for ( int i = 0; i < dim; ++i ) {
73  xmin [ i ] = ptRef.pos() [ i ] - R - dr;
74  xmax [ i ] = ptRef.pos() [ i ] + R + dr;
75 #if 0
76  std :: cout << "xmin[" << i << "] = " << xmin [ i ] << " , "
77  << "xmax[" << i << "] = " << xmax [ i ] << " , "
78  << "\n";
79 #endif
80  }
81 
82  PointsBlock bl1;
83  for ( Scalar x = xmin [ 0 ]; x <= xmax [ 0 ]; x += dr ) {
84  for ( Scalar y = xmin [ 1 ]; y <= xmax [ 1 ]; y += dr ) {
85  Point pt1(x, y);
86  Scalar dist = eucDistance(ptRef, pt1);
87 #if 0
88  pt1.infos();
89  std :: cout << "dist = " << dist << "\n";
90  std :: cout << "TOLERANCE = " << TOLERANCE << "\n";
91  std :: cout << "Rmin = " << Rmin << "\n";
92  std :: cout << "R = " << R << "\n";
93 #endif
94  if ( dist > ( Rmin + TOLERANCE ) && dist <= ( R + TOLERANCE ) ) {
95  bl1.add(pt1);
96  }
97  }
98  }
99 
100 #if !DESABLE_ROTATION == 1
101  bl1.rotate(inData0->blockAngle() [ blIdx0 ], ptRef);
102 #endif
103 
104  return bl1;
105 }
106 
107 template< typename StepperT >
109  , const msbGrid :: InputData *inData0
110  , const StepperT *stepper0
111  , const int &blIdx0
112  , const msbGrid :: Color &color0)
113 {
114  assert(inData0->blockNumber() != 0);
115 
116  typedef msbGrid :: Point Point;
118 
119  typedef msbGrid :: Scalar Scalar;
120  enum { dim = msbGrid :: dim };
121 
123  const Scalar &dr = inData0->dr();
124  Scalar Rmin, R;
125  if ( stepper0->Id() == 0 ) {
126  Rmin = 0.0;
127  R = dr / sqrt(2.0);
128  } else {
129  Rmin = dr / sqrt(2.0) + ( stepper0->Id() - 1 ) * stepper0->velocity() [ blIdx0 ] * dr;
130  R = Rmin + stepper0->velocity() [ blIdx0 ] * dr;
131  }
132 
133  std :: vector< Scalar > xmin(dim, 0.0), xmax(dim, 0.0), dx(dim, 0.0);
134  for ( int i = 0; i < dim; ++i ) {
135  xmin [ i ] = ptRef.pos() [ i ] - ( ( color0 == msbGrid :: Color :: Red ) ? dr / 2.0 : 0.0 ) - stepper0->Id() * stepper0->velocity() [ blIdx0 ] * dr;
136  xmax [ i ] = ptRef.pos() [ i ] + ( ( color0 == msbGrid :: Color :: Red ) ? dr / 2.0 : 0.0 ) + stepper0->Id() * stepper0->velocity() [ blIdx0 ] * dr;
137  }
138 
139  PointsBlock bl1;
140  for ( Scalar y = xmin [ 1 ]; y <= ( xmax [ 1 ] + TOLERANCE ); y += dr ) {
141  for ( Scalar x = xmin [ 0 ]; x <= ( xmax [ 0 ] + TOLERANCE ); x += dr ) {
142  Point pt1(x, y);
143  Scalar dist = eucDistance(ptRef, pt1);
144  if ( ( dist - Rmin ) > TOLERANCE && ( dist - R ) <= TOLERANCE ) {
145  bl1.add(pt1);
146  }
147 
148  if ( ( color0 == msbGrid :: Color :: Green ) && ( dist <= TOLERANCE ) && ( stepper0->Id() == 0 ) ) {
149  bl1.add(pt1);
150  }
151  }
152  }
153 
154 #if !DESABLE_ROTATION == 1
155  bl1.rotate(inData0->blockAngle() [ blIdx0 ], ptRef);
156 #endif
157 
158  return bl1;
159 }
160 
162  , const msbGrid :: PointsBlock &bl1
163  , const msbGrid :: InputData *inData0)
164 {
165  /* Note : 0.8 is enough to get good elements quality between the external boundary and the neighboring blocks */
166  assert(inData0->dist2BoundCoeff() >= 0.8);
167 
168  typedef msbGrid :: Point Point;
170 
171  typedef msbGrid :: Scalar Scalar;
172  enum { dim = msbGrid :: dim };
173 
175 
176  const Scalar dr = inData0->dr();
177  const Scalar xMin = inData0->xMin() + dr * inData0->dist2BoundCoeff() - TOLERANCE;
178  const Scalar xMax = inData0->xMax() - dr * inData0->dist2BoundCoeff() + TOLERANCE;
179  const Scalar yMin = inData0->yMin(xMin) + dr * inData0->dist2BoundCoeff() - TOLERANCE;
180  const Scalar yMax = inData0->yMax(xMax) - dr * inData0->dist2BoundCoeff() + TOLERANCE;
181 
182 #if 0
183  std :: cout << "dr = " << dr << " , "
184  << "xMin = " << xMin << " , "
185  << "xMax = " << xMax << " , "
186  << "yMin = " << yMin << " , "
187  << "yMax = " << yMax << " , "
188  << "TOLERANCE = " << TOLERANCE << " , "
189  << "bl0.size() = " << bl0.size() << " , "
190  << "bl1.size() = " << bl1.size() /* << " , "*/
191  << "\n";
192 #endif
193 
194  for ( int iEnt = 0; iEnt < bl0.size(); ++iEnt ) {
195 #if 0
196  bl0.vEnt() [ iEnt ].infos("bl0");
197 #endif
198  for ( int jEnt = 0; jEnt < bl1.size(); ++jEnt ) {
199 #if 0
200  bl1.vEnt() [ jEnt ].infos("bl1");
201 #endif
202  // const bool dist = ( eucDistance(bl0.vEnt()[iEnt], bl1.vEnt()[jEnt]) <= (dr * inData0->interBlockDistCoeff() + TOLERANCE) );
203  const bool dist = ( ( eucDistance(bl0.vEnt() [ iEnt ], bl1.vEnt() [ jEnt ]) - dr * inData0->interBlockDistCoeff() ) <= -TOLERANCE );
204  const bool xmin = bl0.vEnt() [ iEnt ].x() [ 0 ] <= xMin;
205  const bool xmax = bl0.vEnt() [ iEnt ].x() [ 0 ] >= xMax;
206  const bool ymin = bl0.vEnt() [ iEnt ].x() [ 1 ] <= yMin;
207  const bool ymax = bl0.vEnt() [ iEnt ].x() [ 1 ] >= yMax;
208 
209  if ( xmin || xmax || ymin || ymax ) {
210  bl0.vEnt() [ iEnt ].mark() = true;
211 #if 0
212  std :: cout << "(xmin || xmax || ymin || ymax) is true\n";
213 #endif
214  }
215 
216  if ( dist ) {
217  bl0.vEnt() [ iEnt ].mark() = true;
218 #if 0
219  std :: cout << "(dist) is true\n";
220 #endif
221  }
222  }
223  }
224 }
225 
227  , const msbGrid :: InputData *inData0)
228 {
229  /* Note : 0.8 is enough to get good elements quality between the external boundary and the neighboring blocks */
230  assert(inData0->dist2BoundCoeff() >= 0.8);
231 
232  typedef msbGrid :: Point Point;
234 
235  typedef msbGrid :: Scalar Scalar;
236  enum { dim = msbGrid :: dim };
237 
239 
240  const Scalar dr = inData0->dr();
241  const Scalar xLInf = inData0->xMin() + dr * inData0->dist2BoundCoeff();
242  const Scalar xLSupp = inData0->xMax() - dr * inData0->dist2BoundCoeff();
243  const Scalar yLInf = inData0->yMin(xLInf) + dr * inData0->dist2BoundCoeff();
244  const Scalar yLSupp = inData0->yMax(xLSupp) - dr * inData0->dist2BoundCoeff();
245 
246  for ( int iEnt = 0; iEnt < bl0.size(); ++iEnt ) {
247  const bool xLInfCond = ( ( bl0.vEnt() [ iEnt ].x() [ 0 ] - xLInf ) <= ( -TOLERANCE ) );
248  const bool xLSuppCond = ( ( bl0.vEnt() [ iEnt ].x() [ 0 ] - xLSupp ) >= ( +TOLERANCE ) );
249  const bool yLInfCond = ( ( bl0.vEnt() [ iEnt ].x() [ 1 ] - yLInf ) <= ( -TOLERANCE ) );
250  const bool yLSuppCond = ( ( bl0.vEnt() [ iEnt ].x() [ 1 ] - yLSupp ) >= ( +TOLERANCE ) );
251 
252  if ( xLInfCond || xLSuppCond || yLInfCond || yLSuppCond ) {
253  bl0.vEnt() [ iEnt ].mark() = true;
254  }
255  }
256 }
257 
258 #endif /* #ifndef _GROWTH_COHESION_HH_ */