$extrastylesheet
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.

                                         :
  MeshOutput<MeshBase> (mesh_in),
  _binary (false),
  scalar_idx (0)
{
}
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 119 of file medit_io.h.

                                                         :
  MeshOutput<MeshBase> (mesh_in),
  _binary    (false),
  scalar_idx (c)
{
}

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 128 of file medit_io.h.

References _binary.

Referenced by write(), and write_nodal_data().

{
  return _binary;
}
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::MeshOutput< MeshBase >::mesh(), libMesh::processor_id(), and write_ascii().

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

{
  if (this->mesh().processor_id() == 0)
    if (!this->binary())
      this->write_ascii  (fname);
}
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(), libMesh::QUAD4, libMesh::QUAD9, scalar_idx, libMesh::TET4, and libMesh::TRI3.

Referenced by write(), and write_nodal_data().

{
  // Current lacks in implementation:
  //  (i)   only 3D meshes.
  //  (ii)  only QUAD4, TRI3, TET4 elements, others are omitted !
  //  (iii) no distinction between materials.
  //  (iv)  no vector output, just first scalar as output

  // libmesh_assert three dimensions (should be extended later)
  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().mesh_dimension(), 3);

  // Open the output file stream
  std::ofstream out_stream (fname.c_str());

  // Make sure it opened correctly
  if (!out_stream.good())
    libmesh_file_error(fname.c_str());

  // Get a reference to the mesh
  const MeshBase& the_mesh = MeshOutput<MeshBase>::mesh();

  // Begin interfacing with the MEdit data file
  {
    // header:
    out_stream << "MeshVersionFormatted  1\n";
    out_stream << "Dimension  3\n";
    out_stream << "# Mesh generated by libmesh\n\n";

    // write the nodes:
    out_stream << "# Set of mesh vertices\n";
    out_stream << "Vertices\n";
    out_stream << the_mesh.n_nodes() << "\n";

    for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
      out_stream << the_mesh.point(v)(0) << " " << the_mesh.point(v)(1) << " " << the_mesh.point(v)(2) << " 0\n";
  }

  {
    // write the connectivity:
    out_stream << "\n# Set of Polys\n\n";

    // count occurrences of output elements:
    int n_tri3  = 0;
    int n_quad4 = 0;
    int n_tet4  = 0;

    {
      MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = the_mesh.active_elements_end();

      for ( ; it != end; ++it)
        {
          if ((*it)->type() == TRI3)  n_tri3++;
          if ((*it)->type() == QUAD4) n_quad4++;
          if ((*it)->type() == QUAD9) n_quad4+=4; // (QUAD9 is written as 4 QUAD4.)
          if ((*it)->type() == TET4)  n_tet4++;
        } // for
    }

    // First: write out TRI3 elements:
    out_stream << "Triangles\n";
    out_stream << n_tri3 << "\n";

    {
      MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = the_mesh.active_elements_end();

      for ( ; it != end; ++it)
        if ((*it)->type() == TRI3)
          out_stream << (*it)->node(0)+1  << " " << (*it)->node(1)+1  << " " << (*it)->node(2)+1  << " 0\n";
    }

    // Second: write out QUAD4 elements:
    out_stream << "Quadrilaterals\n";
    out_stream << n_quad4 << "\n";

    {
      MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = the_mesh.active_elements_end();

      for ( ; it != end; ++it)
        if ((*it)->type() == QUAD4)
          {
            out_stream << (*it)->node(0)+1  << " "
                       << (*it)->node(1)+1  << " "
                       << (*it)->node(2)+1  << " "
                       << (*it)->node(3)+1  <<" 0\n";
          } // if
        else if ((*it)->type() == QUAD9)
          {
            out_stream << (*it)->node(0)+1  << " "
                       << (*it)->node(4)+1  << " "
                       << (*it)->node(8)+1  << " "
                       << (*it)->node(7)+1  <<" 0\n";
            out_stream << (*it)->node(7)+1  << " "
                       << (*it)->node(8)+1  << " "
                       << (*it)->node(6)+1  << " "
                       << (*it)->node(3)+1  <<" 0\n";
            out_stream << (*it)->node(4)+1  << " "
                       << (*it)->node(1)+1  << " "
                       << (*it)->node(5)+1  << " "
                       << (*it)->node(8)+1  <<" 0\n";
            out_stream << (*it)->node(8)+1  << " "
                       << (*it)->node(5)+1  << " "
                       << (*it)->node(2)+1  << " "
                       << (*it)->node(6)+1  <<" 0\n";
          } // if
    }


    // Third: write out TET4 elements:
    out_stream << "Tetrahedra\n";
    out_stream << n_tet4 << "\n";

    {
      MeshBase::const_element_iterator       it  = the_mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = the_mesh.active_elements_end();

      for ( ; it != end; ++it)
        if ((*it)->type() == TET4)
          {
            out_stream << (*it)->node(0)+1  << " "
                       << (*it)->node(1)+1  << " "
                       << (*it)->node(2)+1  << " "
                       << (*it)->node(3)+1  <<" 0\n";
          } // if
    }

  }
  // end of the out file
  out_stream << '\n' << "# end of file\n";

  // optionally write the data
  if ((solution_names != NULL) &&
      (vec != NULL))
    {
      // Open the ".bb" file stream
      std::size_t idx = fname.find_last_of(".");
      std::string bbname = fname.substr(0,idx) + ".bb";

      std::ofstream bbout (bbname.c_str());

      // Make sure it opened correctly
      if (!bbout.good())
        libmesh_file_error(bbname.c_str());

      // Header: 3: 3D mesh, 1: scalar output, 2: node-indexed
      const std::size_t n_vars = solution_names->size();
      bbout << "3 1 " << the_mesh.n_nodes() << " 2\n";
      for (dof_id_type n=0; n<the_mesh.n_nodes(); n++)
        bbout << std::setprecision(10) << (*vec)[n*n_vars + scalar_idx] << " ";
      bbout << "\n";
    } // endif
}
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.

Reimplemented in libMesh::NameBasedIO.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_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::MeshOutput< MeshBase >::mesh(), libMesh::processor_id(), libMesh::START_LOG(), and write_ascii().

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

{
  START_LOG("write_nodal_data()", "MEDITIO");

  if (this->mesh().processor_id() == 0)
    if (!this->binary())
      this->write_ascii  (fname, &soln, &names);

  STOP_LOG("write_nodal_data()", "MEDITIO");
}

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::FroIO::write(), libMesh::DivaIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::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: