int main (int argc, char** argv) { BoxLib::Initialize(argc, argv); the_prog_name = argv[0]; parse_args(argv); BoxArray ba(nBoxs); ba.set(0, Box(IntVect(D_DECL(0,0,0)), IntVect(D_DECL(2,2,2)))); for (int i = 1; i < nBoxs; i++) { ba.set(i,BoxLib::grow(ba[i-1],2)); } MultiFab mf(ba, 2, 1); for (MFIter mfi(mf); mfi.isValid(); ++mfi) { mf[mfi.index()].setVal(mfi.index()+1); } // // Set cells in ghost region to zero. // mf.setBndry(0); static const std::string mf_name = "Spam-n-Eggs"; Write_N_Read (mf, mf_name); BoxLib::Finalize(); }
EBRestart::GeomParams::GeomParams( const EBRestart::InputParams& a_inputs ) : domain(Box(IntVect::Zero, IntVect(a_inputs.n_cell) - 1)), dx((a_inputs.prob_hi - a_inputs.prob_lo[0])/a_inputs.n_cell[0]), origin(a_inputs.prob_lo), center(a_inputs.center), radius(a_inputs.radius) { CH_assert( IntVect(a_inputs.n_cell) > IntVect::Zero ); }
int makeTags(IntVectSet& a_tags, const Box& a_domainCoar) { #if (CH_SPACEDIM ==2) int nc = a_domainCoar.size(0); if (nc < 16) { pout() << "coarsest level must be at least 16x16" << endl; return -22; } int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 int nte = (nc*3)/8; //12 int nfe = (nc*5)/8; //20 Box boxf2(IntVect(nmi,nte), IntVect(ntf-1,nfe-1)); Box boxf4(IntVect(nfe,nqu), IntVect(nc -1,nte-1)); #else int nc = a_domainCoar.size(0); int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 Box boxf2(IntVect(0, nqu,nqu), IntVect(nmi-1,ntf-1,ntf-1)); Box boxf4(IntVect(0, 0, 0), IntVect(nqu-1,nqu-1,nqu-1)); #endif a_tags |= boxf2; a_tags |= boxf4; return 0; }
void do_geo(DisjointBoxLayout& a_dbl, EBISLayout & a_ebisl, Box & a_domain, Real & a_dx ) { //define grids int len = 32; int mid = len/2; Real xdom = 1.0; a_dx = xdom/len; const IntVect hi = (len-1)*IntVect::Unit; a_domain= Box(IntVect::Zero, hi); Vector<Box> boxes(4); Vector<int> procs(4); boxes[0] = Box(IntVect(D_DECL(0 , 0, 0)), IntVect(D_DECL(mid-1, mid-1, len-1))); boxes[1] = Box(IntVect(D_DECL(0 ,mid, 0)), IntVect(D_DECL(mid-1, len-1, len-1))); boxes[2] = Box(IntVect(D_DECL(mid, 0, 0)), IntVect(D_DECL(len-1, mid-1, len-1))); boxes[3] = Box(IntVect(D_DECL(mid,mid, 0)), IntVect(D_DECL(len-1, len-1, len-1))); LoadBalance(procs, boxes); /** int loProc = 0; int hiProc = numProc() -1; procs[0] = loProc; procs[1] = hiProc; procs[2] = loProc; procs[3] = hiProc; **/ a_dbl = DisjointBoxLayout(boxes, procs); //define geometry RealVect rampNormal = RealVect::Zero; rampNormal[0] = -0.5; rampNormal[1] = 0.866025404; Real rampAlpha = -0.0625; RealVect rampPoint = RealVect::Zero; rampPoint[0] = rampAlpha / rampNormal[0]; bool inside = true; PlaneIF ramp(rampNormal,rampPoint,inside); RealVect vectDx = RealVect::Unit; vectDx *= a_dx; GeometryShop mygeom( ramp, 0, vectDx ); RealVect origin = RealVect::Zero; EBIndexSpace *ebisPtr = Chombo_EBIS::instance(); ebisPtr->define(a_domain, origin, a_dx, mygeom); //fill layout ebisPtr->fillEBISLayout(a_ebisl, a_dbl, a_domain, 4 ); }
Box BoxLib::refine (const Box& b, int ref_ratio) { Box result = b; result.refine(IntVect(D_DECL(ref_ratio,ref_ratio,ref_ratio))); return result; }
// the contents of v are blown out void ExplicitBitVect::getOnBits (IntVect& v) const { unsigned int nOn = getNumOnBits(); if(!v.empty()) IntVect().swap(v); v.reserve(nOn); for(unsigned int i=0;i<d_size;i++){ if((bool)(*dp_bits)[i]) v.push_back(i); } };
Box BoxLib::coarsen (const Box& b, int ref_ratio) { Box result = b; result.coarsen(IntVect(D_DECL(ref_ratio,ref_ratio,ref_ratio))); return result; }
const IntVect BoxLib::coarsen (const IntVect& p, int s) { BL_ASSERT(s > 0); IntVect v = p; return v.coarsen(IntVect(D_DECL(s,s,s))); }
// """ ------------------------------------------------------- // // getOnBits(IntVect &which) // C++: Passes the set of on bits out in the IntVect passed in. // The contents of IntVect are destroyed. // // Python: Returns the tuple of on bits // // """ ------------------------------------------------------- void SparseBitVect::getOnBits(IntVect &v) const { if (!dp_bits) { throw ValueErrorException("BitVect not properly initialized."); } unsigned int nOn = getNumOnBits(); if (!v.empty()) IntVect().swap(v); v.reserve(nOn); v.resize(nOn); std::copy(dp_bits->begin(), dp_bits->end(), v.begin()); };
void getUnitSquareGrid(const int a_n_radial, const int a_n_poloidal, FArrayBox& a_xi) { Box box(IntVect::Zero, IntVect(a_n_radial,a_n_poloidal)); RealVect dx(1./a_n_radial,1./a_n_poloidal); a_xi.define(box,2); for (BoxIterator bit(box);bit.ok();++bit) { IntVect iv = bit(); for (int dir=0; dir<SpaceDim; ++dir) { a_xi(iv,dir) = iv[dir]*dx[dir]; } } }
std::vector<IntVect> Periodicity::shiftIntVect () const { std::vector<IntVect> r; int per[3] = {0,0,0}; int jmp[3] = {1,1,1}; for (int i = 0; i < BL_SPACEDIM; ++i) { if (isPeriodic(i)) { per[i] = jmp[i] = period[i]; } } for (int i = -per[0]; i <= per[0]; i += jmp[0]) { for (int j = -per[1]; j <= per[1]; j += jmp[1]) { for (int k = -per[2]; k <= per[2]; k += jmp[2]) { r.push_back(IntVect(D_DECL(i,j,k))); } } } return r; }
IntVect iMultiFab::maxIndex (int comp, int nghost) const { BL_ASSERT(nghost >= 0 && nghost <= n_grow); IntVect loc; int mx = -std::numeric_limits<int>::max(); #ifdef _OPENMP #pragma omp parallel #endif { IntVect priv_loc; int priv_mx = -std::numeric_limits<int>::max(); for (MFIter mfi(*this); mfi.isValid(); ++mfi) { const Box& box = BoxLib::grow(mfi.validbox(),nghost); const int lmx = get(mfi).max(box,comp); if (lmx > priv_mx) { priv_mx = lmx; priv_loc = get(mfi).maxIndex(box,comp); } } #ifdef _OPENMP #pragma omp critical (imultifab_maxindex) #endif { if (priv_mx > mx) { mx = priv_mx; loc = priv_loc; } } } const int NProcs = ParallelDescriptor::NProcs(); if (NProcs > 1) { Array<int> mxs(1); Array<int> locs(1); if (ParallelDescriptor::IOProcessor()) { mxs.resize(NProcs); locs.resize(NProcs*BL_SPACEDIM); } const int IOProc = ParallelDescriptor::IOProcessorNumber(); ParallelDescriptor::Gather(&mx, 1, mxs.dataPtr(), 1, IOProc); BL_ASSERT(sizeof(IntVect) == sizeof(int)*BL_SPACEDIM); ParallelDescriptor::Gather(loc.getVect(), BL_SPACEDIM, locs.dataPtr(), BL_SPACEDIM, IOProc); if (ParallelDescriptor::IOProcessor()) { mx = mxs[0]; loc = IntVect(D_DECL(locs[0],locs[1],locs[2])); for (int i = 1; i < NProcs; i++) { if (mxs[i] > mx) { mx = mxs[i]; const int j = BL_SPACEDIM * i; loc = IntVect(D_DECL(locs[j+0],locs[j+1],locs[j+2])); } } } ParallelDescriptor::Bcast(const_cast<int*>(loc.getVect()), BL_SPACEDIM, IOProc); } return loc; }
BoxList& BoxList::maxSize (int chunk) { return maxSize(IntVect(D_DECL(chunk,chunk,chunk))); }
int BoxList::simplify_doit (bool best) { // // Try to merge adjacent boxes. // int count = 0, lo[BL_SPACEDIM], hi[BL_SPACEDIM]; for (iterator bla = begin(), End = end(); bla != End; ) { const int* alo = bla->loVect(); const int* ahi = bla->hiVect(); bool match = false; iterator blb = bla; ++blb; // // If we're not looking for the "best" we can do in one pass, we // limit how far afield we look for abutting boxes. This greatly // speeds up this routine for large numbers of boxes. It does not // do quite as good a job though as full brute force. // const int MaxCnt = (best ? size() : 100); for (int cnt = 0; blb != End && cnt < MaxCnt; cnt++) { const int* blo = blb->loVect(); const int* bhi = blb->hiVect(); // // Determine if a and b can be coalesced. // They must have equal extents in all index directions // except possibly one, and must abutt in that direction. // bool canjoin = true; int joincnt = 0; for (int i = 0; i < BL_SPACEDIM; i++) { if (alo[i]==blo[i] && ahi[i]==bhi[i]) { lo[i] = alo[i]; hi[i] = ahi[i]; } else if (alo[i]<=blo[i] && blo[i]<=ahi[i]+1) { lo[i] = alo[i]; hi[i] = std::max(ahi[i],bhi[i]); joincnt++; } else if (blo[i]<=alo[i] && alo[i]<=bhi[i]+1) { lo[i] = blo[i]; hi[i] = std::max(ahi[i],bhi[i]); joincnt++; } else { canjoin = false; break; } } if (canjoin && (joincnt <= 1)) { // // Modify b and remove a from the list. // blb->setSmall(IntVect(lo)); blb->setBig(IntVect(hi)); lbox.erase(bla++); count++; match = true; break; } else { // // No match found, try next element. // ++blb; } } // // If a match was found, a was already advanced in the list. // if (!match) ++bla; } return count; }
const Periodicity& Periodicity::NonPeriodic () { static const Periodicity np(IntVect(D_DECL(0,0,0))); return np; }
int makeLayouts(DisjointBoxLayout& a_dblCoar, DisjointBoxLayout& a_dblFine, const Box& a_domainCoar, const Box& a_domainFine) { //set up mesh refine object int eekflag= 0; Vector<Box> vboxCoar; Vector<Box> vboxFine; #if 1 ParmParse pp; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 1; int blockFactor = 2; Real fillrat = 0.75; Vector<int> refRat(2,2); BRMeshRefine meshRefObj(a_domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, a_domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = a_domainCoar.size(0); int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 int nte = (nc*3)/8; //12 int nfe = (nc*5)/8; //20 #if (CH_SPACEDIM ==2) Box boxf1(IntVect(0, nqu), IntVect(nmi-1,ntf-1)); Box boxf2(IntVect(nmi,nte), IntVect(ntf-1,nfe-1)); Box boxf3(IntVect(nqu,0 ), IntVect(nfe-1,nqu-1)); Box boxf4(IntVect(nfe,nqu), IntVect(nc -1,nte-1)); // Box boxf5(IntVect(nqu,nqu), IntVect(ntf-1,ntf-1)); #else Box boxf1(IntVect(0, nqu,nqu), IntVect(nmi-1,ntf-1,ntf-1)); Box boxf2(IntVect(nmi,nte,nte), IntVect(ntf-1,nfe-1,nfe-1)); Box boxf3(IntVect(nqu,0,0 ), IntVect(nfe-1,nqu-1,nqu-1)); Box boxf4(IntVect(nfe,nqu,nqu), IntVect(nc -1,nte-1,nte-1)); // Box boxf5(IntVect(nqu,nqu), IntVect(ntf-1,ntf-1)) #endif IntVectSet tags; tags |= boxf1; tags |= boxf2; tags |= boxf3; tags |= boxf4; // tags |= boxf5; int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); vboxCoar = newMeshes[0]; vboxFine = newMeshes[1]; #else vboxCoar = Vector<Box>(1, a_domainCoar); Box shrunkFine = a_domainFine; int nc = Max(a_domainCoar.size(0)/4, 2); shrunkFine.grow(-nc); vboxFine = Vector<Box>(1, shrunkFine); #endif Vector<int> procAssignFine, procAssignCoar; eekflag = LoadBalance(procAssignFine,vboxFine); if (eekflag != 0) return eekflag; eekflag = LoadBalance(procAssignCoar,vboxCoar); if (eekflag != 0) return eekflag; a_dblFine.define(vboxFine, procAssignFine); a_dblCoar.define(vboxCoar, procAssignCoar); return eekflag; }
void setDefaults( int& nref, Vector<Box>& coarboxes, Vector<Box>& fineboxes, Box& domc, Box& domf) { nref = 2; int nc = 16; int nc16 = nc/2; int nc8 = nc/4; int nc24 = 3*nc/4; int nc12 = 3*nc/8; int nc20 = 5*nc/8; IntVect ivclo = IntVect::Zero; fineboxes.resize(0); IntVect ivchi = (nc-1) * IntVect::Unit; #if (CH_SPACEDIM ==1) fineboxes.resize(3); fineboxes[0].define(IntVect(0), IntVect(nc8-1)); fineboxes[1].define(IntVect(nc12), IntVect(nc20-1)); fineboxes[2].define(IntVect(nc24), ivchi); // this is to prevent unused variable warning in 1d int temp =nc16; nc16 = temp; #else Box boxf1(IntVect(D_DECL6(0 ,nc8,0, 0,0,0)), IntVect(D_DECL6(nc16-1,nc24,nc-1, nc-1,nc-1,nc-1))); Box boxf2(IntVect(D_DECL6(nc16,nc12,0, 0,0,0)), IntVect(D_DECL6(nc24-1,nc20-1,nc-1, nc-1,nc-1,nc-1))); Box boxf3(IntVect(D_DECL6(nc8 ,0 ,0, 0,0,0)), IntVect(D_DECL6(nc20-1,nc8-1,nc-1, nc-1,nc-1,nc-1))); Box boxf4(IntVect(D_DECL6(nc20,nc8,0, 0,0,0)), IntVect(D_DECL6(nc-1,nc12-1,nc-1, nc-1,nc-1,nc-1))); fineboxes.resize(4); fineboxes[0] = boxf1; fineboxes[1] = boxf2; fineboxes[2] = boxf3; fineboxes[3] = boxf4; #endif for (int i=0; i<fineboxes.size(); ++i) { fineboxes[i].refine(nref); } domc = Box(ivclo, ivchi); int ichop = domc.size(0)/2; Box bc1 = domc; Box bc2 = bc1.chop(0, ichop); #if (CH_SPACEDIM > 1) Box bc3 = bc2.chop(1, ichop); coarboxes.push_back(bc3); #endif coarboxes.push_back(bc1); coarboxes.push_back(bc2); domf = refine(domc,nref); }
int ReadDatad(int numdat, double *xin, double *yin, double *zin) { double temp[3], minx, maxx, miny, maxy, xtmp, ytmp, ztmp; double qtxy, qtyx, qtzx, qtzy; int i0, i1, n0; bigtri[0][0] = bigtri[0][1] = bigtri[1][1] = bigtri[2][0] = -1; bigtri[1][0] = bigtri[2][1] = 5; if (rootdat EQ NULL) { rootdat = IMakeDatum(); if (error_status) return (error_status); rootsimp = IMakeSimp(); if (error_status) return (error_status); roottemp = IMakeTemp(); if (error_status) return (error_status); rootneig = IMakeNeig(); if (error_status) return (error_status); rootdat->values[0] = rootdat->values[1] = rootdat->values[2] = 0; } else { FreeVecti(jndx); FreeMatrixd(points); FreeMatrixd(joints); } curdat = rootdat; datcnt = 0; minx = xstart - horilap; maxx = xend + horilap; miny = ystart - vertlap; maxy = yend + vertlap; for (n0 = 0 ; n0 < numdat ; n0++) { temp[0] = xin[n0]; temp[1] = yin[n0]; temp[2] = zin[n0]; if (temp[0] > minx AND temp[0] < maxx AND temp[1] > miny AND temp[1] < maxy) { if (curdat->nextdat EQ NULL) { curdat->nextdat = IMakeDatum(); if (error_status) return (error_status); } curdat = curdat->nextdat; datcnt++; for (i1 = 0; i1 < 3; i1++) curdat->values[i1] = temp[i1]; } } if (datcnt > 3) { datcnt3 = datcnt + 3; jndx = IntVect(datcnt3); if (error_status) return (error_status); sumx = sumy = sumz = sumx2 = sumy2 = sumxy = sumxz = sumyz = 0; iscale = 0; /* * Calculate minimums and maximums of the input data accounting for * the scale factors. * * For the initial calculations, we have: * * maxxy[0][0] = maximum x input data value * maxxy[1][0] = minimum x input data value * maxxy[0][1] = maximum y input data value * maxxy[1][1] = minimum y input data value * maxxy[0][2] = maximum z input data value * maxxy[1][2] = minimum z input data value * */ data_limits: maxxy[0][0] = maxxy[0][1] = maxxy[0][2] = -(maxxy[1][0] = maxxy[1][1] = maxxy[1][2] = BIGNUM); curdat = rootdat->nextdat; for (i0 = 0; i0 < datcnt; i0++) { xtmp = curdat->values[0] * magx; if (maxxy[0][0] < xtmp) maxxy[0][0] = xtmp; if (maxxy[1][0] > xtmp) maxxy[1][0] = xtmp; ytmp = curdat->values[1] * magy; if (maxxy[0][1] < ytmp) maxxy[0][1] = ytmp; if (maxxy[1][1] > ytmp) maxxy[1][1] = ytmp; ztmp = curdat->values[2] * magz; if (maxxy[0][2] < ztmp) maxxy[0][2] = ztmp; if (maxxy[1][2] > ztmp) maxxy[1][2] = ztmp; curdat = curdat->nextdat; } /* * Modify the mins and maxs based on the scale factors and overlap regions. * to get the actual minimums and maximums of the data under consideration. */ if (maxxy[0][0] < maxx * magx) maxxy[0][0] = maxx * magx; if (maxxy[1][0] > minx * magx) maxxy[1][0] = minx * magx; if (maxxy[0][1] < maxy * magy) maxxy[0][1] = maxy * magy; if (maxxy[1][1] > miny * magy) maxxy[1][1] = miny * magy; /* * Calculate the extents in x, y, and z. * * maxxy[0][0] = maximum x extent, including overlap regions. * maxxy[0][1] = maximum y extent, including overlap regions. * maxxy[0][2] = maximum z extent. */ for (i0 = 0 ; i0 < 3 ; i0++) { maxxy[0][i0] -= maxxy[1][i0]; } maxhoriz = maxxy[0][0]; if (maxhoriz < maxxy[0][1]) maxhoriz = maxxy[0][1]; wbit = maxhoriz * EPSILON; /* * Calculate the ratio of the x extent by the y extent (qtxy) and * the y extent by the x extent (qtyx) . */ qtxy = maxxy[0][0] / maxxy[0][1]; qtyx = 1./qtxy; if ( (qtxy > (2.+EPSILON)) OR (qtyx > (2.+EPSILON)) ) { if (auto_scale) { /* * Readjust the scaling and recompute the data limits. */ iscale = 1; if (qtxy > (2+EPSILON) ) { magy *= qtxy; } else { magx *= qtyx; } magx_auto = magx; magy_auto = magy; magz_auto = magz; goto data_limits; } else { /* * Issue a warning and turn off gradient estimation. */ TooNarrow(); } } if (igrad) { qtzx = maxxy[0][2] / maxxy[0][0]; qtzy = maxxy[0][2] / maxxy[0][1]; if ( (qtzx > 60) OR (qtzy > 60) ) { if (auto_scale) { /* * Readjust the scaling and recompute the data limits. The X and Y * scales have been appropriately adjusted by the time you get here, * so dividing magz by either qtzx or qtzy will bring it in line. */ iscale = 1; magz *= 1./qtzx; magx_auto = magx; magy_auto = magy; magz_auto = magz; goto data_limits; } else { /* * Issue a warning and turn off gradient estimation. */ TooSteep(); } } if ( (qtzx < .017) OR (qtzy < .017) ) { if (auto_scale) { /* * Readjust the scaling and recompute the data limits. The X and Y * scales have been appropriately adjusted by the time you get here, * so dividing magz by either qtzx or qtzy will bring it in line. */ iscale = 1; magz *= 1./qtzx; magx_auto = magx; magy_auto = magy; magz_auto = magz; goto data_limits; } else { /* * Issue a warning and turn off gradient estimation. */ TooShallow(); } } } if (igrad) { points = DoubleMatrix(datcnt+4, 6); if (error_status) return (error_status); } else { points = DoubleMatrix(datcnt+4, 3); if (error_status) return (error_status); } joints = DoubleMatrix(datcnt3, 2); if (error_status) return (error_status); curdat = rootdat->nextdat; rootdat->nextdat = NULL; for (i0 = 0; i0 < datcnt; i0++) { sumx += points[i0][0] = curdat->values[0] * magx; sumx2 += SQ(points[i0][0]); sumy += points[i0][1] = curdat->values[1] * magy; sumy2 += SQ(points[i0][1]); sumxy += points[i0][0] * points[i0][1]; if (densi) points[i0][2] = 1; else { sumz += points[i0][2] = curdat->values[2] * magz; sumxz += points[i0][0] * points[i0][2]; sumyz += points[i0][1] * points[i0][2]; } holddat = curdat; curdat = curdat->nextdat; free(holddat); } det = (datcnt * (sumx2 * sumy2 - sumxy * sumxy)) - (sumx * (sumx * sumy2 - sumy * sumxy)) + (sumy * (sumx * sumxy - sumy * sumx2)); aaa = ((sumz * (sumx2 * sumy2 - sumxy * sumxy)) - (sumxz * (sumx * sumy2 - sumy * sumxy)) + (sumyz * (sumx * sumxy - sumy * sumx2))) / det; bbb = ((datcnt * (sumxz * sumy2 - sumyz * sumxy)) - (sumz * (sumx * sumy2 - sumy * sumxy)) + (sumy * (sumx * sumyz - sumy * sumxz))) / det; ccc = ((datcnt * (sumx2 * sumyz - sumxy * sumxz)) - (sumx * (sumx * sumyz - sumy * sumxz)) + (sumz * (sumx * sumxy - sumy * sumx2))) / det; for (i0 = 0 ; i0 < 3 ; i0++) { points[datcnt+i0][0] = maxxy[1][0] + bigtri[i0][0] * maxxy[0][0] * RANGE; points[datcnt+i0][1] = maxxy[1][1] + bigtri[i0][1] * maxxy[0][1] * RANGE; if (densi) points[datcnt+i0][2] = 1; else points[datcnt+i0][2] = aaa + bbb * points[datcnt+i0][0] + ccc * points[datcnt+i0][1]; } rootdat = NULL; } else { ErrorHnd(1, "ReadData", filee, "\n"); error_status = 1; return (error_status); } /* * Determine if any input data coordinates are duplicated. */ if (nndup == 1) { for (i0 = 0 ; i0 < datcnt ; i0++) { for (i1 = i0+1 ; i1 < datcnt ; i1++) { if ( (points[i0][0] == points[i1][0]) && (points[i0][1] == points[i1][1]) ) { sprintf(emsg,"\n Coordinates %d and %d are identical.\n",i0,i1); ErrorHnd(2, "ReadData", filee, emsg); error_status = 2; return (error_status); } } } } /* * Introduce a small random perturbation into the coordinate values. */ srand(367); for (i0 = 0 ; i0 < datcnt ; i0++) { for (i1 = 0 ; i1 < 2 ; i1++) { points[i0][i1] += wbit * (0.5 - (double)rand() / RAND_MAX); } } if (sdip OR igrad) { piby2 = 2 * atan(1.0); nn_pi = piby2 * 2; piby32 = 3 * piby2; rad2deg = 90 / piby2; } return (0); }
int test() { #ifdef CH_USE_HDF5 int error; HDF5Handle testFile; CH_assert(!testFile.isOpen()); error = testFile.open("data.h5", HDF5Handle::CREATE); if (error != 0) { if ( verbose ) pout() << indent2 << "File creation failed "<<error<<endl; return error; } CH_assert(testFile.isOpen()); Box domain(IntVect::Zero, 20*IntVect::Unit); DisjointBoxLayout plan1, plan2; { IntVectSet tags; IntVect center = 10*IntVect::Unit; setCircleTags(tags, 6, 1, center); //circle/sphere buildDisjointBoxLayout(plan1, tags, domain); tags.makeEmpty(); setCircleTags(tags, 5, 2, center); buildDisjointBoxLayout(plan2, tags, domain); } if ( verbose ) { pout() << "plan1: " << procID() << "...." << plan1 << endl; pout() << "plan2: " << procID() << "...." << plan2 << endl; } //test LayoutData<Real> specialization LayoutData<Real> specialReal(plan1); LayoutData<Moment> vlPlan(plan1); LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit); LevelData<BaseFab<int> > level2; level2.define(level1); level2.define(plan2, 1); for (DataIterator i(level2.dataIterator()); i.ok(); ++i) { level2[i()].setVal(2); } level1.apply(values::setVal1); level2.apply(values::setVal2); HDF5HeaderData set1; Real dx=0.004; Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4))); Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4))); int currentStep = 2332; set1.m_string["name"] = "set1"; set1.m_real["dx"] = dx; set1.m_int["currentStep"] = currentStep; set1.m_intvect["some intvect or other"] = b1.smallEnd(); set1.m_box["b1"] = b1; set1.m_box["b2"] = b2; testFile.setGroupToLevel(1); error = write(testFile, plan1); if (error != 0) { if ( verbose ) pout() << indent2 << "box write failed "<<error<<endl; return error; } error = write(testFile, level1, "level1 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } error = write(testFile, level2, "level2 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } LevelData<FArrayBox> state(plan2, 3); state.apply(values::setVal3); testFile.setGroupToLevel(0); set1.writeToFile(testFile); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } testFile.setGroup("/"); error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } set1.writeToFile(testFile); set1.writeToFile(testFile); testFile.close(); CH_assert(!testFile.isOpen()); // test the utility functions ReadUGHDF5 and WriteUGHDF5 WriteUGHDF5("UGIO.hdf5", plan2, state, domain); ReadUGHDF5("UGIO.hdf5", plan2, state, domain); //======================================================================== // // now, read this data back in // //======================================================================== BoxLayoutData<BaseFab<int> > readlevel1, readlevel2; error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY); if (error != 0) { if ( verbose ) pout() << indent2 << "File open failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); Vector<Box> boxes; error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } boxes.sort(); Vector<int> assign; error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan2(boxes, assign); readplan2.close(); error = read(testFile, readlevel2, "level2 state vector", readplan2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } testFile.setGroupToLevel(1); error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan1(boxes, assign); readplan1.close(); if ( verbose ) { pout() << "readplan1: " << procID() << "...." << readplan1 << endl; pout() << "readplan2: " << procID() << "...." << readplan2 << endl; } error = read(testFile, readlevel1, "level1 state vector", readplan1); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } if ( verbose ) pout() << plan1<<readplan1<<endl; // real test of IO, make sure the data is the same coming and going DataIterator l1 = level1.dataIterator(); DataIterator rl1 = readlevel1.dataIterator(); DataIterator l2 = level2.dataIterator(); DataIterator rl2 = readlevel2.dataIterator(); if (level1.boxLayout().size() != readlevel1.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl; return 1; } if (level2.boxLayout().size() != readlevel2.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl; return 1; } // we can assume that BoxLayout IO is tested in HDF5boxIO BaseFab<int>* before, *after; for (; l1.ok(); ++l1, ++rl1) { before = &(level1[l1()]); after = &(readlevel1[rl1()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level1.box(l1())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "l1 != readl1 read failed "<<error<<endl; return 2; } } } } for (; l2.ok(); ++l2, ++rl2) { before = &(level2[l2()]); after = &(readlevel2[rl2()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level2.box(l2())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl; return 3; } } } } LevelData<FArrayBox> readState; Real dt, time; int refRatio; testFile.setGroup("/"); error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio); if (error != 0) { if ( verbose ) pout() << indent2 << "readLevel failed "<<error<<endl; return error; } #ifndef CH_MPI // OK, now try to read one FArrayBox at a time // problem with DataIterator and running the out-of-core in parallel, so // have to think about that for now BVS. FArrayBox readFAB; Interval interval(1,2); testFile.setGroup("/"); int index=0; for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit) { FArrayBox& fab = state[dit()]; readFArrayBox(testFile, readFAB, 0, index, interval); for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it) { if (readFAB(it(), 0) != fab(it(), 1)) { if ( verbose ) pout() << indent2 << "state != after for out-of-core "<<error<<endl; return 3; } } } #endif testFile.close(); CH_assert(!testFile.isOpen()); #endif // CH_USE_HDF5 return 0; }
int main (int argc, char* argv[]) { BoxLib::Initialize(argc,argv); std::cout << std::setprecision(10); if (argc < 2) { std::cerr << "usage: " << argv[0] << " inputsfile [options]" << '\n'; exit(-1); } ParmParse pp; int n; BoxArray bs; #if BL_SPACEDIM == 2 Box domain(IntVect(0,0),IntVect(11,11)); std::string boxfile("gr.2_small_a") ; #elif BL_SPACEDIM == 3 Box domain(IntVect(0,0,0),IntVect(11,11,11)); std::string boxfile("grids/gr.3_2x3x4") ; #endif pp.query("boxes", boxfile); std::ifstream ifs(boxfile.c_str(), std::ios::in); if (!ifs) { std::string msg = "problem opening grids file: "; msg += boxfile.c_str(); BoxLib::Abort(msg.c_str()); } ifs >> domain; if (ParallelDescriptor::IOProcessor()) std::cout << "domain: " << domain << std::endl; bs.readFrom(ifs); if (ParallelDescriptor::IOProcessor()) std::cout << "grids:\n" << bs << std::endl; Geometry geom(domain); const Real* H = geom.CellSize(); int ratio=2; pp.query("ratio", ratio); // allocate/init soln and rhs int Ncomp=BL_SPACEDIM; int Nghost=0; int Ngrids=bs.size(); MultiFab soln(bs, Ncomp, Nghost, Fab_allocate); soln.setVal(0.0); MultiFab out(bs, Ncomp, Nghost, Fab_allocate); MultiFab rhs(bs, Ncomp, Nghost, Fab_allocate); rhs.setVal(0.0); for(MFIter rhsmfi(rhs); rhsmfi.isValid(); ++rhsmfi) { FORT_FILLRHS(rhs[rhsmfi].dataPtr(), ARLIM(rhs[rhsmfi].loVect()),ARLIM(rhs[rhsmfi].hiVect()), H,&Ncomp); } // Create the boundary object MCViscBndry vbd(bs,geom); BCRec phys_bc; Array<int> lo_bc(BL_SPACEDIM), hi_bc(BL_SPACEDIM); pp.getarr("lo_bc",lo_bc,0,BL_SPACEDIM); pp.getarr("hi_bc",hi_bc,0,BL_SPACEDIM); for (int i = 0; i < BL_SPACEDIM; i++) { phys_bc.setLo(i,lo_bc[i]); phys_bc.setHi(i,hi_bc[i]); } // Create the BCRec's interpreted by ViscBndry objects #if BL_SPACEDIM==2 Array<BCRec> pbcarray(4); pbcarray[0] = BCRec(D_DECL(REFLECT_ODD,REFLECT_EVEN,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[1] = BCRec(D_DECL(REFLECT_EVEN,REFLECT_ODD,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[2] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[3] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); #elif BL_SPACEDIM==3 Array<BCRec> pbcarray(12); #if 1 pbcarray[0] = BCRec(EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR); pbcarray[1] = BCRec(EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR); pbcarray[2] = BCRec(EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR,EXT_DIR); pbcarray[3] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[4] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[5] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[6] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[7] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[8] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[9] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[10] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); pbcarray[11] = BCRec(D_DECL(EXT_DIR,EXT_DIR,EXT_DIR), D_DECL(EXT_DIR,EXT_DIR,EXT_DIR)); #else for (int i = 0; i < 12; i++) pbcarray[i] = phys_bc; #endif #endif Nghost = 1; // need space for bc info MultiFab fine(bs,Ncomp,Nghost,Fab_allocate); for(MFIter finemfi(fine); finemfi.isValid(); ++finemfi) { FORT_FILLFINE(fine[finemfi].dataPtr(), ARLIM(fine[finemfi].loVect()),ARLIM(fine[finemfi].hiVect()), H,&Ncomp); } // Create "background coarse data" Box crse_bx = Box(domain).coarsen(ratio).grow(1); BoxArray cba(crse_bx); cba.maxSize(32); Real h_crse[BL_SPACEDIM]; for (n=0; n<BL_SPACEDIM; n++) h_crse[n] = H[n]*ratio; MultiFab crse_mf(cba, Ncomp, 0); // FArrayBox crse_fab(crse_bx,Ncomp); for (MFIter mfi(crse_mf); mfi.isValid(); ++mfi) { FORT_FILLCRSE(crse_mf[mfi].dataPtr(), ARLIM(crse_mf[mfi].loVect()),ARLIM(crse_mf[mfi].hiVect()), h_crse,&Ncomp); } // Create coarse boundary register, fill w/data from coarse FAB int bndry_InRad=0; int bndry_OutRad=1; int bndry_Extent=1; BoxArray cbs = BoxArray(bs).coarsen(ratio); BndryRegister cbr(cbs,bndry_InRad,bndry_OutRad,bndry_Extent,Ncomp); for (OrientationIter face; face; ++face) { Orientation f = face(); FabSet& bnd_fs(cbr[f]); bnd_fs.copyFrom(crse_mf, 0, 0, 0, Ncomp); } // Interpolate crse data to fine boundary, where applicable int cbr_Nstart=0; int fine_Nstart=0; int bndry_Nstart=0; vbd.setBndryValues(cbr,cbr_Nstart,fine,fine_Nstart, bndry_Nstart,Ncomp,ratio,pbcarray); Nghost = 1; // other variables don't need extra space DivVis lp(vbd,H); Real a = 0.0; Real b[BL_SPACEDIM]; b[0] = 1.0; b[1] = 1.0; #if BL_SPACEDIM>2 b[2] = 1.0; #endif MultiFab acoefs; int NcompA = (BL_SPACEDIM == 2 ? 2 : 1); acoefs.define(bs, NcompA, Nghost, Fab_allocate); acoefs.setVal(a); MultiFab bcoefs[BL_SPACEDIM]; for (n=0; n<BL_SPACEDIM; ++n) { BoxArray bsC(bs); bcoefs[n].define(bsC.surroundingNodes(n), 1, Nghost, Fab_allocate); #if 1 for(MFIter bmfi(bcoefs[n]); bmfi.isValid(); ++bmfi) { FORT_MAKEMU(bcoefs[n][bmfi].dataPtr(), ARLIM(bcoefs[n][bmfi].loVect()),ARLIM(bcoefs[n][bmfi].hiVect()),H,n); } #else bcoefs[n].setVal(b[n]); #endif } // -->> over dimension lp.setCoefficients(acoefs, bcoefs); #if 1 lp.maxOrder(4); #endif Nghost = 1; MultiFab tsoln(bs, Ncomp, Nghost, Fab_allocate); tsoln.setVal(0.0); #if 1 tsoln.copy(fine); #endif #if 0 // testing apply lp.apply(out,tsoln); Box subbox = out[0].box(); Real n1 = out[0].norm(subbox,1,0,BL_SPACEDIM)*pow(H[0],BL_SPACEDIM); ParallelDescriptor::ReduceRealSum(n1); if (ParallelDescriptor::IOProcessor()) { cout << "n1 output is "<<n1<<std::endl; } out.minus(rhs,0,BL_SPACEDIM,0); // special to single grid prob Real n2 = out[0].norm(subbox,1,0,BL_SPACEDIM)*pow(H[0],BL_SPACEDIM); ParallelDescriptor::ReduceRealSum(n2); if (ParallelDescriptor::IOProcessor()) { cout << "n2 difference is "<<n2<<std::endl; } #if 0 subbox.grow(-1); Real n3 = out[0].norm(subbox,0,0,BL_SPACEDIM)*pow(H[0],BL_SPACEDIM); ParallelDescriptor::ReduceRealMax(n3); if (ParallelDescriptor::IOProcessor()) { cout << "n3 difference is "<<n3<<std::endl; } #endif #endif const IntVect refRatio(D_DECL(2,2,2)); const Real bgVal = 1.0; #if 1 #ifndef NDEBUG // testing flux computation BoxArray xfluxbox(bs); xfluxbox.surroundingNodes(0); MultiFab xflux(xfluxbox,Ncomp,Nghost,Fab_allocate); xflux.setVal(1.e30); BoxArray yfluxbox(bs); yfluxbox.surroundingNodes(1); MultiFab yflux(yfluxbox,Ncomp,Nghost,Fab_allocate); yflux.setVal(1.e30); #if BL_SPACEDIM>2 BoxArray zfluxbox(bs); zfluxbox.surroundingNodes(2); MultiFab zflux(zfluxbox,Ncomp,Nghost,Fab_allocate); zflux.setVal(1.e30); #endif lp.compFlux(xflux, yflux, #if BL_SPACEDIM>2 zflux, #endif tsoln); // Write fluxes //writeMF(&xflux,"xflux.mfab"); //writeMF(&yflux,"yflux.mfab"); #if BL_SPACEDIM>2 //writeMF(&zflux,"zflux.mfab"); #endif #endif #endif Real tolerance = 1.0e-10; pp.query("tol", tolerance); Real tolerance_abs = 1.0e-10; pp.query("tol_abs", tolerance_abs); #if 0 cout << "Bndry Data object:" << std::endl; cout << lp.bndryData() << std::endl; #endif #if 0 bool use_mg_pre = false; MCCGSolver cg(lp,use_mg_pre); cg.solve(soln,rhs,tolerance,tolerance_abs); #else MCMultiGrid mg(lp); mg.solve(soln,rhs,tolerance,tolerance_abs); #endif #if 0 cout << "MCLinOp object:" << std::endl; cout << lp << std::endl; #endif VisMF::Write(soln,"soln"); #if 0 // apply operator to soln to see if really satisfies eqn tsoln.copy(soln); lp.apply(out,tsoln); soln.copy(out); // Output "apply" results on soln VisMF::Write(soln,"apply"); // Compute truncation for (MFIter smfi(soln); smfi.isValid(); ++smfi) { soln[smfi] -= fine[smfi]; } for( int icomp=0; icomp < BL_SPACEDIM ; icomp++ ) { Real solnMin = soln.min(icomp); Real solnMax = soln.max(icomp); ParallelDescriptor::ReduceRealMin(solnMin); ParallelDescriptor::ReduceRealMax(solnMax); if (ParallelDescriptor::IOProcessor()) { cout << icomp << " "<<solnMin << " " << solnMax <<std::endl; } } // Output truncation VisMF::Write(soln,"trunc"); #endif int dumpLp=0; pp.query("dumpLp",dumpLp); bool write_lp = (dumpLp == 1 ? true : false); if (write_lp) std::cout << lp << std::endl; // Output trunc ParallelDescriptor::EndParallel(); }
void fi_new_multifab (MultiFab*& mf, BoxArray*& bao, const BoxArray* bai, int nc, int ng, const int* nodal) { mf = new MultiFab(*bai, nc, ng, Fab_allocate, IntVect(nodal)); bao = (BoxArray*)&(mf->boxArray()); }
const IntVect BoxLib::diagShift (const IntVect& p, int s) { return IntVect(D_DECL(p[0] + s, p[1] + s, p[2] + s)); }
const IntVect BoxLib::scale (const IntVect& p, int s) { return IntVect(D_DECL(s * p[0], s * p[1], s * p[2])); }
int main(int argc, char* argv[]) { BoxLib::Initialize(argc,argv); BL_PROFILE_VAR("main()", pmain); std::cout << std::setprecision(15); solver_type = BoxLib_C; bc_type = Periodic; Real a = 0.0; Real b = 1.0; // ---- First use the number of processors to decide how many grids you have. // ---- We arbitrarily decide to have one grid per MPI process in a uniform // ---- cubic domain, so we require that the number of processors be N^3. // ---- This requirement is somewhat arbitrary, but convenient for now. int nprocs = ParallelDescriptor::NProcs(); // N is the cube root of the number of processors int N(0); for(int i(1); i*i*i <= nprocs; ++i) { if(i*i*i == nprocs) { N = i; } } if(N == 0) { // not a cube if(ParallelDescriptor::IOProcessor()) { std::cerr << "**** Error: nprocs = " << nprocs << " is not currently supported." << std::endl; } BoxLib::Error("We require that the number of processors be a perfect cube"); } if(ParallelDescriptor::IOProcessor()) { std::cout << "N = " << N << std::endl; } // ---- make a box, then a boxarray with maxSize int domain_hi = (N*maxGrid) - 1; Box domain(IntVect(0,0,0), IntVect(domain_hi,domain_hi,domain_hi)); BoxArray bs(domain); bs.maxSize(maxGrid); // This defines the physical size of the box. Right now the box is [0,1] in each direction. RealBox real_box; for (int n = 0; n < BL_SPACEDIM; n++) { real_box.setLo(n, 0.0); real_box.setHi(n, 1.0); } // This says we are using Cartesian coordinates int coord = 0; // This sets the boundary conditions to be periodic or not int is_per[BL_SPACEDIM]; if (bc_type == Dirichlet || bc_type == Neumann) { for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 0; } else { for (int n = 0; n < BL_SPACEDIM; n++) is_per[n] = 1; } // This defines a Geometry object which is useful for writing the plotfiles Geometry geom(domain,&real_box,coord,is_per); for ( int n=0; n<BL_SPACEDIM; n++ ) { dx[n] = ( geom.ProbHi(n) - geom.ProbLo(n) )/domain.length(n); } if (ParallelDescriptor::IOProcessor()) { std::cout << "Domain size : " << N << std::endl; std::cout << "Max_grid_size : " << maxGrid << std::endl; std::cout << "Number of grids : " << bs.size() << std::endl; } // Allocate and define the right hand side. MultiFab rhs(bs, Ncomp, 0, Fab_allocate); setup_rhs(rhs, geom, a, b); MultiFab alpha(bs, Ncomp, 0, Fab_allocate); MultiFab beta[BL_SPACEDIM]; for ( int n=0; n<BL_SPACEDIM; ++n ) { BoxArray bx(bs); beta[n].define(bx.surroundingNodes(n), Ncomp, 1, Fab_allocate); } setup_coeffs(bs, alpha, beta, geom); MultiFab anaSoln; if (comp_norm) { anaSoln.define(bs, Ncomp, 0, Fab_allocate); compute_analyticSolution(anaSoln); } // Allocate the solution array // Set the number of ghost cells in the solution array. MultiFab soln(bs, Ncomp, 1, Fab_allocate); solve(soln, anaSoln, a, b, alpha, beta, rhs, bs, geom, BoxLib_C); BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); }
Box& Box::refine (int ref_ratio) { return this->refine(IntVect(D_DECL(ref_ratio,ref_ratio,ref_ratio))); }
void main_main () { // What time is it now? We'll use this to compute total run time. Real strt_time = ParallelDescriptor::second(); std::cout << std::setprecision(15); int n_cell, max_grid_size, nsteps, plot_int, is_periodic[BL_SPACEDIM]; // Boundary conditions Array<int> lo_bc(BL_SPACEDIM), hi_bc(BL_SPACEDIM); // inputs parameters { // ParmParse is way of reading inputs from the inputs file ParmParse pp; // We need to get n_cell from the inputs file - this is the number of cells on each side of // a square (or cubic) domain. pp.get("n_cell",n_cell); // Default nsteps to 0, allow us to set it to something else in the inputs file pp.get("max_grid_size",max_grid_size); // Default plot_int to 1, allow us to set it to something else in the inputs file // If plot_int < 0 then no plot files will be written plot_int = 1; pp.query("plot_int",plot_int); // Default nsteps to 0, allow us to set it to something else in the inputs file nsteps = 0; pp.query("nsteps",nsteps); // Boundary conditions - default is periodic (INT_DIR) for (int i = 0; i < BL_SPACEDIM; ++i) { lo_bc[i] = hi_bc[i] = INT_DIR; // periodic boundaries are interior boundaries } pp.queryarr("lo_bc",lo_bc,0,BL_SPACEDIM); pp.queryarr("hi_bc",hi_bc,0,BL_SPACEDIM); } // make BoxArray and Geometry BoxArray ba; Geometry geom; { IntVect dom_lo(IntVect(D_DECL(0,0,0))); IntVect dom_hi(IntVect(D_DECL(n_cell-1, n_cell-1, n_cell-1))); Box domain(dom_lo, dom_hi); // Initialize the boxarray "ba" from the single box "bx" ba.define(domain); // Break up boxarray "ba" into chunks no larger than "max_grid_size" along a direction ba.maxSize(max_grid_size); // This defines the physical size of the box. Right now the box is [-1,1] in each direction. RealBox real_box; for (int n = 0; n < BL_SPACEDIM; n++) { real_box.setLo(n,-1.0); real_box.setHi(n, 1.0); } // This says we are using Cartesian coordinates int coord = 0; // This sets the boundary conditions to be doubly or triply periodic int is_periodic[BL_SPACEDIM]; for (int i = 0; i < BL_SPACEDIM; i++) { is_periodic[i] = 0; if (lo_bc[i] == 0 && hi_bc[i] == 0) { is_periodic[i] = 1; } } // This defines a Geometry object geom.define(domain,&real_box,coord,is_periodic); } // Boundary conditions PhysBCFunct physbcf; BCRec bcr(&lo_bc[0], &hi_bc[0]); physbcf.define(geom, bcr, BndryFunctBase(phifill)); // phifill is a fortran function // define dx[] const Real* dx = geom.CellSize(); // Nghost = number of ghost cells for each array int Nghost = 1; // Ncomp = number of components for each array int Ncomp = 1; // time = starting time in the simulation Real time = 0.0; // we allocate two phi multifabs; one will store the old state, the other the new // we swap the indices each time step to avoid copies of new into old PArray<MultiFab> phi(2, PArrayManage); phi.set(0, new MultiFab(ba, Ncomp, Nghost)); phi.set(1, new MultiFab(ba, Ncomp, Nghost)); // Initialize both to zero (just because) phi[0].setVal(0.0); phi[1].setVal(0.0); // Initialize phi[init_index] by calling a Fortran routine. // MFIter = MultiFab Iterator int init_index = 0; for ( MFIter mfi(phi[init_index]); mfi.isValid(); ++mfi ) { const Box& bx = mfi.validbox(); init_phi(phi[init_index][mfi].dataPtr(), bx.loVect(), bx.hiVect(), &Nghost, geom.CellSize(), geom.ProbLo(), geom.ProbHi()); } // compute the time step Real dt = 0.9*dx[0]*dx[0] / (2.0*BL_SPACEDIM); // Write a plotfile of the initial data if plot_int > 0 (plot_int was defined in the inputs file) if (plot_int > 0) { int n = 0; const std::string& pltfile = BoxLib::Concatenate("plt",n,5); writePlotFile(pltfile, phi[init_index], geom, time); } // build the flux multifabs PArray<MultiFab> flux(BL_SPACEDIM, PArrayManage); for (int dir = 0; dir < BL_SPACEDIM; dir++) { // flux(dir) has one component, zero ghost cells, and is nodal in direction dir BoxArray edge_ba = ba; edge_ba.surroundingNodes(dir); flux.set(dir, new MultiFab(edge_ba, 1, 0)); } int old_index = init_index; for (int n = 1; n <= nsteps; n++, old_index = 1 - old_index) { int new_index = 1 - old_index; // new_phi = old_phi + dt * (something) advance(phi[old_index], phi[new_index], flux, time, dt, geom, physbcf, bcr); time = time + dt; // Tell the I/O Processor to write out which step we're doing if (ParallelDescriptor::IOProcessor()) std::cout << "Advanced step " << n << std::endl; // Write a plotfile of the current data (plot_int was defined in the inputs file) if (plot_int > 0 && n%plot_int == 0) { const std::string& pltfile = BoxLib::Concatenate("plt",n,5); writePlotFile(pltfile, phi[new_index], geom, time); } } // Call the timer again and compute the maximum difference between the start time and stop time // over all processors Real stop_time = ParallelDescriptor::second() - strt_time; const int IOProc = ParallelDescriptor::IOProcessorNumber(); ParallelDescriptor::ReduceRealMax(stop_time,IOProc); // Tell the I/O Processor to write out the "run time" if (ParallelDescriptor::IOProcessor()) { std::cout << "Run time = " << stop_time << std::endl; } }
Box& Box::coarsen (int ref_ratio) { return this->coarsen(IntVect(D_DECL(ref_ratio,ref_ratio,ref_ratio))); }
IntVect& IntVect::coarsen (int s) { BL_ASSERT(s > 0); return this->coarsen(IntVect(D_DECL(s,s,s))); }
int makeLayout(DisjointBoxLayout& a_dbl, const Box& a_domainFine) { //set up mesh refine object ParmParse pp; int eekflag= 0; int maxsize; pp.get("maxboxsize",maxsize); int bufferSize = 1; int blockFactor = 2; Real fillrat = 0.75; Box domainCoar = coarsen(a_domainFine, 2); Vector<int> refRat(2,2); BRMeshRefine meshRefObj(domainCoar, refRat, fillrat, blockFactor, bufferSize, maxsize); Vector<Vector<Box> > oldMeshes(2); oldMeshes[0] = Vector<Box>(1, domainCoar); oldMeshes[1] = Vector<Box>(1, a_domainFine); //set up coarse tags int nc = domainCoar.size(0); int nmi = nc/2;//16 int nqu = nc/4;//8 int ntf = (nc*3)/4; //24 int nte = (nc*3)/8; //12 int nfe = (nc*5)/8; //20 #if (CH_SPACEDIM ==2) Box boxf1(IntVect(0, nqu), IntVect(nmi-1,ntf-1)); Box boxf2(IntVect(nmi,nte), IntVect(ntf-1,nfe-1)); Box boxf3(IntVect(nqu,0 ), IntVect(nfe-1,nqu-1)); Box boxf4(IntVect(nfe,nqu), IntVect(nc -1,nte-1)); #else Box boxf1(IntVect(0, nqu,nqu), IntVect(nmi-1,ntf-1,ntf-1)); Box boxf2(IntVect(nmi,nte,nte), IntVect(ntf-1,nfe-1,nfe-1)); Box boxf3(IntVect(nqu,0,0 ), IntVect(nfe-1,nqu-1,nqu-1)); Box boxf4(IntVect(nfe,nqu,nqu), IntVect(nc -1,nte-1,nte-1)); #endif IntVectSet tags; tags |= boxf1; tags |= boxf2; tags |= boxf3; tags |= boxf4; int baseLevel = 0; int topLevel = 0; Vector<Vector<Box> > newMeshes; meshRefObj.regrid(newMeshes, tags, baseLevel, topLevel, oldMeshes); const Vector<Box>& vbox = newMeshes[1]; Vector<int> procAssign; eekflag = LoadBalance(procAssign,vbox); if (eekflag != 0) return eekflag; a_dbl.define(vbox, procAssign); return eekflag; }
int main (int argc, char** argv) { BoxLib::Initialize(argc, argv); BL_PROFILE_VAR("main()", pmain); Array<DistributionMapping::Strategy> dmStrategies(nStrategies); dmStrategies[0] = DistributionMapping::ROUNDROBIN; dmStrategies[1] = DistributionMapping::KNAPSACK; dmStrategies[2] = DistributionMapping::SFC; dmStrategies[3] = DistributionMapping::PFC; Array<std::string> dmSNames(nStrategies); dmSNames[0] = "ROUNDROBIN"; dmSNames[1] = "KNAPSACK"; dmSNames[2] = "SFC"; dmSNames[3] = "PFC"; Array<double> dmSTimes(nStrategies, 0.0); for(int iS(0); iS < nStrategies * nTimes; ++iS) { int whichStrategy(iS % nStrategies); DistributionMapping::strategy(dmStrategies[whichStrategy]); // Box bx(IntVect(0,0,0),IntVect(511,511,255)); // Box bx(IntVect(0,0,0),IntVect(1023,1023,255)); Box bx(IntVect(0,0,0),IntVect(1023,1023,1023)); // Box bx(IntVect(0,0,0),IntVect(2047,2047,1023)); // Box bx(IntVect(0,0,0),IntVect(127,127,127)); // Box bx(IntVect(0,0,0),IntVect(255,255,255)); BoxArray ba(bx); ba.maxSize(64); const int N = 2000; // This should be divisible by 4 !!! if (ParallelDescriptor::IOProcessor() && iS == 0) { std::cout << "Domain: " << bx << " # boxes in BoxArray: " << ba.size() << '\n'; } if (ParallelDescriptor::IOProcessor()) std::cout << "Strategy: " << dmSNames[DistributionMapping::strategy()] << '\n'; ParallelDescriptor::Barrier(); { // // A test of FillBoundary() on 1 grow cell with cross stencil. // MultiFab mf(ba,1,1); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N; i++) mf.FillBoundary(true); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << N << " cross x 1: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // A test of FillBoundary() on 1 grow cell with dense stencil. // MultiFab mf(ba,1,1); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << N << " dense x 1: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // First a test of FillBoundary() on 2 grow cells with dense stencil. // MultiFab mf(ba,1,2); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N/2; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << (N/2) << " dense x 2: " << end << std::endl; dmSTimes[whichStrategy] += end; } } { // // First a test of FillBoundary() on 4 grow cells with dense stencil. // MultiFab mf(ba,1,4); mf.setVal(1.23); ParallelDescriptor::Barrier(); double beg = ParallelDescriptor::second(); for (int i = 0; i < N/4; i++) mf.FillBoundary(false); double end = (ParallelDescriptor::second() - beg); ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << (N/4) << " dense x 4: " << end << std::endl; dmSTimes[whichStrategy] += end; } } if (ParallelDescriptor::IOProcessor()) std::cout << std::endl; } // end for iS if(ParallelDescriptor::IOProcessor()) { for(int i(0); i < nStrategies; ++i) { std::cout << std::endl << "Total times:" << std::endl; std::cout << dmSNames[i] << " time = " << dmSTimes[i] << std::endl; } std::cout << std::endl << std::endl; } BL_PROFILE_VAR_STOP(pmain); BoxLib::Finalize(); return 0; }