File

class File

Public Functions

explicit File(exodusIIcpp::fs::path file_path, exodusIIcpp::FileAccess file_access)

Open/create an ExodusII file.

Parameters:
  • file_path – Path to the file to open/create

  • file_access – Desired file access

    • exodusIIcpp::FileAccess::READ for reading,

    • exodusIIcpp::FileAccess::WRITE for writing.

void open(const std::string &file_path)

Open an ExodusII file.

Parameters:

file_path – Path to the file to open

void create(const std::string &file_path)

Create an ExodusII file.

Parameters:

file_path – Path to the file to create

bool is_opened() const

Is file opened.

Returns:

true if opened, false otherwise

void init()

Init the file before doing any read operations.

void init(const char *title, int n_dims, int n_nodes, int n_elems, int n_elem_blks, int n_node_sets, int n_side_sets)

Init the file before doing any write operations.

Parameters:
  • title – Title of the file. Can be empty.

  • n_dims – Number of spatial dimensions. [1, 2, 3]

  • n_nodes – Total number of nodes

  • n_elems – Total number of elements

  • n_elem_blks – Number of element blocks

  • n_node_sets – Number of node sets

  • n_side_sets – Number of side sets

const std::string &get_title() const

Get the title of the file.

Returns:

The file title

int get_dim() const

Get the spatial dimension.

Returns:

The spatial dimension

int get_num_nodes() const

Get the total number of nodes.

Returns:

The total number of nodes

int get_num_elements() const

Get the total number of elements.

Returns:

The total number of elements

int get_num_element_blocks() const

Get the number of element blocks.

Returns:

The number of element blocks

int get_num_node_sets() const

Get the number of node sets.

Returns:

The number of node sets

int get_num_side_sets() const

Get the number of side sets.

Returns:

The number of side sets

const std::vector<double> &get_x_coords() const

Get the x-coordinates of nodes.

Returns:

The x-coordinates of nodes

const std::vector<double> &get_y_coords() const

Get the y-coordinates of nodes.

Returns:

The y-coordinates of nodes

const std::vector<double> &get_z_coords() const

Get the z-coordinates of nodes.

Returns:

The z-coordinates of nodes

const std::vector<std::string> &get_coord_names() const

Get coordinate names.

Returns:

Array with coordinate names

const std::vector<ElementBlock> &get_element_blocks() const

Get element blocks.

Returns:

The list of element blocks

const ElementBlock &get_element_block(std::size_t idx) const

Get an element block.

Parameters:

idx – Index of the element block: [0..<number of element blocks>)

Returns:

The element block at index idx

const std::vector<SideSet> &get_side_sets() const

Get side sets.

Returns:

The list of side sets

void get_side_set_node_list(int side_set_idx, std::vector<int> &node_count_list, std::vector<int> &node_list) 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]

Parameters:
  • side_set_id – Side set ID (not index)

  • node_count_list – Number of elements in the side set

  • node_list – Nodes corresponding to sides

const std::vector<NodeSet> &get_node_sets() const

Get node sets.

Returns:

The list of node sets

int get_num_times() const

Get number of time steps.

Returns:

Number of time steps

const std::vector<double> &get_times() const

Get time values.

Returns:

Time values

std::vector<std::string> get_nodal_variable_names() const

Get nodal variable names.

Returns:

Nodal variable names

std::vector<std::string> get_elemental_variable_names() const

Get elemental variable names.

Returns:

Elemental variable names

std::vector<std::string> get_global_variable_names() const

Get global variable names.

Returns:

Global variable names

std::vector<double> get_nodal_variable_values(int time_step, int var_idx) const

Get nodal variable values at once.

Parameters:
  • time_step – Time step index (1-based)

  • var_idx – Variable index (1-based)

Returns:

Vector of nodal values for the given variable

std::vector<double> get_elemental_variable_values(int time_step, int var_idx, int block_id) const

Get elemental variable values for a given block at once.

Parameters:
  • time_step – Time step index (1-based)

  • var_idx – Variable index (1-based)

  • block_id – Block ID

Returns:

Vector of elemental values for a given variable and block

std::vector<double> get_global_variable_values(int time_step) const

Get values of global variables for a given time steps.

Parameters:

time_step – Time step index (1-based)

Returns:

Values of global variables

std::vector<double> get_global_variable_values(int var_idx, int begin_idx, int end_idx = -1) const

Get global variable values over time.

Parameters:
  • var_idx – Variable index (1-based)

  • begin_idx – First time step (1-based)

  • end_idx – End time step (1-based). -1 means use last time step.

Returns:

Values of a given global variable over specified time interval

void read()

Read all data from the ExodusII file.

void read_coords()

Read coordinate data from the ExodusII file.

void read_coord_names()

Read coordinate names from the ExodusII file.

void read_elem_map()

Read element map from the ExodusII file.

void read_blocks()

Read element blocks from the ExodusII file.

std::map<int, std::string> read_block_names() const

Read block names.

Returns:

Map of block ID -> block name

void read_node_sets()

Read node sets from the ExodusII file.

std::map<int, std::string> read_node_set_names() const

Read node set names.

Returns:

Map of Node set ID -> node set name

void read_side_sets()

Read side sets from the ExodusII file.

std::map<int, std::string> read_side_set_names() const

Read side set names.

Returns:

Map of Side set ID -> side set name

void read_times()

Read times.

void write_coords(const std::vector<double> &x)

Write 1-D coordinates to the ExodusII file.

Parameters:

x – x-coordinates

void write_coords(const std::vector<double> &x, const std::vector<double> &y)

Write 2-D coordinates to the ExodusII file.

Parameters:
  • x – x-coordinates

  • y – y-coordinates

void write_coords(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &z)

Write 3-D coordinates to the ExodusII file.

Parameters:
  • x – x-coordinates

  • y – y-coordinates

  • z – z-coordinates

void write_coord_names()

Write coordinate names to the ExodusII file.

void write_coord_names(const std::vector<std::string> &coord_names)

Write custom coordinate names to the ExodusII file.

Parameters:

coord_names – Array with coordinate names

void write_info(std::vector<std::string> info)

Write information records to the ExodusII file.

Parameters:

info – List of information records

void write_time(int time_step, double time)

Write time slice to the ExodusII file.

Parameters:
  • time_step – Time step number

  • time – Time corresponding to the time step

void write_node_set_names(const std::vector<std::string> &names)

Write node set names to the ExodusII file.

Parameters:

names – Names of node sets

void write_node_set(int64_t set_id, const std::vector<int> &node_set)

Write node set to the ExodusII file.

Parameters:
  • set_id – Node set index

  • node_set – List of node IDs that comprise the node set

void write_side_set_names(const std::vector<std::string> &names)

Write side set names to the ExodusII file.

Parameters:

names – Names of side sets

void write_side_set(int64_t set_id, const std::vector<int> &elem_list, const std::vector<int> &side_list)

Write side set to the ExodusII file.

Parameters:
  • set_id – Side set index

  • elem_list – List of element IDs that comprise the side set

  • side_list – List of local side numbers that comprise the side set

void write_block_names(const std::vector<std::string> &names)

Write element block names to the ExodusII file.

Parameters:

names – Names of element blocks

void write_block(int64_t blk_id, const char *elem_type, int64_t n_elems_in_block, const std::vector<int> &connect)

Write element block to the ExodusII file.

Note

The number of nodes per element is infered from the size of connect array and the number of elements in the block n_elems_in_block.

Parameters:
  • blk_id – Element block index

  • elem_type – Element type

  • n_elems_in_block – Number of elements in the block

  • connect – Connectivity array [el1_n1, el1_n2, ..., el2_n1, el2_n2, ...]

void write_nodal_var_names(const std::vector<std::string> &var_names)

Write nodal variable names to the ExodusII file.

Parameters:

var_names – Names of nodal variables

void write_elem_var_names(const std::vector<std::string> &var_names)

Write elemental variable names to the ExodusII file.

Parameters:

var_names – Names of elemental variables

void write_global_var_names(const std::vector<std::string> &var_names)

Write global variable names to the ExodusII file.

Parameters:

var_names – Names of global variables

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

Write nodal variable values to the ExodusII file.

Parameters:
  • step_num – Time step index

  • var_index – Variable index

  • values – Values to write

void write_partial_nodal_var(int step_num, int var_index, int64_t obj_id, int64_t start_index, double var_value)

Write nodal variable value to the ExodusII file.

Parameters:
  • step_num – Time step index

  • var_index – Variable index

  • obj_id – Object ID

  • start_index – Index of the value

  • var_value – Value to write

void write_partial_elem_var(int step_num, int var_index, int64_t obj_id, int64_t start_index, double var_value)

Write elemental variable value to the ExodusII file.

Parameters:
  • step_num – Time step index

  • var_index – Variable index

  • obj_id – Object ID

  • start_index – Index of the value

  • var_value – Value to write

void write_global_var(int step_num, int var_index, double value)

Write global variable value to the ExodusII file.

Parameters:
  • step_num – Time step index

  • var_index – Variable index

  • value – Value to write

void update()

Update the file.

Call after the time step data were all saved

void close()

Close the file.