MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Lawrence Livermore National Laboratory. Under 00005 the terms of Contract B545069 with the University of Wisconsin -- 00006 Madison, Lawrence Livermore National Laboratory retains certain 00007 rights in this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 [email protected] 00024 00025 ***************************************************************** */ 00026 00027 #ifndef MESQUITE_MESH_IMPL_DATA_HPP 00028 #define MESQUITE_MESH_IMPL_DATA_HPP 00029 00030 #include "Mesquite.hpp" 00031 #include "Vector3D.hpp" 00032 #include "MeshInterface.hpp" 00033 00034 #include <vector> 00035 #include <sys/types.h> 00036 00037 namespace MBMesquite 00038 { 00039 00040 class MsqError; 00041 00042 /** Class to store mesh representation for MeshImpl */ 00043 class MeshImplData 00044 { 00045 00046 public: 00047 MeshImplData() : haveSlavedFlags( false ) {} 00048 00049 /** Clear all data */ 00050 void clear(); 00051 00052 /** Get number of vertices, does not include mid-nodes */ 00053 size_t num_vertices() const; 00054 /** Get number of elements */ 00055 size_t num_elements() const; 00056 /** Get number of vertex uses (sum of connectivity length for all elements) 00057 * Does not count mid-nodes */ 00058 size_t num_vertex_uses() const; 00059 00060 size_t max_vertex_index() const 00061 { 00062 return vertexList.size(); 00063 } 00064 size_t max_element_index() const 00065 { 00066 return elementList.size(); 00067 } 00068 00069 /** Copy internal representation into CSR rep 00070 * Does not include mid-nodes. */ 00071 void copy_mesh( size_t* vertex_handle_array, 00072 size_t* element_hanlde_array, 00073 size_t* element_conn_offsets, 00074 size_t* element_conn_indices ); 00075 00076 /** Get all vertices, including mid-nodes */ 00077 void all_vertices( std::vector< size_t >& list, MsqError& err ) const; 00078 00079 /** Get all elements */ 00080 void all_elements( std::vector< size_t >& list, MsqError& err ) const; 00081 00082 /** Check if passed vertex index is valid */ 00083 inline bool is_vertex_valid( size_t index ) const 00084 { 00085 return index < vertexList.size() && vertexList[index].valid; 00086 } 00087 00088 /** Check if passed element index is valid */ 00089 inline bool is_element_valid( size_t index ) const 00090 { 00091 return index < elementList.size() && !elementList[index].connectivity.empty(); 00092 } 00093 00094 /** Check if the specified node is used as a mid-node on any element */ 00095 bool is_mid_node( size_t index ) const; 00096 /** Check if the specified node is used as a corner vertex on any element */ 00097 bool is_corner_node( size_t index ) const; 00098 00099 /** Get vertex coordinates */ 00100 const Vector3D& get_vertex_coords( size_t index, MsqError& err ) const; 00101 00102 /** Set vertex coordinates */ 00103 void set_vertex_coords( size_t index, const Vector3D& coords, MsqError& err ); 00104 00105 /** Get vertex fixed flag */ 00106 bool vertex_is_fixed( size_t index, MsqError& err ) const; 00107 00108 /** Get vertex slaved flag */ 00109 bool vertex_is_slaved( size_t index, MsqError& err ) const; 00110 00111 /** Set vertex fixed flag */ 00112 void fix_vertex( size_t index, bool flag, MsqError& err ); 00113 00114 /** Set vertex slaved flag */ 00115 void slave_vertex( size_t index, bool flag, MsqError& err ); 00116 00117 /** Get vertex byte */ 00118 unsigned char get_vertex_byte( size_t index, MsqError& err ) const; 00119 00120 /** Set vertex byte */ 00121 void set_vertex_byte( size_t index, unsigned char value, MsqError& err ); 00122 00123 /** Get element type */ 00124 EntityTopology element_topology( size_t index, MsqError& err ) const; 00125 00126 /** Set element type */ 00127 void element_topology( size_t index, EntityTopology type, MsqError& err ); 00128 00129 /** Get element connectivity list, including mid-nodes */ 00130 const std::vector< size_t >& element_connectivity( size_t index, MsqError& err ) const; 00131 00132 /** Get vertex adjacency list */ 00133 const std::vector< size_t >& vertex_adjacencies( size_t index, MsqError& err ) const; 00134 00135 /** Allocate space for specified number of vertices */ 00136 void allocate_vertices( size_t count, MsqError& err ); 00137 00138 /** Allocate space for specified number of elements */ 00139 void allocate_elements( size_t count, MsqError& err ); 00140 00141 /** Set allocated but unset veretx to specified values */ 00142 void reset_vertex( size_t index, const Vector3D& coords, bool fixed, MsqError& err ); 00143 00144 /** 00145 * Clear element at specified index (if any) including 00146 * connectivity and adjacency data, and re-initialize with 00147 * passed data. 00148 */ 00149 void reset_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err ); 00150 void reset_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err ); 00151 00152 /** Add a new vertex */ 00153 size_t add_vertex( const Vector3D& coords, bool fixed, MsqError& err ); 00154 /** Add a new element */ 00155 size_t add_element( const std::vector< long >& vertices, EntityTopology topology, MsqError& err ); 00156 size_t add_element( const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err ); 00157 00158 /** Delete a vertex - may not be referenced by any element */ 00159 void delete_vertex( size_t index, MsqError& err ); 00160 /** Delete an element */ 00161 void delete_element( size_t index, MsqError& err ); 00162 00163 /** Get all mid-nodes and their adjacent corner vertices */ 00164 void copy_higher_order( std::vector< size_t >& mid_nodes, 00165 std::vector< size_t >& vertices, 00166 std::vector< size_t >& vertex_indices, 00167 std::vector< size_t >& index_offsets, 00168 MsqError& err ); 00169 00170 /** \brief Get elements adjacent to ALL of the passed nodes. 00171 * 00172 * Return the list of elements that is the intersection of the 00173 * adjacency lists of the specified vertices. 00174 */ 00175 void get_adjacent_elements( std::vector< size_t >::const_iterator nodes, 00176 std::vector< size_t >::const_iterator nodes_end, 00177 std::vector< size_t >& elems_out, 00178 MsqError& err ); 00179 00180 /**\brief Skin mesh 00181 * 00182 * Get the boundary of a mesh as element sides 00183 * 00184 *\param sides Element sides as pairs of values : { elem_index, side_number } 00185 */ 00186 void skin( std::vector< size_t >& sides, MsqError& err ); 00187 00188 bool have_slaved_flags() const 00189 { 00190 return haveSlavedFlags; 00191 } 00192 00193 private: 00194 /**\brief helper function for skinning 00195 * 00196 * Check if any elements adjacent to a side of an element 00197 * are of the same dimension as the input element. 00198 *\param elem The element 00199 *\param nodes The nodes composing the side of the element 00200 */ 00201 bool has_adjacent_elements( size_t elem, const std::vector< size_t >& nodes, MsqError& err ); 00202 00203 /** Clear existing element data */ 00204 void clear_element( size_t index, MsqError& err ); 00205 00206 /** Set cleared element */ 00207 void set_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err ); 00208 00209 /** Set cleared element */ 00210 void set_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err ); 00211 00212 /** Struct holding a vertex */ 00213 struct Vertex 00214 { 00215 Vertex( const Vector3D& pos, bool is_fixed ) 00216 : coords( pos ), midcount( 0 ), fixed( is_fixed ), valid( true ), byte( '\0' ) 00217 { 00218 } 00219 00220 Vertex() : midcount( 0 ), valid( false ), byte( '\0' ) {} 00221 00222 Vector3D coords; /**< location */ 00223 std::vector< size_t > adjacencies; /**< indices of adjacent elements */ 00224 unsigned midcount; /**< num elements referencing this as a mid-node */ 00225 bool fixed; /**< is fixed */ 00226 bool slaved; 00227 bool valid; /**< is a valid (initialized) array entry */ 00228 unsigned char byte; /**< mark */ 00229 }; 00230 00231 /** Struct holding an element */ 00232 struct Element 00233 { 00234 std::vector< size_t > connectivity; /**< list of vertex indices */ 00235 EntityTopology topology; /**< element type */ 00236 Element() : topology( MIXED ) {} 00237 }; 00238 00239 std::vector< Vertex > vertexList; /**< Array of vertices */ 00240 std::vector< Element > elementList; /**< Array of elements */ 00241 00242 /** List of unused indices in vertex list */ 00243 std::vector< size_t > deletedVertexList; 00244 /** List of unused indices in element list */ 00245 std::vector< size_t > deletedElementList; 00246 00247 bool haveSlavedFlags; 00248 }; 00249 00250 /**\brief VertexIterator for MeshImpl 00251 * 00252 * Iterate over valid vertex indices 00253 */ 00254 class MeshImplVertIter : public VertexIterator 00255 { 00256 private: 00257 MeshImplData* mesh; 00258 size_t index; 00259 00260 public: 00261 MeshImplVertIter( MeshImplData* data ) : mesh( data ) 00262 { 00263 restart(); 00264 } 00265 00266 virtual ~MeshImplVertIter(); 00267 00268 virtual void restart(); 00269 00270 virtual void operator++(); 00271 00272 virtual Mesh::VertexHandle operator*() const; 00273 00274 virtual bool is_at_end() const; 00275 }; 00276 00277 /**\brief ElementIterator for MeshImpl 00278 * 00279 * Iterate over valid element indices 00280 */ 00281 class MeshImplElemIter : public ElementIterator 00282 { 00283 private: 00284 MeshImplData* mesh; 00285 size_t index; 00286 00287 public: 00288 MeshImplElemIter( MeshImplData* data ) : mesh( data ) 00289 { 00290 restart(); 00291 } 00292 00293 virtual ~MeshImplElemIter(); 00294 00295 virtual void restart(); 00296 00297 virtual void operator++(); 00298 00299 virtual Mesh::ElementHandle operator*() const; 00300 00301 virtual bool is_at_end() const; 00302 }; 00303 00304 } // namespace MBMesquite 00305 00306 #endif