From 7a4bbb3a6d9b6d2eaae2e583948b5705ce1d14d2 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Sun, 10 Oct 2021 17:32:24 +0000 Subject: [PATCH 01/25] Add vector support for preCICE interface --- src/preciceMap.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/preciceMap.cpp b/src/preciceMap.cpp index 43fde4e1..8fc08f9c 100644 --- a/src/preciceMap.cpp +++ b/src/preciceMap.cpp @@ -188,7 +188,11 @@ int main(int argc, char *argv[]) if (interface.isActionRequired(precice::constants::actionWriteInitialData())) { VLOG(1) << "Write initial data for participant " << participant; - interface.writeBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + if (isVector) { + interface.writeBlockVectorData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + } else { + interface.writeBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + } VLOG(1) << "Data written: " << mesh.previewData(); interface.markActionFulfilled(precice::constants::actionWriteInitialData()); @@ -201,14 +205,22 @@ int main(int argc, char *argv[]) VLOG(1) << "Read mesh for t=" << round << " from " << meshes[round]; auto roundmesh = meshes[round].load(dim, dataname); VLOG(1) << "This roundmesh contains: " << roundmesh.summary(); - assert(roundmesh.data.size() == vertexIDs.size()); - interface.writeBlockScalarData(dataID, roundmesh.data.size(), vertexIDs.data(), roundmesh.data.data()); + if (isVector) { + interface.writeBlockVectorData(dataID, roundmesh.data.size(), vertexIDs.data(), roundmesh.data.data()); + } else { + assert(roundmesh.data.size() == vertexIDs.size()); + interface.writeBlockScalarData(dataID, roundmesh.data.size(), vertexIDs.data(), roundmesh.data.data()); + } VLOG(1) << "Data written: " << mesh.previewData(); } interface.advance(1); if (participant == "B") { - interface.readBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + if (isVector) { + interface.readBlockVectorData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + } else { + interface.readBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); + } VLOG(1) << "Data read: " << mesh.previewData(); } round++; From 23bf2565e29496490c46750042abd2cd50e3530d Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Sun, 10 Oct 2021 17:37:20 +0000 Subject: [PATCH 02/25] Remove old test files --- src/tests/edges.conn.txt | 4 ---- src/tests/edges.txt | 4 ---- src/tests/simple.txt | 4 ---- src/tests/triangles.conn.txt | 2 -- src/tests/triangles.txt | 4 ---- 5 files changed, 18 deletions(-) delete mode 100644 src/tests/edges.conn.txt delete mode 100644 src/tests/edges.txt delete mode 100644 src/tests/simple.txt delete mode 100644 src/tests/triangles.conn.txt delete mode 100644 src/tests/triangles.txt diff --git a/src/tests/edges.conn.txt b/src/tests/edges.conn.txt deleted file mode 100644 index 88e903c0..00000000 --- a/src/tests/edges.conn.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 1 -0 2 -2 3 -1 3 diff --git a/src/tests/edges.txt b/src/tests/edges.txt deleted file mode 100644 index a61c92ba..00000000 --- a/src/tests/edges.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0 -0 0.0 1.0 0 -0 1.0 1.0 0 diff --git a/src/tests/simple.txt b/src/tests/simple.txt deleted file mode 100644 index e66c2bff..00000000 --- a/src/tests/simple.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0.1 -0 0.0 1.0 -0.2 -0 1.0 1.0 5.2 diff --git a/src/tests/triangles.conn.txt b/src/tests/triangles.conn.txt deleted file mode 100644 index 249f4cd1..00000000 --- a/src/tests/triangles.conn.txt +++ /dev/null @@ -1,2 +0,0 @@ -0 1 2 -1 3 2 diff --git a/src/tests/triangles.txt b/src/tests/triangles.txt deleted file mode 100644 index a61c92ba..00000000 --- a/src/tests/triangles.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0 -0 0.0 1.0 0 -0 1.0 1.0 0 From af0132a18f482b090577112cc8a7afc61bfab9b1 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:26:34 +0000 Subject: [PATCH 03/25] Add test executables and tests to CMake --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index deadc296..ba13f301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,20 @@ if(METIS_FOUND) target_link_libraries(preciceMap metisAPI) endif() +add_executable(write_test src/tests/write_test.cpp src/mesh.cpp) +target_include_directories(write_test PRIVATE src) +target_link_libraries(write_test + Boost::filesystem + ${VTK_LIBRARIES} +) + +add_executable(read_test src/tests/read_test.cpp src/mesh.cpp) +target_include_directories(read_test PRIVATE src) +target_link_libraries(read_test + Boost::filesystem + ${VTK_LIBRARIES} +) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/make_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/visualize_partition.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/partition_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -70,3 +84,21 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/eval_mesh.py DESTINATION ${C file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_calculator.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh_io.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +enable_testing() + +add_test(write_scalar write_test scalar) +add_test(check_scalar md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/scalarmd5) +set_tests_properties (check_scalar PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(write_vector2d write_test vector2d) +add_test(check_vector2d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector2dmd5) +set_tests_properties (check_vector2d PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(write_vector3d write_test vector3d) +add_test(check_vector3d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector3dmd5) +set_tests_properties (check_vector3d PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(read_scalar read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_scalars 1 Scalars) +add_test(read_vector2d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector2d 2 Vector2D) +add_test(read_vector3d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector3d 3 Vector3D) From eeffb1b0813c0d13e8df80c418110255d32ce8e0 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:52:49 +0000 Subject: [PATCH 04/25] Collect VTK includes and Remove Duplicates --- src/mesh.cpp | 8 ---- src/tests/read_test.cpp | 56 ++++++++++++++++++++++++ src/tests/reference_scalars.vtk | 35 +++++++++++++++ src/tests/reference_vector2d.vtk | 36 +++++++++++++++ src/tests/reference_vector3d.vtk | 38 ++++++++++++++++ src/tests/scalarmd5 | 1 + src/tests/vector2dmd5 | 1 + src/tests/vector3dmd5 | 1 + src/tests/write_test.cpp | 75 ++++++++++++++++++++++++++++++++ 9 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 src/tests/read_test.cpp create mode 100644 src/tests/reference_scalars.vtk create mode 100644 src/tests/reference_vector2d.vtk create mode 100644 src/tests/reference_vector3d.vtk create mode 100644 src/tests/scalarmd5 create mode 100644 src/tests/vector2dmd5 create mode 100644 src/tests/vector3dmd5 create mode 100644 src/tests/write_test.cpp diff --git a/src/mesh.cpp b/src/mesh.cpp index b6b5075c..0ee423c2 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -9,14 +9,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include - #include #include #include diff --git a/src/tests/read_test.cpp b/src/tests/read_test.cpp new file mode 100644 index 00000000..6fe8efba --- /dev/null +++ b/src/tests/read_test.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + auto filename = std::string{argv[1]}; + auto dim = std::stoi(argv[2]); + auto dataname = std::string{argv[3]}; + + auto read_test = aste::BaseName{filename}.with(aste::ExecutionContext()); + auto mesh = read_test.load(dim, dataname); + + assert(mesh.positions.size() == 12); + assert(mesh.edges.size() == 2); + assert(mesh.quadrilaterals.size() == 2); + assert(mesh.triangles.size() == 4); + std::cout << "Number of mesh elements are correctly loaded\n"; + + assert(mesh.edges[1][0] == 10); + assert(mesh.edges[1][1] == 11); + std::cout << "Edges loaded correctly\n"; + assert(mesh.triangles[0][0] == 0); + assert(mesh.triangles[0][1] == 1); + assert(mesh.triangles[0][2] == 3); + std::cout << "Triangles loaded correctly\n"; + assert(mesh.quadrilaterals[1][0] == 4); + assert(mesh.quadrilaterals[1][1] == 5); + assert(mesh.quadrilaterals[1][2] == 8); + assert(mesh.quadrilaterals[1][3] == 7); + std::cout << "Quads loaded correctly\n"; + + switch (dim) { + case 1: + assert(mesh.data.size() == 12); + break; + case 2: + assert(mesh.data.size() == 24); + break; + case 3: + assert(mesh.data.size() == 36); + break; + } + + std::vector testdata; + testdata.resize(mesh.data.size()); + + std::iota(testdata.begin(), testdata.end(), 0); + + for (size_t i = 0; i < mesh.data.size(); ++i) { + assert(mesh.data[i] == testdata[i]); + } + + return 0; +} diff --git a/src/tests/reference_scalars.vtk b/src/tests/reference_scalars.vtk new file mode 100644 index 00000000..86475fa4 --- /dev/null +++ b/src/tests/reference_scalars.vtk @@ -0,0 +1,35 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Scalars 1 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 diff --git a/src/tests/reference_vector2d.vtk b/src/tests/reference_vector2d.vtk new file mode 100644 index 00000000..09085d4b --- /dev/null +++ b/src/tests/reference_vector2d.vtk @@ -0,0 +1,36 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Vector2D 2 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 12 13 14 15 16 17 +18 19 20 21 22 23 diff --git a/src/tests/reference_vector3d.vtk b/src/tests/reference_vector3d.vtk new file mode 100644 index 00000000..34e65562 --- /dev/null +++ b/src/tests/reference_vector3d.vtk @@ -0,0 +1,38 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Vector3D 3 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 12 13 14 15 16 17 +18 19 20 21 22 23 24 25 26 +27 28 29 30 31 32 33 34 35 + diff --git a/src/tests/scalarmd5 b/src/tests/scalarmd5 new file mode 100644 index 00000000..9744db02 --- /dev/null +++ b/src/tests/scalarmd5 @@ -0,0 +1 @@ +1f71cdb40a502bf0b2dc8a79e5143f4d write_test_scalars.vtk diff --git a/src/tests/vector2dmd5 b/src/tests/vector2dmd5 new file mode 100644 index 00000000..62278f08 --- /dev/null +++ b/src/tests/vector2dmd5 @@ -0,0 +1 @@ +402bd93cf239b957b07bc0ab91300f0c write_test_vector2d.vtk diff --git a/src/tests/vector3dmd5 b/src/tests/vector3dmd5 new file mode 100644 index 00000000..822e1c08 --- /dev/null +++ b/src/tests/vector3dmd5 @@ -0,0 +1 @@ +828aac3f5978ada1d4e5d0e46a2183a1 write_test_vector3d.vtk diff --git a/src/tests/write_test.cpp b/src/tests/write_test.cpp new file mode 100644 index 00000000..6751f833 --- /dev/null +++ b/src/tests/write_test.cpp @@ -0,0 +1,75 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + //if (argc != 2) { + // throw std::invalid_argument("Usage is ./executable test_type"); + // return 1; + //} + + auto test_name = std::string{argv[1]}; + + aste::Mesh testMesh; + + testMesh.positions.reserve(12); + + // Points for Quads and Tri Elements + for (double y = 0; y < 3.0; ++y) { + for (double x = 0; x < 3.0; ++x) { + const std::array pos{x, y, 0.0}; + testMesh.positions.push_back(pos); + } + } + //Points for Line Elements + for (double x = 4; x < 7.0; ++x) { + const std::array pos{x, 0.0, 0.0}; + testMesh.positions.push_back(pos); + } + + //Create Lines + std::array line1{9, 10}; + std::array line2{10, 11}; + testMesh.edges.push_back(line1); + testMesh.edges.push_back(line2); + + // Create Triangles + std::array tri1{0, 1, 3}; + std::array tri2{1, 4, 3}; + std::array tri3{1, 2, 4}; + std::array tri4{2, 4, 5}; + testMesh.triangles.push_back(tri1); + testMesh.triangles.push_back(tri2); + testMesh.triangles.push_back(tri3); + testMesh.triangles.push_back(tri4); + + //Create Quad Elements + std::array quad1{3, 4, 7, 6}; + std::array quad2{4, 5, 8, 7}; + testMesh.quadrilaterals.push_back(quad1); + testMesh.quadrilaterals.push_back(quad2); + + if (test_name == "scalar") { + //Create Scalar Data + testMesh.data.resize(testMesh.positions.size()); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto scalar_test = aste::BaseName{"write_test_scalars"}.with(aste::ExecutionContext()); + scalar_test.save(testMesh, "Scalars"); + } else if (test_name == "vector2d") { + // Create 2D Vector Data + testMesh.data.resize(testMesh.positions.size() * 2); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto vector2d_test = aste::BaseName{"write_test_vector2d"}.with(aste::ExecutionContext()); + vector2d_test.save(testMesh, "Vector2D"); + } else if (test_name == "vector3d") { + // Create 3D Vector Data + testMesh.data.resize(testMesh.positions.size() * 3); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto vector3d_test = aste::BaseName{"write_test_vector3d"}.with(aste::ExecutionContext()); + vector3d_test.save(testMesh, "Vector3D"); + } else { + throw std::invalid_argument("Invalid Test Type. Valid Test Types : scalar vector2d vector3d"); + return 1; + } +} From f847bac766bc9655bdbdf3bbab9a34fbfe51b3f2 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:53:42 +0000 Subject: [PATCH 05/25] Bug Fixes --- src/mesh.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 0ee423c2..be3d4401 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -108,7 +108,7 @@ void readMainFile(Mesh &mesh, const std::string &filename, const std::string &da } for (int i = 0; i < reader->GetUnstructuredGridOutput()->GetNumberOfCells(); i++) { - int cellType = reader->GetUnstructuredGridOutput()->GetCell(1)->GetCellType(); + int cellType = reader->GetUnstructuredGridOutput()->GetCell(i)->GetCellType(); if (cellType == VTK_TRIANGLE) { vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); @@ -147,7 +147,7 @@ void MeshName::createDirectories() const void MeshName::save(const Mesh &mesh, const std::string &dataname) const { - const int numComp = mesh.positions.size() / mesh.data.size(); + const int numComp = mesh.data.size() / mesh.positions.size(); vtkSmartPointer unstructuredGrid = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); vtkSmartPointer data = vtkDoubleArray::New(); @@ -156,59 +156,63 @@ void MeshName::save(const Mesh &mesh, const std::string &dataname) const data->SetNumberOfComponents(numComp); // Insert Points and Point Data - for (size_t i = 0; i < mesh.positions.size() - 1; i++) { + for (size_t i = 0; i < mesh.positions.size(); i++) { points->InsertNextPoint(mesh.positions[i][0], mesh.positions[i][1], mesh.positions[i][2]); - for (int j = 0; j < numComp; j++) - data->InsertNextTuple(&mesh.data[i * numComp + j]); + std::vector pointData; + for (int j = 0; j < numComp; j++) { + pointData.push_back(mesh.data[i * numComp + j]); + } + data->InsertNextTuple(pointData.data()); } unstructuredGrid->SetPoints(points); unstructuredGrid->GetPointData()->AddArray(data); // Connectivity Information + vtkSmartPointer cellArray = vtkSmartPointer::New(); + + std::vector cellTypes; + cellTypes.reserve(mesh.quadrilaterals.size() + mesh.triangles.size() + mesh.edges.size()); if (mesh.quadrilaterals.size() > 0) { - vtkSmartPointer quadArray = vtkSmartPointer::New(); + for (size_t i = 0; i < mesh.quadrilaterals.size(); i++) { vtkSmartPointer quadrilateral = vtkSmartPointer::New(); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][0]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][1]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][2]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][3]); + quadrilateral->GetPointIds()->SetId(1, mesh.quadrilaterals[i][1]); + quadrilateral->GetPointIds()->SetId(2, mesh.quadrilaterals[i][2]); + quadrilateral->GetPointIds()->SetId(3, mesh.quadrilaterals[i][3]); - quadArray->InsertNextCell(quadrilateral); + cellArray->InsertNextCell(quadrilateral); + cellTypes.push_back(VTK_QUAD); } - unstructuredGrid->SetCells(VTK_QUAD, quadArray); } if (mesh.triangles.size() > 0) { - vtkSmartPointer triArray = vtkSmartPointer::New(); for (size_t i = 0; i < mesh.triangles.size(); i++) { vtkSmartPointer triangle = vtkSmartPointer::New(); - triangle->GetPointIds()->SetId(0, mesh.triangles[i][0]); triangle->GetPointIds()->SetId(1, mesh.triangles[i][1]); triangle->GetPointIds()->SetId(2, mesh.triangles[i][2]); - triArray->InsertNextCell(triangle); + cellArray->InsertNextCell(triangle); + cellTypes.push_back(VTK_TRIANGLE); } - unstructuredGrid->SetCells(VTK_TRIANGLE, triArray); } if (mesh.edges.size() > 0) { - vtkSmartPointer lineArray = vtkSmartPointer::New(); for (size_t i = 0; i < mesh.edges.size(); i++) { vtkSmartPointer line = vtkSmartPointer::New(); - line->GetPointIds()->SetId(0, mesh.edges[i][0]); line->GetPointIds()->SetId(1, mesh.edges[i][1]); - lineArray->InsertNextCell(line); + cellArray->InsertNextCell(line); + cellTypes.push_back(VTK_LINE); } - unstructuredGrid->SetCells(VTK_LINE, lineArray); } + unstructuredGrid->SetCells(cellTypes.data(), cellArray); + // Write file vtkSmartPointer writer = vtkSmartPointer::New(); From c6d7ff166c33d3d367dd268870eeaa89dd548d62 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Sun, 10 Oct 2021 17:32:24 +0000 Subject: [PATCH 06/25] Add vector support for preCICE interface --- src/preciceMap.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/preciceMap.cpp b/src/preciceMap.cpp index 717129e0..8fc08f9c 100644 --- a/src/preciceMap.cpp +++ b/src/preciceMap.cpp @@ -189,10 +189,8 @@ int main(int argc, char *argv[]) if (interface.isActionRequired(precice::constants::actionWriteInitialData())) { VLOG(1) << "Write initial data for participant " << participant; if (isVector) { - assert(mesh.data.size() == vertexIDs.size() * dim); interface.writeBlockVectorData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); } else { - assert(mesh.data.size() == vertexIDs.size()); interface.writeBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); } VLOG(1) << "Data written: " << mesh.previewData(); @@ -208,7 +206,6 @@ int main(int argc, char *argv[]) auto roundmesh = meshes[round].load(dim, dataname); VLOG(1) << "This roundmesh contains: " << roundmesh.summary(); if (isVector) { - assert(roundmesh.data.size() == vertexIDs.size() * dim); interface.writeBlockVectorData(dataID, roundmesh.data.size(), vertexIDs.data(), roundmesh.data.data()); } else { assert(roundmesh.data.size() == vertexIDs.size()); From 9a29b481ed16452ba9b625b3131d58f55e966516 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Sun, 10 Oct 2021 17:37:20 +0000 Subject: [PATCH 07/25] Remove old test files --- src/tests/edges.conn.txt | 4 ---- src/tests/edges.txt | 4 ---- src/tests/simple.txt | 4 ---- src/tests/triangles.conn.txt | 2 -- src/tests/triangles.txt | 4 ---- 5 files changed, 18 deletions(-) delete mode 100644 src/tests/edges.conn.txt delete mode 100644 src/tests/edges.txt delete mode 100644 src/tests/simple.txt delete mode 100644 src/tests/triangles.conn.txt delete mode 100644 src/tests/triangles.txt diff --git a/src/tests/edges.conn.txt b/src/tests/edges.conn.txt deleted file mode 100644 index 88e903c0..00000000 --- a/src/tests/edges.conn.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 1 -0 2 -2 3 -1 3 diff --git a/src/tests/edges.txt b/src/tests/edges.txt deleted file mode 100644 index a61c92ba..00000000 --- a/src/tests/edges.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0 -0 0.0 1.0 0 -0 1.0 1.0 0 diff --git a/src/tests/simple.txt b/src/tests/simple.txt deleted file mode 100644 index e66c2bff..00000000 --- a/src/tests/simple.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0.1 -0 0.0 1.0 -0.2 -0 1.0 1.0 5.2 diff --git a/src/tests/triangles.conn.txt b/src/tests/triangles.conn.txt deleted file mode 100644 index 249f4cd1..00000000 --- a/src/tests/triangles.conn.txt +++ /dev/null @@ -1,2 +0,0 @@ -0 1 2 -1 3 2 diff --git a/src/tests/triangles.txt b/src/tests/triangles.txt deleted file mode 100644 index a61c92ba..00000000 --- a/src/tests/triangles.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 0.0 0.0 0 -0 1.0 0.0 0 -0 0.0 1.0 0 -0 1.0 1.0 0 From 7e64a438de81b0f042d5a0728bd02c68d10b2977 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:26:34 +0000 Subject: [PATCH 08/25] Add test executables and tests to CMake --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index deadc296..ba13f301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,20 @@ if(METIS_FOUND) target_link_libraries(preciceMap metisAPI) endif() +add_executable(write_test src/tests/write_test.cpp src/mesh.cpp) +target_include_directories(write_test PRIVATE src) +target_link_libraries(write_test + Boost::filesystem + ${VTK_LIBRARIES} +) + +add_executable(read_test src/tests/read_test.cpp src/mesh.cpp) +target_include_directories(read_test PRIVATE src) +target_link_libraries(read_test + Boost::filesystem + ${VTK_LIBRARIES} +) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/make_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/visualize_partition.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/partition_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -70,3 +84,21 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/eval_mesh.py DESTINATION ${C file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/vtk_calculator.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh_io.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +enable_testing() + +add_test(write_scalar write_test scalar) +add_test(check_scalar md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/scalarmd5) +set_tests_properties (check_scalar PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(write_vector2d write_test vector2d) +add_test(check_vector2d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector2dmd5) +set_tests_properties (check_vector2d PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(write_vector3d write_test vector3d) +add_test(check_vector3d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector3dmd5) +set_tests_properties (check_vector3d PROPERTIES PASS_REGULAR_EXPRESSION "OK") + +add_test(read_scalar read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_scalars 1 Scalars) +add_test(read_vector2d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector2d 2 Vector2D) +add_test(read_vector3d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector3d 3 Vector3D) From b0e6f05b5d6d8242d3ba279984a33318ddb207d7 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:52:49 +0000 Subject: [PATCH 09/25] Collect VTK includes and Remove Duplicates --- src/mesh.cpp | 8 ---- src/tests/read_test.cpp | 56 ++++++++++++++++++++++++ src/tests/reference_scalars.vtk | 35 +++++++++++++++ src/tests/reference_vector2d.vtk | 36 +++++++++++++++ src/tests/reference_vector3d.vtk | 38 ++++++++++++++++ src/tests/scalarmd5 | 1 + src/tests/vector2dmd5 | 1 + src/tests/vector3dmd5 | 1 + src/tests/write_test.cpp | 75 ++++++++++++++++++++++++++++++++ 9 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 src/tests/read_test.cpp create mode 100644 src/tests/reference_scalars.vtk create mode 100644 src/tests/reference_vector2d.vtk create mode 100644 src/tests/reference_vector3d.vtk create mode 100644 src/tests/scalarmd5 create mode 100644 src/tests/vector2dmd5 create mode 100644 src/tests/vector3dmd5 create mode 100644 src/tests/write_test.cpp diff --git a/src/mesh.cpp b/src/mesh.cpp index b6b5075c..0ee423c2 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -9,14 +9,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include - #include #include #include diff --git a/src/tests/read_test.cpp b/src/tests/read_test.cpp new file mode 100644 index 00000000..6fe8efba --- /dev/null +++ b/src/tests/read_test.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + auto filename = std::string{argv[1]}; + auto dim = std::stoi(argv[2]); + auto dataname = std::string{argv[3]}; + + auto read_test = aste::BaseName{filename}.with(aste::ExecutionContext()); + auto mesh = read_test.load(dim, dataname); + + assert(mesh.positions.size() == 12); + assert(mesh.edges.size() == 2); + assert(mesh.quadrilaterals.size() == 2); + assert(mesh.triangles.size() == 4); + std::cout << "Number of mesh elements are correctly loaded\n"; + + assert(mesh.edges[1][0] == 10); + assert(mesh.edges[1][1] == 11); + std::cout << "Edges loaded correctly\n"; + assert(mesh.triangles[0][0] == 0); + assert(mesh.triangles[0][1] == 1); + assert(mesh.triangles[0][2] == 3); + std::cout << "Triangles loaded correctly\n"; + assert(mesh.quadrilaterals[1][0] == 4); + assert(mesh.quadrilaterals[1][1] == 5); + assert(mesh.quadrilaterals[1][2] == 8); + assert(mesh.quadrilaterals[1][3] == 7); + std::cout << "Quads loaded correctly\n"; + + switch (dim) { + case 1: + assert(mesh.data.size() == 12); + break; + case 2: + assert(mesh.data.size() == 24); + break; + case 3: + assert(mesh.data.size() == 36); + break; + } + + std::vector testdata; + testdata.resize(mesh.data.size()); + + std::iota(testdata.begin(), testdata.end(), 0); + + for (size_t i = 0; i < mesh.data.size(); ++i) { + assert(mesh.data[i] == testdata[i]); + } + + return 0; +} diff --git a/src/tests/reference_scalars.vtk b/src/tests/reference_scalars.vtk new file mode 100644 index 00000000..86475fa4 --- /dev/null +++ b/src/tests/reference_scalars.vtk @@ -0,0 +1,35 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Scalars 1 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 diff --git a/src/tests/reference_vector2d.vtk b/src/tests/reference_vector2d.vtk new file mode 100644 index 00000000..09085d4b --- /dev/null +++ b/src/tests/reference_vector2d.vtk @@ -0,0 +1,36 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Vector2D 2 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 12 13 14 15 16 17 +18 19 20 21 22 23 diff --git a/src/tests/reference_vector3d.vtk b/src/tests/reference_vector3d.vtk new file mode 100644 index 00000000..34e65562 --- /dev/null +++ b/src/tests/reference_vector3d.vtk @@ -0,0 +1,38 @@ +# vtk DataFile Version 4.1 +vtk output +ASCII +DATASET UNSTRUCTURED_GRID +POINTS 12 float +0 0 0 1 0 0 2 0 0 +0 1 0 1 1 0 2 1 0 +0 2 0 1 2 0 2 2 0 +4 0 0 5 0 0 6 0 0 + +CELLS 8 32 +4 3 4 7 6 +4 4 5 8 7 +3 0 1 3 +3 1 4 3 +3 1 2 4 +3 2 4 5 +2 9 10 +2 10 11 + +CELL_TYPES 8 +9 +9 +5 +5 +5 +5 +3 +3 + +POINT_DATA 12 +FIELD FieldData 1 +Vector3D 3 12 double +0 1 2 3 4 5 6 7 8 +9 10 11 12 13 14 15 16 17 +18 19 20 21 22 23 24 25 26 +27 28 29 30 31 32 33 34 35 + diff --git a/src/tests/scalarmd5 b/src/tests/scalarmd5 new file mode 100644 index 00000000..9744db02 --- /dev/null +++ b/src/tests/scalarmd5 @@ -0,0 +1 @@ +1f71cdb40a502bf0b2dc8a79e5143f4d write_test_scalars.vtk diff --git a/src/tests/vector2dmd5 b/src/tests/vector2dmd5 new file mode 100644 index 00000000..62278f08 --- /dev/null +++ b/src/tests/vector2dmd5 @@ -0,0 +1 @@ +402bd93cf239b957b07bc0ab91300f0c write_test_vector2d.vtk diff --git a/src/tests/vector3dmd5 b/src/tests/vector3dmd5 new file mode 100644 index 00000000..822e1c08 --- /dev/null +++ b/src/tests/vector3dmd5 @@ -0,0 +1 @@ +828aac3f5978ada1d4e5d0e46a2183a1 write_test_vector3d.vtk diff --git a/src/tests/write_test.cpp b/src/tests/write_test.cpp new file mode 100644 index 00000000..6751f833 --- /dev/null +++ b/src/tests/write_test.cpp @@ -0,0 +1,75 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + //if (argc != 2) { + // throw std::invalid_argument("Usage is ./executable test_type"); + // return 1; + //} + + auto test_name = std::string{argv[1]}; + + aste::Mesh testMesh; + + testMesh.positions.reserve(12); + + // Points for Quads and Tri Elements + for (double y = 0; y < 3.0; ++y) { + for (double x = 0; x < 3.0; ++x) { + const std::array pos{x, y, 0.0}; + testMesh.positions.push_back(pos); + } + } + //Points for Line Elements + for (double x = 4; x < 7.0; ++x) { + const std::array pos{x, 0.0, 0.0}; + testMesh.positions.push_back(pos); + } + + //Create Lines + std::array line1{9, 10}; + std::array line2{10, 11}; + testMesh.edges.push_back(line1); + testMesh.edges.push_back(line2); + + // Create Triangles + std::array tri1{0, 1, 3}; + std::array tri2{1, 4, 3}; + std::array tri3{1, 2, 4}; + std::array tri4{2, 4, 5}; + testMesh.triangles.push_back(tri1); + testMesh.triangles.push_back(tri2); + testMesh.triangles.push_back(tri3); + testMesh.triangles.push_back(tri4); + + //Create Quad Elements + std::array quad1{3, 4, 7, 6}; + std::array quad2{4, 5, 8, 7}; + testMesh.quadrilaterals.push_back(quad1); + testMesh.quadrilaterals.push_back(quad2); + + if (test_name == "scalar") { + //Create Scalar Data + testMesh.data.resize(testMesh.positions.size()); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto scalar_test = aste::BaseName{"write_test_scalars"}.with(aste::ExecutionContext()); + scalar_test.save(testMesh, "Scalars"); + } else if (test_name == "vector2d") { + // Create 2D Vector Data + testMesh.data.resize(testMesh.positions.size() * 2); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto vector2d_test = aste::BaseName{"write_test_vector2d"}.with(aste::ExecutionContext()); + vector2d_test.save(testMesh, "Vector2D"); + } else if (test_name == "vector3d") { + // Create 3D Vector Data + testMesh.data.resize(testMesh.positions.size() * 3); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto vector3d_test = aste::BaseName{"write_test_vector3d"}.with(aste::ExecutionContext()); + vector3d_test.save(testMesh, "Vector3D"); + } else { + throw std::invalid_argument("Invalid Test Type. Valid Test Types : scalar vector2d vector3d"); + return 1; + } +} From 0e167793c90109516cf2f6aa3e8dad31f06f69b8 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 22:53:42 +0000 Subject: [PATCH 10/25] Bug Fixes --- src/mesh.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 0ee423c2..be3d4401 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -108,7 +108,7 @@ void readMainFile(Mesh &mesh, const std::string &filename, const std::string &da } for (int i = 0; i < reader->GetUnstructuredGridOutput()->GetNumberOfCells(); i++) { - int cellType = reader->GetUnstructuredGridOutput()->GetCell(1)->GetCellType(); + int cellType = reader->GetUnstructuredGridOutput()->GetCell(i)->GetCellType(); if (cellType == VTK_TRIANGLE) { vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); @@ -147,7 +147,7 @@ void MeshName::createDirectories() const void MeshName::save(const Mesh &mesh, const std::string &dataname) const { - const int numComp = mesh.positions.size() / mesh.data.size(); + const int numComp = mesh.data.size() / mesh.positions.size(); vtkSmartPointer unstructuredGrid = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); vtkSmartPointer data = vtkDoubleArray::New(); @@ -156,59 +156,63 @@ void MeshName::save(const Mesh &mesh, const std::string &dataname) const data->SetNumberOfComponents(numComp); // Insert Points and Point Data - for (size_t i = 0; i < mesh.positions.size() - 1; i++) { + for (size_t i = 0; i < mesh.positions.size(); i++) { points->InsertNextPoint(mesh.positions[i][0], mesh.positions[i][1], mesh.positions[i][2]); - for (int j = 0; j < numComp; j++) - data->InsertNextTuple(&mesh.data[i * numComp + j]); + std::vector pointData; + for (int j = 0; j < numComp; j++) { + pointData.push_back(mesh.data[i * numComp + j]); + } + data->InsertNextTuple(pointData.data()); } unstructuredGrid->SetPoints(points); unstructuredGrid->GetPointData()->AddArray(data); // Connectivity Information + vtkSmartPointer cellArray = vtkSmartPointer::New(); + + std::vector cellTypes; + cellTypes.reserve(mesh.quadrilaterals.size() + mesh.triangles.size() + mesh.edges.size()); if (mesh.quadrilaterals.size() > 0) { - vtkSmartPointer quadArray = vtkSmartPointer::New(); + for (size_t i = 0; i < mesh.quadrilaterals.size(); i++) { vtkSmartPointer quadrilateral = vtkSmartPointer::New(); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][0]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][1]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][2]); - quadrilateral->GetPointIds()->SetId(0, mesh.quadrilaterals[i][3]); + quadrilateral->GetPointIds()->SetId(1, mesh.quadrilaterals[i][1]); + quadrilateral->GetPointIds()->SetId(2, mesh.quadrilaterals[i][2]); + quadrilateral->GetPointIds()->SetId(3, mesh.quadrilaterals[i][3]); - quadArray->InsertNextCell(quadrilateral); + cellArray->InsertNextCell(quadrilateral); + cellTypes.push_back(VTK_QUAD); } - unstructuredGrid->SetCells(VTK_QUAD, quadArray); } if (mesh.triangles.size() > 0) { - vtkSmartPointer triArray = vtkSmartPointer::New(); for (size_t i = 0; i < mesh.triangles.size(); i++) { vtkSmartPointer triangle = vtkSmartPointer::New(); - triangle->GetPointIds()->SetId(0, mesh.triangles[i][0]); triangle->GetPointIds()->SetId(1, mesh.triangles[i][1]); triangle->GetPointIds()->SetId(2, mesh.triangles[i][2]); - triArray->InsertNextCell(triangle); + cellArray->InsertNextCell(triangle); + cellTypes.push_back(VTK_TRIANGLE); } - unstructuredGrid->SetCells(VTK_TRIANGLE, triArray); } if (mesh.edges.size() > 0) { - vtkSmartPointer lineArray = vtkSmartPointer::New(); for (size_t i = 0; i < mesh.edges.size(); i++) { vtkSmartPointer line = vtkSmartPointer::New(); - line->GetPointIds()->SetId(0, mesh.edges[i][0]); line->GetPointIds()->SetId(1, mesh.edges[i][1]); - lineArray->InsertNextCell(line); + cellArray->InsertNextCell(line); + cellTypes.push_back(VTK_LINE); } - unstructuredGrid->SetCells(VTK_LINE, lineArray); } + unstructuredGrid->SetCells(cellTypes.data(), cellArray); + // Write file vtkSmartPointer writer = vtkSmartPointer::New(); From 63ed703a91c167053a56f6ef817cab24e91d69d1 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Mon, 11 Oct 2021 23:10:10 +0000 Subject: [PATCH 11/25] Add mistakenly removed assertions --- src/preciceMap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/preciceMap.cpp b/src/preciceMap.cpp index 8fc08f9c..717129e0 100644 --- a/src/preciceMap.cpp +++ b/src/preciceMap.cpp @@ -189,8 +189,10 @@ int main(int argc, char *argv[]) if (interface.isActionRequired(precice::constants::actionWriteInitialData())) { VLOG(1) << "Write initial data for participant " << participant; if (isVector) { + assert(mesh.data.size() == vertexIDs.size() * dim); interface.writeBlockVectorData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); } else { + assert(mesh.data.size() == vertexIDs.size()); interface.writeBlockScalarData(dataID, mesh.data.size(), vertexIDs.data(), mesh.data.data()); } VLOG(1) << "Data written: " << mesh.previewData(); @@ -206,6 +208,7 @@ int main(int argc, char *argv[]) auto roundmesh = meshes[round].load(dim, dataname); VLOG(1) << "This roundmesh contains: " << roundmesh.summary(); if (isVector) { + assert(roundmesh.data.size() == vertexIDs.size() * dim); interface.writeBlockVectorData(dataID, roundmesh.data.size(), vertexIDs.data(), roundmesh.data.data()); } else { assert(roundmesh.data.size() == vertexIDs.size()); From 5d483099441c357f2b2779b5f60a0955c34e9cdf Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Wed, 13 Oct 2021 18:08:19 +0000 Subject: [PATCH 12/25] Change CMake file for Boost Test --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba13f301..6ab2ea39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ find_package (Threads REQUIRED) find_package(precice REQUIRED CONFIG) -find_package(Boost 1.65.1 REQUIRED COMPONENTS system program_options filesystem) +find_package(Boost 1.65.1 REQUIRED COMPONENTS system program_options filesystem unit_test_framework) find_package(VTK REQUIRED) if (VTK_FOUND) @@ -66,6 +66,8 @@ add_executable(write_test src/tests/write_test.cpp src/mesh.cpp) target_include_directories(write_test PRIVATE src) target_link_libraries(write_test Boost::filesystem + Boost::boost + Boost::unit_test_framework ${VTK_LIBRARIES} ) @@ -73,7 +75,9 @@ add_executable(read_test src/tests/read_test.cpp src/mesh.cpp) target_include_directories(read_test PRIVATE src) target_link_libraries(read_test Boost::filesystem - ${VTK_LIBRARIES} + Boost::boost + Boost::unit_test_framework + ${VTK_LIBRARIES} ) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/make_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -98,7 +102,3 @@ set_tests_properties (check_vector2d PROPERTIES PASS_REGULAR_EXPRESSION "OK") add_test(write_vector3d write_test vector3d) add_test(check_vector3d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector3dmd5) set_tests_properties (check_vector3d PROPERTIES PASS_REGULAR_EXPRESSION "OK") - -add_test(read_scalar read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_scalars 1 Scalars) -add_test(read_vector2d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector2d 2 Vector2D) -add_test(read_vector3d read_test ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/reference_vector3d 3 Vector3D) From d12c42de514713e14f2337848b77e6fe7bf31522 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Wed, 13 Oct 2021 18:08:44 +0000 Subject: [PATCH 13/25] Convert Read Test to A Boost Unit Test --- src/tests/read_test.cpp | 111 +++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/src/tests/read_test.cpp b/src/tests/read_test.cpp index 6fe8efba..c0e2429a 100644 --- a/src/tests/read_test.cpp +++ b/src/tests/read_test.cpp @@ -1,56 +1,75 @@ + +#define BOOST_TEST_MODULE ASTE +#define BOOST_TEST_DYN_LINK +#include + #include #include #include +#include +#include + +struct Case { + std::string fname{}; + std::string dataname{}; + int dim{}; +}; + +std::vector Cases; + +BOOST_AUTO_TEST_SUITE(read_test) + +BOOST_AUTO_TEST_CASE(read_test) -int main(int argc, char *argv[]) { + //Add Cases Here + Cases.push_back(Case{"../src/tests/reference_scalars", "Scalars", 1}); + Cases.push_back(Case{"../src/tests/reference_vector2d", "Vector2D", 2}); + Cases.push_back(Case{"../src/tests/reference_vector3d", "Vector3D", 3}); - auto filename = std::string{argv[1]}; - auto dim = std::stoi(argv[2]); - auto dataname = std::string{argv[3]}; - - auto read_test = aste::BaseName{filename}.with(aste::ExecutionContext()); - auto mesh = read_test.load(dim, dataname); - - assert(mesh.positions.size() == 12); - assert(mesh.edges.size() == 2); - assert(mesh.quadrilaterals.size() == 2); - assert(mesh.triangles.size() == 4); - std::cout << "Number of mesh elements are correctly loaded\n"; - - assert(mesh.edges[1][0] == 10); - assert(mesh.edges[1][1] == 11); - std::cout << "Edges loaded correctly\n"; - assert(mesh.triangles[0][0] == 0); - assert(mesh.triangles[0][1] == 1); - assert(mesh.triangles[0][2] == 3); - std::cout << "Triangles loaded correctly\n"; - assert(mesh.quadrilaterals[1][0] == 4); - assert(mesh.quadrilaterals[1][1] == 5); - assert(mesh.quadrilaterals[1][2] == 8); - assert(mesh.quadrilaterals[1][3] == 7); - std::cout << "Quads loaded correctly\n"; - - switch (dim) { - case 1: - assert(mesh.data.size() == 12); - break; - case 2: - assert(mesh.data.size() == 24); - break; - case 3: - assert(mesh.data.size() == 36); - break; - } + for (auto current_case : Cases) { + auto read_test = aste::BaseName{current_case.fname}.with(aste::ExecutionContext()); + auto mesh = read_test.load(current_case.dim, current_case.dataname); - std::vector testdata; - testdata.resize(mesh.data.size()); + BOOST_TEST(mesh.positions.size() == 12); + BOOST_TEST(mesh.edges.size() == 2); + BOOST_TEST(mesh.quadrilaterals.size() == 2); + BOOST_TEST(mesh.triangles.size() == 4); + //std::cout << "Number of mesh elements are correctly loaded\n"; - std::iota(testdata.begin(), testdata.end(), 0); + BOOST_TEST(mesh.edges[1][0] == 10); + BOOST_TEST(mesh.edges[1][1] == 11); + //std::cout << "Edges loaded correctly\n"; + BOOST_TEST(mesh.triangles[0][0] == 0); + BOOST_TEST(mesh.triangles[0][1] == 1); + BOOST_TEST(mesh.triangles[0][2] == 3); + //std::cout << "Triangles loaded correctly\n"; + BOOST_TEST(mesh.quadrilaterals[1][0] == 4); + BOOST_TEST(mesh.quadrilaterals[1][1] == 5); + BOOST_TEST(mesh.quadrilaterals[1][2] == 8); + BOOST_TEST(mesh.quadrilaterals[1][3] == 7); + //std::cout << "Quads loaded correctly\n"; - for (size_t i = 0; i < mesh.data.size(); ++i) { - assert(mesh.data[i] == testdata[i]); - } + switch (current_case.dim) { + case 1: + BOOST_TEST(mesh.data.size() == 12); + break; + case 2: + BOOST_TEST(mesh.data.size() == 24); + break; + case 3: + BOOST_TEST(mesh.data.size() == 36); + break; + } + + std::vector testdata; + testdata.resize(mesh.data.size()); - return 0; -} + std::iota(testdata.begin(), testdata.end(), 0); + + for (size_t i = 0; i < mesh.data.size(); ++i) { + BOOST_TEST(mesh.data[i] == testdata[i]); + } + } +} // End of test suite +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 7a5103f3a51c503c75fdf8c631a54b39f265f869 Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Thu, 14 Oct 2021 12:53:26 +0200 Subject: [PATCH 14/25] Add static_cast to PointId's --- src/mesh.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index be3d4401..92098995 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -110,17 +110,18 @@ void readMainFile(Mesh &mesh, const std::string &filename, const std::string &da for (int i = 0; i < reader->GetUnstructuredGridOutput()->GetNumberOfCells(); i++) { int cellType = reader->GetUnstructuredGridOutput()->GetCell(i)->GetCellType(); + //Here we use static cast since VTK library returns a long long unsigned int however preCICE uses int for PointId's if (cellType == VTK_TRIANGLE) { vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{cell->GetPointId(0), cell->GetPointId(1), cell->GetPointId(2)}; + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2))}; mesh.triangles.push_back(elem); } else if (cellType == VTK_LINE) { vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{cell->GetPointId(0), cell->GetPointId(1)}; + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1))}; mesh.edges.push_back(elem); } else if (cellType == VTK_QUAD) { vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{cell->GetPointId(0), cell->GetPointId(1), cell->GetPointId(2), cell->GetPointId(3)}; + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2)), static_cast(cell->GetPointId(3))}; mesh.quadrilaterals.push_back(elem); } else { throw std::runtime_error{ From 626ac5327a99a7f84a3708aaf3aa5f65848012ca Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Fri, 15 Oct 2021 21:17:17 +0000 Subject: [PATCH 15/25] Remove md5sum data --- src/tests/scalarmd5 | 1 - src/tests/vector2dmd5 | 1 - src/tests/vector3dmd5 | 1 - 3 files changed, 3 deletions(-) delete mode 100644 src/tests/scalarmd5 delete mode 100644 src/tests/vector2dmd5 delete mode 100644 src/tests/vector3dmd5 diff --git a/src/tests/scalarmd5 b/src/tests/scalarmd5 deleted file mode 100644 index 9744db02..00000000 --- a/src/tests/scalarmd5 +++ /dev/null @@ -1 +0,0 @@ -1f71cdb40a502bf0b2dc8a79e5143f4d write_test_scalars.vtk diff --git a/src/tests/vector2dmd5 b/src/tests/vector2dmd5 deleted file mode 100644 index 62278f08..00000000 --- a/src/tests/vector2dmd5 +++ /dev/null @@ -1 +0,0 @@ -402bd93cf239b957b07bc0ab91300f0c write_test_vector2d.vtk diff --git a/src/tests/vector3dmd5 b/src/tests/vector3dmd5 deleted file mode 100644 index 822e1c08..00000000 --- a/src/tests/vector3dmd5 +++ /dev/null @@ -1 +0,0 @@ -828aac3f5978ada1d4e5d0e46a2183a1 write_test_vector3d.vtk From 0064b13018c15aeea586a85caa40d953a09e091a Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Fri, 15 Oct 2021 21:17:39 +0000 Subject: [PATCH 16/25] Change CMake to single test file --- CMakeLists.txt | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ab2ea39..b0245b1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,24 +62,15 @@ if(METIS_FOUND) target_link_libraries(preciceMap metisAPI) endif() -add_executable(write_test src/tests/write_test.cpp src/mesh.cpp) -target_include_directories(write_test PRIVATE src) -target_link_libraries(write_test +add_executable(testing src/tests/testing.cpp src/tests/read_test.cpp src/tests/write_test.cpp src/mesh.cpp) +target_include_directories(testing PRIVATE src) +target_link_libraries(testing Boost::filesystem Boost::boost Boost::unit_test_framework ${VTK_LIBRARIES} ) -add_executable(read_test src/tests/read_test.cpp src/mesh.cpp) -target_include_directories(read_test PRIVATE src) -target_link_libraries(read_test - Boost::filesystem - Boost::boost - Boost::unit_test_framework - ${VTK_LIBRARIES} -) - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/make_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/visualize_partition.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/partition_mesh.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -91,14 +82,5 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/mesh.py DESTINATION ${C enable_testing() -add_test(write_scalar write_test scalar) -add_test(check_scalar md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/scalarmd5) -set_tests_properties (check_scalar PROPERTIES PASS_REGULAR_EXPRESSION "OK") - -add_test(write_vector2d write_test vector2d) -add_test(check_vector2d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector2dmd5) -set_tests_properties (check_vector2d PROPERTIES PASS_REGULAR_EXPRESSION "OK") +add_test(read_write_test testing) -add_test(write_vector3d write_test vector3d) -add_test(check_vector3d md5sum -c ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/vector3dmd5) -set_tests_properties (check_vector3d PROPERTIES PASS_REGULAR_EXPRESSION "OK") From 8c74da72c3bc2427af86afcecaa789ad6b533b83 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Fri, 15 Oct 2021 21:28:00 +0000 Subject: [PATCH 17/25] Change read/write test to void functions --- src/tests/read_test.cpp | 109 +++++++++++++++------------------------ src/tests/write_test.cpp | 65 +++++++++++------------ 2 files changed, 74 insertions(+), 100 deletions(-) diff --git a/src/tests/read_test.cpp b/src/tests/read_test.cpp index c0e2429a..578f0fba 100644 --- a/src/tests/read_test.cpp +++ b/src/tests/read_test.cpp @@ -1,75 +1,48 @@ +#include "testing.hpp" -#define BOOST_TEST_MODULE ASTE -#define BOOST_TEST_DYN_LINK -#include - -#include -#include -#include -#include -#include - -struct Case { - std::string fname{}; - std::string dataname{}; - int dim{}; -}; - -std::vector Cases; - -BOOST_AUTO_TEST_SUITE(read_test) - -BOOST_AUTO_TEST_CASE(read_test) - +void readtest(const Case ¤t_case) { - //Add Cases Here - Cases.push_back(Case{"../src/tests/reference_scalars", "Scalars", 1}); - Cases.push_back(Case{"../src/tests/reference_vector2d", "Vector2D", 2}); - Cases.push_back(Case{"../src/tests/reference_vector3d", "Vector3D", 3}); - - for (auto current_case : Cases) { - auto read_test = aste::BaseName{current_case.fname}.with(aste::ExecutionContext()); - auto mesh = read_test.load(current_case.dim, current_case.dataname); - - BOOST_TEST(mesh.positions.size() == 12); - BOOST_TEST(mesh.edges.size() == 2); - BOOST_TEST(mesh.quadrilaterals.size() == 2); - BOOST_TEST(mesh.triangles.size() == 4); - //std::cout << "Number of mesh elements are correctly loaded\n"; - BOOST_TEST(mesh.edges[1][0] == 10); - BOOST_TEST(mesh.edges[1][1] == 11); - //std::cout << "Edges loaded correctly\n"; - BOOST_TEST(mesh.triangles[0][0] == 0); - BOOST_TEST(mesh.triangles[0][1] == 1); - BOOST_TEST(mesh.triangles[0][2] == 3); - //std::cout << "Triangles loaded correctly\n"; - BOOST_TEST(mesh.quadrilaterals[1][0] == 4); - BOOST_TEST(mesh.quadrilaterals[1][1] == 5); - BOOST_TEST(mesh.quadrilaterals[1][2] == 8); - BOOST_TEST(mesh.quadrilaterals[1][3] == 7); - //std::cout << "Quads loaded correctly\n"; - - switch (current_case.dim) { - case 1: - BOOST_TEST(mesh.data.size() == 12); - break; - case 2: - BOOST_TEST(mesh.data.size() == 24); - break; - case 3: - BOOST_TEST(mesh.data.size() == 36); - break; - } + auto read_test = aste::BaseName{current_case.fname}.with(aste::ExecutionContext()); + auto mesh = read_test.load(current_case.dim, current_case.dataname); + + BOOST_TEST(mesh.positions.size() == 12); + BOOST_TEST(mesh.edges.size() == 2); + BOOST_TEST(mesh.quadrilaterals.size() == 2); + BOOST_TEST(mesh.triangles.size() == 4); + //std::cout << "Number of mesh elements are correctly loaded\n"; + + BOOST_TEST(mesh.edges[1][0] == 10); + BOOST_TEST(mesh.edges[1][1] == 11); + //std::cout << "Edges loaded correctly\n"; + BOOST_TEST(mesh.triangles[0][0] == 0); + BOOST_TEST(mesh.triangles[0][1] == 1); + BOOST_TEST(mesh.triangles[0][2] == 3); + //std::cout << "Triangles loaded correctly\n"; + BOOST_TEST(mesh.quadrilaterals[1][0] == 4); + BOOST_TEST(mesh.quadrilaterals[1][1] == 5); + BOOST_TEST(mesh.quadrilaterals[1][2] == 8); + BOOST_TEST(mesh.quadrilaterals[1][3] == 7); + //std::cout << "Quads loaded correctly\n"; + + switch (current_case.dim) { + case 1: + BOOST_TEST(mesh.data.size() == 12); + break; + case 2: + BOOST_TEST(mesh.data.size() == 24); + break; + case 3: + BOOST_TEST(mesh.data.size() == 36); + break; + } - std::vector testdata; - testdata.resize(mesh.data.size()); + std::vector testdata; + testdata.resize(mesh.data.size()); - std::iota(testdata.begin(), testdata.end(), 0); + std::iota(testdata.begin(), testdata.end(), 0); - for (size_t i = 0; i < mesh.data.size(); ++i) { - BOOST_TEST(mesh.data[i] == testdata[i]); - } + for (size_t i = 0; i < mesh.data.size(); ++i) { + BOOST_TEST(mesh.data[i] == testdata[i]); } -} // End of test suite -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} \ No newline at end of file diff --git a/src/tests/write_test.cpp b/src/tests/write_test.cpp index 6751f833..a01a8846 100644 --- a/src/tests/write_test.cpp +++ b/src/tests/write_test.cpp @@ -1,18 +1,9 @@ -#include -#include -#include +#include "testing.hpp" -int main(int argc, char *argv[]) +void writetest(const Case ¤t_case) { - //if (argc != 2) { - // throw std::invalid_argument("Usage is ./executable test_type"); - // return 1; - //} - - auto test_name = std::string{argv[1]}; aste::Mesh testMesh; - testMesh.positions.reserve(12); // Points for Quads and Tri Elements @@ -50,26 +41,36 @@ int main(int argc, char *argv[]) testMesh.quadrilaterals.push_back(quad1); testMesh.quadrilaterals.push_back(quad2); - if (test_name == "scalar") { - //Create Scalar Data - testMesh.data.resize(testMesh.positions.size()); - std::iota(testMesh.data.begin(), testMesh.data.end(), 0); - auto scalar_test = aste::BaseName{"write_test_scalars"}.with(aste::ExecutionContext()); - scalar_test.save(testMesh, "Scalars"); - } else if (test_name == "vector2d") { - // Create 2D Vector Data - testMesh.data.resize(testMesh.positions.size() * 2); - std::iota(testMesh.data.begin(), testMesh.data.end(), 0); - auto vector2d_test = aste::BaseName{"write_test_vector2d"}.with(aste::ExecutionContext()); - vector2d_test.save(testMesh, "Vector2D"); - } else if (test_name == "vector3d") { - // Create 3D Vector Data - testMesh.data.resize(testMesh.positions.size() * 3); - std::iota(testMesh.data.begin(), testMesh.data.end(), 0); - auto vector3d_test = aste::BaseName{"write_test_vector3d"}.with(aste::ExecutionContext()); - vector3d_test.save(testMesh, "Vector3D"); - } else { - throw std::invalid_argument("Invalid Test Type. Valid Test Types : scalar vector2d vector3d"); - return 1; + testMesh.data.resize(testMesh.positions.size() * current_case.dim); + std::iota(testMesh.data.begin(), testMesh.data.end(), 0); + auto scalar_test = aste::BaseName{current_case.fname}.with(aste::ExecutionContext()); + scalar_test.save(testMesh, current_case.dataname); + + // Read written data and compare with created data + auto read = aste::BaseName{current_case.fname}.with(aste::ExecutionContext()); + auto loadedMesh = read.load(current_case.dim, current_case.dataname); + + //Check Elements are correctly written + BOOST_TEST(loadedMesh.positions.size() == testMesh.positions.size()); + BOOST_TEST(loadedMesh.edges.size() == testMesh.edges.size()); + BOOST_TEST(loadedMesh.quadrilaterals.size() == testMesh.quadrilaterals.size()); + BOOST_TEST(loadedMesh.triangles.size() == testMesh.triangles.size()); + //Check Edges + BOOST_TEST(loadedMesh.edges[1][0] == testMesh.edges[1][0]); + BOOST_TEST(loadedMesh.edges[1][1] == testMesh.edges[1][1]); + //Check Triangles + BOOST_TEST(loadedMesh.triangles[0][0] == testMesh.triangles[0][0]); + BOOST_TEST(loadedMesh.triangles[0][1] == testMesh.triangles[0][1]); + BOOST_TEST(loadedMesh.triangles[0][2] == testMesh.triangles[0][2]); + //Check Quads + BOOST_TEST(loadedMesh.quadrilaterals[1][0] == testMesh.quadrilaterals[1][0]); + BOOST_TEST(loadedMesh.quadrilaterals[1][1] == testMesh.quadrilaterals[1][1]); + BOOST_TEST(loadedMesh.quadrilaterals[1][2] == testMesh.quadrilaterals[1][2]); + BOOST_TEST(loadedMesh.quadrilaterals[1][3] == testMesh.quadrilaterals[1][3]); + //Check Datasize + BOOST_TEST(loadedMesh.data.size() == testMesh.data.size()); + //Check Data Values + for (size_t i = 0; i < loadedMesh.data.size(); ++i) { + BOOST_TEST(loadedMesh.data[i] == testMesh.data[i]); } } From 7fbf001705cd7cd70fa025487bad87e1be84d6d3 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Fri, 15 Oct 2021 21:28:28 +0000 Subject: [PATCH 18/25] Add test to a main test file --- src/tests/testing.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/tests/testing.hpp | 13 +++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/tests/testing.cpp create mode 100644 src/tests/testing.hpp diff --git a/src/tests/testing.cpp b/src/tests/testing.cpp new file mode 100644 index 00000000..498a9a8c --- /dev/null +++ b/src/tests/testing.cpp @@ -0,0 +1,37 @@ +#define BOOST_TEST_MODULE ASTE +#define BOOST_TEST_DYN_LINK +#include "testing.hpp" + +BOOST_AUTO_TEST_SUITE(read_write_tests) + +BOOST_AUTO_TEST_CASE(read_test_scalar) +{ + readtest(Case{"../src/tests/reference_scalars", "Scalars", 1}); +} + +BOOST_AUTO_TEST_CASE(read_test_2dvector) +{ + readtest(Case{"../src/tests/reference_vector2d", "Vector2D", 2}); +} + +BOOST_AUTO_TEST_CASE(read_test_3dvector) +{ + readtest(Case{"../src/tests/reference_vector3d", "Vector3D", 3}); +} + +BOOST_AUTO_TEST_CASE(write_test_scalar) +{ + writetest(Case{"../src/tests/reference_scalars", "Scalars", 1}); +} + +BOOST_AUTO_TEST_CASE(write_test_2dvector) +{ + writetest(Case{"../src/tests/reference_vector2d", "Vector2D", 2}); +} + +BOOST_AUTO_TEST_CASE(write_test_3dvector) +{ + writetest(Case{"../src/tests/reference_vector3d", "Vector3D", 3}); +} + +BOOST_AUTO_TEST_SUITE_END() //read_write_tests \ No newline at end of file diff --git a/src/tests/testing.hpp b/src/tests/testing.hpp new file mode 100644 index 00000000..60c3aa33 --- /dev/null +++ b/src/tests/testing.hpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +struct Case { + std::string fname{}; + std::string dataname{}; + int dim{}; +}; + +void writetest(const Case ¤t_case); +void readtest(const Case ¤t_case); From c1f5d0ed67dc085a6cb7debf4d686cf71342bdbb Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Sun, 17 Oct 2021 12:42:12 +0000 Subject: [PATCH 19/25] Ignore vscode directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5dc1aacf..ec633d61 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ testMesh.txt *.synctex.gz compile_commands.json build/ +.vscode/* \ No newline at end of file From 79fd90aed088ac6967b3794a1bf6f2b48d90e2c9 Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Mon, 25 Oct 2021 15:17:19 +0200 Subject: [PATCH 20/25] Change from size_t arrays to int array to keep it consistent with preCICE interface --- src/mesh.cpp | 12 ++++++------ src/mesh.hpp | 6 +++--- src/tests/write_test.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 92098995..cfb67d66 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -112,16 +112,16 @@ void readMainFile(Mesh &mesh, const std::string &filename, const std::string &da //Here we use static cast since VTK library returns a long long unsigned int however preCICE uses int for PointId's if (cellType == VTK_TRIANGLE) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2))}; mesh.triangles.push_back(elem); } else if (cellType == VTK_LINE) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1))}; mesh.edges.push_back(elem); } else if (cellType == VTK_QUAD) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2)), static_cast(cell->GetPointId(3))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2)), static_cast(cell->GetPointId(3))}; mesh.quadrilaterals.push_back(elem); } else { throw std::runtime_error{ diff --git a/src/mesh.hpp b/src/mesh.hpp index db716f3a..239982dd 100644 --- a/src/mesh.hpp +++ b/src/mesh.hpp @@ -73,9 +73,9 @@ class BaseName { struct Mesh { using Vertex = std::array; - using Edge = std::array; - using Triangle = std::array; - using Quad = std::array; + using Edge = std::array; + using Triangle = std::array; + using Quad = std::array; std::vector positions; std::vector edges; std::vector triangles; diff --git a/src/tests/write_test.cpp b/src/tests/write_test.cpp index a01a8846..a643131d 100644 --- a/src/tests/write_test.cpp +++ b/src/tests/write_test.cpp @@ -20,24 +20,24 @@ void writetest(const Case ¤t_case) } //Create Lines - std::array line1{9, 10}; - std::array line2{10, 11}; + std::array line1{9, 10}; + std::array line2{10, 11}; testMesh.edges.push_back(line1); testMesh.edges.push_back(line2); // Create Triangles - std::array tri1{0, 1, 3}; - std::array tri2{1, 4, 3}; - std::array tri3{1, 2, 4}; - std::array tri4{2, 4, 5}; + std::array tri1{0, 1, 3}; + std::array tri2{1, 4, 3}; + std::array tri3{1, 2, 4}; + std::array tri4{2, 4, 5}; testMesh.triangles.push_back(tri1); testMesh.triangles.push_back(tri2); testMesh.triangles.push_back(tri3); testMesh.triangles.push_back(tri4); //Create Quad Elements - std::array quad1{3, 4, 7, 6}; - std::array quad2{4, 5, 8, 7}; + std::array quad1{3, 4, 7, 6}; + std::array quad2{4, 5, 8, 7}; testMesh.quadrilaterals.push_back(quad1); testMesh.quadrilaterals.push_back(quad2); From 95fa4e7b266a2cba2e04d8a17775c44dce6ffdea Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Tue, 26 Oct 2021 14:07:17 +0200 Subject: [PATCH 21/25] Add new functionality to safely cast from vtkIDtype to preCICE --- src/mesh.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index cfb67d66..3f80b5d6 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -33,11 +33,21 @@ std::string MeshName::filename() const return _mname + ".vtk"; } +namespace aste { + +} +namespace { +Mesh::VID vtkToPos(vtkIdType id) +{ + assert(id >= 0); + return static_cast(id); +} +} // namespace + namespace { // Reads the main file containing the vertices and data void readMainFile(Mesh &mesh, const std::string &filename, const std::string &dataname, const int &dim) { - if (!fs::is_regular_file(filename)) { throw std::invalid_argument{"The mesh file does not exist: " + filename}; } @@ -112,16 +122,16 @@ void readMainFile(Mesh &mesh, const std::string &filename, const std::string &da //Here we use static cast since VTK library returns a long long unsigned int however preCICE uses int for PointId's if (cellType == VTK_TRIANGLE) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1)), vtkToPos(cell->GetPointId(2))}; mesh.triangles.push_back(elem); } else if (cellType == VTK_LINE) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1))}; mesh.edges.push_back(elem); } else if (cellType == VTK_QUAD) { - vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); - std::array elem{static_cast(cell->GetPointId(0)), static_cast(cell->GetPointId(1)), static_cast(cell->GetPointId(2)), static_cast(cell->GetPointId(3))}; + vtkCell * cell = reader->GetUnstructuredGridOutput()->GetCell(i); + std::array elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1)), vtkToPos(cell->GetPointId(2)), vtkToPos(cell->GetPointId(3))}; mesh.quadrilaterals.push_back(elem); } else { throw std::runtime_error{ From 51fa3a03e374a220ab338d74e84fe06935ebd4ac Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Tue, 26 Oct 2021 14:07:53 +0200 Subject: [PATCH 22/25] Add VID to mesh --- src/mesh.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mesh.hpp b/src/mesh.hpp index 239982dd..1ea84fb2 100644 --- a/src/mesh.hpp +++ b/src/mesh.hpp @@ -71,11 +71,15 @@ class BaseName { std::string _bname; }; +namespace aste { + +} // namespace aste struct Mesh { using Vertex = std::array; - using Edge = std::array; - using Triangle = std::array; - using Quad = std::array; + using VID = std::vector::size_type; + using Edge = std::array; + using Triangle = std::array; + using Quad = std::array; std::vector positions; std::vector edges; std::vector triangles; From fdef25e1dae27a4fc36b3ecb7730ab8b7dacb9e6 Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Tue, 26 Oct 2021 14:08:08 +0200 Subject: [PATCH 23/25] Correct write test cases --- src/tests/testing.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/testing.cpp b/src/tests/testing.cpp index 498a9a8c..37ba81e5 100644 --- a/src/tests/testing.cpp +++ b/src/tests/testing.cpp @@ -21,17 +21,17 @@ BOOST_AUTO_TEST_CASE(read_test_3dvector) BOOST_AUTO_TEST_CASE(write_test_scalar) { - writetest(Case{"../src/tests/reference_scalars", "Scalars", 1}); + writetest(Case{"./scalar_write", "Scalars", 1}); } BOOST_AUTO_TEST_CASE(write_test_2dvector) { - writetest(Case{"../src/tests/reference_vector2d", "Vector2D", 2}); + writetest(Case{"./vector2d_write", "Vector2D", 2}); } BOOST_AUTO_TEST_CASE(write_test_3dvector) { - writetest(Case{"../src/tests/reference_vector3d", "Vector3D", 3}); + writetest(Case{"./vector3d_write", "Vector3D", 3}); } BOOST_AUTO_TEST_SUITE_END() //read_write_tests \ No newline at end of file From d6f06e60ce565c743986f0ce804d5c7bbcaede40 Mon Sep 17 00:00:00 2001 From: Kursat_Yurt Date: Tue, 26 Oct 2021 14:08:38 +0200 Subject: [PATCH 24/25] Adapt VID instead of int type arrays --- src/tests/write_test.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tests/write_test.cpp b/src/tests/write_test.cpp index a643131d..1d051b74 100644 --- a/src/tests/write_test.cpp +++ b/src/tests/write_test.cpp @@ -2,6 +2,7 @@ void writetest(const Case ¤t_case) { + using VID = aste::Mesh::VID; aste::Mesh testMesh; testMesh.positions.reserve(12); @@ -20,24 +21,24 @@ void writetest(const Case ¤t_case) } //Create Lines - std::array line1{9, 10}; - std::array line2{10, 11}; + std::array line1{9, 10}; + std::array line2{10, 11}; testMesh.edges.push_back(line1); testMesh.edges.push_back(line2); // Create Triangles - std::array tri1{0, 1, 3}; - std::array tri2{1, 4, 3}; - std::array tri3{1, 2, 4}; - std::array tri4{2, 4, 5}; + std::array tri1{0, 1, 3}; + std::array tri2{1, 4, 3}; + std::array tri3{1, 2, 4}; + std::array tri4{2, 4, 5}; testMesh.triangles.push_back(tri1); testMesh.triangles.push_back(tri2); testMesh.triangles.push_back(tri3); testMesh.triangles.push_back(tri4); //Create Quad Elements - std::array quad1{3, 4, 7, 6}; - std::array quad2{4, 5, 8, 7}; + std::array quad1{3, 4, 7, 6}; + std::array quad2{4, 5, 8, 7}; testMesh.quadrilaterals.push_back(quad1); testMesh.quadrilaterals.push_back(quad2); From 7c2efcdd0cec9eada5ba3ac5dbb27b6464e19bd5 Mon Sep 17 00:00:00 2001 From: kursatyurt Date: Tue, 26 Oct 2021 12:41:48 +0000 Subject: [PATCH 25/25] Add init and final time and corrrect timesteps --- src/mesh.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index cfb67d66..d568052f 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -250,12 +250,22 @@ std::vector BaseName::findAll(const ExecutionContext &context) const // Check multiple timesteps std::vector meshNames; - for (int t = 0; true; ++t) { + for (int t = 1; true; ++t) { std::string stepMeshName = _bname + ".dt" + std::to_string(t); if (!fs::is_regular_file(stepMeshName + ".vtk")) break; meshNames.push_back(MeshName{stepMeshName}); } + { + auto initMeshName = std::string{_bname + ".init" + ".vtk"}; + if (fs::is_regular_file(initMeshName)) + meshNames.push_back(MeshName{initMeshName}); + } + { + auto finalMeshName = std::string{_bname + ".final" + ".vtk"}; + if (fs::is_regular_file(finalMeshName)) + meshNames.push_back(MeshName{finalMeshName}); + } std::cerr << "Names: " << meshNames.size() << '\n'; return meshNames; } else {