MOAB: Mesh Oriented datABase  (version 5.4.1)
ArrayMesh.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 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,
00073                unsigned long num_vertices,
00074                double* interleaved_vertex_coords,
00075                const int* vertex_fixed_flags,
00076                unsigned long num_elements,
00077                EntityTopology element_type,
00078                const unsigned long* element_connectivity_array,
00079                bool one_based_conn_indices    = false,
00080                unsigned nodes_per_element     = 0,
00081                const int* vertex_slaved_flags = 0 );
00082 
00083     /** Create a MBMesquite::Mesh instance that wraps application-provided
00084      *  arrays.
00085      *
00086      * Note:  An instance of this class will reference the passed in
00087      *        arrays.  It will not copy them.
00088      *
00089      *\param coords_per_vertex Dimension of the mesh (2 or 3)
00090      *\param num_vertices      Number of vertices in the mesh
00091      *\param interleaved_vertex_coords Vertex coordinates.  Ordered as
00092      *                         [x1, y1, z1, x2, y2, z2, ...]
00093      *\param vertex_fixed_flags One value per vertex.  Zero if vertex is
00094      *                         free, one if the poistion is fixed.
00095      *\param num_elements      Number of elements in the mesh
00096      *\param element_types     The topological type for each element.
00097      *\param element_connectivity_array Element connectivity, specified
00098      *                         as vertex indices such that the location
00099      *                         of the vertex coordinates in vertex_coords
00100      *                         is at 3 times the value in this array.
00101      *\param element_connectivity_offsets An optional array of length one greater
00102      *                         than num_elements.  Each entry other than
00103      *                         the last should contain the value of the
00104      *                         index into element_connectivity_array at
00105      *                         which the connectivity data for the
00106      *                         corresponding element begins.  The last
00107      *                         entry in the array must be the next-to-last
00108      *                         entry plus the length of the connectivity
00109      *                         data for the last element, such that the
00110      *                         length of the connectivity data for any
00111      *                         element 'e' can be calculated with:
00112      *                           n = element_connectivity_offsets[e+1] -
00113      *element_connectivity_offsets[e]
00114      *
00115      *                         If this array is not specified, then it
00116      *                         will be assumed that the length of the
00117      *                         connectivity data for each element is the
00118      *                         number of corners necessary to represent
00119      *                         its topological type (that it has no higher-order
00120      *                         nodes.)
00121      *\param one_based_conn_indices Use one-based (Fortran) array indexing.
00122      *\param vertex_slaved_flags One value per vertex.  Zero if vertex is
00123      *                         free, one if the vertex is slaved to the
00124      *                         logical position of the element mapping/shape
00125      *                         function..
00126      */
00127     ArrayMesh( int coords_per_vertex,
00128                unsigned long num_vertices,
00129                double* interleaved_vertex_coords,
00130                const int* vertex_fixed_flags,
00131                unsigned long num_elements,
00132                const EntityTopology* element_types,
00133                const unsigned long* element_connectivity_array,
00134                const unsigned long* element_connectivity_offsets = NULL,
00135                bool one_based_conn_indices                       = false,
00136                const int* vertex_slaved_flags                    = 0 );
00137 
00138     ArrayMesh();
00139 
00140     ~ArrayMesh();
00141 
00142     void clear_mesh();
00143     void set_mesh( int coords_per_vertex,
00144                    unsigned long num_vertices,
00145                    double* interleaved_vertex_coords,
00146                    const int* vertex_fixed_flags,
00147                    unsigned long num_elements,
00148                    EntityTopology element_type,
00149                    const unsigned long* element_connectivity_array,
00150                    bool one_based_conn_indices    = false,
00151                    unsigned nodes_per_element     = 0,
00152                    const int* vertex_slaved_flags = 0 );
00153 
00154     /**\brief Give mesquite access to per-entity application data via a tag
00155      *
00156      * Allow mesquite to access application-owned per-element and/or per-vertex
00157      * data by assigning a tag name to said data.  Mesquite will be allowed
00158      * to read application-owned data.  Any attempt by Mesquite to modify
00159      * the data will result in an internal error condition.
00160      *
00161      *\param tag_name  Tag name through which Mesquite can access the data
00162      *\param data_type The type of the data
00163      *\param vals_per_entity Number of values of type \c data_type that each entity has
00164      *                       Data is assumed to be interleaved such that all values
00165      *                       associated with a a single entity are adjacent in memory
00166      *\param vertex_data     A pointer to the region of memory in which per-vertex
00167      *                       values are stored.  May be NULL if per-vertex data is
00168      *                       not available.  Values are assumed to be in the same
00169      *                       order as the vertex coordinates passed to the constructor
00170      *                       or \c set_mesh.
00171      *\param vertex_data     A pointer to the region of memory in which per-element
00172      *                       values are stored.  May be NULL if per-element data is
00173      *                       not available.  Values are assumed to be in the same
00174      *                       order as the element connetivity passed to the constructor
00175      *                       or \c set_mesh.
00176      *\param default_value   Value to return for all vertices and/or all elements
00177      *                       if the cooresponding data array is null.  May be
00178      *                       NULL if no default value.
00179      */
00180     TagHandle add_read_only_tag_data( const char* tag_name,
00181                                       TagType data_type,
00182                                       int vals_per_entity,
00183                                       const void* vertex_data,
00184                                       const void* element_data,
00185                                       const void* default_value,
00186                                       MsqError& err );
00187 
00188     /**\brief Give mesquite access to per-entity application data via a tag
00189      *
00190      * Allow mesquite to access and/or set application-owned per-element
00191      * and/or per-vertex data by assigning a tag name to said data.
00192      *
00193      *\param tag_name  Tag name through which Mesquite can access the data
00194      *\param data_type The type of the data
00195      *\param vals_per_entity Number of values of type \c data_type that each entity has
00196      *                       Data is assumed to be interleaved such that all values
00197      *                       associated with a a single entity are adjacent in memory
00198      *\param vertex_data     A pointer to the region of memory in which per-vertex
00199      *                       values are stored.  May be NULL if per-vertex data is
00200      *                       not available.  Values are assumed to be in the same
00201      *                       order as the vertex coordinates passed to the constructor
00202      *                       or \c set_mesh.
00203      *\param vertex_data     A pointer to the region of memory in which per-element
00204      *                       values are stored.  May be NULL if per-element data is
00205      *                       not available.  Values are assumed to be in the same
00206      *                       order as the element connetivity passed to the constructor
00207      *                       or \c set_mesh.
00208      *\param default_value   Value to return for all vertices and/or all elements
00209      *                       if the cooresponding data array is null.  May be
00210      *                       NULL if no default value.
00211      */
00212     TagHandle add_writable_tag_data( const char* tag_name,
00213                                      TagType tag_data_type,
00214                                      int vals_per_entity,
00215                                      void* vertex_data,
00216                                      void* element_data,
00217                                      const void* default_value,
00218                                      MsqError& err );
00219 
00220     virtual int get_geometric_dimension( MsqError& err );
00221 
00222     virtual void get_all_elements( std::vector< ElementHandle >& elements, MsqError& err );
00223     virtual void get_all_vertices( std::vector< VertexHandle >& vertices, MsqError& err );
00224 
00225     virtual VertexIterator* vertex_iterator( MsqError& err );
00226     virtual ElementIterator* element_iterator( MsqError& err );
00227 
00228     virtual void vertices_get_fixed_flag( const VertexHandle vert_array[],
00229                                           std::vector< bool >& fixed_flag_array,
00230                                           size_t num_vtx,
00231                                           MsqError& err );
00232     virtual void vertices_get_slaved_flag( const VertexHandle vert_array[],
00233                                            std::vector< bool >& slaved_flag_array,
00234                                            size_t num_vtx,
00235                                            MsqError& err );
00236     virtual void vertices_get_coordinates( const VertexHandle vert_array[],
00237                                            MsqVertex* coordinates,
00238                                            size_t num_vtx,
00239                                            MsqError& err );
00240     virtual void vertex_set_coordinates( VertexHandle vertex, const Vector3D& coordinates, MsqError& err );
00241 
00242     virtual void vertex_set_byte( VertexHandle vertex, unsigned char byte, MsqError& err );
00243     virtual void vertices_set_byte( const VertexHandle* vert_array,
00244                                     const unsigned char* byte_array,
00245                                     size_t array_size,
00246                                     MsqError& err );
00247 
00248     virtual void vertex_get_byte( const VertexHandle vertex, unsigned char* byte, MsqError& err );
00249     virtual void vertices_get_byte( const VertexHandle* vertex,
00250                                     unsigned char* byte_array,
00251                                     size_t array_size,
00252                                     MsqError& err );
00253 
00254     virtual void vertices_get_attached_elements( const VertexHandle* vertex_array,
00255                                                  size_t num_vertex,
00256                                                  std::vector< ElementHandle >& elements,
00257                                                  std::vector< size_t >& offsets,
00258                                                  MsqError& err );
00259 
00260     virtual void elements_get_attached_vertices( const ElementHandle* elem_handles,
00261                                                  size_t num_elems,
00262                                                  std::vector< VertexHandle >& vert_handles,
00263                                                  std::vector< size_t >& offsets,
00264                                                  MsqError& err );
00265 
00266     virtual void elements_get_topologies( const ElementHandle* element_handle_array,
00267                                           EntityTopology* element_topologies,
00268                                           size_t num_elements,
00269                                           MsqError& err );
00270 
00271     virtual TagHandle tag_create( const std::string& tag_name,
00272                                   TagType type,
00273                                   unsigned length,
00274                                   const void* default_value,
00275                                   MsqError& err );
00276 
00277     virtual void tag_delete( TagHandle handle, MsqError& err );
00278 
00279     virtual TagHandle tag_get( const std::string& name, MsqError& err );
00280 
00281     virtual void tag_properties( TagHandle handle,
00282                                  std::string& name_out,
00283                                  TagType& type_out,
00284                                  unsigned& length_out,
00285                                  MsqError& err );
00286 
00287     virtual void tag_set_element_data( TagHandle handle,
00288                                        size_t num_elems,
00289                                        const ElementHandle* elem_array,
00290                                        const void* tag_data,
00291                                        MsqError& err );
00292 
00293     virtual void tag_set_vertex_data( TagHandle handle,
00294                                       size_t num_elems,
00295                                       const VertexHandle* node_array,
00296                                       const void* tag_data,
00297                                       MsqError& err );
00298 
00299     virtual void tag_get_element_data( TagHandle handle,
00300                                        size_t num_elems,
00301                                        const ElementHandle* elem_array,
00302                                        void* tag_data,
00303                                        MsqError& err );
00304 
00305     virtual void tag_get_vertex_data( TagHandle handle,
00306                                       size_t num_elems,
00307                                       const VertexHandle* node_array,
00308                                       void* tag_data,
00309                                       MsqError& err );
00310 
00311     virtual void release_entity_handles( const EntityHandle* handle_array, size_t num_handles, MsqError& err );
00312 
00313     virtual void release();
00314 
00315   private:
00316     inline const unsigned long* elem_verts( size_t elem_index, int& num_vertex ) const;
00317 
00318     void build_vertex_adjacency_list();
00319 
00320     int mDimension;                  //!< Coordinates per vertex
00321     unsigned long vertexCount;       //!< Number of vertices
00322     double* coordArray;              //!< Interleaved vertex coordinates
00323     const int* fixedFlags;           //!< Vertex fixed flags
00324     const int* slavedFlags;          //!< Vertex slaved flags
00325     unsigned char* vertexByteArray;  //!< Vertex bytes
00326 
00327     unsigned long elementCount;          //!< Number of elements
00328     const unsigned long* connArray;      //!< Element connectivity
00329     const unsigned long* connOffsets;    //!< Offsets into connectivity array
00330                                          //!< for each element.  If NULL, then
00331                                          //!< all elements are of the same type
00332                                          //!< and have the same number of vertices.
00333     unsigned long* allocConnOffsets;     //!< Same as connOffsets if allocated
00334                                          //!< by constructor.  NULL if connOffsets
00335                                          //!< is either NULL or application-provided
00336                                          //!< data.
00337     EntityTopology elementType;          //!< Type for all elements if connOffsets is NULL
00338     const EntityTopology* elementTypes;  //!< Type for each element type if connOffsets is not NULL
00339     unsigned nodesPerElement;            //!< Nodes per element if connOffsets is NULL
00340     bool oneBasedArrays;                 //!< FORTRAN-style array indexing
00341 
00342     unsigned long* vertexAdjacencyList;
00343     unsigned long* vertexAdjacencyOffsets;
00344 
00345     static unsigned bytes( TagType type );
00346 
00347     static void fill( unsigned char* buffer, const unsigned char* value, size_t size, size_t count );
00348 
00349     struct Tag
00350     {
00351         char* name;                       //!< Tag name (null-terminated string)
00352         TagType type;                     //!< tag data type
00353         unsigned size;                    //!< number of *bytes* per entity
00354         bool owned;                       //!< true if memory for tag storage is owned by this class
00355         unsigned char* vtxWritePtr;       //!< pointer to writable tag data (NULL if read-only)
00356         const unsigned char* vtxReadPtr;  //!< pointer to tag data
00357         unsigned char* eleWritePtr;       //!< pointer to writable tag data (NULL if read-only)
00358         const unsigned char* eleReadPtr;  //!< pointer to tag data
00359         unsigned char* defaultValue;      //!< Default value
00360         Tag* next;                        //!< Linked-list next pointer
00361     };
00362 
00363     Tag* allocate_tag( const char* name,
00364                        bool owned,
00365                        TagType type,
00366                        unsigned size,
00367                        const void* vertex_ro_data,
00368                        void* vertex_rw_data,
00369                        const void* element_ro_data,
00370                        void* element_rw_data,
00371                        const void* default_value,
00372                        MsqError& err );
00373 
00374     Tag* tagList;
00375 
00376     bool valid() const;
00377 };
00378 
00379 }  // namespace MBMesquite
00380 
00381 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines