00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_VISUALGRIDDATA_H
00010 #define AMROC_VISUALGRIDDATA_H
00011
00019 #include "GridData3.h"
00020 #include "Evaluator.h"
00021
00022 #include <iostream>
00023 #include <vector>
00024 #include <cfloat>
00025 #include <cmath>
00026
00027 template <class VectorType> class VisualGrid;
00028
00035 template <class VectorType>
00036 class VisualGridData {
00037 typedef typename VectorType::InternalDataType DataType;
00038 typedef VisualGridData<VectorType> self;
00039
00040 public:
00041 typedef VisualGrid<VectorType> grid_type;
00042 typedef Evaluator<VectorType> evaluator_type;
00043 typedef GridData<DataType,3> data_block_type;
00044 typedef GridData<VectorType,3> vector_block_type;
00045
00046 typedef std::vector<self *> gblock_list_type;
00047 typedef typename gblock_list_type::iterator gblock_list_iterator;
00048 typedef std::vector<float> point_list_type;
00049 typedef typename point_list_type::iterator point_list_iterator;
00050
00051 enum direction {x_dir, y_dir, z_dir};
00052
00053 public:
00054 VisualGridData(grid_type& gr, data_block_type& db, BBox &bb, int comp, evaluator_type& ev,
00055 int lev, int proc, float* pdx, float* pgeom) :
00056 _Grid(gr), _Evaluator(ev), _Level(lev), _Processor(proc), dx(pdx), geom(pgeom) {
00057
00058 _data_block = new vector_block_type(bb);
00059 BeginFastIndex3(source, db.bbox(), db.data(), DataType);
00060 BeginFastIndex3(target, _data_block->bbox(), _data_block->data(),
00061 VectorType);
00062 if (comp>=0) {
00063 for_3 (i, j, k, bb, bb.stepsize())
00064 FastIndex3(target,i,j,k)(comp) = FastIndex3(source,i,j,k);
00065 end_for
00066 }
00067 else {
00068 for_3 (i, j, k, bb, bb.stepsize())
00069 FastIndex3(target,i,j,k) = FastIndex3(source,i,j,k);
00070 end_for
00071 }
00072 EndFastIndex3(source);
00073 EndFastIndex3(target);
00074 DimUsed = gr.Dimensions();
00075 }
00076
00077 VisualGridData(grid_type& gr, vector_block_type& db, BBox &bb, evaluator_type& ev,
00078 int lev, int proc, float* pdx, float* pgeom) :
00079 _Grid(gr), _Evaluator(ev), _Level(lev), _Processor(proc), dx(pdx), geom(pgeom) {
00080
00081 _data_block = new vector_block_type(bb);
00082 BeginFastIndex3(source, db.bbox(), db.data(), VectorType);
00083 BeginFastIndex3(target, _data_block->bbox(), _data_block->data(),
00084 VectorType);
00085 for_3 (i, j, k, bb, bb.stepsize())
00086 FastIndex3(target,i,j,k) = FastIndex3(source,i,j,k);
00087 end_for
00088 EndFastIndex3(source);
00089 EndFastIndex3(target);
00090 DimUsed = gr.Dimensions();
00091 }
00092
00093 virtual ~VisualGridData()
00094 { delete _data_block; }
00095
00096 public:
00097 virtual void SetBlocks(int blocks[],int& offset,int& nOffset) {
00098 std::cerr << ".";
00099 _nodeOffset = nOffset;
00100 blocks[offset] = DB().extents(0)+DimUsed(0);
00101 blocks[offset+1] = DB().extents(1)+DimUsed(1);
00102 blocks[offset+2] = DB().extents(2)+DimUsed(2);
00103 nOffset += blocks[offset]*blocks[offset+1]*blocks[offset+2];
00104 offset += 3;
00105 }
00106
00107 virtual void SetGridCells(float xyz[][3],int& offset){
00108 std::cerr << ".";
00109 int i, j, k,orii,orij,orik,ssi,ssj,ssk,ijk,idx;
00110 int exti,extj,extk;
00111 exti=DB().extents(0);
00112 extj=DB().extents(1);
00113 extk=DB().extents(2);
00114 orii=DB().lower(0);
00115 orij=DB().lower(1);
00116 orik=DB().lower(2);
00117 ssi=DB().stepsize(0);
00118 ssj=DB().stepsize(1);
00119 ssk=DB().stepsize(2);
00120
00121 idx = 0;
00122 for (k = 0; k < extk; k++){
00123 for (j = 0; j < extj; j++){
00124 for (i = 0; i < exti; i++){
00125
00126 ijk = k*extj*exti + j*exti + i;
00127
00128 xyz[ijk+offset][0] = (orii+((float)i+0.5)*ssi)*dx[0]+geom[0];
00129 xyz[ijk+offset][1] = (orij+((float)j+0.5)*ssj)*dx[1]+geom[2];
00130 xyz[ijk+offset][2] = (orik+((float)k+0.5)*ssk)*dx[2]+geom[4];
00131 idx++;
00132 }
00133 }
00134 }
00135 offset+=idx;
00136 }
00137 virtual void SetGridNodes(float xyz[][3],int& offset) {
00138 std::cerr << ".";
00139 int i, j, k,orii,orij,orik,ssi,ssj,ssk,ijk,idx;
00140 int exti,extj,extk;
00141 exti=DB().extents(0)+DimUsed(0);
00142 extj=DB().extents(1)+DimUsed(1);
00143 extk=DB().extents(2)+DimUsed(2);
00144 orii=DB().lower(0);
00145 orij=DB().lower(1);
00146 orik=DB().lower(2);
00147 ssi=DB().stepsize(0);
00148 ssj=DB().stepsize(1);
00149 ssk=DB().stepsize(2);
00150
00151 idx = 0;
00152 for (k = 0; k < extk; k++){
00153 for (j = 0; j < extj; j++){
00154 for (i = 0; i < exti; i++){
00155
00156 ijk = k*extj*exti + j*exti + i;
00157
00158 xyz[ijk+offset][0] = (float)(orii+i*ssi)*dx[0]+geom[0];
00159 xyz[ijk+offset][1] = (float)(orij+j*ssj)*dx[1]+geom[2];
00160 xyz[ijk+offset][2] = (float)(orik+k*ssk)*dx[2]+geom[4];
00161 idx++;
00162 }
00163 }
00164 }
00165 offset+=idx;
00166 }
00167
00168 virtual void SetGridConns(int con[][8],int& offset) {
00169 std::cerr << ".";
00170 int i,j,k,ijk,idx;
00171 int exti,extj,extk;
00172 exti=DB().extents(0)+DimUsed(0);
00173 extj=DB().extents(1)+DimUsed(1);
00174 extk=DB().extents(2)+DimUsed(2);
00175
00176 idx = 0;
00177 for (k = 0; k < extk-DimUsed(2); k++){
00178 for (j = 0; j < extj-DimUsed(1); j++){
00179 for (i = 0; i < exti-DimUsed(0); i++){
00180
00181 ijk = k*(extj-DimUsed(1))*(exti-DimUsed(0)) +
00182 j*(exti-DimUsed(0)) + i;
00183
00184 con[ijk+offset][0] = k*extj*exti +
00185 j*exti +
00186 i + _nodeOffset;
00187 con[ijk+offset][1] = k*extj*exti +
00188 j*exti +
00189 (i+DimUsed(0)) + _nodeOffset;
00190 con[ijk+offset][2] = k*extj*exti +
00191 (j+DimUsed(1))*exti +
00192 i + _nodeOffset;
00193 con[ijk+offset][3] = k*extj*exti +
00194 (j+DimUsed(1))*exti +
00195 (i+DimUsed(0)) + _nodeOffset;
00196 con[ijk+offset][4] = (k+DimUsed(2))*extj*exti +
00197 j*exti +
00198 i + _nodeOffset;
00199 con[ijk+offset][5] = (k+DimUsed(2))*extj*exti +
00200 j*exti +
00201 (i+DimUsed(0)) + _nodeOffset;
00202 con[ijk+offset][6] = (k+DimUsed(2))*extj*exti +
00203 (j+DimUsed(1))*exti +
00204 i + _nodeOffset;
00205 con[ijk+offset][7] = (k+DimUsed(2))*extj*exti +
00206 (j+DimUsed(1))*exti +
00207 (i+DimUsed(0)) + _nodeOffset;
00208
00209 idx++;
00210 }
00211 }
00212 }
00213 offset+=idx;
00214 }
00215
00216 virtual void SetScalCells(int *key,float v[],int& offset,bool* CompRead) {
00217 std::cerr << ".";
00218 if (*key==1 || *key==2) {
00219 int idx=0;
00220 for_3 (i,j,k,DB().bbox(),DB().bbox().stepsize())
00221 if (*key==1) {
00222 v[idx+offset]= Processor() + 1.0;
00223 TheEvaluator().mvals[0] = Min(TheEvaluator().mvals[0],v[idx+offset]);
00224 TheEvaluator().mvals[1] = Max(TheEvaluator().mvals[1],v[idx+offset]);
00225 }
00226 else {
00227 v[idx+offset]= Level() + 1.0;
00228 TheEvaluator().mvals[2] = Min(TheEvaluator().mvals[2],v[idx+offset]);
00229 TheEvaluator().mvals[3] = Max(TheEvaluator().mvals[3],v[idx+offset]);
00230 }
00231 idx++;
00232 end_for
00233 offset+=idx;
00234 }
00235 else
00236 TheEvaluator().SetScalCells(*key,v,offset,DB(),dx,CompRead);
00237 }
00238
00239 virtual void SetScalNodes(int *key,float v[],int& offset,bool* CompRead) {
00240 std::cerr << ".";
00241 if (*key==1) {
00242 int idx=0;
00243 BBox lbbox(grow(DB().bbox(),DimUsed));
00244 data_block_type dbwork(lbbox);
00245 dbwork = -1.0;
00246 BeginFastIndex3(tgt, lbbox, dbwork.data(), DataType);
00247
00248 for (gblock_list_iterator bit=_Grid.BlockList().begin();
00249 bit!=_Grid.BlockList().end(); bit++)
00250 if ((*bit)->Processor() == Processor()) {
00251 BBox bbcur(growupper((*bit)->DB().bbox(),1));
00252 bbcur.setstepsize(lbbox.stepsize());
00253 bbcur.growupper(-1);
00254 BBox bbwork(lbbox * bbcur);
00255 if (bbwork.empty())
00256 continue;
00257
00258 bbwork.lower() = (bbwork.lower()/bbwork.stepsize())*
00259 bbwork.stepsize();
00260 bbwork.upper() = (bbwork.upper()/bbwork.stepsize())*
00261 bbwork.stepsize();
00262
00263 for_3 (i, j, k, bbwork, bbwork.stepsize())
00264 FastIndex3(tgt,i,j,k) = Processor();
00265 end_for
00266 }
00267
00268 int StepsizeMax = 1;
00269 for (int l=1; l<_Grid.NLevels(); l++)
00270 StepsizeMax *= _Grid.RefineFactor(l-1);
00271
00272 BBox bbox(DB().bbox());
00273 Coords step = DB().bbox().stepsize();
00274 Coords dimstep = DimUsed*step;
00275 bbox.upper() += dimstep;
00276 for_3 (i, j, k, bbox, step)
00277 v[idx+offset] = Processor() + 1.0;
00278
00279 TheEvaluator().mvals[0] = Min(TheEvaluator().mvals[0], v[idx+offset]);
00280 TheEvaluator().mvals[1] = Max(TheEvaluator().mvals[1], v[idx+offset]);
00281 idx++;
00282 end_for
00283
00284 EndFastIndex3(tgt);
00285 offset+=idx;
00286 }
00287
00288 else if (*key==2) {
00289 int idx=0;
00290 BBox lbbox(grow(DB().bbox(),DimUsed));
00291 data_block_type dbwork(lbbox);
00292 dbwork = -1.0;
00293 BeginFastIndex3(tgt, lbbox, dbwork.data(), DataType);
00294
00295 for (gblock_list_iterator bit=_Grid.BlockList().begin();
00296 bit!=_Grid.BlockList().end(); bit++)
00297 if ((*bit)->Level() == Level()) {
00298 BBox bbcur(growupper((*bit)->DB().bbox(),1));
00299 bbcur.setstepsize(lbbox.stepsize());
00300 bbcur.growupper(-1);
00301 BBox bbwork(lbbox * bbcur);
00302 if (bbwork.empty())
00303 continue;
00304
00305 bbwork.lower() = (bbwork.lower()/bbwork.stepsize())*
00306 bbwork.stepsize();
00307 bbwork.upper() = (bbwork.upper()/bbwork.stepsize())*
00308 bbwork.stepsize();
00309
00310 for_3 (i, j, k, bbwork, bbwork.stepsize())
00311 FastIndex3(tgt,i,j,k) = Level();
00312 end_for
00313 }
00314
00315 int StepsizeMax = 1;
00316 for (int l=1; l<_Grid.NLevels(); l++)
00317 StepsizeMax *= _Grid.RefineFactor(l-1);
00318
00319 BBox bbox(DB().bbox());
00320 Coords step = DB().bbox().stepsize();
00321 Coords dimstep = DimUsed*step;
00322 bbox.upper() += dimstep;
00323 for_3 (i, j, k, bbox, step)
00324 v[idx+offset] = Level() + 1.0;
00325
00326 TheEvaluator().mvals[2] = Min(TheEvaluator().mvals[2], v[idx+offset]);
00327 TheEvaluator().mvals[3] = Max(TheEvaluator().mvals[3], v[idx+offset]);
00328 idx++;
00329 end_for
00330
00331 EndFastIndex3(tgt);
00332 offset+=idx;
00333 }
00334
00335 else {
00336 BBox lbbox(grow(DB().bbox(),DimUsed));
00337 lbbox *= _Grid.GlobalBBox();
00338 lbbox.lower() = (lbbox.lower()/lbbox.stepsize())*lbbox.stepsize();
00339 lbbox.upper() = (lbbox.upper()/lbbox.stepsize())*lbbox.stepsize();
00340 vector_block_type dbwork(lbbox);
00341 dbwork = FLT_MAX;
00342 BeginFastIndex3(tgt, lbbox, dbwork.data(), VectorType);
00343
00344 for (gblock_list_iterator bit=_Grid.BlockList().begin();
00345 bit!=_Grid.BlockList().end(); bit++) {
00346 BBox bbcur(growupper((*bit)->DB().bbox(),1));
00347 bbcur.setstepsize(lbbox.stepsize());
00348 bbcur.growupper(-1);
00349 BBox bbwork(lbbox * bbcur);
00350 if (bbwork.empty())
00351 continue;
00352
00353 bbwork.lower() = (bbwork.lower()/bbwork.stepsize())*bbwork.stepsize();
00354 bbwork.upper() = (bbwork.upper()/bbwork.stepsize())*bbwork.stepsize();
00355
00356 Coords step_src = (*bit)->DB().bbox().stepsize();
00357 Coords step_tgt = bbwork.stepsize();
00358 if (step_tgt(0) == step_src(0))
00359 dbwork.copy((*bit)->DB(), bbwork);
00360
00361 else if (step_tgt(0) > step_src(0)) {
00362 BeginFastIndex3(src, (*bit)->DB().bbox(), (*bit)->DB().data(),
00363 VectorType);
00364 for_3 (i, j, k, bbwork, bbwork.stepsize())
00365 BBox AddOver(3,i,j,k,
00366 i+step_tgt(0)-step_src(0),
00367 j+step_tgt(1)-step_src(1),
00368 k+step_tgt(2)-step_src(2),
00369 step_src(0),step_src(1),step_src(2));
00370 AddOver *= (*bit)->DB().bbox();
00371 float c=0;
00372 FastIndex3(tgt,i,j,k) = 0.0;
00373 for_3 (l, m, n, AddOver, step_src)
00374 FastIndex3(tgt,i,j,k) += FastIndex3(src,l,m,n);
00375 c += 1.0;
00376 end_for
00377 if (c>0) FastIndex3(tgt,i,j,k) /= c;
00378 end_for
00379 EndFastIndex3(src);
00380 }
00381
00382 else {
00383 BeginFastIndex3(src, (*bit)->DB().bbox(), (*bit)->DB().data(),
00384 VectorType);
00385 for_3 (i, j, k, bbwork, bbwork.stepsize())
00386 FastIndex3(tgt,i,j,k) = FastIndex3(src,i-i%step_src(0),
00387 j-j%step_src(1),
00388 k-k%step_src(2));
00389 end_for
00390 EndFastIndex3(src);
00391 }
00392 }
00393 EndFastIndex3(tgt);
00394
00395 BBox bbox(DB().bbox());
00396 Coords dimstep = DimUsed*DB().bbox().stepsize();
00397 bbox.upper() += dimstep;
00398 TheEvaluator().SetScalNodes(*key,v,offset,dbwork,bbox,dx,CompRead);
00399 }
00400 }
00401
00402 virtual void SetPointsCells(int *key,point_list_type &p,float v[],bool* CompRead) {
00403 register int d;
00404 float lb[3], ub[3];
00405 for (d=0; d<3; d++) {
00406 lb[d]=DB().lower(d)*dx[d]+geom[2*d];
00407 ub[d]=(DB().extents(d)+DimUsed(d)-1)*DB().stepsize(d)*dx[d]+lb[d];
00408 }
00409 std::vector<unsigned int> plist;
00410 for (register unsigned int i=0;i<p.size()/3;i++) {
00411 for (d=0; d<3; d++)
00412 if (DimUsed(d))
00413 if (p[3*i+d]<lb[d] || p[3*i+d]>ub[d]) break;
00414 if (d==3) plist.push_back(i);
00415 }
00416
00417 if (!plist.empty()) {
00418 float *tmpdata = new float[NCells()];
00419 int offset=0;
00420 SetScalCells(key,tmpdata,offset,CompRead);
00421 for (register unsigned int i=0;i<plist.size();i++) {
00422 int idx[3];
00423 for (d=0; d<3; d++) {
00424 if (DimUsed(d))
00425 idx[d]=int((p[3*plist[i]+d]-lb[d])/(DB().stepsize(d)*dx[d]));
00426 else idx[d]=0;
00427 if (idx[d]<0 || idx[d]>=DB().extents(d)) break;
00428 }
00429 if (d==3) {
00430 v[plist[i]]=tmpdata[idx[0]+DB().extents(0)*(idx[1]+DB().extents(1)*idx[2])];
00431
00432
00433 for (d=0; d<3; d++)
00434 p[3*plist[i]+d]=-1.e37;
00435 }
00436 }
00437 delete [] tmpdata;
00438 }
00439 }
00440
00441 virtual void SetPointsNodes(int *key,point_list_type &p,float v[],bool* CompRead) {
00442 register int d;
00443 float lb[3], ub[3];
00444 for (d=0; d<3; d++) {
00445 lb[d]=DB().lower(d)*dx[d]+geom[2*d];
00446 ub[d]=(DB().extents(d)+DimUsed(d)-1)*DB().stepsize(d)*dx[d]+lb[d];
00447 }
00448 std::vector<unsigned int> plist;
00449 for (register unsigned int i=0;i<p.size()/3;i++) {
00450 for (d=0; d<3; d++)
00451 if (DimUsed(d))
00452 if (p[3*i+d]<lb[d] || p[3*i+d]>ub[d]) break;
00453 if (d==3) plist.push_back(i);
00454 }
00455
00456 if (!plist.empty()) {
00457 float *tmpdata = new float[NNodes()];
00458 int offset=0;
00459 SetScalNodes(key,tmpdata,offset,CompRead);
00460 for (register unsigned int i=0;i<plist.size();i++) {
00461 int idx[3], idp[3], ext[3];
00462 float fac[3];
00463 for (d=0; d<3; d++) {
00464 if (DimUsed(d)) {
00465 idx[d]=int((p[3*plist[i]+d]-lb[d])/(DB().stepsize(d)*dx[d]));
00466 fac[d]=(p[3*plist[i]+d]-lb[d]-idx[d]*DB().stepsize(d)*dx[d])/
00467 (DB().stepsize(d)*dx[d]);
00468 if (fac[d]<=0.5) fac[d]=0.;
00469 else fac[d]=1.;
00470 idp[d]=idx[d]+1;
00471 }
00472 else {
00473 idx[d]=0; fac[d]=0.; idp[d]=0;
00474 }
00475 ext[d]=DB().extents(d)+DimUsed(d);
00476 if (idx[d]<0 || idp[d]>=ext[d]) break;
00477 }
00478
00479 if (d==3) {
00480 float &d0=tmpdata[idx[0]+ext[0]*(idx[1]+ext[1]*idx[2])];
00481 float &d1=tmpdata[idp[0]+ext[0]*(idx[1]+ext[1]*idx[2])];
00482 float &d2=tmpdata[idx[0]+ext[0]*(idp[1]+ext[1]*idx[2])];
00483 float &d3=tmpdata[idp[0]+ext[0]*(idp[1]+ext[1]*idx[2])];
00484 float &d4=tmpdata[idx[0]+ext[0]*(idx[1]+ext[1]*idp[2])];
00485 float &d5=tmpdata[idp[0]+ext[0]*(idx[1]+ext[1]*idp[2])];
00486 float &d6=tmpdata[idx[0]+ext[0]*(idp[1]+ext[1]*idp[2])];
00487 float &d7=tmpdata[idp[0]+ext[0]*(idp[1]+ext[1]*idp[2])];
00488
00489 float x0=FLT_MAX, x1=FLT_MAX, x2=FLT_MAX, x3=FLT_MAX;
00490 if (d0<FLT_MAX && d1<FLT_MAX) x0=(1.-fac[0])*d0+fac[0]*d1;
00491 else { if (d0<FLT_MAX) x0=d0; else if (d1<FLT_MAX) x0=d1; }
00492 if (d2<FLT_MAX && d3<FLT_MAX) x1=(1.-fac[0])*d2+fac[0]*d3;
00493 else { if (d2<FLT_MAX) x1=d2; else if (d3<FLT_MAX) x1=d3; }
00494 if (d4<FLT_MAX && d5<FLT_MAX) x2=(1.-fac[0])*d4+fac[0]*d5;
00495 else { if (d4<FLT_MAX) x2=d4; else if (d5<FLT_MAX) x2=d5; }
00496 if (d6<FLT_MAX && d7<FLT_MAX) x3=(1.-fac[0])*d6+fac[0]*d7;
00497 else { if (d6<FLT_MAX) x3=d6; else if (d7<FLT_MAX) x3=d7; }
00498
00499 float y0=FLT_MAX, y1=FLT_MAX;
00500 if (x0<FLT_MAX && x1<FLT_MAX) y0=(1.-fac[1])*x0+fac[1]*x1;
00501 else { if (x0<FLT_MAX) y0=x0; else if (x1<FLT_MAX) y0=x1; }
00502 if (x2<FLT_MAX && x3<FLT_MAX) y1=(1.-fac[1])*x2+fac[1]*x3;
00503 else { if (x2<FLT_MAX) y1=x2; else if (x3<FLT_MAX) y1=x3; }
00504
00505 v[plist[i]]=FLT_MAX;
00506 if (y0<FLT_MAX && y1<FLT_MAX) v[plist[i]]=(1.-fac[2])*y0+fac[2]*y1;
00507 else { if (y0<FLT_MAX) v[plist[i]]=y0; else if (y1<FLT_MAX) v[plist[i]]=y1; }
00508
00509
00510 for (d=0; d<3; d++)
00511 p[3*plist[i]+d]=-1.e37;
00512 }
00513 }
00514 delete [] tmpdata;
00515 }
00516 }
00517
00518 virtual void VectCells(int *key,float v[][3],int& offset,bool* CompRead) {
00519 std::cerr << ".";
00520 int idx=0;
00521 BeginFastIndex3(dat, DB().bbox(), DB().data(), VectorType);
00522 for_3 (i,j,k,DB().bbox(),DB().bbox().stepsize())
00523 v[idx+offset][0]= FastIndex3(dat,i,j,k)(1);
00524 v[idx+offset][1]= FastIndex3(dat,i,j,k)(2);
00525 v[idx+offset][2]= FastIndex3(dat,i,j,k)(3);
00526 idx++;
00527 end_for
00528 offset+=idx;
00529 EndFastIndex3(dat);
00530 }
00531
00532 virtual void VectNodes(int *key,float v[][3],int& offset,bool* CompRead) {
00533 std::cerr << ".";
00534 int idx=0;
00535
00536 BBox lbbox(grow(DB().bbox(),DimUsed));
00537 lbbox *= _Grid.GlobalBBox();
00538 lbbox.lower() = (lbbox.lower()/lbbox.stepsize())*lbbox.stepsize();
00539 lbbox.upper() = (lbbox.upper()/lbbox.stepsize())*lbbox.stepsize();
00540 vector_block_type dbwork(lbbox);
00541 dbwork = FLT_MAX;
00542 BeginFastIndex3(tgt, lbbox, dbwork.data(), VectorType);
00543
00544 for (gblock_list_iterator bit=_Grid.BlockList().begin();
00545 bit!=_Grid.BlockList().end(); bit++) {
00546 BBox bbcur(growupper((*bit)->DB().bbox(),1));
00547 bbcur.setstepsize(lbbox.stepsize());
00548 bbcur.growupper(-1);
00549 BBox bbwork(lbbox * bbcur);
00550 if (bbwork.empty())
00551 continue;
00552
00553 bbwork.lower() = (bbwork.lower()/bbwork.stepsize())*bbwork.stepsize();
00554 bbwork.upper() = (bbwork.upper()/bbwork.stepsize())*bbwork.stepsize();
00555
00556 Coords step_src = (*bit)->DB().bbox().stepsize();
00557 Coords step_tgt = bbwork.stepsize();
00558 if (step_tgt(0) == step_src(0))
00559 dbwork.copy((*bit)->DB(), bbwork);
00560
00561 else if (step_tgt(0) > step_src(0)) {
00562 BeginFastIndex3(src, (*bit)->DB().bbox(), (*bit)->DB().data(),
00563 VectorType);
00564 for_3 (i, j, k, bbwork, bbwork.stepsize())
00565 BBox AddOver(3,i,j,k,
00566 i+step_tgt(0)-step_src(0),
00567 j+step_tgt(1)-step_src(1),
00568 k+step_tgt(2)-step_src(2),
00569 step_src(0),step_src(1),step_src(2));
00570 AddOver *= (*bit)->DB().bbox();
00571 float c=0;
00572 FastIndex3(tgt,i,j,k) = 0.0;
00573 for_3 (l, m, n, AddOver, step_src)
00574 FastIndex3(tgt,i,j,k) += FastIndex3(src,l,m,n);
00575 c += 1.0;
00576 end_for
00577 if (c>0) FastIndex3(tgt,i,j,k) /= c;
00578 end_for
00579 EndFastIndex3(src);
00580 }
00581
00582 else {
00583 BeginFastIndex3(src, (*bit)->DB().bbox(), (*bit)->DB().data(),
00584 VectorType);
00585 for_3 (i, j, k, bbwork, bbwork.stepsize())
00586 FastIndex3(tgt,i,j,k) = FastIndex3(src,i-i%step_src(0),
00587 j-j%step_src(1),
00588 k-k%step_src(2));
00589 end_for
00590 EndFastIndex3(src);
00591 }
00592 }
00593
00594 BBox bbox(DB().bbox());
00595 Coords dimstep = DimUsed*DB().bbox().stepsize();
00596 bbox.upper() += dimstep;
00597
00598 for_3 (i, j, k, bbox, dimstep)
00599 BBox AddOver(3,i-dimstep(0),j-dimstep(1),k-dimstep(2),
00600 i,j,k,dimstep(0),dimstep(1),dimstep(2));
00601 AddOver *= lbbox;
00602
00603 float c=0;
00604 v[idx+offset][0]=0;
00605 v[idx+offset][1]=0;
00606 v[idx+offset][2]=0;
00607 for_3 (l, m, n, AddOver, dimstep)
00608 v[idx+offset][0] += FastIndex3(tgt,l,m,n)(1);
00609 v[idx+offset][1] += FastIndex3(tgt,l,m,n)(2);
00610 v[idx+offset][2] += FastIndex3(tgt,l,m,n)(3);
00611 c += 1.0;
00612 end_for
00613 if (c>0) {
00614 v[idx+offset][0] /= c;
00615 v[idx+offset][1] /= c;
00616 v[idx+offset][2] /= c;
00617 }
00618 idx++;
00619 end_for
00620
00621 EndFastIndex3(tgt);
00622 offset+=idx;
00623 }
00624
00625 virtual vector_block_type& DB() { return *_data_block; }
00626 virtual int NNodes() { return (!DB().bbox().empty() ?
00627 ((DB().extents(0)+DimUsed(0))*
00628 (DB().extents(1)+DimUsed(1))*
00629 (DB().extents(2)+DimUsed(2))) : 0); }
00630 virtual int NCells() { return DB().size(); }
00631 virtual const int& Level() const { return _Level; }
00632 virtual int Level() { return _Level; }
00633 virtual const int& Processor() const { return _Processor; }
00634 virtual int Processor() { return _Processor; }
00635 virtual evaluator_type& TheEvaluator() { return _Evaluator; }
00636
00637 protected:
00638 grid_type& _Grid;
00639 vector_block_type* _data_block;
00640 evaluator_type& _Evaluator;
00641 int _Level;
00642 int _Processor;
00643 float* dx;
00644 float* geom;
00645 int _nodeOffset;
00646 Coords DimUsed;
00647 };
00648
00649 #endif