Skip to content

Commit

Permalink
Adding API to write nodal variable at once
Browse files Browse the repository at this point in the history
  • Loading branch information
andrsd committed Feb 3, 2024
1 parent f37bd03 commit 467ebec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/exodusIIcppFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ class File {
/// @param var_names Names of global variables
void write_global_var_names(const std::vector<std::string> & var_names);

/// Write nodal variable values to the ExodusII file
///
/// @param step_num Time step index
/// @param var_index Variable index
/// @param values Values to write
void write_nodal_var(int step_num, int var_index, const std::vector<double> & values);

/// Write nodal variable value to the ExodusII file
///
/// @param step_num Time step index
Expand Down
7 changes: 7 additions & 0 deletions src/exodusIIcppFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,13 @@ File::write_global_var_names(const std::vector<std::string> & var_names)
write_variable_names(this->exoid, EX_GLOBAL, var_names);
}

void
File::write_nodal_var(int step_num, int var_index, const std::vector<double> & values)

Check warning on line 689 in src/exodusIIcppFile.cpp

View workflow job for this annotation

GitHub Actions / c++ linter

src/exodusIIcppFile.cpp:689:7 [readability-make-member-function-const]

method 'write_nodal_var' can be made const
{
EXODUSIICPP_CHECK_ERROR(

Check warning on line 691 in src/exodusIIcppFile.cpp

View workflow job for this annotation

GitHub Actions / c++ linter

src/exodusIIcppFile.cpp:691:5 [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead
ex_put_var(this->exoid, step_num, EX_NODAL, var_index, 0, values.size(), values.data()));
}

void
File::write_partial_nodal_var(int step_num,
int var_index,
Expand Down
7 changes: 7 additions & 0 deletions test/File_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ TEST(FileTest, create_edge2)
std::vector<int> connect1 = { 1, 2, 2, 3 };
f.write_block(1, "BAR2", 2, connect1);

f.write_time(1, 1.);

std::vector<std::string> nv_names = { "nv1" };
f.write_nodal_var_names(nv_names);
f.write_nodal_var(1, 1, {10, 11, 12});
f.update();

f.close();

// check the file that we created
Expand Down

0 comments on commit 467ebec

Please sign in to comment.