libMesh::NameBasedIO Class Reference

#include <namebased_io.h>

Inheritance diagram for libMesh::NameBasedIO:

Public Member Functions

 NameBasedIO (const MeshBase &)
 
 NameBasedIO (MeshBase &)
 
virtual void read (const std::string &mesh_file) libmesh_override
 
virtual void write (const std::string &mesh_file) libmesh_override
 
virtual void write_equation_systems (const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=libmesh_nullptr) libmesh_override
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) libmesh_override
 
bool is_parallel_file_format (const std::string &filename)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 
void skip_comment_lines (std::istream &in, const char comment_start)
 
const MeshBasemesh () const
 

Protected Attributes

std::vector< bool > elems_of_dimension
 
const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Detailed Description

This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of the other I/O classes based on filename.

Other I/O classes may have more advanced features that are not accessible via this interface.

Author
Roy H. Stogner
Date
2015

Definition at line 44 of file namebased_io.h.

Constructor & Destructor Documentation

libMesh::NameBasedIO::NameBasedIO ( const MeshBase mesh)
inlineexplicit

Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.

Definition at line 110 of file namebased_io.h.

110  :
111  MeshOutput<MeshBase> (mesh)
112 {
113 }
libMesh::NameBasedIO::NameBasedIO ( MeshBase mesh)
inlineexplicit

Constructor. Takes a writeable reference to a mesh object. This constructor is required to let us read in a mesh.

Definition at line 116 of file namebased_io.h.

116  :
117  MeshInput<MeshBase> (mesh),
118  MeshOutput<MeshBase>(mesh)
119 {
120 }

Member Function Documentation

unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

bool libMesh::NameBasedIO::is_parallel_file_format ( const std::string &  filename)
inline

Definition at line 124 of file namebased_io.h.

Referenced by read(), and write().

125 {
126  return ((name.rfind(".xda") < name.size()) ||
127  (name.rfind(".xdr") < name.size()) ||
128  (name.rfind(".nem") < name.size()) ||
129  (name.rfind(".n") < name.size()) ||
130  (name.rfind(".cp") < name.size())
131  );
132 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
protectedinherited

Returns the object as a writeable reference.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::CheckpointIO::build_elem_list(), libMesh::CheckpointIO::build_node_list(), libMesh::CheckpointIO::current_n_processors(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::GMVIO::read(), libMesh::ExodusII_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::UCDIO::UCDIO(), libMesh::VTKIO::VTKIO(), libMesh::TetGenIO::write(), libMesh::ExodusII_IO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::CheckpointIO::write_bcs(), libMesh::GMVIO::write_binary(), libMesh::CheckpointIO::write_connectivity(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), and libMesh::CheckpointIO::write_subdomain_names().

void libMesh::NameBasedIO::read ( const std::string &  mesh_file)
virtual

This method implements reading a mesh from a specified file.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 62 of file namebased_io.C.

References libMesh::MeshBase::allow_renumbering(), libMesh::XdrIO::binary(), libMesh::MeshCommunication::broadcast(), is_parallel_file_format(), libMesh::XdrIO::legacy(), libMesh::MeshInput< MT >::mesh(), libMesh::ParallelObject::n_processors(), libMesh::Quality::name(), libMesh::ParallelObject::processor_id(), libMesh::OFFIO::read(), libMesh::AbaqusIO::read(), libMesh::TetGenIO::read(), libMesh::UCDIO::read(), libMesh::GMVIO::read(), libMesh::Nemesis_IO::read(), libMesh::GmshIO::read(), libMesh::ExodusII_IO::read(), libMesh::UNVIO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::MatlabIO::read(), and libMesh::VTKIO::read().

Referenced by libMesh::UnstructuredMesh::read().

63 {
64  MeshBase & mymesh = MeshInput<MeshBase>::mesh();
65 
66  // See if the file exists. Perform this check on all processors
67  // so that the code is terminated properly in the case that the
68  // file does not exist.
69 
70  // For Nemesis files, the name we try to read will have suffixes
71  // identifying processor rank
72  if (name.rfind(".nem") + 4 == name.size() ||
73  name.rfind(".n") + 2 == name.size())
74  {
75  std::ostringstream full_name;
76 
77  // Find the length of a string which represents the highest processor ID
78  full_name << (mymesh.n_processors());
79  int field_width = cast_int<int>(full_name.str().size());
80 
81  // reset the string stream
82  full_name.str("");
83 
84  // And build up the full filename
85  full_name << name
86  << '.' << mymesh.n_processors()
87  << '.' << std::setfill('0') << std::setw(field_width) << mymesh.processor_id();
88 
89  std::ifstream in (full_name.str().c_str());
90 
91  if (!in.good())
92  libmesh_error_msg("ERROR: cannot locate specified file:\n\t" << full_name.str());
93  }
94  else if(name.rfind(".cp")) {} // Do error checking in the reader
95  else
96  {
97  std::ifstream in (name.c_str());
98 
99  if (!in.good())
100  libmesh_error_msg("ERROR: cannot locate specified file:\n\t" << name);
101  }
102 
103  // Look for parallel formats first
105  {
106  // no need to handle bz2 files here -- the Xdr class does that.
107  if ((name.rfind(".xda") < name.size()) ||
108  (name.rfind(".xdr") < name.size()))
109  {
110  XdrIO xdr_io(mymesh);
111 
112  // .xda* ==> bzip2/gzip/ASCII flavors
113  if (name.rfind(".xda") < name.size())
114  {
115  xdr_io.binary() = false;
116  xdr_io.read (name);
117  }
118  else // .xdr* ==> true binary XDR file
119  {
120  xdr_io.binary() = true;
121  xdr_io.read (name);
122  }
123 
124  // The xdr_io object gets constructed with legacy() == false.
125  // if legacy() == true then it means that a legacy file was detected and
126  // thus processor 0 performed the read. We therefore need to broadcast the
127  // mesh. Further, for this flavor of mesh solution data ordering is tied
128  // to the node ordering, so we better not reorder the nodes!
129  if (xdr_io.legacy())
130  {
131  mymesh.allow_renumbering(false);
132  MeshCommunication().broadcast(mymesh);
133  }
134 
135  // libHilbert-enabled libMesh builds should construct files
136  // with a canonical node ordering, which libHilbert-enabled
137  // builds will be able to read in again regardless of any
138  // renumbering. So in that case we're free to renumber.
139  // However, if either the writer or the reader of this file
140  // don't have libHilbert, then we'll have to skip
141  // renumbering because we need the numbering to remain
142  // consistent with any solution file we read in next.
143 #ifdef LIBMESH_HAVE_LIBHILBERT
144  // if (!xdr_io.libhilbert_ordering())
145  // skip_renumber_nodes_and_elements = true;
146 #else
147  mymesh.allow_renumbering(false);
148 #endif
149  }
150  else if (name.rfind(".nem") < name.size() ||
151  name.rfind(".n") < name.size())
152  Nemesis_IO(mymesh).read (name);
153  else if (name.rfind(".cp") < name.size())
154  {
155  if(name.rfind(".cpa") < name.size())
156  CheckpointIO(mymesh, false).read(name);
157  else
158  CheckpointIO(mymesh, true).read(name);
159  }
160  }
161 
162  // Serial mesh formats
163  else
164  {
165  // Read the file based on extension. Only processor 0
166  // needs to read the mesh. It will then broadcast it and
167  // the other processors will pick it up
168  if (mymesh.processor_id() == 0)
169  {
170  LOG_SCOPE("read()", "NameBasedIO");
171 
172  std::ostringstream pid_suffix;
173  pid_suffix << '_' << getpid();
174  // Nasty hack for reading/writing zipped files
175  std::string new_name = name;
176  if (name.size() - name.rfind(".bz2") == 4)
177  {
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);
186 #else
187  libmesh_error_msg("ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
188 #endif
189  }
190  else if (name.size() - name.rfind(".xz") == 3)
191  {
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);
200 #else
201  libmesh_error_msg("ERROR: need xz to open .xz file " << name);
202 #endif
203  }
204 
205  if (new_name.rfind(".mat") < new_name.size())
206  MatlabIO(mymesh).read(new_name);
207 
208  else if (new_name.rfind(".ucd") < new_name.size())
209  UCDIO(mymesh).read (new_name);
210 
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()))
214  OFFIO(mymesh).read (new_name);
215 
216  else if (new_name.rfind(".unv") < new_name.size())
217  UNVIO(mymesh).read (new_name);
218 
219  else if ((new_name.rfind(".node") < new_name.size()) ||
220  (new_name.rfind(".ele") < new_name.size()))
221  TetGenIO(mymesh).read (new_name);
222 
223  else if (new_name.rfind(".exd") < new_name.size() ||
224  new_name.rfind(".e") < new_name.size())
225  ExodusII_IO(mymesh).read (new_name);
226 
227  else if (new_name.rfind(".msh") < new_name.size())
228  GmshIO(mymesh).read (new_name);
229 
230  else if (new_name.rfind(".gmv") < new_name.size())
231  GMVIO(mymesh).read (new_name);
232 
233  else if (new_name.rfind(".vtu") < new_name.size())
234  VTKIO(mymesh).read(new_name);
235 
236  else if (new_name.rfind(".inp") < new_name.size())
237  AbaqusIO(mymesh).read(new_name);
238 
239  else
240  {
241  libmesh_error_msg(" ERROR: Unrecognized file extension: " \
242  << name \
243  << "\n I understand the following:\n\n" \
244  << " *.e -- Sandia's ExodusII format\n" \
245  << " *.exd -- Sandia's ExodusII format\n" \
246  << " *.gmv -- LANL's General Mesh Viewer format\n" \
247  << " *.mat -- Matlab triangular ASCII file\n" \
248  << " *.n -- Sandia's Nemesis format\n" \
249  << " *.nem -- Sandia's Nemesis format\n" \
250  << " *.off -- OOGL OFF surface format\n" \
251  << " *.ucd -- AVS's ASCII UCD format\n" \
252  << " *.unv -- I-deas Universal format\n" \
253  << " *.vtu -- Paraview VTK format\n" \
254  << " *.inp -- Abaqus .inp format\n" \
255  << " *.xda -- libMesh ASCII format\n" \
256  << " *.xdr -- libMesh binary format\n" \
257  << " *.gz -- any above format gzipped\n" \
258  << " *.bz2 -- any above format bzip2'ed\n" \
259  << " *.xz -- any above format xzipped\n" \
260  << " *.cpa -- libMesh Checkpoint ASCII format\n" \
261  << " *.cpr -- libMesh Checkpoint binary format\n");
262  }
263 
264  // If we temporarily decompressed a file, remove the
265  // uncompressed version
266  if (name.size() - name.rfind(".bz2") == 4)
267  std::remove(new_name.c_str());
268  if (name.size() - name.rfind(".xz") == 3)
269  std::remove(new_name.c_str());
270  }
271 
272  // Send the mesh & bcs (which are now only on processor 0) to the other
273  // processors
274  MeshCommunication().broadcast (mymesh);
275  }
276 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
bool is_parallel_file_format(const std::string &filename)
Definition: namebased_io.h:124
void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
inlineprotectedinherited

Sets the number of partitions in the mesh. Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 91 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read().

91 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1264
void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().

void libMesh::NameBasedIO::write ( const std::string &  mesh_file)
virtual

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 279 of file namebased_io.C.

References libMesh::Parallel::Communicator::barrier(), libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::err, is_parallel_file_format(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::n_partitions(), libMesh::Quality::name(), libMesh::GMVIO::partitioning(), libMesh::ParallelObject::processor_id(), libMesh::FroIO::write(), libMesh::TecplotIO::write(), libMesh::MEDITIO::write(), libMesh::GMVIO::write(), libMesh::TetGenIO::write(), libMesh::UCDIO::write(), libMesh::Nemesis_IO::write(), libMesh::GmshIO::write(), libMesh::UNVIO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), and libMesh::VTKIO::write().

Referenced by libMesh::UnstructuredMesh::find_neighbors(), and libMesh::UnstructuredMesh::write().

280 {
281  MeshBase & mymesh = MeshInput<MeshBase>::mesh();
282 
283  // parallel formats are special -- they may choose to write
284  // separate files, let's not try to handle the zipping here.
286  {
287  // no need to handle bz2 files here -- the Xdr class does that.
288  if (name.rfind(".xda") < name.size())
289  XdrIO(mymesh).write(name);
290 
291  else if (name.rfind(".xdr") < name.size())
292  XdrIO(mymesh,true).write(name);
293 
294  else if (name.rfind(".nem") < name.size() ||
295  name.rfind(".n") < name.size())
296  Nemesis_IO(mymesh).write(name);
297  }
298 
299  // serial file formats
300  else
301  {
302  // Nasty hack for reading/writing zipped files
303  std::string new_name = name;
304  pid_t pid_0 = 0;
305  if (mymesh.processor_id() == 0)
306  pid_0 = getpid();
307  mymesh.comm().broadcast(pid_0);
308  std::ostringstream pid_suffix;
309  pid_suffix << '_' << pid_0;
310 
311  if (name.size() - name.rfind(".bz2") == 4)
312  {
313  new_name.erase(new_name.end() - 4, new_name.end());
314  new_name += pid_suffix.str();
315  }
316  else if (name.size() - name.rfind(".xz") == 3)
317  {
318  new_name.erase(new_name.end() - 3, new_name.end());
319  new_name += pid_suffix.str();
320  }
321 
322  // New scope so that io will close before we try to zip the file
323  {
324  // Write the file based on extension
325  if (new_name.rfind(".dat") < new_name.size())
326  TecplotIO(mymesh).write (new_name);
327 
328  else if (new_name.rfind(".plt") < new_name.size())
329  TecplotIO(mymesh,true).write (new_name);
330 
331  else if (new_name.rfind(".ucd") < new_name.size())
332  UCDIO (mymesh).write (new_name);
333 
334  else if (new_name.rfind(".gmv") < new_name.size())
335  if (mymesh.n_partitions() > 1)
336  GMVIO(mymesh).write (new_name);
337  else
338  {
339  GMVIO io(mymesh);
340  io.partitioning() = false;
341  io.write (new_name);
342  }
343 
344  else if (new_name.rfind(".e") < new_name.size())
345  ExodusII_IO(mymesh).write(new_name);
346 
347  else if (new_name.rfind(".unv") < new_name.size())
348  UNVIO(mymesh).write (new_name);
349 
350  else if (new_name.rfind(".mesh") < new_name.size())
351  MEDITIO(mymesh).write (new_name);
352 
353  else if (new_name.rfind(".poly") < new_name.size())
354  TetGenIO(mymesh).write (new_name);
355 
356  else if (new_name.rfind(".msh") < new_name.size())
357  GmshIO(mymesh).write (new_name);
358 
359  else if (new_name.rfind(".fro") < new_name.size())
360  FroIO(mymesh).write (new_name);
361 
362  else if (new_name.rfind(".vtu") < new_name.size())
363  VTKIO(mymesh).write (new_name);
364 
365  else
366  {
368  << " ERROR: Unrecognized file extension: " << name
369  << "\n I understand the following:\n\n"
370  << " *.dat -- Tecplot ASCII file\n"
371  << " *.e -- Sandia's ExodusII format\n"
372  << " *.exd -- Sandia's ExodusII format\n"
373  << " *.fro -- ACDL's surface triangulation file\n"
374  << " *.gmv -- LANL's GMV (General Mesh Viewer) format\n"
375  << " *.mesh -- MEdit mesh format\n"
376  << " *.mgf -- MGF binary mesh format\n"
377  << " *.msh -- GMSH ASCII file\n"
378  << " *.n -- Sandia's Nemesis format\n"
379  << " *.nem -- Sandia's Nemesis format\n"
380  << " *.plt -- Tecplot binary file\n"
381  << " *.poly -- TetGen ASCII file\n"
382  << " *.ucd -- AVS's ASCII UCD format\n"
383  << " *.ugrid -- Kelly's DIVA ASCII format\n"
384  << " *.unv -- I-deas Universal format\n"
385  << " *.vtu -- VTK (paraview-readable) format\n"
386  << " *.xda -- libMesh ASCII format\n"
387  << " *.xdr -- libMesh binary format,\n"
388  << std::endl
389  << "\n Exiting without writing output\n";
390  }
391  }
392 
393  // Nasty hack for reading/writing zipped files
394  if (name.size() - name.rfind(".bz2") == 4)
395  {
396  LOG_SCOPE("system(bzip2)", "NameBasedIO");
397  if (mymesh.processor_id() == 0)
398  {
399  std::string system_string = "bzip2 -f -c ";
400  system_string += new_name + " > " + name;
401  if (std::system(system_string.c_str()))
402  libmesh_file_error(system_string);
403  std::remove(new_name.c_str());
404  }
405  mymesh.comm().barrier();
406  }
407  if (name.size() - name.rfind(".xz") == 3)
408  {
409  LOG_SCOPE("system(xz)", "NameBasedIO");
410  if (mymesh.processor_id() == 0)
411  {
412  std::string system_string = "xz -f -c ";
413  system_string += new_name + " > " + name;
414  if (std::system(system_string.c_str()))
415  libmesh_file_error(system_string);
416  std::remove(new_name.c_str());
417  }
418  mymesh.comm().barrier();
419  }
420  }
421 
422 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
OStreamProxy err(std::cerr)
bool is_parallel_file_format(const std::string &filename)
Definition: namebased_io.h:124
void libMesh::NameBasedIO::write_equation_systems ( const std::string &  filename,
const EquationSystems es,
const std::set< std::string > *  system_names = libmesh_nullptr 
)
virtual

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

We override the default MeshOutput::write_equation_systems because it only outputs nodal data by default, whereas we want to output a proper restart file if the requested filename is an XDA or XDR type.

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 490 of file namebased_io.C.

References libMesh::ENCODE, libMesh::WRITE, libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, libMesh::EquationSystems::WRITE_DATA, and libMesh::MeshOutput< MT >::write_equation_systems().

493 {
494  // XDA/XDR require a separate code path, and currently only support
495  // writing complete restarts
496  if (!system_names)
497  {
498  if (filename.rfind(".xda") < filename.size())
499  {
500  es.write(filename,WRITE,
503  return;
504  }
505  else if (filename.rfind(".xdr") < filename.size())
506  {
507  es.write(filename,ENCODE,
510  return;
511  }
512  }
513 
514  // Other formats just use the default "write nodal values" path
516  (filename, es, system_names);
517 }
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
Definition: mesh_output.C:31
void libMesh::NameBasedIO::write_nodal_data ( const std::string &  name,
const std::vector< Number > &  v,
const std::vector< std::string > &  vn 
)
virtual

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 425 of file namebased_io.C.

References libMesh::err, libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::n_subdomains(), libMesh::GMVIO::partitioning(), libMesh::TecplotIO::write_nodal_data(), libMesh::MEDITIO::write_nodal_data(), libMesh::GMVIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::UCDIO::write_nodal_data(), libMesh::Nemesis_IO::write_nodal_data(), libMesh::GmshIO::write_nodal_data(), and libMesh::ExodusII_IO::write_nodal_data().

Referenced by libMesh::UnstructuredMesh::write().

428 {
429  MeshBase & mymesh = MeshInput<MeshBase>::mesh();
430 
431  // Write the file based on extension
432  if (name.rfind(".dat") < name.size())
433  TecplotIO(mymesh).write_nodal_data (name, v, vn);
434 
435  else if (name.rfind(".e") < name.size())
436  ExodusII_IO(mymesh).write_nodal_data(name, v, vn);
437 
438  else if (name.rfind(".gmv") < name.size())
439  {
440  if (mymesh.n_subdomains() > 1)
441  GMVIO(mymesh).write_nodal_data (name, v, vn);
442  else
443  {
444  GMVIO io(mymesh);
445  io.partitioning() = false;
446  io.write_nodal_data (name, v, vn);
447  }
448  }
449 
450  else if (name.rfind(".mesh") < name.size())
451  MEDITIO(mymesh).write_nodal_data (name, v, vn);
452 
453  else if (name.rfind(".msh") < name.size())
454  GmshIO(mymesh).write_nodal_data (name, v, vn);
455 
456  else if (name.rfind(".nem") < name.size() ||
457  name.rfind(".n") < name.size())
458  Nemesis_IO(mymesh).write_nodal_data(name, v, vn);
459 
460  else if (name.rfind(".plt") < name.size())
461  TecplotIO(mymesh,true).write_nodal_data (name, v, vn);
462 
463  else if (name.rfind(".pvtu") < name.size())
464  VTKIO(mymesh).write_nodal_data (name, v, vn);
465 
466  else if (name.rfind(".ucd") < name.size())
467  UCDIO (mymesh).write_nodal_data (name, v, vn);
468 
469  else
470  {
472  << " ERROR: Unrecognized file extension: " << name
473  << "\n I understand the following:\n\n"
474  << " *.dat -- Tecplot ASCII file\n"
475  << " *.e -- Sandia's ExodusII format\n"
476  << " *.exd -- Sandia's ExodusII format\n"
477  << " *.gmv -- LANL's GMV (General Mesh Viewer) format\n"
478  << " *.mesh -- MEdit mesh format\n"
479  << " *.msh -- GMSH ASCII file\n"
480  << " *.n -- Sandia's Nemesis format\n"
481  << " *.nem -- Sandia's Nemesis format\n"
482  << " *.plt -- Tecplot binary file\n"
483  << " *.pvtu -- Paraview VTK file\n"
484  << " *.ucd -- AVS's ASCII UCD format\n"
485  << "\n Exiting without writing output\n";
486  }
487 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
OStreamProxy err(std::cerr)
virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data. Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

Member Data Documentation

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 141 of file mesh_output.h.

Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero

If this is false (default) the mesh will be serialized to all processors

Definition at line 150 of file mesh_output.h.


The documentation for this class was generated from the following files: