void BaseFab<Real>::performSetVal (Real val, const Box& bx, int comp, int ncomp) { BL_ASSERT(domain.contains(bx)); BL_ASSERT(comp >= 0 && comp + ncomp <= nvar); Real* data = dataPtr(comp); if (bx == domain) { for (long i = 0, N = ncomp*numpts; i < N; i++) { *data++ = val; } } else { const int* _box_lo = bx.loVect(); const int* _box_hi = bx.hiVect(); const int* _th_plo = loVect(); const int* _th_phi = hiVect(); FORT_FASTSETVAL(&val, _box_lo, _box_hi, data, ARLIM(_th_plo), ARLIM(_th_phi), &ncomp); } }
void average_face_to_cellcenter (MultiFab& cc, const PArray<MultiFab>& fc, const Geometry& geom) { BL_ASSERT(cc.nComp() >= BL_SPACEDIM); BL_ASSERT(fc.size() == BL_SPACEDIM); BL_ASSERT(fc[0].nComp() == 1); // We only expect fc to have the gradient perpendicular to the face const Real* dx = geom.CellSize(); const Real* problo = geom.ProbLo(); int coord_type = Geometry::Coord(); #ifdef _OPENMP #pragma omp parallel #endif for (MFIter mfi(cc,true); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); BL_FORT_PROC_CALL(BL_AVG_FC_TO_CC,bl_avg_fc_to_cc) (bx.loVect(), bx.hiVect(), BL_TO_FORTRAN(cc[mfi]), D_DECL(BL_TO_FORTRAN(fc[0][mfi]), BL_TO_FORTRAN(fc[1][mfi]), BL_TO_FORTRAN(fc[2][mfi])), dx, problo, coord_type); } }
Real FMultiGrid::solve (PArray<MultiFab>& phi, PArray<MultiFab>& rhs, Real rel_tol, Real abs_tol, int always_use_bnorm , int need_grad_phi, int verbose) { BL_ASSERT( m_bc.initilized || m_bndry != 0); BL_ASSERT(!(m_bc.initilized && m_bndry != 0)); BL_ASSERT(m_coeff.eq_type != invalid_eq); BL_ASSERT(m_mgt_solver == 0); MultiFab* phi_p[m_nlevels]; MultiFab* rhs_p[m_nlevels]; for (int ilev=0; ilev < m_nlevels; ++ilev) { phi_p[ilev] = &phi[ilev]; rhs_p[ilev] = &rhs[ilev]; } init_mgt_solver(phi); Real final_resnorm; m_mgt_solver->solve(phi_p, rhs_p, *m_bndry, rel_tol, abs_tol, always_use_bnorm, final_resnorm, need_grad_phi); return final_resnorm; }
void BaseFab<Real>::copyToMem (const Box& srcbox, int srccomp, int numcomp, Real* dst) const { BL_ASSERT(box().contains(srcbox)); BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= nComp()); if (srcbox.ok()) { const Real* data = dataPtr(srccomp); const int* _box_lo = srcbox.loVect(); const int* _box_hi = srcbox.hiVect(); const int* _th_plo = loVect(); const int* _th_phi = hiVect(); FORT_FASTCOPYTOMEM(_box_lo, _box_hi, data, ARLIM(_th_plo), ARLIM(_th_phi), &numcomp, dst); } }
Real BaseFab<Real>::sum (const Box& bx, int comp, int ncomp) const { BL_ASSERT(domain.contains(bx)); BL_ASSERT(comp >= 0 && comp + ncomp <= nvar); const int* _box_lo = bx.loVect(); const int* _box_hi = bx.hiVect(); const int* _datalo = loVect(); const int* _datahi = hiVect(); const Real* _data = dataPtr(comp); Real sm = 0; FORT_FASTSUM(_data, ARLIM(_datalo), ARLIM(_datahi), _box_lo, _box_hi, &ncomp, &sm); return sm; }
void BaseFab<Real>::copyFromMem (const Box& dstbox, int dstcomp, int numcomp, const Real* src) { BL_ASSERT(box().contains(dstbox)); BL_ASSERT(dstcomp >= 0 && dstcomp+numcomp <= nComp()); if (dstbox.ok()) { Real* data = dataPtr(dstcomp); const int* _box_lo = dstbox.loVect(); const int* _box_hi = dstbox.hiVect(); const int* _th_plo = loVect(); const int* _th_phi = hiVect(); FORT_FASTCOPYFROMMEM(_box_lo, _box_hi, data, ARLIM(_th_plo), ARLIM(_th_phi), &numcomp, src); } }
void BoxList::catenate (BoxList& blist) { BL_ASSERT(ixType() == blist.ixType()); lbox.splice(lbox.end(), blist.lbox); BL_ASSERT(blist.isEmpty()); }
Box Box::chop (int dir, int chop_pnt) { // // Define new high end Box including chop_pnt. // IntVect sm(smallend); IntVect bg(bigend); sm.setVal(dir,chop_pnt); if (btype[dir]) { // // NODE centered Box. // BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt < bigend[dir]); // // Shrink original Box to just contain chop_pnt. // bigend.setVal(dir,chop_pnt); } else { // // CELL centered Box. // BL_ASSERT(chop_pnt > smallend[dir] && chop_pnt <= bigend[dir]); // // Shrink origional Box to one below chop_pnt. // bigend.setVal(dir,chop_pnt-1); } return Box(sm,bg,btype); }
void average_face_to_cellcenter (MultiFab& cc, int dcomp, const std::vector<MultiFab*>& fc) { BL_ASSERT(cc.nComp() >= dcomp + BL_SPACEDIM); BL_ASSERT(fc.size() == BL_SPACEDIM); BL_ASSERT(fc[0]->nComp() == 1); Real dx[3] = {1.0,1.0,1.0}; Real problo[3] = {0.,0.,0.}; int coord_type = 0; #ifdef _OPENMP #pragma omp parallel #endif for (MFIter mfi(cc,true); mfi.isValid(); ++mfi) { const Box& bx = mfi.tilebox(); BL_FORT_PROC_CALL(BL_AVG_FC_TO_CC,bl_avg_fc_to_cc) (bx.loVect(), bx.hiVect(), BL_TO_FORTRAN_N(cc[mfi],dcomp), D_DECL(BL_TO_FORTRAN((*fc[0])[mfi]), BL_TO_FORTRAN((*fc[1])[mfi]), BL_TO_FORTRAN((*fc[2])[mfi])), dx, problo, coord_type); } }
void StateData::copyNew (const StateData& state) { BL_ASSERT(state.hasNewData()); BL_ASSERT(new_data != 0); const MultiFab& MF = state.newData(); int nc = MF.nComp(); int ng = MF.nGrow(); BL_ASSERT(nc == (*new_data).nComp()); BL_ASSERT(ng == (*new_data).nGrow()); MultiFab::Copy(*new_data, state.newData(), 0, 0, nc, ng); StateDescriptor::TimeCenter t_typ(desc->timeType()); if (t_typ == StateDescriptor::Point) { new_time.start = new_time.stop = state.curTime(); } else { Real dt = state.curTime() - state.prevTime(); new_time.start = state.curTime() - dt/2.0; new_time.stop = state.curTime() + dt/2.0; } }
BaseFab<Real>& BaseFab<Real>::invert (Real val, const Box& bx, int comp, int ncomp) { BL_ASSERT(domain.contains(bx)); BL_ASSERT(comp >= 0 && comp + ncomp <= nvar); const int* _box_lo = bx.loVect(); const int* _box_hi = bx.hiVect(); const int* _datalo = loVect(); const int* _datahi = hiVect(); const Real* _data = dataPtr(comp); FORT_FASTINVERT(_data, ARLIM(_datalo), ARLIM(_datahi), _box_lo, _box_hi, &val, &ncomp); return *this; }
void ABec4::aCoefficients (const MultiFab& _a) { BL_ASSERT(_a.ok()); BL_ASSERT(_a.boxArray() == (acoefs[0])->boxArray()); invalidate_a_to_level(0); MultiFab::Copy(*acoefs[0],_a,0,0,acoefs[0]->nComp(),acoefs[0]->nGrow()); }
void ABec4::bCoefficients (const MultiFab& _b) { BL_ASSERT(_b.ok()); BL_ASSERT(_b.boxArray() == (bcoefs[0])->boxArray()); invalidate_b_to_level(0); MultiFab::Copy(*bcoefs[0],_b,0,0,bcoefs[0]->nComp(),bcoefs[0]->nGrow()); }
//---------------------------------------------------------------------------- // like C-style void StoreObject(int i, int maxCntObject, std::string nameClass, void* pThis) { static TMapStrInt mMapClassCnt;// для нахождения по имени класса макс. кол-ва объектов static TMapPtrStr mMapPtrName; // по указателю на объект имя класса int cntMake = 0; bool res = false; LockThread(nsLockThread::eLock);// блокировка switch(i) { case nsStoreObject::ePush: { //------------------------------- TMapStrInt::iterator fit = mMapClassCnt.find(nameClass); if(fit==mMapClassCnt.end()) { // не нашли - добавить mMapClassCnt.insert(TMapStrInt::value_type(nameClass,1)); fit = mMapClassCnt.find(nameClass); // что бы потом найти в деструкторе mMapPtrName.insert(TMapPtrStr::value_type(pThis,nameClass)); } else fit->second++; cntMake = fit->second; } break; case nsStoreObject::ePop: { //------------------------------- TMapPtrStr::iterator fit_name = mMapPtrName.find(pThis); if(fit_name!=mMapPtrName.end()) { TMapStrInt::iterator fit = mMapClassCnt.find(fit_name->second); if(fit!=mMapClassCnt.end()) { fit->second--; cntMake = fit->second; res = true; } } } break; } LockThread(nsLockThread::eUnlock);// разблокировать // проверка результатов switch(i) { case nsStoreObject::ePush: BL_ASSERT(cntMake <= maxCntObject); break; case nsStoreObject::ePop: BL_ASSERT(cntMake >= 0 && res); break; } }
void BoxLib::WriteMultiLevelPlotfile (const std::string& plotfilename, int nlevels, const Array<const MultiFab*>& mf, const Array<std::string>& varnames, const Array<Geometry>& geom, Real time, const Array<int>& level_steps, const Array<IntVect>& ref_ratio) { BL_PROFILE("WriteMultiLevelPlotfile()"); BL_ASSERT(nlevels <= mf.size()); BL_ASSERT(nlevels <= geom.size()); BL_ASSERT(nlevels <= ref_ratio.size()+1); BL_ASSERT(nlevels <= level_steps.size()); BL_ASSERT(mf[0]->nComp() == varnames.size()); int finest_level = nlevels-1; // // Only let 64 CPUs be writing at any one time. // int saveNFiles(VisMF::GetNOutFiles()); VisMF::SetNOutFiles(64); const std::string versionName("HyperCLaw-V1.1"); const std::string levelPrefix("Level_"); const std::string mfPrefix("Cell"); bool callBarrier(true); BoxLib::PreBuildDirectorHierarchy(plotfilename, levelPrefix, nlevels, callBarrier); if (ParallelDescriptor::IOProcessor()) { std::string HeaderFileName(plotfilename + "/Header"); std::ofstream HeaderFile(HeaderFileName.c_str(), std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); if( ! HeaderFile.good()) { BoxLib::FileOpenFailed(HeaderFileName); } Array<BoxArray> boxArrays(nlevels); for(int level(0); level < boxArrays.size(); ++level) { boxArrays[level] = mf[level]->boxArray(); } BoxLib::WriteGenericPlotfileHeader(HeaderFile, nlevels, boxArrays, varnames, geom, time, level_steps, ref_ratio); } for (int level = 0; level <= finest_level; ++level) { VisMF::Write(*mf[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix)); } VisMF::SetNOutFiles(saveNFiles); }
void FMultiGrid::set_bc (int * mg_bc, MultiFab& crse_phi, MultiFab& phi) { BL_ASSERT(m_crse_ratio != IntVect::TheZeroVector()); BL_ASSERT(!m_bc.initilized); m_bc = Boundary(mg_bc, &crse_phi, &phi); }
CArena::CArena (size_t hunk_size) { // // Force alignment of hunksize. // m_hunk = Arena::align(hunk_size == 0 ? DefaultHunkSize : hunk_size); m_used = 0; BL_ASSERT(m_hunk >= hunk_size); BL_ASSERT(m_hunk%Arena::align_size == 0); }
void FMultiGrid::set_gravity_coeffs (Array< PArray<MultiFab> >& b) { BL_ASSERT(m_coeff.eq_type == invalid_eq); BL_ASSERT(b.size() == m_nlevels); BL_ASSERT(b[0].size() == BL_SPACEDIM); m_coeff.eq_type = gravity_eq; m_coeff.coeffs_set = true; Copy(m_coeff.b, b); }
void FMultiGrid::set_mac_coeffs (PArray<MultiFab>& b) { BL_ASSERT(m_coeff.eq_type == invalid_eq); BL_ASSERT(m_nlevels == 1); BL_ASSERT(b.size() == BL_SPACEDIM); m_coeff.eq_type = macproj_eq; m_coeff.coeffs_set = true; Copy(m_coeff.b, b); }
void FMultiGrid::set_scalars (Real alpha, Real beta) { BL_ASSERT(m_coeff.eq_type == invalid_eq || m_coeff.eq_type == general_eq); BL_ASSERT(!m_coeff.scalars_set); m_coeff.eq_type = general_eq; m_coeff.scalars_set = true; m_coeff.alpha = alpha; m_coeff.beta = beta; }
void FMultiGrid::set_coefficients (const MultiFab& a, PArray<MultiFab> & b) { BL_ASSERT(m_coeff.eq_type == invalid_eq || m_coeff.eq_type == general_eq); BL_ASSERT(!m_coeff.coeffs_set); BL_ASSERT(m_nlevels == 1); m_coeff.eq_type = general_eq; m_coeff.coeffs_set = true; Copy(m_coeff.a, a); Copy(m_coeff.b, b); }
void BndryRegister::setBoxes (const BoxArray& _grids) { BL_ASSERT(grids.size() == 0); BL_ASSERT(_grids.size() > 0); BL_ASSERT(_grids[0].cellCentered()); grids.define(_grids); // // Check that bndry regions are not allocated. // for (int k = 0; k < 2*BL_SPACEDIM; k++) BL_ASSERT(bndry[k].size() == 0); }
void FMultiGrid::set_coefficients (PArray<MultiFab>& a, Array<PArray<MultiFab> > & b) { BL_ASSERT(m_coeff.eq_type == invalid_eq || m_coeff.eq_type == general_eq); BL_ASSERT(!m_coeff.coeffs_set); BL_ASSERT(m_nlevels == a.size() && m_nlevels == b.size()); BL_ASSERT(BL_SPACEDIM == b[0].size()); m_coeff.eq_type = general_eq; m_coeff.coeffs_set = true; Copy(m_coeff.a, a); Copy(m_coeff.b, b); }
void AuxBoundaryData::copy (const AuxBoundaryData& src, int src_comp, int dst_comp, int num_comp) { if (m_empty || src.m_empty) return; BL_ASSERT(m_initialized); BL_ASSERT(src_comp + num_comp <= src.m_fabs.nComp()); BL_ASSERT(dst_comp + num_comp <= m_fabs.nComp()); m_fabs.copy(src.m_fabs,src_comp,dst_comp,num_comp); }
bool StateDescriptor::identicalInterps (int scomp, int ncomp) const { BL_ASSERT(scomp >= 0); BL_ASSERT(ncomp >= 1); Interpolater* map = interp(scomp); for (int i = scomp+1; i < scomp+ncomp; i++) if (!(map == interp(i))) return false; return true; }
void average_down (MultiFab& S_fine, MultiFab& S_crse, int scomp, int ncomp, const IntVect& ratio) { BL_ASSERT(S_crse.nComp() == S_fine.nComp()); // // Coarsen() the fine stuff on processors owning the fine data. // BoxArray crse_S_fine_BA = S_fine.boxArray(); crse_S_fine_BA.coarsen(ratio); MultiFab crse_S_fine(crse_S_fine_BA,ncomp,0); #ifdef _OPENMP #pragma omp parallel #endif for (MFIter mfi(crse_S_fine,true); mfi.isValid(); ++mfi) { // NOTE: The tilebox is defined at the coarse level. const Box& tbx = mfi.tilebox(); // NOTE: We copy from component scomp of the fine fab into component 0 of the crse fab // because the crse fab is a temporary which was made starting at comp 0, it is // not part of the actual crse multifab which came in. BL_FORT_PROC_CALL(BL_AVGDOWN,bl_avgdown) (tbx.loVect(), tbx.hiVect(), BL_TO_FORTRAN_N(S_fine[mfi],scomp), BL_TO_FORTRAN_N(crse_S_fine[mfi],0), ratio.getVect(),&ncomp); } S_crse.copy(crse_S_fine,0,scomp,ncomp); }
void Box::next (IntVect& p, const int* shv) const { BL_ASSERT(contains(p)); #if BL_SPACEDIM==1 p.shift(0,shv[0]); #elif BL_SPACEDIM==2 p.shift(0,shv[0]); if (!(p <= bigend)) { // // Reset 1 coord is on edge, and 2 coord is incremented. // p.setVal(0,smallend[0]); p.shift(1,shv[1]); } #elif BL_SPACEDIM==3 p.shift(0,shv[0]); if (!(p <= bigend)) { // // Reset 1 coord is on edge, and 2 coord is incremented. // p.setVal(0,smallend[0]); p.shift(1,shv[1]); if(!(p <= bigend)) { p.setVal(1,smallend[1]); p.shift(2,shv[2]); } } #endif }
void Box::next (IntVect& p) const { BL_ASSERT(contains(p)); p.shift(0,1); #if BL_SPACEDIM==2 if (!(p <= bigend)) { p.setVal(0,smallend[0]); p.shift(1,1); } #elif BL_SPACEDIM==3 if (!(p <= bigend)) { p.setVal(0,smallend[0]); p.shift(1,1); if (!(p <= bigend)) { p.setVal(1,smallend[1]); p.shift(2,1); } } #endif }
bool Box::volumeOK (long& N) const { BL_ASSERT(ok()); N = length(0)-btype[0]; for (int i = 1; i < BL_SPACEDIM; i++) { long diff = (length(i)-btype[i]); if (diff == 0) { N = 0; return true; } else if (N <= std::numeric_limits<long>::max()/diff) { N *= diff; } else { // // The return value of N will be undefined. // return false; } } return true; }
double Box::d_numPts () const { BL_ASSERT(ok()); return D_TERM(double(length(0)), *double(length(1)), *double(length(2))); }