Skip to content

Commit

Permalink
Merge pull request #48 from andrsd/side-set-node-list
Browse files Browse the repository at this point in the history
Adding `File::get_side_set_node_list`
  • Loading branch information
andrsd authored Feb 9, 2024
2 parents 408feca + ed1c44b commit aebc75c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/exodusIIcppFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ class File {
/// @return The list of side sets
const std::vector<SideSet> & 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<int> & node_count_list,
std::vector<int> & node_list) const;

/// Get node sets
///
/// @return The list of node sets
Expand Down
23 changes: 21 additions & 2 deletions src/exodusIIcppFile.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "exodusIIcppFile.h"
#include "exodusII.h"
#include "fmt/printf.h"
#include <stdexcept>
#include <cassert>
#include <iostream>
#include <numeric>

namespace exodusIIcpp {

Expand Down Expand Up @@ -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<int> & node_count_list,
std::vector<int> & 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<NodeSet> &
File::get_node_sets() const
{
Expand Down
6 changes: 6 additions & 0 deletions test/File_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> ss_cnts;
std::vector<int> 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();
}
}

0 comments on commit aebc75c

Please sign in to comment.