Skip to content
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
7 changes: 7 additions & 0 deletions include/exodusIIcpp/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "exodusIIcpp/error.h"
#include "exodusIIcpp/node_set.h"
#include "exodusIIcpp/side_set.h"
#include "exodusIIcpp/truth_table.h"

namespace fs = std::filesystem;

Expand Down Expand Up @@ -148,6 +149,12 @@ class File {
/// @return The number of side sets
int get_num_side_sets() const;

/// Get elemental variable table
///
/// @return Truth table. Rows are block indices (not IDs), columns are
/// variable indices. Both are 1-based indices!
TruthTable get_elemental_var_table() const;

/// Get the x-coordinates of nodes
///
/// @return The x-coordinates of nodes
Expand Down
40 changes: 40 additions & 0 deletions include/exodusIIcpp/truth_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2026 David Andrs <andrsd@gmail.com>
// SPDX-License-Identifier: MIT

#pragma once

#include <cstddef>
#include <cstring>

namespace exodusIIcpp {

class TruthTable {
public:
~TruthTable() { delete[] this->data; }

/// Get value from row `i` and column `j`
///
/// @param i Row (1-based)
/// @param j Column (1-based)
bool
operator()(int i, int j)
{
int ofst = (i - 1) * this->n_cols + (j - 1);
return this->data[ofst] == 1;
}

private:
TruthTable(int rows, int cols) : n_cols(cols)
{
std::size_t n_elems = static_cast<std::size_t>(rows) * static_cast<std::size_t>(cols);
this->data = new int[n_elems];
std::memset(this->data, 0, n_elems * sizeof(int));
}

int n_cols;
int * data;

friend class File;
};

} // namespace exodusIIcpp
3 changes: 3 additions & 0 deletions python/src/exodusIIcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ PYBIND11_MODULE(exodusIIcpp, m)
.value("WRITE", exodusIIcpp::FileAccess::WRITE)
.value("APPEND", exodusIIcpp::FileAccess::APPEND);

py::class_<exodusIIcpp::TruthTable>(m, "TruthTable");

py::class_<exodusIIcpp::ElementBlock>(m, "ElementBlock")
.def(py::init())
.def("get_id", &ElementBlock::get_id)
Expand Down Expand Up @@ -78,6 +80,7 @@ PYBIND11_MODULE(exodusIIcpp, m)
.def("get_num_element_blocks", &File::get_num_element_blocks)
.def("get_num_node_sets", &File::get_num_node_sets)
.def("get_num_side_sets", &File::get_num_side_sets)
.def("get_elemental_var_table", &File::get_elemental_var_table)
.def("get_x_coords", &File::get_x_coords)
.def("get_y_coords", &File::get_y_coords)
.def("get_z_coords", &File::get_z_coords)
Expand Down
15 changes: 15 additions & 0 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ File::get_num_side_sets() const
return this->n_side_sets;
}

TruthTable
File::get_elemental_var_table() const
{
int num_elem_var = 0;
EXODUSIICPP_CHECK_ERROR(ex_get_variable_param(exoid, EX_ELEM_BLOCK, &num_elem_var));

TruthTable truth_table(this->n_elem_blks, num_elem_var);
EXODUSIICPP_CHECK_ERROR(ex_get_truth_table(this->exoid,
EX_ELEM_BLOCK,
this->n_elem_blks,
num_elem_var,
truth_table.data));
return truth_table;
}

const std::vector<double> &
File::get_x_coords() const
{
Expand Down
3 changes: 3 additions & 0 deletions test/File_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ TEST(FileTest, test)
EXPECT_THAT(ss_cnts, ElementsAre(2, 2));
EXPECT_THAT(ss_nodes, ElementsAre(2, 3, 7, 8));

auto ev_tab = f.get_elemental_var_table();
EXPECT_TRUE(ev_tab(1, 3));

f.close();
}
}
Loading