Created
December 12, 2017 12:49
-
-
Save campos-rafael/773f5fa0eb00d67dec3f59772b4668ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SillyFunction | |
{ | |
SillyFunction() {} | |
Vec3d operator()(const Vec3d& xyz) const | |
{ | |
return Vec3d(3.0 * xyz.y() + 1.0, 5.0 * xyz.z() + 7.0, -1.0 * xyz.x() - 9.0); | |
} | |
}; | |
TEST(Grids, MacGrid) | |
{ | |
Vec3dGrid::Ptr grid = Vec3dGrid::create(Vec3d(0)); | |
grid->setGridClass(GRID_STAGGERED); | |
CoordBBox bbox(Coord(0, 0, 0), Coord(2, 2, 2)); | |
Vec3dGrid::Accessor acc = grid->getAccessor(); | |
SillyFunction func; | |
for (int i = bbox.min()[0]; i < bbox.max()[0]; ++i) | |
for (int j = bbox.min()[1]; j < bbox.max()[1]; ++j) | |
for (int k = bbox.min()[2]; k < bbox.max()[2]; ++k) { | |
Coord ijk(i, j, k); | |
Vec3d value = func(Vec3d(i, j, k)); | |
// When setting the velocity on a staggered grid, despite this being a single call, | |
// what you're actually accomplishing is equivalent to the fictitious calls: | |
// acc.setValueForX(Coord(i-0.5, j, k), value); | |
// acc.setValueForY(Coord(i, j-0.5, k), value); | |
// acc.setValueForZ(Coord(i, j, k-0.5), value); | |
acc.setValue(ijk, value); | |
} | |
// tools::Sampler<2, false> sampler; // ==> this works! | |
tools::Sampler<2, true> sampler; // ==> now this works too! | |
for (int i = bbox.min()[0]; i < bbox.max()[0]; ++i) | |
for (int j = bbox.min()[1]; j < bbox.max()[1]; ++j) | |
for (int k = bbox.min()[2]; k < bbox.max()[2]; ++k) | |
{ | |
Vec3d sampledValue_a = sampler.sample(grid->tree(), Vec3R(i-0.5, j, k)); | |
Vec3d sampledValue_b = sampler.sample(grid->tree(), Vec3R(i, j-0.5, k)); | |
Vec3d sampledValue_c = sampler.sample(grid->tree(), Vec3R(i, j, k-0.5)); | |
Vec3d expected = func(Vec3d(i, j, k)); | |
EXPECT_EQ(sampledValue_a.x(), expected.x()); | |
EXPECT_EQ(sampledValue_b.y(), expected.y()); | |
EXPECT_EQ(sampledValue_c.z(), expected.z()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment