From d5c3aa97c68e54ccc0949bcea228c765be2428ba Mon Sep 17 00:00:00 2001 From: philbucher Date: Mon, 8 Feb 2021 15:10:17 +0100 Subject: [PATCH 1/7] removed deprecated methids and interface --- co_sim_io/c/co_sim_io_c.cpp | 42 +--- co_sim_io/c/co_sim_io_c.h | 22 +- co_sim_io/co_sim_io.hpp | 15 -- co_sim_io/impl/co_sim_io_impl.hpp | 26 --- .../impl/communication/communication.hpp | 19 -- .../impl/communication/file_communication.hpp | 197 ------------------ 6 files changed, 4 insertions(+), 317 deletions(-) diff --git a/co_sim_io/c/co_sim_io_c.cpp b/co_sim_io/c/co_sim_io_c.cpp index 795cc2bf..d6b81f08 100644 --- a/co_sim_io/c/co_sim_io_c.cpp +++ b/co_sim_io/c/co_sim_io_c.cpp @@ -68,7 +68,7 @@ CoSimIO_Info CoSimIO_ExportData( return ConvertInfo(CoSimIO::ExportData(ConvertInfo(I_Info), *p_container)); } -CoSimIO_Info CoSimIO_ImportMeshNEW( +CoSimIO_Info CoSimIO_ImportMesh( const CoSimIO_Info I_Info, CoSimIO_ModelPart O_ModelPart) { @@ -77,7 +77,7 @@ CoSimIO_Info CoSimIO_ImportMeshNEW( return ConvertInfo(CoSimIO::ImportMesh(ConvertInfo(I_Info), cpp_model_part)); } -CoSimIO_Info CoSimIO_ExportMeshNEW( +CoSimIO_Info CoSimIO_ExportMesh( const CoSimIO_Info I_Info, const CoSimIO_ModelPart I_ModelPart) { @@ -86,44 +86,6 @@ CoSimIO_Info CoSimIO_ExportMeshNEW( return ConvertInfo(CoSimIO::ExportMesh(ConvertInfo(I_Info), cpp_model_part)); } -CoSimIO_Info CoSimIO_ImportMesh( - const CoSimIO_Info I_Info, - int* I_NumberOfNodes, - int* I_NumberOfElements, - int* I_NumberOfElementConnectivities, - double** I_NodalCoordinates, - int** I_ElementConnectivities, - int** I_ElementTypes) -{ - using namespace CoSimIO::Internals; - constexpr int coordinates_per_node = 3; - std::unique_ptr> p_container_coords(new DataContainerRawMemory(I_NodalCoordinates, *I_NumberOfNodes)); - std::unique_ptr> p_container_conn(new DataContainerRawMemory(I_ElementConnectivities, *I_NumberOfElementConnectivities)); - std::unique_ptr> p_container_types(new DataContainerRawMemory(I_ElementTypes, *I_NumberOfElements)); - auto info = ConvertInfo(CoSimIO::ImportMesh(ConvertInfo(I_Info), *p_container_coords, *p_container_conn, *p_container_types)); - *I_NumberOfNodes = static_cast(p_container_coords->size()) / coordinates_per_node; - *I_NumberOfElementConnectivities = static_cast(p_container_conn->size()); - *I_NumberOfElements = static_cast(p_container_types->size()); - return info; -} - -CoSimIO_Info CoSimIO_ExportMesh( - const CoSimIO_Info I_Info, - const int O_NumberOfNodes, - const int O_NumberOfElements, - const int O_NumberOfElementConnectivities, - const double* O_NodalCoordinates, - const int* O_ElementConnectivities, - const int* O_ElementTypes) -{ - using namespace CoSimIO::Internals; - constexpr int coordinates_per_node = 3; - std::unique_ptr> p_container_coords(new DataContainerRawMemoryReadOnly(O_NodalCoordinates, O_NumberOfNodes * coordinates_per_node)); - std::unique_ptr> p_container_conn(new DataContainerRawMemoryReadOnly(O_ElementConnectivities, O_NumberOfElementConnectivities)); - std::unique_ptr> p_container_types(new DataContainerRawMemoryReadOnly(O_ElementTypes, O_NumberOfElements)); - return ConvertInfo(CoSimIO::ExportMesh(ConvertInfo(I_Info), *p_container_coords, *p_container_conn, *p_container_types)); -} - void CoSimIO_PrintInfo(FILE *Stream, const CoSimIO_Info I_Info) { diff --git a/co_sim_io/c/co_sim_io_c.h b/co_sim_io/c/co_sim_io_c.h index fff606f8..33eaf63e 100644 --- a/co_sim_io/c/co_sim_io_c.h +++ b/co_sim_io/c/co_sim_io_c.h @@ -52,31 +52,13 @@ CoSimIO_Info CoSimIO_ExportData( const int I_Size, const double* I_Data); -CoSimIO_Info CoSimIO_ImportMeshNEW( - const CoSimIO_Info I_Info, - CoSimIO_ModelPart O_ModelPart); - -CoSimIO_Info CoSimIO_ExportMeshNEW( - const CoSimIO_Info I_Info, - const CoSimIO_ModelPart I_ModelPart); - CoSimIO_Info CoSimIO_ImportMesh( const CoSimIO_Info I_Info, - int* I_NumberOfNodes, - int* I_NumberOfElements, - int* I_NumberOfElementConnectivities, - double** I_NodalCoordinates, - int** I_ElementConnectivities, - int** I_ElementTypes); + CoSimIO_ModelPart O_ModelPart); CoSimIO_Info CoSimIO_ExportMesh( const CoSimIO_Info I_Info, - const int O_NumberOfNodes, - const int O_NumberOfElements, - const int O_NumberOfElementConnectivities, - const double* O_NodalCoordinates, - const int* O_ElementConnectivities, - const int* O_ElementTypes); + const CoSimIO_ModelPart I_ModelPart); void CoSimIO_PrintInfo(FILE *Stream, diff --git a/co_sim_io/co_sim_io.hpp b/co_sim_io/co_sim_io.hpp index 03775550..e9403591 100644 --- a/co_sim_io/co_sim_io.hpp +++ b/co_sim_io/co_sim_io.hpp @@ -70,21 +70,6 @@ inline Info ExportMesh( const Info& I_Info, const ModelPart& I_ModelPart); -template -inline Info ImportMesh( - const Info& I_Info, - TDoubleContainerType& rNodalCoordinates, - TIntContainerType& rElementConnectivities, - TIntContainerType& rElementTypes); - -template -inline Info ExportMesh( - const Info& I_Info, - const TDoubleContainerType& rNodalCoordinates, - const TIntContainerType& rElementConnectivities, - const TIntContainerType& rElementTypes); - - inline Info ImportInfo( const Info& I_Info); diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 15880b6e..279a4943 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -161,32 +161,6 @@ inline Info ExportMesh( return CoSimIO::Internals::GetConnection(connection_name).ExportMesh(I_Info, I_ModelPart); } -template<> -inline Info ImportMesh( - const Info& I_Info, - CoSimIO::Internals::DataContainer& rNodalCoordinates, - CoSimIO::Internals::DataContainer& rElementConnectivities, - CoSimIO::Internals::DataContainer& rElementTypes) -{ - const std::string connection_name = I_Info.Get("connection_name"); - const std::string identifier = I_Info.Get("identifier"); - // TODO maybe pass the Info into the function (only changes under the hood necessary) - return Internals::GetConnection(connection_name).ImportMesh(identifier, rNodalCoordinates, rElementConnectivities, rElementTypes); -} - -template<> -inline Info ExportMesh( - const Info& I_Info, - const CoSimIO::Internals::DataContainer& rNodalCoordinates, - const CoSimIO::Internals::DataContainer& rElementConnectivities, - const CoSimIO::Internals::DataContainer& rElementTypes) -{ - const std::string connection_name = I_Info.Get("connection_name"); - const std::string identifier = I_Info.Get("identifier"); - // TODO maybe pass the Info into the function (only changes under the hood necessary) - return Internals::GetConnection(connection_name).ExportMesh(identifier, rNodalCoordinates, rElementConnectivities, rElementTypes); -} - inline Info ImportInfo( const Info& I_Info) { diff --git a/co_sim_io/impl/communication/communication.hpp b/co_sim_io/impl/communication/communication.hpp index c83387a1..fd0b7883 100644 --- a/co_sim_io/impl/communication/communication.hpp +++ b/co_sim_io/impl/communication/communication.hpp @@ -205,25 +205,6 @@ class Communication CO_SIM_IO_ERROR << "ExportMeshImpl not implemented for this comm-type!" << std::endl; return Info(); } - - // old interface, functions need to be removed before release - virtual /*[[deprecated]]*/ Info ImportMeshImpl( - const std::string& rIdentifier, - CoSimIO::Internals::DataContainer& rNodalCoordinates, - CoSimIO::Internals::DataContainer& rElementConnectivities, - CoSimIO::Internals::DataContainer& rElementTypes) - { - CO_SIM_IO_ERROR << "ImportDataImpl not implemented for this comm-type!" << std::endl; - } - - virtual /*[[deprecated]]*/ Info ExportMeshImpl( - const std::string& rIdentifier, - const CoSimIO::Internals::DataContainer& rNodalCoordinates, - const CoSimIO::Internals::DataContainer& rElementConnectivities, - const CoSimIO::Internals::DataContainer& rElementTypes) - { - CO_SIM_IO_ERROR << "ImportDataImpl not implemented for this comm-type!" << std::endl; - } }; } // namespace Internals diff --git a/co_sim_io/impl/communication/file_communication.hpp b/co_sim_io/impl/communication/file_communication.hpp index 5dfc802c..d720c535 100644 --- a/co_sim_io/impl/communication/file_communication.hpp +++ b/co_sim_io/impl/communication/file_communication.hpp @@ -48,30 +48,6 @@ static void CheckStream(const T& rStream, const fs::path& rPath) CO_SIM_IO_ERROR_IF_NOT(rStream.is_open()) << rPath << " could not be opened!" << std::endl; } -/*deprecated*/static int GetNumNodesForVtkCellType(const int VtkCellType) -{ - const std::unordered_map vtk_cell_type_map { - { /*Point3D, */ 1 , 1}, - { /*Line3D2, */ 3 , 2}, - { /*Triangle3D3, */ 5 , 3}, - { /*Quadrilateral3D4, */ 9 , 4}, - { /*Tetrahedra3D4, */ 10 , 4}, - { /*Hexahedra3D8, */ 12 , 8}, - { /*Prism3D6, */ 13 , 6}, - { /*Line3D3, */ 21 , 3}, - { /*Triangle3D6, */ 22 , 6}, - { /*Quadrilateral3D8, */ 23 , 7}, - { /*Tetrahedra3D10, */ 24, 10} - }; - - if (vtk_cell_type_map.count(VtkCellType) > 0) { - return vtk_cell_type_map.at(VtkCellType); - } else { - CO_SIM_IO_ERROR << "Unsupported cell type: " << VtkCellType << std::endl; - return 0; - } -} - } // helpers namespace @@ -523,179 +499,6 @@ class FileCommunication : public Communication return Info(); // TODO use } - Info ImportMeshImpl( - const std::string& rIdentifier, - CoSimIO::Internals::DataContainer& rNodalCoordinates, - CoSimIO::Internals::DataContainer& rElementConnectivities, - CoSimIO::Internals::DataContainer& rElementTypes) override - { - const std::string file_name(GetFullPath("CoSimIO_mesh_" + GetConnectionName() + "_" + rIdentifier + ".vtk")); - - CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Attempting to receive mesh \"" << rIdentifier << "\" in file \"" << file_name << "\" ..." << std::endl; - - WaitForPath(file_name); - - const auto start_time(std::chrono::steady_clock::now()); - - std::ifstream input_file(file_name); - CheckStream(input_file, file_name); - - // reading file - std::string current_line; - bool nodes_read = false; - bool cells_read = false; - - while (std::getline(input_file, current_line)) { - // reading nodes - if (current_line.find("POINTS") != std::string::npos) { - CO_SIM_IO_ERROR_IF(nodes_read) << "The nodes were read already!" << std::endl; - CO_SIM_IO_ERROR_IF(cells_read) << "The cells were read already!" << std::endl; - nodes_read = true; - - int num_nodes; - current_line = current_line.substr(current_line.find("POINTS") + 7); // removing "POINTS" - std::istringstream line_stream(current_line); - line_stream >> num_nodes; - - CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Mesh contains " << num_nodes << " Nodes" << std::endl; - - rNodalCoordinates.resize(3*num_nodes); - - for (int i=0; i> rNodalCoordinates[i]; - } - } - - // reading cells - if (current_line.find("CELLS") != std::string::npos) { - CO_SIM_IO_ERROR_IF_NOT(nodes_read) << "The nodes were not yet read!" << std::endl; - CO_SIM_IO_ERROR_IF(cells_read) << "The cells were read already!" << std::endl; - cells_read = true; - - int num_nodes_per_cell, num_cells, elem_conn, cell_list_size; - current_line = current_line.substr(current_line.find("CELLS") + 6); // removing "CELLS" - std::istringstream line_stream(current_line); - line_stream >> num_cells; - line_stream >> cell_list_size; - - rElementConnectivities.resize(cell_list_size-num_cells); // the first in number in each line is the number of connectivities, which is not needed bcs it can be derived form the elements-type - rElementTypes.resize(num_cells); - - CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Mesh contains " << num_cells << " Elements" << std::endl; - - int counter=0; - for (int i=0; i> num_nodes_per_cell; - for (int j=0; j> elem_conn; - rElementConnectivities[counter++] = elem_conn; - } - } - } - - // reading cell types - if (current_line.find("CELL_TYPES") != std::string::npos) { - CO_SIM_IO_ERROR_IF_NOT(nodes_read) << "The nodes were not yet read!" << std::endl; - CO_SIM_IO_ERROR_IF_NOT(cells_read) << "The cells were not yet read!" << std::endl; - - for (std::size_t i=0; i> rElementTypes[i]; - } - - } - } - - input_file.close(); - RemovePath(file_name); - - CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Finished receiving mesh" << std::endl; - - CO_SIM_IO_INFO_IF("CoSimIO", GetPrintTiming()) << "Receiving Mesh \"" << file_name << "\" took: " << ElapsedSeconds(start_time) << " [sec]" << std::endl; - - return Info(); - } - - Info ExportMeshImpl( - const std::string& rIdentifier, - const CoSimIO::Internals::DataContainer& rNodalCoordinates, - const CoSimIO::Internals::DataContainer& rElementConnectivities, - const CoSimIO::Internals::DataContainer& rElementTypes) override - { - const std::string file_name(GetFullPath("CoSimIO_mesh_" + GetConnectionName() + "_" + rIdentifier + ".vtk")); - - WaitUntilFileIsRemoved(file_name); // TODO maybe this can be queued somehow ... => then it would not block the sender - - const std::size_t num_nodes = rNodalCoordinates.size()/3; - const std::size_t num_elems = rElementTypes.size(); - - CO_SIM_IO_INFO_IF("CoSimIO", GetEchoLevel()>1) << "Attempting to send mesh \"" << rIdentifier << "\" with " << num_nodes << " Nodes | " << num_elems << " Elements in file \"" << file_name << "\" ..." << std::endl; - - const auto start_time(std::chrono::steady_clock::now()); - - std::ofstream output_file; - output_file.open(GetTempFileName(file_name)); - CheckStream(output_file, file_name); - - output_file << std::scientific << std::setprecision(7); // TODO maybe this should be configurable - - // write file header - output_file << "# vtk DataFile Version 4.0\n"; - output_file << "vtk output\n"; - output_file << "ASCII\n"; - output_file << "DATASET UNSTRUCTURED_GRID\n\n"; - - // write nodes - output_file << "POINTS " << num_nodes << " float\n"; - for (std::size_t i=0; i::max(); //in paraview the connectivities start from 0, hence we have to check beforehand what is the connectivities offset - for (std::size_t i=0; i 0 && connectivities_offset != 0) << "Connectivities have an offset of " << connectivities_offset << " which is not allowed!" << std::endl; - - // write cells connectivity - counter = 0; - output_file << "CELLS " << num_elems << " " << cell_list_size << "\n"; - for (std::size_t i=0; i1) << "Finished sending mesh" << std::endl; - - CO_SIM_IO_INFO_IF("CoSimIO", GetPrintTiming()) << "Sending Mesh \"" << rIdentifier << "\" took: " << ElapsedSeconds(start_time) << " [sec]" << std::endl; - - return Info(); - } - std::string GetTempFileName(const std::string& rFileName) const { if (mCommInFolder) { From aed59a06c3ec010dbcbc00dd63c0a2b4ba3510da Mon Sep 17 00:00:00 2001 From: philbucher Date: Mon, 8 Feb 2021 15:39:13 +0100 Subject: [PATCH 2/7] updated C tests --- tests/integration_tutorials/c/export_mesh.c | 53 ++++++++++++----- tests/integration_tutorials/c/import_mesh.c | 66 ++++++++++----------- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/tests/integration_tutorials/c/export_mesh.c b/tests/integration_tutorials/c/export_mesh.c index 2a94800b..e246a1c0 100644 --- a/tests/integration_tutorials/c/export_mesh.c +++ b/tests/integration_tutorials/c/export_mesh.c @@ -33,26 +33,49 @@ int main() COSIMIO_CHECK_EQUAL(CoSimIO_Info_GetInt(connect_info, "connection_status"), CoSimIO_Connected); const char* connection_name = CoSimIO_Info_GetString(connect_info, "connection_name"); + CoSimIO_ModelPart model_part = CoSimIO_CreateModelPart("fluid_mesh"); + int number_of_nodes=6; double nodal_coordinates[] = { - 0.0, 2.5, 1.0, /*0*/ - 2.0, 0.0, 1.5, /*1*/ - 2.0, 2.5, 1.5, /*2*/ - 4.0, 2.5, 1.7, /*3*/ - 4.0, 0.0, 1.7, /*4*/ - 6.0, 0.0, 1.8 /*5*/ + 0.0, 2.5, 1.0, /*1*/ + 2.0, 0.0, 1.5, /*2*/ + 2.0, 2.5, 1.5, /*3*/ + 4.0, 2.5, 1.7, /*4*/ + 4.0, 0.0, 1.7, /*5*/ + 6.0, 0.0, 1.8 /*6*/ }; - int number_of_elements_connectivities = 12; + for (int i=0; i Date: Mon, 8 Feb 2021 15:39:44 +0100 Subject: [PATCH 3/7] tmp removing advanced tests Will be brough back later --- .../c/export_import_mesh.c | 121 --------------- tests/integration_tutorials/c/mapping.c | 142 ------------------ 2 files changed, 263 deletions(-) delete mode 100644 tests/integration_tutorials/c/export_import_mesh.c delete mode 100644 tests/integration_tutorials/c/mapping.c diff --git a/tests/integration_tutorials/c/export_import_mesh.c b/tests/integration_tutorials/c/export_import_mesh.c deleted file mode 100644 index 983cd8de..00000000 --- a/tests/integration_tutorials/c/export_import_mesh.c +++ /dev/null @@ -1,121 +0,0 @@ -// ______ _____ _ ________ -// / ____/___ / ___/(_)___ ___ / _/ __ | -// / / / __ \\__ \/ / __ `__ \ / // / / / -// / /___/ /_/ /__/ / / / / / / // // /_/ / -// \____/\____/____/_/_/ /_/ /_/___/\____/ -// Kratos CoSimulationApplication -// -// License: BSD License, see license.txt -// -// Main authors: Pooyan Dadvand -// - -// CoSimulation includes -#include "c/co_sim_io_c.h" - -#define COSIMIO_CHECK_EQUAL_INT(a, b) \ - if (a != b) { \ - printf("in line %d : %d is not equalt to %d\n", __LINE__ , a, b); \ - return 1; \ - } - -#define COSIMIO_CHECK_EQUAL_DOUBLE(a, b) \ - if (a != b) { \ - printf("in line %d : %f is not equalt to %f\n", __LINE__ , a, b); \ - return 1; \ - } - -int main() -{ - // Creating the connection settings - CoSimIO_Info connection_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(connection_settings, "connection_name", "im_exp_mesh"); // This should be the same in both side - CoSimIO_Info_SetString(connection_settings, "solver_name", "my_solver"); // Not to be confused with the connection name. - CoSimIO_Info_SetInt(connection_settings, "echo_level", 1); - CoSimIO_Info_SetString(connection_settings, "solver_version", "1.25"); - - // Connecting using the connection settings - CoSimIO_Info connect_info = CoSimIO_Connect(connection_settings); - COSIMIO_CHECK_EQUAL_INT(CoSimIO_Info_GetInt(connect_info, "connection_status"), CoSimIO_Connected); - CoSimIO_FreeInfo(connect_info); // Don't forget to free the connect_info - - int export_number_of_nodes=6; - double export_nodal_coordinates[] = { - 0.0, 2.5, 1.0, /*0*/ - 2.0, 0.0, 1.5, /*1*/ - 2.0, 2.5, 1.5, /*2*/ - 4.0, 2.5, 1.7, /*3*/ - 4.0, 0.0, 1.7, /*4*/ - 6.0, 0.0, 1.8 /*5*/ - }; - - int export_number_of_elements_connectivities = 12; - int export_elements_connectivities[] = { - 0, 1, 2, /*1*/ - 1, 3, 2, /*2*/ - 1, 4, 3, /*3*/ - 3, 4, 5, /*4*/ - }; - - int export_number_of_elements = 4; - int export_elements_types[] = {5,5,5,5}; // VTK_TRIANGLE - - // Creatint the export_settings - CoSimIO_Info export_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(export_settings, "identifier", "mesh_exchange_1"); - CoSimIO_Info_SetString(export_settings, "connection_name", "im_exp_mesh"); - - // Exporting the data - CoSimIO_Info export_info = CoSimIO_ExportMesh(export_settings - , export_number_of_nodes,export_number_of_elements,export_number_of_elements_connectivities - , export_nodal_coordinates, export_elements_connectivities, export_elements_types); - - // Freeing the export_info and export_settings - CoSimIO_FreeInfo(export_info); - CoSimIO_FreeInfo(export_settings); - - // Now we import back the mesh - double* import_nodal_coordinates; - int import_number_of_nodes = 0; - int* import_elements_connectivities; - int import_number_of_elements_connectivities = 0; - int* import_elements_types; - int import_number_of_elements = 0; - - // Creating the import_settings - CoSimIO_Info import_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(import_settings, "identifier", "mesh_exchange_2"); - CoSimIO_Info_SetString(import_settings, "connection_name", "im_exp_mesh"); - - // Importing the mesh - CoSimIO_Info import_info = CoSimIO_ImportMesh(import_settings - , &import_number_of_nodes,&import_number_of_elements,&import_number_of_elements_connectivities - , &import_nodal_coordinates, &import_elements_connectivities, &import_elements_types); - - // Freeing the import_info and import_settings - CoSimIO_FreeInfo(import_info); - CoSimIO_FreeInfo(import_settings); - - COSIMIO_CHECK_EQUAL_INT(export_number_of_nodes, import_number_of_nodes); - COSIMIO_CHECK_EQUAL_INT(export_number_of_elements_connectivities, import_number_of_elements_connectivities); - COSIMIO_CHECK_EQUAL_INT(export_number_of_elements, import_number_of_elements); - - for(int i = 0 ; i < import_number_of_nodes * 3 ; i++) - COSIMIO_CHECK_EQUAL_DOUBLE(export_nodal_coordinates[i], import_nodal_coordinates[i]); - - for(int i = 0 ; i < import_number_of_elements_connectivities ; i++) - COSIMIO_CHECK_EQUAL_INT(export_elements_connectivities[i], import_elements_connectivities[i]); - - for(int i = 0 ; i < import_number_of_elements ; i++) - COSIMIO_CHECK_EQUAL_INT(export_elements_types[i], import_elements_types[i]); - - // Disconnecting at the end - CoSimIO_Info disconnect_info = CoSimIO_Disconnect(connection_settings); // disconnect afterwards - COSIMIO_CHECK_EQUAL_INT(CoSimIO_Info_GetInt(disconnect_info, "connection_status"), CoSimIO_Disconnected); - - // Don't forget to release the settings and info - CoSimIO_FreeInfo(connection_settings); - CoSimIO_FreeInfo(disconnect_info); - - return 0; -} diff --git a/tests/integration_tutorials/c/mapping.c b/tests/integration_tutorials/c/mapping.c deleted file mode 100644 index 44021e08..00000000 --- a/tests/integration_tutorials/c/mapping.c +++ /dev/null @@ -1,142 +0,0 @@ -// ______ _____ _ ________ -// / ____/___ / ___/(_)___ ___ / _/ __ | -// / / / __ \\__ \/ / __ `__ \ / // / / / -// / /___/ /_/ /__/ / / / / / / // // /_/ / -// \____/\____/____/_/_/ /_/ /_/___/\____/ -// Kratos CoSimulationApplication -// -// License: BSD License, see license.txt -// -// Main authors: Pooyan Dadvand -// - -// CoSimulation includes -#include "c/co_sim_io_c.h" - -#define COSIMIO_CHECK_EQUAL(a, b) \ - if (a != b) { \ - printf("in line %d : %d is not equalt to %d\n", __LINE__ , a, b); \ - return 1; \ - } - -int main() -{ - // Creating the connection settings - CoSimIO_Info connection_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(connection_settings, "connection_name", "mesh_mapping"); // This should be the same in both side - CoSimIO_Info_SetString(connection_settings, "solver_name", "my_solver"); // Not to be confused with the connection name. - CoSimIO_Info_SetInt(connection_settings, "echo_level", 1); - CoSimIO_Info_SetString(connection_settings, "solver_version", "1.25"); - - // Connecting using the connection settings - CoSimIO_Info connect_info = CoSimIO_Connect(connection_settings); - COSIMIO_CHECK_EQUAL(CoSimIO_Info_GetInt(connect_info, "connection_status"), CoSimIO_Connected); - CoSimIO_FreeInfo(connect_info); // Don't forget to free the connect_info - - // Creating the export origin mesh settings - CoSimIO_Info export_mesh_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(export_mesh_settings, "identifier", "mesh_origin"); - CoSimIO_Info_SetString(export_mesh_settings, "connection_name", "mesh_mapping"); - - // defining the origin mesh - int number_of_nodes_o=6; - double nodal_coordinates_o[] = { - 0.0, 2.5, 0.0, /*0*/ - 2.0, 0.0, 0.0, /*1*/ - 2.0, 2.5, 0.0, /*2*/ - 4.0, 2.5, 0.0, /*3*/ - 4.0, 0.0, 0.0, /*4*/ - 6.0, 0.0, 0.0 /*5*/ - }; - - int number_of_elements_connectivities_o = 12; - int elements_connectivities_o[] = { - 0, 1, 2, /*1*/ - 1, 3, 2, /*2*/ - 1, 4, 3, /*3*/ - 3, 4, 5 /*4*/ - }; - - int number_of_elements_o = 4; - int elements_types_o[] = {5,5,5,5}; // VTK_TRIANGLE - - - // Exporting the origin mesh - CoSimIO_Info export_info_o = CoSimIO_ExportMesh(export_mesh_settings - , number_of_nodes_o, number_of_elements_o, number_of_elements_connectivities_o - , nodal_coordinates_o, elements_connectivities_o, elements_types_o); - - - // Creating the export destination mesh settings - - // defining the destination mesh - int number_of_nodes_d=6; - double nodal_coordinates_d[] = { - 0.2, 2.7, 0.0, /*0*/ - 2.2, 0.2, 0.0, /*1*/ - 2.2, 2.7, 0.0, /*2*/ - 4.2, 2.7, 0.0, /*3*/ - 4.2, 0.2, 0.0, /*4*/ - 6.2, 0.2, 0.0 /*5*/ - }; - - int number_of_elements_connectivities_d = 12; - int elements_connectivities_d[] = { - 0, 1, 2, /*1*/ - 1, 3, 2, /*2*/ - 1, 4, 3, /*3*/ - 3, 4, 5 /*4*/ - }; - - int number_of_elements_d = 4; - int elements_types_d[] = {5,5,5,5}; // VTK_TRIANGLE - - // Exporting the destination mesh - CoSimIO_Info_SetString(export_mesh_settings, "identifier", "mesh_destination"); - CoSimIO_Info export_info_d = CoSimIO_ExportMesh(export_mesh_settings - , number_of_nodes_d, number_of_elements_d, number_of_elements_connectivities_d - , nodal_coordinates_d, elements_connectivities_d, elements_types_d); - - // Free memory - CoSimIO_FreeInfo(export_info_o); - CoSimIO_FreeInfo(export_info_d); - CoSimIO_FreeInfo(export_mesh_settings); - - // Creating the export origin data settings - CoSimIO_Info export_data_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(export_data_settings, "identifier", "data_to_map"); - CoSimIO_Info_SetString(export_data_settings, "connection_name", "mesh_mapping"); - - // Exporting the origin data - double export_data[] = {1, 1.5, 2, 2.5, 3, 3.5}; - CoSimIO_Info export_info = CoSimIO_ExportData(export_data_settings, number_of_nodes_o, export_data); - - // Free memory - CoSimIO_FreeInfo(export_info); - CoSimIO_FreeInfo(export_data_settings); - - - // Creating the import data settings - CoSimIO_Info import_mapped_data_settings=CoSimIO_CreateInfo(); - CoSimIO_Info_SetString(import_mapped_data_settings, "identifier", "mapped_data"); - CoSimIO_Info_SetString(import_mapped_data_settings, "connection_name", "mesh_mapping"); - - // Importing the data - double* mapped_data; - int data_allocated_size = 0; - CoSimIO_Info import_info = CoSimIO_ImportData(import_mapped_data_settings, &data_allocated_size, &mapped_data); - - // Free memory - CoSimIO_FreeInfo(import_info); - CoSimIO_FreeInfo(import_mapped_data_settings); - - // Disconnecting at the end - CoSimIO_Info disconnect_info = CoSimIO_Disconnect(connection_settings); // disconnect afterwards - COSIMIO_CHECK_EQUAL(CoSimIO_Info_GetInt(disconnect_info, "connection_status"), CoSimIO_Disconnected); - - // Don't forget to release the settings and info - CoSimIO_FreeInfo(connection_settings); - CoSimIO_FreeInfo(disconnect_info); - - return 0; -} From 34cd8394f156847916f3c9307d7f5f57b8c80ea2 Mon Sep 17 00:00:00 2001 From: philbucher Date: Mon, 8 Feb 2021 15:44:54 +0100 Subject: [PATCH 4/7] minor --- tests/integration_tutorials/c/import_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tutorials/c/import_mesh.c b/tests/integration_tutorials/c/import_mesh.c index d6a0849f..24a2f05b 100644 --- a/tests/integration_tutorials/c/import_mesh.c +++ b/tests/integration_tutorials/c/import_mesh.c @@ -88,7 +88,7 @@ int main() for (int i=0; i Date: Mon, 8 Feb 2021 15:46:56 +0100 Subject: [PATCH 5/7] unification --- tests/integration_tutorials/python/export_mesh.py | 2 +- tests/integration_tutorials/python/import_mesh.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tutorials/python/export_mesh.py b/tests/integration_tutorials/python/export_mesh.py index 76c5a787..e23f9e0f 100644 --- a/tests/integration_tutorials/python/export_mesh.py +++ b/tests/integration_tutorials/python/export_mesh.py @@ -50,7 +50,7 @@ def cosimio_check_equal(a, b): model_part.CreateNewNode(i+1, *coords) for i, conn in enumerate(element_connectivities): - model_part.CreateNewElement(i+1, CoSimIO.ElementType.Triangle2D3, conn) + model_part.CreateNewElement(i+1, CoSimIO.ElementType.Triangle3D3, conn) # Exporting mesh info = CoSimIO.Info() diff --git a/tests/integration_tutorials/python/import_mesh.py b/tests/integration_tutorials/python/import_mesh.py index f7b5079b..8b36aa70 100644 --- a/tests/integration_tutorials/python/import_mesh.py +++ b/tests/integration_tutorials/python/import_mesh.py @@ -64,7 +64,7 @@ def cosimio_check_equal(a, b): for i, (conn, elem) in enumerate(zip(expected_element_connectivities, model_part.Elements)): cosimio_check_equal(i+1, elem.Id()) - cosimio_check_equal(elem.Type(), CoSimIO.ElementType.Triangle2D3) + cosimio_check_equal(elem.Type(), CoSimIO.ElementType.Triangle3D3) cosimio_check_equal(elem.NumberOfNodes(), 3) for j, node in enumerate(elem.Nodes): cosimio_check_equal(node.Id(), conn[j]) From 68e36ae47e73dfc074250829c8ecd29e42611420 Mon Sep 17 00:00:00 2001 From: philbucher Date: Mon, 8 Feb 2021 15:50:33 +0100 Subject: [PATCH 6/7] missing const --- tests/integration_tutorials/c/export_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tutorials/c/export_mesh.c b/tests/integration_tutorials/c/export_mesh.c index e246a1c0..37c58bfb 100644 --- a/tests/integration_tutorials/c/export_mesh.c +++ b/tests/integration_tutorials/c/export_mesh.c @@ -63,7 +63,7 @@ int main() 4, 5, 6, /*4*/ }; - int num_nodes_per_element = 3; + const int num_nodes_per_element = 3; int connectivity[num_nodes_per_element]; for (int i=0; i Date: Mon, 8 Feb 2021 16:02:38 +0100 Subject: [PATCH 7/7] apparently C doesn't allow this --- tests/integration_tutorials/c/export_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tutorials/c/export_mesh.c b/tests/integration_tutorials/c/export_mesh.c index 37c58bfb..1a0ad3e5 100644 --- a/tests/integration_tutorials/c/export_mesh.c +++ b/tests/integration_tutorials/c/export_mesh.c @@ -64,7 +64,7 @@ int main() }; const int num_nodes_per_element = 3; - int connectivity[num_nodes_per_element]; + int connectivity[3]; for (int i=0; i