libMesh::MatlabIO Class Reference
#include <matlab_io.h>

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) |
Protected Attributes | |
| std::vector< bool > | elems_of_dimension |
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
', length(p), length(t)); fprintf(fid, 'f f
', p); fprintf(fid, 'd d d d
', t); fclose(fid);
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
Definition at line 89 of file matlab_io.h.
Constructor & Destructor Documentation
| libMesh::MatlabIO::MatlabIO | ( | MeshBase & | mesh_in | ) | [inline, explicit] |
Constructor. Takes a non-const Mesh reference which it will fill up with elements.
Definition at line 118 of file matlab_io.h.
Member Function Documentation
| MeshBase & libMesh::MeshInput< MeshBase >::mesh | ( | ) | [protected, inherited] |
Returns the object as a writeable reference.
Referenced by libMesh::GMVIO::_read_materials(), libMesh::GMVIO::_read_nodes(), libMesh::GMVIO::_read_one_cell(), libMesh::AbaqusIO::assign_boundary_node_ids(), libMesh::AbaqusIO::assign_sideset_ids(), libMesh::AbaqusIO::assign_subdomain_ids(), libMesh::VTKIO::cells_to_vtk(), libMesh::GMVIO::copy_nodal_solution(), libMesh::UNVIO::element_in(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::element_out(), libMesh::UNVIO::node_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::node_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::XdrIO::read(), libMesh::VTKIO::read(), libMesh::TetGenIO::read(), libMesh::Nemesis_IO::read(), libMesh::GMVIO::read(), libMesh::ExodusII_IO::read(), libMesh::AbaqusIO::read(), libMesh::LegacyXdrIO::read_ascii(), libMesh::AbaqusIO::read_elements(), libMesh::UNVIO::read_implementation(), libMesh::UCDIO::read_implementation(), libMesh::LegacyXdrIO::read_mesh(), libMesh::GmshIO::read_mesh(), libMesh::AbaqusIO::read_nodes(), libMesh::XdrIO::read_serialized_bcs(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::OFFIO::read_stream(), read_stream(), libMesh::XdrIO::write(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::UNVIO::write_implementation(), libMesh::UCDIO::write_implementation(), libMesh::LegacyXdrIO::write_mesh(), libMesh::GmshIO::write_mesh(), libMesh::UCDIO::write_nodal_data(), libMesh::Nemesis_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::LegacyXdrIO::write_soln().
| void libMesh::MatlabIO::read | ( | const std::string & | name | ) | [virtual] |
Reads in a matlab data file based on the string you pass it.
Implements libMesh::MeshInput< MeshBase >.
Definition at line 33 of file matlab_io.C.
References read_stream().
00034 { 00035 std::ifstream in (name.c_str()); 00036 00037 this->read_stream(in); 00038 }
| void libMesh::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 41 of file matlab_io.C.
References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::MeshBase::clear(), libMesh::err, libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::node_ptr(), libMesh::processor_id(), libMesh::Real, libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), and libMesh::Elem::set_node().
Referenced by read().
00042 { 00043 // This is a serial-only process for now; 00044 // the Mesh should be read on processor 0 and 00045 // broadcast later 00046 libmesh_assert_equal_to (libMesh::processor_id(), 0); 00047 00048 // Get a reference to the mesh 00049 MeshBase& the_mesh = MeshInput<MeshBase>::mesh(); 00050 00051 // Clear any existing mesh data 00052 the_mesh.clear(); 00053 00054 // PDE toolkit only works in 2D 00055 the_mesh.set_mesh_dimension(2); 00056 00057 #if LIBMESH_DIM < 2 00058 libMesh::err << "Cannot open dimension 2 mesh file when configured without 2D support." << 00059 std::endl; 00060 libmesh_error(); 00061 #endif 00062 00063 // Check the input buffer 00064 libmesh_assert (in.good()); 00065 00066 unsigned int nNodes=0, nElem=0; 00067 00068 in >> nNodes // Read the number of nodes 00069 >> nElem; // Read the number of elements 00070 00071 // Sort of check that it worked 00072 libmesh_assert_greater (nNodes, 0); 00073 libmesh_assert_greater (nElem, 0); 00074 00075 // Read the nodal coordinates 00076 { 00077 Real x=0., y=0., z=0.; 00078 00079 for (unsigned int i=0; i<nNodes; i++) 00080 { 00081 in >> x // x-coordinate value 00082 >> y; // y-coordinate value 00083 00084 the_mesh.add_point ( Point(x,y,z), i); 00085 } 00086 } 00087 00088 // Read the elements (elements) 00089 { 00090 unsigned int node=0, dummy=0; 00091 00092 for (unsigned int i=0; i<nElem; i++) 00093 { 00094 Elem* elem = new Tri3; // Always build a triangle 00095 elem->set_id(i); 00096 the_mesh.add_elem (elem); 00097 00098 for (unsigned int n=0; n<3; n++) // Always read three 3 nodes 00099 { 00100 in >> node; 00101 elem->set_node(n) = the_mesh.node_ptr(node-1); // Assign the node number 00102 } 00103 00104 // There is an additional subdomain number here, 00105 // so we read it and get rid of it! 00106 in >> dummy; 00107 } 00108 } 00109 00110 }
| void libMesh::MeshInput< MeshBase >::skip_comment_lines | ( | std::istream & | in, | |
| const char | comment_start | |||
| ) | [protected, inherited] |
Reads input from in, skipping all the lines that start with the character comment_start.
Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().
Member Data Documentation
std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension [protected, inherited] |
A vector of bools describing what dimension elements have been encountered when reading a mesh.
Definition at line 93 of file mesh_input.h.
Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::UNVIO::element_in(), libMesh::VTKIO::read(), libMesh::Nemesis_IO::read(), libMesh::GMVIO::read(), libMesh::ExodusII_IO::read(), libMesh::UNVIO::read_implementation(), libMesh::UCDIO::read_implementation(), libMesh::LegacyXdrIO::read_mesh(), and libMesh::XdrIO::read_serialized_connectivity().
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: