Skip to content

Commit

Permalink
add BoxArray::minmaxSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Aug 14, 2024
1 parent bb81f61 commit 2f3feb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 1 addition & 3 deletions Src/AmrCore/AMReX_AmrMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ AmrMesh::ChopGrids (int lev, BoxArray& ba, int target_size) const
} else {
IntVect bf(1);
bf[idim] = rr;
ba.coarsen(bf); // It's safe to coarsen.
ba.maxSize(chunk/bf);
ba.refine(bf);
ba.minmaxSize(bf, chunk);
}
break;
}
Expand Down
5 changes: 5 additions & 0 deletions Src/Base/AMReX_BoxArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ public:

BoxArray& maxSize (const IntVect& block_size);

//! Forces each Box in BoxArray to have sizes >= min_size and <=
//! max_size. It's the caller's responsibility to make sure both the
//! BoxArray and max_size are coarsenable by min_size.
BoxArray& minmaxSize (const IntVect& min_size, const IntVect& max_size);

//! Refine each Box in the BoxArray to the specified ratio.
BoxArray& refine (int refinement_ratio);

Expand Down
22 changes: 18 additions & 4 deletions Src/Base/AMReX_BoxArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,26 @@ BoxArray::maxSize (const IntVect& block_size)
blst.maxSize(block_size);
const int N = static_cast<int>(blst.size());
if (size() != N) { // If size doesn't change, do nothing.
BoxList bak = (m_simplified_list) ? *m_simplified_list : BoxList();
auto bak = m_simplified_list;
define(std::move(blst));
if (bak.isNotEmpty()) {
m_simplified_list = std::make_shared<BoxList>(std::move(bak));
}
m_simplified_list = bak;
}
return *this;
}

BoxArray&
BoxArray::minmaxSize (const IntVect& min_size, const IntVect& max_size)
{
AMREX_ASSERT(this->coarsenable(min_size) &&
(max_size/min_size)*min_size == max_size);
std::shared_ptr<BoxList> bak;
if (m_bat.is_simple() && crseRatio() == IntVect::TheUnitVector()) {
bak = m_simplified_list;
}
this->coarsen(min_size);
this->maxSize(max_size/min_size);
this->refine(min_size);
m_simplified_list = bak;
return *this;
}

Expand Down

0 comments on commit 2f3feb1

Please sign in to comment.