Go to the documentation of this file.
   24 #include <sys/types.h>  
   28 #include "libmesh/libmesh_logging.h" 
   29 #include "libmesh/mesh_base.h" 
   30 #include "libmesh/mesh_communication.h" 
   31 #include "libmesh/namebased_io.h" 
   32 #include "libmesh/dyna_io.h" 
   33 #include "libmesh/exodusII_io.h" 
   34 #include "libmesh/gmv_io.h" 
   35 #include "libmesh/tecplot_io.h" 
   36 #include "libmesh/tetgen_io.h" 
   37 #include "libmesh/ucd_io.h" 
   38 #include "libmesh/unv_io.h" 
   39 #include "libmesh/matlab_io.h" 
   40 #include "libmesh/off_io.h" 
   41 #include "libmesh/medit_io.h" 
   42 #include "libmesh/nemesis_io.h" 
   43 #include "libmesh/gmsh_io.h" 
   44 #include "libmesh/fro_io.h" 
   45 #include "libmesh/xdr_io.h" 
   46 #include "libmesh/vtk_io.h" 
   47 #include "libmesh/abaqus_io.h" 
   48 #include "libmesh/checkpoint_io.h" 
   49 #include "libmesh/equation_systems.h" 
   50 #include "libmesh/enum_xdr_mode.h" 
   52 #include "libmesh/parallel.h"  
   72   if (
name.rfind(
".nem") + 4 == 
name.size() ||
 
   75       std::ostringstream full_name;
 
   79       int field_width = cast_int<int>(full_name.str().size());
 
   87                 << 
'.' << std::setfill(
'0') << std::setw(field_width) << mymesh.
processor_id();
 
   89       std::ifstream in (full_name.str().c_str());
 
   92         libmesh_error_msg(
"ERROR: cannot locate specified file:\n\t" << full_name.str());
 
   94   else if (
name.rfind(
".cp")) {} 
 
   97       std::ifstream in (
name.c_str());
 
  100         libmesh_error_msg(
"ERROR: cannot locate specified file:\n\t" << 
name);
 
  107       if ((
name.rfind(
".xda") < 
name.size()) ||
 
  110           XdrIO xdr_io(mymesh);
 
  113           if (
name.rfind(
".xda") < 
name.size())
 
  143 #ifdef LIBMESH_HAVE_LIBHILBERT 
  150       else if (
name.rfind(
".nem") < 
name.size() ||
 
  153       else if (
name.rfind(
".cp") < 
name.size())
 
  155           if (
name.rfind(
".cpa") < 
name.size())
 
  170           LOG_SCOPE(
"read()", 
"NameBasedIO");
 
  172           std::ostringstream pid_suffix;
 
  173           pid_suffix << 
'_' << getpid();
 
  175           std::string new_name = 
name;
 
  176           if (
name.size() - 
name.rfind(
".bz2") == 4)
 
  178 #ifdef LIBMESH_HAVE_BZIP 
  179               new_name.erase(new_name.end() - 4, new_name.end());
 
  180               new_name += pid_suffix.str();
 
  181               std::string system_string = 
"bunzip2 -f -k -c ";
 
  182               system_string += 
name + 
" > " + new_name;
 
  183               LOG_SCOPE(
"system(bunzip2)", 
"NameBasedIO");
 
  184               if (std::system(system_string.c_str()))
 
  185                 libmesh_file_error(system_string);
 
  187               libmesh_error_msg(
"ERROR: need bzip2/bunzip2 to open .bz2 file " << 
name);
 
  190           else if (
name.size() - 
name.rfind(
".xz") == 3)
 
  192 #ifdef LIBMESH_HAVE_XZ 
  193               new_name.erase(new_name.end() - 3, new_name.end());
 
  194               new_name += pid_suffix.str();
 
  195               std::string system_string = 
"xz -f -d -k -c ";
 
  196               system_string += 
name + 
" > " + new_name;
 
  197               LOG_SCOPE(
"system(xz -d)", 
"XdrIO");
 
  198               if (std::system(system_string.c_str()))
 
  199                 libmesh_file_error(system_string);
 
  201               libmesh_error_msg(
"ERROR: need xz to open .xz file " << 
name);
 
  205           if (new_name.rfind(
".mat") < new_name.size())
 
  208           else if (new_name.rfind(
".ucd") < new_name.size())
 
  211           else if ((new_name.rfind(
".off")  < new_name.size()) ||
 
  212                    (new_name.rfind(
".ogl")  < new_name.size()) ||
 
  213                    (new_name.rfind(
".oogl") < new_name.size()))
 
  216           else if (new_name.rfind(
".unv") < new_name.size())
 
  219           else if ((new_name.rfind(
".node")  < new_name.size()) ||
 
  220                    (new_name.rfind(
".ele")   < new_name.size()))
 
  223           else if (new_name.rfind(
".exd") < new_name.size() ||
 
  224                    new_name.rfind(
".e") < new_name.size())
 
  227           else if (new_name.rfind(
".msh") < new_name.size())
 
  230           else if (new_name.rfind(
".gmv") < new_name.size())
 
  233           else if (new_name.rfind(
".vtu") < new_name.size())
 
  236           else if (new_name.rfind(
".inp") < new_name.size())
 
  239           else if ((new_name.rfind(
".bext")  < new_name.size()) ||
 
  240                    (new_name.rfind(
".bxt")   < new_name.size()))
 
  245               libmesh_error_msg(
" ERROR: Unrecognized file extension: " \
 
  247                                 << 
"\n   I understand the following:\n\n" \
 
  248                                 << 
"     *.bext -- Bezier files in DYNA format\n" \
 
  249                                 << 
"     *.bxt  -- Bezier files in DYNA format\n" \
 
  250                                 << 
"     *.e    -- Sandia's ExodusII format\n" \
 
  251                                 << 
"     *.exd  -- Sandia's ExodusII format\n" \
 
  252                                 << 
"     *.gmv  -- LANL's General Mesh Viewer format\n" \
 
  253                                 << 
"     *.mat  -- Matlab triangular ASCII file\n" \
 
  254                                 << 
"     *.n    -- Sandia's Nemesis format\n" \
 
  255                                 << 
"     *.nem  -- Sandia's Nemesis format\n" \
 
  256                                 << 
"     *.off  -- OOGL OFF surface format\n" \
 
  257                                 << 
"     *.ucd  -- AVS's ASCII UCD format\n" \
 
  258                                 << 
"     *.unv  -- I-deas Universal format\n" \
 
  259                                 << 
"     *.vtu  -- Paraview VTK format\n" \
 
  260                                 << 
"     *.inp  -- Abaqus .inp format\n" \
 
  261                                 << 
"     *.xda  -- libMesh ASCII format\n" \
 
  262                                 << 
"     *.xdr  -- libMesh binary format\n" \
 
  263                                 << 
"     *.gz   -- any above format gzipped\n" \
 
  264                                 << 
"     *.bz2  -- any above format bzip2'ed\n" \
 
  265                                 << 
"     *.xz   -- any above format xzipped\n" \
 
  266                                 << 
"     *.cpa  -- libMesh Checkpoint ASCII format\n" \
 
  267                                 << 
"     *.cpr  -- libMesh Checkpoint binary format\n");
 
  272           if (
name.size() - 
name.rfind(
".bz2") == 4)
 
  273             std::remove(new_name.c_str());
 
  274           if (
name.size() - 
name.rfind(
".xz") == 3)
 
  275             std::remove(new_name.c_str());
 
  294       if (
name.rfind(
".xda") < 
name.size())
 
  297       else if (
name.rfind(
".xdr") < 
name.size())
 
  300       else if (
name.rfind(
".nem") < 
name.size() ||
 
  304       else if (
name.rfind(
".cpa") < 
name.size())
 
  307       else if (
name.rfind(
".cpr") < 
name.size())
 
  311         libmesh_error_msg(
"Couldn't deduce filetype for " << 
name);
 
  318       std::string new_name = 
name;
 
  322       mymesh.
comm().broadcast(pid_0);
 
  323       std::ostringstream pid_suffix;
 
  324       pid_suffix << 
'_' << pid_0;
 
  326       if (
name.size() - 
name.rfind(
".bz2") == 4)
 
  328           new_name.erase(new_name.end() - 4, new_name.end());
 
  329           new_name += pid_suffix.str();
 
  331       else if (
name.size() - 
name.rfind(
".xz") == 3)
 
  333           new_name.erase(new_name.end() - 3, new_name.end());
 
  334           new_name += pid_suffix.str();
 
  340         if (new_name.rfind(
".dat") < new_name.size())
 
  343         else if (new_name.rfind(
".plt") < new_name.size())
 
  346         else if (new_name.rfind(
".ucd") < new_name.size())
 
  349         else if (new_name.rfind(
".gmv") < new_name.size())
 
  359         else if (new_name.rfind(
".e") < new_name.size())
 
  362         else if (new_name.rfind(
".unv") < new_name.size())
 
  365         else if (new_name.rfind(
".mesh") < new_name.size())
 
  368         else if (new_name.rfind(
".poly") < new_name.size())
 
  371         else if (new_name.rfind(
".msh") < new_name.size())
 
  374         else if (new_name.rfind(
".fro") < new_name.size())
 
  377         else if (new_name.rfind(
".vtu") < new_name.size())
 
  383               << 
" ERROR: Unrecognized file extension: " << 
name 
  384               << 
"\n   I understand the following:\n\n" 
  385               << 
"     *.cpa   -- libMesh ASCII checkpoint format\n" 
  386               << 
"     *.cpr   -- libMesh binary checkpoint format,\n" 
  387               << 
"     *.dat   -- Tecplot ASCII file\n" 
  388               << 
"     *.e     -- Sandia's ExodusII format\n" 
  389               << 
"     *.exd   -- Sandia's ExodusII format\n" 
  390               << 
"     *.fro   -- ACDL's surface triangulation file\n" 
  391               << 
"     *.gmv   -- LANL's GMV (General Mesh Viewer) format\n" 
  392               << 
"     *.mesh  -- MEdit mesh format\n" 
  393               << 
"     *.mgf   -- MGF binary mesh format\n" 
  394               << 
"     *.msh   -- GMSH ASCII file\n" 
  395               << 
"     *.n     -- Sandia's Nemesis format\n" 
  396               << 
"     *.nem   -- Sandia's Nemesis format\n" 
  397               << 
"     *.plt   -- Tecplot binary file\n" 
  398               << 
"     *.poly  -- TetGen ASCII file\n" 
  399               << 
"     *.ucd   -- AVS's ASCII UCD format\n" 
  400               << 
"     *.ugrid -- Kelly's DIVA ASCII format\n" 
  401               << 
"     *.unv   -- I-deas Universal format\n" 
  402               << 
"     *.vtu   -- VTK (paraview-readable) format\n" 
  403               << 
"     *.xda   -- libMesh ASCII format\n" 
  404               << 
"     *.xdr   -- libMesh binary format,\n" 
  406               << 
"\n Exiting without writing output\n";
 
  411       if (
name.size() - 
name.rfind(
".bz2") == 4)
 
  413           LOG_SCOPE(
"system(bzip2)", 
"NameBasedIO");
 
  416               std::string system_string = 
"bzip2 -f -c ";
 
  417               system_string += new_name + 
" > " + 
name;
 
  418               if (std::system(system_string.c_str()))
 
  419                 libmesh_file_error(system_string);
 
  420               std::remove(new_name.c_str());
 
  422           mymesh.
comm().barrier();
 
  424       if (
name.size() - 
name.rfind(
".xz") == 3)
 
  426           LOG_SCOPE(
"system(xz)", 
"NameBasedIO");
 
  429               std::string system_string = 
"xz -f -c ";
 
  430               system_string += new_name + 
" > " + 
name;
 
  431               if (std::system(system_string.c_str()))
 
  432                 libmesh_file_error(system_string);
 
  433               std::remove(new_name.c_str());
 
  435           mymesh.
comm().barrier();
 
  442                                     const std::vector<Number> & v,
 
  443                                     const std::vector<std::string> & vn)
 
  448   if (
name.rfind(
".dat") < 
name.size())
 
  451   else if (
name.rfind(
".e") < 
name.size())
 
  454   else if (
name.rfind(
".gmv") < 
name.size())
 
  466   else if (
name.rfind(
".mesh") < 
name.size())
 
  469   else if (
name.rfind(
".msh") < 
name.size())
 
  472   else if (
name.rfind(
".nem") < 
name.size() ||
 
  476   else if (
name.rfind(
".plt") < 
name.size())
 
  479   else if (
name.rfind(
".pvtu") < 
name.size())
 
  482   else if (
name.rfind(
".ucd") < 
name.size())
 
  488         << 
" ERROR: Unrecognized file extension: " << 
name 
  489         << 
"\n   I understand the following:\n\n" 
  490         << 
"     *.dat  -- Tecplot ASCII file\n" 
  491         << 
"     *.e    -- Sandia's ExodusII format\n" 
  492         << 
"     *.exd  -- Sandia's ExodusII format\n" 
  493         << 
"     *.gmv  -- LANL's GMV (General Mesh Viewer) format\n" 
  494         << 
"     *.mesh -- MEdit mesh format\n" 
  495         << 
"     *.msh  -- GMSH ASCII file\n" 
  496         << 
"     *.n    -- Sandia's Nemesis format\n" 
  497         << 
"     *.nem  -- Sandia's Nemesis format\n" 
  498         << 
"     *.plt  -- Tecplot binary file\n" 
  499         << 
"     *.pvtu -- Paraview VTK file\n" 
  500         << 
"     *.ucd  -- AVS's ASCII UCD format\n" 
  501         << 
"\n Exiting without writing output\n";
 
  508                                           const std::set<std::string> * system_names)
 
  514       if (filename.rfind(
".xda") < filename.size())
 
  521       else if (filename.rfind(
".xdr") < filename.size())
 
  532     (filename, es, system_names);
 
  
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in VTK format.
 
virtual void write(const std::string &base_filename) override
This method implements writing a mesh to a specified file.
 
The AbaqusIO class is a preliminary implementation for reading Abaqus mesh files in ASCII format.
 
This class implements writing meshes in the .fro format used by the MIT ACDL.
 
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
 
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(const std::string &) override
This method implements writing a mesh to 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 write(const std::string &mesh_file) 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 ...
 
bool binary() const
Get/Set the flag indicating if we should read/write binary.
 
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file.
 
virtual void read(const std::string &name) override
Reads in an OFF OOGL data file based on the string you pass it.
 
MeshIO class used for writing XDR (eXternal Data Representation) and XDA mesh files.
 
This class implements writing meshes in the mesh format used by the MEdit visualization tool develope...
 
The libMesh namespace provides an interface to certain functionality in the library.
 
Reading and writing meshes in the Gmsh format.
 
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in TetGen format.
 
const Parallel::Communicator & comm() const
 
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".poly" file.
 
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.
 
unsigned int n_partitions() const
 
This class implements writing meshes in the GMV 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.
 
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
 
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_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a nodal solution.
 
void broadcast(MeshBase &) const
 
bool is_parallel_file_format(const std::string &filename)
 
subdomain_id_type n_subdomains() const
 
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
 
This is the MeshBase class.
 
The UNVIO class implements the Ideas UNV universal file format.
 
processor_id_type n_processors() const
 
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
 
processor_id_type processor_id() 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...
 
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 &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 &) 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 &input_name) override
This method implements reading a mesh from a specified file.
 
This is the EquationSystems class.
 
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in UCD format.
 
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 & partitioning()
Flag indicating whether or not to write the partitioning information for the mesh.
 
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 in UCD format.
 
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 write(const std::string &name) override
This method implements writing a mesh to a specified file.
 
void write(const std::string &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.
 
bool legacy() const
Get/Set the flag indicating if we should read/write legacy.
 
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_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 &fname) override
This method implements writing a mesh to a specified file.
 
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 Dyna format from the ASCII file given by name.
 
virtual void read(const std::string &name) 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.
 
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 read(const std::string &name) override
This method implements reading a mesh from a specified file.
 
This is the MeshCommunication class.
 
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 & writing meshes in the AVS's UCD format.
 
This class implements reading meshes in the Matlab PDE toolkit in a proprietary format.
 
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
 
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
 
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_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.