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 53 #include <sys/types.h> 57 #ifdef LIBMESH_HAVE_PROCESS_H 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);
117 XdrIO xdr_io(mymesh);
150 #ifdef LIBMESH_HAVE_LIBHILBERT 157 else if (
contains(basename,
".nem") ||
177 LOG_SCOPE(
"read()",
"NameBasedIO");
179 std::ostringstream pid_suffix;
180 pid_suffix <<
'_' << getpid();
182 std::string new_name =
name;
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);
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);
215 else if (
contains(basename,
".ucd"))
218 else if (
contains(basename,
".off") ||
223 else if (
contains(basename,
".unv"))
226 else if (
contains(basename,
".node") ||
230 else if (
contains(basename,
".exd") ||
235 else if (
contains(basename,
".msh"))
238 else if (
contains(basename,
".gmv"))
241 else if (
contains(basename,
".stl"))
244 else if (
contains(basename,
".pvtu") ||
248 else if (
contains(basename,
".inp"))
251 else if (
contains(basename,
".bext") ||
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" \
294 std::remove(new_name.c_str());
296 std::remove(new_name.c_str());
323 else if (
contains(basename,
".xdr"))
326 else if (
contains(basename,
".nem") ||
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;
354 new_name.erase(new_name.end() - 4, new_name.end());
355 new_name += pid_suffix.str();
359 new_name.erase(new_name.end() - 3, new_name.end());
360 new_name += pid_suffix.str();
369 else if (
contains(basename,
".plt"))
372 else if (
contains(basename,
".ucd"))
375 else if (
contains(basename,
".gmv"))
385 else if (
contains(basename,
".exd") ||
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";
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());
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)
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);
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
This class implements reading meshes in the Matlab PDE toolkit in a proprietary format.
virtual void read(const std::string &mesh_file) 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 &) override
This method implements reading a mesh from a specified file in UCD format.
virtual void read(const std::string &name) override
Reads in a mesh in the Dyna format from the ASCII file given by name.
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 ...
This is the EquationSystems class.
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
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.
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.
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
Reading and writing meshes in (a subset of) LS-DYNA format.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
This class implements reading and writing triangle meshes in the STL format.
bool is_parallel_file_format(std::string_view filename)
The AbaqusIO class is a preliminary implementation for reading Abaqus mesh files in ASCII format...
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".mesh" file.
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 ends_with(std::string_view superstring, std::string_view suffix)
Look for a substring at the very end of a string.
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
virtual void read(const std::string &name) override
Reads in a matlab data file based on the string you pass it.
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
virtual void write(const std::string &) override
Output the mesh without solutions to a .pvtu file.
const Parallel::Communicator & comm() const
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...
This class implements reading and writing meshes in the TetGen format.
The libMesh namespace provides an interface to certain functionality in the library.
This class implements writing meshes in the GMV format.
This class implements reading and writing meshes in the VTK format.
bool & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
This is the MeshBase class.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in VTK format.
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 &) override
This method implements writing a mesh to a specified file.
This class implements writing meshes in the .fro format used by the MIT ACDL.
processor_id_type n_processors() const
This class is responsible for reading an unstructured, triangulated surface in the standard OFF OOGL ...
This is the MeshCommunication class.
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.
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
virtual void write(const std::string &mesh_file) 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...
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
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...
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
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 &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
Output a nodal solution from data in soln.
unsigned int n_partitions() const
std::string_view basename_of(const std::string &fullname)
subdomain_id_type n_subdomains() const
virtual void read(const std::string &name) override
Reads in an OFF OOGL data file based on the string you pass it.
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
void broadcast(MeshBase &) const
Finds all the processors that may contain elements that neighbor my elements.
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" 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 &base_filename) override
This method implements writing a mesh to a specified file.
This class implements writing meshes in the Tecplot format.
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...
bool binary() const
Get/Set the flag indicating if we should read/write binary.
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
Write out a nodal solution.
processor_id_type processor_id() const
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 write(const std::string &) override
This method implements writing a mesh to a specified file in UCD format.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file.
The UNVIO class implements the Ideas UNV universal file format.