Poster of Linux kernelThe best gift for a Linux geek
MatlabIO

MatlabIO

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

NAME

MatlabIO -  

SYNOPSIS


#include <matlab_io.h>

Inherits MeshInput< MeshBase >.  

Public Member Functions


MatlabIO (MeshBase &)

virtual void read (const std::string &name)
 

Protected Member Functions


MeshBase & mesh ()

void skip_comment_lines (std::istream &in, const char comment_start)
 

Private Member Functions


virtual void read_stream (std::istream &in)
 

Detailed Description

This class implements reading meshes in the Matlab PDE toolkit in a proprietary format.

A VALID INPUT FILE for this type of mesh should be generated in Matlab with the following steps: 1.) Draw the domain and triangulate it in the GUI 2.) Export the mesh to matlab using Mesh->Export Mesh 3.) Create a file with this script: fid = fopen('filename', 'w'); fprintf(fid, 'd d


What's going on here? There is no standard for exporting PDE toolkit meshes to files in Matlab. When you choose 'export mesh' in the GUI, it returns three matrices that it likes to call p, e, and t. All meshes (as far as I can tell) that come from the PDE toolkit are 2D triangle meshes.

p is the point matrix... Row 1: x coordinate Row 2: y coordinate

e is the edge matrix ... Row 1: starting point number (dummy) Row 2: ending point number (dummy) Row 3: starting parameter value (?) (dummy) Row 4: ending parameter value (?) (dummy) Row 5: boundary segment number (?) (dummy) Row 6: left-hand subdomain number (dummy) Row 7: right-hand subdomain number (dummy)

t is the triangle matrix ... Row 1: Node number 1 Row 2: Node number 2 Row 3: Node number 3 Row 4: subdomain number (dummy)

There are some important things to notice here: o The implied ordering of the p matrix is 1..N o The e matrix is entirely irrelevant in this code o All of the matrices are row based

Author:

John W. Peterson, 2004

Definition at line 86 of file matlab_io.h.  

Constructor & Destructor Documentation

 

MatlabIO::MatlabIO (MeshBase &mesh) [inline]Constructor. Takes a non-const Mesh reference which it will fill up with elements.

Definition at line 114 of file matlab_io.h.

                                  :
  MeshInput<MeshBase>  (mesh)
{}
 

Member Function Documentation

 

MeshBase & MeshInput< MeshBase >::mesh () [protected, inherited]Returns the object as a writeable reference.

Referenced by GMVIO::_read_materials(), GMVIO::_read_nodes(), GMVIO::_read_one_cell(), GMVIO::add_cell_centered_data(), GMVIO::copy_nodal_solution(), UNVIO::element_in(), TetGenIO::element_in(), UNVIO::element_out(), UNVIO::node_in(), TetGenIO::node_in(), UNVIO::node_out(), XdrIO::read(), VTKIO::read(), GMVIO::read(), ExodusII_IO::read(), LegacyXdrIO::read_ascii(), LegacyXdrIO::read_binary(), UCDIO::read_implementation(), LegacyXdrIO::read_mesh(), GmshIO::read_mesh(), XdrIO::read_serialized_bcs(), XdrIO::read_serialized_connectivity(), XdrIO::read_serialized_nodes(), OFFIO::read_stream(), read_stream(), VTKIO::solution_to_vtk(), XdrIO::write(), VTKIO::write(), TetGenIO::write(), GMVIO::write_ascii_new_impl(), GMVIO::write_ascii_old_impl(), GMVIO::write_binary(), GMVIO::write_discontinuous_gmv(), UNVIO::write_implementation(), UCDIO::write_implementation(), LegacyXdrIO::write_mesh(), GmshIO::write_mesh(), GmshIO::write_post(), XdrIO::write_serialized_bcs(), XdrIO::write_serialized_connectivity(), XdrIO::write_serialized_nodes(), and LegacyXdrIO::write_soln().  

void MatlabIO::read (const std::string &name) [virtual]Reads in a matlab data file based on the string you pass it.

Implements MeshInput< MeshBase >.

Definition at line 32 of file matlab_io.C.

References read_stream().

Referenced by UnstructuredMesh::read().

{
  std::ifstream in (name.c_str());

  this->read_stream(in);
}
 

void MatlabIO::read_stream (std::istream &in) [private, virtual]Implementation of the read() function. This function is called by the public interface function and implements reading the file.

Definition at line 40 of file matlab_io.C.

References MeshBase::add_elem(), MeshBase::add_point(), MeshBase::clear(), MeshInput< MeshBase >::mesh(), MeshBase::mesh_dimension(), MeshBase::node_ptr(), libMesh::processor_id(), DofObject::set_id(), and Elem::set_node().

Referenced by read().

{
  // This is a serial-only process for now;
  // the Mesh should be read on processor 0 and
  // broadcast later
  libmesh_assert(libMesh::processor_id() == 0);

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

  // Clear any existing mesh data
  mesh.clear();
  
  // PDE toolkit only works in 2D
  libmesh_assert(mesh.mesh_dimension() == 2);

  // Check the input buffer
  libmesh_assert (in.good());

  unsigned int nNodes=0, nElem=0;

  in >> nNodes   // Read the number of nodes
     >> nElem;   // Read the number of elements

  // Sort of check that it worked
  libmesh_assert(nNodes > 0);
  libmesh_assert(nElem > 0);

  // Read the nodal coordinates
  {
    Real x=0., y=0., z=0.;

    for (unsigned int i=0; i<nNodes; i++)
      {
        in >> x   // x-coordinate value
           >> y;  // y-coordinate value

        mesh.add_point ( Point(x,y,z), i);
      }
  }

  // Read the elements (elements)
  {
    unsigned int node=0, dummy=0;
    
    for (unsigned int i=0; i<nElem; i++)
      {
        Elem* elem = new Tri3; // Always build a triangle
        elem->set_id(i);
        mesh.add_elem (elem);
        
        for (unsigned int n=0; n<3; n++)  // Always read three 3 nodes
          {
            in >> node;
            elem->set_node(n) = mesh.node_ptr(node-1);  // Assign the node number
          }
        
        // There is an additional subdomain number here,
        // so we read it and get rid of it!
        in >> dummy;
      }
  }
  
}
 

void MeshInput< MeshBase >::skip_comment_lines (std::istream &in, const charcomment_start) [protected, inherited]Reads input from in, skipping all the lines that start with the character comment_start.

Referenced by TetGenIO::read(), and UCDIO::read_implementation().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Protected Member Functions
Private Member Functions
Detailed Description
Constructor & Destructor Documentation
MatlabIO::MatlabIO (MeshBase &mesh) [inline]Constructor. Takes a non-const Mesh reference which it will fill up with elements.
Member Function Documentation
MeshBase & MeshInput< MeshBase >::mesh () [protected, inherited]Returns the object as a writeable reference.
void MatlabIO::read (const std::string &name) [virtual]Reads in a matlab data file based on the string you pass it.
void MatlabIO::read_stream (std::istream &in) [private, virtual]Implementation of the read() function. This function is called by the public interface function and implements reading the file.
void MeshInput< MeshBase >::skip_comment_lines (std::istream &in, const charcomment_start) [protected, inherited]Reads input from in, skipping all the lines that start with the character comment_start.
Author

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