MFEM v2.0
|
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at 00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights 00003 // reserved. See file COPYRIGHT for details. 00004 // 00005 // This file is part of the MFEM library. For more information and source code 00006 // availability see http://mfem.googlecode.com. 00007 // 00008 // MFEM is free software; you can redistribute it and/or modify it under the 00009 // terms of the GNU Lesser General Public License (as published by the Free 00010 // Software Foundation) version 2.1 dated February 1999. 00011 00012 00013 #include "mesh_headers.hpp" 00014 00015 const int Triangle::edges[3][2] = {{0, 1}, {1, 2}, {2, 0}}; 00016 00017 Triangle::Triangle(const int *ind, int attr) : Element(Geometry::TRIANGLE) 00018 { 00019 attribute = attr; 00020 for (int i = 0; i < 3; i++) 00021 indices[i] = ind[i]; 00022 } 00023 00024 Triangle::Triangle(int ind1, int ind2, int ind3, int attr) 00025 : Element(Geometry::TRIANGLE) 00026 { 00027 attribute = attr; 00028 indices[0] = ind1; 00029 indices[1] = ind2; 00030 indices[2] = ind3; 00031 } 00032 00033 int Triangle::NeedRefinement(DSTable &v_to_v, int *middle) const 00034 { 00035 int m; 00036 00037 if ((m = v_to_v(indices[0], indices[1])) != -1 && middle[m] != -1) return 1; 00038 if ((m = v_to_v(indices[1], indices[2])) != -1 && middle[m] != -1) return 1; 00039 if ((m = v_to_v(indices[2], indices[0])) != -1 && middle[m] != -1) return 1; 00040 return 0; 00041 } 00042 00043 void Triangle::SetVertices(const int *ind) 00044 { 00045 for (int i = 0; i < 3; i++) 00046 indices[i] = ind[i]; 00047 } 00048 00049 void Triangle::MarkEdge(DenseMatrix &pmat) 00050 { 00051 double d[3]; 00052 int shift, v; 00053 00054 d[0] = ( (pmat(0,1)-pmat(0,0))*(pmat(0,1)-pmat(0,0)) + 00055 (pmat(1,1)-pmat(1,0))*(pmat(1,1)-pmat(1,0)) ); 00056 d[1] = ( (pmat(0,2)-pmat(0,1))*(pmat(0,2)-pmat(0,1)) + 00057 (pmat(1,2)-pmat(1,1))*(pmat(1,2)-pmat(1,1)) ); 00058 d[2] = ( (pmat(0,2)-pmat(0,0))*(pmat(0,2)-pmat(0,0)) + 00059 (pmat(1,2)-pmat(1,0))*(pmat(1,2)-pmat(1,0)) ); 00060 00061 if (d[0] >= d[1]) 00062 if (d[0] >= d[2]) shift = 0; 00063 else shift = 2; 00064 else 00065 if (d[1] >= d[2]) shift = 1; 00066 else shift = 2; 00067 00068 switch (shift) 00069 { 00070 case 0: 00071 break; 00072 case 1: 00073 v = indices[0]; 00074 indices[0] = indices[1]; 00075 indices[1] = indices[2]; 00076 indices[2] = v; 00077 break; 00078 case 2: 00079 v = indices[0]; 00080 indices[0] = indices[2]; 00081 indices[2] = indices[1]; 00082 indices[1] = v; 00083 break; 00084 } 00085 } 00086 00087 void Triangle::MarkEdge(const DSTable &v_to_v, const int *length) 00088 { 00089 int l, L, j, ind[3], i; 00090 00091 L = length[ v_to_v(indices[0], indices[1]) ]; j = 0; 00092 if ( (l = length[ v_to_v(indices[1], indices[2]) ]) > L ) { L = l; j = 1; } 00093 if ( (l = length[ v_to_v(indices[2], indices[0]) ]) > L ) { L = l; j = 2; } 00094 00095 for (i = 0; i < 3; i++) 00096 ind[i] = indices[i]; 00097 00098 switch (j) 00099 { 00100 case 1: 00101 indices[0] = ind[1]; indices[1] = ind[2]; indices[2] = ind[0]; 00102 break; 00103 case 2: 00104 indices[0] = ind[2]; indices[1] = ind[0]; indices[2] = ind[1]; 00105 break; 00106 } 00107 } 00108 00109 void Triangle::GetVertices(Array<int> &v) const 00110 { 00111 v.SetSize(3); 00112 for (int i = 0; i < 3; i++) 00113 v[i] = indices[i]; 00114 } 00115 00116 Linear2DFiniteElement TriangleFE;