20#include "libmesh/distributed_mesh.h"
21#include "libmesh/dof_map.h"
22#include "libmesh/elem.h"
23#include "libmesh/exodusII_io.h"
24#include "libmesh/libmesh_logging.h"
25#include "libmesh/nemesis_io.h"
26#include "libmesh/nemesis_io_helper.h"
27#include "libmesh/node.h"
28#include "libmesh/parallel.h"
29#include "libmesh/utility.h"
30#include "libmesh/boundary_info.h"
31#include "libmesh/mesh_communication.h"
32#include "libmesh/fe_interface.h"
33#include "libmesh/fe_type.h"
34#include "libmesh/equation_systems.h"
35#include "libmesh/numeric_vector.h"
36#include "libmesh/int_range.h"
50#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
51struct CompareGlobalIdxMappings
55 bool operator()(
const std::pair<unsigned int, unsigned int> & a,
56 const std::pair<unsigned int, unsigned int> &
b)
const
57 {
return a.first <
b.first; }
61 bool operator()(
const std::pair<unsigned int, unsigned int> & a,
62 const unsigned int b)
const
63 {
return a.first <
b; }
72inline unsigned int to_uint (
const T & t )
74 libmesh_assert_equal_to (t,
static_cast<T
>(
static_cast<unsigned int>(t)));
76 return static_cast<unsigned int>(t);
81#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API) && !defined(NDEBUG)
82inline bool global_idx_mapping_equality (
const std::pair<unsigned int, unsigned int> & a,
83 const std::pair<unsigned int, unsigned int> &
b)
85 return a.first ==
b.first;
96 bool single_precision) :
100#
if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
106 _allow_empty_variables(false)
115 bool single_precision) :
119#
if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
125 _allow_empty_variables(false)
143#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
154#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
181#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
187 std::vector<unsigned char> pid_send_partner (this->
n_processors(), 0);
193 for (
unsigned int cmap=0; cmap<to_uint(
nemhelper->num_node_cmaps); cmap++)
195 libmesh_assert_less (
nemhelper->node_cmap_ids[cmap], this->n_processors());
197 pid_send_partner[
nemhelper->node_cmap_ids[cmap]] = 1;
202 const std::vector<unsigned char> pid_recv_partner (pid_send_partner);
214#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
217 LOG_SCOPE (
"read()",
"Nemesis_IO");
220 parallel_object_only();
230 std::string nemesis_filename =
nemhelper->construct_nemesis_filename(base_filename);
233 libMesh::out <<
"Opening file: " << nemesis_filename << std::endl;
236 nemhelper->open(nemesis_filename.c_str(),
true);
266 libmesh_error_msg_if(
nemhelper->num_external_nodes,
267 "ERROR: there should be no external nodes in an element-based partitioning!");
269 libmesh_assert_equal_to (
nemhelper->num_nodes,
273 libmesh_assert_equal_to (
nemhelper->num_elem,
307 libmesh_assert_equal_to (to_uint(
nemhelper->num_node_cmaps),
nemhelper->node_cmap_node_cnts.size());
308 libmesh_assert_equal_to (to_uint(
nemhelper->num_node_cmaps),
nemhelper->node_cmap_node_ids.size());
309 libmesh_assert_equal_to (to_uint(
nemhelper->num_node_cmaps),
nemhelper->node_cmap_proc_ids.size());
317 std::vector<processor_id_type> node_ownership (
nemhelper->num_internal_nodes +
319 this->processor_id());
322 std::map<unsigned int, unsigned int> pid_to_cmap_map;
325 for (
unsigned int cmap=0; cmap<to_uint(
nemhelper->num_node_cmaps); cmap++)
328 libmesh_assert_equal_to (to_uint(
nemhelper->node_cmap_node_cnts[cmap]),
329 nemhelper->node_cmap_node_ids[cmap].size());
331 libmesh_assert_equal_to (to_uint(
nemhelper->node_cmap_node_cnts[cmap]),
332 nemhelper->node_cmap_proc_ids[cmap].size());
337 cast_int<processor_id_type>(
nemhelper->node_cmap_ids[cmap]);
339 libmesh_assert_less (adjcnt_pid_idx, this->
n_processors());
340 libmesh_assert_not_equal_to (adjcnt_pid_idx, this->
processor_id());
345 pid_to_cmap_map[adjcnt_pid_idx] = cmap;
348 for (
unsigned int idx=0; idx<to_uint(
nemhelper->node_cmap_node_cnts[cmap]); idx++)
351 libmesh_assert_equal_to
353 cast_int<processor_id_type>(
nemhelper->node_cmap_proc_ids[cmap][idx]));
356 const unsigned int local_node_idx =
nemhelper->node_cmap_node_ids[cmap][idx]-1;
358 libmesh_assert_less (local_node_idx, node_ownership.size());
362 node_ownership[local_node_idx] =
363 std::min(node_ownership[local_node_idx], adjcnt_pid_idx);
369 unsigned int num_nodes_i_must_number = 0;
371 for (
const auto & pid : node_ownership)
373 num_nodes_i_must_number++;
376 libmesh_assert_greater_equal (num_nodes_i_must_number,
nemhelper->num_internal_nodes);
381 <<
"num_nodes_i_must_number="
382 << num_nodes_i_must_number
389 std::vector<int> all_loadbal_data ( 8 );
390 all_loadbal_data[0] =
nemhelper->num_internal_nodes;
391 all_loadbal_data[1] =
nemhelper->num_border_nodes;
392 all_loadbal_data[2] =
nemhelper->num_external_nodes;
393 all_loadbal_data[3] =
nemhelper->num_internal_elems;
394 all_loadbal_data[4] =
nemhelper->num_border_elems;
395 all_loadbal_data[5] =
nemhelper->num_node_cmaps;
396 all_loadbal_data[6] =
nemhelper->num_elem_cmaps;
397 all_loadbal_data[7] = num_nodes_i_must_number;
407 std::vector<std::vector<int>>
408 needed_node_idxs (
nemhelper->num_node_cmaps);
410 std::vector<Parallel::Request>
411 needed_nodes_requests (
nemhelper->num_node_cmaps);
413 for (
unsigned int cmap=0; cmap<to_uint(
nemhelper->num_node_cmaps); cmap++)
419 needed_node_idxs[cmap].reserve (
nemhelper->node_cmap_node_cnts[cmap]);
421 const unsigned int adjcnt_pid_idx =
nemhelper->node_cmap_ids[cmap];
424 for (
unsigned int idx=0; idx<to_uint(
nemhelper->node_cmap_node_cnts[cmap]); idx++)
427 local_node_idx =
nemhelper->node_cmap_node_ids[cmap][idx]-1,
428 owning_pid_idx = node_ownership[local_node_idx];
431 if (owning_pid_idx == adjcnt_pid_idx)
434 global_node_idx =
nemhelper->node_num_map[local_node_idx]-1;
435 needed_node_idxs[cmap].push_back(global_node_idx);
440 needed_node_idxs[cmap],
441 needed_nodes_requests[cmap],
449 std::vector<unsigned int>
453 all_num_nodes_i_must_number[pid] = all_loadbal_data[8*pid + 7];
456 libmesh_assert (std::accumulate(all_num_nodes_i_must_number.begin(),
457 all_num_nodes_i_must_number.end(),
460 unsigned int my_next_node = 0;
462 my_next_node += all_num_nodes_i_must_number[pid];
464 const unsigned int my_node_offset = my_next_node;
474 for (
unsigned int i=0; i<to_uint(
nemhelper->num_internal_nodes); ++i)
476 const unsigned int local_node_idx =
nemhelper->node_mapi[i]-1;
478 const unsigned int owning_pid_idx = node_ownership[local_node_idx];
482 libmesh_assert_equal_to (owning_pid_idx, this->
processor_id());
483 libmesh_assert_less (my_next_node,
nemhelper->num_nodes_global);
492 this->processor_id());
495 if (added_node->
id() != my_next_node)
498 <<
", but we wanted ID " << my_next_node << std::endl;
504#ifdef LIBMESH_ENABLE_UNIQUE_ID
509 nemhelper->node_num_map[local_node_idx] = my_next_node++ + 1;
517 typedef std::vector<std::pair<unsigned int, unsigned int>> global_idx_mapping_type;
518 global_idx_mapping_type old_global_to_new_global_map;
519 old_global_to_new_global_map.reserve (num_nodes_i_must_number
522 CompareGlobalIdxMappings global_idx_mapping_comp;
524 for (
unsigned int i=0; i<to_uint(
nemhelper->num_border_nodes); ++i)
527 local_node_idx =
nemhelper->node_mapb[i]-1,
528 owning_pid_idx = node_ownership[local_node_idx];
534 global_node_idx =
nemhelper->node_num_map[local_node_idx]-1;
538 old_global_to_new_global_map.emplace_back(global_node_idx, my_next_node);
550 if (added_node->
id() != my_next_node)
553 <<
", but we wanted ID " << my_next_node << std::endl;
559#ifdef LIBMESH_ENABLE_UNIQUE_ID
564 nemhelper->node_num_map[local_node_idx] = my_next_node++ + 1;
568 libmesh_assert_equal_to (num_nodes_i_must_number, (my_next_node - my_node_offset));
571 std::sort (old_global_to_new_global_map.begin(),
572 old_global_to_new_global_map.end(),
573 global_idx_mapping_comp);
576 libmesh_assert (std::unique (old_global_to_new_global_map.begin(),
577 old_global_to_new_global_map.end(),
578 global_idx_mapping_equality) ==
579 old_global_to_new_global_map.end());
583 std::map<unsigned int, std::vector<int>> requested_node_idxs;
585 std::vector<Parallel::Request> requested_nodes_requests(
nemhelper->num_node_cmaps);
594 std::vector<bool> processed_cmap (
nemhelper->num_node_cmaps,
false);
596 for (
unsigned int comm_step=0; comm_step<2*to_uint(
nemhelper->num_node_cmaps); comm_step++)
603 requesting_pid_idx = status.source(),
604 source_pid_idx = status.source();
610 const unsigned int cmap = pid_to_cmap_map[source_pid_idx];
612 if (!processed_cmap[cmap])
614 processed_cmap[cmap] =
true;
621 std::vector<int> & xfer_buf (requested_node_idxs[requesting_pid_idx]);
624 this->
comm().
receive (requesting_pid_idx, xfer_buf, nodes_tag);
630 const unsigned int old_global_node_idx = xfer_buf[i];
635 const global_idx_mapping_type::const_iterator it =
636 std::lower_bound (old_global_to_new_global_map.begin(),
637 old_global_to_new_global_map.end(),
639 global_idx_mapping_comp);
642 libmesh_assert_equal_to (it->first, old_global_node_idx);
643 libmesh_assert_greater_equal (it->second, my_node_offset);
644 libmesh_assert_less (it->second, my_next_node);
647 xfer_buf[i] = it->second;
651 this->
comm().
send (requesting_pid_idx,
653 requested_nodes_requests[cmap],
669 libmesh_assert_equal_to (to_uint(
nemhelper->node_cmap_ids[cmap]), source_pid_idx);
673 needed_node_idxs[cmap],
676 libmesh_assert_less_equal (needed_node_idxs[cmap].size(),
677 nemhelper->node_cmap_node_ids[cmap].size());
679 for (std::size_t i=0, j=0, ncnis=
nemhelper->node_cmap_node_ids[cmap].size(); i < ncnis; i++)
682 local_node_idx =
nemhelper->node_cmap_node_ids[cmap][i]-1,
683 owning_pid_idx = node_ownership[local_node_idx];
687 if (owning_pid_idx == source_pid_idx)
689 libmesh_assert_less (j, needed_node_idxs[cmap].size());
692 global_node_idx = needed_node_idxs[cmap][j++];
700 cast_int<dof_id_type>(global_node_idx),
701 cast_int<processor_id_type>(source_pid_idx));
704 if (added_node->
id() != global_node_idx)
707 <<
", but we wanted ID " << global_node_idx << std::endl;
713#ifdef LIBMESH_ENABLE_UNIQUE_ID
718 nemhelper->node_num_map[local_node_idx] = global_node_idx + 1;
730 libmesh_assert_equal_to ((my_next_node - my_node_offset), to_uint(
nemhelper->num_nodes));
752 requested_node_idxs.clear();
780 int sum_internal_elems=0, sum_border_elems=0;
781 for (
unsigned int j=3,c=0; c<this->
n_processors(); j+=8,++c)
782 sum_internal_elems += all_loadbal_data[j];
784 for (
unsigned int j=4,c=0; c<this->
n_processors(); j+=8,++c)
785 sum_border_elems += all_loadbal_data[j];
790 libMesh::out <<
"sum_internal_elems=" << sum_internal_elems << std::endl;
793 libMesh::out <<
"sum_border_elems=" << sum_border_elems << std::endl;
796 libmesh_assert_equal_to (sum_internal_elems+sum_border_elems,
nemhelper->num_elems_global);
841 std::size_t local_elem_num = 0;
845 for (
unsigned int i=0; i<to_uint(
nemhelper->num_elem_blk); i++)
857 if (!
nemhelper->num_elem_this_blk)
continue;
861 restrict_int<subdomain_id_type>(
nemhelper->block_ids[i]);
864 const std::string type_str (
nemhelper->elem_type.data() );
867 const auto & conv =
nemhelper->get_conversion(type_str);
870 libMesh::out <<
"Reading a block of " << type_str <<
" elements." << std::endl;
873 for (
unsigned int j=0; j<to_uint(
nemhelper->num_elem_this_blk); j++)
875 auto uelem =
Elem::build (conv.libmesh_elem_type());
881 uelem->subdomain_id() = subdomain_id;
883 uelem->set_id() =
nemhelper->elem_num_map[local_elem_num++]-1;
888#ifdef LIBMESH_ENABLE_UNIQUE_ID
889 uelem->set_unique_id(uelem->id());
903 libmesh_assert_equal_to(elem->
id(),
904 cast_int<dof_id_type>(
nemhelper->elem_num_map[local_elem_num-1]-1));
909 <<
"Setting nodes for Elem " << elem->
id() << std::endl;
911 for (
unsigned int k=0; k<to_uint(
nemhelper->num_nodes_per_elem); k++)
915 conv.get_node_map(k)),
916 local_node_idx =
nemhelper->connect[gi]-1,
917 global_node_idx =
nemhelper->node_num_map[local_node_idx]-1;
925 for (
const auto & [
id, name] :
nemhelper->id_to_block_names)
938 unsigned char max_dim_seen = 0;
941 max_dim_seen =
static_cast<unsigned char>(i);
946 this->
comm().
max(max_dim_seen);
952 <<
"max_dim_seen=" << +max_dim_seen << std::endl;
960 "Cannot open dimension "
962 <<
" mesh file when configured without "
974 <<
"Read global sideset parameter information." << std::endl;
978 <<
"Number of global sideset IDs: " <<
nemhelper->global_sideset_ids.size() << std::endl;
995 <<
"nemhelper->num_side_sets = " <<
nemhelper->num_side_sets << std::endl;
998 <<
"nemhelper->num_elem_all_sidesets = " <<
nemhelper->num_elem_all_sidesets << std::endl;
1003 for (
const auto & [
id, name] :
nemhelper->id_to_ss_names)
1015 int sum_num_global_side_counts = std::accumulate(
nemhelper->num_global_side_counts.begin(),
1016 nemhelper->num_global_side_counts.end(),
1020 int sum_num_elem_all_sidesets =
nemhelper->num_elem_all_sidesets;
1021 this->
comm().
sum(sum_num_elem_all_sidesets);
1023 libmesh_error_msg_if(sum_num_global_side_counts != sum_num_elem_all_sidesets,
1024 "Error! global side count reported by Nemesis does not "
1025 "match the side count reported by the individual files!");
1032 for (
int offset=0, i=0; i<
nemhelper->num_side_sets; i++)
1034 offset += (i > 0 ?
nemhelper->num_sides_per_set[i-1] : 0);
1066 const std::size_t local_id =
nemhelper->elem_list[e]-1;
1074 const auto & conv =
nemhelper->get_conversion(elem->
type());
1080 cast_int<unsigned short>(conv.get_side_map(
nemhelper->side_list[e]-1)),
1081 cast_int<boundary_id_type>(
nemhelper->id_list[e]));
1084 for (
const auto & [
id, name] :
nemhelper->id_to_ss_names)
1095 libmesh_error_msg_if(nbcs !=
nemhelper->elem_list.size(),
1096 "[" << this->processor_id() <<
"] "
1097 <<
"BoundaryInfo contains "
1099 <<
" boundary conditions, while the Exodus file had "
1117 for (
const auto & [
id, name] :
nemhelper->id_to_ns_names)
1132 for (
int nodeset=0; nodeset<
nemhelper->num_node_sets; nodeset++)
1135 int nodeset_id =
nemhelper->nodeset_ids[nodeset];
1140 libMesh::out <<
"nemhelper->nodeset_ids[" << nodeset <<
"]=" << nodeset_id << std::endl;
1150 libmesh_error_msg_if(to_uint(
nemhelper->node_list[node]-1) >=
nemhelper->node_num_map.size(),
1151 "Error, index is past the end of node_num_map array!");
1160 <<
"nodeset " << nodeset
1161 <<
", local node number: " <<
nemhelper->node_list[node]-1
1162 <<
", global node id: " << global_node_id
1168 (cast_int<dof_id_type>(global_node_id),
1169 cast_int<boundary_id_type>(nodeset_id));
1173 for (
const auto & [
id, name] :
nemhelper->id_to_ns_names)
1207#ifdef LIBMESH_ENABLE_UNIQUE_ID
1218 libmesh_error_msg(
"ERROR, Nemesis API is not defined!");
1227#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1235 std::string nemesis_filename =
nemhelper->construct_nemesis_filename(base_filename);
1242 libmesh_warning(
"Warning: Appending in Nemesis_IO::write() does not make sense.\n"
1243 "Creating a new file instead!");
1257 nemhelper->write_nodal_coordinates(mesh);
1275 libmesh_warning(
"Warning: Mesh contains edge boundary IDs, but these "
1276 "are not supported by the Nemesis format.");
1283 libmesh_error_msg(
"ERROR, Nemesis API is not defined!");
1289#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1299 nemhelper->write_timestep(timestep, time);
1309 libmesh_error_msg(
"ERROR, Nemesis API is not defined!");
1316#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1319 const std::vector<std::string> & names)
1323 std::string nemesis_filename =
nemhelper->construct_nemesis_filename(fname);
1332 nemhelper->open(nemesis_filename.c_str(),
false);
1337 nemhelper->read_and_store_header_info();
1355 nemhelper->write_nodal_coordinates(mesh);
1361 libmesh_warning(
"Warning: Mesh contains edge boundary IDs, but these "
1362 "are not supported by the ExodusII format.");
1370#ifdef LIBMESH_USE_COMPLEX_NUMBERS
1371 std::vector<std::string> complex_names =
1373 nemhelper->initialize_nodal_variables(complex_names);
1375 nemhelper->initialize_nodal_variables(names);
1382 const std::vector<std::string> &)
1384 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1391#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1395 const std::vector<std::string> & names)
1397 LOG_SCOPE(
"write_nodal_data(parallel)",
"Nemesis_IO");
1402 std::vector<std::string> output_names;
1407 output_names = names;
1420 const std::set<std::string> * system_names)
1422 LOG_SCOPE(
"write_nodal_data(parallel)",
"Nemesis_IO");
1427 std::vector<std::string> output_names;
1436 std::vector<std::pair<unsigned int, unsigned int>> var_nums;
1439 if (!output_names.empty())
1449 const std::vector<std::string> &)
1451 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1455 const EquationSystems &,
1456 const std::set<std::string> *)
1458 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1465#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1469 libmesh_error_msg_if(!
nemhelper->opened_for_writing,
1470 "ERROR, Nemesis file must be initialized before outputting elemental variables.");
1473 std::vector<std::string> names;
1482 std::vector<std::pair<unsigned int, unsigned int>> var_nums =
1487 if (var_nums.empty())
1490 libMesh::out <<
"No elemental data variables to be written." << std::endl;
1497 std::vector<std::set<subdomain_id_type>> vars_active_subdomains;
1502#ifdef LIBMESH_USE_COMPLEX_NUMBERS
1503 std::vector<std::string> complex_names =
1506 std::vector<std::set<subdomain_id_type>>
1507 complex_vars_active_subdomains =
1508 nemhelper->get_complex_vars_active_subdomains(vars_active_subdomains,
1510 nemhelper->initialize_element_variables(complex_names, complex_vars_active_subdomains);
1520 complex_vars_active_subdomains);
1530 nemhelper->initialize_element_variables(names, vars_active_subdomains);
1540 vars_active_subdomains);
1548 libmesh_not_implemented();
1555#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1558 const std::vector<Number> & soln,
1559 const std::vector<std::string> & names)
1561 LOG_SCOPE(
"write_nodal_data(serialized)",
"Nemesis_IO");
1571 const std::vector<Number> &,
1572 const std::vector<std::string> &)
1574 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1582#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1585 const std::vector<std::string> & names)
1587 libmesh_error_msg_if(!
nemhelper->opened_for_writing,
1588 "ERROR, Nemesis file must be initialized before outputting global variables.");
1590#ifdef LIBMESH_USE_COMPLEX_NUMBERS
1592 std::vector<std::string> complex_names =
1595 nemhelper->initialize_global_variables(complex_names);
1597 unsigned int num_values = soln.size();
1598 unsigned int num_vars = names.size();
1599 unsigned int num_elems = num_values / num_vars;
1603 int nco =
nemhelper->write_complex_abs ? 3 : 2;
1604 std::vector<Real> complex_soln(nco * num_values);
1606 for (
unsigned i=0; i<num_vars; ++i)
1608 for (
unsigned int j=0; j<num_elems; ++j)
1611 complex_soln[nco*i*num_elems + j] =
value.real();
1613 for (
unsigned int j=0; j<num_elems; ++j)
1616 complex_soln[nco*i*num_elems + num_elems + j] =
value.imag();
1620 for (
unsigned int j=0; j<num_elems; ++j)
1623 complex_soln[3*i*num_elems + 2*num_elems + j] = std::abs(
value);
1633 nemhelper->initialize_global_variables( names );
1643 const std::vector<std::string> &)
1645 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1652#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
1656 libmesh_error_msg_if(!
nemhelper->opened_for_writing,
1657 "ERROR, Nemesis file must be initialized before outputting information records.");
1660 nemhelper->write_information_records( records );
1685 libmesh_error_msg_if
1687 "ERROR, ExodusII file must be opened for reading before calling Nemesis_IO::get_time_steps()!");
1696 libmesh_error_msg_if(!
nemhelper->opened_for_reading && !
nemhelper->opened_for_writing,
1697 "ERROR, ExodusII file must be opened for reading or writing before calling Nemesis_IO::get_num_time_steps()!");
1705 std::string system_var_name,
1706 std::string exodus_var_name,
1707 unsigned int timestep)
1709 libmesh_error_msg_if(!
nemhelper->opened_for_reading,
1710 "ERROR, Nemesis file must be opened for reading before copying a nodal solution!");
1712 nemhelper->read_nodal_var_values(exodus_var_name, timestep);
1716 for (
auto p :
nemhelper->nodal_var_values)
1721 if (node && node->
n_comp(system.
number(), var_num) > 0)
1727 system.
solution->set (dof_index, p.second);
1738 std::string system_var_name,
1739 std::string exodus_var_name,
1740 unsigned int timestep)
1742 parallel_object_only();
1748 "Error! Trying to copy elemental solution into a variable that is not scalar elemental data.");
1757 std::map<dof_id_type, Real> elem_var_value_map;
1759 libmesh_error_msg_if(!
nemhelper->opened_for_reading,
1760 "ERROR, Nemesis file must be opened for reading before copying an elemental solution!");
1762 nemhelper->read_elemental_var_values(exodus_var_name, timestep, elem_var_value_map);
1764 std::map<dof_id_type, Real>::iterator
1765 it = elem_var_value_map.begin(),
1766 end = elem_var_value_map.end();
1768 for (; it!=end; ++it)
1772 if (elem && elem->
n_comp(system.
number(), var_num) > 0)
1776 system.
solution->set (dof_index, it->second);
1783 parallel_object_only();
1789 std::vector<std::string> system_var_names,
1790 std::vector<std::string> exodus_var_names,
1791 unsigned int timestep)
1793 libmesh_error_msg_if(!
nemhelper->opened_for_reading,
1794 "ERROR, Nemesis file must be opened for reading before copying a scalar solution!");
1796 libmesh_error_msg_if(system_var_names.size() != exodus_var_names.size(),
1797 "ERROR, the number of system_var_names must match exodus_var_names.");
1799 std::vector<Real> values_from_exodus;
1810 std::vector<dof_id_type> SCALAR_dofs;
1813 system.
solution->set (SCALAR_dofs[0], values_from_exodus[i]);
1823 unsigned int timestep,
1824 std::vector<Real> & global_values)
1826 std::size_t size = global_var_names.size();
1827 libmesh_error_msg_if(size == 0,
"ERROR, empty list of global variables to read from the Nemesis file.");
1830 std::vector<Real> values_from_exodus;
1832 nemhelper->read_global_values(values_from_exodus, timestep);
1833 std::vector<std::string> global_var_names_exodus =
nemhelper->global_var_names;
1835 if (values_from_exodus.size() == 0)
1838 global_values.clear();
1839 for (std::size_t i = 0; i != size; ++i)
1843 auto it = find(global_var_names_exodus.begin(), global_var_names_exodus.end(), global_var_names[i]);
1844 if (it != global_var_names_exodus.end())
1845 global_values.push_back(values_from_exodus[it - global_var_names_exodus.begin()]);
1847 libmesh_error_msg(
"ERROR, Global variable " << global_var_names[i] << \
1848 " not found in Nemesis file.");
1857 libmesh_experimental();
1864 nemhelper->set_hdf5_writing(write_hdf5);
1871 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1876 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1884 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1892 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1900 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1905 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
1912 libmesh_error_msg(
"ERROR, Nemesis API is not defined.");
void max(const T &r, T &o, Request &req) const
MessageTag get_unique_tag(int tagvalue=MessageTag::invalid_tag) const
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
void alltoall(std::vector< T, A > &r) const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
std::string & sideset_name(boundary_id_type id)
std::size_t n_boundary_conds() const
std::size_t n_edge_conds() const
std::string & nodeset_name(boundary_id_type id)
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
This class handles the numbering of degrees of freedom on a mesh.
bool local_index(dof_id_type dof_index) const
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
Fills the vector di with the global degree of freedom indices corresponding to the SCALAR variable vn...
unsigned int n_comp(const unsigned int s, const unsigned int var) const
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
void set_unique_id(unique_id_type new_id)
Sets the unique_id for this DofObject.
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
virtual ElemType type() const =0
This is the EquationSystems class.
std::vector< std::pair< unsigned int, unsigned int > > find_elemental_data_variable_numbers(std::vector< std::string > &names) const
Finds system and variable numbers for variables that can be represented as elemental data.
static bool is_elemental_data_fe_type(const FEType &type)
std::vector< std::pair< unsigned int, unsigned int > > find_variable_numbers(std::vector< std::string > &names, const FEType *type=nullptr, const std::vector< FEType > *types=nullptr) const
Finds system and variable numbers for any variables of 'type' or of 'types' corresponding to the entr...
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
Fill the input vector var_names with the names of the variables for each system.
void get_vars_active_subdomains(const std::vector< std::string > &names, std::vector< std::set< subdomain_id_type > > &vars_active_subdomains) const
Retrieve vars_active_subdomains, which indicates the active subdomains for each variable in names.
static FEFieldType field_type(const FEType &fe_type)
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
This is the MeshBase class.
void set_subdomain_name(subdomain_id_type id, const std::string &name, bool synchronous=false)
Sets the name for the provided id.
virtual bool is_serial() const
virtual dof_id_type parallel_n_elem() const =0
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
virtual const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
virtual void update_post_partitioning()
Recalculate any cached data (or invalidate any caches that are computed on the fly) after elements an...
virtual const Elem * elem_ptr(const dof_id_type i) const =0
virtual void set_next_unique_id(unique_id_type id)=0
Sets the next available unique id to be used.
virtual void delete_remote_elements()
When supported, deletes all nonlocal elements of the mesh except for "ghosts" which touch a local ele...
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
virtual dof_id_type parallel_n_nodes() const =0
virtual unique_id_type parallel_max_unique_id() const =0
This is the MeshCommunication class.
void make_node_unique_ids_parallel_consistent(MeshBase &)
Assuming all unique_ids on local nodes are globally unique, and assuming all processor ids are parall...
void allgather(MeshBase &mesh) const
This method takes an input DistributedMesh which may be distributed among all the processors.
void gather_neighboring_elements(DistributedMesh &) const
This class defines an abstract interface for Mesh output.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
This is the Nemesis_IO_Helper class.
std::unique_ptr< Nemesis_IO_Helper > nemhelper
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
std::vector< std::string > _output_variables
The names of the variables to be output.
virtual ~Nemesis_IO()
Destructor.
Nemesis_IO(MeshBase &mesh, bool single_precision=false)
Constructor.
bool _allow_empty_variables
If true, _output_variables is allowed to remain empty.
bool _append
Default false.
void set_hdf5_writing(bool write_hdf5)
Set to true (the default) to write files in an HDF5-based file format (when HDF5 is available),...
void verbose(bool set_verbosity)
Set the flag indicating if we should be verbose.
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
const std::vector< std::string > & get_elem_var_names()
Return list of the elemental variable names.
const std::vector< std::string > & get_global_var_names()
Return list of the global variable names.
void write_element_data(const EquationSystems &es)
Write out element solution in parallel, without localizing the solution vector.
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
void assert_symmetric_cmaps()
void write_global_data(const std::vector< Number > &, const std::vector< std::string > &)
Write out global variables.
void read_global_variable(std::vector< std::string > global_var_names, unsigned int timestep, std::vector< Real > &global_values)
Given a vector of global variables and a time step, returns the values of the global variable at the ...
const std::vector< Real > & get_time_steps()
Nemesis_IO_Helper & get_nemio_helper()
Return a reference to the Nemesis_IO_Helper object.
void write_timestep(const std::string &fname, const EquationSystems &es, const int timestep, const Real time)
Write one timestep's worth of the solution.
void append(bool val)
If true, this flag will cause the Nemesis_IO object to attempt to open an existing file for writing,...
virtual void write_nodal_data(const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
Output a nodal solution from data in soln.
void set_output_variables(const std::vector< std::string > &output_variables, bool allow_empty=true)
Specify the list of variables which should be included in the output (whitelist) If empty,...
virtual void write(const std::string &base_filename) override
This method implements writing a mesh to a specified file.
void write_information_records(const std::vector< std::string > &)
Write out information records.
void prepare_to_write_nodal_data(const std::string &fname, const std::vector< std::string > &names)
Helper function containing code shared between the two different versions of write_nodal_data which t...
void copy_scalar_solution(System &system, std::vector< std::string > system_var_names, std::vector< std::string > exodus_var_names, unsigned int timestep=1)
Copy global variables into scalar variables of a System object.
int _timestep
Keeps track of the current timestep index being written.
void copy_nodal_solution(System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution in...
void copy_elemental_solution(System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
If we read in a elemental solution while reading in a mesh, we can attempt to copy that elemental sol...
bool _verbose
Controls whether extra debugging information is printed to the screen or not.
A Node is like a Point, but with more information.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
An object whose state is distributed along a set of processors.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
Manages consistently variables, degrees of freedom, and coefficient vectors.
const FEType & variable_type(const unsigned int i) const
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
unsigned int variable_scalar_number(std::string_view var, unsigned int component) const
virtual void update()
Update the local values to reflect the solution on neighboring processors.
unsigned int variable_number(std::string_view var) const
const DofMap & get_dof_map() const
unsigned int number() const
const unsigned int any_source
void deallocate(std::vector< T > &vec)
A convenient method to truly empty a vector using the "swap trick".
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
void libmesh_ignore(const Args &...)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...