libMesh::MEDITIO Class Reference

#include <medit_io.h>

Inheritance diagram for libMesh::MEDITIO:

List of all members.

Public Member Functions

 MEDITIO (const MeshBase &)
 MEDITIO (const MeshBase &, unsigned int c)
virtual void write (const std::string &)
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
bool & binary ()
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=NULL)
unsigned int & ascii_precision ()

Protected Member Functions

const MeshBasemesh () const

Protected Attributes

const bool _is_parallel_format

Private Member Functions

virtual void write_ascii (const std::string &, const std::vector< Number > *=NULL, const std::vector< std::string > *=NULL)

Private Attributes

bool _binary
unsigned int scalar_idx

Detailed Description

This class implements writing meshes in the mesh format used by the MEdit visualization tool developed in the Gamma Project at INRIA Roquencourt. For a full description of the mesh format and to obtain the MEdit software see the MEdit home page.

Author:
F. Prill, 2004

Definition at line 51 of file medit_io.h.


Constructor & Destructor Documentation

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

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

Definition at line 111 of file medit_io.h.

00111                                          :
00112   MeshOutput<MeshBase> (mesh_in),
00113   _binary (false)
00114 {
00115 }

libMesh::MEDITIO::MEDITIO ( const MeshBase mesh_in,
unsigned int  c 
) [inline]

Constructor. Takes a reference to a constant mesh object. and the desired scalar index for mesh colouring. MEdit seems to understand only one scalar value.

Definition at line 118 of file medit_io.h.

00118                                                          :
00119   MeshOutput<MeshBase> (mesh_in),
00120   _binary    (false),
00121   scalar_idx (c)
00122 {
00123 }


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::MEDITIO::binary (  )  [inline]

Flag indicating whether or not to write a binary file

Definition at line 127 of file medit_io.h.

References _binary.

Referenced by write(), and write_nodal_data().

00128 {
00129   return _binary;
00130 }

void libMesh::MEDITIO::write ( const std::string &  fname  )  [virtual]

This method implements writing a mesh to a specified ".mesh" file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 37 of file medit_io.C.

References binary(), libMesh::processor_id(), and write_ascii().

00038 {
00039   if (libMesh::processor_id() == 0)
00040     if (!this->binary())
00041       this->write_ascii  (fname);
00042 }

void libMesh::MEDITIO::write_ascii ( const std::string &  fname,
const std::vector< Number > *  vec = NULL,
const std::vector< std::string > *  solution_names = NULL 
) [private, virtual]

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

Definition at line 61 of file medit_io.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, libMesh::MeshTools::Generation::Private::idx(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::MeshBase::n_nodes(), n_vars, libMesh::MeshBase::point(), libMeshEnums::QUAD4, libMeshEnums::QUAD9, scalar_idx, libMeshEnums::TET4, and libMeshEnums::TRI3.

Referenced by write(), and write_nodal_data().

00064 {
00065   // Current lacks in implementation:
00066   //  (i)   only 3D meshes.
00067   //  (ii)  only QUAD4, TRI3, TET4 elements, others are omitted !
00068   //  (iii) no distinction between materials.
00069   //  (iv)  no vector output, just first scalar as output
00070 
00071   // libmesh_assert three dimensions (should be extended later)
00072   libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().mesh_dimension(), 3);
00073 
00074   // Open the output file stream
00075   std::ofstream out_stream (fname.c_str());
00076 
00077   // Make sure it opened correctly
00078   if (!out_stream.good())
00079     libmesh_file_error(fname.c_str());
00080 
00081   // Get a reference to the mesh
00082   const MeshBase& the_mesh = MeshOutput<MeshBase>::mesh();
00083 
00084   // Begin interfacing with the MEdit data file
00085   {
00086     // header:
00087     out_stream << "MeshVersionFormatted  1\n";
00088     out_stream << "Dimension  3\n";
00089     out_stream << "# Mesh generated by libmesh\n\n";
00090 
00091     // write the nodes:
00092     out_stream << "# Set of mesh vertices\n";
00093     out_stream << "Vertices\n";
00094     out_stream << the_mesh.n_nodes() << "\n";
00095 
00096     for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
00097       out_stream << the_mesh.point(v)(0) << " " << the_mesh.point(v)(1) << " " << the_mesh.point(v)(2) << " 0\n";
00098   }
00099 
00100   {
00101     // write the connectivity:
00102     out_stream << "\n# Set of Polys\n\n";
00103 
00104     // count occurrences of output elements:
00105     int n_tri3  = 0;
00106     int n_quad4 = 0;
00107     int n_tet4  = 0;
00108 
00109     {
00110       MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
00111       const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
00112 
00113       for ( ; it != end; ++it)
00114         {
00115           if ((*it)->type() == TRI3)  n_tri3++;
00116           if ((*it)->type() == QUAD4) n_quad4++;
00117           if ((*it)->type() == QUAD9) n_quad4+=4; // (QUAD9 is written as 4 QUAD4.)
00118           if ((*it)->type() == TET4)  n_tet4++;
00119         } // for
00120     }
00121 
00122     // First: write out TRI3 elements:
00123     out_stream << "Triangles\n";
00124     out_stream << n_tri3 << "\n";
00125 
00126     {
00127       MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
00128       const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
00129 
00130       for ( ; it != end; ++it)
00131         if ((*it)->type() == TRI3)
00132           out_stream << (*it)->node(0)+1  << " " << (*it)->node(1)+1  << " " << (*it)->node(2)+1  << " 0\n";
00133     }
00134 
00135     // Second: write out QUAD4 elements:
00136     out_stream << "Quadrilaterals\n";
00137     out_stream << n_quad4 << "\n";
00138 
00139     {
00140       MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
00141       const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
00142 
00143       for ( ; it != end; ++it)
00144         if ((*it)->type() == QUAD4)
00145           {
00146             out_stream << (*it)->node(0)+1  << " "
00147                 << (*it)->node(1)+1  << " "
00148                 << (*it)->node(2)+1  << " "
00149                 << (*it)->node(3)+1  <<" 0\n";
00150           } // if
00151         else if ((*it)->type() == QUAD9)
00152           {
00153             out_stream << (*it)->node(0)+1  << " "
00154                 << (*it)->node(4)+1  << " "
00155                 << (*it)->node(8)+1  << " "
00156                 << (*it)->node(7)+1  <<" 0\n";
00157             out_stream << (*it)->node(7)+1  << " "
00158                 << (*it)->node(8)+1  << " "
00159                 << (*it)->node(6)+1  << " "
00160                 << (*it)->node(3)+1  <<" 0\n";
00161             out_stream << (*it)->node(4)+1  << " "
00162                 << (*it)->node(1)+1  << " "
00163                 << (*it)->node(5)+1  << " "
00164                 << (*it)->node(8)+1  <<" 0\n";
00165             out_stream << (*it)->node(8)+1  << " "
00166                 << (*it)->node(5)+1  << " "
00167                 << (*it)->node(2)+1  << " "
00168                 << (*it)->node(6)+1  <<" 0\n";
00169           } // if
00170     }
00171 
00172 
00173     // Third: write out TET4 elements:
00174     out_stream << "Tetrahedra\n";
00175     out_stream << n_tet4 << "\n";
00176 
00177     {
00178       MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
00179       const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
00180 
00181       for ( ; it != end; ++it)
00182         if ((*it)->type() == TET4)
00183           {
00184             out_stream << (*it)->node(0)+1  << " "
00185                 << (*it)->node(1)+1  << " "
00186                 << (*it)->node(2)+1  << " "
00187                 << (*it)->node(3)+1  <<" 0\n";
00188           } // if
00189     }
00190 
00191   }
00192   // end of the out file
00193   out_stream << '\n' << "# end of file\n";
00194 
00195   // optionally write the data
00196   if ((solution_names != NULL) &&
00197       (vec != NULL))
00198     {
00199       // Open the ".bb" file stream
00200       std::size_t idx = fname.find_last_of(".");
00201       std::string bbname = fname.substr(0,idx) + ".bb";
00202 
00203       std::ofstream bbout (bbname.c_str());
00204 
00205       // Make sure it opened correctly
00206       if (!bbout.good())
00207         libmesh_file_error(bbname.c_str());
00208 
00209       // Header: 3: 3D mesh, 1: scalar output, 2: node-indexed
00210       const std::size_t n_vars = solution_names->size();
00211       bbout << "3 1 " << the_mesh.n_nodes() << " 2\n";
00212       for (dof_id_type n=0; n<the_mesh.n_nodes(); n++)
00213         bbout << std::setprecision(10) << (*vec)[n*n_vars + scalar_idx] << " ";
00214       bbout << "\n";
00215     } // endif
00216 }

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

void libMesh::MEDITIO::write_nodal_data ( const std::string &  fname,
const std::vector< Number > &  soln,
const std::vector< std::string > &  names 
) [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 46 of file medit_io.C.

References binary(), libMesh::processor_id(), and write_ascii().

00049 {
00050   START_LOG("write_nodal_data()", "MEDITIO");
00051 
00052   if (libMesh::processor_id() == 0)
00053     if (!this->binary())
00054       this->write_ascii  (fname, &soln, &names);
00055 
00056   STOP_LOG("write_nodal_data()", "MEDITIO");
00057 }


Member Data Documentation

bool libMesh::MEDITIO::_binary [private]

Flag to write binary data.

Definition at line 101 of file medit_io.h.

Referenced by binary().

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 libMesh::DivaIO::write().

unsigned int libMesh::MEDITIO::scalar_idx [private]

Definition at line 103 of file medit_io.h.

Referenced by write_ascii().


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

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

Hosted By:
SourceForge.net Logo