mesh_data_tetgen_support.C
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 // C++ includes 00021 #include <fstream> 00022 00023 // Local includes 00024 #include "libmesh/mesh_data.h" 00025 00026 namespace libMesh 00027 { 00028 00029 00030 00031 00032 //--------------------------------------------------------------------- 00033 // MeshDate TetGen support function 00034 void MeshData::read_tetgen (const std::string& name) 00035 { 00036 std::string name_node, name_ele, dummy; 00037 std::string desc = name; 00038 00039 00040 // Check name for *.node or *.ele extension. 00041 // Set std::istream for node_stream and ele_stream. 00042 if (name.rfind(".node") < name.size()) 00043 { 00044 name_node = name; 00045 dummy = name; 00046 std::size_t position = dummy.rfind(".node"); 00047 name_ele = dummy.replace(position, 5, ".ele"); 00048 desc.erase(position); 00049 } 00050 else if (name.rfind(".ele") < name.size()) 00051 { 00052 name_ele = name; 00053 dummy = name; 00054 std::size_t position = dummy.rfind(".ele"); 00055 name_node = dummy.replace(position, 4, ".node"); 00056 desc.erase(position); 00057 } 00058 else 00059 { 00060 libMesh::err << "ERROR: Unrecognized file name: " 00061 << name << std::endl; 00062 libmesh_error(); 00063 } 00064 00065 // Set the streams from which to read in. 00066 std::ifstream node_stream (name_node.c_str()); 00067 std::ifstream ele_stream (name_ele.c_str()); 00068 00069 if ( !node_stream.good() || !ele_stream.good() ) 00070 { 00071 libMesh::err << "ERROR: One or both Input file(s) not good." << std::endl 00072 << "Error checking files " 00073 << name_node << " and " 00074 << name_ele << std::endl; 00075 libmesh_error(); 00076 } 00077 00078 00079 // Set the descriptive name. 00080 // TetGen won't give a name, so we use the filename. 00081 this->_data_descriptor = desc; 00082 00083 00084 //-------------------------------------------------- 00085 // Read in the data associated with the nodes. 00086 { 00087 unsigned int n_node=0, f_n_id=0, nAttri=0, BoundMark=0; 00088 Real dummy_val=0.0; 00089 std::vector<Number> AttriValue; 00090 00091 // Read the parameters from the node_stream. 00092 node_stream >> n_node // Read the number of nodes 00093 >> dummy_val // Read the dimension 00094 >> nAttri // Read the number of attributes 00095 >> BoundMark; // (0 or 1) boundary markers are in the stream or not. 00096 00097 // Resize the values vector. 00098 AttriValue.resize(nAttri); 00099 00100 for (unsigned int i=0; i<n_node; i++) 00101 { 00102 node_stream >> f_n_id; 00103 00104 00105 // Read the nodal coordinates for this node into dummy_val, 00106 // since we don't need them. 00107 for (unsigned int j=0; j<3; j++) 00108 node_stream >> dummy_val; 00109 00110 // Read the attributes from the stream. 00111 for (unsigned int j=0; j<nAttri; j++) 00112 node_stream >> AttriValue[j]; 00113 00114 // Read boundary marker if BoundaryMarker=1. 00115 if (BoundMark == 1) 00116 node_stream >> dummy_val; 00117 00118 // For the foreign node id locate the Node*. 00119 const Node* node = foreign_id_to_node(f_n_id); 00120 00121 // Insert this node and the values in our _node_data. 00122 _node_data.insert (std::make_pair(node, AttriValue)); 00123 } 00124 } 00125 00126 00127 //-------------------------------------------------- 00128 // Read in the data associated with the elements. 00129 { 00130 unsigned int n_elem, f_e_id, n_nodes, nAttri=0; 00131 Real dummy_val=0.0; 00132 std::vector<Number> AttriValue; 00133 00134 // Read the parameters from the ele_stream. 00135 ele_stream >> n_elem // Read the number of tetrahedrons 00136 >> n_nodes // Read the points per tetrahedron 00137 >> nAttri; // Read the number of attributes 00138 00139 // Resize the values vector. 00140 AttriValue.resize(nAttri); 00141 00142 for (unsigned int i=0; i<n_elem; i++) 00143 { 00144 ele_stream >> f_e_id; 00145 00146 // For the number of nodes for this element read them into dummy_val, 00147 // since we don't need them. 00148 for (unsigned int n=0; n<n_nodes; n++) 00149 ele_stream >> dummy_val; 00150 00151 // Read the attributes from the stream. 00152 for (unsigned int j=0; j<nAttri; j++) 00153 ele_stream >> AttriValue[j]; 00154 00155 // For the foreign elem id locate the Elem*. 00156 const Elem* elem = foreign_id_to_elem(f_e_id); 00157 00158 // Insert this elem and the values in our _elem_data. 00159 _elem_data.insert (std::make_pair(elem, AttriValue)); 00160 } 00161 } 00162 00163 //-------------------------------------------------- 00164 // Finished reading. Now ready for use. 00165 this->_node_data_closed = true; 00166 this->_elem_data_closed = true; 00167 00168 node_stream.close(); 00169 ele_stream.close(); 00170 } 00171 00172 } // namespace libMesh
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: