libMesh::DivaIO Class Reference

#include <diva_io.h>

Inheritance diagram for libMesh::DivaIO:

List of all members.

Public Member Functions

 DivaIO (const MeshBase &)
virtual void write (const std::string &)
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=NULL)
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

virtual 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, 2004

Definition at line 47 of file diva_io.h.


Constructor & Destructor Documentation

libMesh::DivaIO::DivaIO ( const MeshBase mesh_in  )  [inline, explicit]

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

Definition at line 79 of file diva_io.h.

00079                                        :
00080   MeshOutput<MeshBase>  (mesh_in)
00081 {}


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

00035 {
00036   // We may need to gather a ParallelMesh to output it, making that
00037   // const qualifier in our constructor a dirty lie
00038   MeshSerializer serialize(const_cast<MeshBase&>(this->mesh()), !_is_parallel_format);
00039 
00040   // Open the output file stream
00041   std::ofstream out_file(fname.c_str());
00042 
00043   // Make sure it opened correctly
00044   if (!out_file.good())
00045     libmesh_file_error(fname.c_str());
00046 
00047   this->write_stream (out_file);
00048 }

virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = NULL 
) [virtual, inherited]

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

Referenced by libMesh::Nemesis_IO::write_timestep().

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
) [inline, virtual, inherited]

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::GmshIO, libMesh::GMVIO, libMesh::GnuPlotIO, libMesh::MEDITIO, libMesh::Nemesis_IO, libMesh::TecplotIO, libMesh::UCDIO, and libMesh::VTKIO.

Definition at line 98 of file mesh_output.h.

00101   { libmesh_error(); }

void libMesh::DivaIO::write_stream ( std::ostream &  out  )  [private, virtual]

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::MeshBase::boundary_info, libMesh::Elem::build_side(), libMesh::Elem::connectivity(), libMesh::MeshBase::elem(), libMesh::err, libMeshEnums::HEX20, libMeshEnums::HEX27, libMeshEnums::HEX8, libMesh::MeshOutput< MeshBase >::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(), libMeshEnums::PRISM18, libMeshEnums::PRISM6, libMeshEnums::PYRAMID5, libMeshEnums::QUAD4, libMeshEnums::QUAD8, libMeshEnums::QUAD9, side, libMeshEnums::TECPLOT, libMeshEnums::TET10, libMeshEnums::TET4, libMeshEnums::TRI3, libMeshEnums::TRI6, libMesh::Elem::type(), and libMesh::TypeVector< T >::write_unformatted().

Referenced by write().

00054 {
00055   /*
00056     From Kelly: (kelly@tacc.utexas.edu)
00057 
00058     Ok, the following is the format:
00059 
00060     #points #triangles #quads #tets #prisms #pyramids #hexs
00061     loop over all points (written out x y z x y z ...)
00062     loop over all triangles (written out i1 i2 i3) (These are indices into
00063     the points going from
00064     1 to #points)
00065     loop over all quads (written out i1 i2 i3 i4) (Same numbering scheme)
00066     loop over all triangles and quads (write out b1) (This is a boundary
00067     condition for each
00068     triangle and each
00069     hex. You can put
00070     anything you want
00071     here)
00072     loop over all tets (written out i1 i2 i3 i4) (Same)
00073     loop over all pyramids (written out i1 i2 i3 i4 i5) (Same)
00074     loop over all prisms (written out i1 i2 i3 i4 i5 i6) (Same)
00075     loop over all hexs (written out i1 i2 i3 i4 i5 i6 i7 i8) (Same)
00076 
00077   */
00078 
00079   // Be sure the stream has been created successfully.
00080   libmesh_assert (out_file.good());
00081 
00082   // Can't use a constant mesh reference since we have to
00083   // sync the boundary info.
00084   libmesh_here();
00085   libMesh::err << "WARNING...  Sure you want to do this?"
00086                 << std::endl;
00087   MeshBase& the_mesh = const_cast<MeshBase&>
00088     (MeshOutput<MeshBase>::mesh());
00089 
00090   if (the_mesh.mesh_dimension() < 3)
00091     {
00092       libMesh::err << "WARNING: DIVA only supports 3D meshes.\n\n"
00093                     << "Exiting without producing output.\n";
00094       return;
00095     }
00096 
00097 
00098 
00099   BoundaryMesh boundary_mesh (the_mesh.mesh_dimension()-1);
00100   the_mesh.boundary_info->sync(boundary_mesh);
00101 
00102 
00106   out_file << the_mesh.n_nodes()
00107            << ' '
00108            << (MeshTools::n_active_elem_of_type(boundary_mesh,TRI3) +
00109                MeshTools::n_active_elem_of_type(boundary_mesh,TRI6)*4)
00110            << ' '
00111            << (MeshTools::n_active_elem_of_type(boundary_mesh, QUAD4) +
00112                MeshTools::n_active_elem_of_type(boundary_mesh, QUAD8) +
00113                MeshTools::n_active_elem_of_type(boundary_mesh, QUAD9)*4)
00114            << ' '
00115            << (MeshTools::n_active_elem_of_type(the_mesh, TET4) +
00116                MeshTools::n_active_elem_of_type(the_mesh, TET10)*8)
00117            << ' '
00118            << MeshTools::n_active_elem_of_type(the_mesh, PYRAMID5)
00119            << ' '
00120            << (MeshTools::n_active_elem_of_type(the_mesh, PRISM6) +
00121                MeshTools::n_active_elem_of_type(the_mesh, PRISM18)*8)
00122            << ' '
00123            << (MeshTools::n_active_elem_of_type(the_mesh, HEX8)  +
00124                MeshTools::n_active_elem_of_type(the_mesh, HEX20) +
00125                MeshTools::n_active_elem_of_type(the_mesh, HEX27)*8)
00126            << ' '
00127            << '\n';
00128 
00129   boundary_mesh.clear();
00130 
00131 
00135   for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
00136     the_mesh.point(v).write_unformatted(out_file);
00137 
00138 
00142   {
00146     for(unsigned int e=0; e<the_mesh.n_elem(); e++)
00147       if (the_mesh.elem(e)->active())
00148         for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
00149           if (the_mesh.elem(e)->neighbor(s) == NULL)
00150             {
00151               const AutoPtr<Elem> side(the_mesh.elem(e)->build_side(s));
00152 
00153               if (side->type() == TRI3)
00154                 {
00155                   out_file << side->node(0)+1 << " "
00156                            << side->node(1)+1 << " "
00157                            << side->node(2)+1 << '\n';
00158                 }
00159               else if (side->type() == TRI6)
00160                 {
00161                   out_file << side->node(0)+1 << " "
00162                            << side->node(3)+1 << " "
00163                            << side->node(5)+1 << '\n'
00164 
00165                            << side->node(3)+1 << " "
00166                            << side->node(1)+1 << " "
00167                            << side->node(4)+1 << '\n'
00168 
00169                            << side->node(5)+1 << " "
00170                            << side->node(4)+1 << " "
00171                            << side->node(2)+1 << '\n'
00172 
00173                            << side->node(3)+1 << " "
00174                            << side->node(4)+1 << " "
00175                            << side->node(5)+1 << '\n';
00176                 }
00177             }
00178 
00179 
00183     for(unsigned int e=0; e<the_mesh.n_elem(); e++)
00184       if (the_mesh.elem(e)->active())
00185         for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
00186           if (the_mesh.elem(e)->neighbor(s) == NULL)
00187             {
00188               const AutoPtr<Elem> side(the_mesh.elem(e)->build_side(s));
00189 
00190               if ((side->type() == QUAD4) ||
00191                   (side->type() == QUAD8)  )
00192                 {
00193                   out_file << side->node(0)+1 << " "
00194                            << side->node(1)+1 << " "
00195                            << side->node(2)+1 << " "
00196                            << side->node(3)+1 << '\n';
00197                 }
00198               else if (side->type() == QUAD9)
00199                 {
00200                   out_file << side->node(0)+1 << " "
00201                            << side->node(4)+1 << " "
00202                            << side->node(8)+1 << " "
00203                            << side->node(7)+1 << '\n'
00204 
00205                            << side->node(4)+1 << " "
00206                            << side->node(1)+1 << " "
00207                            << side->node(5)+1 << " "
00208                            << side->node(8)+1 << '\n'
00209 
00210                            << side->node(7)+1 << " "
00211                            << side->node(8)+1 << " "
00212                            << side->node(6)+1 << " "
00213                            << side->node(3)+1 << '\n'
00214 
00215                            << side->node(8)+1 << " "
00216                            << side->node(5)+1 << " "
00217                            << side->node(2)+1 << " "
00218                            << side->node(6)+1 << '\n';
00219                 }
00220             }
00221   }
00222 
00223 
00224 
00228   {
00232     for(unsigned int e=0; e<the_mesh.n_elem(); e++)
00233       if (the_mesh.elem(e)->active())
00234         for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
00235           if (the_mesh.elem(e)->neighbor(s) == NULL)
00236             {
00237               const AutoPtr<Elem> side(the_mesh.elem(e)->build_side(s));
00238 
00239               if ((side->type() == TRI3) ||
00240                   (side->type() == TRI6)  )
00241 
00242                 out_file << the_mesh.boundary_info->boundary_id(the_mesh.elem(e), s)
00243                          << '\n';
00244             }
00245 
00246 
00250     for(unsigned int e=0; e<the_mesh.n_elem(); e++)
00251       if (the_mesh.elem(e)->active())
00252         for (unsigned int s=0; s<the_mesh.elem(e)->n_sides(); s++)
00253           if (the_mesh.elem(e)->neighbor(s) == NULL)
00254             {
00255               const AutoPtr<Elem> side(the_mesh.elem(e)->build_side(s));
00256 
00257               if ((side->type() == QUAD4) ||
00258                   (side->type() == QUAD8) ||
00259                   (side->type() == QUAD9))
00260 
00261                 out_file << the_mesh.boundary_info->boundary_id(the_mesh.elem(e), s);
00262             }
00263   }
00264 
00265 
00266 
00270   for (unsigned int e=0; e<the_mesh.n_elem(); e++)
00271     if (the_mesh.elem(e)->active())
00272       {
00273         if (the_mesh.elem(e)->type() == TET4)
00274           {
00275             out_file << the_mesh.elem(e)->node(0)+1 << " "
00276                      << the_mesh.elem(e)->node(1)+1 << " "
00277                      << the_mesh.elem(e)->node(2)+1 << " "
00278                      << the_mesh.elem(e)->node(3)+1 << '\n';
00279           }
00280         else if (the_mesh.elem(e)->type() == TET10)
00281           {
00282             out_file << the_mesh.elem(e)->node(0)+1 << " "
00283                      << the_mesh.elem(e)->node(4)+1 << " "
00284                      << the_mesh.elem(e)->node(6)+1 << " "
00285                      << the_mesh.elem(e)->node(7)+1 << '\n';
00286 
00287             out_file << the_mesh.elem(e)->node(4)+1 << " "
00288                      << the_mesh.elem(e)->node(1)+1 << " "
00289                      << the_mesh.elem(e)->node(5)+1 << " "
00290                      << the_mesh.elem(e)->node(8)+1 << '\n';
00291 
00292             out_file << the_mesh.elem(e)->node(6)+1 << " "
00293                      << the_mesh.elem(e)->node(5)+1 << " "
00294                      << the_mesh.elem(e)->node(2)+1 << " "
00295                      << the_mesh.elem(e)->node(9)+1 << '\n';
00296 
00297             out_file << the_mesh.elem(e)->node(7)+1 << " "
00298                      << the_mesh.elem(e)->node(8)+1 << " "
00299                      << the_mesh.elem(e)->node(9)+1 << " "
00300                      << the_mesh.elem(e)->node(3)+1 << '\n';
00301 
00302             out_file << the_mesh.elem(e)->node(4)+1 << " "
00303                      << the_mesh.elem(e)->node(8)+1 << " "
00304                      << the_mesh.elem(e)->node(6)+1 << " "
00305                      << the_mesh.elem(e)->node(7)+1 << '\n';
00306 
00307             out_file << the_mesh.elem(e)->node(4)+1 << " "
00308                      << the_mesh.elem(e)->node(5)+1 << " "
00309                      << the_mesh.elem(e)->node(6)+1 << " "
00310                      << the_mesh.elem(e)->node(8)+1 << '\n';
00311 
00312             out_file << the_mesh.elem(e)->node(6)+1 << " "
00313                      << the_mesh.elem(e)->node(5)+1 << " "
00314                      << the_mesh.elem(e)->node(9)+1 << " "
00315                      << the_mesh.elem(e)->node(8)+1 << '\n';
00316 
00317             out_file << the_mesh.elem(e)->node(6)+1 << " "
00318                      << the_mesh.elem(e)->node(8)+1 << " "
00319                      << the_mesh.elem(e)->node(9)+1 << " "
00320                      << the_mesh.elem(e)->node(7)+1 << '\n';
00321           }
00322       }
00323 
00324 
00328   for (unsigned int e=0; e<the_mesh.n_elem(); e++)
00329     if (the_mesh.elem(e)->active())
00330       if (the_mesh.elem(e)->type() == PYRAMID5)
00331         {
00332           out_file << the_mesh.elem(e)->node(0)+1 << " "
00333                    << the_mesh.elem(e)->node(1)+1 << " "
00334                    << the_mesh.elem(e)->node(2)+1 << " "
00335                    << the_mesh.elem(e)->node(3)+1 << " "
00336                    << the_mesh.elem(e)->node(4)+1 << '\n';
00337         }
00338 
00339 
00340 
00344   for (unsigned int e=0; e<the_mesh.n_elem(); e++)
00345     if (the_mesh.elem(e)->active())
00346       {
00347         if (the_mesh.elem(e)->type() == PRISM6)
00348           {
00349             out_file << the_mesh.elem(e)->node(0)+1 << " "
00350                      << the_mesh.elem(e)->node(1)+1 << " "
00351                      << the_mesh.elem(e)->node(2)+1 << " "
00352                      << the_mesh.elem(e)->node(3)+1 << " "
00353                      << the_mesh.elem(e)->node(4)+1 << " "
00354                      << the_mesh.elem(e)->node(5)+1 << '\n';
00355           }
00356         else if (the_mesh.elem(e)->type() == PRISM18)
00357           {
00358             libmesh_error();
00359           }
00360       }
00361 
00362 
00366   for (unsigned int e=0; e<the_mesh.n_elem(); e++)
00367     if (the_mesh.elem(e)->active())
00368       if ((the_mesh.elem(e)->type() == HEX8)   ||
00369           (the_mesh.elem(e)->type() == HEX20) ||
00370           (the_mesh.elem(e)->type() == HEX27)   )
00371         {
00372           std::vector<dof_id_type> conn;
00373           for (unsigned int se=0; se<the_mesh.elem(e)->n_sub_elem(); se++)
00374             {
00375               the_mesh.elem(e)->connectivity(se, TECPLOT, conn);
00376 
00377               out_file << conn[0] << ' '
00378                        << conn[1] << ' '
00379                        << conn[2] << ' '
00380                        << conn[3] << ' '
00381                        << conn[4] << ' '
00382                        << conn[5] << ' '
00383                        << conn[6] << ' '
00384                        << conn[7] << '\n';
00385             }
00386         }
00387 }


Member Data Documentation

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format [protected, inherited]

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

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


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

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:14 UTC

Hosted By:
SourceForge.net Logo