libMesh
nemesis_io_helper.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_NEMESIS_IO_HELPER_H
19 #define LIBMESH_NEMESIS_IO_HELPER_H
20 
21 #include "libmesh/libmesh_config.h"
22 
23 #if defined(LIBMESH_HAVE_NEMESIS_API) && defined(LIBMESH_HAVE_EXODUS_API)
24 
25 // Local headers
26 #include "libmesh/exodusII_io_helper.h"
27 
28 // C++ headers
29 #include <set>
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class EquationSystems;
37 template <typename T> class NumericVector;
38 
39 // The Nemesis API header file. Should already be
40 // correctly extern C'd but it doesn't hurt :)
41 namespace Nemesis {
42 extern "C" {
43  // this include guard gets set by exodus, but we included it
44  // in a namespace, so nemesis will not properly resolve e.g.
45  // ex_entity_id in the global namespace. undefine the guard
46  // to get ne_nemesisI.h to properly include the typedefs
47 # ifdef EXODUS_II_HDR
48 # undef EXODUS_II_HDR
49 # endif
50 # ifdef EXODUSII_H
51 # undef EXODUSII_H
52 # endif
53 # include "ne_nemesisI.h"
54 }
55 }
56 
57 
71 {
72 public:
76  explicit
77  Nemesis_IO_Helper(const ParallelObject & parent,
78  bool verbose=false, bool single_precision=false);
79 
83  virtual ~Nemesis_IO_Helper();
84 
90  void write_complex_magnitude (bool val);
91 
107  void read_nodeset(int id);
108 
115  void get_init_global();
116 
121  void get_ss_param_global();
122  void get_ns_param_global();
123  void get_eb_info_global();
124  void get_init_info();
125  void get_loadbal_param();
126  void get_elem_map();
127  void get_node_map();
128  void get_cmap_params();
129  void get_node_cmap();
130  void get_elem_cmap();
131 
142  void put_init_info(unsigned num_proc,
143  unsigned num_proc_in_file,
144  const char * ftype);
145 
156  unsigned num_elem_blks_global,
157  unsigned num_node_sets_global,
158  unsigned num_side_sets_global);
159 
167  void put_eb_info_global(std::vector<int> & global_elem_blk_ids,
168  std::vector<int> & global_elem_blk_cnts);
169 
178  void put_ns_param_global(std::vector<int> & global_nodeset_ids,
179  std::vector<int> & num_global_node_counts,
180  std::vector<int> & num_global_node_df_counts);
181 
190  void put_ss_param_global(std::vector<int> & global_sideset_ids,
191  std::vector<int> & num_global_side_counts,
192  std::vector<int> & num_global_side_df_counts);
193 
194 
195 
209  unsigned num_border_nodes,
210  unsigned num_external_nodes,
211  unsigned num_internal_elems,
212  unsigned num_border_elems,
213  unsigned num_node_cmaps,
214  unsigned num_elem_cmaps);
215 
223  void put_cmap_params(std::vector<int> & node_cmap_ids,
224  std::vector<int> & node_cmap_node_cnts,
225  std::vector<int> & elem_cmap_ids,
226  std::vector<int> & elem_cmap_elem_cnts);
227 
244  void put_node_cmap(std::vector<std::vector<int>> & node_cmap_node_ids,
245  std::vector<std::vector<int>> & node_cmap_proc_ids);
246 
252  void put_node_map(std::vector<int> & node_mapi,
253  std::vector<int> & node_mapb,
254  std::vector<int> & node_mape);
255 
265  void put_elem_cmap(std::vector<std::vector<int>> & elem_cmap_elem_ids,
266  std::vector<std::vector<int>> & elem_cmap_side_ids,
267  std::vector<std::vector<int>> & elem_cmap_proc_ids);
268 
274  void put_elem_map(std::vector<int> & elem_mapi,
275  std::vector<int> & elem_mapb);
276 
281  virtual void write_nodal_coordinates(const MeshBase & mesh, bool use_discontinuous=false) override;
282 
286  virtual void write_elements(const MeshBase & mesh, bool use_discontinuous=false) override;
287 
291  virtual void write_sidesets(const MeshBase & mesh) override;
292 
296  virtual void write_nodesets(const MeshBase & mesh) override;
297 
302  virtual void initialize(std::string title, const MeshBase & mesh, bool use_discontinuous=false) override;
303 
308  void compute_num_global_elem_blocks(const MeshBase & pmesh);
309 
316  void build_element_and_node_maps(const MeshBase & pmesh);
317 
333  void write_nodal_solution(const NumericVector<Number> & parallel_soln,
334  const std::vector<std::string> & names,
335  int timestep,
336  const std::vector<std::string> & output_names);
337 
341  void write_nodal_solution(const EquationSystems & es,
342  const std::vector<std::pair<unsigned int, unsigned int>> & var_nums,
343  int timestep,
344  const std::vector<std::string> & output_names);
345 
349  void write_nodal_solution(const std::vector<Number> & values,
350  const std::vector<std::string> & names,
351  int timestep);
352 
357  virtual
358  void initialize_element_variables(std::vector<std::string> names,
359  const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains) override;
364  void write_element_values(const MeshBase & mesh,
365  const EquationSystems & es,
366  const std::vector<std::pair<unsigned int, unsigned int>> &var_nums,
367  int timestep,
368  const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains);
369 
374  std::string construct_nemesis_filename(std::string_view base_filename);
375 
385 
395 
400  int num_proc;
401 
408 
414  char ftype;
415 
416  // Stores node ids read in by the read_nodeset() function
417  std::vector<int> node_list;
418 
426  std::vector<int> global_sideset_ids;
427  std::vector<int> num_global_side_counts;
428  std::vector<int> num_global_side_df_counts;
429 
430 
438  std::vector<int> global_nodeset_ids;
439  std::vector<int> num_global_node_counts;
440  std::vector<int> num_global_node_df_counts;
441 
442 
448  std::vector<int> global_elem_blk_ids;
449  std::vector<int> global_elem_blk_cnts;
450 
455 
459  std::map<subdomain_id_type, std::vector<dof_id_type>> subdomain_map;
460 
465  std::map<int, std::vector<int>> block_id_to_elem_connectivity;
466 
476 
483 
490 
496 
503 
510 
517 
518 
519 
525  std::vector<int> elem_mapi;
526 
532  std::vector<int> elem_mapb;
533 
534 
535 
541  std::vector<int> node_mapi;
542 
548  std::vector<int> node_mapb;
549 
555  std::vector<int> node_mape;
556 
557 
564  std::vector<int> node_cmap_ids;
565  std::vector<int> node_cmap_node_cnts;
566  std::vector<int> elem_cmap_ids;
567  std::vector<int> elem_cmap_elem_cnts;
568 
569 
578  std::vector<std::vector<int>> node_cmap_node_ids;
579  std::vector<std::vector<int>> node_cmap_proc_ids;
580 
581 
587  std::vector<std::vector<int>> elem_cmap_elem_ids;
588  std::vector<std::vector<int>> elem_cmap_side_ids;
589  std::vector<std::vector<int>> elem_cmap_proc_ids;
590 
601 
602 protected:
607  virtual void read_var_names_impl(const char * var_type,
608  int & count,
609  std::vector<std::string> & result) override;
610 
611 private:
616  std::map<subdomain_id_type, unsigned> local_subdomain_counts;
617 
622  std::set<unsigned> border_node_ids;
623 
629  std::map<unsigned, std::set<unsigned>> proc_nodes_touched_intersections;
630 
634  typedef std::map<unsigned, std::set<unsigned>>::iterator proc_nodes_touched_iterator;
635 
639  std::map<unsigned, std::set<std::pair<unsigned,unsigned>>> proc_border_elem_sets;
640 
644  typedef std::map<unsigned, std::set<std::pair<unsigned,unsigned>>>::iterator proc_border_elem_sets_iterator;
645 
649  std::set<unsigned> internal_node_ids;
650 
654  std::set<unsigned> internal_elem_ids;
655 
659  std::set<unsigned> border_elem_ids;
660 
665  void compute_num_global_nodesets(const MeshBase & pmesh);
666 
671  void compute_num_global_sidesets(const MeshBase & pmesh);
672 
678  void compute_border_node_ids(const MeshBase & pmesh);
679 
685 
691 
697 
703  void compute_node_maps();
704 
710 
715  void compute_element_maps();
716 
722  void write_exodus_initialization_info(const MeshBase & pmesh,
723  const std::string & title);
724 };
725 
726 } // namespace libMesh
727 
728 #endif // #if defined(LIBMESH_HAVE_NEMESIS_API) && defined(LIBMESH_HAVE_EXODUS_API)
729 #endif // LIBMESH_NEMESIS_IO_HELPER_H
This is the EquationSystems class.
Nemesis_IO_Helper(const ParallelObject &parent, bool verbose=false, bool single_precision=false)
Constructor.
std::map< subdomain_id_type, std::vector< dof_id_type > > subdomain_map
Map of subdomains to element numbers.
virtual ~Nemesis_IO_Helper()
Destructor.
std::vector< int > num_global_node_counts
void compute_element_maps()
This function computes element maps (really just packs vectors) which map the elements to internal an...
std::vector< int > global_nodeset_ids
Containers for reading global nodeset information.
virtual void initialize(std::string title, const MeshBase &mesh, bool use_discontinuous=false) override
Specialization of the initialize function from ExodusII_IO_Helper that also writes global initial dat...
void read_nodeset(int id)
Reading functions.
char ftype
The type of file to be written.
std::vector< int > global_sideset_ids
Containers for reading global sideset (boundary conditions) information.
void compute_num_global_nodesets(const MeshBase &pmesh)
This function uses global communication routines to determine the number of nodesets across the entir...
std::vector< int > node_cmap_ids
Vectors for storing the communication map parameters.
void get_ss_param_global()
Fills: global_sideset_ids, num_global_side_counts, num_global_side_df_counts Call after: get_init_glo...
int num_external_nodes
The number of FEM nodes that reside on another processor but whose element partially resides on the c...
int nemesis_err_flag
Member data.
std::vector< int > node_mape
Vector which stores external node IDs.
void compute_elem_communication_maps()
This function computes element communication maps (really just packs vectors) in preparation for writ...
void compute_num_global_elem_blocks(const MeshBase &pmesh)
This function uses global communication routines to determine the number of element blocks across the...
MeshBase & mesh
int num_node_cmaps
The number of nodal communication maps for this processor.
void put_elem_map(std::vector< int > &elem_mapi, std::vector< int > &elem_mapb)
Outputs IDs of internal and border elements.
std::vector< int > num_global_node_df_counts
std::vector< std::vector< int > > elem_cmap_side_ids
std::vector< std::vector< int > > node_cmap_proc_ids
void put_ns_param_global(std::vector< int > &global_nodeset_ids, std::vector< int > &num_global_node_counts, std::vector< int > &num_global_node_df_counts)
This function writes information about global node sets.
The libMesh namespace provides an interface to certain functionality in the library.
void put_eb_info_global(std::vector< int > &global_elem_blk_ids, std::vector< int > &global_elem_blk_cnts)
Writes global block information to the file .) global_elem_blk_ids - list of block IDs for all blocks...
std::vector< int > node_list
void compute_border_node_ids(const MeshBase &pmesh)
This function constructs the set of border node IDs present on the current mesh.
std::vector< char > & title
bool write_complex_abs
By default, when complex numbers are enabled, for each variable we write out three values: the real p...
void compute_communication_map_parameters()
This function determines the communication map parameters which will eventually be written to file...
virtual void write_elements(const MeshBase &mesh, bool use_discontinuous=false) override
This function is specialized to write the connectivity.
int num_nodes_global
Global initial information.
void compute_node_communication_maps()
Compute the node communication maps (really just pack vectors) in preparation for writing them to fil...
std::vector< int > num_global_side_df_counts
This is the MeshBase class.
Definition: mesh_base.h:74
void write_element_values(const MeshBase &mesh, const EquationSystems &es, const std::vector< std::pair< unsigned int, unsigned int >> &var_nums, int timestep, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains)
Writes the vector of elemental variable values, one variable and one subdomain at a time...
void build_element_and_node_maps(const MeshBase &pmesh)
This function builds the libmesh -> exodus and exodus -> libmesh node and element maps...
void put_init_global(dof_id_type num_nodes_global, dof_id_type num_elems_global, unsigned num_elem_blks_global, unsigned num_node_sets_global, unsigned num_side_sets_global)
Writes global information including: .) global number of nodes .) global number of elems ...
This is the Nemesis_IO_Helper class.
virtual void write_nodal_coordinates(const MeshBase &mesh, bool use_discontinuous=false) override
This function is specialized from ExodusII_IO_Helper to write only the nodal coordinates stored on th...
std::vector< int > num_global_side_counts
std::vector< int > global_elem_blk_ids
Read the global element block IDs and counts.
virtual void initialize_element_variables(std::vector< std::string > names, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains) override
Override the Exodus Helper&#39;s implementation of this function so that it works correctly in parallel...
std::vector< std::vector< int > > elem_cmap_elem_ids
3 vectors of vectors for storing element communication IDs for this processor.
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
std::set< unsigned > border_elem_ids
A set of border elem IDs for this processor.
std::set< unsigned > internal_node_ids
A set of internal node IDs for this processor.
std::vector< int > node_mapi
Vector which stores internal node IDs.
int num_proc
The number of processors for which the NEMESIS I file was created.
std::string construct_nemesis_filename(std::string_view base_filename)
Given base_filename, foo.e, constructs the Nemesis filename foo.e.X.Y, where X=n. ...
This is the ExodusII_IO_Helper class.
std::vector< std::vector< int > > elem_cmap_proc_ids
void put_cmap_params(std::vector< int > &node_cmap_ids, std::vector< int > &node_cmap_node_cnts, std::vector< int > &elem_cmap_ids, std::vector< int > &elem_cmap_elem_cnts)
Outputs initial information for communication maps.
std::set< unsigned > border_node_ids
The set which will eventually contain the IDs of "border nodes".
std::set< int > nodes_attached_to_local_elems
libMesh numbered node ids attached to local elems.
void get_init_global()
Fills: num_nodes_global, num_elems_global, num_elem_blks_global, num_node_sets_global, num_side_sets_global Call after: read_and_store_header_info() Call before: Any other get_* function from this class.
An object whose state is distributed along a set of processors.
void compute_num_global_sidesets(const MeshBase &pmesh)
This function uses global communication routines to determine the number of sidesets across the entir...
int num_internal_elems
The number of internal FEM elements.
void compute_internal_and_border_elems_and_internal_nodes(const MeshBase &pmesh)
This function constructs the set of border and internal element IDs and internal node IDs present on ...
void compute_node_maps()
Compute the node maps (really just pack vectors) which map the nodes to internal, border...
void put_elem_cmap(std::vector< std::vector< int >> &elem_cmap_elem_ids, std::vector< std::vector< int >> &elem_cmap_side_ids, std::vector< std::vector< int >> &elem_cmap_proc_ids)
Writes information about elemental communication map.
std::map< subdomain_id_type, unsigned > local_subdomain_counts
This map keeps track of the number of elements in each subdomain (block) for this processor...
std::map< int, std::vector< int > > block_id_to_elem_connectivity
This is the block connectivity, i.e.
virtual void write_nodesets(const MeshBase &mesh) override
Writes the nodesets for this processor.
std::map< unsigned, std::set< unsigned > >::iterator proc_nodes_touched_iterator
Typedef for an iterator into the data structure above.
void put_node_map(std::vector< int > &node_mapi, std::vector< int > &node_mapb, std::vector< int > &node_mape)
Outputs IDs of internal, border, and external nodes.
std::vector< int > elem_cmap_elem_cnts
int num_elem_cmaps
The number of elemental communication maps for this processor.
std::vector< int > elem_cmap_ids
void put_ss_param_global(std::vector< int > &global_sideset_ids, std::vector< int > &num_global_side_counts, std::vector< int > &num_global_side_df_counts)
This function writes information about global side sets.
virtual void write_sidesets(const MeshBase &mesh) override
Writes the sidesets for this processor.
int num_proc_in_file
The number of processors for which the NEMESIS I file stores information.
std::vector< int > node_cmap_node_cnts
std::map< unsigned, std::set< unsigned > > proc_nodes_touched_intersections
Another map to store sets of intersections with each other processor (other than ourself, of course).
void write_exodus_initialization_info(const MeshBase &pmesh, const std::string &title)
This function writes exodus-specific initialization information.
void put_init_info(unsigned num_proc, unsigned num_proc_in_file, const char *ftype)
Writing functions.
void put_node_cmap(std::vector< std::vector< int >> &node_cmap_node_ids, std::vector< std::vector< int >> &node_cmap_proc_ids)
Outputs all of the nodal communication maps for this processor.
std::vector< int > elem_mapb
Vector which stores border element IDs.
std::vector< int > node_mapb
Vector which stores border node IDs.
std::vector< std::vector< int > > node_cmap_node_ids
2 vectors of vectors for storing the node communication IDs for this processor.
std::map< unsigned, std::set< std::pair< unsigned, unsigned > > >::iterator proc_border_elem_sets_iterator
Typedef for an iterator into the data structure above.
std::vector< int > global_elem_blk_cnts
void put_loadbal_param(unsigned num_internal_nodes, unsigned num_border_nodes, unsigned num_external_nodes, unsigned num_internal_elems, unsigned num_border_elems, unsigned num_node_cmaps, unsigned num_elem_cmaps)
Writes load balance parameters, some of which are described below: .) num_internal_nodes - nodes "who...
std::vector< int > elem_mapi
Vector which stores internal element IDs.
std::map< unsigned, std::set< std::pair< unsigned, unsigned > > > proc_border_elem_sets
Map between processor ID and (element,side) pairs bordering that processor ID.
int num_border_nodes
The number of FEM nodes local to a processor but residing in an element which also has FEM nodes on o...
int num_internal_nodes
To be used with the Nemesis::ne_get_loadbal_param() routine.
std::set< unsigned > internal_elem_ids
A set of internal elem IDs for this processor.
uint8_t dof_id_type
Definition: id_types.h:67
virtual void read_var_names_impl(const char *var_type, int &count, std::vector< std::string > &result) override
read_var_names() dispatches to this function.
int num_border_elems
The number of border FEM elements.
void write_nodal_solution(const NumericVector< Number > &parallel_soln, const std::vector< std::string > &names, int timestep, const std::vector< std::string > &output_names)
Takes a parallel solution vector containing the node-major solution vector for all variables and outp...