Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/correct mappings #13

Merged
merged 7 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion include/UGrid/UGridEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, netCDF::NcVarAtt> const& attributes);
Expand Down
2 changes: 1 addition & 1 deletion include/UGridApi/Mesh1D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions include/UGridApi/Mesh2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/UGridApi/Network1D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions include/UGridApi/UGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass i by ref.


/// @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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass i by ref.


#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/UGrid/Contacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ void Contacts::get(ugridapi::Contacts& contacts) const
{
it->second.at(0).getVar(contacts.contact_type);
}
}
}
8 changes: 4 additions & 4 deletions src/UGrid/Mesh1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
53 changes: 30 additions & 23 deletions src/UGrid/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comments about put:

  1. Are all topology attributes mandatory? Are some optional? If the key of a mandatory attribute is not found in the map, a run time error should be thrown.
  2. Can't the if statements be replaced by a generic function?

{
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())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand Down
10 changes: 5 additions & 5 deletions src/UGrid/Network1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions src/UGridApi/UGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,5 +1103,15 @@ namespace ugridapi
type = static_cast<int>(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
Loading