Commit 7f331e08 authored by berenger-bramas's avatar berenger-bramas

change the way to compute accuracy (and add a class in FMath to do that)

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@427 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 9db8d6e0
......@@ -155,6 +155,33 @@ struct FMath{
return std::isfinite(value);
}
/** A class to compute accuracy */
class FAccurater {
FReal l2Dot;
FReal l2Diff;
FReal max;
FReal maxDiff;
public:
FAccurater() : l2Dot(0), l2Diff(0), max(0), maxDiff(0) {
}
/** Add value to the current list */
void add(const FReal inGood, const FReal inBad){
l2Diff += (inBad - inGood) * (inBad - inGood);
l2Dot += inGood * inGood;
max = Max(max , Abs(inGood));
maxDiff = Max(maxDiff, Abs(inGood-inBad));
}
/** Get the L2 norm */
FReal getL2Norm() const{
return Sqrt(l2Diff / l2Dot);
}
/** Get the inf norm */
FReal getInfNorm() const{
return maxDiff / max;
}
};
};
......
......@@ -73,8 +73,8 @@ class TestSphericalDirect : public FUTester<TestSphericalDirect> {
const int NbLevels = 4;
const int SizeSubLevels = 2;
const int DevP = 12;
FSphericalCell::Init(DevP);
const int DevP = 8;
FSphericalCell::Init(DevP, true);
// Create octree
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
......@@ -103,8 +103,8 @@ class TestSphericalDirect : public FUTester<TestSphericalDirect> {
// Compare
Print("Compute Diff...");
FReal potentialDiff = 0;
FReal fx = 0, fy = 0, fz = 0;
FMath::FAccurater potentialDiff;
FMath::FAccurater fx, fy, fz;
{ // Check that each particle has been summed with all other
OctreeClass::Iterator octreeIterator(&tree);
octreeIterator.gotoBottomLeft();
......@@ -115,13 +115,13 @@ class TestSphericalDirect : public FUTester<TestSphericalDirect> {
while( leafIter.hasNotFinished() ){
const ParticleClass& other = particles[leafIter.data().getIndex()];
potentialDiff += (other.getPotential(),leafIter.data().getPotential())/other.getPotential();
potentialDiff.add(other.getPotential(),leafIter.data().getPotential());
fx += FMath::Abs((other.getForces().getX()-leafIter.data().getForces().getX())/other.getForces().getX());
fx.add(other.getForces().getX(),leafIter.data().getForces().getX());
fy += FMath::Abs((other.getForces().getY()-leafIter.data().getForces().getY())/other.getForces().getY());
fy.add(other.getForces().getY(),leafIter.data().getForces().getY());
fz += FMath::Abs((other.getForces().getZ()-leafIter.data().getForces().getZ())/other.getForces().getZ());
fz.add(other.getForces().getZ(),leafIter.data().getForces().getZ());
leafIter.gotoNext();
}
......@@ -131,19 +131,27 @@ class TestSphericalDirect : public FUTester<TestSphericalDirect> {
delete[] particles;
Print("Potential diff is = ");
Print(potentialDiff);
Print(potentialDiff.getL2Norm());
Print(potentialDiff.getInfNorm());
Print("Fx diff is = ");
Print(fx);
Print(fx.getL2Norm());
Print(fx.getInfNorm());
Print("Fy diff is = ");
Print(fy);
Print(fy.getL2Norm());
Print(fy.getInfNorm());
Print("Fz diff is = ");
Print(fz);
const FReal MaximumDiff = FReal(0.5);
assert(potentialDiff < MaximumDiff);
assert(fx < MaximumDiff);
assert(fy < MaximumDiff);
assert(fz < MaximumDiff);
Print(fz.getL2Norm());
Print(fz.getInfNorm());
const FReal MaximumDiff = FReal(0.0001);
assert(potentialDiff.getL2Norm() < MaximumDiff);
assert(potentialDiff.getInfNorm() < MaximumDiff);
assert(fx.getL2Norm() < MaximumDiff);
assert(fx.getInfNorm() < MaximumDiff);
assert(fy.getL2Norm() < MaximumDiff);
assert(fy.getInfNorm() < MaximumDiff);
assert(fz.getL2Norm() < MaximumDiff);
assert(fz.getInfNorm() < MaximumDiff);
}
void After() {
......
......@@ -139,8 +139,8 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
// Compare
Print("Compute Diff...");
FReal potentialDiff = 0;
FReal fx = 0, fy = 0, fz = 0;
FMath::FAccurater potentialDiff;
FMath::FAccurater fx, fy, fz;
{ // Check that each particle has been summed with all other
OctreeClass::Iterator octreeIterator(&tree);
octreeIterator.gotoBottomLeft();
......@@ -163,13 +163,13 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
other.getForces().getX(),other.getForces().getY(),other.getForces().getZ());// todo delete
potentialDiff += (other.getPotential(),leafIter.data().getPotential())/other.getPotential();
potentialDiff.add(other.getPotential(),leafIter.data().getPotential());
fx += FMath::Abs((other.getForces().getX()-leafIter.data().getForces().getX())/other.getForces().getX());
fx.add(other.getForces().getX(),leafIter.data().getForces().getX());
fy += FMath::Abs((other.getForces().getY()-leafIter.data().getForces().getY())/other.getForces().getY());
fy.add(other.getForces().getY(),leafIter.data().getForces().getY());
fz += FMath::Abs((other.getForces().getZ()-leafIter.data().getForces().getZ())/other.getForces().getZ());
fz.add(other.getForces().getZ(),leafIter.data().getForces().getZ());
leafIter.gotoNext();
}
......@@ -180,19 +180,27 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
delete[] particles;
Print("Potential diff is = ");
Print(potentialDiff);
Print(potentialDiff.getL2Norm());
Print(potentialDiff.getInfNorm());
Print("Fx diff is = ");
Print(fx);
Print(fx.getL2Norm());
Print(fx.getInfNorm());
Print("Fy diff is = ");
Print(fy);
Print(fy.getL2Norm());
Print(fy.getInfNorm());
Print("Fz diff is = ");
Print(fz);
const FReal MaximumDiff = FReal(0.5);
assert(potentialDiff < MaximumDiff);
assert(fx < MaximumDiff);
assert(fy < MaximumDiff);
assert(fz < MaximumDiff);
Print(fz.getL2Norm());
Print(fz.getInfNorm());
const FReal MaximumDiff = FReal(0.0001);
assert(potentialDiff.getL2Norm() < MaximumDiff);
assert(potentialDiff.getInfNorm() < MaximumDiff);
assert(fx.getL2Norm() < MaximumDiff);
assert(fx.getInfNorm() < MaximumDiff);
assert(fy.getL2Norm() < MaximumDiff);
assert(fy.getInfNorm() < MaximumDiff);
assert(fz.getL2Norm() < MaximumDiff);
assert(fz.getInfNorm() < MaximumDiff);
}
/** Test real Periodic FMM */
......@@ -292,8 +300,8 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
// Compare
Print("Compute Diff...");
FReal potentialDiff = 0;
FReal fx = 0, fy = 0, fz = 0;
FMath::FAccurater potentialDiff;
FMath::FAccurater fx, fy, fz;
{ // Check that each particle has been summed with all other
ParticleClass*const partBox = 0;//&particles[boxStartIdx];
......@@ -316,13 +324,13 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
other.getForces().getX(),other.getForces().getY(),other.getForces().getZ());// todo delete
potentialDiff += (other.getPotential(),leafIter.data().getPotential())/other.getPotential();
potentialDiff.add(other.getPotential(),leafIter.data().getPotential());
fx += FMath::Abs((other.getForces().getX()-leafIter.data().getForces().getX())/other.getForces().getX());
fx.add(other.getForces().getX(),leafIter.data().getForces().getX());
fy += FMath::Abs((other.getForces().getY()-leafIter.data().getForces().getY())/other.getForces().getY());
fy.add(other.getForces().getY(),leafIter.data().getForces().getY());
fz += FMath::Abs((other.getForces().getZ()-leafIter.data().getForces().getZ())/other.getForces().getZ());
fz.add(other.getForces().getZ(),leafIter.data().getForces().getZ());
leafIter.gotoNext();
}
......@@ -333,19 +341,27 @@ class TestSphericalDirectPeriodic : public FUTester<TestSphericalDirectPeriodic>
delete[] particles;
Print("Potential diff is = ");
Print(potentialDiff);
Print(potentialDiff.getL2Norm());
Print(potentialDiff.getInfNorm());
Print("Fx diff is = ");
Print(fx);
Print(fx.getL2Norm());
Print(fx.getInfNorm());
Print("Fy diff is = ");
Print(fy);
Print(fy.getL2Norm());
Print(fy.getInfNorm());
Print("Fz diff is = ");
Print(fz);
const FReal MaximumDiff = FReal(0.5);
assert(potentialDiff < MaximumDiff);
assert(fx < MaximumDiff);
assert(fy < MaximumDiff);
assert(fz < MaximumDiff);
Print(fz.getL2Norm());
Print(fz.getInfNorm());
const FReal MaximumDiff = FReal(0.0001);
assert(potentialDiff.getL2Norm() < MaximumDiff);
assert(potentialDiff.getInfNorm() < MaximumDiff);
assert(fx.getL2Norm() < MaximumDiff);
assert(fx.getInfNorm() < MaximumDiff);
assert(fy.getL2Norm() < MaximumDiff);
assert(fy.getInfNorm() < MaximumDiff);
assert(fz.getL2Norm() < MaximumDiff);
assert(fz.getInfNorm() < MaximumDiff);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment