diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fc8e1c..350898d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,18 +72,18 @@ endif() find_package(Boost REQUIRED COMPONENTS system filesystem) include_directories(${Boost_INCLUDE_DIR}) +# Use NetCDF +find_package(netCDF REQUIRED COMPONENTS C) +if (netCDF_FOUND) + message(STATUS "Found NetCDF: in ${netCDF_INSTALL_PREFIX} (found version \"${NetCDFVersion}\")") +endif() + # Use NetCDF-cxx find_package(netCDFCxx 4.3.1 REQUIRED) if (NetCDFCxx_FOUND) message(STATUS "NetCDFCXX include dirs: ${NetCDFCxx_INCLUDE_DIRS}") endif() -# Use NetCDF -find_package(netCDF REQUIRED) -if (netCDF_FOUND) - message(STATUS "netCDF_LIB_DIR dirs: ${netCDF_LIB_DIR}") -endif() - # FetchContent added in CMake 3.11, downloads during the configure step include(FetchContent) diff --git a/include/UGrid/UGridEntity.hpp b/include/UGrid/UGridEntity.hpp index 54b070d..fbae7cb 100644 --- a/include/UGrid/UGridEntity.hpp +++ b/include/UGrid/UGridEntity.hpp @@ -146,7 +146,7 @@ namespace ugrid /// @param is_spherical [in] 1 if coordinates are in a spherical system, 0 otherwise void define(char* entity_name, int start_index, std::string const& long_name, int topology_dimension, int is_spherical); - /// @brief A function to determine if a variable is a topology variable (this function migh get overwritten in derived if necessary) + /// @brief A function to determine if a variable is a topology variable (this function might get overwritten in derived if necessary) /// @param attributes [in] The variable attributes /// @return True if the variable is a topology variable static bool is_topology_variable(std::map const& attributes); diff --git a/include/UGridApi/Mesh1D.hpp b/include/UGridApi/Mesh1D.hpp index 20521bd..2759a60 100644 --- a/include/UGridApi/Mesh1D.hpp +++ b/include/UGridApi/Mesh1D.hpp @@ -47,7 +47,7 @@ namespace ugridapi double* node_y = nullptr; /// @brief The edge node connectivity - int* edge_node = nullptr; + int* edge_nodes = nullptr; /// @brief The network edge id where every node lies int* node_edge_id = nullptr; diff --git a/include/UGridApi/Mesh2D.hpp b/include/UGridApi/Mesh2D.hpp index bddcd3a..b258131 100644 --- a/include/UGridApi/Mesh2D.hpp +++ b/include/UGridApi/Mesh2D.hpp @@ -38,10 +38,10 @@ namespace ugridapi char* name = nullptr; /// @brief The edge node connectivity - int* edge_node = nullptr; + int* edge_nodes = nullptr; /// @brief The node composing each face - int* face_node = nullptr; + int* face_nodes = nullptr; /// @brief The node x coordinates double* node_x = nullptr; @@ -62,13 +62,13 @@ namespace ugridapi double* face_y = nullptr; /// @brief The edge composing each face - int* edge_face = nullptr; + int* edge_faces = nullptr; /// @brief For each face, the edge composing it - int* face_edge = nullptr; + int* face_edges = nullptr; /// @brief For each face, the neighboring face - int* face_face = nullptr; + int* face_faces = nullptr; /// @brief The node z coordinates double* node_z = nullptr; diff --git a/include/UGridApi/Network1D.hpp b/include/UGridApi/Network1D.hpp index 6726836..eb5d8a9 100644 --- a/include/UGridApi/Network1D.hpp +++ b/include/UGridApi/Network1D.hpp @@ -48,7 +48,7 @@ namespace ugridapi char* node_long_name = nullptr; /// @brief The node defining each edge - int* edge_node = nullptr; + int* edge_nodes = nullptr; /// @brief The edge lengths double* edge_length = nullptr; diff --git a/include/UGridApi/UGrid.hpp b/include/UGridApi/UGrid.hpp index e3b71f0..4341374 100644 --- a/include/UGridApi/UGrid.hpp +++ b/include/UGridApi/UGrid.hpp @@ -431,6 +431,16 @@ namespace ugridapi /// @returns Error code UGRID_API int ug_get_faces_location_type(int& type); + /// @brief Gets the int fill value + /// @param[out] fillValue The int indicating the fill value + /// @returns Error code + UGRID_API int ug_get_int_fill_value(int& fillValue); + + /// @brief Gets the double fill value + /// @param[out] fillValue The double indicating the fill value + /// @returns Error code + UGRID_API int ug_get_double_fill_value(double& fillValue); + #ifdef __cplusplus } #endif diff --git a/src/UGrid/Contacts.cpp b/src/UGrid/Contacts.cpp index 72d8336..4c6f602 100644 --- a/src/UGrid/Contacts.cpp +++ b/src/UGrid/Contacts.cpp @@ -227,4 +227,4 @@ void Contacts::get(ugridapi::Contacts& contacts) const { it->second.at(0).getVar(contacts.contact_type); } -} \ No newline at end of file +} diff --git a/src/UGrid/Mesh1D.cpp b/src/UGrid/Mesh1D.cpp index 2135c27..bb466ae 100644 --- a/src/UGrid/Mesh1D.cpp +++ b/src/UGrid/Mesh1D.cpp @@ -197,9 +197,9 @@ void Mesh1D::put(ugridapi::Mesh1D const& mesh1d) { it->second.at(0).putVar(mesh1d.node_long_name); } - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh1d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh1d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(mesh1d.edge_node); + it->second.at(0).putVar(mesh1d.edge_nodes); } } @@ -240,8 +240,8 @@ void Mesh1D::get(ugridapi::Mesh1D& mesh1d) const { it->second.at(0).getVar(mesh1d.node_long_name); } - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh1d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh1d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(mesh1d.edge_node); + it->second.at(0).getVar(mesh1d.edge_nodes); } } diff --git a/src/UGrid/Mesh2D.cpp b/src/UGrid/Mesh2D.cpp index 79b12c6..650c2cf 100644 --- a/src/UGrid/Mesh2D.cpp +++ b/src/UGrid/Mesh2D.cpp @@ -109,8 +109,7 @@ void Mesh2D::define(ugridapi::Mesh2D const& mesh2d) {{"long_name", "Start and end node of mesh edge"}}); // Define edge_nodes coordinates - bool const add_coordinate_variable = mesh2d.edge_x != nullptr && mesh2d.edge_y != nullptr; - if (add_coordinate_variable) + if (mesh2d.edge_x != nullptr && mesh2d.edge_y != nullptr) { define_topology_coordinates(UGridFileDimensions::edge, "characteristic %s of the mesh edge (e.g. midpoint)"); } @@ -138,7 +137,7 @@ void Mesh2D::define(ugridapi::Mesh2D const& mesh2d) "face_nodes", netCDF::NcType::nc_INT, {UGridFileDimensions::face, UGridFileDimensions::max_face_node}, - {{"long_name", "Vertex node of mesh face(counterclockwise)"}}); + {{"long_name", "Vertex node of mesh face(counterclockwise)"}}, true); // Define face coordinates bool const add_coordinate_variable = mesh2d.face_x != nullptr && mesh2d.face_y != nullptr; @@ -151,7 +150,7 @@ void Mesh2D::define(ugridapi::Mesh2D const& mesh2d) // define_topology_coordinates(UGridFileDimensions::face, "%s bounds of mesh face (i.e. corner coordinates)", "%s%s_bnd"); // Define optional variables - if (mesh2d.face_edge != nullptr) + if (mesh2d.face_edges != nullptr) { // Define face_edges topology attribute and variable string_builder.clear(); @@ -161,9 +160,9 @@ void Mesh2D::define(ugridapi::Mesh2D const& mesh2d) "face_edge", netCDF::NcType::nc_INT, {UGridFileDimensions::face, UGridFileDimensions::max_face_node}, - {{"long_name", "Side edge of mesh face (counterclockwise)"}}); + {{"long_name", "Side edge of mesh face (counterclockwise)"}}, true); } - if (mesh2d.face_face != nullptr) + if (mesh2d.face_faces != nullptr) { // Define face_links topology attribute and variable string_builder.clear(); @@ -175,7 +174,7 @@ void Mesh2D::define(ugridapi::Mesh2D const& mesh2d) {UGridFileDimensions::face, UGridFileDimensions::max_face_node}, {{"long_name", "Neighboring face of mesh face (counterclockwise)"}}); } - if (mesh2d.edge_face != nullptr) + if (mesh2d.edge_faces != nullptr) { // Define edge_face topology attribute variable and variable string_builder.clear(); @@ -214,9 +213,13 @@ void Mesh2D::put(ugridapi::Mesh2D const& mesh2d) } // Edges - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh2d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh2d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) + { + it->second.at(0).putVar(mesh2d.edge_nodes); + } + if (auto const it = m_topology_attribute_variables.find("edge_face_connectivity"); mesh2d.edge_faces != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(mesh2d.edge_node); + it->second.at(0).putVar(mesh2d.edge_faces); } if (auto const it = m_topology_attribute_variables.find("edge_coordinates"); mesh2d.edge_x != nullptr && it != m_topology_attribute_variables.end()) { @@ -228,17 +231,17 @@ void Mesh2D::put(ugridapi::Mesh2D const& mesh2d) } // Faces - if (auto const it = m_topology_attribute_variables.find("face_node_connectivity"); mesh2d.face_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_node_connectivity"); mesh2d.face_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(mesh2d.face_node); + it->second.at(0).putVar(mesh2d.face_nodes); } - if (auto const it = m_topology_attribute_variables.find("face_edge_connectivity"); mesh2d.face_face != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_edge_connectivity"); mesh2d.face_edges != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(mesh2d.face_face); + it->second.at(0).putVar(mesh2d.face_edges); } - if (auto const it = m_topology_attribute_variables.find("face_face_connectivity"); mesh2d.edge_face != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_face_connectivity"); mesh2d.face_faces != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(mesh2d.edge_face); + it->second.at(0).putVar(mesh2d.face_faces); } if (auto const it = m_topology_attribute_variables.find("face_coordinates"); mesh2d.face_x != nullptr && it != m_topology_attribute_variables.end()) { @@ -290,9 +293,13 @@ void Mesh2D::get(ugridapi::Mesh2D& mesh2d) const } // Edges - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh2d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); mesh2d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) + { + it->second.at(0).getVar(mesh2d.edge_nodes); + } + if (auto const it = m_topology_attribute_variables.find("edge_face_connectivity"); mesh2d.edge_faces != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(mesh2d.edge_node); + it->second.at(0).getVar(mesh2d.edge_faces); } if (auto const it = m_topology_attribute_variables.find("edge_coordinates"); mesh2d.edge_x != nullptr && it != m_topology_attribute_variables.end()) { @@ -304,17 +311,17 @@ void Mesh2D::get(ugridapi::Mesh2D& mesh2d) const } // Faces - if (auto const it = m_topology_attribute_variables.find("face_node_connectivity"); mesh2d.face_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_node_connectivity"); mesh2d.face_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(mesh2d.face_node); + it->second.at(0).getVar(mesh2d.face_nodes); } - if (auto const it = m_topology_attribute_variables.find("face_edge_connectivity"); mesh2d.face_face != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_edge_connectivity"); mesh2d.face_edges != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(mesh2d.face_face); + it->second.at(0).getVar(mesh2d.face_edges); } - if (auto const it = m_topology_attribute_variables.find("face_face_connectivity"); mesh2d.edge_face != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("face_face_connectivity"); mesh2d.face_faces != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(mesh2d.edge_face); + it->second.at(0).getVar(mesh2d.face_faces); } if (auto const it = m_topology_attribute_variables.find("face_coordinates"); mesh2d.face_x != nullptr && it != m_topology_attribute_variables.end()) { diff --git a/src/UGrid/Network1D.cpp b/src/UGrid/Network1D.cpp index bd81fc6..85e5ba9 100644 --- a/src/UGrid/Network1D.cpp +++ b/src/UGrid/Network1D.cpp @@ -77,7 +77,7 @@ void Network1D::define(ugridapi::Network1D const& network1d) { throw std::invalid_argument("Network1D::define network node coordinates missing"); } - if (network1d.edge_node == nullptr) + if (network1d.edge_nodes == nullptr) { throw std::invalid_argument("Network1D::define network edge (branches) missing"); } @@ -266,9 +266,9 @@ void Network1D::put(ugridapi::Network1D const& network1d) it->second.at(0).putVar(network1d.node_long_name); } - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); network1d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); network1d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).putVar(network1d.edge_node); + it->second.at(0).putVar(network1d.edge_nodes); } if (auto const it = m_topology_attribute_variables.find("edge_length"); network1d.edge_length != nullptr && it != m_topology_attribute_variables.end()) @@ -339,9 +339,9 @@ void Network1D::get(ugridapi::Network1D& network1d) const it->second.at(1).getVar(network1d.node_y); } - if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); network1d.edge_node != nullptr && it != m_topology_attribute_variables.end()) + if (auto const it = m_topology_attribute_variables.find("edge_node_connectivity"); network1d.edge_nodes != nullptr && it != m_topology_attribute_variables.end()) { - it->second.at(0).getVar(network1d.edge_node); + it->second.at(0).getVar(network1d.edge_nodes); } if (auto const it = find_attribute_variable_name_with_aliases("node_id"); network1d.node_id != nullptr && it != m_topology_attribute_variables.end()) diff --git a/src/UGridApi/UGrid.cpp b/src/UGridApi/UGrid.cpp index 771a7d7..e61e5d0 100644 --- a/src/UGridApi/UGrid.cpp +++ b/src/UGridApi/UGrid.cpp @@ -1103,5 +1103,15 @@ namespace ugridapi type = static_cast(MeshLocations::Faces); return Success; } + UGRID_API int ug_get_int_fill_value(int& fillValue) + { + fillValue = ugrid::int_missing_value; + return Success; + } + UGRID_API int ug_get_double_fill_value(double& fillValue) + { + fillValue = ugrid::double_missing_value; + return Success; + } } // namespace ugridapi diff --git a/tests/api/ApiTests.cpp b/tests/api/ApiTests.cpp index 51930bd..30b7bcf 100644 --- a/tests/api/ApiTests.cpp +++ b/tests/api/ApiTests.cpp @@ -115,18 +115,18 @@ TEST(ApiTest, InquireAndGet_OneMesh2D_ShouldReadMesh2d) std::unique_ptr const name(new char[name_long_length]); mesh2d.name = name.get(); - std::unique_ptr const node_x(new double[mesh2d.num_nodes]); - mesh2d.node_x = node_x.get(); - std::unique_ptr const node_y(new double[mesh2d.num_nodes]); - mesh2d.node_y = node_y.get(); - std::unique_ptr const edge_nodes(new int[mesh2d.num_edges * 2]); - mesh2d.edge_node = edge_nodes.get(); - std::unique_ptr const face_x(new double[mesh2d.num_faces]); - mesh2d.face_x = face_x.get(); - std::unique_ptr const face_y(new double[mesh2d.num_faces]); - mesh2d.face_y = face_y.get(); - std::unique_ptr const face_nodes(new int[mesh2d.num_faces * mesh2d.num_face_nodes_max]); - mesh2d.face_node = face_nodes.get(); + std::vector node_x(mesh2d.num_nodes); + mesh2d.node_x = node_x.data(); + std::vector node_y(mesh2d.num_nodes); + mesh2d.node_y = node_y.data(); + std::vector edge_nodes(mesh2d.num_edges * 2); + mesh2d.edge_nodes = edge_nodes.data(); + std::vector face_x(mesh2d.num_faces); + mesh2d.face_x = face_x.data(); + std::vector face_y(mesh2d.num_faces); + mesh2d.face_y = face_y.data(); + std::vector face_nodes(mesh2d.num_faces * mesh2d.num_face_nodes_max); + mesh2d.face_nodes = face_nodes.data(); // Execute error_code = ug_mesh2d_get(file_id, 0, mesh2d); @@ -136,15 +136,15 @@ TEST(ApiTest, InquireAndGet_OneMesh2D_ShouldReadMesh2d) std::string mesh_name(mesh2d.name); right_trim_string(mesh_name); ASSERT_EQ(mesh_name, "mesh2d"); - std::vector node_x_vector(node_x.get(), node_x.get() + mesh2d.num_nodes); + std::vector node_x_vector(node_x.data(), node_x.data() + mesh2d.num_nodes); std::vector node_x_expected{0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3}; ASSERT_THAT(node_x_vector, ::testing::ContainerEq(node_x_expected)); - std::vector node_y_vector(node_y.get(), node_y.get() + mesh2d.num_nodes); + std::vector node_y_vector(node_y.data(), node_y.data() + mesh2d.num_nodes); std::vector node_y_vector_expected{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}; ASSERT_THAT(node_y_vector, ::testing::ContainerEq(node_y_vector_expected)); - std::vector edge_nodes_vector(edge_nodes.get(), edge_nodes.get() + mesh2d.num_edges * 2); + std::vector edge_nodes_vector(edge_nodes.data(), edge_nodes.data() + mesh2d.num_edges * 2); std::vector edge_nodes_vector_expected{ 1, 2, 3, 4, @@ -172,15 +172,15 @@ TEST(ApiTest, InquireAndGet_OneMesh2D_ShouldReadMesh2d) 15, 16}; ASSERT_THAT(edge_nodes_vector, ::testing::ContainerEq(edge_nodes_vector_expected)); - std::vector face_x_vector(face_x.get(), face_x.get() + mesh2d.num_faces); + std::vector face_x_vector(face_x.data(), face_x.data() + mesh2d.num_faces); std::vector face_x_vector_expected{0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 2.5, 2.5}; ASSERT_THAT(face_x_vector, ::testing::ContainerEq(face_x_vector_expected)); - std::vector face_y_vector(face_y.get(), face_y.get() + mesh2d.num_faces); + std::vector face_y_vector(face_y.data(), face_y.data() + mesh2d.num_faces); std::vector face_y_vector_expected{0.5, 1.5, 2.5, 0.5, 1.5, 2.5, 0.5, 1.5, 2.5}; ASSERT_THAT(face_y_vector, ::testing::ContainerEq(face_y_vector_expected)); - std::vector face_nodes_vector(face_nodes.get(), face_nodes.get() + mesh2d.num_faces * mesh2d.num_face_nodes_max); + std::vector face_nodes_vector(face_nodes.data(), face_nodes.data() + mesh2d.num_faces * mesh2d.num_face_nodes_max); std::vector face_nodes_vector_expected{ 1, 2, 4, 3, 3, 4, 6, 5, @@ -218,14 +218,14 @@ TEST(ApiTest, DefineAndPut_OneMesh2D_ShouldWriteData) std::unique_ptr const name(new char[name_long_length]); string_to_char_array("mesh2d", name_long_length, name.get()); mesh2d.name = name.get(); - std::unique_ptr const node_x(new double[]{0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3}); + std::vector node_x{0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3}; - mesh2d.node_x = node_x.get(); - std::unique_ptr const node_y(new double[]{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}); + mesh2d.node_x = node_x.data(); + std::vector node_y{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}; - mesh2d.node_y = node_y.get(); + mesh2d.node_y = node_y.data(); mesh2d.num_nodes = 16; - std::unique_ptr const edge_nodes(new int[]{ + std::vector edge_nodes{ 1, 2, 3, @@ -274,16 +274,17 @@ TEST(ApiTest, DefineAndPut_OneMesh2D_ShouldWriteData) 15, 15, 16, - }); - mesh2d.edge_node = edge_nodes.get(); + }; + + mesh2d.edge_nodes = edge_nodes.data(); mesh2d.num_edges = 23; - std::unique_ptr const face_x(new double[]{0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 2.5, 2.5}); - mesh2d.face_x = face_x.get(); - std::unique_ptr const face_y(new double[]{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}); - mesh2d.face_y = face_y.get(); + std::vector face_x{0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 2.5, 2.5}; + mesh2d.face_x = face_x.data(); + std::vector face_y{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}; + mesh2d.face_y = face_y.data(); mesh2d.num_faces = 9; - std::unique_ptr const face_nodes(new int[]{ + std::vector face_nodes{ 1, 2, 4, 3, 3, 4, 6, 5, 5, 6, 8, 7, @@ -292,8 +293,8 @@ TEST(ApiTest, DefineAndPut_OneMesh2D_ShouldWriteData) 6, 11, 12, 8, 9, 13, 14, 10, 10, 14, 15, 11, - 11, 15, 16, 12}); - mesh2d.face_node = face_nodes.get(); + 11, 15, 16, 12}; + mesh2d.face_nodes = face_nodes.data(); mesh2d.num_face_nodes_max = 4; // Execute @@ -357,7 +358,7 @@ TEST(ApiTest, InquireAndGet_OneNetwork1D_ShouldReadNetwork1D) network1d.node_y = node_y.get(); std::unique_ptr const edge_node(new int[network1d.num_edges * 2]); - network1d.edge_node = edge_node.get(); + network1d.edge_nodes = edge_node.get(); std::unique_ptr const geometry_nodes_x(new double[network1d.num_geometry_nodes]); network1d.geometry_nodes_x = geometry_nodes_x.get(); @@ -470,27 +471,27 @@ TEST(ApiTest, DefineAndPut_OneNetwork1D_ShouldWriteData) std::unique_ptr const name(new char[name_long_length]); string_to_char_array("network1d", name_long_length, name.get()); network1d.name = name.get(); - std::unique_ptr const node_x(new double[]{293.78, 538.89}); - network1d.node_x = node_x.get(); - std::unique_ptr const node_y(new double[]{27.48, 956.75}); - network1d.node_y = node_y.get(); + std::vector node_x{293.78, 538.89}; + network1d.node_x = node_x.data(); + std::vector node_y{27.48, 956.75}; + network1d.node_y = node_y.data(); network1d.num_nodes = 2; - std::unique_ptr const edge_node(new int[]{0, 1}); - network1d.edge_node = edge_node.get(); + std::vector edge_node{0, 1}; + network1d.edge_nodes = edge_node.data(); network1d.num_edges = 1; - std::unique_ptr const geometry_nodes_x(new double[]{293.78, 278.97, 265.31, 254.17, 247.44, 248.3, 259.58, - 282.24, 314.61, 354.44, 398.94, 445, 490.6, 532.84, 566.64, 589.08, - 600.72, 603.53, 599.27, 590.05, 577.56, 562.97, 547.12, 530.67, 538.89}); - network1d.geometry_nodes_x = geometry_nodes_x.get(); + std::vector geometry_nodes_x{293.78, 278.97, 265.31, 254.17, 247.44, 248.3, 259.58, + 282.24, 314.61, 354.44, 398.94, 445, 490.6, 532.84, 566.64, 589.08, + 600.72, 603.53, 599.27, 590.05, 577.56, 562.97, 547.12, 530.67, 538.89}; + network1d.geometry_nodes_x = geometry_nodes_x.data(); - std::unique_ptr const geometry_nodes_y(new double[]{27.48, 74.87, 122.59, 170.96, 220.12, 269.67, 317.89, - 361.93, 399.39, 428.84, 450.76, 469.28, 488.89, 514.78, 550.83, 594.93, - 643.09, 692.6, 742.02, 790.79, 838.83, 886.28, 933.33, 980.17, 956.75}); - network1d.geometry_nodes_y = geometry_nodes_y.get(); + std::vector geometry_nodes_y{27.48, 74.87, 122.59, 170.96, 220.12, 269.67, 317.89, + 361.93, 399.39, 428.84, 450.76, 469.28, 488.89, 514.78, 550.83, 594.93, + 643.09, 692.6, 742.02, 790.79, 838.83, 886.28, 933.33, 980.17, 956.75}; + network1d.geometry_nodes_y = geometry_nodes_y.data(); - std::unique_ptr const geometry_nodes_count(new int[]{25}); - network1d.num_edge_geometry_nodes = geometry_nodes_count.get(); + std::vector geometry_nodes_count{25}; + network1d.num_edge_geometry_nodes = geometry_nodes_count.data(); network1d.num_geometry_nodes = 25; @@ -567,7 +568,7 @@ TEST(ApiTest, InquireAndGet_OneMesh1D_ShouldReadMesh1D) mesh1d.node_edge_offset = edge_offset.get(); std::unique_ptr const edge_nodes(new int[mesh1d.num_edges * 2]); - mesh1d.edge_node = edge_nodes.get(); + mesh1d.edge_nodes = edge_nodes.get(); std::unique_ptr const node_id(new char[name_length * mesh1d.num_nodes]); mesh1d.node_id = node_id.get(); @@ -629,43 +630,44 @@ TEST(ApiTest, DefineAndPut_OneMesh1D_ShouldWriteData) std::unique_ptr const network_name(new char[]{"network1d "}); mesh1d.network_name = network_name.get(); - std::unique_ptr const node_edge_id(new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - mesh1d.node_edge_id = node_edge_id.get(); + std::vector node_edge_id{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + mesh1d.node_edge_id = node_edge_id.data(); - std::unique_ptr const node_edge_offset(new double[]{ + std::vector node_edge_offset{ 0, 49.65, 99.29, 148.92, 198.54, 248.09, 297.62, 347.15, 396.66, 446.19, 495.8, 545.44, 595.08, 644.63, 694.04, 743.52, 793.07, 842.65, 892.26, 941.89, 991.53, 1041.17, 1090.82, - 1140.46, 1165.29}); - mesh1d.node_edge_offset = node_edge_offset.get(); + 1140.46, 1165.29}; + mesh1d.node_edge_offset = node_edge_offset.data(); mesh1d.num_nodes = 25; mesh1d.num_edges = 24; - std::unique_ptr const edges_nodes(new int[]{0, 1, - 1, 2, - 2, 3, - 3, 4, - 4, 5, - 5, 6, - 6, 7, - 7, 8, - 8, 9, - 9, 10, - 10, 11, - 11, 12, - 12, 13, - 13, 14, - 14, 15, - 15, 16, - 16, 17, - 17, 18, - 18, 19, - 19, 20, - 20, 21, - 21, 22, - 22, 23, - 23, 24}); - mesh1d.edge_node = edges_nodes.get(); + std::vector edges_nodes{0, 1, + 1, 2, + 2, 3, + 3, 4, + 4, 5, + 5, 6, + 6, 7, + 7, 8, + 8, 9, + 9, 10, + 10, 11, + 11, 12, + 12, 13, + 13, 14, + 14, 15, + 15, 16, + 16, 17, + 17, 18, + 18, 19, + 19, 20, + 20, 21, + 21, 22, + 22, 23, + 23, 24}; + + mesh1d.edge_nodes = edges_nodes.data(); std::vector ids; std::vector long_names; @@ -853,33 +855,34 @@ TEST(ApiTest, DefineAndPut_OneContact_ShouldWriteAContact) ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); contacts.mesh_to_location = face_location_enum; - std::unique_ptr const contact_type(new int[]{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}); - contacts.contact_type = contact_type.get(); + std::vector contact_type{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; + contacts.contact_type = contact_type.data(); + + std::vector edges{13, 1, + 13, 2, + 13, 3, + 13, 4, + 70, 5, + 76, 6, + 91, 7, + 13, 8, + 13, 9, + 13, 10, + 13, 11, + 13, 12, + 178, 13, + 200, 14, + 228, 15, + 255, 16, + 277, 17, + 293, 18, + 304, 19, + 315, 20, + 326, 21, + 337, 22, + 353, 23}; + contacts.edges = edges.data(); - std::unique_ptr const edges(new int[]{13, 1, - 13, 2, - 13, 3, - 13, 4, - 70, 5, - 76, 6, - 91, 7, - 13, 8, - 13, 9, - 13, 10, - 13, 11, - 13, 12, - 178, 13, - 200, 14, - 228, 15, - 255, 16, - 277, 17, - 293, 18, - 304, 19, - 315, 20, - 326, 21, - 337, 22, - 353, 23}); - contacts.edges = edges.get(); contacts.num_contacts = 23; std::vector ids; @@ -1180,14 +1183,14 @@ TEST(ApiTest, TopologyDefineDoubleVariableOnLocation_OnExistingFile_ShouldDefine std::unique_ptr const name(new char[name_long_length]); string_to_char_array("mesh2d", name_long_length, name.get()); mesh2d.name = name.get(); - std::unique_ptr const node_x(new double[]{0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3}); + std::vector node_x{0, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 2, 3, 3, 3, 3}; - mesh2d.node_x = node_x.get(); - std::unique_ptr const node_y(new double[]{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}); + mesh2d.node_x = node_x.data(); + std::vector node_y{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}; - mesh2d.node_y = node_y.get(); + mesh2d.node_y = node_y.data(); mesh2d.num_nodes = 16; - std::unique_ptr const edge_nodes(new int[]{ + std::vector edge_nodes{ 1, 2, 3, @@ -1236,16 +1239,17 @@ TEST(ApiTest, TopologyDefineDoubleVariableOnLocation_OnExistingFile_ShouldDefine 15, 15, 16, - }); - mesh2d.edge_node = edge_nodes.get(); + }; + + mesh2d.edge_nodes = edge_nodes.data(); mesh2d.num_edges = 23; - std::unique_ptr const face_x(new double[]{0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 2.5, 2.5}); - mesh2d.face_x = face_x.get(); - std::unique_ptr const face_y(new double[]{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}); - mesh2d.face_y = face_y.get(); + std::vector face_x{0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 2.5, 2.5}; + mesh2d.face_x = face_x.data(); + std::vector face_y{0, 0, 1, 1, 2, 2, 3, 3, 0, 1, 2, 3, 0, 1, 2, 3}; + mesh2d.face_y = face_y.data(); mesh2d.num_faces = 9; - std::unique_ptr const face_nodes(new int[]{ + std::vector face_nodes{ 1, 2, 4, 3, 3, 4, 6, 5, 5, 6, 8, 7, @@ -1254,8 +1258,8 @@ TEST(ApiTest, TopologyDefineDoubleVariableOnLocation_OnExistingFile_ShouldDefine 6, 11, 12, 8, 9, 13, 14, 10, 10, 14, 15, 11, - 11, 15, 16, 12}); - mesh2d.face_node = face_nodes.get(); + 11, 15, 16, 12}; + mesh2d.face_nodes = face_nodes.data(); mesh2d.num_face_nodes_max = 4; // Open file @@ -1310,4 +1314,68 @@ TEST(ApiTest, TopologyDefineDoubleVariableOnLocation_OnExistingFile_ShouldDefine error_code = ugridapi::ug_file_close(file_id); ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); -} \ No newline at end of file +} + +TEST(ApiTest, InquireAndGetFaceEdges_OneMesh2D_ShouldReadMesh2D) +{ + // Prepare + // Open a file + std::string const file_path = TEST_FOLDER + "/AllUGridEntities.nc"; + + int file_mode = -1; + auto error_code = ugridapi::ug_file_read_mode(file_mode); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + + int file_id = -1; + error_code = ugridapi::ug_file_open(file_path.c_str(), file_mode, file_id); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + + // get the number of topologies + int topology_type; + error_code = ugridapi::ug_topology_get_network1d_enum(topology_type); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + int num_topologies; + error_code = ugridapi::ug_topology_get_count(file_id, topology_type, num_topologies); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + ASSERT_EQ(num_topologies, 1); + + // get the dimensions + ugridapi::Mesh2D mesh2d; + error_code = ug_mesh2d_inq(file_id, 0, mesh2d); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + + // Allocate data variables + int name_length; + error_code = ugridapi::ug_name_get_length(name_length); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + int long_names_length; + error_code = ugridapi::ug_name_get_long_length(long_names_length); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + + std::vector edge_faces(mesh2d.num_edges * 2); + mesh2d.edge_faces = edge_faces.data(); + + std::vector face_edges(mesh2d.num_faces * mesh2d.num_face_nodes_max, -1); + mesh2d.face_edges = face_edges.data(); + + // get the data + error_code = ug_mesh2d_get(file_id, 0, mesh2d); + + // Close the file + error_code = ugridapi::ug_file_close(file_id); + ASSERT_EQ(ugridapi::UGridioApiErrors::Success, error_code); + + // Assert + std::vector edge_faces_expected{23, 0, 45, 0, 56, 0, 67, 0, 78, 0}; + for (int i = 0; i < edge_faces_expected.size(); ++i) + { + ASSERT_EQ(edge_faces_expected[i], edge_faces[i]); + } + + // No faces found, the initial -1 are retained + std::vector face_edges_expected{-1, -1, -1, -1}; + for (int i = 0; i < face_edges_expected.size(); ++i) + { + ASSERT_EQ(face_edges_expected[i], face_edges[i]); + } +}