ExodusII_IO_Helper Class Reference

#include <exodusII_io_helper.h>

Inheritance diagram for ExodusII_IO_Helper:

List of all members.

Classes

class  Conversion
class  ElementMaps

Public Member Functions

 ExodusII_IO_Helper (bool v=false)
virtual ~ExodusII_IO_Helper ()
bool created ()
void verbose (bool set_verbosity)
int get_num_dim () const
int get_num_nodes () const
int get_num_elem () const
int get_num_elem_blk () const
int get_num_elem_this_blk () const
int get_num_nodes_per_elem () const
int get_num_side_sets () const
int get_num_node_sets () const
int get_connect (int i) const
int get_num_sides_per_set (int i) const
int get_num_nodes_per_set (int i) const
const std::vector< int > & get_elem_list () const
const std::vector< int > & get_side_list () const
const std::vector< int > & get_node_list () const
int get_nodeset_id (unsigned int i) const
const std::vector< int > & get_id_list () const
const char * get_elem_type () const
double get_x (int i) const
double get_y (int i) const
double get_z (int i) const
void open (const char *filename)
void read_header ()
void print_header ()
void read_nodes ()
void read_node_num_map ()
void print_nodes ()
void read_block_info ()
int get_block_id (int block)
void read_elem_in_block (int block)
void read_elem_num_map ()
void read_sideset_info ()
void read_nodeset_info ()
void read_sideset (int id, int offset)
void read_nodeset (int id)
void print_sideset_info ()
void print_nodeset_info ()
void close ()
int inquire (int req_info, std::string error_msg="")
const std::vector< double > & get_time_steps ()
int get_num_nodal_vars ()
const std::vector< std::string > & get_nodal_var_names ()
const std::vector< double > & get_nodal_var_values (std::string nodal_var_name, int time_step)
void create (std::string filename)
void initialize (std::string title, const MeshBase &mesh)
void write_nodal_coordinates (const MeshBase &mesh)
void write_elements (const MeshBase &mesh)
void write_sidesets (const MeshBase &mesh)
void write_nodesets (const MeshBase &mesh)
void initialize_nodal_variables (std::vector< std::string > names)
void write_timestep (int timestep, double time)
void write_nodal_values (int var_id, const std::vector< Number > &values, int timestep)
void check_err (const int error, const std::string msg)
void message (const std::string msg)
void message (const std::string msg, int i)

Public Attributes

int comp_ws
int io_ws
int ex_id
int ex_err
int num_dim
int num_nodes
int num_elem
int num_elem_blk
int num_node_sets
int num_side_sets
int num_elem_this_blk
int num_nodes_per_elem
int num_attr
int req_info
int ret_int
int num_elem_all_sidesets
std::vector< int > block_ids
std::vector< int > connect
std::vector< int > ss_ids
std::vector< int > nodeset_ids
std::vector< int > num_sides_per_set
std::vector< int > num_nodes_per_set
std::vector< int > num_df_per_set
std::vector< int > num_node_df_per_set
std::vector< int > elem_list
std::vector< int > side_list
std::vector< int > node_list
std::vector< int > id_list
std::vector< int > node_num_map
std::vector< int > elem_num_map
float ex_version
float ret_float
std::vector< double > x
std::vector< double > y
std::vector< double > z
char ret_char
std::vector< char > title
std::vector< char > elem_type
std::map< int, int > libmesh_elem_num_to_exodus
int num_time_steps
std::vector< double > time_steps
int num_nodal_vars
std::vector< std::string > nodal_var_names
std::vector< double > nodal_var_values
std::vector< std::vector< char > > vvc
std::vector< char * > strings

Protected Attributes

bool _created
bool _verbose


Detailed Description

This is the ExodusII_IO_Helper class. This class hides the implementation details of interfacing with the Exodus binary format.

Author:
Johw W. Peterson, 2002.

Definition at line 46 of file exodusII_io_helper.h.


Constructor & Destructor Documentation

ExodusII_IO_Helper::ExodusII_IO_Helper ( bool  v = false  )  [inline]

Constructor. Automatically initializes all the private members of the class. Also allows you to set the verbosity level to v=1 (on) or v=0 (off).

Definition at line 55 of file exodusII_io_helper.h.

References elem_type, and title.

00055                                    : 
00056     comp_ws(sizeof(double)),
00057     io_ws(0),
00058     ex_id(0),
00059     ex_err(0),
00060     num_dim(0),
00061     num_nodes(0),
00062     num_elem(0),
00063     num_elem_blk(0),
00064     num_node_sets(0),
00065     num_side_sets(0),
00066     num_elem_this_blk(0),
00067     num_nodes_per_elem(0),
00068     num_attr(0),
00069     req_info(0),
00070     ret_int(0),
00071     num_elem_all_sidesets(0),
00072     ex_version(0.0),
00073     ret_float(0.0),
00074     ret_char(0),
00075     num_time_steps(0),
00076     _created(false),
00077     _verbose(v)
00078 
00079   {
00080     title.resize(MAX_LINE_LENGTH+1);
00081     elem_type.resize(MAX_STR_LENGTH);
00082   }

ExodusII_IO_Helper::~ExodusII_IO_Helper (  )  [virtual]

Destructor. The only memory allocated is for title and elem_type. This memory is freed in the destructor.

Definition at line 105 of file exodusII_io_helper.C.

00106 {
00107 }


Member Function Documentation

void ExodusII_IO_Helper::close (  ) 

Closes the ExodusII mesh file.

Definition at line 435 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, and message().

Referenced by ExodusII_IO::~ExodusII_IO().

00436 {
00437   ex_err = exII::ex_close(ex_id);
00438   check_err(ex_err, "Error closing Exodus file.");
00439   message("Exodus file closed successfully."); 
00440 }

void ExodusII_IO_Helper::create ( std::string  filename  ) 

Opens an ExodusII mesh file named filename for writing.

Definition at line 538 of file exodusII_io_helper.C.

References _created, _verbose, check_err(), comp_ws, ex_id, ex_version, and io_ws.

00539 {
00540   //Store things as doubles
00541   comp_ws = 8;
00542   io_ws = 8;
00543     
00544   ex_id = exII::ex_create(filename.c_str(), EX_CLOBBER, &comp_ws, &io_ws);
00545     
00546   ex_id = exII::ex_open(filename.c_str(),
00547                         EX_WRITE,
00548                         &comp_ws,
00549                         &io_ws,
00550                         &ex_version);
00551   
00552   check_err(ex_id, "Error creating ExodusII mesh file.");
00553   if (_verbose) std::cout << "File created successfully." << std::endl;
00554 
00555   _created = true;
00556 }

bool ExodusII_IO_Helper::created (  ) 

Returns true once create() has been successfully called, and false otherwise.

Definition at line 819 of file exodusII_io_helper.C.

References _created.

00820 {
00821   return _created;
00822 }

int ExodusII_IO_Helper::get_block_id ( int  block  ) 

Get's the block number for the given block.

Definition at line 256 of file exodusII_io_helper.C.

References block_ids.

Referenced by ExodusII_IO::read().

00257 {
00258   libmesh_assert (static_cast<unsigned int>(block) < block_ids.size());
00259     
00260   return block_ids[block];
00261 }

int ExodusII_IO_Helper::get_connect ( int  i  )  const [inline]

Returns:
the number of elements in all the sidesets. Effectively returns the total number of elements on the ExodusII mesh boundary.

the $ i^{th} $ node number in the element connectivity list for a given element.

Definition at line 174 of file exodusII_io_helper.h.

References connect.

Referenced by ExodusII_IO::read().

00174 { return connect[i]; }

const std::vector<int>& ExodusII_IO_Helper::get_elem_list (  )  const [inline]

Returns:
the $ i^{th} $ entry in the element list. The element list contains the numbers of all elements on the boundary.

a constant reference to the elem_list.

Definition at line 202 of file exodusII_io_helper.h.

References elem_list.

Referenced by ExodusII_IO::read().

00202 { return elem_list; }

const char* ExodusII_IO_Helper::get_elem_type (  )  const [inline]

Returns:
the current element type. Note: the default behavior is for this value to be in all capital letters, e.g. HEX27.

Definition at line 249 of file exodusII_io_helper.h.

References elem_type.

Referenced by ExodusII_IO::read().

00249 { return &elem_type[0]; }

const std::vector<int>& ExodusII_IO_Helper::get_id_list (  )  const [inline]

Returns:
the $ i^{th} $ entry in the id list. This is the id for the ith face on the boundary.

a constant reference to the id_list.

Definition at line 239 of file exodusII_io_helper.h.

References id_list.

Referenced by ExodusII_IO::read().

00239 { return id_list; }

const std::vector< std::string > & ExodusII_IO_Helper::get_nodal_var_names (  ) 

Definition at line 464 of file exodusII_io_helper.C.

References _verbose, ex_id, nodal_var_names, num_nodal_vars, strings, and vvc.

Referenced by get_nodal_var_values().

00465 {
00466   // Allocate enough space for our variable name strings.
00467   nodal_var_names.resize(num_nodal_vars);
00468     
00469   // Use the vvc and strings objects to emulate the behavior of
00470   // a char** object.
00471   vvc.resize(num_nodal_vars);
00472   strings.resize(num_nodal_vars);
00473   for (int i=0;i<num_nodal_vars;i++)
00474     vvc[i].resize(MAX_STR_LENGTH+1);
00475 
00476   for (int i=0;i<num_nodal_vars;i++)
00477     strings[i]=&(vvc[i][0]); // set pointer into vvc only *after* all resizing is complete
00478     
00479   exII::ex_get_var_names(ex_id,
00480                          "n",
00481                          num_nodal_vars,
00482                          &strings[0]//var_names
00483                          );
00484 
00485   if (_verbose)
00486     {
00487       std::cout << "Read the variable(s) from the file:" << std::endl;
00488       for (int i=0; i<num_nodal_vars; i++)
00489         std::cout << "strings[" << i << "]=" << strings[i] << std::endl;
00490     }
00491 
00492   
00493   // Copy the char buffers into strings.  
00494   for (int i=0;i<num_nodal_vars;i++)
00495     nodal_var_names[i]=strings[i]; // calls string::op=(const char*)
00496 
00497   
00498   return nodal_var_names;
00499 }

const std::vector< double > & ExodusII_IO_Helper::get_nodal_var_values ( std::string  nodal_var_name,
int  time_step 
)

Definition at line 504 of file exodusII_io_helper.C.

References ex_id, get_nodal_var_names(), nodal_var_names, nodal_var_values, and num_nodes.

00505 {
00506   nodal_var_values.resize(num_nodes);
00507     
00508   this->get_nodal_var_names();
00509 
00510   //See if we can find the variable we are looking for
00511   unsigned int var_index = 0;
00512   bool found = false;
00513 
00514   found = nodal_var_names[var_index] == nodal_var_name;
00515     
00516   while(!found && var_index < nodal_var_names.size())
00517     {
00518       var_index++;
00519       found = nodal_var_names[var_index] == nodal_var_name;
00520     }
00521 
00522   if(!found)
00523     {
00524       std::cerr << "Unable to locate variable named: " << nodal_var_name << std::endl;
00525       return nodal_var_values;
00526     }
00527 
00528   exII::ex_get_nodal_var(ex_id, time_step, var_index+1, num_nodes, &nodal_var_values[0]);
00529   
00530   return nodal_var_values;
00531 }

const std::vector<int>& ExodusII_IO_Helper::get_node_list (  )  const [inline]

Returns:
a constant reference to the node_list.

Definition at line 222 of file exodusII_io_helper.h.

References node_list.

Referenced by ExodusII_IO::read().

00222 { return node_list; }

int ExodusII_IO_Helper::get_nodeset_id ( unsigned int  i  )  const [inline]

Returns:
the nodeset id corresponding to the ith nodeset.

Definition at line 227 of file exodusII_io_helper.h.

References nodeset_ids.

Referenced by ExodusII_IO::read().

00227 { return nodeset_ids[i]; }

int ExodusII_IO_Helper::get_num_dim (  )  const [inline]

Returns:
the ExodusII mesh dimension.

Definition at line 107 of file exodusII_io_helper.h.

References num_dim.

00107 { return num_dim; }

int ExodusII_IO_Helper::get_num_elem (  )  const [inline]

Returns:
the total number of elements in the ExodusII mesh.

Definition at line 120 of file exodusII_io_helper.h.

References num_elem.

Referenced by ExodusII_IO::read().

00120 { return num_elem; }

int ExodusII_IO_Helper::get_num_elem_blk (  )  const [inline]

Returns:
the total number of element blocks in the ExodusII mesh.

Definition at line 127 of file exodusII_io_helper.h.

References num_elem_blk.

Referenced by ExodusII_IO::read().

00127 { return num_elem_blk; }

int ExodusII_IO_Helper::get_num_elem_this_blk (  )  const [inline]

For a given block, returns the total number of elements.

Definition at line 134 of file exodusII_io_helper.h.

References num_elem_this_blk.

Referenced by ExodusII_IO::read().

00134 { return num_elem_this_blk; }

int ExodusII_IO_Helper::get_num_nodal_vars (  )  [inline]

Definition at line 407 of file exodusII_io_helper.h.

References num_nodal_vars.

00407 { return num_nodal_vars; }

int ExodusII_IO_Helper::get_num_node_sets (  )  const [inline]

Returns:
the total number of nodesets in the ExodusII mesh.

Definition at line 157 of file exodusII_io_helper.h.

References num_node_sets.

Referenced by ExodusII_IO::read().

00157 { return num_node_sets; }

int ExodusII_IO_Helper::get_num_nodes (  )  const [inline]

Returns:
the total number of nodes in the ExodusII mesh.

Definition at line 113 of file exodusII_io_helper.h.

References num_nodes.

Referenced by ExodusII_IO::read().

00113 { return num_nodes; }

int ExodusII_IO_Helper::get_num_nodes_per_elem (  )  const [inline]

Returns:
the number of nodes per element in a given block. e.g. for HEX27 it returns 27.

Definition at line 142 of file exodusII_io_helper.h.

References num_nodes_per_elem.

Referenced by ExodusII_IO::read().

00142 { return num_nodes_per_elem; }

int ExodusII_IO_Helper::get_num_nodes_per_set ( int  i  )  const [inline]

For a single nodeset, returns the total number of nodes in the nodeset.

Definition at line 188 of file exodusII_io_helper.h.

References num_nodes_per_set.

00188 { return num_nodes_per_set[i]; }

int ExodusII_IO_Helper::get_num_side_sets (  )  const [inline]

Returns:
the total number of sidesets in the ExodusII mesh. Each sideset contains only one type of element.

Definition at line 150 of file exodusII_io_helper.h.

References num_side_sets.

Referenced by ExodusII_IO::read().

00150 { return num_side_sets; }

int ExodusII_IO_Helper::get_num_sides_per_set ( int  i  )  const [inline]

For a single sideset, returns the total number of elements in the sideset.

Definition at line 181 of file exodusII_io_helper.h.

References num_sides_per_set.

Referenced by ExodusII_IO::read().

00181 { return num_sides_per_set[i]; }

const std::vector<int>& ExodusII_IO_Helper::get_side_list (  )  const [inline]

Returns:
the $ i^{th} $ entry in the side list. This is effectively the "side" (face in 3D or edge in 2D) number which lies on the boundary.

a constant reference to the side_list.

Definition at line 217 of file exodusII_io_helper.h.

References side_list.

Referenced by ExodusII_IO::read().

00217 { return side_list; }

const std::vector< double > & ExodusII_IO_Helper::get_time_steps (  ) 

Definition at line 455 of file exodusII_io_helper.C.

References ex_id, num_time_steps, and time_steps.

00456 {
00457   time_steps.resize(num_time_steps);
00458   exII::ex_get_all_times(ex_id, time_steps.empty() ? NULL : &time_steps[0]);
00459   return time_steps;
00460 }

double ExodusII_IO_Helper::get_x ( int  i  )  const [inline]

Returns:
the $ i^{th} $ node's x-coordinate.

Definition at line 255 of file exodusII_io_helper.h.

References x.

Referenced by ExodusII_IO::read().

00255 { return x[i]; }

double ExodusII_IO_Helper::get_y ( int  i  )  const [inline]

Returns:
the $ i^{th} $ node's y-coordinate.

Definition at line 261 of file exodusII_io_helper.h.

References y.

Referenced by ExodusII_IO::read().

00261 { return y[i]; }

double ExodusII_IO_Helper::get_z ( int  i  )  const [inline]

Returns:
the $ i^{th} $ node's z-coordinate.

Definition at line 267 of file exodusII_io_helper.h.

References z.

Referenced by ExodusII_IO::read().

00267 { return z[i]; }

void ExodusII_IO_Helper::initialize ( std::string  title,
const MeshBase mesh 
)

Initializes the Exodus file

Definition at line 560 of file exodusII_io_helper.C.

References MeshBase::boundary_info, check_err(), MeshBase::elem(), ex_err, ex_id, DofObject::id(), MeshBase::n_elem(), MeshBase::n_nodes(), num_dim, num_elem, num_elem_blk, num_node_sets, num_nodes, num_side_sets, MeshBase::spatial_dimension(), and Elem::subdomain_id().

00561 {
00562   num_dim = mesh.spatial_dimension();
00563   num_nodes = mesh.n_nodes();
00564   num_elem = mesh.n_elem();
00565 
00566   std::vector<short int> unique_side_boundaries;
00567   std::vector<short int> unique_node_boundaries;
00568 
00569   mesh.boundary_info->build_side_boundary_ids(unique_side_boundaries);
00570   mesh.boundary_info->build_node_boundary_ids(unique_node_boundaries);
00571 
00572   num_side_sets = unique_side_boundaries.size();
00573   num_node_sets = unique_node_boundaries.size();
00574   
00575   //loop through element and map between block and element vector
00576   std::map<subdomain_id_type, std::vector<unsigned int>  > subdomain_map;
00577   for(int i=0;i<num_elem;i++)
00578     {
00579       Elem * elem = mesh.elem(i);
00580       subdomain_id_type cur_subdomain = elem->subdomain_id();
00581      
00582       subdomain_map[cur_subdomain].push_back(elem->id());
00583     }
00584   num_elem_blk = subdomain_map.size();
00585 
00586   std::cout<<"Num elem block: "<<num_elem_blk<<std::endl;
00587 
00588   ex_err = exII::ex_put_init(ex_id,
00589                              str_title.c_str(),
00590                              num_dim,
00591                              num_nodes,
00592                              num_elem,
00593                              num_elem_blk,
00594                              num_node_sets,
00595                              num_side_sets);
00596     
00597   check_err(ex_err, "Error initializing new Exodus file.");
00598 }

void ExodusII_IO_Helper::initialize_nodal_variables ( std::vector< std::string >  names  ) 

Sets up the nodal variables

Definition at line 762 of file exodusII_io_helper.C.

References _verbose, check_err(), ex_err, ex_id, num_nodal_vars, strings, and vvc.

00763 {
00764   num_nodal_vars = names.size();
00765 
00766   ex_err = exII::ex_put_var_param(ex_id, "n", num_nodal_vars);
00767   check_err(ex_err, "Error setting number of nodal vars.");
00768 
00769   // Use the vvc and strings objects to emulate the behavior of
00770   // a char** object.
00771   vvc.resize(num_nodal_vars);
00772   strings.resize(num_nodal_vars);
00773 
00774   // For each string in names, allocate enough space in vvc and copy from
00775   // the C++ string into vvc for passing to the C interface.
00776   for (int i=0; i<num_nodal_vars; i++)
00777     {
00778       vvc[i].resize(names[i].size()+1);
00779       std::strcpy(&(vvc[i][0]), names[i].c_str());
00780     }
00781 
00782   for (int i=0; i<num_nodal_vars; i++)
00783     strings[i] = &(vvc[i][0]); // set pointer into vvc only *after* all resizing is complete
00784 
00785   if (_verbose)
00786     {
00787       std::cout << "Writing variable name(s) to file: " << std::endl;
00788       for (int i=0;i<num_nodal_vars;i++)
00789         std::cout << "strings[" << i << "]=" << strings[i] << std::endl;
00790     }
00791     
00792   ex_err = exII::ex_put_var_names(ex_id,
00793                                   "n",
00794                                   num_nodal_vars,
00795                                   &strings[0]//var_names
00796                                   );
00797     
00798   check_err(ex_err, "Error setting nodal variable names.");
00799 }

int ExodusII_IO_Helper::inquire ( int  req_info,
std::string  error_msg = "" 
)

Generic inquiry, returns the value

Definition at line 442 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, ret_char, ret_float, and ret_int.

Referenced by read_header().

00443 {
00444   ex_err = exII::ex_inquire(ex_id,
00445                             req_info,
00446                             &ret_int,
00447                             &ret_float,
00448                             &ret_char);
00449     
00450   check_err(ex_err, error_msg);
00451 
00452   return ret_int;
00453 }

void ExodusII_IO_Helper::message ( const std::string  msg,
int  i 
)

Prints the message defined in msg to std::cout and appends the number i to the end of the message. Useful for printing messages in loops. Can be turned off if verbosity is set to 0.

Definition at line 134 of file exodusII_io_helper.C.

References _verbose.

00135 {
00136   if (_verbose) std::cout << msg << i << "." << std::endl;
00137 }

void ExodusII_IO_Helper::message ( const std::string  msg  ) 

Prints the message defined in msg to std::cout. Can be turned off if verbosity is set to 0.

Definition at line 127 of file exodusII_io_helper.C.

References _verbose.

Referenced by close(), read_block_info(), read_elem_in_block(), read_elem_num_map(), read_header(), read_node_num_map(), read_nodes(), read_nodeset(), read_nodeset_info(), read_sideset(), and read_sideset_info().

00128 {
00129   if (_verbose) std::cout << msg << std::endl;
00130 }

void ExodusII_IO_Helper::open ( const char *  filename  ) 

Opens an ExodusII mesh file named filename for reading.

Definition at line 141 of file exodusII_io_helper.C.

References _verbose, check_err(), comp_ws, ex_id, ex_version, and io_ws.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00142 {
00143   ex_id = exII::ex_open(filename,
00144                         EX_READ,
00145                         &comp_ws,
00146                         &io_ws,
00147                         &ex_version);
00148   
00149   check_err(ex_id, "Error opening ExodusII mesh file.");
00150   if (_verbose) std::cout << "File opened successfully." << std::endl;
00151 }

void ExodusII_IO_Helper::print_header (  ) 

Prints the ExodusII mesh file header, which includes the mesh title, the number of nodes, number of elements, mesh dimension, number of sidesets, and number of nodesets

Definition at line 178 of file exodusII_io_helper.C.

References _verbose, num_dim, num_elem, num_elem_blk, num_node_sets, num_nodes, num_side_sets, and title.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00179 {
00180   if (_verbose)
00181     std::cout << "Title: \t" << &title[0] << std::endl
00182               << "Mesh Dimension: \t"   << num_dim << std::endl
00183               << "Number of Nodes: \t" << num_nodes << std::endl
00184               << "Number of elements: \t" << num_elem << std::endl
00185               << "Number of elt blocks: \t" << num_elem_blk << std::endl
00186               << "Number of node sets: \t" << num_node_sets << std::endl
00187               << "Number of side sets: \t" << num_side_sets << std::endl;
00188 }

void ExodusII_IO_Helper::print_nodes (  ) 

Prints the nodal information to std::cout.

Definition at line 229 of file exodusII_io_helper.C.

References num_nodes, x, y, and z.

00230 {
00231   for (int i=0; i<num_nodes; i++)
00232     {
00233       std::cout << "(" << x[i] << ", " << y[i] << ", " << z[i] << ")" << std::endl;
00234     }
00235 }

void ExodusII_IO_Helper::print_nodeset_info (  ) 

Prints information about all the nodesets.

void ExodusII_IO_Helper::print_sideset_info (  ) 

Prints information about all the sidesets.

Definition at line 425 of file exodusII_io_helper.C.

References elem_list, num_elem_all_sidesets, and side_list.

00426 {
00427   for (int i=0; i<num_elem_all_sidesets; i++)
00428     {
00429       std::cout << elem_list[i] << " " << side_list[i] << std::endl;
00430     }
00431 }

void ExodusII_IO_Helper::read_block_info (  ) 

Reads information for all of the blocks in the ExodusII mesh file.

Definition at line 239 of file exodusII_io_helper.C.

References block_ids, check_err(), ex_err, ex_id, message(), and num_elem_blk.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00240 {
00241   block_ids.resize(num_elem_blk);
00242   // Get all element block IDs.
00243   ex_err = exII::ex_get_elem_blk_ids(ex_id,
00244                                      block_ids.empty() ? NULL : &block_ids[0]);
00245   // Usually, there is only one
00246   // block since there is only
00247   // one type of element.
00248   // However, there could be more.
00249 
00250   check_err(ex_err, "Error getting block IDs.");
00251   message("All block IDs retrieved successfully."); 
00252 }

void ExodusII_IO_Helper::read_elem_in_block ( int  block  ) 

Reads all of the element connectivity for block block in the ExodusII mesh file.

Definition at line 265 of file exodusII_io_helper.C.

References _verbose, block_ids, check_err(), connect, elem_type, ex_err, ex_id, message(), num_attr, num_elem_this_blk, and num_nodes_per_elem.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00266 {
00267   libmesh_assert (static_cast<unsigned int>(block) < block_ids.size());
00268   
00269   ex_err = exII::ex_get_elem_block(ex_id,
00270                                    block_ids[block],
00271                                    &elem_type[0],
00272                                    &num_elem_this_blk,
00273                                    &num_nodes_per_elem,
00274                                    &num_attr);
00275   if (_verbose)
00276     std::cout << "Reading a block of " << num_elem_this_blk
00277               << " " << &elem_type[0] << "(s)"
00278               << " having " << num_nodes_per_elem
00279               << " nodes per element." << std::endl;
00280       
00281   check_err(ex_err, "Error getting block info.");
00282   message("Info retrieved successfully for block: ", block); 
00283   
00284   
00285   
00286   // Read in the connectivity of the elements of this block,
00287   // watching out for the case where we actually have no
00288   // elements in this block (possible with parallel files)
00289   connect.resize(num_nodes_per_elem*num_elem_this_blk);
00290 
00291   if (!connect.empty())
00292     {
00293       ex_err = exII::ex_get_elem_conn(ex_id,
00294                                       block_ids[block],
00295                                       &connect[0]);
00296   
00297       check_err(ex_err, "Error reading block connectivity.");
00298       message("Connectivity retrieved successfully for block: ", block);
00299     }
00300 }

void ExodusII_IO_Helper::read_elem_num_map (  ) 

Reads the optional node_num_map from the ExodusII mesh file.

Definition at line 304 of file exodusII_io_helper.C.

References _verbose, check_err(), elem_num_map, ex_err, ex_id, message(), std::min(), num_elem, and libMesh::processor_id().

Referenced by Nemesis_IO::read().

00305 {
00306   elem_num_map.resize(num_elem);
00307 
00308   ex_err = exII::ex_get_elem_num_map (ex_id,
00309                                       elem_num_map.empty() ? NULL : &elem_num_map[0]);
00310                                       
00311   check_err(ex_err, "Error retrieving element number map.");
00312   message("Element numbering map retrieved successfully."); 
00313 
00314 
00315   if (_verbose)
00316     {
00317       std::cout << "[" << libMesh::processor_id() << "] elem_num_map[i] = ";
00318       for (unsigned int i=0; i< static_cast<unsigned int>(std::min(10, num_elem-1)); ++i)
00319         std::cout << elem_num_map[i] << ", ";
00320       std::cout << "... " << elem_num_map.back() << std::endl;
00321     }
00322 }

void ExodusII_IO_Helper::read_header (  ) 

Reads an ExodusII mesh file header.

Definition at line 155 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, inquire(), message(), num_dim, num_elem, num_elem_blk, num_nodal_vars, num_node_sets, num_nodes, num_side_sets, num_time_steps, and title.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00156 {
00157   ex_err = exII::ex_get_init(ex_id,
00158                              title.empty() ? NULL : &title[0],
00159                              &num_dim,
00160                              &num_nodes,
00161                              &num_elem,
00162                              &num_elem_blk,
00163                              &num_node_sets,
00164                              &num_side_sets);
00165 
00166   check_err(ex_err, "Error retrieving header info.");
00167 
00168   num_time_steps = inquire(exII::EX_INQ_TIME, "Error retrieving time steps");
00169 
00170   exII::ex_get_var_param(ex_id, "n", &num_nodal_vars);
00171 
00172   message("Exodus header info retrieved successfully.");
00173 }

void ExodusII_IO_Helper::read_node_num_map (  ) 

Reads the optional node_num_map from the ExodusII mesh file.

Definition at line 209 of file exodusII_io_helper.C.

References _verbose, check_err(), ex_err, ex_id, message(), std::min(), node_num_map, num_nodes, and libMesh::processor_id().

Referenced by Nemesis_IO::read().

00210 {
00211   node_num_map.resize(num_nodes);
00212 
00213   ex_err = exII::ex_get_node_num_map (ex_id,
00214                                       node_num_map.empty() ? NULL : &node_num_map[0]);
00215                                       
00216   check_err(ex_err, "Error retrieving nodal number map.");
00217   message("Nodal numbering map retrieved successfully."); 
00218 
00219   if (_verbose)
00220     {
00221       std::cout << "[" << libMesh::processor_id() << "] node_num_map[i] = ";
00222       for (unsigned int i=0; i< static_cast<unsigned int>(std::min(10, num_nodes-1)); ++i)
00223         std::cout << node_num_map[i] << ", ";
00224       std::cout << "... " << node_num_map.back() << std::endl;
00225     }
00226 }

void ExodusII_IO_Helper::read_nodes (  ) 

Reads the nodal data (x,y,z coordinates) from the ExodusII mesh file.

Definition at line 192 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, message(), num_nodes, x, y, and z.

Referenced by Nemesis_IO::read(), and ExodusII_IO::read().

00193 {
00194   x.resize(num_nodes);
00195   y.resize(num_nodes); 
00196   z.resize(num_nodes); 
00197 
00198   ex_err = exII::ex_get_coord(ex_id,
00199                               static_cast<void*>(&x[0]),
00200                               static_cast<void*>(&y[0]),
00201                               static_cast<void*>(&z[0]));
00202   
00203   check_err(ex_err, "Error retrieving nodal data.");
00204   message("Nodal data retrieved successfully."); 
00205 }

void ExodusII_IO_Helper::read_nodeset ( int  id  ) 

Reads information about nodeset id and inserts it into the global nodeset array at the position offset.

Definition at line 401 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, message(), node_list, nodeset_ids, num_node_df_per_set, and num_nodes_per_set.

Referenced by ExodusII_IO::read().

00402 {
00403   libmesh_assert (static_cast<unsigned int>(id) < nodeset_ids.size());
00404   libmesh_assert (static_cast<unsigned int>(id) < num_nodes_per_set.size());
00405   libmesh_assert (static_cast<unsigned int>(id) < num_node_df_per_set.size());
00406   
00407   ex_err = exII::ex_get_node_set_param(ex_id,
00408                                        nodeset_ids[id],
00409                                        &num_nodes_per_set[id],
00410                                        &num_node_df_per_set[id]);
00411   check_err(ex_err, "Error retrieving nodeset parameters.");
00412   message("Parameters retrieved successfully for nodeset: ", id);
00413 
00414   node_list.resize(num_nodes_per_set[id]);
00415 
00416   ex_err = exII::ex_get_node_set(ex_id,
00417                                  nodeset_ids[id],
00418                                  &node_list[0]);
00419   
00420   check_err(ex_err, "Error retrieving nodeset data.");
00421   message("Data retrieved successfully for nodeset: ", id);
00422 }

void ExodusII_IO_Helper::read_nodeset_info (  ) 

Reads information about all of the nodesets in the ExodusII mesh file.

Definition at line 358 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, message(), nodeset_ids, num_node_df_per_set, num_node_sets, and num_nodes_per_set.

Referenced by ExodusII_IO::read().

00359 {
00360   nodeset_ids.resize(num_node_sets);
00361   if (num_node_sets > 0)
00362     {
00363       ex_err = exII::ex_get_node_set_ids(ex_id,
00364                                          &nodeset_ids[0]);
00365       check_err(ex_err, "Error retrieving nodeset information.");
00366       message("All nodeset information retrieved successfully."); 
00367 
00368       // Resize appropriate data structures -- only do this once outnode the loop
00369       num_nodes_per_set.resize(num_node_sets);
00370       num_node_df_per_set.resize(num_node_sets);
00371     }
00372 }

void ExodusII_IO_Helper::read_sideset ( int  id,
int  offset 
)

Reads information about sideset id and inserts it into the global sideset array at the position offset.

Definition at line 375 of file exodusII_io_helper.C.

References check_err(), elem_list, ex_err, ex_id, id_list, message(), num_df_per_set, num_sides_per_set, side_list, and ss_ids.

Referenced by ExodusII_IO::read().

00376 {
00377   libmesh_assert (static_cast<unsigned int>(id) < ss_ids.size());
00378   libmesh_assert (static_cast<unsigned int>(id) < num_sides_per_set.size());
00379   libmesh_assert (static_cast<unsigned int>(id) < num_df_per_set.size());
00380   libmesh_assert (static_cast<unsigned int>(offset) < elem_list.size());
00381   libmesh_assert (static_cast<unsigned int>(offset) < side_list.size());
00382   
00383   ex_err = exII::ex_get_side_set_param(ex_id,
00384                                        ss_ids[id],
00385                                        &num_sides_per_set[id],
00386                                        &num_df_per_set[id]);
00387   check_err(ex_err, "Error retrieving sideset parameters.");
00388   message("Parameters retrieved successfully for sideset: ", id);
00389 
00390   ex_err = exII::ex_get_side_set(ex_id,
00391                                  ss_ids[id],
00392                                  &elem_list[offset],
00393                                  &side_list[offset]);
00394   check_err(ex_err, "Error retrieving sideset data.");
00395   message("Data retrieved successfully for sideset: ", id);
00396 
00397   for (int i=0; i<num_sides_per_set[id]; i++)
00398     id_list[i+offset] = ss_ids[id];
00399 }

void ExodusII_IO_Helper::read_sideset_info (  ) 

Reads information about all of the sidesets in the ExodusII mesh file.

Definition at line 326 of file exodusII_io_helper.C.

References check_err(), elem_list, ex_err, ex_id, id_list, message(), num_df_per_set, num_elem_all_sidesets, num_side_sets, num_sides_per_set, req_info, ret_char, ret_float, ret_int, side_list, and ss_ids.

Referenced by ExodusII_IO::read().

00327 {
00328   ss_ids.resize(num_side_sets);
00329   if (num_side_sets > 0)
00330     {
00331       ex_err = exII::ex_get_side_set_ids(ex_id,
00332                                          &ss_ids[0]);
00333       check_err(ex_err, "Error retrieving sideset information.");
00334       message("All sideset information retrieved successfully."); 
00335 
00336       // Resize appropriate data structures -- only do this once outside the loop
00337       num_sides_per_set.resize(num_side_sets);
00338       num_df_per_set.resize(num_side_sets);
00339 
00340       // Inquire about the length of the
00341       // concatenated side sets element list
00342       req_info = exII::EX_INQ_SS_ELEM_LEN; 
00343       ex_err = exII::ex_inquire(ex_id,
00344                                 req_info,
00345                                 &ret_int,
00346                                 &ret_float,
00347                                 &ret_char);
00348       check_err(ex_err, "Error inquiring about side set element list length.");
00349 
00350       //std::cout << "Value returned by ex_inquire was: " << ret_int << std::endl;
00351       num_elem_all_sidesets = ret_int;  
00352       elem_list.resize (num_elem_all_sidesets);
00353       side_list.resize (num_elem_all_sidesets);
00354       id_list.resize   (num_elem_all_sidesets);
00355     }
00356 }

void ExodusII_IO_Helper::verbose ( bool  set_verbosity  ) 

Get/set flag telling whether message printing is on or off.

Definition at line 109 of file exodusII_io_helper.C.

References _verbose.

Referenced by Nemesis_IO::verbose(), and ExodusII_IO::verbose().

00110 {
00111   _verbose = set_verbosity;
00112 }

void ExodusII_IO_Helper::write_elements ( const MeshBase mesh  ) 

Writes the elements contained in "mesh" FIXME: This only works for Mesh's having a single type of element!

Definition at line 623 of file exodusII_io_helper.C.

References _verbose, Elem::active(), ExodusII_IO_Helper::ElementMaps::assign_conversion(), check_err(), connect, MeshBase::elem(), elem_id, elem_num_map, ex_err, ex_id, ExodusII_IO_Helper::Conversion::exodus_elem_type(), ExodusII_IO_Helper::Conversion::get_node_map(), DofObject::id(), libmesh_elem_num_to_exodus, Elem::n_nodes(), Elem::node(), num_elem, num_nodes_per_elem, Elem::subdomain_id(), and Elem::type().

00624 {
00625   std::map<unsigned int, std::vector<unsigned int>  > subdomain_map;
00626   
00627   //loop through element and map between block and element vector
00628   for(unsigned int i=0; i<static_cast<unsigned int>(num_elem); i++)
00629     {
00630       Elem * elem = mesh.elem(i);
00631 
00632       //Only write out the active elements
00633       if(elem->active())
00634       {
00635         unsigned int cur_subdomain = elem->subdomain_id();
00636      
00637         subdomain_map[cur_subdomain].push_back(elem->id());
00638       }
00639     }
00640 
00641   std::vector<int> elem_num_map;
00642 
00643   std::map<unsigned int, std::vector<unsigned int>  >::iterator it;
00644   
00645   for(it = subdomain_map.begin() ; it != subdomain_map.end(); it++)
00646     {
00647       std::vector<unsigned int> & tmp_vec = (*it).second;
00648 
00649       ExodusII_IO_Helper::ElementMaps em;
00650 
00651       //Use the first element in this block to get representative information.
00652       //Note that Exodus assumes all elements in a block are of the same type!
00653       //We are using that same assumption here!
00654       const ExodusII_IO_Helper::Conversion conv = em.assign_conversion(mesh.elem(tmp_vec[0])->type());
00655       num_nodes_per_elem = mesh.elem(tmp_vec[0])->n_nodes();
00656     
00657       ex_err = exII::ex_put_elem_block(ex_id, (*it).first, conv.exodus_elem_type().c_str(), tmp_vec.size(),num_nodes_per_elem,0);
00658     
00659       check_err(ex_err, "Error writing element block.");
00660   
00661       connect.resize(tmp_vec.size()*num_nodes_per_elem);
00662 
00663       for (unsigned int i=0; i<tmp_vec.size(); i++)
00664         {
00665           unsigned int elem_id = tmp_vec[i];
00666           elem_num_map.push_back(elem_id);
00667           libmesh_elem_num_to_exodus[elem_id] = elem_num_map.size();
00668           
00669           Elem * elem = mesh.elem(elem_id);
00670           
00671           for (unsigned int j=0; j < static_cast<unsigned int>(num_nodes_per_elem); j++)
00672             {  
00673               const unsigned int connect_index   = (i*num_nodes_per_elem)+j;
00674               const unsigned int elem_node_index = conv.get_node_map(j);
00675               if (_verbose)
00676                 {
00677                   std::cout << "Exodus node index: " << j
00678                             << "=LibMesh node index " << elem_node_index << std::endl;
00679                 }
00680               connect[connect_index] = elem->node(elem_node_index)+1;
00681             }
00682         }
00683     ex_err = exII::ex_put_elem_conn(ex_id, (*it).first, &connect[0]);
00684     check_err(ex_err, "Error writing element connectivities");
00685   }
00686 
00687 //  ex_err = exII::ex_put_elem_num_map(ex_id, &elem_num_map[0]);
00688   check_err(ex_err, "Error writing element connectivities");
00689 }

void ExodusII_IO_Helper::write_nodal_coordinates ( const MeshBase mesh  ) 

Writes the nodal coordinates contained in "mesh"

Definition at line 600 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, MeshBase::node_ptr(), num_nodes, x, y, and z.

00601 {
00602   x.resize(num_nodes);
00603   y.resize(num_nodes);
00604   z.resize(num_nodes);
00605 
00606   for (/* unsigned */ int i=0; i<num_nodes; ++i)
00607     {
00608       x[i]=(*mesh.node_ptr(i))(0);
00609       y[i]=(*mesh.node_ptr(i))(1);
00610       z[i]=(*mesh.node_ptr(i))(2);
00611     }
00612 
00613   ex_err = exII::ex_put_coord(ex_id,
00614                               x.empty() ? NULL : &x[0],
00615                               y.empty() ? NULL : &y[0],
00616                               z.empty() ? NULL : &z[0]);
00617 
00618   check_err(ex_err, "Error writing coordinates to Exodus file.");
00619 }

void ExodusII_IO_Helper::write_nodal_values ( int  var_id,
const std::vector< Number > &  values,
int  timestep 
)

Writes the vector of values to a nodal variable.

Definition at line 811 of file exodusII_io_helper.C.

References check_err(), ex_err, ex_id, and num_nodes.

00812 {
00813   ex_err = exII::ex_put_nodal_var(ex_id, timestep, var_id, num_nodes, &values[0]);
00814   check_err(ex_err, "Error writing nodal values.");
00815 }  

void ExodusII_IO_Helper::write_nodesets ( const MeshBase mesh  ) 

Writes the nodesets contained in "mesh"

Definition at line 730 of file exodusII_io_helper.C.

References MeshBase::boundary_info, check_err(), ex_err, and ex_id.

00731 {
00732   ExodusII_IO_Helper::ElementMaps em;
00733 
00734   std::vector< unsigned int > nl;
00735   std::vector< short int > il;
00736       
00737   mesh.boundary_info->build_node_list(nl, il);
00738 
00739   //Maps from nodeset id to the nodes
00740   std::map<short int, std::vector<int> > node;
00741 
00742   //Accumulate the vectors to pass into ex_put_node_set
00743   for(unsigned int i = 0; i < nl.size(); i++)
00744     node[il[i]].push_back(nl[i]);    
00745   
00746   std::vector<short int> node_boundary_ids;
00747   mesh.boundary_info->build_node_boundary_ids(node_boundary_ids);
00748   
00749   for(unsigned int i = 0; i < node_boundary_ids.size(); i++)
00750   {
00751     int nodeset_id = node_boundary_ids[i];
00752 
00753     ex_err = exII::ex_put_node_set_param(ex_id, nodeset_id, node[nodeset_id].size(), 0);
00754     check_err(ex_err, "Error writing nodeset parameters");
00755 
00756     ex_err = exII::ex_put_node_set(ex_id, nodeset_id, &node[nodeset_id][0]);
00757     check_err(ex_err, "Error writing nodesets");
00758   }
00759 }

void ExodusII_IO_Helper::write_sidesets ( const MeshBase mesh  ) 

Writes the sidesets contained in "mesh"

Definition at line 691 of file exodusII_io_helper.C.

References ExodusII_IO_Helper::ElementMaps::assign_conversion(), MeshBase::boundary_info, check_err(), MeshBase::elem(), ex_err, ex_id, ExodusII_IO_Helper::Conversion::get_inverse_side_map(), side, and Elem::type().

00692 {
00693   ExodusII_IO_Helper::ElementMaps em;
00694 
00695   std::vector< unsigned int > el;
00696   std::vector< unsigned short int > sl;
00697   std::vector< short int > il;
00698       
00699   mesh.boundary_info->build_side_list(el, sl, il);
00700 
00701   //Maps from sideset id to the element and sides
00702   std::map<int, std::vector<int> > elem;
00703   std::map<int, std::vector<int> > side;
00704 
00705   //Accumulate the vectors to pass into ex_put_side_set
00706   for(unsigned int i = 0; i < el.size(); i++)
00707   {
00708     const ExodusII_IO_Helper::Conversion conv = em.assign_conversion(mesh.elem(el[i])->type());
00709 
00710     elem[il[i]].push_back(el[i]+1);
00711     side[il[i]].push_back(conv.get_inverse_side_map(sl[i]));    
00712   }
00713   
00714   std::vector<short int> side_boundary_ids;
00715   mesh.boundary_info->build_side_boundary_ids(side_boundary_ids);
00716   
00717   for(unsigned int i = 0; i < side_boundary_ids.size(); i++)
00718   {
00719     int ss_id = side_boundary_ids[i];
00720 
00721     ex_err = exII::ex_put_side_set_param(ex_id, ss_id, elem[ss_id].size(), 4);
00722     check_err(ex_err, "Error writing sideset parameters");
00723     
00724     ex_err = exII::ex_put_side_set(ex_id, ss_id, &elem[ss_id][0], &side[ss_id][0]);
00725     check_err(ex_err, "Error writing sidesets");
00726   }
00727 }

void ExodusII_IO_Helper::write_timestep ( int  timestep,
double  time 
)

Writes the time for the timestep

Definition at line 803 of file exodusII_io_helper.C.

References check_err(), ex_err, and ex_id.

00804 {
00805   ex_err = exII::ex_put_time(ex_id, timestep, &time);
00806   check_err(ex_err, "Error writing timestep.");
00807 }


Member Data Documentation

bool ExodusII_IO_Helper::_created [protected]

Definition at line 581 of file exodusII_io_helper.h.

Referenced by create(), and created().

Definition at line 523 of file exodusII_io_helper.h.

Referenced by create(), and open().

Definition at line 552 of file exodusII_io_helper.h.

Referenced by read_elem_num_map(), and write_elements().

Definition at line 553 of file exodusII_io_helper.h.

Referenced by create(), and open().

std::vector<int> ExodusII_IO_Helper::id_list

Definition at line 550 of file exodusII_io_helper.h.

Referenced by get_id_list(), read_sideset(), and read_sideset_info().

Definition at line 524 of file exodusII_io_helper.h.

Referenced by create(), and open().

Definition at line 565 of file exodusII_io_helper.h.

Referenced by write_elements().

std::vector<std::string> ExodusII_IO_Helper::nodal_var_names

Definition at line 571 of file exodusII_io_helper.h.

Referenced by get_nodal_var_names(), and get_nodal_var_values().

Definition at line 572 of file exodusII_io_helper.h.

Referenced by get_nodal_var_values().

Definition at line 549 of file exodusII_io_helper.h.

Referenced by get_node_list(), and read_nodeset().

Definition at line 551 of file exodusII_io_helper.h.

Referenced by Nemesis_IO::read(), and read_node_num_map().

Definition at line 542 of file exodusII_io_helper.h.

Referenced by get_nodeset_id(), read_nodeset(), and read_nodeset_info().

Definition at line 535 of file exodusII_io_helper.h.

Referenced by read_elem_in_block().

Definition at line 545 of file exodusII_io_helper.h.

Referenced by read_sideset(), and read_sideset_info().

Definition at line 546 of file exodusII_io_helper.h.

Referenced by read_nodeset(), and read_nodeset_info().

Definition at line 568 of file exodusII_io_helper.h.

Referenced by get_time_steps(), and read_header().

Definition at line 536 of file exodusII_io_helper.h.

Referenced by read_sideset_info().

Definition at line 558 of file exodusII_io_helper.h.

Referenced by inquire(), and read_sideset_info().

Definition at line 554 of file exodusII_io_helper.h.

Referenced by inquire(), and read_sideset_info().

Definition at line 537 of file exodusII_io_helper.h.

Referenced by inquire(), and read_sideset_info().

std::vector<int> ExodusII_IO_Helper::ss_ids

Definition at line 541 of file exodusII_io_helper.h.

Referenced by read_sideset(), and read_sideset_info().

std::vector<char*> ExodusII_IO_Helper::strings

Definition at line 578 of file exodusII_io_helper.h.

Referenced by get_nodal_var_names(), and initialize_nodal_variables().

std::vector<double> ExodusII_IO_Helper::time_steps

Definition at line 569 of file exodusII_io_helper.h.

Referenced by get_time_steps().

std::vector<char> ExodusII_IO_Helper::title

Definition at line 560 of file exodusII_io_helper.h.

Referenced by ExodusII_IO_Helper(), print_header(), and read_header().

std::vector<std::vector<char> > ExodusII_IO_Helper::vvc

Definition at line 577 of file exodusII_io_helper.h.

Referenced by get_nodal_var_names(), and initialize_nodal_variables().

std::vector<double> ExodusII_IO_Helper::x

std::vector<double> ExodusII_IO_Helper::y

std::vector<double> ExodusII_IO_Helper::z


The documentation for this class was generated from the following files:

Site Created By: libMesh Developers
Last modified: November 25 2009 03:44:12.

Hosted By:
SourceForge.net Logo