예제 #1
0
/*
typedef GridSerializerVTK< ls::Grid3D<double>, StructuredPointsTraits > BasicSerializerVTK_SPoint;
// The list of types we want to test.
typedef testing::Types<BasicSerializerVTK, BasicSerializerVTK_SPoint> Implementations;

TYPED_TEST_CASE(VTKTest, BasicSerializerVTK);
*/
TEST(VTKTest, writeAndRead3)
{
  Close_relative close_at_tol(10e-8); // for whatever reason vtk writes with error

  size_t n = 12, m = 11, w = 14;
  Grid3D<double> grid(n, m, w);

  double top[] = {4.0, 5.0, 9.0};
  double low[] = {-3.0, -4.0, -5.0};
  Box3D box(low, top);
  double h[] = {box.getSizeX() / (n - 1.0), box.getSizeY() / (m - 1.0), box.getSizeZ() / (w - 1.0)};

  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < m; ++j) {
      for (size_t k = 0; k < w; ++k) {
        MathVector3D p(i * h[0], j * h[1], k * h[2]);
        p += box.getLow();
        assert(box.inside(p));
        grid(i, j, k) = testFunction2(p);
      }
    }
  }

  grid.setBoundingBox(box);
  BasicSerializerVTK writer(grid, "test-aux/writeAndRead3");
  writer.run();

  Grid3D<double> readGrid; // at this point I don't know the size
  BasicDeserializerVTK reader(readGrid, "test-aux/writeAndRead3");
  reader.run();

  EXPECT_EQ(grid.getBoundingBox(), readGrid.getBoundingBox());

  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < m; ++j) {
      for (size_t k = 0; k < w; ++k) {
        if (grid(i, j, k) != readGrid(i, j, k)) {
          EXPECT_TRUE(close_at_tol(grid(i, j, k), readGrid(i, j, k)));
        }
      }
    }
  }
}
예제 #2
0
TEST(VTKTest, writeAndRead1)
{
  Close_relative close_at_tol(10e-8); // for whatever reason vtk writes with error

  size_t n = 8, m = 8, w = 8;
  Box3D domainWrite(1.0, 1.0, 1.0);
  Grid3D<double> grid(n, m, w);
  double h = 1.0 / (n - 1);
  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < m; ++j) {
      for (size_t k = 0; k < w; ++k) {
        double point[] = { i * h - 0.5, j * h - 0.5, k * h - 0.5};
        grid(i, j, k) = testFunction1(point);
      }
    }
  }

  grid.setBoundingBox(domainWrite);
  BasicSerializerVTK writer(grid, "test-aux/writeAndRead1");
  EXPECT_TRUE(writer.run());

  Grid3D<double> readGrid; // at this point I don't know the size
  BasicDeserializerVTK reader(readGrid, "test-aux/writeAndRead1");
  EXPECT_TRUE(reader.run());

  EXPECT_EQ(grid.getBoundingBox(), readGrid.getBoundingBox());

  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < m; ++j) {
      for (size_t k = 0; k < w; ++k) {
        if (grid(i, j, k) != readGrid(i, j, k)) {
          EXPECT_TRUE(close_at_tol(grid(i, j, k), readGrid(i, j, k)));
        }
      }
    }
  }
}