libMesh::DivaIO Class Reference

#include <diva_io.h>

Inheritance diagram for libMesh::DivaIO:

Public Member Functions

 DivaIO (const MeshBase &)
 
virtual void write (const std::string &) libmesh_override
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

const MeshBasemesh () const
 

Protected Attributes

const bool _is_parallel_format
 

Private Member Functions

void write_stream (std::ostream &out)
 

Detailed Description

This class implements writing meshes in the Diva format. This is a scientific visualization program created by Kelly Gaither. More information on Diva can be found here: http://www.erc.msstate.edu/simcenter/docs/diva/

Author
John W. Peterson
Date
2004

Definition at line 43 of file diva_io.h.

Constructor & Destructor Documentation

libMesh::DivaIO::DivaIO ( const MeshBase mesh_in)
inlineexplicit

Note that only writing diva files is supported since Diva is not a mesh generator.

Definition at line 75 of file diva_io.h.

75  :
76  MeshOutput<MeshBase> (mesh_in)
77 {}

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

void libMesh::DivaIO::write ( const std::string &  fname)
virtual

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 34 of file diva_io.C.

References libMesh::MeshOutput< MeshBase >::_is_parallel_format, libMesh::MeshOutput< MeshBase >::mesh(), and write_stream().

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

35 {
36  // We may need to gather a ParallelMesh to output it, making that
37  // const qualifier in our constructor a dirty lie
38  MeshSerializer serialize(const_cast<MeshBase &>(this->mesh()), !_is_parallel_format);
39 
40  // Open the output file stream
41  std::ofstream out_file(fname.c_str());
42 
43  // Make sure it opened correctly
44  if (!out_file.good())
45  libmesh_file_error(fname.c_str());
46 
47  this->write_stream (out_file);
48 }
const MeshBase & mesh() const
void write_stream(std::ostream &out)
Definition: diva_io.C:53
virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = libmesh_nullptr 
)
virtualinherited

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

Reimplemented in libMesh::NameBasedIO.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().

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

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

Reimplemented in libMesh::ExodusII_IO, libMesh::GMVIO, libMesh::Nemesis_IO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::UCDIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 95 of file mesh_output.h.

98  { libmesh_not_implemented(); }
void libMesh::DivaIO::write_stream ( std::ostream &  out)
private

The actual implementation of writing the diva file. This file is called by the public interface file after it constructs an ofstream.

Write the header

Write the nodes

Write the BC faces

Write the triangles

Write the quadrilaterals

Write the BC IDs

Write the triangles

Write the quadrilaterals

Write all the Tets

Write all the Pyramids

Write all the Prisms

Write all the Hexes

Definition at line 53 of file diva_io.C.

References libMesh::Elem::active(), libMesh::BoundaryInfo::boundary_id(), libMesh::Elem::build_side(), libMesh::ParallelMesh::clear(), libMesh::ParallelObject::comm(), libMesh::Elem::connectivity(), libMesh::MeshBase::elem(), libMesh::err, libMesh::MeshBase::get_boundary_info(), libMesh::HEX20, libMesh::HEX27, libMesh::HEX8, libMesh::libmesh_assert(), libmesh_nullptr, libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshTools::n_active_elem_of_type(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_sides(), libMesh::Elem::n_sub_elem(), libMesh::Elem::neighbor(), libMesh::Elem::node(), libMesh::MeshBase::point(), libMesh::PRISM18, libMesh::PRISM6, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::QUAD8, libMesh::QUAD9, side, libMesh::BoundaryInfo::sync(), libMesh::TECPLOT, libMesh::TET10, libMesh::TET4, libMesh::TRI3, libMesh::TRI6, libMesh::Elem::type(), and libMesh::TypeVector< T >::write_unformatted().

Referenced by write().

54 {
55  /*
56  From Kelly: (kelly@tacc.utexas.edu)
57 
58  Ok, the following is the format:
59 
60  #points #triangles #quads #tets #prisms #pyramids #hexs
61  loop over all points (written out x y z x y z ...)
62  loop over all triangles (written out i1 i2 i3) (These are indices into
63  the points going from
64  1 to #points)
65  loop over all quads (written out i1 i2 i3 i4) (Same numbering scheme)
66  loop over all triangles and quads (write out b1) (This is a boundary
67  condition for each
68  triangle and each
69  hex. You can put
70  anything you want
71  here)
72  loop over all tets (written out i1 i2 i3 i4) (Same)
73  loop over all pyramids (written out i1 i2 i3 i4 i5) (Same)
74  loop over all prisms (written out i1 i2 i3 i4 i5 i6) (Same)
75  loop over all hexs (written out i1 i2 i3 i4 i5 i6 i7 i8) (Same)
76 
77  */
78 
79  // Be sure the stream has been created successfully.
80  libmesh_assert (out_file.good());
81 
82  // Can't use a constant mesh reference since we have to
83  // sync the boundary info.
84  libmesh_here();
85  libMesh::err << "WARNING... Sure you want to do this?"
86  << std::endl;
87  MeshBase & the_mesh = const_cast<MeshBase &>
89 
90  if (the_mesh.mesh_dimension() < 3)
91  {
92  libMesh::err << "WARNING: DIVA only supports 3D meshes.\n\n"
93  << "Exiting without producing output.\n";
94  return;
95  }
96 
97 
98 
99  BoundaryMesh boundary_mesh
100  (the_mesh.comm(),
101  cast_int<unsigned char>(the_mesh.mesh_dimension()-1));
102  the_mesh.get_boundary_info().sync(boundary_mesh);
103 
104 
108  out_file << the_mesh.n_nodes()
109  << ' '
110  << (MeshTools::n_active_elem_of_type(boundary_mesh,TRI3) +
111  MeshTools::n_active_elem_of_type(boundary_mesh,TRI6)*4)
112  << ' '
113  << (MeshTools::n_active_elem_of_type(boundary_mesh, QUAD4) +
114  MeshTools::n_active_elem_of_type(boundary_mesh, QUAD8) +
115  MeshTools::n_active_elem_of_type(boundary_mesh, QUAD9)*4)
116  << ' '
117  << (MeshTools::n_active_elem_of_type(the_mesh, TET4) +
119  << ' '
121  << ' '
124  << ' '
125  << (MeshTools::n_active_elem_of_type(the_mesh, HEX8) +
128  << ' '
129  << '\n';
130 
131  boundary_mesh.clear();
132 
133 
137  for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
138  the_mesh.point(v).write_unformatted(out_file);
139 
140 
144  {
148  for(unsigned int e=0; e<the_mesh.n_elem(); e++)
149  if (the_mesh.elem(e)->active())
150  for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
151  if (the_mesh.elem(e)->neighbor(s) == libmesh_nullptr)
152  {
153  const UniquePtr<Elem> side(the_mesh.elem(e)->build_side(s));
154 
155  if (side->type() == TRI3)
156  {
157  out_file << side->node(0)+1 << " "
158  << side->node(1)+1 << " "
159  << side->node(2)+1 << '\n';
160  }
161  else if (side->type() == TRI6)
162  {
163  out_file << side->node(0)+1 << " "
164  << side->node(3)+1 << " "
165  << side->node(5)+1 << '\n'
166 
167  << side->node(3)+1 << " "
168  << side->node(1)+1 << " "
169  << side->node(4)+1 << '\n'
170 
171  << side->node(5)+1 << " "
172  << side->node(4)+1 << " "
173  << side->node(2)+1 << '\n'
174 
175  << side->node(3)+1 << " "
176  << side->node(4)+1 << " "
177  << side->node(5)+1 << '\n';
178  }
179  }
180 
181 
185  for(unsigned int e=0; e<the_mesh.n_elem(); e++)
186  if (the_mesh.elem(e)->active())
187  for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
188  if (the_mesh.elem(e)->neighbor(s) == libmesh_nullptr)
189  {
190  const UniquePtr<Elem> side(the_mesh.elem(e)->build_side(s));
191 
192  if ((side->type() == QUAD4) ||
193  (side->type() == QUAD8) )
194  {
195  out_file << side->node(0)+1 << " "
196  << side->node(1)+1 << " "
197  << side->node(2)+1 << " "
198  << side->node(3)+1 << '\n';
199  }
200  else if (side->type() == QUAD9)
201  {
202  out_file << side->node(0)+1 << " "
203  << side->node(4)+1 << " "
204  << side->node(8)+1 << " "
205  << side->node(7)+1 << '\n'
206 
207  << side->node(4)+1 << " "
208  << side->node(1)+1 << " "
209  << side->node(5)+1 << " "
210  << side->node(8)+1 << '\n'
211 
212  << side->node(7)+1 << " "
213  << side->node(8)+1 << " "
214  << side->node(6)+1 << " "
215  << side->node(3)+1 << '\n'
216 
217  << side->node(8)+1 << " "
218  << side->node(5)+1 << " "
219  << side->node(2)+1 << " "
220  << side->node(6)+1 << '\n';
221  }
222  }
223  }
224 
225 
226 
230  {
234  for(unsigned int e=0; e<the_mesh.n_elem(); e++)
235  if (the_mesh.elem(e)->active())
236  for (unsigned short s=0; s<the_mesh.elem(e)->n_sides(); s++)
237  if (the_mesh.elem(e)->neighbor(s) == libmesh_nullptr)
238  {
239  const UniquePtr<Elem> side(the_mesh.elem(e)->build_side(s));
240 
241  if ((side->type() == TRI3) ||
242  (side->type() == TRI6) )
243 
244  out_file << the_mesh.get_boundary_info().boundary_id(the_mesh.elem(e), s)
245  << '\n';
246  }
247 
248 
252  for(unsigned int e=0; e<the_mesh.n_elem(); e++)
253  if (the_mesh.elem(e)->active())
254  for (unsigned short s=0; s<the_mesh.elem(e)->n_sides(); s++)
255  if (the_mesh.elem(e)->neighbor(s) == libmesh_nullptr)
256  {
257  const UniquePtr<Elem> side(the_mesh.elem(e)->build_side(s));
258 
259  if ((side->type() == QUAD4) ||
260  (side->type() == QUAD8) ||
261  (side->type() == QUAD9))
262 
263  out_file << the_mesh.get_boundary_info().boundary_id(the_mesh.elem(e), s);
264  }
265  }
266 
267 
268 
272  for (unsigned int e=0; e<the_mesh.n_elem(); e++)
273  if (the_mesh.elem(e)->active())
274  {
275  if (the_mesh.elem(e)->type() == TET4)
276  {
277  out_file << the_mesh.elem(e)->node(0)+1 << " "
278  << the_mesh.elem(e)->node(1)+1 << " "
279  << the_mesh.elem(e)->node(2)+1 << " "
280  << the_mesh.elem(e)->node(3)+1 << '\n';
281  }
282  else if (the_mesh.elem(e)->type() == TET10)
283  {
284  out_file << the_mesh.elem(e)->node(0)+1 << " "
285  << the_mesh.elem(e)->node(4)+1 << " "
286  << the_mesh.elem(e)->node(6)+1 << " "
287  << the_mesh.elem(e)->node(7)+1 << '\n';
288 
289  out_file << the_mesh.elem(e)->node(4)+1 << " "
290  << the_mesh.elem(e)->node(1)+1 << " "
291  << the_mesh.elem(e)->node(5)+1 << " "
292  << the_mesh.elem(e)->node(8)+1 << '\n';
293 
294  out_file << the_mesh.elem(e)->node(6)+1 << " "
295  << the_mesh.elem(e)->node(5)+1 << " "
296  << the_mesh.elem(e)->node(2)+1 << " "
297  << the_mesh.elem(e)->node(9)+1 << '\n';
298 
299  out_file << the_mesh.elem(e)->node(7)+1 << " "
300  << the_mesh.elem(e)->node(8)+1 << " "
301  << the_mesh.elem(e)->node(9)+1 << " "
302  << the_mesh.elem(e)->node(3)+1 << '\n';
303 
304  out_file << the_mesh.elem(e)->node(4)+1 << " "
305  << the_mesh.elem(e)->node(8)+1 << " "
306  << the_mesh.elem(e)->node(6)+1 << " "
307  << the_mesh.elem(e)->node(7)+1 << '\n';
308 
309  out_file << the_mesh.elem(e)->node(4)+1 << " "
310  << the_mesh.elem(e)->node(5)+1 << " "
311  << the_mesh.elem(e)->node(6)+1 << " "
312  << the_mesh.elem(e)->node(8)+1 << '\n';
313 
314  out_file << the_mesh.elem(e)->node(6)+1 << " "
315  << the_mesh.elem(e)->node(5)+1 << " "
316  << the_mesh.elem(e)->node(9)+1 << " "
317  << the_mesh.elem(e)->node(8)+1 << '\n';
318 
319  out_file << the_mesh.elem(e)->node(6)+1 << " "
320  << the_mesh.elem(e)->node(8)+1 << " "
321  << the_mesh.elem(e)->node(9)+1 << " "
322  << the_mesh.elem(e)->node(7)+1 << '\n';
323  }
324  }
325 
326 
330  for (unsigned int e=0; e<the_mesh.n_elem(); e++)
331  if (the_mesh.elem(e)->active())
332  if (the_mesh.elem(e)->type() == PYRAMID5)
333  {
334  out_file << the_mesh.elem(e)->node(0)+1 << " "
335  << the_mesh.elem(e)->node(1)+1 << " "
336  << the_mesh.elem(e)->node(2)+1 << " "
337  << the_mesh.elem(e)->node(3)+1 << " "
338  << the_mesh.elem(e)->node(4)+1 << '\n';
339  }
340 
341 
342 
346  for (unsigned int e=0; e<the_mesh.n_elem(); e++)
347  if (the_mesh.elem(e)->active())
348  {
349  if (the_mesh.elem(e)->type() == PRISM6)
350  {
351  out_file << the_mesh.elem(e)->node(0)+1 << " "
352  << the_mesh.elem(e)->node(1)+1 << " "
353  << the_mesh.elem(e)->node(2)+1 << " "
354  << the_mesh.elem(e)->node(3)+1 << " "
355  << the_mesh.elem(e)->node(4)+1 << " "
356  << the_mesh.elem(e)->node(5)+1 << '\n';
357  }
358  else if (the_mesh.elem(e)->type() == PRISM18)
359  libmesh_error_msg("PRISM18 element type not supported.");
360  }
361 
362 
366  for (unsigned int e=0; e<the_mesh.n_elem(); e++)
367  if (the_mesh.elem(e)->active())
368  if ((the_mesh.elem(e)->type() == HEX8) ||
369  (the_mesh.elem(e)->type() == HEX20) ||
370  (the_mesh.elem(e)->type() == HEX27) )
371  {
372  std::vector<dof_id_type> conn;
373  for (unsigned int se=0; se<the_mesh.elem(e)->n_sub_elem(); se++)
374  {
375  the_mesh.elem(e)->connectivity(se, TECPLOT, conn);
376 
377  out_file << conn[0] << ' '
378  << conn[1] << ' '
379  << conn[2] << ' '
380  << conn[3] << ' '
381  << conn[4] << ' '
382  << conn[5] << ' '
383  << conn[6] << ' '
384  << conn[7] << '\n';
385  }
386  }
387 }
libmesh_assert(remote_elem)
unsigned short int side
Definition: xdr_io.C:50
const class libmesh_nullptr_t libmesh_nullptr
const MT & mesh() const
Definition: mesh_output.h:199
OStreamProxy err(std::cerr)
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:551

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

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


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