nemesis_io_helper.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
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 
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 
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) override;
270 
274  virtual void write_elements(const MeshBase & mesh, bool use_discontinuous=false) override;
275 
279  virtual void write_sidesets(const MeshBase & mesh) override;
280 
284  virtual void write_nodesets(const MeshBase & mesh) override;
285 
290  virtual void create(std::string filename) override;
291 
296  virtual void initialize(std::string title, const MeshBase & mesh, bool use_discontinuous=false) override;
297 
313  void write_nodal_solution(const NumericVector<Number> & parallel_soln,
314  const std::vector<std::string> & names,
315  int timestep,
316  const std::vector<std::string> & output_names);
317 
321  void write_nodal_solution(const std::vector<Number> & values,
322  const std::vector<std::string> & names,
323  int timestep);
324 
329  virtual
330  void initialize_element_variables(std::vector<std::string> names,
331  const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains) override;
336  void write_element_values(const MeshBase & mesh,
337  const NumericVector<Number> & parallel_soln,
338  const std::vector<std::string> & names,
339  int timestep,
340  const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains);
341 
346  std::string construct_nemesis_filename(const std::string & base_filename);
347 
357 
367 
372  int num_proc;
373 
380 
386  char ftype;
387 
395  std::vector<int> global_sideset_ids;
396  std::vector<int> num_global_side_counts;
397  std::vector<int> num_global_side_df_counts;
398 
399 
407  std::vector<int> global_nodeset_ids;
408  std::vector<int> num_global_node_counts;
409  std::vector<int> num_global_node_df_counts;
410 
411 
417  std::vector<int> global_elem_blk_ids;
418  std::vector<int> global_elem_blk_cnts;
419 
424 
428  std::map<subdomain_id_type, std::vector<dof_id_type>> subdomain_map;
429 
434  std::map<int, std::vector<int>> block_id_to_elem_connectivity;
435 
445 
452 
459 
465 
472 
479 
486 
487 
488 
494  std::vector<int> elem_mapi;
495 
501  std::vector<int> elem_mapb;
502 
503 
504 
510  std::vector<int> node_mapi;
511 
517  std::vector<int> node_mapb;
518 
524  std::vector<int> node_mape;
525 
526 
533  std::vector<int> node_cmap_ids;
534  std::vector<int> node_cmap_node_cnts;
535  std::vector<int> elem_cmap_ids;
536  std::vector<int> elem_cmap_elem_cnts;
537 
538 
547  std::vector<std::vector<int>> node_cmap_node_ids;
548  std::vector<std::vector<int>> node_cmap_proc_ids;
549 
550 
556  std::vector<std::vector<int>> elem_cmap_elem_ids;
557  std::vector<std::vector<int>> elem_cmap_side_ids;
558  std::vector<std::vector<int>> elem_cmap_proc_ids;
559 
560 
561 private:
566  std::map<subdomain_id_type, unsigned> local_subdomain_counts;
567 
572  std::set<unsigned> border_node_ids;
573 
579  std::map<unsigned, std::set<unsigned>> proc_nodes_touched_intersections;
580 
584  typedef std::map<unsigned, std::set<unsigned>>::iterator proc_nodes_touched_iterator;
585 
589  std::map<unsigned, std::set<std::pair<unsigned,unsigned>>> proc_border_elem_sets;
590 
594  typedef std::map<unsigned, std::set<std::pair<unsigned,unsigned>>>::iterator proc_border_elem_sets_iterator;
595 
599  std::set<unsigned> internal_node_ids;
600 
604  std::set<unsigned> internal_elem_ids;
605 
609  std::set<unsigned> border_elem_ids;
610 
615  void compute_num_global_elem_blocks(const MeshBase & pmesh);
616 
621  void compute_num_global_nodesets(const MeshBase & pmesh);
622 
627  void compute_num_global_sidesets(const MeshBase & pmesh);
628 
635  void build_element_and_node_maps(const MeshBase & pmesh);
636 
642  void compute_border_node_ids(const MeshBase & pmesh);
643 
649 
655 
661 
667  void compute_node_maps();
668 
674 
679  void compute_element_maps();
680 
686  void write_exodus_initialization_info(const MeshBase & pmesh,
687  const std::string & title);
688 };
689 
690 } // namespace libMesh
691 
692 #endif // #if defined(LIBMESH_HAVE_NEMESIS_API) && defined(LIBMESH_HAVE_EXODUS_API)
693 #endif // LIBMESH_NEMESIS_IO_HELPER_H
Nemesis_IO_Helper(const ParallelObject &parent, bool verbose=false, bool single_precision=false)
std::map< subdomain_id_type, std::vector< dof_id_type > > subdomain_map
std::vector< int > num_global_node_counts
std::vector< int > global_nodeset_ids
virtual void initialize(std::string title, const MeshBase &mesh, bool use_discontinuous=false) override
std::vector< int > global_sideset_ids
void compute_num_global_nodesets(const MeshBase &pmesh)
std::vector< int > node_cmap_ids
std::vector< int > node_mape
void compute_num_global_elem_blocks(const MeshBase &pmesh)
MeshBase & mesh
void put_elem_map(std::vector< int > &elem_mapi, std::vector< int > &elem_mapb)
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)
void put_eb_info_global(std::vector< int > &global_elem_blk_ids, std::vector< int > &global_elem_blk_cnts)
void compute_border_node_ids(const MeshBase &pmesh)
virtual void write_elements(const MeshBase &mesh, bool use_discontinuous=false) override
std::vector< int > num_global_side_df_counts
Base class for Mesh.
Definition: mesh_base.h:77
void build_element_and_node_maps(const MeshBase &pmesh)
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)
virtual void write_nodal_coordinates(const MeshBase &mesh, bool use_discontinuous=false) override
std::vector< int > num_global_side_counts
std::vector< int > global_elem_blk_ids
virtual void initialize_element_variables(std::vector< std::string > names, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains) override
std::vector< std::vector< int > > elem_cmap_elem_ids
std::set< unsigned > border_elem_ids
std::set< unsigned > internal_node_ids
std::vector< int > node_mapi
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)
std::set< unsigned > border_node_ids
std::set< int > nodes_attached_to_local_elems
An object whose state is distributed along a set of processors.
void compute_num_global_sidesets(const MeshBase &pmesh)
void compute_internal_and_border_elems_and_internal_nodes(const MeshBase &pmesh)
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)
std::map< subdomain_id_type, unsigned > local_subdomain_counts
std::map< int, std::vector< int > > block_id_to_elem_connectivity
virtual void write_nodesets(const MeshBase &mesh) override
std::map< unsigned, std::set< unsigned > >::iterator proc_nodes_touched_iterator
void put_node_map(std::vector< int > &node_mapi, std::vector< int > &node_mapb, std::vector< int > &node_mape)
std::vector< int > elem_cmap_elem_cnts
std::string construct_nemesis_filename(const std::string &base_filename)
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)
virtual void write_sidesets(const MeshBase &mesh) override
std::vector< int > node_cmap_node_cnts
std::map< unsigned, std::set< unsigned > > proc_nodes_touched_intersections
void write_element_values(const MeshBase &mesh, const NumericVector< Number > &parallel_soln, const std::vector< std::string > &names, int timestep, const std::vector< std::set< subdomain_id_type >> &vars_active_subdomains)
void write_exodus_initialization_info(const MeshBase &pmesh, const std::string &title)
void put_init_info(unsigned num_proc, unsigned num_proc_in_file, const char *ftype)
void put_node_cmap(std::vector< std::vector< int >> &node_cmap_node_ids, std::vector< std::vector< int >> &node_cmap_proc_ids)
std::vector< int > elem_mapb
std::vector< int > node_mapb
std::vector< std::vector< int > > node_cmap_node_ids
std::map< unsigned, std::set< std::pair< unsigned, unsigned > > >::iterator proc_border_elem_sets_iterator
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)
virtual void create(std::string filename) override
std::vector< int > elem_mapi
std::map< unsigned, std::set< std::pair< unsigned, unsigned > > > proc_border_elem_sets
void put_n_coord(unsigned start_node_num, unsigned num_nodes, std::vector< Real > &x_coor, std::vector< Real > &y_coor, std::vector< Real > &z_coor)
std::set< unsigned > internal_elem_ids
uint8_t dof_id_type
Definition: id_types.h:64
void write_nodal_solution(const NumericVector< Number > &parallel_soln, const std::vector< std::string > &names, int timestep, const std::vector< std::string > &output_names)