libMesh
Loading...
Searching...
No Matches
nemesis_io_helper.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
32namespace libMesh
33{
34
35// Forward declarations
36class EquationSystems;
37template <typename T> class NumericVector;
38
39
53{
54public:
58 explicit
59 Nemesis_IO_Helper(const ParallelObject & parent,
60 bool verbose=false, bool single_precision=false);
61
65 virtual ~Nemesis_IO_Helper();
66
72 void write_complex_magnitude (bool val);
73
89 void read_nodeset(int id);
90
97 void get_init_global();
98
103 void get_ss_param_global();
104 void get_ns_param_global();
105 void get_eb_info_global();
106 void get_init_info();
107 void get_loadbal_param();
108 void get_elem_map();
109 void get_node_map();
110 void get_cmap_params();
111 void get_node_cmap();
112 void get_elem_cmap();
113
124 void put_init_info(unsigned num_proc,
125 unsigned num_proc_in_file,
126 const char * ftype);
127
138 unsigned num_elem_blks_global,
139 unsigned num_node_sets_global,
140 unsigned num_side_sets_global);
141
149 void put_eb_info_global(std::vector<int> & global_elem_blk_ids,
150 std::vector<int> & global_elem_blk_cnts);
151
160 void put_ns_param_global(std::vector<int> & global_nodeset_ids,
161 std::vector<int> & num_global_node_counts,
162 std::vector<int> & num_global_node_df_counts);
163
172 void put_ss_param_global(std::vector<int> & global_sideset_ids,
173 std::vector<int> & num_global_side_counts,
174 std::vector<int> & num_global_side_df_counts);
175
176
177
191 unsigned num_border_nodes,
192 unsigned num_external_nodes,
193 unsigned num_internal_elems,
194 unsigned num_border_elems,
195 unsigned num_node_cmaps,
196 unsigned num_elem_cmaps);
197
205 void put_cmap_params(std::vector<int> & node_cmap_ids,
206 std::vector<int> & node_cmap_node_cnts,
207 std::vector<int> & elem_cmap_ids,
208 std::vector<int> & elem_cmap_elem_cnts);
209
226 void put_node_cmap(std::vector<std::vector<int>> & node_cmap_node_ids,
227 std::vector<std::vector<int>> & node_cmap_proc_ids);
228
234 void put_node_map(std::vector<int> & node_mapi,
235 std::vector<int> & node_mapb,
236 std::vector<int> & node_mape);
237
247 void put_elem_cmap(std::vector<std::vector<int>> & elem_cmap_elem_ids,
248 std::vector<std::vector<int>> & elem_cmap_side_ids,
249 std::vector<std::vector<int>> & elem_cmap_proc_ids);
250
256 void put_elem_map(std::vector<int> & elem_mapi,
257 std::vector<int> & elem_mapb);
258
263 virtual void write_nodal_coordinates(const MeshBase & mesh, bool use_discontinuous=false) override;
264
268 virtual void write_elements(const MeshBase & mesh, bool use_discontinuous=false) override;
269
273 virtual void write_sidesets(const MeshBase & mesh) override;
274
278 virtual void write_nodesets(const MeshBase & mesh) override;
279
284 virtual void initialize(std::string title, const MeshBase & mesh, bool use_discontinuous=false) override;
285
290 void compute_num_global_elem_blocks(const MeshBase & pmesh);
291
298 void build_element_and_node_maps(const MeshBase & pmesh);
299
315 void write_nodal_solution(const NumericVector<Number> & parallel_soln,
316 const std::vector<std::string> & names,
317 int timestep,
318 const std::vector<std::string> & output_names);
319
324 const std::vector<std::pair<unsigned int, unsigned int>> & var_nums,
325 int timestep,
326 const std::vector<std::string> & output_names);
327
331 void write_nodal_solution(const std::vector<Number> & values,
332 const std::vector<std::string> & names,
333 int timestep);
334
339 virtual
340 void initialize_element_variables(std::vector<std::string> names,
341 const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains) override;
347 const EquationSystems & es,
348 const std::vector<std::pair<unsigned int, unsigned int>> &var_nums,
349 int timestep,
350 const std::vector<std::set<subdomain_id_type>> & vars_active_subdomains);
351
356 std::string construct_nemesis_filename(std::string_view base_filename);
357
367
377
383
390
396 char ftype;
397
398 // Stores node ids read in by the read_nodeset() function
399 std::vector<int> node_list;
400
408 std::vector<int> global_sideset_ids;
409 std::vector<int> num_global_side_counts;
411
412
420 std::vector<int> global_nodeset_ids;
421 std::vector<int> num_global_node_counts;
423
424
430 std::vector<int> global_elem_blk_ids;
431 std::vector<int> global_elem_blk_cnts;
432
437
441 std::map<subdomain_id_type, std::vector<dof_id_type>> subdomain_map;
442
447 std::map<int, std::vector<int>> block_id_to_elem_connectivity;
448
458
465
472
478
485
492
499
500
501
507 std::vector<int> elem_mapi;
508
514 std::vector<int> elem_mapb;
515
516
517
523 std::vector<int> node_mapi;
524
530 std::vector<int> node_mapb;
531
537 std::vector<int> node_mape;
538
539
546 std::vector<int> node_cmap_ids;
547 std::vector<int> node_cmap_node_cnts;
548 std::vector<int> elem_cmap_ids;
549 std::vector<int> elem_cmap_elem_cnts;
550
551
560 std::vector<std::vector<int>> node_cmap_node_ids;
561 std::vector<std::vector<int>> node_cmap_proc_ids;
562
563
569 std::vector<std::vector<int>> elem_cmap_elem_ids;
570 std::vector<std::vector<int>> elem_cmap_side_ids;
571 std::vector<std::vector<int>> elem_cmap_proc_ids;
572
583
584protected:
589 virtual void read_var_names_impl(const char * var_type,
590 int & count,
591 std::vector<std::string> & result) override;
592
593private:
598 std::map<subdomain_id_type, unsigned> local_subdomain_counts;
599
604 std::set<unsigned> border_node_ids;
605
611 std::map<unsigned, std::set<unsigned>> proc_nodes_touched_intersections;
612
616 typedef std::map<unsigned, std::set<unsigned>>::iterator proc_nodes_touched_iterator;
617
621 std::map<unsigned, std::set<std::pair<unsigned,unsigned>>> proc_border_elem_sets;
622
626 typedef std::map<unsigned, std::set<std::pair<unsigned,unsigned>>>::iterator proc_border_elem_sets_iterator;
627
631 std::set<unsigned> internal_node_ids;
632
636 std::set<unsigned> internal_elem_ids;
637
641 std::set<unsigned> border_elem_ids;
642
647 void compute_num_global_nodesets(const MeshBase & pmesh);
648
653 void compute_num_global_sidesets(const MeshBase & pmesh);
654
660 void compute_border_node_ids(const MeshBase & pmesh);
661
667
673
679
685 void compute_node_maps();
686
692
698
705 const std::string & title);
706};
707
708} // namespace libMesh
709
710#endif // #if defined(LIBMESH_HAVE_NEMESIS_API) && defined(LIBMESH_HAVE_EXODUS_API)
711#endif // LIBMESH_NEMESIS_IO_HELPER_H
This is the EquationSystems class.
This is the ExodusII_IO_Helper class.
This is the MeshBase class.
Definition mesh_base.h:81
This is the Nemesis_IO_Helper class.
void compute_node_maps()
Compute the node maps (really just pack vectors) which map the nodes to internal, border,...
int num_border_elems
The number of border FEM elements.
std::vector< std::vector< int > > elem_cmap_proc_ids
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...
int num_external_nodes
The number of FEM nodes that reside on another processor but whose element partially resides on the c...
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.
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...
virtual void write_sidesets(const MeshBase &mesh) override
Writes the sidesets for this processor.
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...
int num_internal_nodes
To be used with the Nemesis::ne_get_loadbal_param() routine.
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.
int num_internal_elems
The number of internal FEM elements.
void get_ss_param_global()
Fills: global_sideset_ids, num_global_side_counts, num_global_side_df_counts Call after: get_init_glo...
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.
std::set< unsigned > internal_elem_ids
A set of internal elem IDs for this processor.
char ftype
The type of file to be written.
void put_init_info(unsigned num_proc, unsigned num_proc_in_file, const char *ftype)
Writing functions.
std::map< unsigned, std::set< unsigned > > proc_nodes_touched_intersections
Another map to store sets of intersections with each other processor (other than ourself,...
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.
std::vector< int > elem_cmap_elem_cnts
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
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...
std::vector< int > elem_mapb
Vector which stores border element IDs.
std::vector< int > global_elem_blk_cnts
int num_proc_in_file
The number of processors for which the NEMESIS I file stores information.
void compute_communication_map_parameters()
This function determines the communication map parameters which will eventually be written to file.
void read_nodeset(int id)
Reading functions.
std::set< unsigned > border_elem_ids
A set of border elem IDs for this processor.
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< subdomain_id_type, std::vector< dof_id_type > > subdomain_map
Map of subdomains to element numbers.
void compute_num_global_elem_blocks(const MeshBase &pmesh)
This function uses global communication routines to determine the number of element blocks across the...
void get_init_global()
Fills: num_nodes_global, num_elems_global, num_elem_blks_global, num_node_sets_global,...
int num_node_cmaps
The number of nodal communication maps for this processor.
std::set< int > nodes_attached_to_local_elems
libMesh numbered node ids attached to local elems.
std::set< unsigned > internal_node_ids
A set of internal node IDs for this processor.
void compute_num_global_nodesets(const MeshBase &pmesh)
This function uses global communication routines to determine the number of nodesets across the entir...
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< unsigned, std::set< unsigned > >::iterator proc_nodes_touched_iterator
Typedef for an iterator into the data structure above.
std::vector< int > num_global_side_df_counts
std::vector< int > elem_mapi
Vector which stores internal element IDs.
void write_exodus_initialization_info(const MeshBase &pmesh, const std::string &title)
This function writes exodus-specific initialization information.
void compute_elem_communication_maps()
This function computes element communication maps (really just packs vectors) in preparation for writ...
std::vector< int > num_global_side_counts
void compute_element_maps()
This function computes element maps (really just packs vectors) which map the elements to internal an...
std::vector< int > node_mape
Vector which stores external node IDs.
std::vector< int > node_mapb
Vector which stores border node IDs.
std::vector< int > node_cmap_node_cnts
std::vector< int > node_cmap_ids
Vectors for storing the communication map parameters.
void put_elem_map(std::vector< int > &elem_mapi, std::vector< int > &elem_mapb)
Outputs IDs of internal and border elements.
int num_nodes_global
Global initial information.
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's implementation of this function so that it works correctly in parallel.
std::vector< int > global_elem_blk_ids
Read the global element block IDs and counts.
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 ...
std::vector< int > num_global_node_df_counts
std::vector< std::vector< int > > node_cmap_proc_ids
void compute_num_global_sidesets(const MeshBase &pmesh)
This function uses global communication routines to determine the number of sidesets across the entir...
std::map< int, std::vector< int > > block_id_to_elem_connectivity
This is the block connectivity, i.e.
std::vector< int > global_nodeset_ids
Containers for reading global nodeset information.
std::vector< std::vector< int > > elem_cmap_elem_ids
3 vectors of vectors for storing element communication IDs for this processor.
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::vector< int > num_global_node_counts
void compute_border_node_ids(const MeshBase &pmesh)
This function constructs the set of border node IDs present on the current mesh.
void build_element_and_node_maps(const MeshBase &pmesh)
This function builds the libmesh -> exodus and exodus -> libmesh node and element maps.
bool write_complex_abs
By default, when complex numbers are enabled, for each variable we write out three values: the real p...
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...
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 ....
std::vector< int > node_mapi
Vector which stores internal node IDs.
int num_elem_cmaps
The number of elemental communication maps for this processor.
void compute_node_communication_maps()
Compute the node communication maps (really just pack vectors) in preparation for writing them to fil...
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...
std::set< unsigned > border_node_ids
The set which will eventually contain the IDs of "border nodes".
std::vector< int > elem_cmap_ids
std::vector< std::vector< int > > elem_cmap_side_ids
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::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.
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.
virtual void write_elements(const MeshBase &mesh, bool use_discontinuous=false) override
This function is specialized to write the connectivity.
std::vector< std::vector< int > > node_cmap_node_ids
2 vectors of vectors for storing the node communication IDs for this processor.
virtual ~Nemesis_IO_Helper()
Destructor.
int num_proc
The number of processors for which the NEMESIS I file was created.
std::vector< int > global_sideset_ids
Containers for reading global sideset (boundary conditions) information.
virtual void write_nodesets(const MeshBase &mesh) override
Writes the nodesets for this processor.
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.
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.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
An object whose state is distributed along a set of processors.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t dof_id_type
Definition id_types.h:67