Poster of Linux kernelThe best gift for a Linux geek
MEDITIO

MEDITIO

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

MEDITIO -  

SYNOPSIS


#include <medit_io.h>

Inherits MeshOutput< MeshBase >.  

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 &)
 

Protected Member Functions


const MeshBase & mesh () const
 

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

Constructor & Destructor Documentation

 

MEDITIO::MEDITIO (const MeshBase &mesh) [inline]Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.

Definition at line 106 of file medit_io.h.

                                      :
  MeshOutput<MeshBase> (mesh),
  _binary (false)
{
}
 

MEDITIO::MEDITIO (const MeshBase &mesh, unsigned intc) [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 113 of file medit_io.h.

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

Member Function Documentation

 

bool & MEDITIO::binary () [inline]Flag indicating whether or not to write a binary file

Definition at line 122 of file medit_io.h.

References _binary.

Referenced by write(), and write_nodal_data().

{
  return _binary;
}
 

const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.

Referenced by PostscriptIO::write(), FroIO::write(), write_ascii(), EnsightIO::write_geometry_ascii(), EnsightIO::write_scalar_ascii(), GnuPlotIO::write_solution(), DivaIO::write_stream(), and EnsightIO::write_vector_ascii().  

void MEDITIO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified '.mesh' file.

Implements MeshOutput< MeshBase >.

Definition at line 35 of file medit_io.C.

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

Referenced by UnstructuredMesh::write().

{
  if (libMesh::processor_id() == 0)
    if (!this->binary())
      this->write_ascii  (fname);
}
 

void 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 55 of file medit_io.C.

References MeshBase::active_elements_begin(), MeshBase::active_elements_end(), MeshTools::Generation::Private::idx(), MeshOutput< MeshBase >::mesh(), MeshBase::n_nodes(), MeshBase::point(), libMeshEnums::QUAD4, libMeshEnums::QUAD9, scalar_idx, libMeshEnums::TET4, and libMeshEnums::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 (MeshOutput<MeshBase>::mesh().mesh_dimension() == 3);

  // Open the output file stream
  std::ofstream out (fname.c_str());
  
  // Make sure it opened correctly
  if (!out.good())
    libmesh_file_error(fname.c_str());

  // Get a reference to the mesh
  const MeshBase& mesh = MeshOutput<MeshBase>::mesh();
  
  // Begin interfacing with the MEdit data file
  {
    // header:
    out << 'MeshVersionFormatted  1;
    out << 'Dimension  3;
    out << '# Mesh generated by libmeshn';

    // write the nodes:
    out << '# Set of mesh vertices;
    out << 'Vertices;
    out << mesh.n_nodes() << ';

    for (unsigned int v=0; v<mesh.n_nodes(); v++)
      out << mesh.point(v)(0) << ' ' << mesh.point(v)(1) << ' ' << mesh.point(v)(2) << ' 0;
  }

  {
    // write the connectivity:
    out << ' Set of Polysn';
    
    // count occurrences of output elements:
    int n_tri3  = 0;
    int n_quad4 = 0;
    int n_tet4  = 0;

    {
//       const_active_elem_iterator       it (mesh.elements_begin());
//       const const_active_elem_iterator end(mesh.elements_end());

      MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = 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 << 'Triangles;
    out << n_tri3 << ';

    {
//       const_active_elem_iterator       it (mesh.elements_begin());
//       const const_active_elem_iterator end(mesh.elements_end());

      MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = mesh.active_elements_end(); 
    
      for ( ; it != end; ++it) 
        if ((*it)->type() == TRI3)
          out << (*it)->node(0)+1  << ' ' << (*it)->node(1)+1  << ' ' << (*it)->node(2)+1  << ' 0;
    }
    
    // Second: write out QUAD4 elements:
    out << 'Quadrilaterals;
    out << n_quad4 << ';

    {
//       const_active_elem_iterator       it (mesh.elements_begin());
//       const const_active_elem_iterator end(mesh.elements_end());

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

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

    
    // Third: write out TET4 elements:
    out << 'Tetrahedra;
    out << n_tet4 << ';

    {
//       const_active_elem_iterator       it (mesh.elements_begin());
//       const const_active_elem_iterator end(mesh.elements_end());

      MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
      const MeshBase::const_element_iterator end = mesh.active_elements_end(); 
      
      for ( ; it != end; ++it) 
        if ((*it)->type() == TET4)
          {
            out << (*it)->node(0)+1  << ' ' 
                << (*it)->node(1)+1  << ' ' 
                << (*it)->node(2)+1  << ' ' 
                << (*it)->node(3)+1  <<' 0;
          } // if
    }
    
  }  
  // end of the out file
  out << ' << '# end of file;

  // optionally write the data
  if ((solution_names != NULL) &&
      (vec != NULL))
    {
      // Open the '.bb' file stream
      int 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 (!out.good())
        libmesh_file_error(bbname.c_str());

      // Header: 3: 3D mesh, 1: scalar output, 2: node-indexed 
      const unsigned int n_vars = solution_names->size();
      bbout << '3 1 ' << mesh.n_nodes() << ' 2;
      for (unsigned int n=0; n<mesh.n_nodes(); n++)
        bbout << std::setprecision(10) << (*vec)[n*n_vars + scalar_idx] << ' ';
      bbout << ';
    } // endif
}
 

virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [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 VTKIO.  

void 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 MeshOutput< MeshBase >.

Definition at line 44 of file medit_io.C.

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

{
  if (libMesh::processor_id() == 0)
    if (!this->binary())
      this->write_ascii  (fname, &soln, &names);
}
 

Member Data Documentation

 

bool MEDITIO::_binary [private]Flag to write binary data.

Definition at line 96 of file medit_io.h.

Referenced by binary().  

unsigned int MEDITIO::scalar_idx [private]

Definition at line 98 of file medit_io.h.

Referenced by write_ascii().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Protected Member Functions
Private Member Functions
Private Attributes
Detailed Description
Constructor & Destructor Documentation
MEDITIO::MEDITIO (const MeshBase &mesh) [inline]Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh.
MEDITIO::MEDITIO (const MeshBase &mesh, unsigned intc) [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.
Member Function Documentation
bool & MEDITIO::binary () [inline]Flag indicating whether or not to write a binary file
const MeshBase & MeshOutput< MeshBase >::mesh () const [protected, inherited]Returns the object as a read-only reference.
void MEDITIO::write (const std::string &fname) [virtual]This method implements writing a mesh to a specified '.mesh' file.
void 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.
virtual void MeshOutput< MeshBase >::write_equation_systems (const std::string &, const EquationSystems &) [virtual, inherited]This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.
void 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.
Member Data Documentation
bool MEDITIO::_binary [private]Flag to write binary data.
unsigned int MEDITIO::scalar_idx [private]
Author

This document was created by man2html, using the manual pages.
Time: 21:50:06 GMT, April 16, 2011