libMesh
nemesis_io.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 
19 
20 #ifndef LIBMESH_NEMESIS_IO_H
21 #define LIBMESH_NEMESIS_IO_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/mesh_input.h"
27 #include "libmesh/mesh_output.h"
28 #include "libmesh/parallel_object.h"
29 
30 // C++ includes
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class Nemesis_IO_Helper;
37 class System;
38 
51 class Nemesis_IO : public MeshInput<MeshBase>,
52  public MeshOutput<MeshBase>,
53  public ParallelObject
54 {
55 
56 public:
57 
62  explicit
63  Nemesis_IO (MeshBase & mesh, bool single_precision=false);
64 
69  explicit
70  Nemesis_IO (const MeshBase & mesh, bool single_precision=false);
71 
75  virtual ~Nemesis_IO ();
76 
82  virtual void read (const std::string & base_filename) override;
83 
87  virtual void write (const std::string & base_filename) override;
88 
92  void write_timestep (const std::string & fname,
93  const EquationSystems & es,
94  const int timestep,
95  const Real time);
96 
106  void set_output_variables(const std::vector<std::string> & output_variables,
107  bool allow_empty = true);
108 
112  virtual void write_nodal_data (const std::string & fname,
113  const std::vector<Number> & soln,
114  const std::vector<std::string> & names) override;
115 
119  virtual void write_nodal_data (const std::string & fname,
120  const EquationSystems & es,
121  const std::set<std::string> * system_names) override;
122 
126  virtual void write_nodal_data (const std::string & fname,
127  const NumericVector<Number> & parallel_soln,
128  const std::vector<std::string> & names) override;
129 
137  void write_element_data (const EquationSystems & es);
138 
142  void verbose (bool set_verbosity);
143 
149  void write_complex_magnitude (bool val);
150 
154  void write_global_data (const std::vector<Number> &,
155  const std::vector<std::string> &);
156 
160  void write_information_records (const std::vector<std::string> &);
161 
167  void append(bool val);
168 
172  const std::vector<std::string> & get_elem_var_names();
173 
177  const std::vector<std::string> & get_nodal_var_names();
178 
182  const std::vector<std::string> & get_global_var_names();
183 
187  const std::vector<Real> & get_time_steps();
188 
198  int get_num_time_steps();
199 
204  void copy_nodal_solution(System & system,
205  std::string system_var_name,
206  std::string exodus_var_name,
207  unsigned int timestep=1);
208 
213  void copy_elemental_solution(System & system,
214  std::string system_var_name,
215  std::string exodus_var_name,
216  unsigned int timestep=1);
217 
221  void copy_scalar_solution(System & system,
222  std::vector<std::string> system_var_names,
223  std::vector<std::string> exodus_var_names,
224  unsigned int timestep=1);
225 
233  void read_global_variable(std::vector<std::string> global_var_names,
234  unsigned int timestep,
235  std::vector<Real> & global_values);
236 
243  void set_hdf5_writing(bool write_hdf5);
244 
245 #ifdef LIBMESH_HAVE_NEMESIS_API
246 
250 #endif
251 
252 private:
253 
254  /*
255  * A helper function for use in debug and devel modes, for asserting
256  * that we get symmetric communication maps from a file we read
257  * and/or that we're writing them out in a symmetric fashion
258  * ourselves.
259  */
260  void assert_symmetric_cmaps();
261 
262 #if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
263  std::unique_ptr<Nemesis_IO_Helper> nemhelper;
264 
270 #endif
271 
275  bool _verbose;
276 
281  bool _append;
282 
288  void prepare_to_write_nodal_data (const std::string & fname,
289  const std::vector<std::string> & names);
290 
295  std::vector<std::string> _output_variables;
296 
303 };
304 
305 
306 } // namespace libMesh
307 
308 
309 #endif // LIBMESH_NEMESIS_IO_H
This is the EquationSystems class.
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
Definition: nemesis_io.C:214
const std::vector< std::string > & get_global_var_names()
Return list of the global variable names.
Definition: nemesis_io.C:1690
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...
Definition: nemesis_io.C:1718
void write_information_records(const std::vector< std::string > &)
Write out information records.
Definition: nemesis_io.C:1668
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 ...
Definition: nemesis_io.C:1834
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
The libMesh namespace provides an interface to certain functionality in the library.
bool _verbose
Controls whether extra debugging information is printed to the screen or not.
Definition: nemesis_io.h:275
This is the MeshBase class.
Definition: mesh_base.h:80
This is the Nemesis_IO_Helper class.
virtual ~Nemesis_IO()
Destructor.
void write_timestep(const std::string &fname, const EquationSystems &es, const int timestep, const Real time)
Write one timestep&#39;s worth of the solution.
Definition: nemesis_io.C:1290
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...
Definition: nemesis_io.C:1317
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
Definition: nemesis_io.h:51
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
void write_element_data(const EquationSystems &es)
Write out element solution in parallel, without localizing the solution vector.
Definition: nemesis_io.C:1466
bool _append
Default false.
Definition: nemesis_io.h:281
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
Definition: nemesis_io.C:1678
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.
Definition: nemesis_io.C:1800
bool _allow_empty_variables
If true, _output_variables is allowed to remain empty.
Definition: nemesis_io.h:302
An object whose state is distributed along a set of processors.
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.
Definition: nemesis_io.C:1571
void assert_symmetric_cmaps()
Definition: nemesis_io.C:177
int _timestep
Keeps track of the current timestep index being written.
Definition: nemesis_io.h:269
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void write_global_data(const std::vector< Number > &, const std::vector< std::string > &)
Write out global variables.
Definition: nemesis_io.C:1598
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...
Definition: nemesis_io.C:1751
virtual void write(const std::string &base_filename) override
This method implements writing a mesh to a specified file.
Definition: nemesis_io.C:1228
void append(bool val)
If true, this flag will cause the Nemesis_IO object to attempt to open an existing file for writing...
Definition: nemesis_io.C:161
std::unique_ptr< Nemesis_IO_Helper > nemhelper
Definition: nemesis_io.h:263
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...
Definition: nemesis_io.C:168
const std::vector< std::string > & get_elem_var_names()
Return list of the elemental variable names.
Definition: nemesis_io.C:1684
const std::vector< Real > & get_time_steps()
Definition: nemesis_io.C:1697
Nemesis_IO(MeshBase &mesh, bool single_precision=false)
Constructor.
Definition: nemesis_io.C:94
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)...
Definition: nemesis_io.C:1874
Nemesis_IO_Helper & get_nemio_helper()
Return a reference to the Nemesis_IO_Helper object.
Definition: nemesis_io.C:1864
void verbose(bool set_verbosity)
Set the flag indicating if we should be verbose.
Definition: nemesis_io.C:138
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
Definition: nemesis_io.C:151
std::vector< std::string > _output_variables
The names of the variables to be output.
Definition: nemesis_io.h:295