From e3f9dce823ec6f87da682858be107e2fed5a691f Mon Sep 17 00:00:00 2001 From: Alphadius Date: Tue, 19 Sep 2023 16:40:30 +0200 Subject: [PATCH 1/5] add executable blocking --- blocking/CMakeLists.txt | 7 ++ blocking/src/blocking_exe.cpp | 104 +++++++++++++++++++++++ blocking/tst/CMakeLists.txt | 3 +- blocking/tst/ClassificationTestSuite.h | 79 +++++++++++++++++ blocking/tst/ExecutionActionsTestSuite.h | 26 +++--- blocking/tst/main_test.cpp | 1 + 6 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 blocking/src/blocking_exe.cpp create mode 100644 blocking/tst/ClassificationTestSuite.h diff --git a/blocking/CMakeLists.txt b/blocking/CMakeLists.txt index 46e3d5973..02658fdeb 100644 --- a/blocking/CMakeLists.txt +++ b/blocking/CMakeLists.txt @@ -106,3 +106,10 @@ if(WITH_TEST) add_subdirectory(tst) endif(WITH_TEST) #============================================================================== + +#============================================================================== +# EXECUTABLES +#============================================================================== +add_executable(blocking src/blocking_exe.cpp) +target_link_libraries(blocking PRIVATE ${GMDS_LIB}) +target_compile_features(blocking PUBLIC cxx_std_14) \ No newline at end of file diff --git a/blocking/src/blocking_exe.cpp b/blocking/src/blocking_exe.cpp new file mode 100644 index 000000000..70840ed8d --- /dev/null +++ b/blocking/src/blocking_exe.cpp @@ -0,0 +1,104 @@ +/*----------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +/*----------------------------------------------------------------------------*/ +using namespace gmds; +/*----------------------------------------------------------------------------*/ +void set_up_geom_model(gmds::cad::FACManager* AGeomModel, const std::string AFileName) +{ + gmds::Mesh vol_mesh(gmds::MeshModel(gmds::DIM3 | gmds::R | gmds::F | gmds::E | gmds::N | gmds::R2N | gmds::R2F | gmds::R2E | gmds::F2N | gmds::F2R | gmds::F2E + | gmds::E2F | gmds::E2N | gmds::N2E)); + //std::string dir(TEST_SAMPLES_DIR); + //std::string vtk_file = dir +"/"+ AFileName; + std::string vtk_file = AFileName; + gmds::IGMeshIOService ioService(&vol_mesh); + gmds::VTKReader vtkReader(&ioService); + vtkReader.setCellOptions(gmds::N | gmds::R); + vtkReader.read(vtk_file); + gmds::MeshDoctor doc(&vol_mesh); + doc.buildFacesAndR2F(); + doc.buildEdgesAndX2E(); + doc.updateUpwardConnectivity(); + AGeomModel->initFrom3DMesh(&vol_mesh); + +} + +int main(int argc, char* argv[]) +{ + std::cout << "============== CLASSIFICATION ================" << std::endl; + + //================================================================== + // PARAMETERS' PARSING + //================================================================== + std::string file_geom, file_mesh, file_out; + if (argc != 4) { + std::cout << "Require three paramaters : \n"; + std::cout << " - [IN ] tetrahedral mesh (.vtk) that describes the geometry, \n"; + std::cout << " - [IN ] mesh (.vtk) that describes the blocking to be classified, \n"; + std::cout << " - [OUT] the name of the classified blocking (.vtk). \n" << std::endl; + throw gmds::GMDSException("Wrong number of parameters"); + } + + file_geom = std::string(argv[1]); + file_mesh = std::string(argv[2]); + file_out = std::string(argv[3]); + std::cout << "Parameters " << std::endl; + std::cout << " - Geometry file: " << file_geom << std::endl; + std::cout << " - Mesh file : " << file_mesh << std::endl; + std::cout << " - Output file : " << file_out << std::endl; + std::cout << "=======================================" << std::endl; + + //================================================================== + // GEOMETRY READING + //================================================================== + gmds::cad::FACManager geom_model; + set_up_geom_model(&geom_model,file_geom); + + //================================================================== + // MESH READING + //================================================================== + std::cout<<"> Start mesh reading"< +/*----------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +/*----------------------------------------------------------------------------*/ +/**@brief setup function that initialize a geometric model using the faceted + * representation and an input vtk file name. The vtk file must contain a + * tetrahedral mesh + * + * @param AGeomModel geometric model we initialize + * @param AFileName vtk filename + */ +void set_up_geom_model(gmds::cad::FACManager* AGeomModel, const std::string AFileName) +{ + gmds::Mesh vol_mesh(gmds::MeshModel(gmds::DIM3 | gmds::R | gmds::F | gmds::E | gmds::N | gmds::R2N | gmds::R2F | gmds::R2E | gmds::F2N | gmds::F2R | gmds::F2E + | gmds::E2F | gmds::E2N | gmds::N2E)); + std::string vtk_file = AFileName; + gmds::IGMeshIOService ioService(&vol_mesh); + gmds::VTKReader vtkReader(&ioService); + vtkReader.setCellOptions(gmds::N | gmds::R); + vtkReader.read(vtk_file); + gmds::MeshDoctor doc(&vol_mesh); + doc.buildFacesAndR2F(); + doc.buildEdgesAndX2E(); + doc.updateUpwardConnectivity(); + AGeomModel->initFrom3DMesh(&vol_mesh); + +} + + +TEST(ClassificationTestSuite, test_chord_collapse) +{ + gmds::cad::FACManager geom_model; + set_up_geom_model(&geom_model,"tet_in_box.vtk"); + gmds::blocking::CurvedBlocking bl(&geom_model, false); + + gmds::Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::R|gmds::R2N)); + + gmds::GridBuilder gb(&m,3); + gb.execute(4,1.0, 4, 1.0, 4, 1.0); + bl.init_from_mesh(m); + + + std::vector bl_faces = bl.get_all_faces(); + + ASSERT_EQ(bl.get_nb_cells<3>(),27); + + bool found_face = false; + auto face_id = -1; + gmds::math::Point seed(1.5,1.5,0.0); + for(auto i=0; i f_nodes = bl.get_nodes_of_face(bl_faces[face_id]); + bl.collapse_chord(bl_faces[face_id],f_nodes[0],f_nodes[2]); + + ASSERT_EQ(bl.get_nb_cells<3>(),24); + + gmds::Mesh m_out(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::E | gmds::F | gmds::R | gmds::E2N | gmds::F2N | gmds::R2N)); + bl.convert_to_mesh(m_out); + + gmds::IGMeshIOService ioService(&m_out); + gmds::VTKWriter writer(&ioService); + writer.setCellOptions(gmds::N | gmds::F); + writer.setDataOptions(gmds::N |gmds::F ); + writer.write("collapse.vtk"); +} \ No newline at end of file diff --git a/blocking/tst/ExecutionActionsTestSuite.h b/blocking/tst/ExecutionActionsTestSuite.h index 9c1baae4f..1c9b92f26 100644 --- a/blocking/tst/ExecutionActionsTestSuite.h +++ b/blocking/tst/ExecutionActionsTestSuite.h @@ -110,11 +110,11 @@ TEST(ExecutionActionsTestSuite,cube){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cube_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cube_blocking_edges.vtk"); } TEST(ExecutionActionsTestSuite,cb1){ @@ -231,11 +231,11 @@ TEST(ExecutionActionsTestSuite,cb1){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cb1_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cb1_blocking_edges.vtk"); } @@ -363,15 +363,15 @@ TEST(ExecutionActionsTestSuite,cb2){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cb2_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cb2_blocking_edges.vtk"); gmds::VTKWriter vtk_writer_faces(&ios); vtk_writer_faces.setCellOptions(gmds::N|gmds::F); vtk_writer_faces.setDataOptions(gmds::N|gmds::F); - vtk_writer_faces.write("debug_blocking_faces.vtk"); + vtk_writer_faces.write("cb2_blocking_faces.vtk"); } @@ -489,11 +489,11 @@ TEST(ExecutionActionsTestSuite,cb3){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cb3_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cb3_blocking_edges.vtk"); } @@ -618,11 +618,11 @@ TEST(ExecutionActionsTestSuite,cb4){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cb4_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cb4_blocking_edges.vtk"); } TEST(ExecutionActionsTestSuite,cb5){ @@ -690,10 +690,10 @@ TEST(ExecutionActionsTestSuite,cb5){ gmds::VTKWriter vtk_writer(&ios); vtk_writer.setCellOptions(gmds::N|gmds::R); vtk_writer.setDataOptions(gmds::N|gmds::R); - vtk_writer.write("debug_blocking.vtk"); + vtk_writer.write("cb5_blocking.vtk"); gmds::VTKWriter vtk_writer_edges(&ios); vtk_writer_edges.setCellOptions(gmds::N|gmds::E); vtk_writer_edges.setDataOptions(gmds::N|gmds::E); - vtk_writer_edges.write("debug_blocking_edges.vtk"); + vtk_writer_edges.write("cb5_blocking_edges.vtk"); } diff --git a/blocking/tst/main_test.cpp b/blocking/tst/main_test.cpp index b1611f96a..57b1106b0 100644 --- a/blocking/tst/main_test.cpp +++ b/blocking/tst/main_test.cpp @@ -10,6 +10,7 @@ #include "SheetInsertTestSuite.h" #include "WriterDartsVTKTestSuite.h" #include "ExecutionActionsTestSuite.h" +#include "ClassificationTestSuite.h" #ifdef USE_CGNS #include "CGNSWriterTestSuite.h" #endif From ea07edf51c88741810a55ec4051d9158e3d5f534 Mon Sep 17 00:00:00 2001 From: Alphadius Date: Wed, 20 Sep 2023 09:31:56 +0200 Subject: [PATCH 2/5] change the executable to be used with only a file on entry. It can be executed with multiple shapes --- blocking/src/blocking_exe.cpp | 117 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/blocking/src/blocking_exe.cpp b/blocking/src/blocking_exe.cpp index 70840ed8d..a8a2ff508 100644 --- a/blocking/src/blocking_exe.cpp +++ b/blocking/src/blocking_exe.cpp @@ -8,6 +8,8 @@ #include #include #include + +#include "fstream" /*----------------------------------------------------------------------------*/ using namespace gmds; /*----------------------------------------------------------------------------*/ @@ -34,71 +36,76 @@ int main(int argc, char* argv[]) { std::cout << "============== CLASSIFICATION ================" << std::endl; - //================================================================== - // PARAMETERS' PARSING - //================================================================== - std::string file_geom, file_mesh, file_out; - if (argc != 4) { - std::cout << "Require three paramaters : \n"; - std::cout << " - [IN ] tetrahedral mesh (.vtk) that describes the geometry, \n"; - std::cout << " - [IN ] mesh (.vtk) that describes the blocking to be classified, \n"; - std::cout << " - [OUT] the name of the classified blocking (.vtk). \n" << std::endl; + if (argc != 2) { + std::cout << "Require one paramater : \n"; + std::cout << " - [IN ] the file with the name of the folder to go, \n"; throw gmds::GMDSException("Wrong number of parameters"); } + auto file = std::string(argv[1]); - file_geom = std::string(argv[1]); - file_mesh = std::string(argv[2]); - file_out = std::string(argv[3]); - std::cout << "Parameters " << std::endl; - std::cout << " - Geometry file: " << file_geom << std::endl; - std::cout << " - Mesh file : " << file_mesh << std::endl; - std::cout << " - Output file : " << file_out << std::endl; - std::cout << "=======================================" << std::endl; + std::ifstream m_stream(file); + std::string line; + while(std::getline(m_stream,line)){ - //================================================================== - // GEOMETRY READING - //================================================================== - gmds::cad::FACManager geom_model; - set_up_geom_model(&geom_model,file_geom); + //================================================================== + // PARAMETERS PARSING + //================================================================== + std::string file_geom, file_mesh, file_out; - //================================================================== - // MESH READING - //================================================================== - std::cout<<"> Start mesh reading"< Start mesh reading"< Date: Wed, 20 Sep 2023 14:35:01 +0200 Subject: [PATCH 3/5] comment the executable blocking_exe.cpp --- blocking/src/blocking_exe.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/blocking/src/blocking_exe.cpp b/blocking/src/blocking_exe.cpp index a8a2ff508..d3dbb40cb 100644 --- a/blocking/src/blocking_exe.cpp +++ b/blocking/src/blocking_exe.cpp @@ -36,13 +36,29 @@ int main(int argc, char* argv[]) { std::cout << "============== CLASSIFICATION ================" << std::endl; + /* + * The folder with the shapes to test needs to be defined like that : + * DataFolder/ + * || + * \/ + * -folderShape1 / folderShape1.vtk (the geometry file) folderShape1_blocking.vtk (the blocking file) + * -folderShape2 / folderShape2.vtk (the geometry file) folderShape2_blocking.vtk (the blocking file) + * .... + * -folderShapeX / folderShapeX.vtk (the geometry file) folderShapeX_blocking.vtk (the blocking file) + * + * The file on entry is just a list of the folder's name: + * folderShape1 + * folderShape2 + * ... + * folderShapeX + */ if (argc != 2) { std::cout << "Require one paramater : \n"; std::cout << " - [IN ] the file with the name of the folder to go, \n"; throw gmds::GMDSException("Wrong number of parameters"); } auto file = std::string(argv[1]); - + //We browse the file until the end std::ifstream m_stream(file); std::string line; while(std::getline(m_stream,line)){ @@ -52,10 +68,15 @@ int main(int argc, char* argv[]) //================================================================== std::string file_geom, file_mesh, file_out; - std::string path_folder = "/home/bourmaudp/Documents/DATA/Easy_Shapes_Class/"; - std::string path_folder_shape = path_folder+line+"/"; + //The path of the data folder + std::string path_data_folder = "/home/bourmaudp/Documents/DATA/Easy_Shapes_Class/"; + //Path of the current folder with the geometry and the blocking + std::string path_folder_shape = path_data_folder+line+"/"; + //Geometry file file_geom = path_folder_shape+line+".vtk"; + //Blocking file file_mesh = path_folder_shape+line+"_blocking.vtk"; + //The path to save the classification and the name of the file file_out = path_folder_shape+line+"_blocking_class_save.vtk"; std::cout << "Parameters " << std::endl; std::cout << " - Geometry file: " << file_geom << std::endl; @@ -73,7 +94,7 @@ int main(int argc, char* argv[]) // MESH READING //================================================================== std::cout<<"> Start mesh reading"< Date: Fri, 22 Sep 2023 10:09:16 +0200 Subject: [PATCH 4/5] add possibilities to read voxel with the vtkReader (Nicolas update) --- blocking/src/blocking_exe.cpp | 5 ++ blocking/tst/ExecutionActionsTestSuite.h | 71 +++++++++++++++++++++++- io/src/VTKReader.cpp | 15 ++++- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/blocking/src/blocking_exe.cpp b/blocking/src/blocking_exe.cpp index d3dbb40cb..71f5abd07 100644 --- a/blocking/src/blocking_exe.cpp +++ b/blocking/src/blocking_exe.cpp @@ -104,11 +104,15 @@ int main(int argc, char* argv[]) MeshDoctor doc2(&m); doc2.updateUpwardConnectivity(); + std::cout<<"MESH Blocking INFO : N, "< Start mesh reading" << std::endl; + // the used model is specified according to the class requirements. + gmds::Mesh m(gmds::MeshModel(gmds::DIM3 | gmds::N | gmds::E | gmds::E2N |gmds::R | gmds::R2N)); + + gmds::IGMeshIOService ioService2(&m); + gmds::VTKReader vtkReader2(&ioService2); + vtkReader2.setCellOptions(gmds::N | gmds::E); + vtkReader2.read(file_mesh); + gmds::MeshDoctor doc2(&m); + doc2.buildE(); + doc2.updateUpwardConnectivity(); + + std::cout << "MESH Blocking INFO : N, " << m.getNbNodes() <<" ,E, "<createHex(nodes[0], + nodes[1], + nodes[3], + nodes[2], + nodes[4], + nodes[5], + nodes[7], + nodes[6]); + } else if (m_cell_types[i] == GMDS_HEX) { m_mesh_service->createHex(nodes[0], nodes[1], nodes[2], From 7fc6112abc01235ce22b29a0d9d42af8cdd8eb04 Mon Sep 17 00:00:00 2001 From: Alphadius Date: Fri, 22 Sep 2023 10:10:01 +0200 Subject: [PATCH 5/5] clean print before the merge request --- blocking/src/blocking_exe.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/blocking/src/blocking_exe.cpp b/blocking/src/blocking_exe.cpp index 71f5abd07..20aa4a253 100644 --- a/blocking/src/blocking_exe.cpp +++ b/blocking/src/blocking_exe.cpp @@ -104,14 +104,11 @@ int main(int argc, char* argv[]) MeshDoctor doc2(&m); doc2.updateUpwardConnectivity(); - std::cout<<"MESH Blocking INFO : N, "<