MOAB: Mesh Oriented datABase  (version 5.3.0)
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     diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
00024     pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
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, MsqVertex* vert, size_t local_map_size, int* local_map,
00091                                               MsqError& err ) const;
00092     //! gets the vertices of the mesh entity
00093     void get_node_indices( std::vector< std::size_t >& vertex_list ) const;
00094     void append_node_indices( std::vector< std::size_t >& vertex_list ) const;
00095     //! Very efficient retrieval of vertices indexes
00096     //! (corresponding to the PatchData vertex array).
00097     inline const std::size_t* get_vertex_index_array() const;
00098     inline std::size_t* get_vertex_index_array();
00099 
00100     //! Sets element data
00101     void set_element_type( EntityTopology type )
00102     {
00103         mType = type;
00104     }
00105 
00106     //! Set connectivity data (vertex array) for element.
00107     //! MsqMeshEntity keeps the pointer to the passed array, it
00108     //! does not copy it.  The caller is still responsible for
00109     //! releasing the memory for the passed index array after
00110     //! the MsqMeshEntity is destroyed.  The intention is that
00111     //! this is a pointer to a portion of a larger connectivity array
00112     //! managed by the owning PatchData.
00113     void set_connectivity( std::size_t* indices, size_t num_vertices );
00114 
00115     std::size_t get_vertex_index( std::size_t vertex_in_element ) const;
00116 
00117     //! Returns the centroid of the element.
00118     void get_centroid( Vector3D& centroid, const PatchData& pd, MsqError& err ) const;
00119 
00120     //! Fills a vector<size_t> with vertices connected to the given
00121     //! vertex through the edges of this MsqMeshEntity.
00122     void get_connected_vertices( std::size_t vertex_index, std::vector< std::size_t >& vert_indices, MsqError& err );
00123 
00124     //! Computes the area of the element.
00125     //! The returned value is always non-negative.
00126     double compute_unsigned_area( PatchData& pd, MsqError& err );
00127 
00128     //! Computes the signed area of the element.
00129     double compute_signed_area( PatchData& pd, MsqError& err );
00130 
00131     //! Check sign of the determinant mapping fuction Jacobian
00132     //! at representative sample points in the element.
00133     //!\param inverted_count  Number of sampling locations within the
00134     //!                       element for which the determinant of the
00135     //!                       mapping function Jacobian was negative.
00136     //!\param tested_count    The number of sampling locations in the
00137     //!                       element for which the Jacobian was tested.
00138     void check_element_orientation( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
00139     void check_element_orientation_corners( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
00140 
00141     //! Uses a MeshDomain call-back function to compute the normal at the corner.
00142     // void compute_corner_normal( std::size_t corner_pt,
00143     //                            Vector3D &normal,
00144     //                            PatchData &pd,
00145     //                            MsqError &err);
00146     void compute_corner_normals( Vector3D normals[], PatchData& pd, MsqError& err );
00147 
00148     //! Get NodeSet indicating all nodes present for this element type.
00149     NodeSet all_nodes( MsqError& err ) const;
00150 
00151   private:
00152     //! Check for a negative Jacobian at the specified sample point
00153     //! of a volume element.
00154     bool inverted_jacobian_3d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
00155 
00156     //! Check for a negative Jacobian at the specified sample point
00157     //! of a surface element.
00158     bool inverted_jacobian_2d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
00159 
00160     EntityTopology mType;
00161     /** Pointer to connectivity array.
00162      *  NOTE: The memory occupied by this array is assumed to be
00163      *        owned/managed by the owning PatchData.  Do not try
00164      *        to delete/resize/etc. this array directly!
00165      */
00166     size_t* vertexIndices;
00167     size_t numVertexIndices;
00168 
00169     // output operator for debugging.
00170     friend std::ostream& operator<<( std::ostream& stream, const MsqMeshEntity& entity );
00171 };
00172 
00173 // Returns the number of vertices in this type
00174 // of element, or 0 if a variable number.
00175 inline size_t MsqMeshEntity::vertex_count() const
00176 {
00177     return mType == POLYGON || mType == POLYHEDRON ? node_count() : TopologyInfo::corners( mType );
00178 }
00179 
00180 inline void MsqMeshEntity::set_connectivity( std::size_t* indices, size_t num_vertices )
00181 {
00182     vertexIndices    = indices;
00183     numVertexIndices = num_vertices;
00184 }
00185 
00186 inline const std::size_t* MsqMeshEntity::get_vertex_index_array() const
00187 {
00188     return vertexIndices;
00189 }
00190 
00191 inline std::size_t* MsqMeshEntity::get_vertex_index_array()
00192 {
00193     return vertexIndices;
00194 }
00195 
00196 inline std::size_t MsqMeshEntity::get_vertex_index( std::size_t vertex_in_element ) const
00197 {
00198     // Make sure we're in range
00199     assert( vertex_in_element < vertex_count() );
00200     // Return the index
00201     return vertexIndices[vertex_in_element];
00202 }
00203 }  // namespace MBMesquite
00204 
00205 #endif  // MsqMeshEntity_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines