22 #ifdef LIBMESH_HAVE_EXODUS_API 45 #define ARRAY_LENGTH(a) (sizeof((a))/sizeof((a)[0])) 54 std::map<std::string, ElemType> element_equivalence_map;
58 void init_element_equivalence_map()
60 if (element_equivalence_map.empty())
63 element_equivalence_map[
"SPHERE"] =
NODEELEM;
66 element_equivalence_map[
"EDGE"] =
EDGE2;
67 element_equivalence_map[
"EDGE2"] =
EDGE2;
68 element_equivalence_map[
"TRUSS"] =
EDGE2;
69 element_equivalence_map[
"BEAM"] =
EDGE2;
70 element_equivalence_map[
"BAR"] =
EDGE2;
71 element_equivalence_map[
"TRUSS2"] =
EDGE2;
72 element_equivalence_map[
"BEAM2"] =
EDGE2;
73 element_equivalence_map[
"BAR2"] =
EDGE2;
76 element_equivalence_map[
"EDGE3"] =
EDGE3;
77 element_equivalence_map[
"TRUSS3"] =
EDGE3;
78 element_equivalence_map[
"BEAM3"] =
EDGE3;
79 element_equivalence_map[
"BAR3"] =
EDGE3;
82 element_equivalence_map[
"QUAD"] =
QUAD4;
83 element_equivalence_map[
"QUAD4"] =
QUAD4;
87 element_equivalence_map[
"SHELL4"] =
QUADSHELL4;
90 element_equivalence_map[
"QUAD8"] =
QUAD8;
93 element_equivalence_map[
"SHELL8"] =
QUADSHELL8;
96 element_equivalence_map[
"QUAD9"] =
QUAD9;
100 element_equivalence_map[
"TRI"] =
TRI3;
101 element_equivalence_map[
"TRI3"] =
TRI3;
102 element_equivalence_map[
"TRIANGLE"] =
TRI3;
105 element_equivalence_map[
"TRISHELL"] =
TRISHELL3;
106 element_equivalence_map[
"TRISHELL3"] =
TRISHELL3;
109 element_equivalence_map[
"TRI6"] =
TRI6;
113 element_equivalence_map[
"HEX"] =
HEX8;
114 element_equivalence_map[
"HEX8"] =
HEX8;
117 element_equivalence_map[
"HEX20"] =
HEX20;
120 element_equivalence_map[
"HEX27"] =
HEX27;
123 element_equivalence_map[
"TETRA"] =
TET4;
124 element_equivalence_map[
"TETRA4"] =
TET4;
127 element_equivalence_map[
"TETRA10"] =
TET10;
130 element_equivalence_map[
"WEDGE"] =
PRISM6;
133 element_equivalence_map[
"WEDGE15"] =
PRISM15;
136 element_equivalence_map[
"WEDGE18"] =
PRISM18;
139 element_equivalence_map[
"PYRAMID"] =
PYRAMID5;
140 element_equivalence_map[
"PYRAMID5"] =
PYRAMID5;
143 element_equivalence_map[
"PYRAMID13"] =
PYRAMID13;
146 element_equivalence_map[
"PYRAMID14"] =
PYRAMID14;
192 const int ExodusII_IO_Helper::ElementMaps::hex20_node_map[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
193 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
203 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
205 21, 25, 24, 26, 23, 22, 20};
213 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
215 26, 20, 25, 24, 22, 21, 23};
223 const int ExodusII_IO_Helper::ElementMaps::prism15_node_map[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
225 const int ExodusII_IO_Helper::ElementMaps::prism18_node_map[18] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
226 10, 11, 12, 13, 14, 15, 16, 17};
228 const int ExodusII_IO_Helper::ElementMaps::pyramid13_node_map[13] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
229 const int ExodusII_IO_Helper::ElementMaps::pyramid14_node_map[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
272 bool run_only_on_proc0,
273 bool single_precision) :
284 num_elem_this_blk(0),
285 num_nodes_per_elem(0),
287 num_elem_all_sidesets(0),
292 opened_for_writing(false),
293 opened_for_reading(false),
294 _run_only_on_proc0(run_only_on_proc0),
295 _elem_vars_initialized(false),
296 _global_vars_initialized(false),
297 _nodal_vars_initialized(false),
298 _use_mesh_dimension_instead_of_spatial_dimension(false),
299 _write_as_dimension(0),
300 _single_precision(single_precision)
302 title.resize(MAX_LINE_LENGTH+1);
338 float ex_version = 0.;
343 comp_ws = cast_int<int>(
sizeof(float));
348 comp_ws = cast_int<int>(
std::min(
sizeof(
Real),
sizeof(
double)));
355 ex_id = exII::ex_open(filename,
356 read_only ? EX_READ : EX_WRITE,
361 std::string err_msg = std::string(
"Error opening ExodusII mesh file: ") + std::string(filename);
362 EX_CHECK_ERR(
ex_id, err_msg);
386 EX_CHECK_ERR(
ex_err,
"Error retrieving header info.");
391 EX_CHECK_ERR(
ex_err,
"Error reading number of nodal variables.");
394 EX_CHECK_ERR(
ex_err,
"Error reading number of elemental variables.");
397 EX_CHECK_ERR(
ex_err,
"Error reading number of global variables.");
399 message(
"Exodus header info retrieved successfully.");
414 <<
" QA record(s) in the Exodus file." 421 typedef char * inner_array_t[4];
422 inner_array_t * qa_record =
new inner_array_t[num_qa_rec];
424 for (
int i=0; i<num_qa_rec; i++)
425 for (
int j=0; j<4; j++)
426 qa_record[i][j] =
new char[MAX_STR_LENGTH+1];
429 EX_CHECK_ERR(
ex_err,
"Error reading the QA records.");
434 for (
int i=0; i<num_qa_rec; i++)
437 for (
int j=0; j<4; j++)
444 for (
int i=0; i<num_qa_rec; i++)
445 for (
int j=0; j<4; j++)
446 delete [] qa_record[i][j];
459 <<
"Mesh Dimension: \t" <<
num_dim << std::endl
460 <<
"Number of Nodes: \t" <<
num_nodes << std::endl
461 <<
"Number of elements: \t" <<
num_elem << std::endl
462 <<
"Number of elt blocks: \t" <<
num_elem_blk << std::endl
478 static_cast<void *>(
x.data()),
479 static_cast<void *>(
y.data()),
480 static_cast<void *>(
z.data()));
482 EX_CHECK_ERR(
ex_err,
"Error retrieving nodal data.");
483 message(
"Nodal data retrieved successfully.");
496 EX_CHECK_ERR(
ex_err,
"Error retrieving nodal number map.");
497 message(
"Nodal numbering map retrieved successfully.");
502 for (
unsigned int i=0; i<static_cast<unsigned int>(
std::min(10,
num_nodes-1)); ++i)
512 out_stream <<
"(" <<
x[i] <<
", " <<
y[i] <<
", " <<
z[i] <<
")" << std::endl;
528 EX_CHECK_ERR(
ex_err,
"Error getting block IDs.");
529 message(
"All block IDs retrieved successfully.");
531 char name_buffer[MAX_STR_LENGTH+1];
536 EX_CHECK_ERR(
ex_err,
"Error getting block name.");
539 message(
"All block names retrieved successfully.");
546 libmesh_assert_less (static_cast<unsigned int>(index),
block_ids.size());
555 libmesh_assert_less (static_cast<unsigned int>(index),
block_ids.size());
564 libmesh_assert_less (static_cast<unsigned int>(index),
ss_ids.size());
573 libmesh_assert_less (static_cast<unsigned int>(index),
ss_ids.size());
582 libmesh_assert_less (static_cast<unsigned int>(index),
nodeset_ids.size());
591 libmesh_assert_less (static_cast<unsigned int>(index),
nodeset_ids.size());
601 libmesh_assert_less (static_cast<unsigned int>(block),
block_ids.size());
613 <<
" nodes per element." << std::endl;
615 EX_CHECK_ERR(
ex_err,
"Error getting block info.");
616 message(
"Info retrieved successfully for block: ", block);
631 EX_CHECK_ERR(
ex_err,
"Error reading block connectivity.");
632 message(
"Connectivity retrieved successfully for block: ", block);
646 EX_CHECK_ERR(
ex_err,
"Error retrieving element number map.");
647 message(
"Element numbering map retrieved successfully.");
653 for (
unsigned int i=0; i<static_cast<unsigned int>(
std::min(10,
num_elem-1)); ++i)
668 EX_CHECK_ERR(
ex_err,
"Error retrieving sideset information.");
669 message(
"All sideset information retrieved successfully.");
683 char name_buffer[MAX_STR_LENGTH+1];
688 EX_CHECK_ERR(
ex_err,
"Error getting side set name.");
691 message(
"All side set names retrieved successfully.");
701 EX_CHECK_ERR(
ex_err,
"Error retrieving nodeset information.");
702 message(
"All nodeset information retrieved successfully.");
709 char name_buffer[MAX_STR_LENGTH+1];
714 EX_CHECK_ERR(
ex_err,
"Error getting node set name.");
717 message(
"All node set names retrieved successfully.");
724 libmesh_assert_less (static_cast<unsigned int>(
id),
ss_ids.size());
726 libmesh_assert_less (static_cast<unsigned int>(
id),
num_df_per_set.size());
727 libmesh_assert_less_equal (static_cast<unsigned int>(offset),
elem_list.size());
728 libmesh_assert_less_equal (static_cast<unsigned int>(offset),
side_list.size());
734 EX_CHECK_ERR(
ex_err,
"Error retrieving sideset parameters.");
735 message(
"Parameters retrieved successfully for sideset: ",
id);
741 if (static_cast<unsigned int>(offset) ==
elem_list.size() ||
742 static_cast<unsigned int>(offset) ==
side_list.size() )
755 EX_CHECK_ERR(
ex_err,
"Error retrieving sideset data.");
756 message(
"Data retrieved successfully for sideset: ",
id);
767 libmesh_assert_less (static_cast<unsigned int>(
id),
nodeset_ids.size());
775 EX_CHECK_ERR(
ex_err,
"Error retrieving nodeset parameters.");
776 message(
"Parameters retrieved successfully for nodeset: ",
id);
788 EX_CHECK_ERR(
ex_err,
"Error retrieving nodeset data.");
789 message(
"Data retrieved successfully for nodeset: ",
id);
806 EX_CHECK_ERR(
ex_err,
"Error closing Exodus file.");
807 message(
"Exodus file closed successfully.");
818 float ret_float = 0.;
826 EX_CHECK_ERR(
ex_err, error_msg);
842 EX_CHECK_ERR(
ex_err,
"Error reading timesteps!");
862 unsigned int var_index = 0;
879 libmesh_error_msg(
"Unable to locate variable named: " << nodal_var_name);
891 EX_CHECK_ERR(
ex_err,
"Error reading nodal variable values!");
910 libmesh_error_msg(
"Unrecognized ExodusVarType " << type);
918 std::vector<std::string> & result)
922 EX_CHECK_ERR(
ex_err,
"Error reading number of variables.");
929 NamesData names_table(count, MAX_STR_LENGTH);
936 EX_CHECK_ERR(
ex_err,
"Error reading variable names!");
940 libMesh::out <<
"Read the variable(s) from the file:" << std::endl;
941 for (
int i=0; i<count; i++)
946 result.resize(count);
949 for (
int i=0; i<count; i++)
970 libmesh_error_msg(
"Unrecognized ExodusVarType " << type);
979 count = cast_int<int>(names.size());
983 EX_CHECK_ERR(
ex_err,
"Error setting number of vars.");
987 NamesData names_table(count, MAX_STR_LENGTH);
990 for (
int i=0; i != count; ++i)
995 libMesh::out <<
"Writing variable name(s) to file: " << std::endl;
996 for (
int i=0; i != count; ++i)
1006 EX_CHECK_ERR(
ex_err,
"Error writing variable names.");
1014 std::map<dof_id_type, Real> & elem_var_value_map)
1019 unsigned int var_index = 0;
1036 libmesh_error_msg(
"Unable to locate variable named: " << elemental_var_name);
1040 unsigned ex_el_num = 0;
1042 for (
unsigned i=0; i<static_cast<unsigned>(
num_elem_blk); i++)
1050 EX_CHECK_ERR(
ex_err,
"Error getting number of elements in block.");
1052 std::vector<Real> block_elem_var_values(
num_elem);
1058 block_elem_var_values.data());
1059 EX_CHECK_ERR(
ex_err,
"Error getting elemental values.");
1065 unsigned mapped_elem_id = this->
elem_num_map[ex_el_num] - 1;
1068 elem_var_value_map[mapped_elem_id] = block_elem_var_values[j];
1092 comp_ws = cast_int<int>(
sizeof(float));
1093 io_ws = cast_int<int>(
sizeof(float));
1099 comp_ws = cast_int<int>
1101 io_ws = cast_int<int>
1105 ex_id = exII::ex_create(filename.c_str(), EX_CLOBBER, &comp_ws, &io_ws);
1107 EX_CHECK_ERR(
ex_id,
"Error creating ExodusII mesh file.");
1110 libMesh::out <<
"File created successfully." << std::endl;
1137 if (!use_discontinuous)
1150 std::vector<boundary_id_type> unique_side_boundaries;
1151 std::vector<boundary_id_type> unique_node_boundaries;
1157 std::vector<boundary_id_type> shellface_boundaries;
1159 for (
const auto &
id : shellface_boundaries)
1160 unique_side_boundaries.push_back(
id);
1164 num_side_sets = cast_int<int>(unique_side_boundaries.size());
1165 num_node_sets = cast_int<int>(unique_node_boundaries.size());
1168 std::map<subdomain_id_type, std::vector<unsigned int>> subdomain_map;
1175 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 1176 if (elem->infinite())
1181 subdomain_map[cur_subdomain].push_back(elem->id());
1185 if (str_title.size() > MAX_LINE_LENGTH)
1187 libMesh::err <<
"Warning, Exodus files cannot have titles longer than " 1189 <<
" characters. Your title will be truncated." 1191 str_title.resize(MAX_LINE_LENGTH);
1203 EX_CHECK_ERR(
ex_err,
"Error initializing new Exodus file.");
1237 if (!use_discontinuous)
1241 const Node & node = *node_ptr;
1268 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1270 x.push_back(elem->point(n)(0));
1272 y.push_back(elem->point(n)(1));
1277 z.push_back(elem->point(n)(2));
1294 x_single(
x.begin(),
x.end()),
1295 y_single(
y.begin(),
y.end()),
1296 z_single(
z.begin(),
z.end());
1299 x_single.empty() ? nullptr : x_single.data(),
1300 y_single.empty() ? nullptr : y_single.data(),
1301 z_single.empty() ? nullptr : z_single.data());
1306 x.empty() ? nullptr :
x.data(),
1307 y.empty() ? nullptr :
y.data(),
1308 z.empty() ? nullptr :
z.data());
1312 EX_CHECK_ERR(
ex_err,
"Error writing coordinates to Exodus file.");
1314 if (!use_discontinuous)
1318 EX_CHECK_ERR(
ex_err,
"Error writing node_num_map");
1334 typedef std::map<subdomain_id_type, std::vector<dof_id_type>> subdomain_map_type;
1335 subdomain_map_type subdomain_map;
1343 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 1344 if (elem->infinite())
1348 subdomain_map[ elem->subdomain_id() ].push_back(elem->id());
1355 std::vector<int>::iterator curr_elem_map_end =
elem_num_map.begin();
1357 std::vector<int> elem_blk_id;
1358 std::vector<int> num_elem_this_blk_vec;
1359 std::vector<int> num_nodes_per_elem_vec;
1360 std::vector<int> num_attr_vec;
1370 unsigned int counter = 0;
1371 for (
auto & pr : subdomain_map)
1377 subdomain_map_type::mapped_type & tmp_vec = pr.second;
1387 elem_blk_id.push_back(pr.first);
1389 num_elem_this_blk_vec.push_back(cast_int<int>(tmp_vec.size()));
1391 num_attr_vec.push_back(0);
1400 num_elem_this_blk_vec.data(),
1401 num_nodes_per_elem_vec.data(),
1402 num_attr_vec.data(),
1404 EX_CHECK_ERR(
ex_err,
"Error writing element blocks.");
1407 unsigned libmesh_elem_num_to_exodus_counter = 0;
1412 std::map< std::pair<dof_id_type,unsigned int>,
dof_id_type > discontinuous_node_indices;
1413 if (use_discontinuous)
1417 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1419 std::pair<dof_id_type,unsigned int> id_pair;
1420 id_pair.first = elem->id();
1422 discontinuous_node_indices[id_pair] = node_counter;
1427 for (
auto & pr : subdomain_map)
1430 subdomain_map_type::mapped_type & tmp_vec = pr.second;
1444 unsigned int elem_id = tmp_vec[i];
1460 libmesh_error_msg(
"Error: Exodus requires all elements with a given subdomain ID to be the same type.\n" \
1461 <<
"Can't write both " \
1465 <<
" in the same block!");
1475 <<
" = LibMesh node index " << elem_node_index << std::endl;
1478 if (!use_discontinuous)
1486 std::map<int, int>::iterator pos =
1491 libmesh_error_msg(
"libmesh node id " << libmesh_node_id <<
" not found in node_num_map.");
1496 connect[connect_index] = pos->second;
1500 std::pair<dof_id_type,unsigned int> id_pair;
1501 id_pair.first = elem_id;
1502 id_pair.second = elem_node_index;
1503 auto node_it = discontinuous_node_indices.find(id_pair);
1505 libmesh_assert(node_it != discontinuous_node_indices.end());
1507 connect[connect_index] = node_it->second;
1513 EX_CHECK_ERR(
ex_err,
"Error writing element connectivities");
1517 curr_elem_map_end = std::transform(tmp_vec.begin(),
1520 std::bind2nd(std::plus<subdomain_map_type::mapped_type::value_type>(), 1));
1530 EX_CHECK_ERR(
ex_err,
"Error writing element map");
1536 EX_CHECK_ERR(
ex_err,
"Error writing element names");
1552 std::map<int, std::vector<int>> elem;
1553 std::map<int, std::vector<int>>
side;
1554 std::vector<boundary_id_type> side_boundary_ids;
1561 std::vector<const Elem *> family;
1562 #ifdef LIBMESH_ENABLE_AMR 1572 for (
const auto & f : family)
1593 std::vector<const Elem *> family;
1594 #ifdef LIBMESH_ENABLE_AMR 1604 for (
const auto & f : family)
1616 std::vector<boundary_id_type> shellface_boundary_ids;
1618 for (
const auto &
id : shellface_boundary_ids)
1619 side_boundary_ids.push_back(
id);
1623 if (side_boundary_ids.size() > 0)
1625 NamesData names_table(side_boundary_ids.size(), MAX_STR_LENGTH);
1627 std::vector<exII::ex_set> sets(side_boundary_ids.size());
1636 sets[i].num_entry = elem[ss_id].size();
1637 sets[i].num_distribution_factor = 0;
1638 sets[i].entry_list = elem[ss_id].data();
1639 sets[i].extra_list =
side[ss_id].data();
1640 sets[i].distribution_factor_list =
nullptr;
1644 EX_CHECK_ERR(
ex_err,
"Error writing sidesets");
1647 EX_CHECK_ERR(
ex_err,
"Error writing sideset names");
1659 std::map<boundary_id_type, std::vector<int>> node;
1664 node[std::get<1>(t)].push_back(std::get<0>(t) + 1);
1666 std::vector<boundary_id_type> node_boundary_ids;
1670 if (node_boundary_ids.size() > 0)
1672 NamesData names_table(node_boundary_ids.size(), MAX_STR_LENGTH);
1674 for (
const auto & nodeset_id : node_boundary_ids)
1676 int actual_id = nodeset_id;
1681 EX_CHECK_ERR(
ex_err,
"Error writing nodeset parameters");
1684 EX_CHECK_ERR(
ex_err,
"Error writing nodesets");
1689 EX_CHECK_ERR(
ex_err,
"Error writing nodeset names");
1696 const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains)
1702 if (names.size() == 0)
1725 for (
auto var_num :
index_range(vars_active_subdomains))
1729 std::set<subdomain_id_type> current_set;
1730 if (vars_active_subdomains[var_num].empty())
1732 current_set.insert(cast_int<subdomain_id_type>(block_id));
1734 current_set = vars_active_subdomains[var_num];
1737 for (
auto block_id : current_set)
1741 libmesh_error_msg(
"ExodusII_IO_Helper: block id " << block_id <<
" not found in block_ids.");
1743 std::size_t block_index =
1746 std::size_t truth_tab_index = block_index*
num_elem_vars + var_num;
1747 truth_tab[truth_tab_index] = 1;
1755 EX_CHECK_ERR(
ex_err,
"Error writing element truth table.");
1766 if (names.size() == 0)
1794 if (names.size() == 0)
1815 std::vector<std::string> & names,
1816 std::vector<std::string> & names_from_file)
1827 if (names_from_file != names)
1829 libMesh::err <<
"Error! The Exodus file already contains the variables:" << std::endl;
1830 for (
const auto &
name : names_from_file)
1833 libMesh::err <<
"And you asked to write:" << std::endl;
1834 for (
const auto &
name : names)
1837 libmesh_error_msg(
"Cannot overwrite existing variables in Exodus II file.");
1850 float cast_time = float(time);
1857 EX_CHECK_ERR(
ex_err,
"Error writing timestep.");
1860 EX_CHECK_ERR(
ex_err,
"Error flushing buffers to file.");
1866 const std::vector<Real> & values,
1868 const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains)
1874 std::map<subdomain_id_type, std::vector<unsigned int>> subdomain_map;
1878 EX_CHECK_ERR(
ex_err,
"Error reading number of elemental variables.");
1882 subdomain_map[elem->subdomain_id()].push_back(elem->id());
1892 libmesh_assert_equal_to(vars_active_subdomains.size(),
static_cast<unsigned>(
num_elem_vars));
1893 for (
unsigned int i=0; i<static_cast<unsigned>(
num_elem_vars); ++i)
1896 std::map<subdomain_id_type, std::vector<unsigned int>>::iterator it = subdomain_map.begin();
1898 const std::set<subdomain_id_type> & active_subdomains = vars_active_subdomains[i];
1899 for (
unsigned int j=0; it!=subdomain_map.end(); ++it, ++j)
1904 if (!active_subdomains.empty())
1905 if (active_subdomains.find(it->first) == active_subdomains.end())
1910 const std::vector<unsigned int> & elem_nums = (*it).second;
1911 const unsigned int num_elems_this_block =
1912 cast_int<unsigned int>(elem_nums.size());
1913 std::vector<Real>
data(num_elems_this_block);
1915 for (
unsigned int k=0; k<num_elems_this_block; ++k)
1920 std::vector<float> cast_data(
data.begin(),
data.end());
1926 num_elems_this_block,
1935 num_elems_this_block,
1938 EX_CHECK_ERR(
ex_err,
"Error writing element values.");
1943 EX_CHECK_ERR(
ex_err,
"Error flushing buffers to file.");
1955 std::vector<float> cast_values(values.begin(), values.end());
1962 EX_CHECK_ERR(
ex_err,
"Error writing nodal values.");
1965 EX_CHECK_ERR(
ex_err,
"Error flushing buffers to file.");
1982 libMesh::err <<
"Warning! The Exodus file already contains information records.\n" 1983 <<
"Exodus does not support writing additional records in this situation." 1988 int num_records = cast_int<int>(records.size());
1990 if (num_records > 0)
1992 NamesData info(num_records, MAX_LINE_LENGTH);
1996 for (
const auto & record : records)
2000 EX_CHECK_ERR(
ex_err,
"Error writing global values.");
2003 EX_CHECK_ERR(
ex_err,
"Error flushing buffers to file.");
2016 std::vector<float> cast_values(values.begin(), values.end());
2023 EX_CHECK_ERR(
ex_err,
"Error writing global values.");
2026 EX_CHECK_ERR(
ex_err,
"Error flushing buffers to file.");
2039 EX_CHECK_ERR(
ex_err,
"Error reading global values.");
2066 std::vector<std::string>::const_iterator names_it = names.begin();
2067 std::vector<std::string>::const_iterator names_end = names.end();
2069 std::vector<std::string> complex_names;
2073 for (; names_it != names_end; ++names_it)
2075 std::stringstream name_real, name_imag, name_abs;
2076 name_real <<
"r_" << *names_it;
2077 name_imag <<
"i_" << *names_it;
2078 name_abs <<
"a_" << *names_it;
2080 complex_names.push_back(name_real.str());
2081 complex_names.push_back(name_imag.str());
2082 complex_names.push_back(name_abs.str());
2085 return complex_names;
2091 const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains)
const 2093 std::vector<std::set<subdomain_id_type>> complex_vars_active_subdomains;
2095 for (
auto & s : vars_active_subdomains)
2099 complex_vars_active_subdomains.push_back(s);
2100 complex_vars_active_subdomains.push_back(s);
2101 complex_vars_active_subdomains.push_back(s);
2104 return complex_vars_active_subdomains;
2113 init_element_equivalence_map();
2116 std::transform(type_str.begin(), type_str.end(), type_str.begin(), ::toupper);
2118 std::map<std::string, ElemType>::iterator it =
2119 element_equivalence_map.find(type_str);
2121 if (it != element_equivalence_map.end())
2124 libmesh_error_msg(
"ERROR! Unrecognized element type_str: " << type_str);
2136 ARRAY_LENGTH(nodeelem_node_map),
2138 ARRAY_LENGTH(nodeelem_node_map),
2150 ARRAY_LENGTH(edge2_node_map),
2152 ARRAY_LENGTH(edge2_node_map),
2154 ARRAY_LENGTH(edge_edge_map),
2155 edge_inverse_edge_map,
2156 ARRAY_LENGTH(edge_inverse_edge_map),
2163 ARRAY_LENGTH(edge3_node_map),
2165 ARRAY_LENGTH(edge3_node_map),
2167 ARRAY_LENGTH(edge_edge_map),
2168 edge_inverse_edge_map,
2169 ARRAY_LENGTH(edge_inverse_edge_map),
2176 ARRAY_LENGTH(quad4_node_map),
2178 ARRAY_LENGTH(quad4_node_map),
2180 ARRAY_LENGTH(quad_edge_map),
2181 quad_inverse_edge_map,
2182 ARRAY_LENGTH(quad_inverse_edge_map),
2191 ARRAY_LENGTH(quad4_node_map),
2193 ARRAY_LENGTH(quad4_node_map),
2194 quadshell4_edge_map,
2195 ARRAY_LENGTH(quadshell4_edge_map),
2196 quadshell4_inverse_edge_map,
2197 ARRAY_LENGTH(quadshell4_inverse_edge_map),
2198 quadshell4_shellface_map,
2199 ARRAY_LENGTH(quadshell4_shellface_map),
2200 quadshell4_inverse_shellface_map,
2201 ARRAY_LENGTH(quadshell4_inverse_shellface_map),
2210 ARRAY_LENGTH(quad8_node_map),
2212 ARRAY_LENGTH(quad8_node_map),
2214 ARRAY_LENGTH(quad_edge_map),
2215 quad_inverse_edge_map,
2216 ARRAY_LENGTH(quad_inverse_edge_map),
2225 ARRAY_LENGTH(quad8_node_map),
2227 ARRAY_LENGTH(quad8_node_map),
2228 quadshell4_edge_map,
2229 ARRAY_LENGTH(quadshell4_edge_map),
2230 quadshell4_inverse_edge_map,
2231 ARRAY_LENGTH(quadshell4_inverse_edge_map),
2232 quadshell4_shellface_map,
2233 ARRAY_LENGTH(quadshell4_shellface_map),
2234 quadshell4_inverse_shellface_map,
2235 ARRAY_LENGTH(quadshell4_inverse_shellface_map),
2244 ARRAY_LENGTH(quad9_node_map),
2246 ARRAY_LENGTH(quad9_node_map),
2248 ARRAY_LENGTH(quad_edge_map),
2249 quad_inverse_edge_map,
2250 ARRAY_LENGTH(quad_inverse_edge_map),
2259 ARRAY_LENGTH(tri3_node_map),
2261 ARRAY_LENGTH(tri3_node_map),
2263 ARRAY_LENGTH(tri_edge_map),
2264 tri_inverse_edge_map,
2265 ARRAY_LENGTH(tri_inverse_edge_map),
2273 ARRAY_LENGTH(tri3_node_map),
2275 ARRAY_LENGTH(tri3_node_map),
2277 ARRAY_LENGTH(trishell3_edge_map),
2278 trishell3_inverse_edge_map,
2279 ARRAY_LENGTH(trishell3_inverse_edge_map),
2280 trishell3_shellface_map,
2281 ARRAY_LENGTH(trishell3_shellface_map),
2282 trishell3_inverse_shellface_map,
2283 ARRAY_LENGTH(trishell3_inverse_shellface_map),
2292 ARRAY_LENGTH(tri3_node_map),
2294 ARRAY_LENGTH(tri3_node_map),
2296 ARRAY_LENGTH(tri_edge_map),
2297 tri_inverse_edge_map,
2298 ARRAY_LENGTH(tri_inverse_edge_map),
2307 ARRAY_LENGTH(tri6_node_map),
2309 ARRAY_LENGTH(tri6_node_map),
2311 ARRAY_LENGTH(tri_edge_map),
2312 tri_inverse_edge_map,
2313 ARRAY_LENGTH(tri_inverse_edge_map),
2322 ARRAY_LENGTH(hex8_node_map),
2324 ARRAY_LENGTH(hex8_node_map),
2326 ARRAY_LENGTH(hex_face_map),
2327 hex_inverse_face_map,
2328 ARRAY_LENGTH(hex_inverse_face_map),
2337 ARRAY_LENGTH(hex20_node_map),
2339 ARRAY_LENGTH(hex20_node_map),
2341 ARRAY_LENGTH(hex_face_map),
2342 hex_inverse_face_map,
2343 ARRAY_LENGTH(hex_inverse_face_map),
2352 ARRAY_LENGTH(hex27_node_map),
2353 hex27_inverse_node_map,
2354 ARRAY_LENGTH(hex27_inverse_node_map),
2356 ARRAY_LENGTH(hex27_face_map),
2357 hex27_inverse_face_map,
2358 ARRAY_LENGTH(hex27_inverse_face_map),
2367 ARRAY_LENGTH(tet4_node_map),
2369 ARRAY_LENGTH(tet4_node_map),
2371 ARRAY_LENGTH(tet_face_map),
2372 tet_inverse_face_map,
2373 ARRAY_LENGTH(tet_inverse_face_map),
2382 ARRAY_LENGTH(tet10_node_map),
2384 ARRAY_LENGTH(tet10_node_map),
2386 ARRAY_LENGTH(tet_face_map),
2387 tet_inverse_face_map,
2388 ARRAY_LENGTH(tet_inverse_face_map),
2397 ARRAY_LENGTH(prism6_node_map),
2399 ARRAY_LENGTH(prism6_node_map),
2401 ARRAY_LENGTH(prism_face_map),
2402 prism_inverse_face_map,
2403 ARRAY_LENGTH(prism_inverse_face_map),
2412 ARRAY_LENGTH(prism15_node_map),
2414 ARRAY_LENGTH(prism15_node_map),
2416 ARRAY_LENGTH(prism_face_map),
2417 prism_inverse_face_map,
2418 ARRAY_LENGTH(prism_inverse_face_map),
2427 ARRAY_LENGTH(prism18_node_map),
2429 ARRAY_LENGTH(prism18_node_map),
2431 ARRAY_LENGTH(prism_face_map),
2432 prism_inverse_face_map,
2433 ARRAY_LENGTH(prism_inverse_face_map),
2442 ARRAY_LENGTH(pyramid5_node_map),
2444 ARRAY_LENGTH(pyramid5_node_map),
2446 ARRAY_LENGTH(pyramid_face_map),
2447 pyramid_inverse_face_map,
2448 ARRAY_LENGTH(pyramid_inverse_face_map),
2457 ARRAY_LENGTH(pyramid13_node_map),
2459 ARRAY_LENGTH(pyramid13_node_map),
2461 ARRAY_LENGTH(pyramid_face_map),
2462 pyramid_inverse_face_map,
2463 ARRAY_LENGTH(pyramid_inverse_face_map),
2472 ARRAY_LENGTH(pyramid14_node_map),
2474 ARRAY_LENGTH(pyramid14_node_map),
2476 ARRAY_LENGTH(pyramid_face_map),
2477 pyramid_inverse_face_map,
2478 ARRAY_LENGTH(pyramid_inverse_face_map),
2485 libmesh_error_msg(
"Unsupported element type: " << type);
2495 if (static_cast<size_t>(i) >= side_map_size)
2504 data_table(n_strings),
2505 data_table_pointers(n_strings),
2507 table_size(n_strings)
2509 for (
size_t i=0; i<n_strings; ++i)
2525 libmesh_assert_less (counter, table_size);
2528 size_t num_copied =
name.copy(data_table[counter].
data(), data_table[counter].size()-1);
2531 data_table[counter][num_copied] =
'\0';
2541 return data_table_pointers.data();
2548 if (static_cast<unsigned>(i) >= table_size)
2549 libmesh_error_msg(
"Requested char * " << i <<
" but only have " << table_size <<
"!");
2552 return data_table[i].data();
2560 #endif // #ifdef LIBMESH_HAVE_EXODUS_API std::string name(const ElemQuality q)
virtual void write_sidesets(const MeshBase &mesh)
static const int quad9_node_map[9]
void use_mesh_dimension_instead_of_spatial_dimension(bool val)
EXODUS_EXPORT int ex_put_glob_vars(int exoid, int time_step, int num_glob_vars, const void *glob_var_vals)
std::vector< int > id_list
EXODUS_EXPORT int ex_get_elem_block(int exoid, ex_entity_id elem_blk_id, char *elem_type, void_int *num_elem_this_blk, void_int *num_nodes_per_elem, void_int *num_attr)
EXODUS_EXPORT int ex_get_side_set_ids(int exoid, void_int *ids)
static const int prism_inverse_face_map[5]
EXODUS_EXPORT int ex_put_info(int exoid, int num_info, char *info[])
std::vector< int > node_num_map
static const int tet10_node_map[10]
std::vector< Real > nodal_var_values
std::vector< std::string > get_complex_names(const std::vector< std::string > &names) const
bool _elem_vars_initialized
EXODUS_EXPORT int ex_get_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, char *name)
std::vector< int > num_sides_per_set
const char * get_elem_type() const
std::vector< std::string > elem_var_names
virtual dof_id_type n_active_elem() const =0
A geometric point in (x,y,z) space associated with a DOF.
EXODUS_EXPORT int ex_get_qa(int exoid, char *qa_record[][4])
EXODUS_EXPORT int ex_get_node_set_param(int exoid, ex_entity_id node_set_id, void_int *num_nodes_in_set, void_int *num_df_in_set)
void write_var_names_impl(const char *var_type, int &count, std::vector< std::string > &names)
static const int quadshell4_inverse_shellface_map[2]
EXODUS_EXPORT int ex_get_var_names(int exoid, const char *var_type, int num_vars, char *var_names[])
EXODUS_EXPORT int ex_get_node_num_map(int exoid, void_int *node_map)
EXODUS_EXPORT int ex_get_side_set(int exoid, ex_entity_id side_set_id, void_int *side_set_elem_list, void_int *side_set_side_list)
void write_var_names(ExodusVarType type, std::vector< std::string > &names)
std::map< int, std::string > id_to_ss_names
virtual ~ExodusII_IO_Helper()
static const int tet_face_map[4]
std::string get_block_name(int index)
static const int hex_face_map[6]
void read_nodal_var_values(std::string nodal_var_name, int time_step)
static const int quad8_node_map[8]
ExodusII_IO_Helper(const ParallelObject &parent, bool v=false, bool run_only_on_proc0=true, bool single_precision=false)
void write_information_records(const std::vector< std::string > &records)
void read_var_names_impl(const char *var_type, int &count, std::vector< std::string > &result)
static const int invalid_id
static const int prism15_node_map[15]
void write_as_dimension(unsigned dim)
void read_nodeset(int id)
static const int hex8_node_map[8]
static const int pyramid13_node_map[13]
EXODUS_EXPORT int ex_put_concat_elem_block(int exoid, const void_int *elem_blk_id, char *elem_type[], const void_int *num_elem_this_blk, const void_int *num_nodes_per_elem, const void_int *num_attr, int define_maps)
void print_nodes(std::ostream &out=libMesh::out)
std::string get_side_set_name(int index)
EXODUS_EXPORT int ex_get_node_set(int exoid, ex_entity_id node_set_id, void_int *node_set_node_list)
static const int hex27_inverse_node_map[27]
EXODUS_EXPORT int ex_put_node_set_param(int exoid, ex_entity_id node_set_id, int64_t num_nodes_in_set, int64_t num_dist_in_set)
static const int tet4_node_map[4]
The base class for all geometric element types.
IntRange< std::size_t > index_range(const std::vector< T > &vec)
bool _global_vars_initialized
ExodusII_IO_Helper::Conversion assign_conversion(std::string type_str)
static const int tet_inverse_face_map[4]
EXODUS_EXPORT int ex_get_elem_num_map(int exoid, void_int *elem_map)
std::vector< int > block_ids
std::vector< int > side_list
int inquire(int req_info, std::string error_msg="")
virtual void write_nodesets(const MeshBase &mesh)
static const int trishell3_inverse_shellface_map[2]
EXODUS_EXPORT int ex_put_var_param(int exoid, const char *var_type, int num_vars)
EXODUS_EXPORT int ex_put_coord(int exoid, const void *x_coor, const void *y_coor, const void *z_coor)
void build_side_boundary_ids(std::vector< boundary_id_type > &b_ids) const
static const int pyramid5_node_map[5]
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
static const int edge2_node_map[2]
std::vector< Real > time_steps
virtual void write_elements(const MeshBase &mesh, bool use_discontinuous=false)
static const int tri_inverse_edge_map[3]
std::vector< std::vector< char > > data_table
EXODUS_EXPORT int ex_get_node_set_ids(int exoid, void_int *ids)
static const int pyramid_face_map[5]
ElemType get_canonical_type() const
static const int hex27_inverse_face_map[6]
const BoundaryInfo & get_boundary_info() const
long double max(long double a, double b)
void write_nodal_values(int var_id, const std::vector< Real > &values, int timestep)
static const int quadshell4_edge_map[4]
void check_existing_vars(ExodusVarType type, std::vector< std::string > &names, std::vector< std::string > &names_from_file)
EXODUS_EXPORT int ex_put_init(int exoid, const char *title, int64_t num_dim, int64_t num_nodes, int64_t num_elem, int64_t num_elem_blk, int64_t num_node_sets, int64_t num_side_sets)
EXODUS_EXPORT int ex_put_var_names(int exoid, const char *var_type, int num_vars, char *var_names[])
static const int pyramid14_node_map[14]
static const int quad_inverse_edge_map[4]
void write_element_values(const MeshBase &mesh, const std::vector< Real > &values, int timestep, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains)
void write_timestep(int timestep, Real time)
static const int prism6_node_map[6]
std::map< int, int > libmesh_elem_num_to_exodus
EXODUS_EXPORT int ex_put_sets(int exoid, size_t set_count, const struct ex_set *sets)
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
std::vector< int > node_list
bool _use_mesh_dimension_instead_of_spatial_dimension
EXODUS_EXPORT int ex_inquire(int exoid, int inquiry, void_int *, float *, char *)
EXODUS_EXPORT int ex_get_init(int exoid, char *title, void_int *num_dim, void_int *num_nodes, void_int *num_elem, void_int *num_elem_blk, void_int *num_node_sets, void_int *num_side_sets)
EXODUS_EXPORT int ex_get_all_times(int exoid, void *time_values)
EXODUS_EXPORT int ex_put_elem_var(int exoid, int time_step, int elem_var_index, ex_entity_id elem_blk_id, int64_t num_elem_this_blk, const void *elem_var_vals)
virtual node_iterator nodes_begin()=0
EXODUS_EXPORT int ex_put_node_set(int exoid, ex_entity_id node_set_id, const void_int *node_set_node_list)
virtual void initialize_element_variables(std::vector< std::string > names, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains)
void open(const char *filename, bool read_only)
static const int edge_inverse_edge_map[2]
void build_node_list(std::vector< dof_id_type > &node_id_list, std::vector< boundary_id_type > &bc_id_list) const
static const int hex27_face_map[6]
char * get_char_star(int i)
static const int pyramid_inverse_face_map[5]
static const int trishell3_edge_map[3]
std::vector< int > nodeset_ids
void active_family_tree_by_side(std::vector< const Elem *> &family, const unsigned int side, const bool reset=true) const
void push_back_entry(const std::string &name)
void read_global_values(std::vector< Real > &values, int timestep)
virtual unsigned int n_nodes() const =0
std::vector< int > elem_list
EXODUS_EXPORT int ex_get_elem_blk_ids(int exoid, void_int *ids)
std::vector< std::string > global_var_names
static const int edge_edge_map[2]
EXODUS_EXPORT int ex_get_nodal_var(int exoid, int time_step, int nodal_var_index, int64_t num_nodes, void *nodal_var_vals)
virtual SimpleRange< node_iterator > node_ptr_range()=0
void read_var_names(ExodusVarType type)
std::vector< int > connect
EXODUS_EXPORT int ex_get_side_set_param(int exoid, ex_entity_id side_set_id, void_int *num_side_in_set, void_int *num_dist_fact_in_set)
std::vector< int > ss_ids
int get_inverse_shellface_map(int i) const
static const int quad_edge_map[4]
void set_coordinate_offset(Point p)
std::string & subdomain_name(subdomain_id_type id)
static const int hex20_node_map[20]
OStreamProxy err(std::cerr)
void write_global_values(const std::vector< Real > &values, int timestep)
EXODUS_EXPORT int ex_put_names(int exoid, ex_entity_type obj_type, char *names[])
int get_inverse_node_map(int i) const
void build_shellface_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &shellface_list, std::vector< boundary_id_type > &bc_id_list) const
An object whose state is distributed along a set of processors.
void read_elem_in_block(int block)
static const int tri6_node_map[6]
const std::string & get_nodeset_name(boundary_id_type id) const
std::map< int, int > libmesh_node_num_to_exodus
static const int edge3_node_map[3]
void initialize_global_variables(std::vector< std::string > names)
EXODUS_EXPORT int ex_get_elem_var(int exoid, int time_step, int elem_var_index, ex_entity_id elem_blk_id, int64_t num_elem_this_blk, void *elem_var_vals)
unsigned _write_as_dimension
std::vector< char * > data_table_pointers
std::string enum_to_string(const T e)
std::vector< int > num_node_df_per_set
char ** get_char_star_star()
int get_node_set_id(int index)
virtual const Elem * elem_ptr(const dof_id_type i) const =0
void build_node_boundary_ids(std::vector< boundary_id_type > &b_ids) const
EXODUS_EXPORT int ex_get_coord(int exoid, void *x_coor, void *y_coor, void *z_coor)
void message(const std::string &msg)
virtual void initialize(std::string title, const MeshBase &mesh, bool use_discontinuous=false)
EXODUS_EXPORT int ex_get_glob_vars(int exoid, int time_step, int num_glob_vars, void *glob_var_vals)
virtual void create(std::string filename)
static const int hex27_node_map[27]
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual node_iterator nodes_end()=0
void read_num_time_steps()
EXODUS_EXPORT int ex_put_node_num_map(int exoid, const void_int *node_map)
EXODUS_EXPORT int ex_close(int exoid)
unsigned int spatial_dimension() const
void read_sideset(int id, int offset)
EXODUS_EXPORT int ex_put_elem_conn(int exoid, ex_entity_id elem_blk_id, const void_int *connect)
int get_inverse_side_map(int i) const
NamesData(size_t n_strings, size_t string_length)
const std::string & get_sideset_name(boundary_id_type id) const
virtual const Elem & elem_ref(const dof_id_type i) const
std::map< int, std::string > id_to_block_names
static const int trishell3_shellface_map[2]
EXODUS_EXPORT int ex_get_elem_conn(int exoid, ex_entity_id elem_blk_id, void_int *connect)
unsigned int mesh_dimension() const
std::vector< int > elem_num_map
static const int hex_inverse_face_map[6]
int get_side_set_id(int index)
static const int prism18_node_map[18]
EXODUS_EXPORT int ex_get_var_param(int exoid, const char *var_type, int *num_vars)
std::map< int, std::string > id_to_ns_names
void initialize_nodal_variables(std::vector< std::string > names)
std::vector< char > title
std::vector< int > num_nodes_per_set
std::string exodus_elem_type() const
static const int prism_face_map[5]
EXODUS_EXPORT int ex_put_elem_var_tab(int exoid, int num_elem_blk, int num_elem_var, int *elem_var_tab)
std::vector< std::string > nodal_var_names
EXODUS_EXPORT int ex_update(int exoid)
EXODUS_EXPORT void ex_err(const char *module_name, const char *message, int err_num)
std::string get_node_set_name(int index)
std::string current_filename
static const int trishell3_inverse_edge_map[3]
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
EXODUS_EXPORT int ex_put_elem_num_map(int exoid, const void_int *elem_map)
OStreamProxy out(std::cout)
void read_elemental_var_values(std::string elemental_var_name, int time_step, std::map< dof_id_type, Real > &elem_var_value_map)
std::vector< char > elem_type
static const int quadshell4_shellface_map[2]
EXODUS_EXPORT int ex_put_time(int exoid, int time_step, const void *time_value)
virtual ElemType type() const =0
long double min(long double a, double b)
A geometric point in (x,y,z) space.
dof_id_type node_id(const unsigned int i) const
static const int tri3_node_map[3]
int get_block_id(int index)
static const int quadshell4_inverse_edge_map[4]
std::vector< int > num_df_per_set
void build_shellface_boundary_ids(std::vector< boundary_id_type > &b_ids) const
int num_elem_all_sidesets
virtual void write_nodal_coordinates(const MeshBase &mesh, bool use_discontinuous=false)
static const int nodeelem_node_map[1]
static const int tri_edge_map[3]
int get_side_map(int i) const
EXODUS_EXPORT int ex_put_nodal_var(int exoid, int time_step, int nodal_var_index, int64_t num_nodes, const void *nodal_var_vals)
std::vector< std::set< subdomain_id_type > > get_complex_vars_active_subdomains(const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains) const
static const int quad4_node_map[4]
bool _nodal_vars_initialized