MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /** 00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating, 00003 * storing and accessing finite element mesh data. 00004 * 00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract 00006 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00007 * retains certain 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 */ 00015 00016 #ifndef SWEPT_ELEMENT_DATA_HPP 00017 #define SWEPT_ELEMENT_DATA_HPP 00018 00019 // 00020 // Class: SweptElementData 00021 // 00022 // Purpose: represent a rectangular element of mesh 00023 // 00024 // A SweptElement represents a rectangular element of mesh, including both vertices and 00025 // elements, and the parametric space used to address that element. Vertex data, 00026 // i.e. coordinates, may not be stored directly in the element, but the element returns 00027 // information about the vertex handles of vertices in the element. Vertex and element 00028 // handles associated with the element are each contiguous. 00029 00030 #include "SequenceData.hpp" 00031 #include "moab/HomXform.hpp" 00032 #include "moab/CN.hpp" 00033 #include "SweptVertexData.hpp" 00034 #include "Internals.hpp" 00035 #include "moab/Range.hpp" 00036 00037 #include <vector> 00038 #include <algorithm> 00039 00040 namespace moab 00041 { 00042 00043 class SweptElementData : public SequenceData 00044 { 00045 00046 //! structure to hold references to bounding vertex blocks 00047 class VertexDataRef 00048 { 00049 private: 00050 HomCoord minmax[2]; 00051 HomXform xform, invXform; 00052 SweptVertexData* srcSeq; 00053 00054 public: 00055 friend class SweptElementData; 00056 00057 VertexDataRef( const HomCoord& min, const HomCoord& max, const HomXform& tmp_xform, SweptVertexData* this_seq ); 00058 00059 bool contains( const HomCoord& coords ) const; 00060 }; 00061 00062 private: 00063 //! parameter min/max/stride, in homogeneous coords ijkh 00064 HomCoord elementParams[3]; 00065 00066 //! difference between max and min params plus one (i.e. # VERTICES in 00067 //! each parametric direction) 00068 int dIJK[3]; 00069 00070 //! difference between max and min params (i.e. # ELEMENTS in 00071 //! each parametric direction) 00072 int dIJKm1[3]; 00073 00074 //! bare constructor, so compiler doesn't create one for me 00075 SweptElementData(); 00076 00077 //! list of bounding vertex blocks 00078 std::vector< VertexDataRef > vertexSeqRefs; 00079 00080 public: 00081 //! constructor 00082 SweptElementData( EntityHandle start_handle, const int imin, const int jmin, const int kmin, const int imax, 00083 const int jmax, const int kmax, const int* Cq ); 00084 00085 virtual ~SweptElementData(); 00086 00087 //! get handle of vertex at homogeneous coords 00088 inline EntityHandle get_vertex( const HomCoord& coords ) const; 00089 inline EntityHandle get_vertex( int i, int j, int k ) const 00090 { 00091 return get_vertex( HomCoord( i, j, k ) ); 00092 } 00093 00094 //! get handle of element at i, j, k 00095 EntityHandle get_element( const int i, const int j, const int k ) const; 00096 00097 //! get min params for this element 00098 const HomCoord& min_params() const; 00099 00100 //! get max params for this element 00101 const HomCoord& max_params() const; 00102 00103 //! get the number of vertices in each direction, inclusive 00104 void param_extents( int& di, int& dj, int& dk ) const; 00105 00106 //! given a handle, get the corresponding parameters 00107 ErrorCode get_params( const EntityHandle ehandle, int& i, int& j, int& k ) const; 00108 00109 //! convenience functions for parameter extents 00110 int i_min() const 00111 { 00112 return ( elementParams[0].hom_coord() )[0]; 00113 } 00114 int j_min() const 00115 { 00116 return ( elementParams[0].hom_coord() )[1]; 00117 } 00118 int k_min() const 00119 { 00120 return ( elementParams[0].hom_coord() )[2]; 00121 } 00122 int i_max() const 00123 { 00124 return ( elementParams[1].hom_coord() )[0]; 00125 } 00126 int j_max() const 00127 { 00128 return ( elementParams[1].hom_coord() )[1]; 00129 } 00130 int k_max() const 00131 { 00132 return ( elementParams[1].hom_coord() )[2]; 00133 } 00134 00135 //! test the bounding vertex sequences and determine whether they fully 00136 //! define the vertices covering this element block's parameter space 00137 bool boundary_complete() const; 00138 00139 //! test whether this sequence contains these parameters 00140 inline bool contains( const HomCoord& coords ) const; 00141 00142 //! get connectivity of an entity given entity's parameters 00143 inline ErrorCode get_params_connectivity( const int i, const int j, const int k, 00144 std::vector< EntityHandle >& connectivity ) const; 00145 00146 //! add a vertex seq ref to this element sequence; 00147 //! if bb_input is true, bounding box (in eseq-local coords) of vseq being added 00148 //! is input in bb_min and bb_max (allows partial sharing of vseq rather than the whole 00149 //! vseq); if it's false, the whole vseq is referenced and the eseq-local coordinates 00150 //! is computed from the transformed bounding box of the vseq 00151 ErrorCode add_vsequence( SweptVertexData* vseq, const HomCoord& p1, const HomCoord& q1, const HomCoord& p2, 00152 const HomCoord& q2, const HomCoord& p3, const HomCoord& q3, bool bb_input = false, 00153 const HomCoord& bb_min = HomCoord::unitv[0], const HomCoord& bb_max = HomCoord::unitv[0] ); 00154 00155 SequenceData* subset( EntityHandle start, EntityHandle end, const int* sequence_data_sizes, 00156 const int* tag_data_sizes ) const; 00157 00158 static EntityID calc_num_entities( EntityHandle start_handle, int irange, int jrange, int krange ); 00159 00160 unsigned long get_memory_use() const; 00161 }; 00162 00163 inline EntityHandle SweptElementData::get_element( const int i, const int j, const int k ) const 00164 { 00165 return start_handle() + ( i - i_min() ) + ( j - j_min() ) * dIJKm1[0] + ( k - k_min() ) * dIJKm1[0] * dIJKm1[1]; 00166 } 00167 00168 inline const HomCoord& SweptElementData::min_params() const 00169 { 00170 return elementParams[0]; 00171 } 00172 00173 inline const HomCoord& SweptElementData::max_params() const 00174 { 00175 return elementParams[1]; 00176 } 00177 00178 //! get the number of vertices in each direction, inclusive 00179 inline void SweptElementData::param_extents( int& di, int& dj, int& dk ) const 00180 { 00181 di = dIJK[0]; 00182 dj = dIJK[1]; 00183 dk = dIJK[2]; 00184 } 00185 00186 inline ErrorCode SweptElementData::get_params( const EntityHandle ehandle, int& i, int& j, int& k ) const 00187 { 00188 if( TYPE_FROM_HANDLE( ehandle ) != TYPE_FROM_HANDLE( start_handle() ) ) return MB_FAILURE; 00189 00190 int hdiff = ehandle - start_handle(); 00191 00192 // use double ?: test below because on some platforms, both sides of the : are 00193 // evaluated, and if dIJKm1[1] is zero, that'll generate a divide-by-zero 00194 k = ( dIJKm1[1] > 0 ? hdiff / ( dIJKm1[1] > 0 ? dIJKm1[0] * dIJKm1[1] : 1 ) : 0 ); 00195 j = ( hdiff - ( k * dIJKm1[0] * dIJKm1[1] ) ) / dIJKm1[0]; 00196 i = hdiff % dIJKm1[0]; 00197 00198 k += elementParams[0].k(); 00199 j += elementParams[0].j(); 00200 i += elementParams[0].i(); 00201 00202 return ( ehandle >= start_handle() && ehandle < start_handle() + size() && i >= i_min() && i <= i_max() && 00203 j >= j_min() && j <= j_max() && k >= k_min() && k <= k_max() ) 00204 ? MB_SUCCESS 00205 : MB_FAILURE; 00206 } 00207 00208 inline bool SweptElementData::contains( const HomCoord& temp ) const 00209 { 00210 // upper bound is < instead of <= because element params max is one less 00211 // than vertex params max 00212 return ( temp >= elementParams[0] && temp < elementParams[1] ); 00213 } 00214 00215 inline bool SweptElementData::VertexDataRef::contains( const HomCoord& coords ) const 00216 { 00217 return ( minmax[0] <= coords && minmax[1] >= coords ); 00218 } 00219 00220 inline SweptElementData::VertexDataRef::VertexDataRef( const HomCoord& this_min, const HomCoord& this_max, 00221 const HomXform& tmp_xform, SweptVertexData* this_seq ) 00222 : xform( tmp_xform ), invXform( tmp_xform.inverse() ), srcSeq( this_seq ) 00223 { 00224 minmax[0] = HomCoord( this_min ); 00225 minmax[1] = HomCoord( this_max ); 00226 } 00227 00228 inline EntityHandle SweptElementData::get_vertex( const HomCoord& coords ) const 00229 { 00230 assert( boundary_complete() ); 00231 for( std::vector< VertexDataRef >::const_iterator it = vertexSeqRefs.begin(); it != vertexSeqRefs.end(); ++it ) 00232 { 00233 if( ( *it ).minmax[0] <= coords && ( *it ).minmax[1] >= coords ) 00234 { 00235 // first get the vertex block-local parameters 00236 HomCoord local_coords = coords / ( *it ).xform; 00237 00238 // now get the vertex handle for those coords 00239 return ( *it ).srcSeq->get_vertex( local_coords ); 00240 } 00241 } 00242 00243 // got here, it's an error 00244 return 0; 00245 } 00246 00247 inline ErrorCode SweptElementData::add_vsequence( SweptVertexData* vseq, const HomCoord& p1, const HomCoord& q1, 00248 const HomCoord& p2, const HomCoord& q2, const HomCoord& p3, 00249 const HomCoord& q3, bool bb_input, const HomCoord& bb_min, 00250 const HomCoord& bb_max ) 00251 { 00252 // compute the transform given the vseq-local parameters and the mapping to 00253 // this element sequence's parameters passed in minmax 00254 HomXform M; 00255 M.three_pt_xform( p1, q1, p2, q2, p3, q3 ); 00256 00257 // min and max in element seq's parameter system may not be same as those in 00258 // vseq's system, so need to take min/max 00259 00260 HomCoord minmax[2]; 00261 if( bb_input ) 00262 { 00263 minmax[0] = bb_min; 00264 minmax[1] = bb_max; 00265 } 00266 else 00267 { 00268 minmax[0] = vseq->min_params() * M; 00269 minmax[1] = vseq->max_params() * M; 00270 } 00271 00272 // check against other vseq's to make sure they don't overlap 00273 for( std::vector< VertexDataRef >::const_iterator vsit = vertexSeqRefs.begin(); vsit != vertexSeqRefs.end(); 00274 ++vsit ) 00275 if( ( *vsit ).contains( minmax[0] ) || ( *vsit ).contains( minmax[1] ) ) return MB_FAILURE; 00276 00277 HomCoord tmp_min( std::min( minmax[0].i(), minmax[1].i() ), std::min( minmax[0].j(), minmax[1].j() ), 00278 std::min( minmax[0].k(), minmax[1].k() ) ); 00279 HomCoord tmp_max( std::max( minmax[0].i(), minmax[1].i() ), std::max( minmax[0].j(), minmax[1].j() ), 00280 std::max( minmax[0].k(), minmax[1].k() ) ); 00281 00282 // set up a new vertex sequence reference 00283 VertexDataRef tmp_seq_ref( tmp_min, tmp_max, M, vseq ); 00284 00285 // add to the list 00286 vertexSeqRefs.push_back( tmp_seq_ref ); 00287 00288 return MB_SUCCESS; 00289 } 00290 00291 inline ErrorCode SweptElementData::get_params_connectivity( const int i, const int j, const int k, 00292 std::vector< EntityHandle >& connectivity ) const 00293 { 00294 if( contains( HomCoord( i, j, k ) ) == false ) return MB_FAILURE; 00295 00296 connectivity.push_back( get_vertex( i, j, k ) ); 00297 connectivity.push_back( get_vertex( i + 1, j, k ) ); 00298 if( CN::Dimension( TYPE_FROM_HANDLE( start_handle() ) ) < 2 ) return MB_SUCCESS; 00299 connectivity.push_back( get_vertex( i + 1, j + 1, k ) ); 00300 connectivity.push_back( get_vertex( i, j + 1, k ) ); 00301 if( CN::Dimension( TYPE_FROM_HANDLE( start_handle() ) ) < 3 ) return MB_SUCCESS; 00302 connectivity.push_back( get_vertex( i, j, k + 1 ) ); 00303 connectivity.push_back( get_vertex( i + 1, j, k + 1 ) ); 00304 connectivity.push_back( get_vertex( i + 1, j + 1, k + 1 ) ); 00305 connectivity.push_back( get_vertex( i, j + 1, k + 1 ) ); 00306 return MB_SUCCESS; 00307 } 00308 00309 } // namespace moab 00310 00311 #endif