Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Dec 29, 2023
1 parent 75571e2 commit 17e7ea5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 62 deletions.
22 changes: 22 additions & 0 deletions Src/Base/AMReX_Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ Geometry::computeRoundoffDomain ()
// The assertion on rlo_out makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rlo_out > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);
amrex::Print().SetPrecision(17) << "AAAAA rlo_out = " << rlo_out
<< " rlo = " << rlo
<< " iters = " << iters << std::endl;
}
else
{
Expand All @@ -585,6 +588,9 @@ Geometry::computeRoundoffDomain ()
// The assertion on rtmp makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rtmp > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);
amrex::Print().SetPrecision(17) << "BBBBB rlo_out = " << rlo_out
<< " rlo = " << rlo
<< " iters = " << iters << std::endl;
}

{
Expand Down Expand Up @@ -616,6 +622,10 @@ Geometry::computeRoundoffDomain ()
// The assertion on rlo_minus makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rlo_minus > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);

amrex::Print().SetPrecision(17) << "CCCCC rlo_out = " << rlo_out
<< " rlo = " << rlo
<< " iters = " << iters << std::endl;
}

ParticleReal rhi_out;
Expand All @@ -632,6 +642,10 @@ Geometry::computeRoundoffDomain ()
// The assertion on rhi_out makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rhi_out > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);

amrex::Print().SetPrecision(17) << "AAAAA rhi_out = " << rhi_out
<< " rhi = " << rhi
<< " iters = " << iters << std::endl;
}
else
{
Expand All @@ -651,6 +665,10 @@ Geometry::computeRoundoffDomain ()
// The assertion on rtmp makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rtmp > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);

amrex::Print().SetPrecision(17) << "BBBBB rhi_out = " << rhi_out
<< " rhi = " << rhi
<< " iters = " << iters << std::endl;
}

{
Expand Down Expand Up @@ -682,6 +700,10 @@ Geometry::computeRoundoffDomain ()
// The assertion on rhi_plus makes sure the compiler cannot optimize it away.
AMREX_ALWAYS_ASSERT(rhi_plus > std::numeric_limits<ParticleReal>::lowest()
&& iters < maxiters);

amrex::Print().SetPrecision(17) << "CCCCC rhi_out = " << rhi_out
<< " rhi = " << rhi
<< " iters = " << iters << std::endl;
}
}
}
Expand Down
75 changes: 13 additions & 62 deletions Tests/RoundoffDomain/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,24 @@ using namespace amrex;
int main(int argc, char* argv[])
{
amrex::Initialize(argc,argv);
ULong seed;
{
std::random_device rd; // non-deterministic random numbers
std::uniform_int_distribution<ULong> dist(0,std::numeric_limits<ULong>::max());
seed = dist(rd);
amrex::ResetRandomSeed(seed);
}
for (int icell = 0; icell < 10000; ++icell)

{
int ncells = int(amrex::Random_int(102400)) + 4;
int ncells = 64;
Box domain(IntVect(0),IntVect(ncells-1));

for (int ieps = 0; ieps < 1000; ++ieps)
{
std::array<Real,AMREX_SPACEDIM> rblo{AMREX_D_DECL(Real(0.),Real(-1.),Real(-0.3))};
std::array<Real,AMREX_SPACEDIM> rbhi{AMREX_D_DECL(Real(1.),Real( 0.),Real( 0.5))};
if (ieps % 100 != 0) {
auto eps = (amrex::Random() - Real(0.5)) * Real(1.e-4);
AMREX_D_TERM(rblo[0] += eps;,
rblo[1] -= eps;,
rblo[2] += eps);
AMREX_D_TERM(rbhi[0] -= eps;,
rbhi[1] += eps;,
rbhi[2] -= eps);
}
std::array<Real,AMREX_SPACEDIM> rblo{AMREX_D_DECL(Real(-3.703e18),Real(-3.703e18),Real(-3.703e18))};
std::array<Real,AMREX_SPACEDIM> rbhi{AMREX_D_DECL(Real( 3.703e18),Real( 3.703e18),Real( 3.703e18))};

RealBox rb(rblo, rbhi);
Geometry geom(domain, rb, 0, {AMREX_D_DECL(0,0,0)});

RealBox rb(rblo, rbhi);
Geometry geom(domain, rb, 0, {AMREX_D_DECL(0,0,0)});
auto rlo = geom.ProbLoArrayInParticleReal();
auto rhi = geom.ProbHiArrayInParticleReal();

auto rlo = geom.ProbLoArrayInParticleReal();
auto rhi = geom.ProbHiArrayInParticleReal();
auto plo = geom.ProbLoArray();
auto dxinv = geom.InvCellSizeArray();
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
auto index = [&] (ParticleReal x) -> int
{
return int(std::floor((x - plo[idim])*dxinv[idim]));
};
auto epsilon = std::numeric_limits<ParticleReal>::epsilon()
* std::max(ParticleReal(geom.CellSize(idim)),std::abs(rlo[idim]))
* ParticleReal(2.5);
auto rlom = rlo[idim] - epsilon;
epsilon = std::numeric_limits<ParticleReal>::epsilon()
* std::max(ParticleReal(geom.CellSize(idim)),std::abs(rhi[idim]))
* ParticleReal(2.5);
auto rhip = rhi[idim] + epsilon;
bool pass = (index(rlom) == -1)
&& (index(rlo[idim]) == 0 )
&& (index(rhi[idim]) == ncells-1)
&& (index(rhip) == ncells);
if (!pass) {
amrex::AllPrint().SetPrecision(17)
<< "Random seed = " << seed << "\n"
<< "RealBox: " << rb << "\n"
<< "Geometry: " << geom << "\n"
<< " rlo[" << idim << "] = " << rlo[idim]
<< " rhi[" << idim << "] = " << rhi[idim]
<< " rlo_minus = " << rlom
<< " rhi_plus = " << rhip << "\n"
<< " ilo = " << index(rlo[idim])
<< " ihi = " << index(rhi[idim])
<< " ilo-1 = " << index(rlom)
<< " ihi+1 = " << index(rhip)
<< "\n";
amrex::Abort("Failed");
}
}
for (int i = 0; i < AMREX_SPACEDIM; ++i) {
amrex::Print().SetPrecision(17)
<< "xxxxx rlo[" << i << "] = " << rlo[i]
<< ", rhi[" << i << "] = " << rhi[i] << std::endl;
}
}
amrex::Finalize();
Expand Down

0 comments on commit 17e7ea5

Please sign in to comment.