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