MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2007 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to 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 (2007) kraftche@cae.wisc.edu 00024 00025 ***************************************************************** */ 00026 00027 /** \file ArrayMesh.hpp 00028 * \brief Access mesh stored in arrays 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #ifndef MSQ_ARRAY_MESH_HPP 00033 #define MSQ_ARRAY_MESH_HPP 00034 00035 #include "Mesquite.hpp" 00036 #include "MeshInterface.hpp" 00037 00038 namespace MBMesquite 00039 { 00040 00041 class ArrayMesh : public Mesh 00042 { 00043 public: 00044 /** Create a MBMesquite::Mesh instance that wraps application-provided 00045 * arrays. 00046 * 00047 * Note: An instance of this class will reference the passed in 00048 * arrays. It will not copy them. 00049 * 00050 *\param coords_per_vertex Dimension of the mesh (2 or 3) 00051 *\param num_vertices Number of vertices in the mesh 00052 *\param interleaved_vertex_coords Vertex coordinates. Ordered as 00053 * [x1, y1, z1, x2, y2, z2, ...] 00054 *\param vertex_fixed_flags One value per vertex. Zero if vertex is 00055 * free, one if the position is fixed. 00056 *\param num_elements Number of elements in the mesh 00057 *\param element_type The type of the elements 00058 *\param element_connectivity_array Element connectivity, specified 00059 * as vertex indices such that the location 00060 * of the vertex coordinates in vertex_coords 00061 * is at 3 times the value in this array. 00062 *\param one_based_conn_indices Use one-based (Fortran) array indexing. 00063 *\param nodes_per_element Number of nodes in each element. If not 00064 * specified, number of nodes in a linear 00065 * element with the type 'element_type' is 00066 * assumed. 00067 *\param vertex_slaved_flags One value per vertex. Zero if vertex is 00068 * free, one if the vertex is slaved to the 00069 * logical position of the element mapping/shape 00070 * function.. 00071 */ 00072 ArrayMesh( int coords_per_vertex, unsigned long num_vertices, double* interleaved_vertex_coords, 00073 const int* vertex_fixed_flags, unsigned long num_elements, EntityTopology element_type, 00074 const unsigned long* element_connectivity_array, bool one_based_conn_indices = false, 00075 unsigned nodes_per_element = 0, const int* vertex_slaved_flags = 0 ); 00076 00077 /** Create a MBMesquite::Mesh instance that wraps application-provided 00078 * arrays. 00079 * 00080 * Note: An instance of this class will reference the passed in 00081 * arrays. It will not copy them. 00082 * 00083 *\param coords_per_vertex Dimension of the mesh (2 or 3) 00084 *\param num_vertices Number of vertices in the mesh 00085 *\param interleaved_vertex_coords Vertex coordinates. Ordered as 00086 * [x1, y1, z1, x2, y2, z2, ...] 00087 *\param vertex_fixed_flags One value per vertex. Zero if vertex is 00088 * free, one if the poistion is fixed. 00089 *\param num_elements Number of elements in the mesh 00090 *\param element_types The topological type for each element. 00091 *\param element_connectivity_array Element connectivity, specified 00092 * as vertex indices such that the location 00093 * of the vertex coordinates in vertex_coords 00094 * is at 3 times the value in this array. 00095 *\param element_connectivity_offsets An optional array of length one greater 00096 * than num_elements. Each entry other than 00097 * the last should contain the value of the 00098 * index into element_connectivity_array at 00099 * which the connectivity data for the 00100 * corresponding element begins. The last 00101 * entry in the array must be the next-to-last 00102 * entry plus the length of the connectivity 00103 * data for the last element, such that the 00104 * length of the connectivity data for any 00105 * element 'e' can be calculated with: 00106 * n = element_connectivity_offsets[e+1] - 00107 *element_connectivity_offsets[e] 00108 * 00109 * If this array is not specified, then it 00110 * will be assumed that the length of the 00111 * connectivity data for each element is the 00112 * number of corners necessary to represent 00113 * its topological type (that it has no higher-order 00114 * nodes.) 00115 *\param one_based_conn_indices Use one-based (Fortran) array indexing. 00116 *\param vertex_slaved_flags One value per vertex. Zero if vertex is 00117 * free, one if the vertex is slaved to the 00118 * logical position of the element mapping/shape 00119 * function.. 00120 */ 00121 ArrayMesh( int coords_per_vertex, unsigned long num_vertices, double* interleaved_vertex_coords, 00122 const int* vertex_fixed_flags, unsigned long num_elements, const EntityTopology* element_types, 00123 const unsigned long* element_connectivity_array, 00124 const unsigned long* element_connectivity_offsets = NULL, bool one_based_conn_indices = false, 00125 const int* vertex_slaved_flags = 0 ); 00126 00127 ArrayMesh(); 00128 00129 ~ArrayMesh(); 00130 00131 void clear_mesh(); 00132 void set_mesh( int coords_per_vertex, unsigned long num_vertices, double* interleaved_vertex_coords, 00133 const int* vertex_fixed_flags, unsigned long num_elements, EntityTopology element_type, 00134 const unsigned long* element_connectivity_array, bool one_based_conn_indices = false, 00135 unsigned nodes_per_element = 0, const int* vertex_slaved_flags = 0 ); 00136 00137 /**\brief Give mesquite access to per-entity application data via a tag 00138 * 00139 * Allow mesquite to access application-owned per-element and/or per-vertex 00140 * data by assigning a tag name to said data. Mesquite will be allowed 00141 * to read application-owned data. Any attempt by Mesquite to modify 00142 * the data will result in an internal error condition. 00143 * 00144 *\param tag_name Tag name through which Mesquite can access the data 00145 *\param data_type The type of the data 00146 *\param vals_per_entity Number of values of type \c data_type that each entity has 00147 * Data is assumed to be interleaved such that all values 00148 * associated with a a single entity are adjacent in memory 00149 *\param vertex_data A pointer to the region of memory in which per-vertex 00150 * values are stored. May be NULL if per-vertex data is 00151 * not available. Values are assumed to be in the same 00152 * order as the vertex coordinates passed to the constructor 00153 * or \c set_mesh. 00154 *\param vertex_data A pointer to the region of memory in which per-element 00155 * values are stored. May be NULL if per-element data is 00156 * not available. Values are assumed to be in the same 00157 * order as the element connetivity passed to the constructor 00158 * or \c set_mesh. 00159 *\param default_value Value to return for all vertices and/or all elements 00160 * if the cooresponding data array is null. May be 00161 * NULL if no default value. 00162 */ 00163 TagHandle add_read_only_tag_data( const char* tag_name, TagType data_type, int vals_per_entity, 00164 const void* vertex_data, const void* element_data, const void* default_value, 00165 MsqError& err ); 00166 00167 /**\brief Give mesquite access to per-entity application data via a tag 00168 * 00169 * Allow mesquite to access and/or set application-owned per-element 00170 * and/or per-vertex data by assigning a tag name to said data. 00171 * 00172 *\param tag_name Tag name through which Mesquite can access the data 00173 *\param data_type The type of the data 00174 *\param vals_per_entity Number of values of type \c data_type that each entity has 00175 * Data is assumed to be interleaved such that all values 00176 * associated with a a single entity are adjacent in memory 00177 *\param vertex_data A pointer to the region of memory in which per-vertex 00178 * values are stored. May be NULL if per-vertex data is 00179 * not available. Values are assumed to be in the same 00180 * order as the vertex coordinates passed to the constructor 00181 * or \c set_mesh. 00182 *\param vertex_data A pointer to the region of memory in which per-element 00183 * values are stored. May be NULL if per-element data is 00184 * not available. Values are assumed to be in the same 00185 * order as the element connetivity passed to the constructor 00186 * or \c set_mesh. 00187 *\param default_value Value to return for all vertices and/or all elements 00188 * if the cooresponding data array is null. May be 00189 * NULL if no default value. 00190 */ 00191 TagHandle add_writable_tag_data( const char* tag_name, TagType tag_data_type, int vals_per_entity, 00192 void* vertex_data, void* element_data, const void* default_value, MsqError& err ); 00193 00194 virtual int get_geometric_dimension( MsqError& err ); 00195 00196 virtual void get_all_elements( std::vector< ElementHandle >& elements, MsqError& err ); 00197 virtual void get_all_vertices( std::vector< VertexHandle >& vertices, MsqError& err ); 00198 00199 virtual VertexIterator* vertex_iterator( MsqError& err ); 00200 virtual ElementIterator* element_iterator( MsqError& err ); 00201 00202 virtual void vertices_get_fixed_flag( const VertexHandle vert_array[], std::vector< bool >& fixed_flag_array, 00203 size_t num_vtx, MsqError& err ); 00204 virtual void vertices_get_slaved_flag( const VertexHandle vert_array[], std::vector< bool >& slaved_flag_array, 00205 size_t num_vtx, MsqError& err ); 00206 virtual void vertices_get_coordinates( const VertexHandle vert_array[], MsqVertex* coordinates, size_t num_vtx, 00207 MsqError& err ); 00208 virtual void vertex_set_coordinates( VertexHandle vertex, const Vector3D& coordinates, MsqError& err ); 00209 00210 virtual void vertex_set_byte( VertexHandle vertex, unsigned char byte, MsqError& err ); 00211 virtual void vertices_set_byte( const VertexHandle* vert_array, const unsigned char* byte_array, size_t array_size, 00212 MsqError& err ); 00213 00214 virtual void vertex_get_byte( const VertexHandle vertex, unsigned char* byte, MsqError& err ); 00215 virtual void vertices_get_byte( const VertexHandle* vertex, unsigned char* byte_array, size_t array_size, 00216 MsqError& err ); 00217 00218 virtual void vertices_get_attached_elements( const VertexHandle* vertex_array, size_t num_vertex, 00219 std::vector< ElementHandle >& elements, std::vector< size_t >& offsets, 00220 MsqError& err ); 00221 00222 virtual void elements_get_attached_vertices( const ElementHandle* elem_handles, size_t num_elems, 00223 std::vector< VertexHandle >& vert_handles, 00224 std::vector< size_t >& offsets, MsqError& err ); 00225 00226 virtual void elements_get_topologies( const ElementHandle* element_handle_array, EntityTopology* element_topologies, 00227 size_t num_elements, MsqError& err ); 00228 00229 virtual TagHandle tag_create( const std::string& tag_name, TagType type, unsigned length, const void* default_value, 00230 MsqError& err ); 00231 00232 virtual void tag_delete( TagHandle handle, MsqError& err ); 00233 00234 virtual TagHandle tag_get( const std::string& name, MsqError& err ); 00235 00236 virtual void tag_properties( TagHandle handle, std::string& name_out, TagType& type_out, unsigned& length_out, 00237 MsqError& err ); 00238 00239 virtual void tag_set_element_data( TagHandle handle, size_t num_elems, const ElementHandle* elem_array, 00240 const void* tag_data, MsqError& err ); 00241 00242 virtual void tag_set_vertex_data( TagHandle handle, size_t num_elems, const VertexHandle* node_array, 00243 const void* tag_data, MsqError& err ); 00244 00245 virtual void tag_get_element_data( TagHandle handle, size_t num_elems, const ElementHandle* elem_array, 00246 void* tag_data, MsqError& err ); 00247 00248 virtual void tag_get_vertex_data( TagHandle handle, size_t num_elems, const VertexHandle* node_array, 00249 void* tag_data, MsqError& err ); 00250 00251 virtual void release_entity_handles( const EntityHandle* handle_array, size_t num_handles, MsqError& err ); 00252 00253 virtual void release(); 00254 00255 private: 00256 inline const unsigned long* elem_verts( size_t elem_index, int& num_vertex ) const; 00257 00258 void build_vertex_adjacency_list(); 00259 00260 int mDimension; //!< Coordinates per vertex 00261 unsigned long vertexCount; //!< Number of vertices 00262 double* coordArray; //!< Interleaved vertex coordinates 00263 const int* fixedFlags; //!< Vertex fixed flags 00264 const int* slavedFlags; //!< Vertex slaved flags 00265 unsigned char* vertexByteArray; //!< Vertex bytes 00266 00267 unsigned long elementCount; //!< Number of elements 00268 const unsigned long* connArray; //!< Element connectivity 00269 const unsigned long* connOffsets; //!< Offsets into connectivity array 00270 //!< for each element. If NULL, then 00271 //!< all elements are of the same type 00272 //!< and have the same number of vertices. 00273 unsigned long* allocConnOffsets; //!< Same as connOffsets if allocated 00274 //!< by constructor. NULL if connOffsets 00275 //!< is either NULL or application-provided 00276 //!< data. 00277 EntityTopology elementType; //!< Type for all elements if connOffsets is NULL 00278 const EntityTopology* elementTypes; //!< Type for each element type if connOffsets is not NULL 00279 unsigned nodesPerElement; //!< Nodes per element if connOffsets is NULL 00280 bool oneBasedArrays; //!< FORTRAN-style array indexing 00281 00282 unsigned long* vertexAdjacencyList; 00283 unsigned long* vertexAdjacencyOffsets; 00284 00285 static unsigned bytes( TagType type ); 00286 00287 static void fill( unsigned char* buffer, const unsigned char* value, size_t size, size_t count ); 00288 00289 struct Tag 00290 { 00291 char* name; //!< Tag name (null-terminated string) 00292 TagType type; //!< tag data type 00293 unsigned size; //!< number of *bytes* per entity 00294 bool owned; //!< true if memory for tag storage is owned by this class 00295 unsigned char* vtxWritePtr; //!< pointer to writable tag data (NULL if read-only) 00296 const unsigned char* vtxReadPtr; //!< pointer to tag data 00297 unsigned char* eleWritePtr; //!< pointer to writable tag data (NULL if read-only) 00298 const unsigned char* eleReadPtr; //!< pointer to tag data 00299 unsigned char* defaultValue; //!< Default value 00300 Tag* next; //!< Linked-list next pointer 00301 }; 00302 00303 Tag* allocate_tag( const char* name, bool owned, TagType type, unsigned size, const void* vertex_ro_data, 00304 void* vertex_rw_data, const void* element_ro_data, void* element_rw_data, 00305 const void* default_value, MsqError& err ); 00306 00307 Tag* tagList; 00308 00309 bool valid() const; 00310 }; 00311 00312 } // namespace MBMesquite 00313 00314 #endif