libMesh
nemesis_io_helper.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 declaration
36 template <typename T> class NumericVector;
37 
38 // The Nemesis API header file. Should already be
39 // correctly extern C'd but it doesn't hurt :)
40 namespace Nemesis {
41 extern "C" {
42  // this include guard gets set by exodus, but we included it
43  // in a namespace, so nemesis will not properly resolve e.g.
44  // ex_entity_id in the global namespace. undefine the guard
45  // to get ne_nemesisI.h to properly include the typedefs
46 # ifdef EXODUS_II_HDR
47 # undef EXODUS_II_HDR
48 # endif
49 # include "ne_nemesisI.h"
50 }
51 }
52 
53 
65 {
66 public:
70  explicit
71  Nemesis_IO_Helper(const ParallelObject & parent,
72  bool verbose=false, bool single_precision=false);
73 
77  virtual ~Nemesis_IO_Helper();
78 
92  void get_init_global();
93 
98  void get_ss_param_global();
99  void get_ns_param_global();
100  void get_eb_info_global();
101  void get_init_info();
102  void get_loadbal_param();
103  void get_elem_map();
104  void get_node_map();
105  void get_cmap_params();
106  void get_node_cmap();
107  void get_elem_cmap();
108 
119  void put_init_info(unsigned num_proc,
120  unsigned num_proc_in_file,
121  const char * ftype);
122 
131  void put_init_global(dof_id_type num_nodes_global,
132  dof_id_type num_elems_global,
133  unsigned num_elem_blks_global,
134  unsigned num_node_sets_global,
135  unsigned num_side_sets_global);
136 
144  void put_eb_info_global(std::vector<int> & global_elem_blk_ids,
145  std::vector<int> & global_elem_blk_cnts);
146 
155  void put_ns_param_global(std::vector<int> & global_nodeset_ids,
156  std::vector<int> & num_global_node_counts,
157  std::vector<int> & num_global_node_df_counts);
158 
167  void put_ss_param_global(std::vector<int> & global_sideset_ids,
168  std::vector<int> & num_global_side_counts,
169  std::vector<int> & num_global_side_df_counts);
170 
171 
172 
185  void put_loadbal_param(unsigned num_internal_nodes,
186  unsigned num_border_nodes,
187  unsigned num_external_nodes,
188  unsigned num_internal_elems,
189  unsigned num_border_elems,
190  unsigned num_node_cmaps,
191  unsigned num_elem_cmaps);
192 
200  void put_cmap_params(std::vector<int> & node_cmap_ids,
201  std::vector<int> & node_cmap_node_cnts,
202  std::vector<int> & elem_cmap_ids,
203  std::vector<int> & elem_cmap_elem_cnts);
204 
221  void put_node_cmap(std::vector<std::vector<int>> & node_cmap_node_ids,
222  std::vector<std::vector<int>> & node_cmap_proc_ids);
223 
229  void put_node_map(std::vector<int> & node_mapi,
230  std::vector<int> & node_mapb,
231  std::vector<int> & node_mape);
232 
242  void put_elem_cmap(std::vector<std::vector<int>> & elem_cmap_elem_ids,
243  std::vector<std::vector<int>> & elem_cmap_side_ids,
244  std::vector<std::vector<int>> & elem_cmap_proc_ids);
245 
251  void put_elem_map(std::vector<int> & elem_mapi,
252  std::vector<int> & elem_mapb);
253 
258  void put_n_coord(unsigned start_node_num,
259  unsigned num_nodes,
260  std::vector<Real> & x_coor,
261  std::vector<Real> & y_coor,
262  std::vector<Real> & z_coor);
263 
264 
269  virtual void write_nodal_coordinates(const MeshBase & mesh, bool use_discontinuous=false);
270 
274  virtual void write_elements(const MeshBase & mesh, bool use_discontinuous=false);
275 
279  virtual void write_sidesets(const MeshBase & mesh);
280 
284  virtual void write_nodesets(const MeshBase & mesh);
285 
290  virtual void create(std::string filename);
291 
296  virtual void initialize(std::string title, const MeshBase & mesh, bool use_discontinuous=false);
297 
309  void write_nodal_solution(const NumericVector<Number> & parallel_soln,
310  const std::vector<std::string> & names,
311  int timestep);
312 
316  void write_nodal_solution(const std::vector<Number> & values,
317  const std::vector<std::string> & names,
318  int timestep);
319 
324  std::string construct_nemesis_filename(const std::string & base_filename);
325 
335 
345 
350  int num_proc;
351 
358 
364  char ftype;
365 
373  std::vector<int> global_sideset_ids;
374  std::vector<int> num_global_side_counts;
375  std::vector<int> num_global_side_df_counts;
376 
377 
385  std::vector<int> global_nodeset_ids;
386  std::vector<int> num_global_node_counts;
387  std::vector<int> num_global_node_df_counts;
388 
389 
395  std::vector<int> global_elem_blk_ids;
396  std::vector<int> global_elem_blk_cnts;
397 
402 
406  std::map<subdomain_id_type, std::vector<unsigned int>> subdomain_map;
407 
412  std::map<int, std::vector<int>> block_id_to_elem_connectivity;
413 
423 
430 
437 
443 
450 
457 
464 
465 
466 
472  std::vector<int> elem_mapi;
473 
479  std::vector<int> elem_mapb;
480 
481 
482 
488  std::vector<int> node_mapi;
489 
495  std::vector<int> node_mapb;
496 
502  std::vector<int> node_mape;
503 
504 
511  std::vector<int> node_cmap_ids;
512  std::vector<int> node_cmap_node_cnts;
513  std::vector<int> elem_cmap_ids;
514  std::vector<int> elem_cmap_elem_cnts;
515 
516 
525  std::vector<std::vector<int>> node_cmap_node_ids;
526  std::vector<std::vector<int>> node_cmap_proc_ids;
527 
528 
534  std::vector<std::vector<int>> elem_cmap_elem_ids;
535  std::vector<std::vector<int>> elem_cmap_side_ids;
536  std::vector<std::vector<int>> elem_cmap_proc_ids;
537 
538 
539 private:
544  std::map<subdomain_id_type, unsigned> local_subdomain_counts;
545 
550  std::set<unsigned> border_node_ids;
551 
557  std::map<unsigned, std::set<unsigned>> proc_nodes_touched_intersections;
558 
562  typedef std::map<unsigned, std::set<unsigned>>::iterator proc_nodes_touched_iterator;
563 
567  std::map<unsigned, std::set<std::pair<unsigned,unsigned>>> proc_border_elem_sets;
568 
572  typedef std::map<unsigned, std::set<std::pair<unsigned,unsigned>>>::iterator proc_border_elem_sets_iterator;
573 
577  std::set<unsigned> internal_node_ids;
578 
582  std::set<unsigned> internal_elem_ids;
583 
587  std::set<unsigned> border_elem_ids;
588 
593  void compute_num_global_elem_blocks(const MeshBase & pmesh);
594 
599  void compute_num_global_nodesets(const MeshBase & pmesh);
600 
605  void compute_num_global_sidesets(const MeshBase & pmesh);
606 
613  void build_element_and_node_maps(const MeshBase & pmesh);
614 
620  void compute_border_node_ids(const MeshBase & pmesh);
621 
626  void compute_internal_and_border_elems_and_internal_nodes(const MeshBase & pmesh);
627 
632  void compute_communication_map_parameters();
633 
638  void compute_node_communication_maps();
639 
645  void compute_node_maps();
646 
651  void compute_elem_communication_maps();
652 
657  void compute_element_maps();
658 
664  void write_exodus_initialization_info(const MeshBase & pmesh,
665  const std::string & title);
666 };
667 
668 } // namespace libMesh
669 
670 #endif // #if defined(LIBMESH_HAVE_NEMESIS_API) && defined(LIBMESH_HAVE_EXODUS_API)
671 #endif // LIBMESH_NEMESIS_IO_HELPER_H
std::vector< int > num_global_node_counts
std::vector< int > global_nodeset_ids
Containers for reading global nodeset information.
char ftype
The type of file to be written.
std::vector< int > global_sideset_ids
Containers for reading global sideset (boundary conditions) information.
std::vector< int > node_cmap_ids
Vectors for storing the communication map parameters.
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.
MeshBase & mesh
int num_node_cmaps
The number of nodal communication maps for this processor.
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
The libMesh namespace provides an interface to certain functionality in the library.
void initialize(EquationSystems &es, const std::string &system_name)
Definition: main.C:52
int num_nodes_global
Global initial information.
std::vector< int > num_global_side_df_counts
This is the MeshBase class.
Definition: mesh_base.h:68
This is the Nemesis_IO_Helper class.
std::vector< int > num_global_side_counts
std::vector< int > global_elem_blk_ids
Read the global element block IDs and counts.
std::vector< std::vector< int > > elem_cmap_elem_ids
3 vectors of vectors for storing element communication IDs for this processor.
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.
This is the ExodusII_IO_Helper class.
std::vector< std::vector< int > > elem_cmap_proc_ids
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.
This class forms the base class for all other classes that are expected to be implemented in parallel...
int num_internal_elems
The number of internal FEM elements.
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.
std::map< unsigned, std::set< unsigned > >::iterator proc_nodes_touched_iterator
Typedef for an iterator into the data structure above.
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
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).
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
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.
std::map< subdomain_id_type, std::vector< unsigned int > > subdomain_map
Map of subdomains to element numbers.
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:64
int num_border_elems
The number of border FEM elements.