diff --git a/include/exodusIIcppFile.h b/include/exodusIIcppFile.h index 491103f..46a5d48 100644 --- a/include/exodusIIcppFile.h +++ b/include/exodusIIcppFile.h @@ -173,6 +173,19 @@ class File { /// @return The list of side sets const std::vector & get_side_sets() const; + /// Get node list for a given side set index + /// + /// Example: For a side set that would have one EDGE2 and one TRI3, we would receive: + /// - node_count_list: [2, 3] + /// - node_list: [1, 2, 7, 2, 8] + /// + /// @param side_set_id Side set ID (not index) + /// @param node_count_list Number of elements in the side set + /// @param node_list Nodes corresponding to sides + void get_side_set_node_list(int side_set_idx, + std::vector & node_count_list, + std::vector & node_list) const; + /// Get node sets /// /// @return The list of node sets diff --git a/src/exodusIIcppFile.cpp b/src/exodusIIcppFile.cpp index bb1eb27..4e28789 100644 --- a/src/exodusIIcppFile.cpp +++ b/src/exodusIIcppFile.cpp @@ -1,9 +1,8 @@ #include "exodusIIcppFile.h" #include "exodusII.h" #include "fmt/printf.h" -#include #include -#include +#include namespace exodusIIcpp { @@ -273,6 +272,26 @@ File::get_side_sets() const return this->side_sets; } +void +File::get_side_set_node_list(int side_set_id, + std::vector & node_count_list, + std::vector & node_list) const +{ + int num_sides_in_set; + EXODUSIICPP_CHECK_ERROR( + ex_get_set_param(this->exoid, EX_SIDE_SET, side_set_id, &num_sides_in_set, nullptr)); + + node_count_list.resize(num_sides_in_set); + // the maximum number of nodes of a 2D element (which would be a side element) is 9 on QUAD9 + node_list.resize(num_sides_in_set * 9); + EXODUSIICPP_CHECK_ERROR(ex_get_side_set_node_list(this->exoid, + side_set_id, + node_count_list.data(), + node_list.data())); + int n = std::accumulate(node_count_list.begin(), node_count_list.end(), 0); + node_list.resize(n); +} + const std::vector & File::get_node_sets() const { diff --git a/test/File_test.cpp b/test/File_test.cpp index d737635..beae547 100644 --- a/test/File_test.cpp +++ b/test/File_test.cpp @@ -308,6 +308,12 @@ TEST(FileTest, test) auto ev3b2_vals = f.get_elemental_variable_values(10, 3, 11); EXPECT_THAT(ev3b2_vals, ElementsAre(DoubleEq(7.1))); + std::vector ss_cnts; + std::vector ss_nodes; + f.get_side_set_node_list(31, ss_cnts, ss_nodes); + EXPECT_THAT(ss_cnts, ElementsAre(2, 2)); + EXPECT_THAT(ss_nodes, ElementsAre(2, 3, 7, 8)); + f.close(); } }