Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : #ifndef LIBMESH_MATLAB_IO_H 20 : #define LIBMESH_MATLAB_IO_H 21 : 22 : // Local includes 23 : #include "libmesh/libmesh_common.h" 24 : #include "libmesh/mesh_input.h" 25 : 26 : // C++ includes 27 : 28 : namespace libMesh 29 : { 30 : 31 : // Forward declarations 32 : class MeshBase; 33 : 34 : /** 35 : * This class implements reading meshes in the Matlab PDE toolkit 36 : * in a proprietary format. 37 : * 38 : * A VALID INPUT FILE for this type of mesh should be 39 : * generated in Matlab with the following steps: 40 : * 1.) Draw the domain and triangulate it in the GUI 41 : * 2.) Export the mesh to matlab using Mesh->Export Mesh 42 : * 3.) Create a file with this script: 43 : * \code 44 : * fid = fopen('filename', 'w'); 45 : * fprintf(fid, '%d %d \n', length(p), length(t)); 46 : * fprintf(fid, '%f %f \n', p); 47 : * fprintf(fid, '%d %d %d %d \n', t); 48 : * fclose(fid); 49 : * \endcode 50 : * 51 : * What's going on here? 52 : * There is no standard for exporting PDE toolkit meshes 53 : * to files in Matlab. When you choose "export mesh" in the GUI, 54 : * it returns three matrices that it likes to call 55 : * p, e, and t. All meshes (as far as I can tell) that 56 : * come from the PDE toolkit are 2D triangle meshes. 57 : * 58 : * p is the point matrix... 59 : * Row 1: x coordinate 60 : * Row 2: y coordinate 61 : * 62 : * e is the edge matrix ... 63 : * Row 1: starting point number (dummy) 64 : * Row 2: ending point number (dummy) 65 : * Row 3: starting parameter value (?) (dummy) 66 : * Row 4: ending parameter value (?) (dummy) 67 : * Row 5: boundary segment number (?) (dummy) 68 : * Row 6: left-hand subdomain number (dummy) 69 : * Row 7: right-hand subdomain number (dummy) 70 : * 71 : * t is the triangle matrix ... 72 : * Row 1: Node number 1 73 : * Row 2: Node number 2 74 : * Row 3: Node number 3 75 : * Row 4: subdomain number (dummy) 76 : * 77 : * There are some important things to notice here: 78 : * o The implied ordering of the p matrix is 1..N 79 : * o The e matrix is entirely irrelevant in this code 80 : * o All of the matrices are row based 81 : * 82 : * \author John W. Peterson 83 : * \date 2004 84 : */ 85 : class MatlabIO : public MeshInput<MeshBase> 86 : { 87 : public: 88 : /** 89 : * Constructor. Takes a non-const Mesh reference which it 90 : * will fill up with elements. 91 : */ 92 : explicit 93 : MatlabIO (MeshBase &); 94 : 95 : /** 96 : * Reads in a matlab data file based on the string 97 : * you pass it. 98 : */ 99 : virtual void read (const std::string & name) override; 100 : 101 : private: 102 : /** 103 : * Implementation of the read() function. This function 104 : * is called by the public interface function and implements 105 : * reading the file. 106 : */ 107 : void read_stream (std::istream & in); 108 : }; 109 : 110 : 111 : // ------------------------------------------------------------ 112 : // MatlabIO inline members 113 : inline 114 0 : MatlabIO::MatlabIO (MeshBase & mesh_in) : 115 0 : MeshInput<MeshBase> (mesh_in) 116 0 : {} 117 : 118 : } // namespace libMesh 119 : 120 : 121 : #endif // LIBMESH_MATLAB_IO_H