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 MsqIMesh.hpp 00028 * \brief Adaptor for ITAPS iMesh interface 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #ifndef MSQ_I_MESH_HPP 00033 #define MSQ_I_MESH_HPP 00034 00035 #include "MeshInterface.hpp" 00036 #include "iMesh.h" 00037 00038 namespace MBMesquite 00039 { 00040 00041 /** The name of the tag (integer) that Mesquite will use 00042 * to store internal data 00043 */ 00044 const char* const VERTEX_BYTE_TAG_NAME = "MesquiteVertexByte"; 00045 00046 /**\class MsqIMesh 00047 *\brief Mesquite iMesh Adapter 00048 * 00049 * Adpater for interfacing Mesquite with an application that provides 00050 * the ITAPS iMesh interface for interacting with mesh data. 00051 */ 00052 class MsqIMesh : virtual public MBMesquite::Mesh 00053 { 00054 public: 00055 //********* Functions that are NOT inherited ************ 00056 00057 MsqIMesh(); 00058 virtual ~MsqIMesh(); 00059 00060 /**\brief Create iMesh adaptor instance 00061 *\param imesh The iMesh instance to interact with 00062 *\param meshset The set of elements for which to optimize the quality 00063 * 00064 *\param element_dimension Optimize the subset of the elements in 00065 * 'meshset' with this dimension. Pass iBase_ALL_TYPES 00066 * for both iBase_FACE and iBase_REGION elements. 00067 * If 'meshset' is the root set, then this argument is 00068 * typically either iBase_FACE or iBase_REGION. 00069 * 00070 *\param fixed_tag A pointer to the tag handle designating a tag 00071 * containing fixed flags for vertices. The tag must 00072 * have size==1 and type==iBase_INTEGER or iBase_BYTES. 00073 * A value of one for a vertex indicates that the vertex 00074 * position is fixed. A value of zero indicates a free 00075 * vertex (a vertex that Mesquite may move to improve 00076 * mesh quality.) If this tag is not specified, then 00077 * the boundary constraints of the optimization must be 00078 * specified using an MsqIRel instance. 00079 * 00080 *\param slaved_tag A pointer to the tag handle designating a tag 00081 * containing slaved flags for vertices. The tag must 00082 * have size==1 and type==iBase_INTEGER or iBase_BYTES. 00083 * This tag value is ignored for corner vertices of 00084 * elements. The concept of 'slaved' is applicable only 00085 * to non-corner vertices in higher-order elements. A 00086 * value of one for a vertex indicates that the vertex 00087 * position should is a fucntion of the element shape 00088 * function, while a zero value indicates that the 00089 * element shape function is a function of the vertex 00090 * position. 00091 */ 00092 MsqIMesh( iMesh_Instance imesh, iBase_EntitySetHandle meshset, iBase_EntityType element_dimension, MsqError& err, 00093 const iBase_TagHandle* fixed_tag = 0, const iBase_TagHandle* slaved_tag = 0 ); 00094 00095 /**\brief Create iMesh adaptor instance 00096 * 00097 * This constructor is provided for the creation of an MsqIMesh instance 00098 * that is to be re-used for multiple optimization calls for different 00099 * sets of elements. set_active_set must be called to define the 00100 * subset of the mesh to optimize before an instance constructed with 00101 * this constructor may be used in an optimization. 00102 * 00103 *\param imesh The iMesh instance to interact with 00104 * 00105 *\param element_dimension Optimize the subset of the elements in 00106 * root set with this dimension. Pass iBase_ALL_TYPES 00107 * for both iBase_FACE and iBase_REGION elements. 00108 * If 'meshset' is the root set, then this argument is 00109 * typically either iBase_FACE or iBase_REGION. 00110 * 00111 *\param fixed_tag A pointer to the tag handle designating a tag 00112 * containing fixed flags for vertices. The tag must 00113 * have size==1 and type==iBase_INTEGER or iBase_BYTES. 00114 * A value of one for a vertex indicates that the vertex 00115 * position is fixed. A value of zero indicates a free 00116 * vertex (a vertex that Mesquite may move to improve 00117 * mesh quality.) If this tag is not specified, then 00118 * the boundary constraints of the optimization must be 00119 * specified using an MsqIRel instance. 00120 * 00121 *\param slaved_tag A pointer to the tag handle designating a tag 00122 * containing slaved flags for vertices. The tag must 00123 * have size==1 and type==iBase_INTEGER or iBase_BYTES. 00124 * This tag value is ignored for corner vertices of 00125 * elements. The concept of 'slaved' is applicable only 00126 * to non-corner vertices in higher-order elements. A 00127 * value of one for a vertex indicates that the vertex 00128 * position should is a fucntion of the element shape 00129 * function, while a zero value indicates that the 00130 * element shape function is a function of the vertex 00131 * position. 00132 */ 00133 MsqIMesh( iMesh_Instance imesh, iBase_EntityType element_dimension, MsqError& err, 00134 const iBase_TagHandle* fixed_tag = 0, const iBase_TagHandle* slaved_tag = 0 ); 00135 00136 /** \brief set mesh to be smoothed. 00137 * 00138 * Set the mesh which Mesquite is to smooth. Optionally 00139 * specify fixed vertices. 00140 * NOTE: If an active set is not specified, the default 00141 * is to use the global set (the ENTIRE mesh.) 00142 * 00143 *\param element_set ITAPS entity set handle for set containing 00144 * mesh elements and vertices for which quality 00145 * is to be improved. 00146 */ 00147 void set_active_set( iBase_EntitySetHandle meshset, iBase_EntityType element_dimension, MsqError& err ); 00148 00149 void set_fixed_tag( iBase_TagHandle tag, MsqError& err ); //!< Set tag for vertex fixed flag 00150 void set_slaved_tag( iBase_TagHandle tag, MsqError& err ); //!< Set tag for vertex slaved flag 00151 void clear_fixed_tag(); //!< No tag for vertex fixed flag 00152 void clear_slaved_tag(); //!< No tag for vertex fixed flag 00153 const iBase_TagHandle* get_fixed_tag() const; //!< Get tag for vertex fixed flag 00154 const iBase_TagHandle* get_slaved_tag() const; //!< Get tag for vertex slaved flag 00155 00156 virtual iMesh_Instance get_imesh_instance() const; 00157 virtual iBase_EntitySetHandle get_entity_set() const; 00158 00159 //********* Functions that ARE inherited ************ 00160 00161 /**\brief Get dimension of vertex coordinates (2D vs. 3D). */ 00162 virtual int get_geometric_dimension( MBMesquite::MsqError& /*err*/ ); 00163 00164 /** \brief Get handles for all elemnents */ 00165 virtual void get_all_elements( std::vector< ElementHandle >& elements, MsqError& err ); 00166 00167 /** \brief Get handles for all vertices */ 00168 virtual void get_all_vertices( std::vector< VertexHandle >& vertices, MsqError& err ); 00169 00170 /**\brief Query "fixed" flag for a vertex */ 00171 virtual void vertices_get_fixed_flag( const VertexHandle vert_array[], std::vector< bool >& fixed_flag_array, 00172 size_t num_vtx, MsqError& err ); 00173 00174 virtual void vertices_get_slaved_flag( const VertexHandle vert_array[], std::vector< bool >& slaved_flag_array, 00175 size_t num_vtx, MsqError& err ); 00176 00177 /**\brief Get vertex coordinates */ 00178 virtual void vertices_get_coordinates( const VertexHandle vert_array[], MsqVertex* coordinates, size_t num_vtx, 00179 MsqError& err ); 00180 /**\brief Set vertex coordinates */ 00181 virtual void vertex_set_coordinates( VertexHandle vertex, const Vector3D& coordinates, MsqError& err ); 00182 00183 /**\brief Set vertex mark */ 00184 virtual void vertex_set_byte( VertexHandle vertex, unsigned char byte, MsqError& err ); 00185 /**\brief Set vertex mark */ 00186 virtual void vertices_set_byte( const VertexHandle* vert_array, const unsigned char* byte_array, size_t array_size, 00187 MsqError& err ); 00188 00189 /**\brief Get vertex mark */ 00190 virtual void vertex_get_byte( VertexHandle vertex, unsigned char* byte, MsqError& err ); 00191 /**\brief Get vertex mark */ 00192 virtual void vertices_get_byte( const VertexHandle* vert_array, unsigned char* byte_array, size_t array_size, 00193 MsqError& err ); 00194 00195 /**\brief Get vertex-to-element adjacencies */ 00196 virtual void vertices_get_attached_elements( const VertexHandle* vertex_array, size_t num_vertices, 00197 std::vector< ElementHandle >& elements, std::vector< size_t >& offsets, 00198 MsqError& err ); 00199 00200 /**\brief Get element connectivity */ 00201 virtual void elements_get_attached_vertices( const ElementHandle* elem_handles, size_t num_elems, 00202 std::vector< VertexHandle >& vertices, std::vector< size_t >& offsets, 00203 MsqError& err ); 00204 00205 /**\brief Return topology type enum for an array of elements */ 00206 virtual void elements_get_topologies( const ElementHandle* element_handle_array, EntityTopology* element_topologies, 00207 size_t num_elements, MsqError& err ); 00208 00209 //**************** Memory Management **************** 00210 /**\brief no-op */ 00211 virtual void release_entity_handles( const EntityHandle* handle_array, size_t num_handles, MsqError& err ); 00212 00213 // Instead of deleting a Mesh when you think you are done, 00214 // call release(). In simple cases, the implementation could 00215 // just call the destructor. More sophisticated implementations 00216 // may want to keep the Mesh object to live longer than Mesquite 00217 // is using it. 00218 virtual void release(); 00219 00220 //*************** Tags *********** 00221 00222 /** \brief Create a tag 00223 * 00224 * Create a user-defined data type that can be attached 00225 * to any element or vertex in the mesh. For an opaque or 00226 * undefined type, use type=BYTE and length=sizeof(..). 00227 * 00228 * \param tag_name A unique name for the data object 00229 * \param type The type of the data 00230 * \param length Number of values per entity (1->scalar, >1 ->vector) 00231 * \param default_value Default value to assign to all entities - may be NULL 00232 * \return - Handle for tag definition 00233 */ 00234 virtual TagHandle tag_create( const std::string& tag_name, TagType type, unsigned length, const void* default_value, 00235 MsqError& err ); 00236 00237 /** \brief Remove a tag and all corresponding data 00238 * 00239 * Delete a tag. 00240 */ 00241 virtual void tag_delete( TagHandle handle, MsqError& err ); 00242 00243 /** \brief Get handle for existing tag, by name. */ 00244 virtual TagHandle tag_get( const std::string& name, MsqError& err ); 00245 00246 /** \brief Get properites of tag 00247 * 00248 * Get data type and number of values per entity for tag. 00249 * \param handle Tag to get properties of. 00250 * \param name_out Passed back tag name. 00251 * \param type_out Passed back tag type. 00252 * \param length_out Passed back number of values per entity. 00253 */ 00254 virtual void tag_properties( TagHandle handle, std::string& name_out, TagType& type_out, unsigned& length_out, 00255 MsqError& err ); 00256 00257 /** \brief Set tag values on elements 00258 * 00259 * Set the value of a tag for a list of mesh elements. 00260 * \param handle The tag 00261 * \param num_elems Length of elem_array 00262 * \param elem_array Array of elements for which to set the tag value. 00263 * \param tag_data Tag data for each element, contiguous in memory. 00264 * This data is expected to be 00265 00266 * num_elems*tag_length*sizeof(tag_type) bytes. 00267 */ 00268 virtual void tag_set_element_data( TagHandle handle, size_t num_elems, const ElementHandle* elem_array, 00269 const void* tag_data, MsqError& err ); 00270 00271 /** \brief Set tag values on vertices 00272 * 00273 * Set the value of a tag for a list of mesh vertices. 00274 * \param handle The tag 00275 * \param num_elems Length of node_array 00276 * \param node_array Array of vertices for which to set the tag value. 00277 * \param tag_data Tag data for each element, contiguous in memory. 00278 * This data is expected to be 00279 * num_elems*tag_length*sizeof(tag_type) bytes. 00280 */ 00281 virtual void tag_set_vertex_data( TagHandle handle, size_t num_elems, const VertexHandle* node_array, 00282 const void* tag_data, MsqError& err ); 00283 00284 /** \brief Get tag values on elements 00285 * 00286 * Get the value of a tag for a list of mesh elements. 00287 * \param handle The tag 00288 * \param num_elems Length of elem_array 00289 * \param elem_array Array of elements for which to get the tag value. 00290 * \param tag_data Return buffer in which to copy tag data, contiguous 00291 * in memory. This data is expected to be 00292 * num_elems*tag_length*sizeof(tag_type) bytes. 00293 */ 00294 virtual void tag_get_element_data( TagHandle handle, size_t num_elems, const ElementHandle* elem_array, 00295 void* tag_data, MsqError& err ); 00296 00297 /** \brief Get tag values on vertices. 00298 * 00299 * Get the value of a tag for a list of mesh vertices. 00300 * \param handle The tag 00301 * \param num_elems Length of elem_array 00302 * \param elem_array Array of vertices for which to get the tag value. 00303 * \param tag_data Return buffer in which to copy tag data, contiguous 00304 * in memory. This data is expected to be 00305 * num_elems*tag_length*sizeof(tag_type) bytes. 00306 */ 00307 virtual void tag_get_vertex_data( TagHandle handle, size_t num_elems, const VertexHandle* node_array, 00308 void* tag_data, MsqError& err ); 00309 00310 protected: 00311 iBase_TagValueType check_valid_flag_tag( iBase_TagHandle tag, const char* which_flag, MsqError& err ); 00312 00313 void set_int_tag( void* tag, void* meshset, int value, MsqError& err ); 00314 00315 /** \brief Call TSTTM::Arr::getEntArrAdj 00316 * 00317 * Common code for \ref vertices_get_attached_elements and 00318 * \ref elements_get_attached_vertices 00319 * 00320 *\param source Array of handles of source entities to query from 00321 *\param num_source The length of \ref source 00322 *\param target_type The type of entity to query for 00323 *\param target The output list of adjacent entities 00324 *\param offsets For each entity in \ref source, the offset in 00325 * \ref target at which the corresponding adjacent 00326 * entities are stored. (output) 00327 */ 00328 void get_adjacent_entities( const iBase_EntityHandle* source, size_t num_source, iBase_EntityType target_type, 00329 std::vector< EntityHandle >& target, std::vector< size_t >& offsets, MsqError& err ); 00330 00331 /** The IMesh instance */ 00332 iMesh_Instance meshInstance; 00333 00334 private: 00335 void init_active_mesh( iMesh_Instance mesh, MsqError& err, const iBase_TagHandle* fixed_tag, 00336 const iBase_TagHandle* slaved_tag ); 00337 00338 void get_flag_data( iBase_TagHandle tag, bool have_tag, iBase_TagValueType type, const VertexHandle vert_array[], 00339 std::vector< bool >& flag_array, size_t num_vtx, MsqError& err ); 00340 00341 /** \brief Set tag values */ 00342 void tag_set_data( TagHandle handle, size_t num_elems, const EntityHandle* handle_array, const void* tag_data, 00343 MsqError& err ); 00344 00345 /** \brief Get tag values */ 00346 void tag_get_data( TagHandle handle, size_t num_elems, const EntityHandle* handle_array, void* tag_data, 00347 MsqError& err ); 00348 00349 /** Have mesh */ 00350 bool haveMesh; 00351 /** ITAPS entity set handle for elements to improve */ 00352 // iBase_EntitySetHandle elementSet; 00353 /** ITAPS entity set handle for nodes to move */ 00354 // iBase_EntitySetHandle nodeSet; 00355 /** std::set containing elements in elementSet, used 00356 * to constrain vertex->element adjaceny queries to 00357 * only those elements that are in the input element set. 00358 */ 00359 // std::vector<iBase_EntityHandle> inputElements; 00360 00361 /** The type of elements contained in the input element set. 00362 * Should be one of: 00363 * - iBase_REGION - volume elements 00364 * - iBase_FACE - face/2d elements 00365 * - iBase_ALL_TYPES - mixed volume and face elements 00366 */ 00367 iBase_EntityType inputSetType; 00368 /** The meshset containing the elements to optimize */ 00369 iBase_EntitySetHandle inputSet; 00370 00371 /** Handle for tag used to hold vertex byte */ 00372 iBase_TagHandle byteTag; 00373 /** Tag was created in constructor */ 00374 bool createdByteTag; 00375 /** Handle for tag used to hold vertex-fixed flag */ 00376 iBase_TagHandle fixedTag; 00377 /** fixedTag handle is valid */ 00378 bool haveFixedTag; 00379 /** iBase_TYPE for fixed tag */ 00380 iBase_TagValueType fixedTagType; 00381 /** Handle for tag used to hold vertex-slaved flag */ 00382 iBase_TagHandle slavedTag; 00383 /** slavedTag handle is valid */ 00384 bool haveSlavedTag; 00385 /** iBase_TYPE for slaved tag */ 00386 iBase_TagValueType slavedTagType; 00387 /** Dimension is queried once during create and cached */ 00388 int geometricDimension; 00389 /** Map iMesh_EntityTopology to MBMesquite::EntityTopology */ 00390 EntityTopology topologyMap[iMesh_ALL_TOPOLOGIES + 1]; 00391 }; 00392 00393 } // namespace MBMesquite 00394 00395 #endif