MFEM  v3.1 Finite element discretization library
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.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
10 // Software Foundation) version 2.1 dated February 1999.
11
12
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  {
25  indices[i] = ind[i];
26  }
27 }
28
29 Triangle::Triangle(int ind1, int ind2, int ind3, int attr)
30  : Element(Geometry::TRIANGLE)
31 {
32  attribute = attr;
33  indices[0] = ind1;
34  indices[1] = ind2;
35  indices[2] = ind3;
36 }
37
38 int Triangle::NeedRefinement(DSTable &v_to_v, int *middle) const
39 {
40  int m;
41
42  if ((m = v_to_v(indices[0], indices[1])) != -1 && middle[m] != -1) { return 1; }
43  if ((m = v_to_v(indices[1], indices[2])) != -1 && middle[m] != -1) { return 1; }
44  if ((m = v_to_v(indices[2], indices[0])) != -1 && middle[m] != -1) { return 1; }
45  return 0;
46 }
47
48 void Triangle::SetVertices(const int *ind)
49 {
50  for (int i = 0; i < 3; i++)
51  {
52  indices[i] = ind[i];
53  }
54 }
55
57 {
58  double d[3];
59  int shift, v;
60
61  d[0] = ( (pmat(0,1)-pmat(0,0))*(pmat(0,1)-pmat(0,0)) +
62  (pmat(1,1)-pmat(1,0))*(pmat(1,1)-pmat(1,0)) );
63  d[1] = ( (pmat(0,2)-pmat(0,1))*(pmat(0,2)-pmat(0,1)) +
64  (pmat(1,2)-pmat(1,1))*(pmat(1,2)-pmat(1,1)) );
65  d[2] = ( (pmat(0,2)-pmat(0,0))*(pmat(0,2)-pmat(0,0)) +
66  (pmat(1,2)-pmat(1,0))*(pmat(1,2)-pmat(1,0)) );
67
68  // if pmat has 3 rows, then use extra term in each sum
69  if (pmat.Height()==3)
70  {
71  d[0] += (pmat(2,1)-pmat(2,0))*(pmat(2,1)-pmat(2,0));
72  d[1] += (pmat(2,2)-pmat(2,1))*(pmat(2,2)-pmat(2,1));
73  d[2] += (pmat(2,2)-pmat(2,0))*(pmat(2,2)-pmat(2,0));
74  }
75
76  if (d[0] >= d[1])
77  if (d[0] >= d[2]) { shift = 0; }
78  else { shift = 2; }
79  else if (d[1] >= d[2]) { shift = 1; }
80  else { shift = 2; }
81
82  switch (shift)
83  {
84  case 0:
85  break;
86  case 1:
87  v = indices[0];
88  indices[0] = indices[1];
89  indices[1] = indices[2];
90  indices[2] = v;
91  break;
92  case 2:
93  v = indices[0];
94  indices[0] = indices[2];
95  indices[2] = indices[1];
96  indices[1] = v;
97  break;
98  }
99 }
100
101 void Triangle::MarkEdge(const DSTable &v_to_v, const int *length)
102 {
103  int l, L, j, ind[3], i;
104
105  L = length[ v_to_v(indices[0], indices[1]) ]; j = 0;
106  if ( (l = length[ v_to_v(indices[1], indices[2]) ]) > L ) { L = l; j = 1; }
107  if ( (l = length[ v_to_v(indices[2], indices[0]) ]) > L ) { L = l; j = 2; }
108
109  for (i = 0; i < 3; i++)
110  {
111  ind[i] = indices[i];
112  }
113
114  switch (j)
115  {
116  case 1:
117  indices[0] = ind[1]; indices[1] = ind[2]; indices[2] = ind[0];
118  break;
119  case 2:
120  indices[0] = ind[2]; indices[1] = ind[0]; indices[2] = ind[1];
121  break;
122  }
123 }
124
126 {
127  v.SetSize(3);
128  for (int i = 0; i < 3; i++)
129  {
130  v[i] = indices[i];
131  }
132 }
133
135
136 }
virtual int * GetVertices()
Definition: triangle.hpp:59
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:38
Data type dense matrix using column-major storage.
Definition: densemat.hpp:22
static const int edges[3][2]
Definition: triangle.hpp:27
virtual void MarkEdge(DenseMatrix &pmat)
Definition: triangle.cpp:56
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:48
Class for linear FE on triangle.
Definition: fe.hpp:374
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:323
Linear2DFiniteElement TriangleFE
Definition: triangle.cpp:134
Abstract data type element.
Definition: element.hpp:27
int indices[3]
Definition: triangle.hpp:26