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") ||
234 else if (
contains(basename,
".msh"))
237 else if (
contains(basename,
".gmv"))
240 else if (
contains(basename,
".stl"))
243 else if (
contains(basename,
".pvtu") ||
247 else if (
contains(basename,
".inp"))
250 else if (
contains(basename,
".bext") ||
254 else if (
contains(basename,
".bez"))
259 libmesh_error_msg(
" ERROR: Unrecognized file extension: " \
261 <<
"\n I understand the following:\n\n" \
262 <<
" *.bext -- Bezier files in DYNA format\n" \
263 <<
" *.bez -- Bezier DYNA files, omit spline nodes\n" \
264 <<
" *.bxt -- Bezier files in DYNA format\n" \
265 <<
" *.cpa -- libMesh Checkpoint ASCII format\n" \
266 <<
" *.cpr -- libMesh Checkpoint binary format\n" \
267 <<
" *.e -- Sandia's ExodusII format\n" \
268 <<
" *.exd -- Sandia's ExodusII format\n" \
269 <<
" *.gmv -- LANL's General Mesh Viewer format\n" \
270 <<
" *.inp -- Abaqus .inp format\n" \
271 <<
" *.mat -- Matlab triangular ASCII file\n" \
272 <<
" *.n -- Sandia's Nemesis format\n" \
273 <<
" *.nem -- Sandia's Nemesis format\n" \
274 <<
" *.off -- OOGL OFF surface format\n" \
275 <<
" *.ogl -- OOGL OFF surface format\n" \
276 <<
" *.oogl -- OOGL OFF surface format\n" \
277 <<
" *.pvtu -- Paraview VTK format\n" \
278 <<
" *.stl -- STereoLithography triangulation format\n" \
279 <<
" *.ucd -- AVS's ASCII UCD format\n" \
280 <<
" *.unv -- I-deas Universal format\n" \
281 <<
" *.vtu -- Paraview VTK format\n" \
282 <<
" *.xda -- libMesh ASCII format\n" \
283 <<
" *.xdr -- libMesh binary format\n" \
284 <<
" *.gz -- any above format gzipped\n" \
285 <<
" *.bz2 -- any above format bzip2'ed\n" \
286 <<
" *.xz -- any above format xzipped\n" \
293 std::remove(new_name.c_str());
295 std::remove(new_name.c_str());
322 else if (
contains(basename,
".xdr"))
325 else if (
contains(basename,
".nem") ||
329 else if (
contains(basename,
".cpa"))
332 else if (
contains(basename,
".cpr"))
336 libmesh_error_msg(
"Couldn't deduce filetype for " <<
name);
343 std::string new_name =
name;
348 std::ostringstream pid_suffix;
349 pid_suffix <<
'_' << pid_0;
353 new_name.erase(new_name.end() - 4, new_name.end());
354 new_name += pid_suffix.str();
358 new_name.erase(new_name.end() - 3, new_name.end());
359 new_name += pid_suffix.str();
368 else if (
contains(basename,
".plt"))
371 else if (
contains(basename,
".ucd"))
374 else if (
contains(basename,
".gmv"))
384 else if (
contains(basename,
".exd") ||
388 else if (
contains(basename,
".unv"))
391 else if (
contains(basename,
".mesh"))
394 else if (
contains(basename,
".poly"))
397 else if (
contains(basename,
".msh"))
400 else if (
contains(basename,
".fro"))
403 else if (
contains(basename,
".pvtu"))
406 else if (
contains(basename,
".stl"))
412 <<
" ERROR: Unrecognized file extension: " <<
name 413 <<
"\n I understand the following:\n\n" 414 <<
" *.cpa -- libMesh ASCII checkpoint format\n" 415 <<
" *.cpr -- libMesh binary checkpoint format,\n" 416 <<
" *.dat -- Tecplot ASCII file\n" 417 <<
" *.e -- Sandia's ExodusII format\n" 418 <<
" *.exd -- Sandia's ExodusII format\n" 419 <<
" *.fro -- ACDL's surface triangulation file\n" 420 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n" 421 <<
" *.mesh -- MEdit mesh format\n" 422 <<
" *.msh -- GMSH ASCII file\n" 423 <<
" *.n -- Sandia's Nemesis format\n" 424 <<
" *.nem -- Sandia's Nemesis format\n" 425 <<
" *.plt -- Tecplot binary file\n" 426 <<
" *.poly -- TetGen ASCII file\n" 427 <<
" *.pvtu -- VTK (paraview-readable) format\n" 428 <<
" *.stl -- STereoLithography triangulation format\n" \
429 <<
" *.ucd -- AVS's ASCII UCD format\n" 430 <<
" *.unv -- I-deas Universal format\n" 431 <<
" *.xda -- libMesh ASCII format\n" 432 <<
" *.xdr -- libMesh binary format,\n" 434 <<
"\n Exiting without writing output\n";
441 LOG_SCOPE(
"system(bzip2)",
"NameBasedIO");
444 std::string system_string =
"bzip2 -f -c ";
445 system_string += new_name +
" > " +
name;
446 if (std::system(system_string.c_str()))
447 libmesh_file_error(system_string);
448 std::remove(new_name.c_str());
454 LOG_SCOPE(
"system(xz)",
"NameBasedIO");
457 std::string system_string =
"xz -f -c ";
458 system_string += new_name +
" > " +
name;
459 if (std::system(system_string.c_str()))
460 libmesh_file_error(system_string);
461 std::remove(new_name.c_str());
470 const std::vector<Number> & v,
471 const std::vector<std::string> & vn)
520 <<
" ERROR: Unrecognized file extension: " <<
name 521 <<
"\n I understand the following:\n\n" 522 <<
" *.dat -- Tecplot ASCII file\n" 523 <<
" *.e -- Sandia's ExodusII format\n" 524 <<
" *.exd -- Sandia's ExodusII format\n" 525 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n" 526 <<
" *.mesh -- MEdit mesh format\n" 527 <<
" *.msh -- GMSH ASCII file\n" 528 <<
" *.n -- Sandia's Nemesis format\n" 529 <<
" *.nem -- Sandia's Nemesis format\n" 530 <<
" *.plt -- Tecplot binary file\n" 531 <<
" *.pvtu -- Paraview VTK file\n" 532 <<
" *.ucd -- AVS's ASCII UCD format\n" 533 <<
"\n Exiting without writing output\n";
540 const std::set<std::string> * system_names)
546 const std::string_view basename =
567 (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.