doxygen: add newline after \file
[blender.git] / intern / elbeem / intern / solver_util.cpp
1 /** \file
2  * \ingroup elbeem
3  */
4 /******************************************************************************
5  *
6  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
7  * Copyright 2003-2006 Nils Thuerey
8  *
9  * Standard LBM Factory implementation
10  *
11  *****************************************************************************/
12
13 #include "solver_class.h"
14 #include "solver_relax.h"
15 #include "particletracer.h"
16
17 // MPT
18 #include "ntl_world.h"
19 #include "simulation_object.h"
20
21 #include "globals.h"
22
23 #include <stdlib.h>
24 #include <zlib.h>
25 #ifndef sqrtf
26 #define sqrtf sqrt
27 #endif
28
29 /******************************************************************************
30  * helper functions
31  *****************************************************************************/
32
33 // try to enhance surface?
34 #define SURFACE_ENH 2
35
36 //! for raytracing
37 void LbmFsgrSolver::prepareVisualization( void ) {
38         int lev = mMaxRefine;
39         int workSet = mLevel[lev].setCurr;
40
41         int mainGravDir=6; // if normalizing fails, we asume z-direction gravity
42         LbmFloat mainGravLen = 0.;
43         FORDF1{
44                 LbmFloat thisGravLen = dot(LbmVec(dfVecX[l],dfVecY[l],dfVecZ[l]), mLevel[mMaxRefine].gravity ); 
45                 if(thisGravLen>mainGravLen) {
46                         mainGravLen = thisGravLen;
47                         mainGravDir = l;
48                 }
49         }
50
51 #if LBMDIM==2
52         // 2d, place in the middle of isofield slice (k=2)
53 #  define ZKD1 0
54         // 2d z offset = 2, lbmGetData adds 1, so use one here
55 #  define ZKOFF 1
56         // reset all values...
57         for(int k= 0; k< 5; ++k) 
58    for(int j=0;j<mLevel[lev].lSizey-0;j++) 
59     for(int i=0;i<mLevel[lev].lSizex-0;i++) {
60                 *mpIso->lbmGetData(i,j,ZKOFF)=0.0;
61         }
62 #else // LBMDIM==2
63         // 3d, use normal bounds
64 #  define ZKD1 1
65 #  define ZKOFF k
66         // reset all values...
67         for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) 
68    for(int j=0;j<mLevel[lev].lSizey-0;j++) 
69     for(int i=0;i<mLevel[lev].lSizex-0;i++) {
70                 *mpIso->lbmGetData(i,j,ZKOFF)=0.0;
71         }
72 #endif // LBMDIM==2
73
74         // MPT, ignore
75         if((glob_mpactive) && (glob_mpnum>1) && (glob_mpindex==0)) {
76                 mpIso->resetAll(0.);
77         }
78
79
80         LbmFloat minval = mIsoValue*1.05; // / mIsoWeight[13]; 
81         // add up...
82         float val = 0.0;
83         for(int k= getForZMin1(); k< getForZMax1(lev); ++k) 
84    for(int j=1;j<mLevel[lev].lSizey-1;j++) 
85     for(int i=1;i<mLevel[lev].lSizex-1;i++) {
86                         const CellFlagType cflag = RFLAG(lev, i,j,k,workSet);
87                         //if(cflag&(CFBnd|CFEmpty)) {
88
89 #if SURFACE_ENH==0
90
91                         // no enhancements...
92                         if( (cflag&(CFFluid|CFUnused)) ) {
93                                 val = 1.;
94                         } else if( (cflag&CFInter) ) {
95                                 val = (QCELL(lev, i,j,k,workSet, dFfrac)); 
96                         } else {
97                                 continue;
98                         }
99
100 #else // SURFACE_ENH!=1
101                         if(cflag&CFBnd) {
102                                 // treated in second loop
103                                 continue;
104                         } else if(cflag&CFUnused) {
105                                 val = 1.;
106                         } else if( (cflag&CFFluid) && (cflag&CFNoBndFluid)) {
107                                 // optimized fluid
108                                 val = 1.;
109                         } else if( (cflag&(CFEmpty|CFInter|CFFluid)) ) {
110                                 int noslipbnd = 0;
111                                 int intercnt = 0;
112                                 FORDF1 { 
113                                         const CellFlagType nbflag = RFLAG_NB(lev, i,j,k, workSet,l);
114                                         if(nbflag&CFInter){ intercnt++; }
115
116                                         // check all directions otherwise we get bugs with splashes on obstacles
117                                         if(l!=mainGravDir) continue; // only check bnd along main grav. dir
118                                         //if((nbflag&CFBnd)&&(nbflag&CFBndNoslip)){ noslipbnd=1; }
119                                         if((nbflag&CFBnd)){ noslipbnd=1; }
120                                 }
121
122                                 if(cflag&CFEmpty) {
123                                         // special empty treatment
124                                         if((noslipbnd)&&(intercnt>6)) {
125                                                 *mpIso->lbmGetData(i,j,ZKOFF) += minval;
126                                         } else if((noslipbnd)&&(intercnt>0)) {
127                                                 // necessary?
128                                                 *mpIso->lbmGetData(i,j,ZKOFF) += mIsoValue*0.9;
129                                         } else {
130                                                 // nothing to do...
131                                         }
132
133                                         continue;
134                                 } else if(cflag&(CFNoNbEmpty|CFFluid)) {
135                                         // no empty nb interface cells are treated as full
136                                         val=1.0;
137                                 } else {
138                                         val = (QCELL(lev, i,j,k,workSet, dFfrac)); 
139                                 }
140                                 
141                                 if(noslipbnd) {
142                                         if(val<minval) val = minval; 
143                                         *mpIso->lbmGetData(i,j,ZKOFF) += minval-( val * mIsoWeight[13] ); 
144                                 }
145                         } else { // all others, unused?
146                                 continue;
147                         } 
148 #endif // SURFACE_ENH>0
149
150                         *mpIso->lbmGetData( i-1 , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[0] ); 
151                         *mpIso->lbmGetData( i   , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[1] ); 
152                         *mpIso->lbmGetData( i+1 , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[2] ); 
153
154                         *mpIso->lbmGetData( i-1 , j   ,ZKOFF-ZKD1) += ( val * mIsoWeight[3] ); 
155                         *mpIso->lbmGetData( i   , j   ,ZKOFF-ZKD1) += ( val * mIsoWeight[4] ); 
156                         *mpIso->lbmGetData( i+1 , j   ,ZKOFF-ZKD1) += ( val * mIsoWeight[5] ); 
157
158                         *mpIso->lbmGetData( i-1 , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[6] ); 
159                         *mpIso->lbmGetData( i   , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[7] ); 
160                         *mpIso->lbmGetData( i+1 , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[8] ); 
161
162
163                         *mpIso->lbmGetData( i-1 , j-1  ,ZKOFF  ) += ( val * mIsoWeight[9] ); 
164                         *mpIso->lbmGetData( i   , j-1  ,ZKOFF  ) += ( val * mIsoWeight[10] ); 
165                         *mpIso->lbmGetData( i+1 , j-1  ,ZKOFF  ) += ( val * mIsoWeight[11] ); 
166
167                         *mpIso->lbmGetData( i-1 , j    ,ZKOFF  ) += ( val * mIsoWeight[12] ); 
168                         *mpIso->lbmGetData( i   , j    ,ZKOFF  ) += ( val * mIsoWeight[13] ); 
169                         *mpIso->lbmGetData( i+1 , j    ,ZKOFF  ) += ( val * mIsoWeight[14] ); 
170
171                         *mpIso->lbmGetData( i-1 , j+1  ,ZKOFF  ) += ( val * mIsoWeight[15] ); 
172                         *mpIso->lbmGetData( i   , j+1  ,ZKOFF  ) += ( val * mIsoWeight[16] ); 
173                         *mpIso->lbmGetData( i+1 , j+1  ,ZKOFF  ) += ( val * mIsoWeight[17] ); 
174
175
176                         *mpIso->lbmGetData( i-1 , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[18] ); 
177                         *mpIso->lbmGetData( i   , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[19] ); 
178                         *mpIso->lbmGetData( i+1 , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[20] ); 
179
180                         *mpIso->lbmGetData( i-1 , j   ,ZKOFF+ZKD1) += ( val * mIsoWeight[21] ); 
181                         *mpIso->lbmGetData( i   , j   ,ZKOFF+ZKD1)+= ( val * mIsoWeight[22] ); 
182                         *mpIso->lbmGetData( i+1 , j   ,ZKOFF+ZKD1) += ( val * mIsoWeight[23] ); 
183
184                         *mpIso->lbmGetData( i-1 , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[24] ); 
185                         *mpIso->lbmGetData( i   , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[25] ); 
186                         *mpIso->lbmGetData( i+1 , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[26] ); 
187         }
188
189         // TEST!?
190 #if SURFACE_ENH>=2
191
192         if(mFsSurfGenSetting&fssgNoObs) {
193                 for(int k= getForZMin1(); k< getForZMax1(lev); ++k) 
194                  for(int j=1;j<mLevel[lev].lSizey-1;j++) 
195                         for(int i=1;i<mLevel[lev].lSizex-1;i++) {
196                                 const CellFlagType cflag = RFLAG(lev, i,j,k,workSet);
197                                 if(cflag&(CFBnd)) {
198                                         CellFlagType nbored=0;
199                                         LbmFloat avgfill=0.,avgfcnt=0.;
200                                         FORDF1 { 
201                                                 const int ni = i+dfVecX[l];
202                                                 const int nj = j+dfVecY[l];
203                                                 const int nk = ZKOFF+dfVecZ[l];
204
205                                                 const CellFlagType nbflag = RFLAG(lev, ni,nj,nk, workSet);
206                                                 nbored |= nbflag;
207                                                 if(nbflag&CFInter) {
208                                                         avgfill += QCELL(lev, ni,nj,nk, workSet,dFfrac); avgfcnt += 1.;
209                                                 } else if(nbflag&CFFluid) {
210                                                         avgfill += 1.; avgfcnt += 1.;
211                                                 } else if(nbflag&CFEmpty) {
212                                                         avgfill += 0.; avgfcnt += 1.;
213                                                 }
214
215                                                 //if( (ni<0) || (nj<0) || (nk<0) 
216                                                  //|| (ni>=mLevel[mMaxRefine].lSizex) 
217                                                  //|| (nj>=mLevel[mMaxRefine].lSizey) 
218                                                  //|| (nk>=mLevel[mMaxRefine].lSizez) ) continue;
219                                         }
220
221                                         if(nbored&CFInter) {
222                                                 if(avgfcnt>0.) avgfill/=avgfcnt;
223                                                 *mpIso->lbmGetData(i,j,ZKOFF) = avgfill; continue;
224                                         } 
225                                         else if(nbored&CFFluid) {
226                                                 *mpIso->lbmGetData(i,j,ZKOFF) = 1.; continue;
227                                         }
228
229                                 }
230                         }
231
232                 // move surface towards inner "row" of obstacle
233                 // cells if necessary (all obs cells without fluid/inter
234                 // nbs (=iso==0) next to obstacles...)
235                 for(int k= getForZMin1(); k< getForZMax1(lev); ++k) 
236                         for(int j=1;j<mLevel[lev].lSizey-1;j++) 
237                                 for(int i=1;i<mLevel[lev].lSizex-1;i++) {
238                                         const CellFlagType cflag = RFLAG(lev, i,j,k,workSet);
239                                         if( (cflag&(CFBnd)) && (*mpIso->lbmGetData(i,j,ZKOFF)==0.)) {
240                                                 int bndnbcnt=0;
241                                                 FORDF1 { 
242                                                         const int ni = i+dfVecX[l];
243                                                         const int nj = j+dfVecY[l];
244                                                         const int nk = ZKOFF+dfVecZ[l];
245                                                         const CellFlagType nbflag = RFLAG(lev, ni,nj,nk, workSet);
246                                                         if(nbflag&CFBnd) bndnbcnt++;
247                                                 }
248                                                 if(bndnbcnt>0) *mpIso->lbmGetData(i,j,ZKOFF)=mIsoValue*0.95; 
249                                         }
250                                 }
251         }
252         // */
253
254         if(mFsSurfGenSetting&fssgNoNorth) 
255                 for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) 
256                         for(int j=0;j<mLevel[lev].lSizey-0;j++) {
257                                 *mpIso->lbmGetData(0,                   j,ZKOFF) = *mpIso->lbmGetData(1,                   j,ZKOFF);
258                         }
259         if(mFsSurfGenSetting&fssgNoEast) 
260                 for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) 
261                         for(int i=0;i<mLevel[lev].lSizex-0;i++) {
262                                 *mpIso->lbmGetData(i,0,                   ZKOFF) = *mpIso->lbmGetData(i,1,                   ZKOFF);
263                         }
264         if(mFsSurfGenSetting&fssgNoSouth) 
265                 for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) 
266                         for(int j=0;j<mLevel[lev].lSizey-0;j++) {
267                                 *mpIso->lbmGetData(mLevel[lev].lSizex-1,j,ZKOFF) = *mpIso->lbmGetData(mLevel[lev].lSizex-2,j,ZKOFF);
268                         }
269         if(mFsSurfGenSetting&fssgNoWest) 
270                 for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) 
271                         for(int i=0;i<mLevel[lev].lSizex-0;i++) {
272                                 *mpIso->lbmGetData(i,mLevel[lev].lSizey-1,ZKOFF) = *mpIso->lbmGetData(i,mLevel[lev].lSizey-2,ZKOFF);
273                         }
274         if(LBMDIM>2) {
275                 if(mFsSurfGenSetting&fssgNoBottom) 
276                         for(int j=0;j<mLevel[lev].lSizey-0;j++) 
277                                 for(int i=0;i<mLevel[lev].lSizex-0;i++) {
278                                         *mpIso->lbmGetData(i,j,0                   ) = *mpIso->lbmGetData(i,j,1                   );
279                                 } 
280                 if(mFsSurfGenSetting&fssgNoTop) 
281                         for(int j=0;j<mLevel[lev].lSizey-0;j++) 
282                                 for(int i=0;i<mLevel[lev].lSizex-0;i++) {
283                                         *mpIso->lbmGetData(i,j,mLevel[lev].lSizez-1) = *mpIso->lbmGetData(i,j,mLevel[lev].lSizez-2);
284                                 } 
285         }
286 #endif // SURFACE_ENH>=2
287
288
289         // update preview, remove 2d?
290         if((mOutputSurfacePreview)&&(LBMDIM==3)) {
291                 int pvsx = (int)(mPreviewFactor*mSizex);
292                 int pvsy = (int)(mPreviewFactor*mSizey);
293                 int pvsz = (int)(mPreviewFactor*mSizez);
294                 //float scale = (float)mSizex / previewSize;
295                 LbmFloat scalex = (LbmFloat)mSizex/(LbmFloat)pvsx;
296                 LbmFloat scaley = (LbmFloat)mSizey/(LbmFloat)pvsy;
297                 LbmFloat scalez = (LbmFloat)mSizez/(LbmFloat)pvsz;
298                 for(int k= 0; k< (pvsz-1); ++k) 
299                 for(int j=0;j< pvsy;j++) 
300                 for(int i=0;i< pvsx;i++) {
301                                         *mpPreviewSurface->lbmGetData(i,j,k) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley), (int)(k*scalez) );
302                                 }
303                 // set borders again...
304                 for(int k= 0; k< (pvsz-1); ++k) {
305                         for(int j=0;j< pvsy;j++) {
306                                 *mpPreviewSurface->lbmGetData(0,j,k) = *mpIso->lbmGetData( 0, (int)(j*scaley), (int)(k*scalez) );
307                                 *mpPreviewSurface->lbmGetData(pvsx-1,j,k) = *mpIso->lbmGetData( mSizex-1, (int)(j*scaley), (int)(k*scalez) );
308                         }
309                         for(int i=0;i< pvsx;i++) {
310                                 *mpPreviewSurface->lbmGetData(i,0,k) = *mpIso->lbmGetData( (int)(i*scalex), 0, (int)(k*scalez) );
311                                 *mpPreviewSurface->lbmGetData(i,pvsy-1,k) = *mpIso->lbmGetData( (int)(i*scalex), mSizey-1, (int)(k*scalez) );
312                         }
313                 }
314                 for(int j=0;j<pvsy;j++)
315                         for(int i=0;i<pvsx;i++) {      
316                                 *mpPreviewSurface->lbmGetData(i,j,0) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley) , 0);
317                                 *mpPreviewSurface->lbmGetData(i,j,pvsz-1) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley) , mSizez-1);
318                         }
319
320                 if(mFarFieldSize>=1.2) {
321                         // also remove preview border
322                         for(int k= 0; k< (pvsz-1); ++k) {
323                                 for(int j=0;j< pvsy;j++) {
324                                         *mpPreviewSurface->lbmGetData(0,j,k) = 
325                                         *mpPreviewSurface->lbmGetData(1,j,k) =  
326                                         *mpPreviewSurface->lbmGetData(2,j,k);
327                                         *mpPreviewSurface->lbmGetData(pvsx-1,j,k) = 
328                                         *mpPreviewSurface->lbmGetData(pvsx-2,j,k) = 
329                                         *mpPreviewSurface->lbmGetData(pvsx-3,j,k);
330                                         //0.0;
331                                 }
332                                 for(int i=0;i< pvsx;i++) {
333                                         *mpPreviewSurface->lbmGetData(i,0,k) = 
334                                         *mpPreviewSurface->lbmGetData(i,1,k) = 
335                                         *mpPreviewSurface->lbmGetData(i,2,k);
336                                         *mpPreviewSurface->lbmGetData(i,pvsy-1,k) = 
337                                         *mpPreviewSurface->lbmGetData(i,pvsy-2,k) = 
338                                         *mpPreviewSurface->lbmGetData(i,pvsy-3,k);
339                                         //0.0;
340                                 }
341                         }
342                         for(int j=0;j<pvsy;j++)
343                                 for(int i=0;i<pvsx;i++) {      
344                                         *mpPreviewSurface->lbmGetData(i,j,0) = 
345                                         *mpPreviewSurface->lbmGetData(i,j,1) = 
346                                         *mpPreviewSurface->lbmGetData(i,j,2);
347                                         *mpPreviewSurface->lbmGetData(i,j,pvsz-1) = 
348                                         *mpPreviewSurface->lbmGetData(i,j,pvsz-2) = 
349                                         *mpPreviewSurface->lbmGetData(i,j,pvsz-3);
350                                         //0.0;
351                         }
352                 }
353         }
354
355         // MPT
356         #if LBM_INCLUDE_TESTSOLVERS==1
357         mrIsoExchange();
358         #endif // LBM_INCLUDE_TESTSOLVERS==1
359
360         return;
361 }
362
363 /*! calculate speeds of fluid objects (or inflow) */
364 void LbmFsgrSolver::recalculateObjectSpeeds() {
365         const bool debugRecalc = false;
366         int numobjs = (int)(this->mpGiObjects->size());
367         // note - (numobjs + 1) is entry for domain settings
368
369         if(debugRecalc) errMsg("recalculateObjectSpeeds","start, #obj:"<<numobjs);
370         if(numobjs>255-1) {
371                 errFatal("LbmFsgrSolver::recalculateObjectSpeeds","More than 256 objects currently not supported...",SIMWORLD_INITERROR);
372                 return;
373         }
374         mObjectSpeeds.resize(numobjs+1);
375         for(int i=0; i<(int)(numobjs+0); i++) {
376                 mObjectSpeeds[i] = vec2L(this->mpParam->calculateLattVelocityFromRw( vec2P( (*this->mpGiObjects)[i]->getInitialVelocity(mSimulationTime) )));
377                 if(debugRecalc) errMsg("recalculateObjectSpeeds","id"<<i<<" set to "<< mObjectSpeeds[i]<<", unscaled:"<< (*this->mpGiObjects)[i]->getInitialVelocity(mSimulationTime) );
378         }
379
380         // also reinit part slip values here
381         mObjectPartslips.resize(numobjs+1);
382         for(int i=0; i<=(int)(numobjs+0); i++) {
383                 if(i<numobjs) {
384                         mObjectPartslips[i] = (LbmFloat)(*this->mpGiObjects)[i]->getGeoPartSlipValue();
385                 } else {
386                         // domain setting
387                         mObjectPartslips[i] = this->mDomainPartSlipValue;
388                 }
389                 LbmFloat set = mObjectPartslips[i];
390
391                 // as in setInfluenceVelocity
392                 const LbmFloat dt = mLevel[mMaxRefine].timestep;
393                 const LbmFloat dtInter = 0.01;
394                 //LbmFloat facFv = 1.-set;
395                 // mLevel[mMaxRefine].timestep
396                 LbmFloat facNv = (LbmFloat)( 1.-pow( (double)(set), (double)(dt/dtInter)) );
397                 errMsg("mObjectPartslips","id:"<<i<<"/"<<numobjs<<"  ts:"<<dt<< " its:"<<(dt/dtInter) <<" set"<<set<<" nv"<<facNv<<" test:"<<
398                          pow( (double)(1.-facNv),(double)(dtInter/dt))  );
399                 mObjectPartslips[i] = facNv;
400
401                 if(debugRecalc) errMsg("recalculateObjectSpeeds","id"<<i<<" parts "<< mObjectPartslips[i] );
402         }
403
404         if(debugRecalc) errMsg("recalculateObjectSpeeds","done, domain:"<<mObjectPartslips[numobjs]<<" n"<<numobjs);
405 }
406
407
408
409 /*****************************************************************************/
410 /*! debug object display */
411 /*****************************************************************************/
412 vector<ntlGeometryObject*> LbmFsgrSolver::getDebugObjects() { 
413         vector<ntlGeometryObject*> debo; 
414         if(this->mOutputSurfacePreview) {
415                 debo.push_back( mpPreviewSurface );
416         }
417 #if LBM_INCLUDE_TESTSOLVERS==1
418         if(mUseTestdata) {
419                 vector<ntlGeometryObject*> tdebo; 
420                 tdebo = mpTest->getDebugObjects();
421                 for(size_t i=0; i<tdebo.size(); i++) debo.push_back( tdebo[i] );
422         }
423 #endif // ELBEEM_PLUGIN
424         return debo; 
425 }
426
427 /******************************************************************************
428  * particle handling
429  *****************************************************************************/
430
431 /*! init particle positions */
432 int LbmFsgrSolver::initParticles() { 
433   int workSet = mLevel[mMaxRefine].setCurr;
434   int tries = 0;
435   int num = 0;
436         ParticleTracer *partt = mpParticles;
437
438   partt->setStart( this->mvGeoStart + ntlVec3Gfx(mLevel[mMaxRefine].nodeSize*0.5) );
439   partt->setEnd  ( this->mvGeoEnd   + ntlVec3Gfx(mLevel[mMaxRefine].nodeSize*0.5) );
440
441   partt->setSimStart( ntlVec3Gfx(0.0) );
442   partt->setSimEnd  ( ntlVec3Gfx(mSizex,   mSizey,   getForZMaxBnd(mMaxRefine)) );
443   
444   while( (num<partt->getNumInitialParticles()) && (tries<100*partt->getNumInitialParticles()) ) {
445     LbmFloat x,y,z,t;
446     x = 1.0+(( (LbmFloat)(mSizex-3.) )          * (rand()/(RAND_MAX+1.0)) );
447     y = 1.0+(( (LbmFloat)(mSizey-3.) )          * (rand()/(RAND_MAX+1.0)) );
448     z = 1.0+(( (LbmFloat) getForZMax1(mMaxRefine)-2. )* (rand()/(RAND_MAX+1.0)) );
449     int i = (int)(x+0.5);
450     int j = (int)(y+0.5);
451     int k = (int)(z+0.5);
452     if(LBMDIM==2) {
453       k = 0; z = 0.5; // place in the middle of domain
454     }
455
456     //if( RFLAG(mMaxRefine, i,j,k, workSet)& (CFFluid) ) 
457     //&& ( RFLAG(mMaxRefine, i,j,k, workSet)& CFNoNbFluid ) 
458     //if( RFLAG(mMaxRefine, i,j,k, workSet) & (CFFluid|CFInter|CFMbndInflow) ) { 
459     if( RFLAG(mMaxRefine, i,j,k, workSet) & (CFNoBndFluid|CFUnused) ) { 
460                         bool cellOk = true;
461                         //? FORDF1 { if(!(RFLAG_NB(mMaxRefine,i,j,k,workSet, l) & CFFluid)) cellOk = false; }
462                         if(!cellOk) continue;
463       // in fluid...
464       partt->addParticle(x,y,z);
465                         partt->getLast()->setStatus(PART_IN);
466                         partt->getLast()->setType(PART_TRACER);
467
468                         partt->getLast()->setSize(1.);
469                         // randomize size
470                         partt->getLast()->setSize(0.5 + (rand()/(RAND_MAX+1.0)));
471
472                         if( ( partt->getInitStart()>0.)
473                                         && ( partt->getInitEnd()>0.)
474                                         && ( partt->getInitEnd()>partt->getInitStart() )) {
475                 t = partt->getInitStart()+ (partt->getInitEnd()-partt->getInitStart())*(rand()/(RAND_MAX+1.0));
476                                 partt->getLast()->setLifeTime( -t );
477                         }
478       num++;
479     }
480     tries++;
481   } // */
482
483         /*FSGR_FORIJK1(mMaxRefine) {
484                 if( (RFLAG(mMaxRefine,i,j,k, workSet) & (CFNoBndFluid)) ) {
485         LbmFloat rndn = (rand()/(RAND_MAX+1.0));
486                         if(rndn>0.0) {
487                                 ntlVec3Gfx pos( (LbmFloat)(i)-0.5, (LbmFloat)(j)-0.5, (LbmFloat)(k)-0.5 );
488                                 if(LBMDIM==2) { pos[2]=0.5; }
489                                 partt->addParticle( pos[0],pos[1],pos[2] );
490                                 partt->getLast()->setStatus(PART_IN);
491                                 partt->getLast()->setType(PART_TRACER);
492                                 partt->getLast()->setSize(1.0);
493                         }
494                 }
495         } // */
496
497
498         // DEBUG TEST
499 #if LBM_INCLUDE_TESTSOLVERS==1
500         if(mUseTestdata) { 
501                 const bool partDebug=false;
502                 if(mpTest->mPartTestcase==0){ errMsg("LbmTestdata"," part init "<<mpTest->mPartTestcase); }
503                 if(mpTest->mPartTestcase==-12){ 
504                         const int lev = mMaxRefine;
505                         for(int i=5;i<15;i++) {
506                                 LbmFloat x,y,z;
507                                 y = 0.5+(LbmFloat)(i);
508                                 x = mLevel[lev].lSizex/20.0*10.0;
509                                 z = mLevel[lev].lSizez/20.0*2.0;
510                                 partt->addParticle(x,y,z);
511                                 partt->getLast()->setStatus(PART_IN);
512                                 partt->getLast()->setType(PART_BUBBLE);
513                                 partt->getLast()->setSize(  (-4.0+(LbmFloat)i)/1.0  );
514                                 if(partDebug) errMsg("PARTTT","SET "<<PRINT_VEC(x,y,z)<<" p"<<partt->getLast()->getPos() <<" s"<<partt->getLast()->getSize() );
515                         }
516                 }
517                 if(mpTest->mPartTestcase==-11){ 
518                         const int lev = mMaxRefine;
519                         for(int i=5;i<15;i++) {
520                                 LbmFloat x,y,z;
521                                 y = 10.5+(LbmFloat)(i);
522                                 x = mLevel[lev].lSizex/20.0*10.0;
523                                 z = mLevel[lev].lSizez/20.0*40.0;
524                                 partt->addParticle(x,y,z);
525                                 partt->getLast()->setStatus(PART_IN);
526                                 partt->getLast()->setType(PART_DROP);
527                                 partt->getLast()->setSize(  (-4.0+(LbmFloat)i)/1.0  );
528                                 if(partDebug) errMsg("PARTTT","SET "<<PRINT_VEC(x,y,z)<<" p"<<partt->getLast()->getPos() <<" s"<<partt->getLast()->getSize() );
529                         }
530                 }
531                 // place floats on rectangular region FLOAT_JITTER_BND
532                 if(mpTest->mPartTestcase==-10){ 
533                         const int lev = mMaxRefine;
534                         const int sx = mLevel[lev].lSizex;
535                         const int sy = mLevel[lev].lSizey;
536                         //for(int j=-(int)(sy*0.25);j<-(int)(sy*0.25)+2;++j) { for(int i=-(int)(sx*0.25);i<-(int)(sy*0.25)+2;++i) {
537                         //for(int j=-(int)(sy*1.25);j<(int)(2.25*sy);++j) { for(int i=-(int)(sx*1.25);i<(int)(2.25*sx);++i) {
538                         for(int j=-(int)(sy*0.3);j<(int)(1.3*sy);++j) { for(int i=-(int)(sx*0.3);i<(int)(1.3*sx);++i) {
539                         //for(int j=-(int)(sy*0.2);j<(int)(0.2*sy);++j) { for(int i= (int)(sx*0.5);i<= (int)(0.51*sx);++i) {
540                                         LbmFloat x,y,z;
541                                         x = 0.0+(LbmFloat)(i);
542                                         y = 0.0+(LbmFloat)(j);
543                                         //z = mLevel[lev].lSizez/10.0*2.5 - 1.0;
544                                         z = mLevel[lev].lSizez/20.0*9.5 - 1.0;
545                                         //z = mLevel[lev].lSizez/20.0*4.5 - 1.0;
546                                         partt->addParticle(x,y,z);
547                                         //if( (i>0)&&(i<sx) && (j>0)&&(j<sy) ) { partt->getLast()->setStatus(PART_IN); } else { partt->getLast()->setStatus(PART_OUT); }
548                                         partt->getLast()->setStatus(PART_IN);
549                                         partt->getLast()->setType(PART_FLOAT);
550                                         partt->getLast()->setSize( 15.0 );
551                                         if(partDebug) errMsg("PARTTT","SET "<<PRINT_VEC(x,y,z)<<" p"<<partt->getLast()->getPos() <<" s"<<partt->getLast()->getSize() );
552                          }
553                 }       }
554         } 
555         // DEBUG TEST
556 #endif // LBM_INCLUDE_TESTSOLVERS
557
558         
559   debMsgStd("LbmFsgrSolver::initParticles",DM_MSG,"Added "<<num<<" particles, genProb:"<<this->mPartGenProb<<", tries:"<<tries, 10);
560   if(num != partt->getNumParticles()) return 1;
561
562         return 0;
563 }
564
565 // helper function for particle debugging
566 /*static string getParticleStatusString(int state) {
567         std::ostringstream out;
568         if(state&PART_DROP)   out << "dropp ";
569         if(state&PART_TRACER) out << "tracr ";
570         if(state&PART_BUBBLE) out << "bubbl ";
571         if(state&PART_FLOAT)  out << "float ";
572         if(state&PART_INTER)  out << "inter ";
573
574         if(state&PART_IN)   out << "inn ";
575         if(state&PART_OUT)  out << "out ";
576         if(state&PART_INACTIVE)  out << "INACT ";
577         if(state&PART_OUTFLUID)  out << "outfluid ";
578         return out.str();
579 } // */
580
581 #define P_CHANGETYPE(p, newtype) \
582                 p->setLifeTime(0.); \
583     /* errMsg("PIT","U pit"<<(p)->getId()<<" pos:"<< (p)->getPos()<<" status:"<<convertFlags2String((p)->getFlags())<<" to "<< (newtype) ); */ \
584                 p->setType(newtype); 
585
586 // tracer defines
587 #define TRACE_JITTER 0.025
588 #define TRACE_RAND (rand()/(RAND_MAX+1.0))*TRACE_JITTER-(TRACE_JITTER*0.5)
589 #define FFGET_NORM(var,dl) \
590                                                         if(RFLAG_NB(lev,i,j,k,workSet, dl) &(CFInter)){ (var) = QCELL_NB(lev,i,j,k,workSet,dl,dFfrac); } \
591                                                         else if(RFLAG_NB(lev,i,j,k,workSet, dl) &(CFFluid|CFUnused)){ (var) = 1.; } else (var) = 0.0;
592
593 // float jitter
594 #define FLOAT_JITTER_BND (FLOAT_JITTER*2.0)
595 #define FLOAT_JITTBNDRAND(x) ((rand()/(RAND_MAX+1.0))*FLOAT_JITTER_BND*(1.-(x/(LbmFloat)maxdw))-(FLOAT_JITTER_BND*(1.-(x)/(LbmFloat)maxdw)*0.5)) 
596
597 #define DEL_PART { \
598         /*errMsg("PIT","DEL AT "<< __LINE__<<" type:"<<p->getType()<<"  ");  */ \
599         p->setActive( false ); \
600         continue; }
601
602 void LbmFsgrSolver::advanceParticles() { 
603   const int level = mMaxRefine;
604   const int workSet = mLevel[level].setCurr;
605         LbmFloat vx=0.0,vy=0.0,vz=0.0;
606         //int debugOutCounter=0; // debug output counter
607
608         myTime_t parttstart = getTime(); 
609         const LbmFloat cellsize = this->mpParam->getCellSize();
610         const LbmFloat timestep = this->mpParam->getTimestep();
611         //const LbmFloat viscAir = 1.79 * 1e-5; // RW2L kin. viscosity, mu
612         //const LbmFloat viscWater = 1.0 * 1e-6; // RW2L kin. viscosity, mu
613         const LbmFloat rhoAir = 1.2;  // [kg m^-3] RW2L
614         const LbmFloat rhoWater = 1000.0; // RW2L
615         const LbmFloat minDropSize = 0.0005; // [m], = 2mm  RW2L
616         const LbmVec   velAir(0.); // [m / s]
617
618         const LbmFloat r1 = 0.005;  // r max
619         const LbmFloat r2 = 0.0005; // r min
620         const LbmFloat v1 = 9.0; // v max
621         const LbmFloat v2 = 2.0; // v min
622         const LbmVec rwgrav = vec2L( this->mpParam->getGravity(mSimulationTime) );
623         const bool useff = (mFarFieldSize>1.2); // if(mpTest->mFarfMode>0){ 
624
625         // TODO scale bubble/part damping dep. on timestep, also drop bnd rev damping
626         const int cutval = mCutoff; // use full border!?
627         if(this->mStepCnt%50==49) { mpParticles->cleanup(); }
628   for(vector<ParticleObject>::iterator pit= mpParticles->getParticlesBegin();
629       pit!= mpParticles->getParticlesEnd(); pit++) {
630     //if((*pit).getPos()[2]>10.) errMsg("PIT"," pit"<<(*pit).getId()<<" pos:"<< (*pit).getPos()<<" status:["<<getParticleStatusString((*pit).getFlags())<<"] vel:"<< (*pit).getVel()  );
631     if( (*pit).getActive()==false ) continue;
632                 // skip until reached
633                 ParticleObject *p = &(*pit);
634                 if(p->getLifeTime()<0.){ 
635                         if(p->getLifeTime() < -mSimulationTime) continue; 
636                         else p->setLifeTime(-mLevel[level].timestep); // zero for following update
637                 }
638     int i,j,k;
639                 p->setLifeTime(p->getLifeTime()+mLevel[level].timestep);
640
641                 // nearest neighbor, particle positions don't include empty bounds
642                 ntlVec3Gfx pos = p->getPos();
643                 i= (int)pos[0]; j= (int)pos[1]; k= (int)pos[2];// no offset necessary
644                 if(LBMDIM==2) { k = 0; }
645
646                 // only testdata handling, all for sws
647 #if LBM_INCLUDE_TESTSOLVERS==1
648                 if(useff && (mpTest->mFarfMode>0)) {
649                         p->setStatus(PART_OUT);
650                         mpTest->handleParticle(p, i,j,k); continue;
651                 } 
652 #endif // LBM_INCLUDE_TESTSOLVERS==1
653
654                 // in out tests
655                 if(p->getStatus()&PART_IN) { // IN
656                         if( (i<cutval)||(i>mSizex-1-cutval)||
657                                         (j<cutval)||(j>mSizey-1-cutval)
658                                         //||(k<cutval)||(k>mSizez-1-cutval) 
659                                         ) {
660                                 if(!useff) { DEL_PART;
661                                 } else { 
662                                         p->setStatus(PART_OUT); 
663                                 }
664                         } 
665                 } else { // OUT rough check
666                         // check in again?
667                         if( (i>=cutval)&&(i<=mSizex-1-cutval)&&
668                                         (j>=cutval)&&(j<=mSizey-1-cutval)
669                                         ) {
670                                 p->setStatus(PART_IN);
671                         }
672                 }
673
674                 if( (p->getType()==PART_BUBBLE) ||
675                     (p->getType()==PART_TRACER) ) {
676
677                         // no interpol
678                         vx = vy = vz = 0.0;
679                         if(p->getStatus()&PART_IN) { // IN
680                                 if(k>=cutval) {
681                                         if(k>mSizez-1-cutval) DEL_PART; 
682
683                                         if( RFLAG(level, i,j,k, workSet)&(CFFluid|CFUnused) ) {
684                                                 // still ok
685                                                 int partLev = level;
686                                                 int si=i, sj=j, sk=k;
687                                                 while(partLev>0 && RFLAG(partLev, si,sj,sk, workSet)&(CFUnused)) {
688                                                         partLev--;
689                                                         si/=2;
690                                                         sj/=2;
691                                                         sk/=2;
692                                                 }
693                                                 // get velocity from fluid cell
694                                                 if( RFLAG(partLev, si,sj,sk, workSet)&(CFFluid) ) {
695                                                         LbmFloat *ccel = RACPNT(partLev, si,sj,sk, workSet);
696                                                         FORDF1{
697                                                                 LbmFloat cdf = RAC(ccel, l);
698                                                                 // TODO update below
699                                                                 vx  += (this->dfDvecX[l]*cdf); 
700                                                                 vy  += (this->dfDvecY[l]*cdf);  
701                                                                 vz  += (this->dfDvecZ[l]*cdf);  
702                                                         }
703                                                         // remove gravity influence
704                                                         const LbmFloat lesomega = mLevel[level].omega; // no les
705                                                         vx -= mLevel[level].gravity[0] * lesomega*0.5;
706                                                         vy -= mLevel[level].gravity[1] * lesomega*0.5;
707                                                         vz -= mLevel[level].gravity[2] * lesomega*0.5;
708                                                 } // fluid vel
709
710                                         } else { // OUT
711                                                 // out of bounds, deactivate...
712                                                 // FIXME make fsgr treatment
713                                                 if(p->getType()==PART_BUBBLE) { P_CHANGETYPE(p, PART_FLOAT ); continue; }
714                                         }
715                                 } else {
716                                         // below 3d region, just rise
717                                 }
718                         } else { // OUT
719 #                               if LBM_INCLUDE_TESTSOLVERS==1
720                                 if(useff) { mpTest->handleParticle(p, i,j,k); }
721                                 else DEL_PART;
722 #                               else // LBM_INCLUDE_TESTSOLVERS==1
723                                 DEL_PART;
724 #                               endif // LBM_INCLUDE_TESTSOLVERS==1
725                                 // TODO use x,y vel...?
726                         }
727
728                         ntlVec3Gfx v = p->getVel(); // dampen...
729                         if( (useff)&& (p->getType()==PART_BUBBLE) ) {
730                                 // test rise
731
732                                 if(mPartUsePhysModel) {
733                                         LbmFloat radius = p->getSize() * minDropSize;
734                                         //LbmVec   velPart = vec2L(p->getVel()) *cellsize/timestep; // L2RW, lattice velocity
735                                         //LbmVec   velWater = LbmVec(vx,vy,vz) *cellsize/timestep;// L2RW, fluid velocity
736                                         //LbmVec   velRel = velWater - velPart;
737                                         //LbmFloat velRelNorm = norm(velRel);
738                                         //LbmFloat pvolume = rhoAir * 4.0/3.0 * M_PI* radius*radius*radius; // volume: 4/3 pi r^3
739
740                                         //LbmVec fb = -rwgrav* pvolume *rhoWater;
741                                         //LbmVec fd = velRel*6.0*M_PI*radius* (1e-3); //viscWater;
742                                         //LbmVec change = (fb+fd) *10.0*timestep  *(timestep/cellsize);
743                                         /*if(debugOutCounter<0) {
744                                                 errMsg("PIT","BTEST1   vol="<<pvolume<<" radius="<<radius<<" vn="<<velRelNorm<<" velPart="<<velPart<<" velRel"<<velRel);
745                                                 errMsg("PIT","BTEST2        cellsize="<<cellsize<<" timestep="<<timestep<<" viscW="<<viscWater<<" ss/mb="<<(timestep/(pvolume*rhoAir)));
746                                                 errMsg("PIT","BTEST2        grav="<<rwgrav<<"  " );
747                                                 errMsg("PIT","BTEST2        change="<<(change)<<" fb="<<(fb)<<" fd="<<(fd)<<" ");
748                                                 errMsg("PIT","BTEST2        change="<<norm(change)<<" fb="<<norm(fb)<<" fd="<<norm(fd)<<" ");
749                                         } // DEBUG */
750                                                 
751                                         LbmVec fd2 = (LbmVec(vx,vy,vz)-vec2L(p->getVel())) * 6.0*M_PI*radius* (1e-3); //viscWater;
752                                         LbmFloat w = 0.99;
753                                         vz = (1.0-w)*vz + w*(p->getVel()[2]-0.5*(p->getSize()/5.0)*mLevel[level].gravity[2]);
754                                         v = ntlVec3Gfx(vx,vy,vz)+vec2G(fd2);
755                                         p->setVel( v );
756                                 } else {
757                                         // non phys, half old, half fluid, use slightly slower acc
758                                         v = v*0.5 + ntlVec3Gfx(vx,vy,vz)* 0.5-vec2G(mLevel[level].gravity)*0.5;
759                                         p->setVel( v * 0.99 );
760                                 }
761                                 p->advanceVel();
762
763                         } else if(p->getType()==PART_TRACER) {
764                                 v = ntlVec3Gfx(vx,vy,vz);
765                                 CellFlagType fflag = RFLAG(level, i,j,k, workSet);
766
767                                 if(fflag&(CFFluid|CFInter) ) { p->setInFluid(true);
768                                 } else { p->setInFluid(false); }
769
770                                 if( (( fflag&CFFluid ) && ( fflag&CFNoBndFluid )) ||
771                                                 (( fflag&CFInter ) && (!(fflag&CFNoNbFluid)) ) ) {
772                                         // only real fluid
773 #                                       if LBMDIM==3
774                                         p->advance( TRACE_RAND,TRACE_RAND,TRACE_RAND);
775 #                                       else
776                                         p->advance( TRACE_RAND,TRACE_RAND, 0.);
777 #                                       endif
778
779                                 } else {
780                                         // move inwards along normal, make sure normal is valid first
781                                         // todo use class funcs!
782                                         const int lev = level;
783                                         LbmFloat nx=0.,ny=0.,nz=0., nv1,nv2;
784                                         bool nonorm = false;
785                                         if(i<=0)              { nx = -1.; nonorm = true; }
786                                         if(i>=mSizex-1) { nx =  1.; nonorm = true; }
787                                         if(j<=0)              { ny = -1.; nonorm = true; }
788                                         if(j>=mSizey-1) { ny =  1.; nonorm = true; }
789 #                                       if LBMDIM==3
790                                         if(k<=0)              { nz = -1.; nonorm = true; }
791                                         if(k>=mSizez-1) { nz =  1.; nonorm = true; }
792 #                                       endif // LBMDIM==3
793                                         if(!nonorm) {
794                                                 FFGET_NORM(nv1,dE); FFGET_NORM(nv2,dW);
795                                                 nx = 0.5* (nv2-nv1);
796                                                 FFGET_NORM(nv1,dN); FFGET_NORM(nv2,dS);
797                                                 ny = 0.5* (nv2-nv1);
798 #                                               if LBMDIM==3
799                                                 FFGET_NORM(nv1,dT); FFGET_NORM(nv2,dB);
800                                                 nz = 0.5* (nv2-nv1);
801 #                                               else // LBMDIM==3
802                                                 nz = 0.;
803 #                                               endif // LBMDIM==3
804                                         } else {
805                                                 v = p->getVel() + vec2G(mLevel[level].gravity);
806                                         }
807                                         p->advanceVec( (ntlVec3Gfx(nx,ny,nz)) * -0.1 ); // + vec2G(mLevel[level].gravity);
808                                 }
809                         }
810
811                         p->setVel( v );
812                         p->advanceVel();
813                 } 
814
815                 // drop handling
816                 else if(p->getType()==PART_DROP) {
817                         ntlVec3Gfx v = p->getVel(); // dampen...
818
819                         if(mPartUsePhysModel) {
820                                 LbmFloat radius = p->getSize() * minDropSize;
821                                 LbmVec   velPart = vec2L(p->getVel()) *cellsize /timestep; // * cellsize / timestep; // L2RW, lattice velocity
822                                 LbmVec   velRel = velAir - velPart;
823                                 //LbmVec   velRelLat = velRel /cellsize*timestep; // L2RW
824                                 LbmFloat velRelNorm = norm(velRel);
825                                 // TODO calculate values in lattice units, compute CD?!??!
826                                 LbmFloat mb = rhoWater * 4.0/3.0 * M_PI* radius*radius*radius; // mass: 4/3 pi r^3 rho
827                                 const LbmFloat rw = (r1-radius)/(r1-r2);
828                                 const LbmFloat rmax = (0.5 + 0.5*rw);
829                                 const LbmFloat vmax = (v2 + (v1-v2)* (1.0-rw) );
830                                 const LbmFloat cd = (rmax) * (velRelNorm)/(vmax);
831
832                                 LbmVec fg = rwgrav * mb;//  * (1.0-rhoAir/rhoWater);
833                                 LbmVec fd = velRel* velRelNorm* cd*M_PI *rhoAir *0.5 *radius*radius;
834                                 LbmVec change = (fg+   fd ) *timestep / mb  *(timestep/cellsize);
835                                 //if(k>0) { errMsg("\nPIT","NTEST1   mb="<<mb<<" radius="<<radius<<" vn="<<velRelNorm<<" velPart="<<velPart<<" velRel"<<velRel<<" pgetVel="<<p->getVel() ); }
836
837                                 v += vec2G(change);
838                                 p->setVel(v); 
839                                 // NEW
840                         } else {
841                                 p->setVel( v ); 
842                                 int gravk = (int)(p->getPos()[2]+mLevel[level].gravity[2]);
843                                 if(gravk>=0 && gravk<mSizez && RFLAG(level, i,j,gravk, workSet)&CFBnd) {
844                                         // dont add for "resting" parts
845                                         v[2] = 0.;
846                                         p->setVel( v*0.9 ); // restdamping
847                                 } else {
848                                         p->addToVel( vec2G(mLevel[level].gravity) );
849                                 }
850                         } // OLD
851                         p->advanceVel();
852
853                         if(p->getStatus()&PART_IN) { // IN
854                                 if(k<cutval) { DEL_PART; continue; }
855                                 if(k<=mSizez-1-cutval){ 
856                                         CellFlagType pflag = RFLAG(level, i,j,k, workSet);
857                                         //errMsg("PIT move"," at "<<PRINT_IJK<<" flag"<<convertCellFlagType2String(pflag) );
858                                         if (pflag & CFMbndOutflow) {
859                                                 DEL_PART;
860                                                 continue;
861                                         }
862                                         if(pflag & (CFBnd)) {
863                                                 handleObstacleParticle(p);
864                                                 continue;
865                                         } else if(pflag & (CFEmpty)) {
866                                                 // still ok
867                                         } else if((pflag & CFInter) 
868                                                   //&&(!(RFLAG(level, i,j,k, workSet)& CFNoNbFluid)) 
869                                                                                 ) {
870                                                 // add to no nb fluid i.f.'s, so skip if interface with fluid nb
871                                         } else if(pflag  & (CFFluid|CFUnused|CFInter) ){ // interface cells ignored here due to previous check!
872                                                 // add dropmass again, (these are only interf. with nonbfl.)
873                                                 int oi= (int)(pos[0]-1.25*v[0]+0.5);
874                                                 int oj= (int)(pos[1]-1.25*v[1]+0.5);
875                                                 int ok= (int)(pos[2]-1.25*v[2]+0.5);
876                                                 const LbmFloat size = p->getSize();
877                                                 const LbmFloat dropmass = ParticleObject::getMass(mPartDropMassSub*size);
878                                                 bool orgcellok = false;
879                                                 if( (oi<0)||(oi>mSizex-1)||
880                                                     (oj<0)||(oj>mSizey-1)||
881                                                     (ok<0)||(ok>mSizez-1) ) {
882                                                         // org cell not ok!
883                                                 } else if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){
884                                                         orgcellok = true;
885                                                 } else {
886                                                         // search upward for interface
887                                                         oi=i; oj=j; ok=k;
888                                                         for(int kk=0; kk<5 && ok<=mSizez-2; kk++) {
889                                                                 ok++; // check sizez-2 due to this increment!
890                                                                 if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){
891                                                                         kk = 5; orgcellok = true;
892                                                                 }
893                                                         }
894                                                 }
895
896                                                 //errMsg("PTIMPULSE"," new v"<<v<<" at "<<PRINT_VEC(oi,oj,ok)<<" , was "<<PRINT_VEC(i,j,k)<<" ok "<<orgcellok );
897                                                 if(orgcellok) {
898                                                         QCELL(level, oi,oj,ok, workSet, dMass) += dropmass;
899                                                         QCELL(level, oi,oj,ok, workSet, dFfrac) += dropmass; // assume rho=1?
900
901                                                         if(RFLAG(level, oi,oj,ok, workSet) & CFNoBndFluid){
902                                                         // check speed, perhaps normalize
903                                                         gfxReal vlensqr = normNoSqrt(v);
904                                                         if(vlensqr > 0.166*0.166) {
905                                                                 v *= 1./sqrtf((float)vlensqr)*0.166;
906                                                         }
907                                                         // compute cell velocity
908                                                         LbmFloat *tcel = RACPNT(level, oi,oj,ok, workSet);
909                                                         LbmFloat velUx=0., velUy=0., velUz=0.;
910                                                         FORDF0 { 
911                                                                 velUx  += (this->dfDvecX[l]*RAC(tcel,l));
912                                                                 velUy  += (this->dfDvecY[l]*RAC(tcel,l)); 
913                                                                 velUz  += (this->dfDvecZ[l]*RAC(tcel,l)); 
914                                                         }
915                                                         // add impulse
916                                                         /*
917                                                         LbmFloat cellVelSqr = velUx*velUx+ velUy*velUy+ velUz*velUz;
918                                                         //errMsg("PTIMPULSE"," new v"<<v<<" cvs"<<cellVelSqr<<"="<<sqrt(cellVelSqr));
919                                                         if(cellVelSqr< 0.166*0.166) {
920                                                                 FORDF1 { 
921                                                                         const LbmFloat add = 3. * dropmass * this->dfLength[l]*(v[0]*this->dfDvecX[l]+v[1]*this->dfDvecY[l]+v[2]*this->dfDvecZ[l]);
922                                                                         RAC(tcel,l) += add;
923                                                                 } } // */
924                                                         } // only add impulse away from obstacles! 
925                                                 } // orgcellok
926
927                                                 // FIXME make fsgr treatment
928                                                 P_CHANGETYPE(p, PART_FLOAT ); continue; 
929                                                 // jitter in cell to prevent stacking when hitting a steep surface
930                                                 ntlVec3Gfx cpos = p->getPos(); 
931                                                 cpos[0] += (rand()/(RAND_MAX+1.0))-0.5;
932                                                 cpos[1] += (rand()/(RAND_MAX+1.0))-0.5; 
933                                                 cpos[2] += (rand()/(RAND_MAX+1.0))-0.5; 
934                                                 p->setPos(cpos);
935                                         } else {
936                                                 DEL_PART;
937                                                 this->mNumParticlesLost++;
938                                         }
939                                 }
940                         } else { // OUT
941 #                               if LBM_INCLUDE_TESTSOLVERS==1
942                                 if(useff) { mpTest->handleParticle(p, i,j,k); }
943                                 else{ DEL_PART; }
944 #                               else // LBM_INCLUDE_TESTSOLVERS==1
945                                 DEL_PART; 
946 #                               endif // LBM_INCLUDE_TESTSOLVERS==1
947                         }
948
949                 } // air particle
950
951                 // inter particle
952                 else if(p->getType()==PART_INTER) {
953                         // unused!?
954                         if(p->getStatus()&PART_IN) { // IN
955                                 if((k<cutval)||(k>mSizez-1-cutval)) {
956                                         // undecided particle above or below... remove?
957                                         DEL_PART; 
958                                 }
959
960                                 CellFlagType pflag = RFLAG(level, i,j,k, workSet);
961                                 if(pflag& CFInter ) {
962                                         // still ok
963                                 } else if(pflag& (CFFluid|CFUnused) ) {
964                                         P_CHANGETYPE(p, PART_FLOAT ); continue;
965                                 } else if(pflag& CFEmpty ) {
966                                         P_CHANGETYPE(p, PART_DROP ); continue;
967                                 } else if(pflag& CFBnd ) {
968                                         P_CHANGETYPE(p, PART_FLOAT ); continue;
969                                 }
970                         } else { // OUT
971                                 // undecided particle outside... remove?
972                                 DEL_PART; 
973                         }
974                 }
975
976                 // float particle
977                 else if(p->getType()==PART_FLOAT) {
978
979                         if(p->getStatus()&PART_IN) { // IN
980                                 if(k<cutval) DEL_PART; 
981                                 // not valid for mass... 
982                                 vx = vy = vz = 0.0;
983
984                                 // define from particletracer.h
985 #if MOVE_FLOATS==1
986                                 const int DEPTH_AVG=3; // only average interface vels
987                                 int ccnt=0;
988                                 for(int kk=0;kk<DEPTH_AVG;kk+=1) {
989                                         if((k-kk)<1) continue;
990                                         if(RFLAG(level, i,j,k, workSet)&(CFInter)) {} else continue;
991                                         ccnt++;
992                                         FORDF1{
993                                                 LbmFloat cdf = QCELL(level, i,j,k-kk, workSet, l);
994                                                 vx  += (this->dfDvecX[l]*cdf); 
995                                                 vy  += (this->dfDvecY[l]*cdf);  
996                                                 vz  += (this->dfDvecZ[l]*cdf);  
997                                         }
998                                 }
999                                 if(ccnt) {
1000                                 // use halved surface velocity (todo, use omega instead)
1001                                 vx /=(LbmFloat)(ccnt * 2.0); // half xy speed! value2
1002                                 vy /=(LbmFloat)(ccnt * 2.0);
1003                                 vz /=(LbmFloat)(ccnt); }
1004 #else // MOVE_FLOATS==1
1005                                 vx=vy=0.; //p->setVel(ntlVec3Gfx(0.) ); // static_float
1006 #endif // MOVE_FLOATS==1
1007                                 vx += (rand()/(RAND_MAX+1.0))*(FLOAT_JITTER*0.2)-(FLOAT_JITTER*0.2*0.5);
1008                                 vy += (rand()/(RAND_MAX+1.0))*(FLOAT_JITTER*0.2)-(FLOAT_JITTER*0.2*0.5);
1009
1010                                 //bool delfloat = false;
1011                                 if( ( RFLAG(level, i,j,k, workSet)& (CFFluid|CFUnused) ) ) {
1012                                         // in fluid cell
1013                                         vz = p->getVel()[2]-1.0*mLevel[level].gravity[2]; // simply rise...
1014                                         if(vz<0.) vz=0.;
1015                                 } else if( ( RFLAG(level, i,j,k, workSet)& CFBnd ) ) {
1016                                         // force downwards movement, move below obstacle...
1017                                         //vz = p->getVel()[2]+1.0*mLevel[level].gravity[2]; // fall...
1018                                         //if(vz>0.) vz=0.;
1019                                         DEL_PART; 
1020                                 } else if( ( RFLAG(level, i,j,k, workSet)& CFInter ) ) {
1021                                         // keep in interface , one grid cell offset is added in part. gen
1022                                 } else { // all else...
1023                                         if( ( RFLAG(level, i,j,k-1, workSet)& (CFFluid|CFInter) ) ) {
1024                                                 vz = p->getVel()[2]+2.0*mLevel[level].gravity[2]; // fall...
1025                                                 if(vz>0.) vz=0.; }
1026                                         else { DEL_PART; }
1027                                 }
1028
1029                                 p->setVel( vec2G( ntlVec3Gfx(vx,vy,vz) ) ); //?
1030                                 p->advanceVel();
1031                         } else {
1032 #if LBM_INCLUDE_TESTSOLVERS==1
1033                                 if(useff) { mpTest->handleParticle(p, i,j,k); }
1034                                 else DEL_PART; 
1035 #else // LBM_INCLUDE_TESTSOLVERS==1
1036                                 DEL_PART; 
1037 #endif // LBM_INCLUDE_TESTSOLVERS==1
1038                         }
1039                                 
1040                         // additional bnd jitter
1041                         if((0) && (useff) && (p->getLifeTime()<3.*mLevel[level].timestep)) {
1042                                 // use half butoff border 1/8
1043                                 int maxdw = (int)(mLevel[level].lSizex*0.125*0.5);
1044                                 if(maxdw<3) maxdw=3;
1045                                 if((j>=0)&&(j<=mSizey-1)) {
1046                                         if(ABS(i-(               cutval))<maxdw) { p->advance(  FLOAT_JITTBNDRAND( ABS(i-(               cutval))), 0.,0.); }
1047                                         if(ABS(i-(mSizex-1-cutval))<maxdw) { p->advance(  FLOAT_JITTBNDRAND( ABS(i-(mSizex-1-cutval))), 0.,0.); }
1048                                 }
1049                         }
1050                 }  // PART_FLOAT
1051                 
1052                 // unknown particle type        
1053                 else {
1054                         errMsg("LbmFsgrSolver::advanceParticles","PIT pit invalid type!? "<<p->getStatus() );
1055                 }
1056   }
1057         myTime_t parttend = getTime(); 
1058         debMsgStd("LbmFsgrSolver::advanceParticles",DM_MSG,"Time for particle update:"<< getTimeString(parttend-parttstart)<<", #particles:"<<mpParticles->getNumParticles() , 10 );
1059 }
1060
1061 void LbmFsgrSolver::notifySolverOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) {
1062         int workSet = mLevel[mMaxRefine].setCurr;
1063         std::ostringstream name;
1064
1065         // debug - raw dump of ffrac values, as text!
1066         if(mDumpRawText) { 
1067                 name << outfilename<< frameNrStr <<".dump";
1068                 FILE *file = fopen(name.str().c_str(),"w");
1069                 if(file) {
1070
1071                         for(int k= getForZMinBnd(); k< getForZMaxBnd(mMaxRefine); ++k)  {
1072                                 for(int j=0;j<mLevel[mMaxRefine].lSizey-0;j++)  {
1073                                         for(int i=0;i<mLevel[mMaxRefine].lSizex-0;i++) {
1074                                                 float val = 0.;
1075                                                 if(RFLAG(mMaxRefine, i,j,k, workSet) & CFInter) {
1076                                                         val = QCELL(mMaxRefine,i,j,k, mLevel[mMaxRefine].setCurr,dFfrac);
1077                                                         if(val<0.) val=0.;
1078                                                         if(val>1.) val=1.;
1079                                                 }
1080                                                 if(RFLAG(mMaxRefine, i,j,k, workSet) & CFFluid) val = 1.;
1081                                                 fprintf(file, "%f ",val); // text
1082                                                 //errMsg("W", PRINT_IJK<<" val:"<<val);
1083                                         }
1084                                         fprintf(file, "\n"); // text
1085                                 }
1086                                 fprintf(file, "\n"); // text
1087                         }
1088                         fclose(file);
1089
1090                 } // file
1091         } // */
1092
1093         if(mDumpRawBinary) {
1094                 if(!mDumpRawBinaryZip) {
1095                         // unzipped, only fill
1096                         name << outfilename<< frameNrStr <<".bdump";
1097                         FILE *file = fopen(name.str().c_str(),"w");
1098                         if(file) {
1099                                 for(int k= getForZMinBnd(); k< getForZMaxBnd(mMaxRefine); ++k)  {
1100                                         for(int j=0;j<mLevel[mMaxRefine].lSizey-0;j++)  {
1101                                                 for(int i=0;i<mLevel[mMaxRefine].lSizex-0;i++) {
1102                                                         float val = 0.;
1103                                                         if(RFLAG(mMaxRefine, i,j,k, workSet) & CFInter) {
1104                                                                 val = QCELL(mMaxRefine,i,j,k, mLevel[mMaxRefine].setCurr,dFfrac);
1105                                                                 if(val<0.) val=0.;
1106                                                                 if(val>1.) val=1.;
1107                                                         }
1108                                                         if(RFLAG(mMaxRefine, i,j,k, workSet) & CFFluid) val = 1.;
1109                                                         fwrite( &val, sizeof(val), 1, file); // binary
1110                                                 }
1111                                         }
1112                                 }
1113                                 fclose(file);
1114                         } // file
1115                 } // unzipped
1116                 else {
1117                         // zipped, use iso values
1118                         prepareVisualization();
1119                         name << outfilename<< frameNrStr <<".bdump.gz";
1120                         gzFile gzf = gzopen(name.str().c_str(),"wb9");
1121                         if(gzf) {
1122                                 // write size
1123                                 int s;
1124                                 s=mSizex;       gzwrite(gzf, &s, sizeof(s));
1125                                 s=mSizey;       gzwrite(gzf, &s, sizeof(s));
1126                                 s=mSizez;       gzwrite(gzf, &s, sizeof(s));
1127
1128                                 // write isovalues
1129                                 for(int k= getForZMinBnd(); k< getForZMaxBnd(mMaxRefine); ++k)  {
1130                                         for(int j=0;j<mLevel[mMaxRefine].lSizey;j++)  {
1131                                                 for(int i=0;i<mLevel[mMaxRefine].lSizex;i++) {
1132                                                         float val = 0.;
1133                                                         val = *mpIso->lbmGetData( i,j,k );
1134                                                         gzwrite(gzf, &val, sizeof(val));
1135                                                 }
1136                                         }
1137                                 }
1138                                 gzclose(gzf);
1139                         } // gzf
1140                 } // zip
1141         } // bin dump
1142
1143         dumptype = 0; frameNr = 0; // get rid of warning
1144 }
1145
1146 /*! move a particle at a boundary */
1147 void LbmFsgrSolver::handleObstacleParticle(ParticleObject *p) {
1148         //if(normNoSqrt(v)<=0.) continue; // skip stuck
1149         /*
1150                  p->setVel( v * -1. ); // revert
1151                  p->advanceVel(); // move back twice...
1152                  if( RFLAG(mMaxRefine, i,j,k, workSet)& (CFBndNoslip)) {
1153                  p->setVel( v * -0.5 ); // revert & dampen
1154                  }
1155                  p->advanceVel();  
1156         // */
1157         // TODO mark/remove stuck parts!?
1158
1159         const int level = mMaxRefine;
1160         const int workSet = mLevel[level].setCurr;
1161         LbmVec v = vec2L( p->getVel() );
1162         if(normNoSqrt(v)<=0.) { 
1163                 p->setVel(vec2G(mLevel[level].gravity)); 
1164         }
1165
1166         CellFlagType pflag = CFBnd;
1167         ntlVec3Gfx posOrg(p->getPos());
1168         ntlVec3Gfx npos(0.);
1169         int ni=1,nj=1,nk=1;
1170         int tries = 0;
1171
1172         // try to undo movement
1173         p->advanceVec( (p->getVel()-vec2G(mLevel[level].gravity)) * -2.);  
1174
1175         npos = p->getPos(); ni= (int)npos[0]; 
1176         nj= (int)npos[1]; nk= (int)npos[2];
1177         if(LBMDIM==2) { nk = 0; }
1178         //errMsg("BOUNDCPAR"," t"<<PRINT_VEC(ni,nj,nk)<<" v"<<v<<" p"<<npos);
1179
1180         // delete out of domain
1181         if(!checkDomainBounds(level,ni,nj,nk)) {
1182                 //errMsg("BOUNDCPAR"," DEL! ");
1183                 p->setActive( false ); 
1184                 return;
1185         }
1186         pflag =  RFLAG(level, ni,nj,nk, workSet);
1187         
1188         // try to force particle out of boundary
1189         bool haveNorm = false;
1190         LbmVec bnormal;
1191         if(pflag&CFBnd) {
1192                 npos = posOrg; ni= (int)npos[0]; 
1193                 nj= (int)npos[1]; nk= (int)npos[2];
1194                 if(LBMDIM==2) { nk = 0; }
1195
1196                 computeObstacleSurfaceNormalAcc(ni,nj,nk, &bnormal[0]);
1197                 haveNorm = true;
1198                 normalize(bnormal);
1199                 bnormal *= 0.25;
1200
1201                 tries = 1;
1202                 while(pflag&CFBnd && tries<=5) {
1203                         // use increasing step sizes
1204                         p->advanceVec( vec2G( bnormal *0.5 *(gfxReal)tries ) );  
1205                         npos = p->getPos();
1206                         ni= (int)npos[0]; 
1207                         nj= (int)npos[1]; 
1208                         nk= (int)npos[2];
1209
1210                         // delete out of domain
1211                         if(!checkDomainBounds(level,ni,nj,nk)) {
1212                                 //errMsg("BOUNDCPAR"," DEL! ");
1213                                 p->setActive( false ); 
1214                                 return;
1215                         }
1216                         pflag =  RFLAG(level, ni,nj,nk, workSet);
1217                         tries++;
1218                 }
1219
1220                 // really stuck, delete...
1221                 if(pflag&CFBnd) {
1222                         p->setActive( false ); 
1223                         return;
1224                 }
1225         }
1226
1227         // not in bound anymore!
1228         if(!haveNorm) {
1229                 CellFlagType *bflag = &RFLAG(level, ni,nj,nk, workSet);
1230                 LbmFloat     *bcell = RACPNT(level, ni,nj,nk, workSet);
1231                 computeObstacleSurfaceNormal(bcell,bflag, &bnormal[0]);
1232         }
1233         normalize(bnormal);
1234         LbmVec normComp = bnormal * dot(vec2L(v),bnormal);
1235         //errMsg("BOUNDCPAR","bnormal"<<bnormal<<" normComp"<<normComp<<" newv"<<(v-normComp) );
1236         v = (v-normComp)*0.9; // only move tangential
1237         v *= 0.9; // restdamping , todo use timestep
1238         p->setVel(vec2G(v));
1239         p->advanceVel();
1240 }
1241
1242 /*****************************************************************************/
1243 /*! internal quick print function (for debugging) */
1244 /*****************************************************************************/
1245 void 
1246 LbmFsgrSolver::printLbmCell(int level, int i, int j, int k, int set) {
1247         stdCellId *newcid = new stdCellId;
1248         newcid->level = level;
1249         newcid->x = i;
1250         newcid->y = j;
1251         newcid->z = k;
1252
1253         // this function is not called upon clicking, then its from setMouseClick
1254         debugPrintNodeInfo( newcid, set );
1255         delete newcid;
1256 }
1257 void 
1258 LbmFsgrSolver::debugMarkCellCall(int level, int vi,int vj,int vk) {
1259         stdCellId *newcid = new stdCellId;
1260         newcid->level = level;
1261         newcid->x = vi;
1262         newcid->y = vj;
1263         newcid->z = vk;
1264         this->addCellToMarkedList( newcid );
1265 }
1266
1267                 
1268 /*****************************************************************************/
1269 // implement CellIterator<UniformFsgrCellIdentifier> interface
1270 /*****************************************************************************/
1271
1272
1273
1274 // values from guiflkt.cpp
1275 extern double guiRoiSX, guiRoiSY, guiRoiSZ, guiRoiEX, guiRoiEY, guiRoiEZ;
1276 extern int guiRoiMaxLev, guiRoiMinLev;
1277 #define CID_SX (int)( (mLevel[cid->level].lSizex-1) * guiRoiSX )
1278 #define CID_SY (int)( (mLevel[cid->level].lSizey-1) * guiRoiSY )
1279 #define CID_SZ (int)( (mLevel[cid->level].lSizez-1) * guiRoiSZ )
1280
1281 #define CID_EX (int)( (mLevel[cid->level].lSizex-1) * guiRoiEX )
1282 #define CID_EY (int)( (mLevel[cid->level].lSizey-1) * guiRoiEY )
1283 #define CID_EZ (int)( (mLevel[cid->level].lSizez-1) * guiRoiEZ )
1284
1285 CellIdentifierInterface* 
1286 LbmFsgrSolver::getFirstCell( ) {
1287         int level = mMaxRefine;
1288
1289 #if LBMDIM==3
1290         if(mMaxRefine>0) { level = mMaxRefine-1; } // NO1HIGHESTLEV DEBUG
1291 #endif
1292         level = guiRoiMaxLev;
1293         if(level>mMaxRefine) level = mMaxRefine;
1294         
1295         //errMsg("LbmFsgrSolver::getFirstCell","Celliteration started...");
1296         stdCellId *cid = new stdCellId;
1297         cid->level = level;
1298         cid->x = CID_SX;
1299         cid->y = CID_SY;
1300         cid->z = CID_SZ;
1301         return cid;
1302 }
1303
1304 LbmFsgrSolver::stdCellId* 
1305 LbmFsgrSolver::convertBaseCidToStdCid( CellIdentifierInterface* basecid) {
1306         //stdCellId *cid = dynamic_cast<stdCellId*>( basecid );
1307         stdCellId *cid = (stdCellId*)( basecid );
1308         return cid;
1309 }
1310
1311 void LbmFsgrSolver::advanceCell( CellIdentifierInterface* basecid) {
1312         stdCellId *cid = convertBaseCidToStdCid(basecid);
1313         if(cid->getEnd()) return;
1314
1315         //debugOut(" ADb "<<cid->x<<","<<cid->y<<","<<cid->z<<" e"<<cid->getEnd(), 10);
1316         cid->x++;
1317         if(cid->x > CID_EX){ cid->x = CID_SX; cid->y++; 
1318                 if(cid->y > CID_EY){ cid->y = CID_SY; cid->z++; 
1319                         if(cid->z > CID_EZ){ 
1320                                 cid->level--;
1321                                 cid->x = CID_SX; 
1322                                 cid->y = CID_SY; 
1323                                 cid->z = CID_SZ; 
1324                                 if(cid->level < guiRoiMinLev) {
1325                                         cid->level = guiRoiMaxLev;
1326                                         cid->setEnd( true );
1327                                 }
1328                         }
1329                 }
1330         }
1331         //debugOut(" ADa "<<cid->x<<","<<cid->y<<","<<cid->z<<" e"<<cid->getEnd(), 10);
1332 }
1333
1334 bool LbmFsgrSolver::noEndCell( CellIdentifierInterface* basecid) {
1335         stdCellId *cid = convertBaseCidToStdCid(basecid);
1336         return (!cid->getEnd());
1337 }
1338
1339 void LbmFsgrSolver::deleteCellIterator( CellIdentifierInterface** cid ) {
1340         delete *cid;
1341         *cid = NULL;
1342 }
1343
1344 CellIdentifierInterface* LbmFsgrSolver::getCellAt( ntlVec3Gfx pos ) {
1345         //int cellok = false;
1346         pos -= (this->mvGeoStart);
1347
1348         LbmFloat mmaxsize = mLevel[mMaxRefine].nodeSize;
1349         for(int level=mMaxRefine; level>=0; level--) { // finest first
1350         //for(int level=0; level<=mMaxRefine; level++) { // coarsest first
1351                 LbmFloat nsize = mLevel[level].nodeSize;
1352                 int x,y,z;
1353                 // CHECK +- maxsize?
1354                 x = (int)((pos[0]+0.5*mmaxsize) / nsize );
1355                 y = (int)((pos[1]+0.5*mmaxsize) / nsize );
1356                 z = (int)((pos[2]+0.5*mmaxsize) / nsize );
1357                 if(LBMDIM==2) z = 0;
1358
1359                 // double check...
1360                 if(x<0) continue;
1361                 if(y<0) continue;
1362                 if(z<0) continue;
1363                 if(x>=mLevel[level].lSizex) continue;
1364                 if(y>=mLevel[level].lSizey) continue;
1365                 if(z>=mLevel[level].lSizez) continue;
1366
1367                 // return fluid/if/border cells
1368                 if( ( (RFLAG(level, x,y,z, mLevel[level].setCurr)&(CFUnused)) ) ||
1369                           ( (level<mMaxRefine) && (RFLAG(level, x,y,z, mLevel[level].setCurr)&(CFUnused|CFEmpty)) ) ) {
1370                         continue;
1371                 } // */
1372
1373                 stdCellId *newcid = new stdCellId;
1374                 newcid->level = level;
1375                 newcid->x = x;
1376                 newcid->y = y;
1377                 newcid->z = z;
1378                 //errMsg("cellAt",this->mName<<" "<<pos<<" l"<<level<<":"<<x<<","<<y<<","<<z<<" "<<convertCellFlagType2String(RFLAG(level, x,y,z, mLevel[level].setCurr)) );
1379                 return newcid;
1380         }
1381
1382         return NULL;
1383 }
1384
1385
1386 // INFO functions
1387
1388 int      LbmFsgrSolver::getCellSet      ( CellIdentifierInterface* basecid) {
1389         stdCellId *cid = convertBaseCidToStdCid(basecid);
1390         return mLevel[cid->level].setCurr;
1391         //return mLevel[cid->level].setOther;
1392 }
1393
1394 int      LbmFsgrSolver::getCellLevel    ( CellIdentifierInterface* basecid) {
1395         stdCellId *cid = convertBaseCidToStdCid(basecid);
1396         return cid->level;
1397 }
1398
1399 ntlVec3Gfx   LbmFsgrSolver::getCellOrigin   ( CellIdentifierInterface* basecid) {
1400         ntlVec3Gfx ret;
1401
1402         stdCellId *cid = convertBaseCidToStdCid(basecid);
1403         ntlVec3Gfx cs( mLevel[cid->level].nodeSize );
1404         if(LBMDIM==2) { cs[2] = 0.0; }
1405
1406         if(LBMDIM==2) {
1407                 ret =(this->mvGeoStart + ntlVec3Gfx( cid->x *cs[0], cid->y *cs[1], (this->mvGeoEnd[2]-this->mvGeoStart[2])*0.5 )
1408                                 + ntlVec3Gfx(0.0,0.0,cs[1]*-0.25)*cid->level )
1409                         +getCellSize(basecid);
1410         } else {
1411                 ret =(this->mvGeoStart + ntlVec3Gfx( cid->x *cs[0], cid->y *cs[1], cid->z *cs[2] ))
1412                         +getCellSize(basecid);
1413         }
1414         return (ret);
1415 }
1416
1417 ntlVec3Gfx   LbmFsgrSolver::getCellSize     ( CellIdentifierInterface* basecid) {
1418         // return half size
1419         stdCellId *cid = convertBaseCidToStdCid(basecid);
1420         ntlVec3Gfx retvec( mLevel[cid->level].nodeSize * 0.5 );
1421         // 2d display as rectangles
1422         if(LBMDIM==2) { retvec[2] = 0.0; }
1423         return (retvec);
1424 }
1425
1426 LbmFloat LbmFsgrSolver::getCellDensity  ( CellIdentifierInterface* basecid,int set) {
1427         stdCellId *cid = convertBaseCidToStdCid(basecid);
1428
1429         // skip non-fluid cells
1430         if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&(CFFluid|CFInter)) {
1431                 // ok go on...
1432         } else {
1433                 return 0.;
1434         }
1435
1436         LbmFloat rho = 0.0;
1437         FORDF0 { rho += QCELL(cid->level, cid->x,cid->y,cid->z, set, l); } // ORG
1438         return ((rho-1.0) * mLevel[cid->level].simCellSize / mLevel[cid->level].timestep) +1.0; // ORG
1439         /*if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFInter) { // test
1440                 LbmFloat ux,uy,uz;
1441                 ux=uy=uz= 0.0;
1442                 int lev = cid->level;
1443                 LbmFloat df[27], feqOld[27];
1444                 FORDF0 {
1445                         rho += QCELL(lev, cid->x,cid->y,cid->z, set, l);
1446                         ux += this->dfDvecX[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l);
1447                         uy += this->dfDvecY[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l);
1448                         uz += this->dfDvecZ[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l);
1449                         df[l] = QCELL(lev, cid->x,cid->y,cid->z, set, l);
1450                 }
1451                 FORDF0 {
1452                         feqOld[l] = getCollideEq(l, rho,ux,uy,uz); 
1453                 }
1454                 // debugging mods
1455                 //const LbmFloat Qo = this->getLesNoneqTensorCoeff(df,feqOld);
1456                 //const LbmFloat modOmega = this->getLesOmega(mLevel[lev].omega, mLevel[lev].lcsmago,Qo);
1457                 //rho = (2.0-modOmega) *25.0;
1458                 //rho = Qo*100.0;
1459                 //if(cid->x==24){ errMsg("MODOMT"," at "<<PRINT_VEC(cid->x,cid->y,cid->z)<<" = "<<rho<<" "<<Qo); }
1460                 //else{ rho=0.0; }
1461         } // test 
1462         return rho; // test */
1463 }
1464
1465 LbmVec   LbmFsgrSolver::getCellVelocity ( CellIdentifierInterface* basecid,int set) {
1466         stdCellId *cid = convertBaseCidToStdCid(basecid);
1467
1468         // skip non-fluid cells
1469         if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&(CFFluid|CFInter)) {
1470                 // ok go on...
1471         } else {
1472                 return LbmVec(0.0);
1473         }
1474
1475         LbmFloat ux,uy,uz;
1476         ux=uy=uz= 0.0;
1477         FORDF0 {
1478                 ux += this->dfDvecX[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l);
1479                 uy += this->dfDvecY[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l);
1480                 uz += this->dfDvecZ[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l);
1481         }
1482         LbmVec vel(ux,uy,uz);
1483         // TODO fix...
1484         return (vel * mLevel[cid->level].simCellSize / mLevel[cid->level].timestep * this->mDebugVelScale); // normal
1485 }
1486
1487 LbmFloat   LbmFsgrSolver::getCellDf( CellIdentifierInterface* basecid,int set, int dir) {
1488         stdCellId *cid = convertBaseCidToStdCid(basecid);
1489         return QCELL(cid->level, cid->x,cid->y,cid->z, set, dir);
1490 }
1491 LbmFloat   LbmFsgrSolver::getCellMass( CellIdentifierInterface* basecid,int set) {
1492         stdCellId *cid = convertBaseCidToStdCid(basecid);
1493         return QCELL(cid->level, cid->x,cid->y,cid->z, set, dMass);
1494 }
1495 LbmFloat   LbmFsgrSolver::getCellFill( CellIdentifierInterface* basecid,int set) {
1496         stdCellId *cid = convertBaseCidToStdCid(basecid);
1497         if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFInter) return QCELL(cid->level, cid->x,cid->y,cid->z, set, dFfrac);
1498         if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFFluid) return 1.0;
1499         return 0.0;
1500         //return QCELL(cid->level, cid->x,cid->y,cid->z, set, dFfrac);
1501 }
1502 CellFlagType LbmFsgrSolver::getCellFlag( CellIdentifierInterface* basecid,int set) {
1503         stdCellId *cid = convertBaseCidToStdCid(basecid);
1504         return RFLAG(cid->level, cid->x,cid->y,cid->z, set);
1505 }
1506
1507 LbmFloat LbmFsgrSolver::getEquilDf( int l ) {
1508         return this->dfEquil[l];
1509 }
1510
1511
1512 ntlVec3Gfx LbmFsgrSolver::getVelocityAt   (float xp, float yp, float zp) {
1513         ntlVec3Gfx avgvel(0.0);
1514         LbmFloat   avgnum = 0.;
1515
1516         // taken from getCellAt!
1517         const int level = mMaxRefine;
1518         const int workSet = mLevel[level].setCurr;
1519         const LbmFloat nsize = mLevel[level].nodeSize;
1520         const int x = (int)((-this->mvGeoStart[0]+xp-0.5*nsize) / nsize );
1521         const int y = (int)((-this->mvGeoStart[1]+yp-0.5*nsize) / nsize );
1522         int       z = (int)((-this->mvGeoStart[2]+zp-0.5*nsize) / nsize );
1523         if(LBMDIM==2) z=0;
1524         //errMsg("DUMPVEL","p"<<PRINT_VEC(xp,yp,zp)<<" at "<<PRINT_VEC(x,y,z)<<" max"<<PRINT_VEC(mLevel[level].lSizex,mLevel[level].lSizey,mLevel[level].lSizez) );
1525
1526         // return fluid/if/border cells
1527         // search neighborhood, do smoothing
1528         FORDF0{ 
1529                 const int i = x+this->dfVecX[l];
1530                 const int j = y+this->dfVecY[l];
1531                 const int k = z+this->dfVecZ[l];
1532
1533                 if( (i<0) || (j<0) || (k<0) 
1534                  || (i>=mLevel[level].lSizex) 
1535                  || (j>=mLevel[level].lSizey) 
1536                  || (k>=mLevel[level].lSizez) ) continue;
1537
1538                 if( (RFLAG(level, i,j,k, mLevel[level].setCurr)&(CFFluid|CFInter)) ) {
1539                         ntlVec3Gfx vel(0.0);
1540                         LbmFloat *ccel = RACPNT(level, i,j,k ,workSet); // omp
1541                         for(int n=1; n<this->cDfNum; n++) {
1542                                 vel[0]  += (this->dfDvecX[n]*RAC(ccel,n));
1543                                 vel[1]  += (this->dfDvecY[n]*RAC(ccel,n)); 
1544                                 vel[2]  += (this->dfDvecZ[n]*RAC(ccel,n)); 
1545                         } 
1546
1547                         avgvel += vel;
1548                         avgnum += 1.0;
1549                         if(l==0) { // center slightly more weight
1550                                 avgvel += vel; avgnum += 1.0;
1551                         }
1552                 } // */
1553         }
1554
1555         if(avgnum>0.) {
1556                 ntlVec3Gfx retv = avgvel / avgnum;
1557                 retv *= nsize/mLevel[level].timestep;
1558                 // scale for current animation settings (frame time)
1559                 retv *= mpParam->getCurrentAniFrameTime();
1560                 //errMsg("DUMPVEL","t"<<mSimulationTime<<" at "<<PRINT_VEC(xp,yp,zp)<<" ret:"<<retv<<", avgv:"<<avgvel<<" n"<<avgnum<<" nsize"<<nsize<<" ts"<<mLevel[level].timestep<<" fr"<<mpParam->getCurrentAniFrameTime() );
1561                 return retv;
1562         }
1563         // no cells here...?
1564         //errMsg("DUMPVEL"," at "<<PRINT_VEC(xp,yp,zp)<<" v"<<avgvel<<" n"<<avgnum<<" no vel !?");
1565         return ntlVec3Gfx(0.);
1566 }
1567
1568 #if LBM_USE_GUI==1
1569 //! show simulation info (implement SimulationObject pure virtual func)
1570 void 
1571 LbmFsgrSolver::debugDisplay(int set){ 
1572         //lbmDebugDisplay< LbmFsgrSolver >( set, this ); 
1573         lbmDebugDisplay( set ); 
1574 }
1575 #endif
1576
1577 /*****************************************************************************/
1578 // strict debugging functions
1579 /*****************************************************************************/
1580 #if FSGR_STRICT_DEBUG==1
1581 #define STRICT_EXIT *((int *)0)=0;
1582
1583 int LbmFsgrSolver::debLBMGI(int level, int ii,int ij,int ik, int is) {
1584         if(level <  0){ errMsg("LbmStrict::debLBMGI"," invLev- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; } 
1585         if(level >  mMaxRefine){ errMsg("LbmStrict::debLBMGI"," invLev+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; } 
1586
1587         if((ii==-1)&&(ij==0)) {
1588                 // special case for main loop, ok
1589         } else {
1590                 if(ii<0){ errMsg("LbmStrict"," invX- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1591                 if(ij<0){ errMsg("LbmStrict"," invY- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1592                 if(ii>mLevel[level].lSizex-1){ errMsg("LbmStrict"," invX+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1593                 if(ij>mLevel[level].lSizey-1){ errMsg("LbmStrict"," invY+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1594         }
1595         if(ik<0){ errMsg("LbmStrict"," invZ- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1596         if(ik>mLevel[level].lSizez-1){ errMsg("LbmStrict"," invZ+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1597         if(is<0){ errMsg("LbmStrict"," invS- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1598         if(is>1){ errMsg("LbmStrict"," invS+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1599         return _LBMGI(level, ii,ij,ik, is);
1600 };
1601
1602 CellFlagType& LbmFsgrSolver::debRFLAG(int level, int xx,int yy,int zz,int set){
1603         return _RFLAG(level, xx,yy,zz,set);   
1604 };
1605
1606 CellFlagType& LbmFsgrSolver::debRFLAG_NB(int level, int xx,int yy,int zz,int set, int dir) {
1607         if(dir<0)         { errMsg("LbmStrict"," invD- l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1608         // warning might access all spatial nbs
1609         if(dir>this->cDirNum){ errMsg("LbmStrict"," invD+ l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1610         return _RFLAG_NB(level, xx,yy,zz,set, dir);
1611 };
1612
1613 CellFlagType& LbmFsgrSolver::debRFLAG_NBINV(int level, int xx,int yy,int zz,int set, int dir) {
1614         if(dir<0)         { errMsg("LbmStrict"," invD- l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1615         if(dir>this->cDirNum){ errMsg("LbmStrict"," invD+ l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1616         return _RFLAG_NBINV(level, xx,yy,zz,set, dir);
1617 };
1618
1619 int LbmFsgrSolver::debLBMQI(int level, int ii,int ij,int ik, int is, int l) {
1620         if(level <  0){ errMsg("LbmStrict::debLBMQI"," invLev- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; } 
1621         if(level >  mMaxRefine){ errMsg("LbmStrict::debLBMQI"," invLev+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; } 
1622
1623         if((ii==-1)&&(ij==0)) {
1624                 // special case for main loop, ok
1625         } else {
1626                 if(ii<0){ errMsg("LbmStrict"," invX- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1627                 if(ij<0){ errMsg("LbmStrict"," invY- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1628                 if(ii>mLevel[level].lSizex-1){ errMsg("LbmStrict"," invX+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1629                 if(ij>mLevel[level].lSizey-1){ errMsg("LbmStrict"," invY+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1630         }
1631         if(ik<0){ errMsg("LbmStrict"," invZ- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1632         if(ik>mLevel[level].lSizez-1){ errMsg("LbmStrict"," invZ+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1633         if(is<0){ errMsg("LbmStrict"," invS- l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1634         if(is>1){ errMsg("LbmStrict"," invS+ l"<<level<<"|"<<ii<<","<<ij<<","<<ik<<" s"<<is); STRICT_EXIT; }
1635         if(l<0)        { errMsg("LbmStrict"," invD- "<<" l"<<l); STRICT_EXIT; }
1636         if(l>this->cDfNum){  // dFfrac is an exception
1637                 if((l != dMass) && (l != dFfrac) && (l != dFlux)){ errMsg("LbmStrict"," invD+ "<<" l"<<l); STRICT_EXIT; } }
1638 #if COMPRESSGRIDS==1
1639         //if((!this->mInitDone) && (is!=mLevel[level].setCurr)){ STRICT_EXIT; } // COMPRT debug
1640 #endif // COMPRESSGRIDS==1
1641         return _LBMQI(level, ii,ij,ik, is, l);
1642 };
1643
1644 LbmFloat& LbmFsgrSolver::debQCELL(int level, int xx,int yy,int zz,int set,int l) {
1645         //errMsg("LbmStrict","debQCELL debug: l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" l"<<l<<" index"<<LBMGI(level, xx,yy,zz,set)); 
1646         return _QCELL(level, xx,yy,zz,set,l);
1647 };
1648
1649 LbmFloat& LbmFsgrSolver::debQCELL_NB(int level, int xx,int yy,int zz,int set, int dir,int l) {
1650         if(dir<0)        { errMsg("LbmStrict"," invD- l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1651         if(dir>this->cDfNum){ errMsg("LbmStrict"," invD+ l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1652         return _QCELL_NB(level, xx,yy,zz,set, dir,l);
1653 };
1654
1655 LbmFloat& LbmFsgrSolver::debQCELL_NBINV(int level, int xx,int yy,int zz,int set, int dir,int l) {
1656         if(dir<0)        { errMsg("LbmStrict"," invD- l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1657         if(dir>this->cDfNum){ errMsg("LbmStrict"," invD+ l"<<level<<"|"<<xx<<","<<yy<<","<<zz<<" s"<<set<<" d"<<dir); STRICT_EXIT; }
1658         return _QCELL_NBINV(level, xx,yy,zz,set, dir,l);
1659 };
1660
1661 LbmFloat* LbmFsgrSolver::debRACPNT(int level,  int ii,int ij,int ik, int is ) {
1662         return _RACPNT(level, ii,ij,ik, is );
1663 };
1664
1665 LbmFloat& LbmFsgrSolver::debRAC(LbmFloat* s,int l) {
1666         if(l<0)        { errMsg("LbmStrict"," invD- "<<" l"<<l); STRICT_EXIT; }
1667         if(l>dTotalNum){ errMsg("LbmStrict"," invD+ "<<" l"<<l); STRICT_EXIT; } 
1668         //if(l>this->cDfNum){ // dFfrac is an exception 
1669         //if((l != dMass) && (l != dFfrac) && (l != dFlux)){ errMsg("LbmStrict"," invD+ "<<" l"<<l); STRICT_EXIT; } }
1670         return _RAC(s,l);
1671 };
1672
1673 #endif // FSGR_STRICT_DEBUG==1
1674
1675
1676 /******************************************************************************
1677  * GUI&debugging functions
1678  *****************************************************************************/
1679
1680 //! display a single node
1681 void LbmFsgrSolver::debugPrintNodeInfo(CellIdentifierInterface* cell, int forceSet) {
1682                 //string printInfo,
1683                 // force printing of one set? default = -1 = off
1684   bool printDF     = false;
1685   bool printRho    = false;
1686   bool printVel    = false;
1687   bool printFlag   = false;
1688   bool printGeom   = false;
1689   bool printMass=false;
1690         bool printBothSets = false;
1691         string printInfo = this->getNodeInfoString();
1692
1693         for(size_t i=0; i<printInfo.length()-0; i++) {
1694                 char what = printInfo[i];
1695                 switch(what) {
1696                         case '+': // all on
1697                                                                 printDF = true; printRho = true; printVel = true; printFlag = true; printGeom = true; printMass = true ;
1698                                                                 printBothSets = true; break;
1699                         case '-': // all off
1700                                                                 printDF = false; printRho = false; printVel = false; printFlag = false; printGeom = false; printMass = false; 
1701                                                                 printBothSets = false; break;
1702                         case 'd': printDF = true; break;
1703                         case 'r': printRho = true; break;
1704                         case 'v': printVel = true; break;
1705                         case 'f': printFlag = true; break;
1706                         case 'g': printGeom = true; break;
1707                         case 'm': printMass = true; break;
1708                         case 's': printBothSets = true; break;
1709                         default: 
1710                                 errFatal("debugPrintNodeInfo","Invalid node info id "<<what,SIMWORLD_GENERICERROR); return;
1711                 }
1712         }
1713
1714         ntlVec3Gfx org      = this->getCellOrigin( cell );
1715         ntlVec3Gfx halfsize = this->getCellSize( cell );
1716         int    set      = this->getCellSet( cell );
1717         debMsgStd("debugPrintNodeInfo",DM_NOTIFY, "Printing cell info '"<<printInfo<<"' for node: "<<cell->getAsString()<<" from "<<this->getName()<<" currSet:"<<set , 1);
1718         if(printGeom) debMsgStd("                  ",DM_MSG, "Org:"<<org<<" Halfsize:"<<halfsize<<" ", 1);
1719
1720         int setmax = 2;
1721         if(!printBothSets) setmax = 1;
1722         if(forceSet>=0) setmax = 1;
1723
1724         for(int s=0; s<setmax; s++) {
1725                 int workset = set;
1726                 if(s==1){ workset = (set^1); }          
1727                 if(forceSet>=0) workset = forceSet;
1728                 debMsgStd("                  ",DM_MSG, "Printing set:"<<workset<<" orgSet:"<<set, 1);
1729                 
1730                 if(printDF) {
1731                         for(int l=0; l<LBM_DFNUM; l++) { // FIXME ??
1732                                 debMsgStd("                  ",DM_MSG, "  Df"<<l<<": "<<this->getCellDf(cell,workset,l), 1);
1733                         }
1734                 }
1735                 if(printRho) {
1736                         debMsgStd("                  ",DM_MSG, "  Rho: "<<this->getCellDensity(cell,workset), 1);
1737                 }
1738                 if(printVel) {
1739                         debMsgStd("                  ",DM_MSG, "  Vel: "<<this->getCellVelocity(cell,workset), 1);
1740                 }
1741                 if(printFlag) {
1742                         CellFlagType flag = this->getCellFlag(cell,workset);
1743                         debMsgStd("                  ",DM_MSG, "  Flg: "<< flag<<" "<<convertFlags2String( flag ) <<" "<<convertCellFlagType2String( flag ), 1);
1744                 }
1745                 if(printMass) {
1746                         debMsgStd("                  ",DM_MSG, "  Mss: "<<this->getCellMass(cell,workset), 1);
1747                 }
1748                 // dirty... TODO fixme
1749                 debMsgStd("                  ",DM_MSG, "  Flx: "<<this->getCellDf(cell,workset,dFlux), 1);
1750         }
1751 }
1752
1753