Skip to content

Commit

Permalink
Use BoxList::catenate() instead of BoxList::join() when possible.
Browse files Browse the repository at this point in the history
The former is more memory efficient.
  • Loading branch information
lijewski committed Oct 21, 2011
1 parent b0c9b71 commit ba0a1ea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Src/C_AMRLib/Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ Amr::ProjPeriodic (BoxList& blout,

BoxList tmp(blorig);
tmp.intersect(domain);
blout.join(tmp);
blout.catenate(tmp);

if (rk != 0 && geom.isPeriodic(2))
blorig.shift(2,-rk*domain.length(2));
Expand Down
18 changes: 13 additions & 5 deletions Src/C_BaseLib/BoxArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,14 @@ BoxList
BoxLib::GetBndryCells (const BoxArray& ba,
int ngrow)
{
BL_ASSERT(ba.ok());
BL_ASSERT(ba.size() > 0);
//
// First get list of all ghost cells.
//
BoxList gcells, bcells = ba.boxList();
const IndexType btype = ba[0].ixType();

BoxList bcells = ba.boxList(), gcells(btype), leftover(btype);

bcells.simplify();

Expand All @@ -612,14 +616,18 @@ BoxLib::GetBndryCells (const BoxArray& ba,

for (int i = 0, N = tba.size(); i < N; ++i)
{
gcells.join(BoxLib::boxDiff(BoxLib::grow(tba[i],ngrow),tba[i]));
bcells = BoxLib::boxDiff(BoxLib::grow(tba[i],ngrow),tba[i]);

gcells.catenate(bcells);
}
//
// Now strip out intersections with original BoxArray.
//
std::vector< std::pair<int,Box> > isects;

for (BoxList::const_iterator it = gcells.begin(), End = gcells.end(); it != End; ++it)
{
std::vector< std::pair<int,Box> > isects = tba.intersections(*it);
isects = tba.intersections(*it);

if (isects.empty())
{
Expand All @@ -630,10 +638,10 @@ BoxLib::GetBndryCells (const BoxArray& ba,
//
// Collect all the intersection pieces.
//
BoxList pieces;
BoxList pieces(btype);
for (int i = 0, N = isects.size(); i < N; i++)
pieces.push_back(isects[i].second);
BoxList leftover = BoxLib::complementIn(*it,pieces);
leftover = BoxLib::complementIn(*it,pieces);
bcells.catenate(leftover);
}
}
Expand Down
33 changes: 18 additions & 15 deletions Src/C_BaseLib/BoxList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,39 +279,40 @@ BoxList::complementIn (const Box& b,
{
clear();

Box minbox = bl.minimalBox();
BoxList tmpbl = BoxLib::boxDiff(b,minbox);
Box mbox = bl.minimalBox();
BoxList diff = BoxLib::boxDiff(b,mbox);

catenate(tmpbl);
catenate(diff);

BoxArray ba(bl);

BoxList mesh(b.ixType());
if (minbox.ok())
mesh.push_back(minbox);
if (mbox.ok())
mesh.push_back(mbox);
mesh.maxSize(BL_SPACEDIM == 3 ? 64 : 128);

std::vector< std::pair<int,Box> > isects;

for (BoxList::const_iterator bli = mesh.begin(), End = mesh.end(); bli != End; ++bli)
{
const Box bx = *bli & b;

if (!bx.ok()) continue;

std::vector< std::pair<int,Box> > isects = ba.intersections(bx);
isects = ba.intersections(bx);

if (!isects.empty())
if (isects.empty())
{
push_back(bx);
}
else
{
tmpbl.clear();
BoxList tm(b.ixType());
BoxList tm(b.ixType()), tmpbl(b.ixType());
for (int i = 0, N = isects.size(); i < N; i++)
tmpbl.push_back(isects[i].second);
tm.complementIn_base(bx,tmpbl);
catenate(tm);
}
else
{
push_back(bx);
}
}
}

Expand All @@ -328,14 +329,16 @@ BoxList::complementIn_base (const Box& b,

push_back(b);

BoxList diff;

for (const_iterator bli = bl.begin(), End = bl.end(); bli != End && isNotEmpty(); ++bli)
{
for (iterator newbli = lbox.begin(); newbli != lbox.end(); )
{
if (newbli->intersects(*bli))
{
BoxList tm = BoxLib::boxDiff(*newbli, *bli);
lbox.splice(lbox.begin(), tm.lbox);
diff = BoxLib::boxDiff(*newbli, *bli);
lbox.splice(lbox.begin(), diff.lbox);
lbox.erase(newbli++);
}
else
Expand Down
4 changes: 2 additions & 2 deletions Src/Extern/amrdata/AmrData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ void AmrData::FillVar(MultiFab &destMultiFab, int finestFillLevel,
BoxArray(BoxLib::complementIn(tempCoarseBox,
tempUnfillableBoxes));

unfillableBoxesOnThisLevel.join(tempUnfillableBoxes);
unfillableBoxesOnThisLevel.catenate(tempUnfillableBoxes);
++currentBLI;
}
}
Expand Down Expand Up @@ -1410,7 +1410,7 @@ void AmrData::FillVar(Array<FArrayBox *> &destFabs, const Array<Box> &destBoxes,
BoxArray(BoxLib::complementIn(tempCoarseBox,
tempUnfillableBoxes));

unfillableBoxesOnThisLevel.join(tempUnfillableBoxes);
unfillableBoxesOnThisLevel.catenate(tempUnfillableBoxes);
++currentBLI;
}
}
Expand Down

0 comments on commit ba0a1ea

Please sign in to comment.