elem/Tri3.cpp

00001 #include "DAPTA.hpp"
00002 
00003 namespace DAPTA { // Define namespace DAPTA
00004 
00005 /*
00006 Tri3<V>::Tri3(VertexHandle i, VertexHandle j, VertexHandle k)
00007 */
00008 template <typename V>
00009 Tri3<V>::Tri3(VertexHandle i, VertexHandle j, VertexHandle k) {
00010    assert(i != NULL);
00011    assert(j != NULL);
00012    assert(k != NULL);
00013 
00014    for(int x=0; x<4; x++)
00015       vertices.at(x) = NULL;
00016 
00017    vertices.at(0) = i;
00018    vertices.at(1) = j;
00019    vertices.at(2) = k;
00020       
00021    for(int x=0; x<num_adjacents; x++) {
00022       adjacents.at(x) = NULL;
00023       coh_adjacents.at(x) = NULL;
00024    }
00025    
00026    globalID = 0;
00027 };
00028 
00029 /*
00030 Tri3<V>::Tri3(boost::array<VertexHandle, num_vertices> nodes)
00031 */
00032 template <typename V>
00033 Tri3<V>::Tri3(boost::array<VertexHandle, num_vertices> nodes) {
00034    for(int i=0; i<num_vertices; i++) {
00035       assert(nodes.at(i) != NULL);
00036       vertices.at(i) = nodes.at(i);
00037    }
00038    
00039    for(int x=0; x<num_adjacents; x++) {
00040       adjacents.at(x) = NULL;
00041       coh_adjacents.at(x) = NULL;
00042    }
00043    
00044    globalID = 0;
00045 }
00046 
00047 /*
00048 int Tri3<V>::FindVertex(VertexHandle v)
00049 Returns the index in the vertices vector where v is located.
00050 */
00051 template <typename V>
00052 int Tri3<V>::FindVertex(VertexHandle v) {
00053    assert(v != NULL);
00054    
00055    int j=0;
00056    while(j<vertices.size() && vertices.at(j)!=v)
00057       j++;
00058    return j;
00059 }
00060 
00061 /*
00062 bool Tri3<V>::IsBoundaryNode(VertexHandle v1)
00063 */
00064 template <typename V>
00065 bool Tri3<V>::IsBoundaryNode(VertexHandle v1) {
00066    return this->IsBoundaryNode(FindVertex(v1));
00067 }
00068 
00069 /*
00070 bool Tri3<V>::IsBoundaryNode(int v1)
00071 */
00072 template <typename V>
00073 bool Tri3<V>::IsBoundaryNode(int v1) {
00074    assert(v1 < vertices.size());
00075 
00076    // Start iterating round with this tetra
00077    ElementHandle cur_tri = this;
00078 
00079    // Choose a direction to go round in
00080    int next_face=0;
00081    while(next_face == v1)
00082       next_face++;
00083 
00084    do {
00085       if((cur_tri->adjacents.at(next_face) == NULL) || (cur_tri->coh_adjacents.at(next_face) != NULL)) {
00086          // If we've found a boundary face then return true
00087          // Boundary is if there's a cohesive element there, or if there isn't any element there
00088          return true;
00089       }
00090       cur_tri = cur_tri->NextTriOnNode(v1, next_face);
00091    } while(cur_tri != this);
00092    
00093    // We didn't find a boundary face, so this isn't a boundary edge
00094    return false;
00095 }
00096 
00097 /*
00098 bool Tri3<V>::IsBoundaryEdge(VertexHandle v1, VertexHandle v2)
00099 */
00100 template <typename V>
00101 bool Tri3<V>::IsBoundaryEdge(VertexHandle v1, VertexHandle v2) {
00102    return this->IsBoundaryEdge(FindVertex(v1), FindVertex(v2));
00103 }
00104 
00105 /*
00106 bool Tri3<V>::IsBoundaryEdge(int v1, int v2)
00107 */
00108 template <typename V>
00109 bool Tri3<V>::IsBoundaryEdge(int v1, int v2) {
00110    if((this->adjacents.at(this->FaceToVertex(v1, v2)) == NULL) || (this->coh_adjacents.at(this->FaceToVertex(v1, v2)) != NULL))
00111       return true;
00112    else
00113       return false;
00114 }
00115 
00116 /*
00117 typename Tri3<V>::ElementHandle Tri3<V>::NextTriOnNode(int &v1, int &f)
00118 Update v1 and f indexes and return pointer to the next tri along when iterating
00119 around a node defined by v1 going in the direction of f.
00120 */
00121 template <typename V>
00122 typename Tri3<V>::ElementHandle Tri3<V>::NextTriOnNode(int &v1, int &f) {
00123    ElementHandle new_tri = adjacents.at(f);
00124 
00125    assert(new_tri != NULL);
00126    
00127    int new_f=this->FaceToVertex(v1, f);
00128 
00129    VertexHandle v1_vertex, new_f_vertex;
00130    v1_vertex = this->vertices.at(v1);
00131    new_f_vertex = this->vertices.at(new_f);
00132 
00133    v1 = new_tri->FindVertex(v1_vertex);
00134    f = new_tri->FindVertex(new_f_vertex);
00135    
00136    assert(v1 < new_tri->vertices.size());
00137    assert(f < new_tri->vertices.size());
00138    
00139    return new_tri;
00140 }
00141 
00142 /*
00143 int Tri3<V>::FaceToVertex(VertexHandle v1, VertexHandle v2)
00144 */
00145 template <typename V>
00146 int Tri3<V>::FaceToVertex(VertexHandle v1, VertexHandle v2) {
00147    return this->FaceToVertex(FindVertex(v1), FindVertex(v2));
00148 }
00149 
00150 /*
00151 int Tri3<V>::FaceToVertex(int v1, int v2)
00152 */
00153 template <typename V>
00154 int Tri3<V>::FaceToVertex(int v1, int v2) {
00155    int ret = 0;
00156    while((v1 == ret) || (v2 == ret))
00157       ret++;
00158    return ret;
00159 }
00160 
00161 /*
00162 int Tri3<V>::FaceToVertex(boost::array<VertexHandle, 2> vs)
00163 Return the index of the vertex defining the face defined by v1, v2 and v3
00164 */
00165 template <typename V>
00166 int Tri3<V>::FaceToVertex(boost::array<VertexHandle, 2> vs) {
00167    return this->FaceToVertex(vs.at(0), vs.at(1));
00168 }
00169 
00170 /*
00171 Tri3<V>::FaceElementType Tri3<V>::GetFace(int ind)
00172 Return the edge data structure for the edge defined by index, ind
00173 */
00174 template <typename V>
00175 typename Tri3<V>::FaceElementType Tri3<V>::GetFace(int ind) {
00176    boost::array<VertexHandle, FaceElementType::num_vertices> vs;
00177    vs.at(0) = vertices.at((ind+1)%3);
00178    vs.at(1) = vertices.at((ind+2)%3);
00179    return FaceElementType(vs);
00180 }
00181 
00182 /*
00183 int Tri3<V>::GetFaceIndex(Tri3<V>::FaceElementType face)
00184 Return the index for the face as defined
00185 */
00186 template <typename V>
00187 int Tri3<V>::GetFaceIndex(Tri3<V>::FaceElementType face) {
00188    return FaceToVertex(face.vertices);
00189    
00190    for(int i=0; i<num_adjacents; i++)
00191       if(face == this->GetFace(i))
00192          return i;
00193    return num_adjacents;
00194 }
00195 
00196 /*
00197 Tri3<V>::EdgeElementType Tri3<V>::GetEdge(int ind)
00198 Return the edge data structure for the edge defined by index, ind
00199 */
00200 template <typename V>
00201 typename Tri3<V>::EdgeElementType Tri3<V>::GetEdge(int ind) {
00202    boost::array<VertexHandle, EdgeElementType::num_vertices> vs;
00203    vs.at(0) = vertices.at(ind);
00204    return   EdgeElementType(vs);
00205 }
00206 
00207 /*
00208 int Tri3<V>::GetEdgeIndex(Tri3<V>::EdgeElementType edge)
00209 Return the index for the edge as defined
00210 */
00211 template <typename V>
00212 int Tri3<V>::GetEdgeIndex(Tri3<V>::EdgeElementType edge) {
00213    for(int i=0; i<num_edges; i++)
00214       if(edge == this->GetEdge(i))
00215          return i;
00216    return num_edges;
00217 }
00218 
00219 /*
00220 std::vector<EdgeElementType> Tri3<V>::GetEdges(int f)
00221 Return the edges in an array which correspond to the given face, f
00222 */
00223 template <typename V>
00224 std::vector<typename Tri3<V>::EdgeElementType> Tri3<V>::GetEdges(int f) {
00225    std::vector<EdgeElementType> edges;
00226 
00227    boost::array<VertexHandle,EdgeElementType::num_vertices> vertices_1, vertices_2;
00228    
00229    vertices_1.at(0) = this->vertices.at((f+1)%3);
00230    vertices_2.at(0) = this->vertices.at((f+2)%3);
00231    edges.push_back(EdgeElementType(vertices_1));
00232    edges.push_back(EdgeElementType(vertices_2));
00233    
00234    return edges;
00235 }
00236 
00237 /*
00238 std::vector<EdgeElementType> Tri3<V>::GetAllEdges()
00239 */
00240 template <typename V>
00241 std::vector<typename Tri3<V>::EdgeElementType> Tri3<V>::GetAllEdges() {
00242    std::vector<EdgeElementType> edges;
00243    
00244    boost::array<VertexHandle,EdgeElementType::num_vertices> vertices_1, vertices_2, vertices_3;
00245    
00246    vertices_1.at(0) = this->vertices.at(0);
00247    vertices_2.at(0) = this->vertices.at(1);
00248    vertices_3.at(0) = this->vertices.at(2);
00249    edges.push_back(EdgeElementType(vertices_1));
00250    edges.push_back(EdgeElementType(vertices_2));
00251    edges.push_back(EdgeElementType(vertices_3));
00252    
00253    return edges;
00254 }
00255 
00256 /*
00257 Tri3<V>::ElementHandle Tri3<V>::NextOnEdge(int ind)
00258 Return the next element on the edge defined by index, ind
00259 */
00260 template <typename V>
00261 typename Tri3<V>::ElementHandle Tri3<V>::NextOnEdge(int ind) {
00262    return adjacents.at((ind+1)%3);
00263 }
00264 
00265 /*
00266 Tri3<V>::ElementHandle Tri3<V>::PrevOnEdge(int ind)
00267 Return the previous element on the edge defined by index, ind
00268 */
00269 template <typename V>
00270 typename Tri3<V>::ElementHandle Tri3<V>::PrevOnEdge(int ind) {
00271    return adjacents.at((ind+2)%3);
00272 }
00273 
00274 /*
00275 Tri3<V>::CohElementHandle Tri3<V>::NextCohOnEdge(int ind)
00276 Return the previous element on the edge defined by index, ind
00277 */
00278 template <typename V>
00279 typename Tri3<V>::CohElementHandle Tri3<V>::NextCohOnEdge(int ind) {
00280    return coh_adjacents.at((ind+1)%3);
00281 }
00282 
00283 /*
00284 Tri3<V>::CohElementHandle Tri3<V>::PrevCohOnEdge(int ind)
00285 Return the previous element on the edge defined by index, ind
00286 */
00287 template <typename V>
00288 typename Tri3<V>::CohElementHandle Tri3<V>::PrevCohOnEdge(int ind) {
00289    return coh_adjacents.at((ind+2)%3);
00290 }
00291 
00292 /*
00293 typename Tri3<V>::VertexHandle Tri3<V>::GetCentre()
00294 Return a the centre of the element (vertex will have it's global ID set to that of the element)
00295 */
00296 template <typename V>
00297 typename Tri3<V>::VertexHandle Tri3<V>::GetCentre() {
00298    typename V::CoordType new_x=0.0, new_y=0.0, new_z=0.0;
00299    for(int i=0; i<3; i++) {
00300       new_x += vertices.at(i)->coords.at(0);
00301       new_y += vertices.at(i)->coords.at(1);
00302       new_z += vertices.at(i)->coords.at(2);
00303    }
00304    new_x /= 3; new_y /= 3; new_z /= 3;
00305    
00306    return new V(new_x, new_y, new_z);
00307 }
00308 
00309 } // namespace DAPTA

Generated on Tue May 29 17:13:48 2007 for DAPTA by  doxygen 1.5.1