20#include "libmesh/libmesh_logging.h"
21#include "libmesh/mesh_base.h"
22#include "libmesh/mesh_communication.h"
23#include "libmesh/namebased_io.h"
24#include "libmesh/dyna_io.h"
25#include "libmesh/exodusII_io.h"
26#include "libmesh/gmv_io.h"
27#include "libmesh/tecplot_io.h"
28#include "libmesh/tetgen_io.h"
29#include "libmesh/ucd_io.h"
30#include "libmesh/unv_io.h"
31#include "libmesh/utility.h"
32#include "libmesh/matlab_io.h"
33#include "libmesh/off_io.h"
34#include "libmesh/medit_io.h"
35#include "libmesh/nemesis_io.h"
36#include "libmesh/gmsh_io.h"
37#include "libmesh/fro_io.h"
38#include "libmesh/stl_io.h"
39#include "libmesh/xdr_io.h"
40#include "libmesh/vtk_io.h"
41#include "libmesh/abaqus_io.h"
42#include "libmesh/checkpoint_io.h"
43#include "libmesh/equation_systems.h"
44#include "libmesh/enum_xdr_mode.h"
45#include "libmesh/parallel.h"
52#ifdef LIBMESH_HAVE_UNISTD_H
57#ifdef LIBMESH_HAVE_PROCESS_H
84 if (ends_with(basename,
".nem") || ends_with(basename,
".n"))
86 std::ostringstream full_name;
90 int field_width = cast_int<int>(full_name.str().size());
98 <<
'.' << std::setfill(
'0') << std::setw(field_width) << mymesh.
processor_id();
100 std::ifstream in (full_name.str().c_str());
101 libmesh_error_msg_if(!in.good(),
"ERROR: cannot locate specified file:\n\t" << full_name.str());
103 else if (contains(basename,
".cp")) {}
106 std::ifstream in (name.c_str());
107 libmesh_error_msg_if(!in.good(),
"ERROR: cannot locate specified file:\n\t" << name);
114 if (contains(basename,
".xda") ||
115 contains(basename,
".xdr"))
117 XdrIO xdr_io(mymesh);
120 if (contains(basename,
".xda"))
150#ifdef LIBMESH_HAVE_LIBHILBERT
157 else if (contains(basename,
".nem") ||
158 contains(basename,
".n"))
160 else if (contains(basename,
".cp"))
162 if (contains(basename,
".cpa"))
177 LOG_SCOPE(
"read()",
"NameBasedIO");
179 std::ostringstream pid_suffix;
180 pid_suffix <<
'_' << getpid();
182 std::string new_name = name;
183 if (ends_with(name,
".bz2"))
185#ifdef LIBMESH_HAVE_BZIP
186 new_name.erase(new_name.end() - 4, new_name.end());
187 new_name += pid_suffix.str();
188 std::string system_string =
"bunzip2 -f -k -c ";
189 system_string += name +
" > " + new_name;
190 LOG_SCOPE(
"system(bunzip2)",
"NameBasedIO");
191 if (std::system(system_string.c_str()))
192 libmesh_file_error(system_string);
194 libmesh_error_msg(
"ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
197 else if (ends_with(name,
".xz"))
199#ifdef LIBMESH_HAVE_XZ
200 new_name.erase(new_name.end() - 3, new_name.end());
201 new_name += pid_suffix.str();
202 std::string system_string =
"xz -f -d -k -c ";
203 system_string += name +
" > " + new_name;
204 LOG_SCOPE(
"system(xz -d)",
"XdrIO");
205 if (std::system(system_string.c_str()))
206 libmesh_file_error(system_string);
208 libmesh_error_msg(
"ERROR: need xz to open .xz file " << name);
212 if (contains(basename,
".mat"))
215 else if (contains(basename,
".ucd"))
218 else if (contains(basename,
".off") ||
219 contains(basename,
".ogl") ||
220 contains(basename,
".oogl"))
223 else if (contains(basename,
".unv"))
226 else if (contains(basename,
".node") ||
227 contains(basename,
".ele"))
230 else if (contains(basename,
".exd") ||
231 contains(basename,
".exo") ||
232 contains(basename,
".e"))
235 else if (contains(basename,
".msh"))
238 else if (contains(basename,
".gmv"))
241 else if (contains(basename,
".stl"))
244 else if (contains(basename,
".pvtu") ||
245 contains(basename,
".vtu"))
248 else if (contains(basename,
".inp"))
251 else if (contains(basename,
".bext") ||
252 contains(basename,
".bxt"))
255 else if (contains(basename,
".bez"))
260 libmesh_error_msg(
" ERROR: Unrecognized file extension: " \
262 <<
"\n I understand the following:\n\n" \
263 <<
" *.bext -- Bezier files in DYNA format\n" \
264 <<
" *.bez -- Bezier DYNA files, omit spline nodes\n" \
265 <<
" *.bxt -- Bezier files in DYNA format\n" \
266 <<
" *.cpa -- libMesh Checkpoint ASCII format\n" \
267 <<
" *.cpr -- libMesh Checkpoint binary format\n" \
268 <<
" *.e -- Sandia's ExodusII format\n" \
269 <<
" *.exo -- Sandia's ExodusII format\n" \
270 <<
" *.gmv -- LANL's General Mesh Viewer format\n" \
271 <<
" *.inp -- Abaqus .inp format\n" \
272 <<
" *.mat -- Matlab triangular ASCII file\n" \
273 <<
" *.n -- Sandia's Nemesis format\n" \
274 <<
" *.nem -- Sandia's Nemesis format\n" \
275 <<
" *.off -- OOGL OFF surface format\n" \
276 <<
" *.ogl -- OOGL OFF surface format\n" \
277 <<
" *.oogl -- OOGL OFF surface format\n" \
278 <<
" *.pvtu -- Paraview VTK format\n" \
279 <<
" *.stl -- STereoLithography triangulation format\n" \
280 <<
" *.ucd -- AVS's ASCII UCD format\n" \
281 <<
" *.unv -- I-deas Universal format\n" \
282 <<
" *.vtu -- Paraview VTK format\n" \
283 <<
" *.xda -- libMesh ASCII format\n" \
284 <<
" *.xdr -- libMesh binary format\n" \
285 <<
" *.gz -- any above format gzipped\n" \
286 <<
" *.bz2 -- any above format bzip2'ed\n" \
287 <<
" *.xz -- any above format xzipped\n" \
293 if (ends_with(basename,
".bz2"))
294 std::remove(new_name.c_str());
295 if (ends_with(basename,
".xz"))
296 std::remove(new_name.c_str());
320 if (contains(basename,
".xda"))
323 else if (contains(basename,
".xdr"))
326 else if (contains(basename,
".nem") ||
327 contains(basename,
".n"))
330 else if (contains(basename,
".cpa"))
333 else if (contains(basename,
".cpr"))
337 libmesh_error_msg(
"Couldn't deduce filetype for " << name);
344 std::string new_name = name;
349 std::ostringstream pid_suffix;
350 pid_suffix <<
'_' << pid_0;
352 if (ends_with(name,
".bz2"))
354 new_name.erase(new_name.end() - 4, new_name.end());
355 new_name += pid_suffix.str();
357 else if (ends_with(name,
".xz"))
359 new_name.erase(new_name.end() - 3, new_name.end());
360 new_name += pid_suffix.str();
366 if (contains(basename,
".dat"))
369 else if (contains(basename,
".plt"))
372 else if (contains(basename,
".ucd"))
375 else if (contains(basename,
".gmv"))
385 else if (contains(basename,
".exd") ||
386 contains(basename,
".exo") ||
387 contains(basename,
".e"))
390 else if (contains(basename,
".unv"))
393 else if (contains(basename,
".mesh"))
396 else if (contains(basename,
".poly"))
399 else if (contains(basename,
".msh"))
402 else if (contains(basename,
".fro"))
405 else if (contains(basename,
".pvtu"))
408 else if (contains(basename,
".stl"))
414 <<
" ERROR: Unrecognized file extension: " << name
415 <<
"\n I understand the following:\n\n"
416 <<
" *.cpa -- libMesh ASCII checkpoint format\n"
417 <<
" *.cpr -- libMesh binary checkpoint format,\n"
418 <<
" *.dat -- Tecplot ASCII file\n"
419 <<
" *.e -- Sandia's ExodusII format\n"
420 <<
" *.exo -- Sandia's ExodusII format\n"
421 <<
" *.fro -- ACDL's surface triangulation file\n"
422 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n"
423 <<
" *.mesh -- MEdit mesh format\n"
424 <<
" *.msh -- GMSH ASCII file\n"
425 <<
" *.n -- Sandia's Nemesis format\n"
426 <<
" *.nem -- Sandia's Nemesis format\n"
427 <<
" *.plt -- Tecplot binary file\n"
428 <<
" *.poly -- TetGen ASCII file\n"
429 <<
" *.pvtu -- VTK (paraview-readable) format\n"
430 <<
" *.stl -- STereoLithography triangulation format\n" \
431 <<
" *.ucd -- AVS's ASCII UCD format\n"
432 <<
" *.unv -- I-deas Universal format\n"
433 <<
" *.xda -- libMesh ASCII format\n"
434 <<
" *.xdr -- libMesh binary format,\n"
436 <<
"\n Exiting without writing output\n";
441 if (ends_with(basename,
".bz2"))
443 LOG_SCOPE(
"system(bzip2)",
"NameBasedIO");
446 std::string system_string =
"bzip2 -f -c ";
447 system_string += new_name +
" > " + name;
448 if (std::system(system_string.c_str()))
449 libmesh_file_error(system_string);
450 std::remove(new_name.c_str());
454 if (ends_with(basename,
".xz"))
456 LOG_SCOPE(
"system(xz)",
"NameBasedIO");
459 std::string system_string =
"xz -f -c ";
460 system_string += new_name +
" > " + name;
461 if (std::system(system_string.c_str()))
462 libmesh_file_error(system_string);
463 std::remove(new_name.c_str());
472 const std::vector<Number> & v,
473 const std::vector<std::string> & vn)
481 if (contains(name,
".dat"))
484 else if (contains(name,
".exd") ||
485 contains(name,
".exo") ||
486 contains(name,
".e"))
489 else if (contains(name,
".gmv"))
501 else if (contains(name,
".mesh"))
504 else if (contains(name,
".msh"))
507 else if (contains(name,
".nem") ||
508 contains(name,
".n"))
511 else if (contains(name,
".plt"))
514 else if (contains(name,
".pvtu"))
517 else if (contains(name,
".ucd"))
523 <<
" ERROR: Unrecognized file extension: " << name
524 <<
"\n I understand the following:\n\n"
525 <<
" *.dat -- Tecplot ASCII file\n"
526 <<
" *.e -- Sandia's ExodusII format\n"
527 <<
" *.exo -- Sandia's ExodusII format\n"
528 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n"
529 <<
" *.mesh -- MEdit mesh format\n"
530 <<
" *.msh -- GMSH ASCII file\n"
531 <<
" *.n -- Sandia's Nemesis format\n"
532 <<
" *.nem -- Sandia's Nemesis format\n"
533 <<
" *.plt -- Tecplot binary file\n"
534 <<
" *.pvtu -- Paraview VTK file\n"
535 <<
" *.ucd -- AVS's ASCII UCD format\n"
536 <<
"\n Exiting without writing output\n";
543 const std::set<std::string> * system_names)
549 const std::string_view basename =
570 (filename, es, system_names);
578 return (contains(name,
".xda") || contains(name,
".xdr") ||
579 ends_with(name,
".nem") || ends_with(name,
".n") ||
580 contains(name,
".cp"));
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
The AbaqusIO class is a preliminary implementation for reading Abaqus mesh files in ASCII format.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
Reading and writing meshes in (a subset of) LS-DYNA format.
virtual void read(const std::string &name) override
Reads in a mesh in the Dyna format from the ASCII file given by name.
This is the EquationSystems class.
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a nodal solution.
This class implements writing meshes in the .fro format used by the MIT ACDL.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
This class implements writing meshes in the GMV format.
bool & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Reading and writing meshes in the Gmsh format.
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file in the Gmsh *.msh format.
virtual void read(const std::string &name) override
Reads in a mesh in the Gmsh *.msh format from the ASCII file given by name.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
This class implements writing meshes in the mesh format used by the MEdit visualization tool develope...
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".mesh" file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
This class implements reading meshes in the Matlab PDE toolkit in a proprietary format.
virtual void read(const std::string &name) override
Reads in a matlab data file based on the string you pass it.
This is the MeshBase class.
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
unsigned int n_partitions() const
subdomain_id_type n_subdomains() const
This is the MeshCommunication class.
void broadcast(MeshBase &) const
This method takes a mesh (which is assumed to reside on processor 0) and broadcasts it to all the oth...
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
bool is_parallel_file_format(std::string_view filename)
virtual void write_equation_systems(const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
This method implements writing a mesh with data to a specified file where the data is taken from the ...
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
virtual void write(const std::string &mesh_file) override
This method implements writing a mesh to a specified file.
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
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.
virtual void write(const std::string &base_filename) override
This method implements writing a mesh to a specified file.
This class is responsible for reading an unstructured, triangulated surface in the standard OFF OOGL ...
virtual void read(const std::string &name) override
Reads in an OFF OOGL data file based on the string you pass it.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
This class implements reading and writing triangle meshes in the STL format.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
This class implements writing meshes in the Tecplot format.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
This class implements reading and writing meshes in the TetGen format.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" file.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
This class implements reading & writing meshes in the AVS's UCD format.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file in UCD format.
virtual void write_nodal_data(const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
This method implements writing a mesh and solution to a specified file in UCD format.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in UCD format.
The UNVIO class implements the Ideas UNV universal file format.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
This class implements reading and writing meshes in the VTK format.
virtual void write(const std::string &) override
Output the mesh without solutions to a .pvtu file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in VTK format.
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
bool binary() const
Get/Set the flag indicating if we should read/write binary.
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
bool ends_with(std::string_view superstring, std::string_view suffix)
Look for a substring at the very end of a string.
std::string_view basename_of(const std::string &fullname)
The libMesh namespace provides an interface to certain functionality in the library.