MOAB: Mesh Oriented datABase  (version 5.4.1)
MsqMeshEntity.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government 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     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 
00028 /*! \file MsqMeshEntity.hpp
00029 
00030 \author Darryl Melander
00031 \author Thomas Leurent
00032 \author Michael Brewer
00033 
00034 */
00035 
00036 #ifndef MSQMESHENTITY_HPP
00037 #define MSQMESHENTITY_HPP
00038 
00039 #include "Mesquite.hpp"
00040 #include "TopologyInfo.hpp"
00041 #include "Vector3D.hpp"
00042 #include "NodeSet.hpp"
00043 #include "Sample.hpp"
00044 
00045 #include <vector>
00046 #include <cstring>
00047 #include <cassert>
00048 
00049 namespace MBMesquite
00050 {
00051 class PatchData;
00052 class MsqVertex;
00053 
00054 /*!
00055     \class MsqMeshEntity
00056     \brief MsqMeshEntity is the Mesquite object that stores information about
00057     the elements in the mesh.
00058 
00059 
00060 */
00061 class MESQUITE_EXPORT MsqMeshEntity
00062 {
00063   public:
00064     MsqMeshEntity() : mType( MIXED ), vertexIndices( 0 ), numVertexIndices( 0 ) {}
00065 
00066     //! Returns element type
00067     inline EntityTopology get_element_type() const
00068     {
00069         return mType;
00070     }
00071 
00072     //! Returns the number of vertices in this element,
00073     //! based on its element type.
00074     inline std::size_t vertex_count() const;
00075     //! Return number of nodes in element (number of corner
00076     //! vertices + number of higher-order nodes).
00077     inline std::size_t node_count() const
00078     {
00079         return numVertexIndices;
00080     }
00081     //! Returns number of target matrices for this element type
00082     inline std::size_t corner_count() const
00083     {
00084         return mType == PYRAMID ? 4 : vertex_count();
00085     }
00086 
00087     //! gets the vertices of the mesh entity
00088     void get_vertex_indices( std::vector< std::size_t >& vertex_list ) const;
00089     void append_vertex_indices( std::vector< std::size_t >& vertex_list ) const;
00090     size_t get_local_matrix_map_about_vertex( PatchData& pd,
00091                                               MsqVertex* vert,
00092                                               size_t local_map_size,
00093                                               int* local_map,
00094                                               MsqError& err ) const;
00095     //! gets the vertices of the mesh entity
00096     void get_node_indices( std::vector< std::size_t >& vertex_list ) const;
00097     void append_node_indices( std::vector< std::size_t >& vertex_list ) const;
00098     //! Very efficient retrieval of vertices indexes
00099     //! (corresponding to the PatchData vertex array).
00100     inline const std::size_t* get_vertex_index_array() const;
00101     inline std::size_t* get_vertex_index_array();
00102 
00103     //! Sets element data
00104     void set_element_type( EntityTopology type )
00105     {
00106         mType = type;
00107     }
00108 
00109     //! Set connectivity data (vertex array) for element.
00110     //! MsqMeshEntity keeps the pointer to the passed array, it
00111     //! does not copy it.  The caller is still responsible for
00112     //! releasing the memory for the passed index array after
00113     //! the MsqMeshEntity is destroyed.  The intention is that
00114     //! this is a pointer to a portion of a larger connectivity array
00115     //! managed by the owning PatchData.
00116     void set_connectivity( std::size_t* indices, size_t num_vertices );
00117 
00118     std::size_t get_vertex_index( std::size_t vertex_in_element ) const;
00119 
00120     //! Returns the centroid of the element.
00121     void get_centroid( Vector3D& centroid, const PatchData& pd, MsqError& err ) const;
00122 
00123     //! Fills a vector<size_t> with vertices connected to the given
00124     //! vertex through the edges of this MsqMeshEntity.
00125     void get_connected_vertices( std::size_t vertex_index, std::vector< std::size_t >& vert_indices, MsqError& err );
00126 
00127     //! Computes the area of the element.
00128     //! The returned value is always non-negative.
00129     double compute_unsigned_area( PatchData& pd, MsqError& err );
00130 
00131     //! Computes the signed area of the element.
00132     double compute_signed_area( PatchData& pd, MsqError& err );
00133 
00134     //! Check sign of the determinant mapping fuction Jacobian
00135     //! at representative sample points in the element.
00136     //!\param inverted_count  Number of sampling locations within the
00137     //!                       element for which the determinant of the
00138     //!                       mapping function Jacobian was negative.
00139     //!\param tested_count    The number of sampling locations in the
00140     //!                       element for which the Jacobian was tested.
00141     void check_element_orientation( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
00142     void check_element_orientation_corners( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
00143 
00144     //! Uses a MeshDomain call-back function to compute the normal at the corner.
00145     // void compute_corner_normal( std::size_t corner_pt,
00146     //                            Vector3D &normal,
00147     //                            PatchData &pd,
00148     //                            MsqError &err);
00149     void compute_corner_normals( Vector3D normals[], PatchData& pd, MsqError& err );
00150 
00151     //! Get NodeSet indicating all nodes present for this element type.
00152     NodeSet all_nodes( MsqError& err ) const;
00153 
00154   private:
00155     //! Check for a negative Jacobian at the specified sample point
00156     //! of a volume element.
00157     bool inverted_jacobian_3d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
00158 
00159     //! Check for a negative Jacobian at the specified sample point
00160     //! of a surface element.
00161     bool inverted_jacobian_2d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
00162 
00163     EntityTopology mType;
00164     /** Pointer to connectivity array.
00165      *  NOTE: The memory occupied by this array is assumed to be
00166      *        owned/managed by the owning PatchData.  Do not try
00167      *        to delete/resize/etc. this array directly!
00168      */
00169     size_t* vertexIndices;
00170     size_t numVertexIndices;
00171 
00172     // output operator for debugging.
00173     friend std::ostream& operator<<( std::ostream& stream, const MsqMeshEntity& entity );
00174 };
00175 
00176 // Returns the number of vertices in this type
00177 // of element, or 0 if a variable number.
00178 inline size_t MsqMeshEntity::vertex_count() const
00179 {
00180     return mType == POLYGON || mType == POLYHEDRON ? node_count() : TopologyInfo::corners( mType );
00181 }
00182 
00183 inline void MsqMeshEntity::set_connectivity( std::size_t* indices, size_t num_vertices )
00184 {
00185     vertexIndices    = indices;
00186     numVertexIndices = num_vertices;
00187 }
00188 
00189 inline const std::size_t* MsqMeshEntity::get_vertex_index_array() const
00190 {
00191     return vertexIndices;
00192 }
00193 
00194 inline std::size_t* MsqMeshEntity::get_vertex_index_array()
00195 {
00196     return vertexIndices;
00197 }
00198 
00199 inline std::size_t MsqMeshEntity::get_vertex_index( std::size_t vertex_in_element ) const
00200 {
00201     // Make sure we're in range
00202     assert( vertex_in_element < vertex_count() );
00203     // Return the index
00204     return vertexIndices[vertex_in_element];
00205 }
00206 }  // namespace MBMesquite
00207 
00208 #endif  // MsqMeshEntity_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines