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 81 if (basename.rfind(
".nem") == basename.size() - 4 ||
82 basename.rfind(
".n") == basename.size() - 2)
84 std::ostringstream full_name;
88 int field_width = cast_int<int>(full_name.str().size());
96 <<
'.' << std::setfill(
'0') << std::setw(field_width) << mymesh.
processor_id();
98 std::ifstream in (full_name.str().c_str());
99 libmesh_error_msg_if(!in.good(),
"ERROR: cannot locate specified file:\n\t" << full_name.str());
101 else if (basename.rfind(
".cp")) {}
104 std::ifstream in (
name.c_str());
105 libmesh_error_msg_if(!in.good(),
"ERROR: cannot locate specified file:\n\t" <<
name);
112 if ((basename.rfind(
".xda") < basename.size()) ||
113 (basename.rfind(
".xdr") < basename.size()))
115 XdrIO xdr_io(mymesh);
118 if (basename.rfind(
".xda") < basename.size())
148 #ifdef LIBMESH_HAVE_LIBHILBERT 155 else if (basename.rfind(
".nem") < basename.size() ||
156 basename.rfind(
".n") < basename.size())
158 else if (basename.rfind(
".cp") < basename.size())
160 if (basename.rfind(
".cpa") < basename.size())
175 LOG_SCOPE(
"read()",
"NameBasedIO");
177 std::ostringstream pid_suffix;
178 pid_suffix <<
'_' << getpid();
180 std::string new_name =
name;
181 if (
name.rfind(
".bz2") ==
name.size() - 4)
183 #ifdef LIBMESH_HAVE_BZIP 184 new_name.erase(new_name.end() - 4, new_name.end());
185 new_name += pid_suffix.str();
186 std::string system_string =
"bunzip2 -f -k -c ";
187 system_string +=
name +
" > " + new_name;
188 LOG_SCOPE(
"system(bunzip2)",
"NameBasedIO");
189 if (std::system(system_string.c_str()))
190 libmesh_file_error(system_string);
192 libmesh_error_msg(
"ERROR: need bzip2/bunzip2 to open .bz2 file " <<
name);
195 else if (
name.rfind(
".xz") ==
name.size() - 3)
197 #ifdef LIBMESH_HAVE_XZ 198 new_name.erase(new_name.end() - 3, new_name.end());
199 new_name += pid_suffix.str();
200 std::string system_string =
"xz -f -d -k -c ";
201 system_string +=
name +
" > " + new_name;
202 LOG_SCOPE(
"system(xz -d)",
"XdrIO");
203 if (std::system(system_string.c_str()))
204 libmesh_file_error(system_string);
206 libmesh_error_msg(
"ERROR: need xz to open .xz file " <<
name);
210 if (basename.rfind(
".mat") < basename.size())
213 else if (basename.rfind(
".ucd") < basename.size())
216 else if ((basename.rfind(
".off") < basename.size()) ||
217 (basename.rfind(
".ogl") < basename.size()) ||
218 (basename.rfind(
".oogl") < basename.size()))
221 else if (basename.rfind(
".unv") < basename.size())
224 else if ((basename.rfind(
".node") < basename.size()) ||
225 (basename.rfind(
".ele") < basename.size()))
228 else if (basename.rfind(
".exd") < basename.size() ||
229 basename.rfind(
".e") < basename.size())
232 else if (basename.rfind(
".msh") < basename.size())
235 else if (basename.rfind(
".gmv") < basename.size())
238 else if (basename.rfind(
".stl") < basename.size())
241 else if (basename.rfind(
".pvtu") < basename.size() ||
242 basename.rfind(
".vtu") < basename.size())
245 else if (basename.rfind(
".inp") < basename.size())
248 else if ((basename.rfind(
".bext") < basename.size()) ||
249 (basename.rfind(
".bxt") < basename.size()))
252 else if (basename.rfind(
".bez") < basename.size())
257 libmesh_error_msg(
" ERROR: Unrecognized file extension: " \
259 <<
"\n I understand the following:\n\n" \
260 <<
" *.bext -- Bezier files in DYNA format\n" \
261 <<
" *.bez -- Bezier DYNA files, omit spline nodes\n" \
262 <<
" *.bxt -- Bezier files in DYNA format\n" \
263 <<
" *.cpa -- libMesh Checkpoint ASCII format\n" \
264 <<
" *.cpr -- libMesh Checkpoint binary format\n" \
265 <<
" *.e -- Sandia's ExodusII format\n" \
266 <<
" *.exd -- Sandia's ExodusII format\n" \
267 <<
" *.gmv -- LANL's General Mesh Viewer format\n" \
268 <<
" *.inp -- Abaqus .inp format\n" \
269 <<
" *.mat -- Matlab triangular ASCII file\n" \
270 <<
" *.n -- Sandia's Nemesis format\n" \
271 <<
" *.nem -- Sandia's Nemesis format\n" \
272 <<
" *.off -- OOGL OFF surface format\n" \
273 <<
" *.ogl -- OOGL OFF surface format\n" \
274 <<
" *.oogl -- OOGL OFF surface format\n" \
275 <<
" *.pvtu -- Paraview VTK format\n" \
276 <<
" *.stl -- STereoLithography triangulation format\n" \
277 <<
" *.ucd -- AVS's ASCII UCD format\n" \
278 <<
" *.unv -- I-deas Universal format\n" \
279 <<
" *.vtu -- Paraview VTK format\n" \
280 <<
" *.xda -- libMesh ASCII format\n" \
281 <<
" *.xdr -- libMesh binary format\n" \
282 <<
" *.gz -- any above format gzipped\n" \
283 <<
" *.bz2 -- any above format bzip2'ed\n" \
284 <<
" *.xz -- any above format xzipped\n" \
290 if (
name.rfind(
".bz2") ==
name.size() - 4)
291 std::remove(new_name.c_str());
292 if (
name.rfind(
".xz") ==
name.size() - 3)
293 std::remove(new_name.c_str());
314 if (basename.rfind(
".xda") < basename.size())
317 else if (basename.rfind(
".xdr") < basename.size())
320 else if (basename.rfind(
".nem") < basename.size() ||
321 basename.rfind(
".n") < basename.size())
324 else if (basename.rfind(
".cpa") < basename.size())
327 else if (basename.rfind(
".cpr") < basename.size())
331 libmesh_error_msg(
"Couldn't deduce filetype for " <<
name);
338 std::string new_name =
name;
343 std::ostringstream pid_suffix;
344 pid_suffix <<
'_' << pid_0;
346 if (
name.rfind(
".bz2") ==
name.size() - 4)
348 new_name.erase(new_name.end() - 4, new_name.end());
349 new_name += pid_suffix.str();
351 else if (
name.rfind(
".xz") ==
name.size() - 3)
353 new_name.erase(new_name.end() - 3, new_name.end());
354 new_name += pid_suffix.str();
360 if (basename.rfind(
".dat") < basename.size())
363 else if (basename.rfind(
".plt") < basename.size())
366 else if (basename.rfind(
".ucd") < basename.size())
369 else if (basename.rfind(
".gmv") < basename.size())
379 else if (basename.rfind(
".exd") < basename.size() ||
380 basename.rfind(
".e") < basename.size())
383 else if (basename.rfind(
".unv") < basename.size())
386 else if (basename.rfind(
".mesh") < basename.size())
389 else if (basename.rfind(
".poly") < basename.size())
392 else if (basename.rfind(
".msh") < basename.size())
395 else if (basename.rfind(
".fro") < basename.size())
398 else if (basename.rfind(
".pvtu") < basename.size())
401 else if (basename.rfind(
".stl") < basename.size())
407 <<
" ERROR: Unrecognized file extension: " <<
name 408 <<
"\n I understand the following:\n\n" 409 <<
" *.cpa -- libMesh ASCII checkpoint format\n" 410 <<
" *.cpr -- libMesh binary checkpoint format,\n" 411 <<
" *.dat -- Tecplot ASCII file\n" 412 <<
" *.e -- Sandia's ExodusII format\n" 413 <<
" *.exd -- Sandia's ExodusII format\n" 414 <<
" *.fro -- ACDL's surface triangulation file\n" 415 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n" 416 <<
" *.mesh -- MEdit mesh format\n" 417 <<
" *.msh -- GMSH ASCII file\n" 418 <<
" *.n -- Sandia's Nemesis format\n" 419 <<
" *.nem -- Sandia's Nemesis format\n" 420 <<
" *.plt -- Tecplot binary file\n" 421 <<
" *.poly -- TetGen ASCII file\n" 422 <<
" *.pvtu -- VTK (paraview-readable) format\n" 423 <<
" *.stl -- STereoLithography triangulation format\n" \
424 <<
" *.ucd -- AVS's ASCII UCD format\n" 425 <<
" *.unv -- I-deas Universal format\n" 426 <<
" *.xda -- libMesh ASCII format\n" 427 <<
" *.xdr -- libMesh binary format,\n" 429 <<
"\n Exiting without writing output\n";
434 if (
name.rfind(
".bz2") ==
name.size() - 4)
436 LOG_SCOPE(
"system(bzip2)",
"NameBasedIO");
439 std::string system_string =
"bzip2 -f -c ";
440 system_string += new_name +
" > " +
name;
441 if (std::system(system_string.c_str()))
442 libmesh_file_error(system_string);
443 std::remove(new_name.c_str());
447 if (
name.rfind(
".xz") ==
name.size() - 3)
449 LOG_SCOPE(
"system(xz)",
"NameBasedIO");
452 std::string system_string =
"xz -f -c ";
453 system_string += new_name +
" > " +
name;
454 if (std::system(system_string.c_str()))
455 libmesh_file_error(system_string);
456 std::remove(new_name.c_str());
465 const std::vector<Number> & v,
466 const std::vector<std::string> & vn)
471 if (
name.rfind(
".dat") <
name.size())
474 else if (
name.rfind(
".exd") <
name.size() ||
478 else if (
name.rfind(
".gmv") <
name.size())
490 else if (
name.rfind(
".mesh") <
name.size())
493 else if (
name.rfind(
".msh") <
name.size())
496 else if (
name.rfind(
".nem") <
name.size() ||
500 else if (
name.rfind(
".plt") <
name.size())
503 else if (
name.rfind(
".pvtu") <
name.size())
506 else if (
name.rfind(
".ucd") <
name.size())
512 <<
" ERROR: Unrecognized file extension: " <<
name 513 <<
"\n I understand the following:\n\n" 514 <<
" *.dat -- Tecplot ASCII file\n" 515 <<
" *.e -- Sandia's ExodusII format\n" 516 <<
" *.exd -- Sandia's ExodusII format\n" 517 <<
" *.gmv -- LANL's GMV (General Mesh Viewer) format\n" 518 <<
" *.mesh -- MEdit mesh format\n" 519 <<
" *.msh -- GMSH ASCII file\n" 520 <<
" *.n -- Sandia's Nemesis format\n" 521 <<
" *.nem -- Sandia's Nemesis format\n" 522 <<
" *.plt -- Tecplot binary file\n" 523 <<
" *.pvtu -- Paraview VTK file\n" 524 <<
" *.ucd -- AVS's ASCII UCD format\n" 525 <<
"\n Exiting without writing output\n";
532 const std::set<std::string> * system_names)
538 const std::string_view basename =
541 if (basename.rfind(
".xda") < basename.size())
548 else if (basename.rfind(
".xdr") < basename.size())
559 (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 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...
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.