MFEM  v3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
triangle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.googlecode.com.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 
13 #include "mesh_headers.hpp"
14 
15 namespace mfem
16 {
17 
18 const int Triangle::edges[3][2] = {{0, 1}, {1, 2}, {2, 0}};
19 
20 Triangle::Triangle(const int *ind, int attr) : Element(Geometry::TRIANGLE)
21 {
22  attribute = attr;
23  for (int i = 0; i < 3; i++)
24  indices[i] = ind[i];
25 }
26 
27 Triangle::Triangle(int ind1, int ind2, int ind3, int attr)
28  : Element(Geometry::TRIANGLE)
29 {
30  attribute = attr;
31  indices[0] = ind1;
32  indices[1] = ind2;
33  indices[2] = ind3;
34 }
35 
36 int Triangle::NeedRefinement(DSTable &v_to_v, int *middle) const
37 {
38  int m;
39 
40  if ((m = v_to_v(indices[0], indices[1])) != -1 && middle[m] != -1) return 1;
41  if ((m = v_to_v(indices[1], indices[2])) != -1 && middle[m] != -1) return 1;
42  if ((m = v_to_v(indices[2], indices[0])) != -1 && middle[m] != -1) return 1;
43  return 0;
44 }
45 
46 void Triangle::SetVertices(const int *ind)
47 {
48  for (int i = 0; i < 3; i++)
49  indices[i] = ind[i];
50 }
51 
53 {
54  double d[3];
55  int shift, v;
56 
57  d[0] = ( (pmat(0,1)-pmat(0,0))*(pmat(0,1)-pmat(0,0)) +
58  (pmat(1,1)-pmat(1,0))*(pmat(1,1)-pmat(1,0)) );
59  d[1] = ( (pmat(0,2)-pmat(0,1))*(pmat(0,2)-pmat(0,1)) +
60  (pmat(1,2)-pmat(1,1))*(pmat(1,2)-pmat(1,1)) );
61  d[2] = ( (pmat(0,2)-pmat(0,0))*(pmat(0,2)-pmat(0,0)) +
62  (pmat(1,2)-pmat(1,0))*(pmat(1,2)-pmat(1,0)) );
63 
64  // if pmat has 3 rows, then use extra term in each sum
65  if (pmat.Height()==3)
66  {
67  d[0] += (pmat(2,1)-pmat(2,0))*(pmat(2,1)-pmat(2,0));
68  d[1] += (pmat(2,2)-pmat(2,1))*(pmat(2,2)-pmat(2,1));
69  d[2] += (pmat(2,2)-pmat(2,0))*(pmat(2,2)-pmat(2,0));
70  }
71 
72  if (d[0] >= d[1])
73  if (d[0] >= d[2]) shift = 0;
74  else shift = 2;
75  else
76  if (d[1] >= d[2]) shift = 1;
77  else shift = 2;
78 
79  switch (shift)
80  {
81  case 0:
82  break;
83  case 1:
84  v = indices[0];
85  indices[0] = indices[1];
86  indices[1] = indices[2];
87  indices[2] = v;
88  break;
89  case 2:
90  v = indices[0];
91  indices[0] = indices[2];
92  indices[2] = indices[1];
93  indices[1] = v;
94  break;
95  }
96 }
97 
98 void Triangle::MarkEdge(const DSTable &v_to_v, const int *length)
99 {
100  int l, L, j, ind[3], i;
101 
102  L = length[ v_to_v(indices[0], indices[1]) ]; j = 0;
103  if ( (l = length[ v_to_v(indices[1], indices[2]) ]) > L ) { L = l; j = 1; }
104  if ( (l = length[ v_to_v(indices[2], indices[0]) ]) > L ) { L = l; j = 2; }
105 
106  for (i = 0; i < 3; i++)
107  ind[i] = indices[i];
108 
109  switch (j)
110  {
111  case 1:
112  indices[0] = ind[1]; indices[1] = ind[2]; indices[2] = ind[0];
113  break;
114  case 2:
115  indices[0] = ind[2]; indices[1] = ind[0]; indices[2] = ind[1];
116  break;
117  }
118 }
119 
121 {
122  v.SetSize(3);
123  for (int i = 0; i < 3; i++)
124  v[i] = indices[i];
125 }
126 
128 
129 }
virtual int * GetVertices()
Definition: triangle.hpp:58
int NeedRefinement(DSTable &v_to_v, int *middle) const
Return 1 if the element needs refinement in order to get conforming mesh.
Definition: triangle.cpp:36
Data type dense matrix.
Definition: densemat.hpp:22
static const int edges[3][2]
Definition: triangle.hpp:26
virtual void MarkEdge(DenseMatrix &pmat)
Definition: triangle.cpp:52
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows.
Definition: operator.hpp:35
virtual void SetVertices(const int *ind)
Set the vertices according to the given input.
Definition: triangle.cpp:46
Class for linear FE on triangle.
Definition: fe.hpp:362
int attribute
Element&#39;s attribute (specifying material property, etc).
Definition: element.hpp:32
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:293
Linear2DFiniteElement TriangleFE
Definition: triangle.cpp:127
Abstract data type element.
Definition: element.hpp:27
int indices[3]
Definition: triangle.hpp:25