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) override
 
virtual void write (const std::string &mesh_file) override
 
virtual void write_equation_systems (const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
 
bool is_parallel_file_format (const std::string &filename)
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< 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

◆ NameBasedIO() [1/2]

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 }

◆ NameBasedIO() [2/2]

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

Constructor. Takes a writable 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

◆ ascii_precision()

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

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.

Definition at line 244 of file mesh_output.h.

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

245 {
246  return _ascii_precision;
247 }

◆ is_parallel_file_format()

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

Definition at line 124 of file namebased_io.h.

References libMesh::Quality::name().

Referenced by read(), and write().

125 {
126  return ((name.rfind(".xda") < name.size()) ||
127  (name.rfind(".xdr") < name.size()) ||
128  (name.rfind(".nem") + 4 == name.size()) ||
129  (name.rfind(".n") + 2 == name.size()) ||
130  (name.rfind(".cp") < name.size())
131  );
132 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ mesh() [1/2]

MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
inlineprotectedinherited
Returns
The object as a writable reference.

Definition at line 169 of file mesh_input.h.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::VTKIO::cells_to_vtk(), 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::VTKIO::nodes_to_vtk(), libMesh::Nemesis_IO::prepare_to_write_nodal_data(), libMesh::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::VTKIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::CheckpointIO::read_remote_elem(), 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::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_header(), libMesh::UCDIO::write_implementation(), libMesh::UCDIO::write_interior_elems(), libMesh::GmshIO::write_mesh(), libMesh::VTKIO::write_nodal_data(), 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::UCDIO::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(), libMesh::UCDIO::write_soln(), and libMesh::CheckpointIO::write_subdomain_names().

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }

◆ mesh() [2/2]

◆ read()

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

This method implements reading a mesh from a specified file.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 59 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::Nemesis_IO::read(), libMesh::GmshIO::read(), libMesh::UNVIO::read(), libMesh::ExodusII_IO::read(), libMesh::UCDIO::read(), libMesh::GMVIO::read(), libMesh::XdrIO::read(), libMesh::MatlabIO::read(), libMesh::CheckpointIO::read(), and libMesh::VTKIO::read().

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

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

◆ set_n_partitions()

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_header().

91 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1371

◆ skip_comment_lines()

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.

Definition at line 179 of file mesh_input.h.

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

181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }

◆ write()

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

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 276 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::TetGenIO::write(), libMesh::GMVIO::write(), libMesh::Nemesis_IO::write(), libMesh::GmshIO::write(), libMesh::ExodusII_IO::write(), libMesh::UNVIO::write(), libMesh::UCDIO::write(), libMesh::XdrIO::write(), and libMesh::VTKIO::write().

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

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

◆ write_discontinuous_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

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

Definition at line 92 of file mesh_output.C.

References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), and libMesh::out.

Referenced by libMesh::ExodusII_IO::write_timestep_discontinuous().

95 {
96  LOG_SCOPE("write_discontinuous_equation_systems()", "MeshOutput");
97 
98  // We may need to gather and/or renumber a DistributedMesh to output
99  // it, making that const qualifier in our constructor a dirty lie
100  MT & my_mesh = const_cast<MT &>(*_obj);
101 
102  // If we're asked to write data that's associated with a different
103  // mesh, output files full of garbage are the result.
104  libmesh_assert_equal_to(&es.get_mesh(), _obj);
105 
106  // A non-renumbered mesh may not have a contiguous numbering, and
107  // that needs to be fixed before we can build a solution vector.
108  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
109  my_mesh.max_node_id() != my_mesh.n_nodes())
110  {
111  // If we were allowed to renumber then we should have already
112  // been properly renumbered...
113  libmesh_assert(!my_mesh.allow_renumbering());
114 
115  libmesh_do_once(libMesh::out <<
116  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
117  << std::endl;);
118 
119  my_mesh.allow_renumbering(true);
120 
121  my_mesh.renumber_nodes_and_elements();
122 
123  // Not sure what good going back to false will do here, the
124  // renumbering horses have already left the barn...
125  my_mesh.allow_renumbering(false);
126  }
127 
128  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
129 
130  // Build the list of variable names that will be written.
131  std::vector<std::string> names;
132  es.build_variable_names (names, nullptr, system_names);
133 
134  if (!_is_parallel_format)
135  {
136  // Build the nodal solution values & get the variable
137  // names from the EquationSystems object
138  std::vector<Number> soln;
139  es.build_discontinuous_solution_vector (soln, system_names);
140 
141  this->write_nodal_data_discontinuous (fname, soln, names);
142  }
143  else // _is_parallel_format
144  {
145  libmesh_not_implemented();
146  }
147 }
virtual void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:114
const MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ write_equation_systems()

void libMesh::NameBasedIO::write_equation_systems ( const std::string &  filename,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
overridevirtual

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 487 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().

490 {
491  // XDA/XDR require a separate code path, and currently only support
492  // writing complete restarts
493  if (!system_names)
494  {
495  if (filename.rfind(".xda") < filename.size())
496  {
497  es.write(filename,WRITE,
500  return;
501  }
502  else if (filename.rfind(".xdr") < filename.size())
503  {
504  es.write(filename,ENCODE,
507  return;
508  }
509  }
510 
511  // Other formats just use the default "write nodal values" path
513  (filename, es, system_names);
514 }
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
Definition: mesh_output.C:31

◆ write_nodal_data() [1/2]

void libMesh::NameBasedIO::write_nodal_data ( const std::string &  name,
const std::vector< Number > &  v,
const std::vector< std::string > &  vn 
)
overridevirtual

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 422 of file namebased_io.C.

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

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

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

◆ write_nodal_data() [2/2]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
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.

Definition at line 150 of file mesh_output.C.

References libMesh::NumericVector< T >::localize().

153 {
154  // This is the fallback implementation for parallel I/O formats that
155  // do not yet implement proper writing in parallel, and instead rely
156  // on the full solution vector being available on all processors.
157  std::vector<Number> soln;
158  parallel_soln.localize(soln);
159  this->write_nodal_data(fname, soln, names);
160 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
virtual void localize(std::vector< T > &v_local) const =0

◆ write_nodal_data_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

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

Reimplemented in libMesh::ExodusII_IO.

Definition at line 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

Member Data Documentation

◆ _is_parallel_format

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 159 of file mesh_output.h.

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

◆ _serial_only_needed_on_proc_0

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 168 of file mesh_output.h.

◆ elems_of_dimension


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