Skip to content

Commit

Permalink
Fixed bug in surface area calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
selimanac committed Sep 30, 2018
1 parent 24422d5 commit 2752f56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ log.txt
lib-src/AABB.cc

lib-src/build-mac-linux.sh
.vscode/settings.json
65 changes: 33 additions & 32 deletions daabbcc/src/AABB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ namespace aabb
// Validate the dimensionality of the bounds vectors.
if (lowerBound.size() != upperBound.size())
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");
assert("[ERROR]: Dimensionality mismatch!");


assert("[ERROR]: Dimensionality mismatch!");
}

// Validate that the upper bounds exceed the lower bounds.
for (unsigned int i=0;i<lowerBound.size();i++)
{
// Validate the bound.
if (lowerBound[i] >= upperBound[i])
if (lowerBound[i] > upperBound[i])
{
//throw std::invalid_argument("[ERROR]: AABB lower bound is greater than the upper bound!");
assert("[ERROR]: AABB lower bound is greater than the upper bound!");

assert("[ERROR]: AABB lower bound is greater than the upper bound!");
}
}

Expand All @@ -68,14 +67,14 @@ namespace aabb

double AABB::computeSurfaceArea() const
{
// Sum of volumes of all the sides.
// Sum of "area" of all the sides.
double sum = 0;

// General formula for one side: hold one dimension constant
// and multiply by all the other ones.
for (unsigned int d1 = 0; d1 < lowerBound.size(); d1++)
{
// Volume of current side.
// "Area" of current side.
double product = 1;

for (unsigned int d2 = 0; d2 < lowerBound.size(); d2++)
Expand All @@ -86,6 +85,9 @@ namespace aabb
double dx = upperBound[d2] - lowerBound[d2];
product *= dx;
}

// Update the sum.
sum += product;
}

return 2.0 * sum;
Expand Down Expand Up @@ -196,7 +198,7 @@ namespace aabb
// Validate the dimensionality.
if ((dimension < 2))
{
//throw std::invalid_argument("[ERROR]: Invalid dimensionality!");

assert("[ERROR]: Invalid dimensionality!");
}

Expand Down Expand Up @@ -236,15 +238,15 @@ namespace aabb
// Validate the dimensionality.
if (dimension < 2)
{
//throw std::invalid_argument("[ERROR]: Invalid dimensionality!");
assert("[ERROR]: Invalid dimensionality!");

assert("[ERROR]: Invalid dimensionality!");
}

// Validate the dimensionality of the vectors.
if ((periodicity.size() != dimension) || (boxSize.size() != dimension))
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");
assert("[ERROR]: Dimensionality mismatch!");

assert("[ERROR]: Dimensionality mismatch!");
}

// Initialise the tree.
Expand Down Expand Up @@ -343,22 +345,22 @@ namespace aabb
// Make sure the particle doesn't already exist.
if (particleMap.count(particle) != 0)
{
//throw std::invalid_argument("[ERROR]: Particle already exists in tree!");
assert("[ERROR]: Particle already exists in tree!");

assert("[ERROR]: Particle already exists in tree!");
}

// Validate the dimensionality of the position vector.
if (position.size() != dimension)
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");

assert("[ERROR]: Dimensionality mismatch!");
}

// Allocate a new node for the particle.
unsigned int node = allocateNode();

// AABB size in each dimension.
double size[dimension];
std::vector<double> size(dimension);

// Compute the AABB limits.
for (unsigned int i=0;i<dimension;i++)
Expand Down Expand Up @@ -395,14 +397,14 @@ namespace aabb
// Make sure the particle doesn't already exist.
if (particleMap.count(particle) != 0)
{
//throw std::invalid_argument("[ERROR]: Particle already exists in tree!");
assert("[ERROR]: Particle already exists in tree!");

assert("[ERROR]: Particle already exists in tree!");
}

// Validate the dimensionality of the bounds vectors.
if ((lowerBound.size() != dimension) || (upperBound.size() != dimension))
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");

assert("[ERROR]: Dimensionality mismatch!");
}

Expand All @@ -416,10 +418,10 @@ namespace aabb
for (unsigned int i=0;i<dimension;i++)
{
// Validate the bound.
if (lowerBound[i] >= upperBound[i])
if (lowerBound[i] > upperBound[i])
{
//throw std::invalid_argument("[ERROR]: AABB lower bound is greater than the upper bound!");
assert("[ERROR]: AABB lower bound is greater than the upper bound!");

assert("[ERROR]: AABB lower bound is greater than the upper bound!");
}

nodes[node].aabb.lowerBound[i] = lowerBound[i];
Expand Down Expand Up @@ -465,8 +467,7 @@ namespace aabb
// The particle doesn't exist.
if (it == particleMap.end())
{
//throw std::invalid_argument("[ERROR]: Invalid particle index!");


assert("[ERROR]: Invalid particle index!");
}

Expand Down Expand Up @@ -513,8 +514,8 @@ namespace aabb
// Validate the dimensionality of the position vector.
if (position.size() != dimension)
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");
assert("[ERROR]: Dimensionality mismatch!");

assert("[ERROR]: Dimensionality mismatch!");
}

// AABB bounds vectors.
Expand All @@ -538,7 +539,7 @@ namespace aabb
// Validate the dimensionality of the bounds vectors.
if ((lowerBound.size() != dimension) && (upperBound.size() != dimension))
{
//throw std::invalid_argument("[ERROR]: Dimensionality mismatch!");

assert("[ERROR]: Dimensionality mismatch!");
}

Expand All @@ -551,7 +552,7 @@ namespace aabb
// The particle doesn't exist.
if (it == particleMap.end())
{
//throw std::invalid_argument("[ERROR]: Invalid particle index!");

assert("[ERROR]: Invalid particle index!");
}

Expand All @@ -568,9 +569,9 @@ namespace aabb
for (unsigned int i=0;i<dimension;i++)
{
// Validate the bound.
if (lowerBound[i] >= upperBound[i])
if (lowerBound[i] > upperBound[i])
{
//throw std::invalid_argument("[ERROR]: AABB lower bound is greater than the upper bound!");

assert("[ERROR]: AABB lower bound is greater than the upper bound!");
}

Expand Down Expand Up @@ -612,7 +613,7 @@ namespace aabb
// Make sure that this is a valid particle.
if (particleMap.count(particle) == 0)
{
//throw std::invalid_argument("[ERROR]: Invalid particle index!");

assert("[ERROR]: Invalid particle index!");
}

Expand Down

0 comments on commit 2752f56

Please sign in to comment.