// ------------------------------------------------------------- void Mask::buildMask(BaseFab<int>& a_mask, const ProblemDomain& a_dProblem, const BoxLayout& a_grids, const BoxLayout* a_fineGridsPtr, int a_nRefFine) { // first set entire box to Physical BC a_mask.setVal(maskPhysical); // now set all of domain interior to coarse Box domainInterior(a_mask.box()); domainInterior &= a_dProblem; a_mask.setVal(maskCoarse,domainInterior,0); // now loop over this level's boxes and set them to "copy" LayoutIterator lit = a_grids.layoutIterator(); for (lit.reset(); lit.ok(); ++lit) { Box intersectBox = a_grids.get(lit()); intersectBox &= a_mask.box(); if (!intersectBox.isEmpty()) { a_mask.setVal(maskCopy,intersectBox,0); } } // if finer grids exist, set them to "covered" if (a_fineGridsPtr != NULL) { CH_assert (a_nRefFine > 1); LayoutIterator litFine = a_fineGridsPtr->layoutIterator(); for (litFine.reset(); litFine.ok(); ++litFine) { Box coarsenedBox(a_fineGridsPtr->get(litFine())); coarsenedBox.coarsen(a_nRefFine); coarsenedBox &= a_mask.box(); if (!coarsenedBox.isEmpty()) { a_mask.setVal(maskCovered,coarsenedBox,0); } } } }
Real DotProduct(const BoxLayoutData<FArrayBox>& a_dataOne, const BoxLayoutData<FArrayBox>& a_dataTwo, const BoxLayout& a_dblIn, const Interval& a_comps) { Vector<Real> rhodot; rhodot.reserve(10); const int startcomp = a_comps.begin(); const int endcomp = a_comps.end(); //calculate the single-processor dot product DataIterator dit = a_dataOne.dataIterator(); for (dit.reset(); dit.ok(); ++dit) { Box fabbox = a_dblIn.get(dit()); const FArrayBox& onefab = a_dataOne[dit()]; const FArrayBox& twofab = a_dataTwo[dit()]; CH_assert(onefab.box().contains(fabbox)); CH_assert(twofab.box().contains(fabbox)); Real dotgrid = 0; FORT_DOTPRODUCT(CHF_REAL(dotgrid), CHF_CONST_FRA(onefab), CHF_CONST_FRA(twofab), CHF_BOX(fabbox), CHF_CONST_INT(startcomp), CHF_CONST_INT(endcomp)); rhodot.push_back(dotgrid); } // now for the multi-processor fandango //gather all the rhodots onto a vector and add them up int baseProc = 0; Vector<Vector<Real> >dotVec; gather(dotVec, rhodot, baseProc); Real rhodotTot = 0.0; if (procID() == baseProc) { CH_assert(dotVec.size() == numProc()); rhodot.resize(a_dblIn.size()); int index = 0; for (int p = 0; p < dotVec.size(); p++) { Vector<Real>& v = dotVec[p]; for (int i = 0; i < v.size(); i++, index++) { rhodot[index] = v[i]; } } rhodot.sort(); for (int ivec = 0; ivec < rhodot.size(); ivec++) { rhodotTot += rhodot[ivec]; } } //broadcast the sum to all processors. broadcast(rhodotTot, baseProc); //return the total return rhodotTot; }