MOAB: Mesh Oriented datABase  (version 5.2.1)
MeshImplData.hpp
Go to the documentation of this file.
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     kraftche@cae.wisc.edu
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, size_t* element_hanlde_array, size_t* element_conn_offsets,
00072                     size_t* element_conn_indices );
00073 
00074     /** Get all vertices, including mid-nodes */
00075     void all_vertices( std::vector< size_t >& list, MsqError& err ) const;
00076 
00077     /** Get all elements */
00078     void all_elements( std::vector< size_t >& list, MsqError& err ) const;
00079 
00080     /** Check if passed vertex index is valid */
00081     inline bool is_vertex_valid( size_t index ) const
00082     {
00083         return index < vertexList.size() && vertexList[index].valid;
00084     }
00085 
00086     /** Check if passed element index is valid */
00087     inline bool is_element_valid( size_t index ) const
00088     {
00089         return index < elementList.size() && !elementList[index].connectivity.empty();
00090     }
00091 
00092     /** Check if the specified node is used as a mid-node on any element */
00093     bool is_mid_node( size_t index ) const;
00094     /** Check if the specified node is used as a corner vertex on any element */
00095     bool is_corner_node( size_t index ) const;
00096 
00097     /** Get vertex coordinates */
00098     const Vector3D& get_vertex_coords( size_t index, MsqError& err ) const;
00099 
00100     /** Set vertex coordinates */
00101     void set_vertex_coords( size_t index, const Vector3D& coords, MsqError& err );
00102 
00103     /** Get vertex fixed flag */
00104     bool vertex_is_fixed( size_t index, MsqError& err ) const;
00105 
00106     /** Get vertex slaved flag */
00107     bool vertex_is_slaved( size_t index, MsqError& err ) const;
00108 
00109     /** Set vertex fixed flag */
00110     void fix_vertex( size_t index, bool flag, MsqError& err );
00111 
00112     /** Set vertex slaved flag */
00113     void slave_vertex( size_t index, bool flag, MsqError& err );
00114 
00115     /** Get vertex byte */
00116     unsigned char get_vertex_byte( size_t index, MsqError& err ) const;
00117 
00118     /** Set vertex byte */
00119     void set_vertex_byte( size_t index, unsigned char value, MsqError& err );
00120 
00121     /** Get element type */
00122     EntityTopology element_topology( size_t index, MsqError& err ) const;
00123 
00124     /** Set element type */
00125     void element_topology( size_t index, EntityTopology type, MsqError& err );
00126 
00127     /** Get element connectivity list, including mid-nodes */
00128     const std::vector< size_t >& element_connectivity( size_t index, MsqError& err ) const;
00129 
00130     /** Get vertex adjacency list */
00131     const std::vector< size_t >& vertex_adjacencies( size_t index, MsqError& err ) const;
00132 
00133     /** Allocate space for specified number of vertices */
00134     void allocate_vertices( size_t count, MsqError& err );
00135 
00136     /** Allocate space for specified number of elements */
00137     void allocate_elements( size_t count, MsqError& err );
00138 
00139     /** Set allocated but unset veretx to specified values */
00140     void reset_vertex( size_t index, const Vector3D& coords, bool fixed, MsqError& err );
00141 
00142     /**
00143      *  Clear element at specified index (if any) including
00144      *  connectivity and adjacency data, and re-initialize with
00145      *  passed data.
00146      */
00147     void reset_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
00148     void reset_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
00149 
00150     /** Add a new vertex */
00151     size_t add_vertex( const Vector3D& coords, bool fixed, MsqError& err );
00152     /** Add a new element */
00153     size_t add_element( const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
00154     size_t add_element( const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
00155 
00156     /** Delete a vertex - may not be referenced by any element */
00157     void delete_vertex( size_t index, MsqError& err );
00158     /** Delete an element */
00159     void delete_element( size_t index, MsqError& err );
00160 
00161     /** Get all mid-nodes and their adjacent corner vertices */
00162     void copy_higher_order( std::vector< size_t >& mid_nodes, std::vector< size_t >& vertices,
00163                             std::vector< size_t >& vertex_indices, std::vector< size_t >& index_offsets,
00164                             MsqError& err );
00165 
00166     /** \brief Get elements adjacent to ALL of the passed nodes.
00167      *
00168      * Return the list of elements that is the intersection of the
00169      * adjacency lists of the specified vertices.
00170      */
00171     void get_adjacent_elements( std::vector< size_t >::const_iterator nodes,
00172                                 std::vector< size_t >::const_iterator nodes_end, std::vector< size_t >& elems_out,
00173                                 MsqError& err );
00174 
00175     /**\brief Skin mesh
00176      *
00177      * Get the boundary of a mesh as element sides
00178      *
00179      *\param sides Element sides as pairs of values : { elem_index, side_number }
00180      */
00181     void skin( std::vector< size_t >& sides, MsqError& err );
00182 
00183     bool have_slaved_flags() const
00184     {
00185         return haveSlavedFlags;
00186     }
00187 
00188   private:
00189     /**\brief helper function for skinning
00190      *
00191      * Check if any elements adjacent to a side of an element
00192      * are of the same dimension as the input element.
00193      *\param elem  The element
00194      *\param nodes The nodes composing the side of the element
00195      */
00196     bool has_adjacent_elements( size_t elem, const std::vector< size_t >& nodes, MsqError& err );
00197 
00198     /** Clear existing element data */
00199     void clear_element( size_t index, MsqError& err );
00200 
00201     /** Set cleared element */
00202     void set_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
00203 
00204     /** Set cleared element */
00205     void set_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
00206 
00207     /** Struct holding a vertex */
00208     struct Vertex
00209     {
00210         Vertex( const Vector3D& pos, bool is_fixed )
00211             : coords( pos ), midcount( 0 ), fixed( is_fixed ), valid( true ), byte( '\0' )
00212         {
00213         }
00214 
00215         Vertex() : midcount( 0 ), valid( false ), byte( '\0' ) {}
00216 
00217         Vector3D coords;                   /**< location */
00218         std::vector< size_t > adjacencies; /**< indices of adjacent elements */
00219         unsigned midcount;                 /**< num elements referencing this as a mid-node */
00220         bool fixed;                        /**< is fixed */
00221         bool slaved;
00222         bool valid;         /**< is a valid (initialized) array entry */
00223         unsigned char byte; /**< mark */
00224     };
00225 
00226     /** Struct holding an element */
00227     struct Element
00228     {
00229         std::vector< size_t > connectivity; /**< list of vertex indices */
00230         EntityTopology topology;            /**< element type */
00231         Element() : topology( MIXED ) {}
00232     };
00233 
00234     std::vector< Vertex > vertexList;   /**< Array of vertices */
00235     std::vector< Element > elementList; /**< Array of elements */
00236 
00237     /** List of unused indices in vertex list */
00238     std::vector< size_t > deletedVertexList;
00239     /** List of unused indices in element list */
00240     std::vector< size_t > deletedElementList;
00241 
00242     bool haveSlavedFlags;
00243 };
00244 
00245 /**\brief VertexIterator for MeshImpl
00246  *
00247  * Iterate over valid vertex indices
00248  */
00249 class MeshImplVertIter : public VertexIterator
00250 {
00251   private:
00252     MeshImplData* mesh;
00253     size_t index;
00254 
00255   public:
00256     MeshImplVertIter( MeshImplData* data ) : mesh( data )
00257     {
00258         restart();
00259     }
00260 
00261     virtual ~MeshImplVertIter();
00262 
00263     virtual void restart();
00264 
00265     virtual void operator++();
00266 
00267     virtual Mesh::VertexHandle operator*() const;
00268 
00269     virtual bool is_at_end() const;
00270 };
00271 
00272 /**\brief ElementIterator for MeshImpl
00273  *
00274  * Iterate over valid element indices
00275  */
00276 class MeshImplElemIter : public ElementIterator
00277 {
00278   private:
00279     MeshImplData* mesh;
00280     size_t index;
00281 
00282   public:
00283     MeshImplElemIter( MeshImplData* data ) : mesh( data )
00284     {
00285         restart();
00286     }
00287 
00288     virtual ~MeshImplElemIter();
00289 
00290     virtual void restart();
00291 
00292     virtual void operator++();
00293 
00294     virtual Mesh::ElementHandle operator*() const;
00295 
00296     virtual bool is_at_end() const;
00297 };
00298 
00299 }  // namespace MBMesquite
00300 
00301 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines