Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2004 Sandia Corporation and Argonne National
5 : : Laboratory. Under the terms of Contract DE-AC04-94AL85000
6 : : with Sandia Corporation, the U.S. Government retains certain
7 : : rights in this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : [email protected], [email protected], [email protected],
24 : : [email protected], [email protected], [email protected]
25 : :
26 : : ***************************************************************** */
27 : :
28 : : /*! \file MsqMeshEntity.hpp
29 : :
30 : : \author Darryl Melander
31 : : \author Thomas Leurent
32 : : \author Michael Brewer
33 : :
34 : : */
35 : :
36 : : #ifndef MSQMESHENTITY_HPP
37 : : #define MSQMESHENTITY_HPP
38 : :
39 : : #include "Mesquite.hpp"
40 : : #include "TopologyInfo.hpp"
41 : : #include "Vector3D.hpp"
42 : : #include "NodeSet.hpp"
43 : : #include "Sample.hpp"
44 : :
45 : : #include <vector>
46 : : #include <cstring>
47 : : #include <cassert>
48 : :
49 : : namespace MBMesquite
50 : : {
51 : : class PatchData;
52 : : class MsqVertex;
53 : :
54 : : /*!
55 : : \class MsqMeshEntity
56 : : \brief MsqMeshEntity is the Mesquite object that stores information about
57 : : the elements in the mesh.
58 : :
59 : :
60 : : */
61 : : class MESQUITE_EXPORT MsqMeshEntity
62 : : {
63 : : public:
64 : 185332 : MsqMeshEntity() : mType( MIXED ), vertexIndices( 0 ), numVertexIndices( 0 ) {}
65 : :
66 : : //! Returns element type
67 : 139980233 : inline EntityTopology get_element_type() const
68 : : {
69 : 139980233 : return mType;
70 : : }
71 : :
72 : : //! Returns the number of vertices in this element,
73 : : //! based on its element type.
74 : : inline std::size_t vertex_count() const;
75 : : //! Return number of nodes in element (number of corner
76 : : //! vertices + number of higher-order nodes).
77 : 123461058 : inline std::size_t node_count() const
78 : : {
79 : 123461058 : return numVertexIndices;
80 : : }
81 : : //! Returns number of target matrices for this element type
82 : 0 : inline std::size_t corner_count() const
83 : : {
84 [ # # ]: 0 : return mType == PYRAMID ? 4 : vertex_count();
85 : : }
86 : :
87 : : //! gets the vertices of the mesh entity
88 : : void get_vertex_indices( std::vector< std::size_t >& vertex_list ) const;
89 : : void append_vertex_indices( std::vector< std::size_t >& vertex_list ) const;
90 : : size_t get_local_matrix_map_about_vertex( PatchData& pd, MsqVertex* vert, size_t local_map_size, int* local_map,
91 : : MsqError& err ) const;
92 : : //! gets the vertices of the mesh entity
93 : : void get_node_indices( std::vector< std::size_t >& vertex_list ) const;
94 : : void append_node_indices( std::vector< std::size_t >& vertex_list ) const;
95 : : //! Very efficient retrieval of vertices indexes
96 : : //! (corresponding to the PatchData vertex array).
97 : : inline const std::size_t* get_vertex_index_array() const;
98 : : inline std::size_t* get_vertex_index_array();
99 : :
100 : : //! Sets element data
101 : 3940880 : void set_element_type( EntityTopology type )
102 : : {
103 : 3940880 : mType = type;
104 : 3940880 : }
105 : :
106 : : //! Set connectivity data (vertex array) for element.
107 : : //! MsqMeshEntity keeps the pointer to the passed array, it
108 : : //! does not copy it. The caller is still responsible for
109 : : //! releasing the memory for the passed index array after
110 : : //! the MsqMeshEntity is destroyed. The intention is that
111 : : //! this is a pointer to a portion of a larger connectivity array
112 : : //! managed by the owning PatchData.
113 : : void set_connectivity( std::size_t* indices, size_t num_vertices );
114 : :
115 : : std::size_t get_vertex_index( std::size_t vertex_in_element ) const;
116 : :
117 : : //! Returns the centroid of the element.
118 : : void get_centroid( Vector3D& centroid, const PatchData& pd, MsqError& err ) const;
119 : :
120 : : //! Fills a vector<size_t> with vertices connected to the given
121 : : //! vertex through the edges of this MsqMeshEntity.
122 : : void get_connected_vertices( std::size_t vertex_index, std::vector< std::size_t >& vert_indices, MsqError& err );
123 : :
124 : : //! Computes the area of the element.
125 : : //! The returned value is always non-negative.
126 : : double compute_unsigned_area( PatchData& pd, MsqError& err );
127 : :
128 : : //! Computes the signed area of the element.
129 : : double compute_signed_area( PatchData& pd, MsqError& err );
130 : :
131 : : //! Check sign of the determinant mapping fuction Jacobian
132 : : //! at representative sample points in the element.
133 : : //!\param inverted_count Number of sampling locations within the
134 : : //! element for which the determinant of the
135 : : //! mapping function Jacobian was negative.
136 : : //!\param tested_count The number of sampling locations in the
137 : : //! element for which the Jacobian was tested.
138 : : void check_element_orientation( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
139 : : void check_element_orientation_corners( PatchData& pd, int& inverted_count, int& tested_count, MsqError& err );
140 : :
141 : : //! Uses a MeshDomain call-back function to compute the normal at the corner.
142 : : // void compute_corner_normal( std::size_t corner_pt,
143 : : // Vector3D &normal,
144 : : // PatchData &pd,
145 : : // MsqError &err);
146 : : void compute_corner_normals( Vector3D normals[], PatchData& pd, MsqError& err );
147 : :
148 : : //! Get NodeSet indicating all nodes present for this element type.
149 : : NodeSet all_nodes( MsqError& err ) const;
150 : :
151 : : private:
152 : : //! Check for a negative Jacobian at the specified sample point
153 : : //! of a volume element.
154 : : bool inverted_jacobian_3d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
155 : :
156 : : //! Check for a negative Jacobian at the specified sample point
157 : : //! of a surface element.
158 : : bool inverted_jacobian_2d( PatchData& pd, NodeSet nodes, Sample sample, MsqError& err );
159 : :
160 : : EntityTopology mType;
161 : : /** Pointer to connectivity array.
162 : : * NOTE: The memory occupied by this array is assumed to be
163 : : * owned/managed by the owning PatchData. Do not try
164 : : * to delete/resize/etc. this array directly!
165 : : */
166 : : size_t* vertexIndices;
167 : : size_t numVertexIndices;
168 : :
169 : : // output operator for debugging.
170 : : friend std::ostream& operator<<( std::ostream& stream, const MsqMeshEntity& entity );
171 : : };
172 : :
173 : : // Returns the number of vertices in this type
174 : : // of element, or 0 if a variable number.
175 : 2600999 : inline size_t MsqMeshEntity::vertex_count() const
176 : : {
177 [ + - ][ - + ]: 2600999 : return mType == POLYGON || mType == POLYHEDRON ? node_count() : TopologyInfo::corners( mType );
178 : : }
179 : :
180 : 3940880 : inline void MsqMeshEntity::set_connectivity( std::size_t* indices, size_t num_vertices )
181 : : {
182 : 3940880 : vertexIndices = indices;
183 : 3940880 : numVertexIndices = num_vertices;
184 : 3940880 : }
185 : :
186 : 79769119 : inline const std::size_t* MsqMeshEntity::get_vertex_index_array() const
187 : : {
188 : 79769119 : return vertexIndices;
189 : : }
190 : :
191 : 35202556 : inline std::size_t* MsqMeshEntity::get_vertex_index_array()
192 : : {
193 : 35202556 : return vertexIndices;
194 : : }
195 : :
196 : 1635120 : inline std::size_t MsqMeshEntity::get_vertex_index( std::size_t vertex_in_element ) const
197 : : {
198 : : // Make sure we're in range
199 [ - + ]: 1635120 : assert( vertex_in_element < vertex_count() );
200 : : // Return the index
201 : 1635120 : return vertexIndices[vertex_in_element];
202 : : }
203 : : } // namespace MBMesquite
204 : :
205 : : #endif // MsqMeshEntity_hpp
|