Flow123d  jenkins-Flow123d-windows-release-multijob-285
ref_element.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
27  * @author Jan Stebel
28  */
29 
30 #include "system/global_defs.h"
31 #include "system/system.hh"
32 #include "mesh/ref_element.hh"
33 
34 using namespace arma;
35 using namespace std;
36 
37 template<> const unsigned int RefElement<1>::side_permutations[][n_nodes_per_side] = { { 0 } };
38 
39 template<> const unsigned int RefElement<2>::side_permutations[][n_nodes_per_side] = { { 0, 1 }, { 1, 0 } };
40 
41 template<> const unsigned int RefElement<3>::side_permutations[][n_nodes_per_side] = {
42  { 0, 1, 2 },
43  { 0, 2, 1 },
44  { 1, 0, 2 },
45  { 1, 2, 0 },
46  { 2, 0, 1 },
47  { 2, 1, 0 }
48 };
49 
50 
51 template<> const unsigned int RefElement<1>::side_nodes[][1] = {
52  { 0 },
53  { 1 }
54 };
55 
56 template<> const unsigned int RefElement<2>::side_nodes[][2] = {
57  { 0, 1},
58  { 1, 2},
59  { 0, 2}
60 };
61 
62 template<> const unsigned int RefElement<3>::side_nodes[][3] = {
63  {1,2,3},
64  {0,2,3},
65  {0,1,3},
66  {0,1,2}
67 };
68 
69 
70 
71 template<> const unsigned int RefElement<3>::side_lines[][3] = {
72  {3,4,5},
73  {1,2,5},
74  {0,2,4},
75  {0,1,3}
76 };
77 
78 
79 
80 template<> const unsigned int RefElement<3>::line_nodes[][2] = {
81  {0,1},
82  {0,2},
83  {0,3},
84  {1,2},
85  {1,3},
86  {2,3}
87 };
88 
89 
90 
91 template<unsigned int dim>
92 vec::fixed<dim+1> RefElement<dim>::node_coords(unsigned int nid)
93 {
94  ASSERT(nid < n_nodes, "Vertex number is out of range!");
95 
96  vec::fixed<dim+1> p;
97  p.zeros();
98 
99  if (nid == 0)
100  p(dim) = 1;
101  else
102  p(nid-1) = 1;
103 
104  return p;
105 }
106 
107 
108 template<unsigned int dim>
109 vec::fixed<dim> RefElement<dim>::normal_vector(unsigned int sid)
110 {
111  ASSERT(sid < n_sides, "Side number is out of range!");
112  vec::fixed<dim> p;
113  unsigned int new_sid = sid;
114 
115  if (dim==1)
116  new_sid = (sid+1)%2;
117  else if (dim==2)
118  new_sid = (sid+2)%3;
119 
120  if (new_sid == 0)
121  p.fill(1./sqrt(dim));
122  else
123  {
124  p.zeros();
125  p(new_sid-1) = -1;
126  }
127 
128  return p;
129 }
130 
131 
132 
133 template <>
134 unsigned int RefElement<3>::line_between_faces(unsigned int f1, unsigned int f2) {
135  unsigned int i,j;
136  i=j=0;
137  while (side_lines[f1][i] != side_lines[f2][j])
138  if (side_lines[f1][i] < side_lines[f2][j]) i++;
139  else j++;
140  return side_lines[f1][i];
141 }
142 
143 
144 
145 template<unsigned int dim>
146 unsigned int RefElement<dim>::permutation_index(unsigned int p[n_nodes_per_side])
147 {
148  unsigned int index;
149  for (index = 0; index < n_side_permutations; index++)
150  if (equal(p, p + n_nodes_per_side, side_permutations[index]))
151  return index;
152 
153  xprintf(PrgErr, "Side permutation not found.\n");
154 
155  // The following line is present in order to suppress compilers warning
156  // about missing return value.
157  return 0;
158 }
159 
160 
161 template class RefElement<1>;
162 template class RefElement<2>;
163 template class RefElement<3>;
164 
165 
166 
167 
static arma::vec::fixed< dim+1 > node_coords(unsigned int nid)
Definition: ref_element.cc:92
static unsigned int permutation_index(unsigned int p[n_nodes_per_side])
Definition: ref_element.cc:146
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
Global macros to enhance readability and debugging, general constants.
#define ASSERT(...)
Definition: global_defs.h:121
#define xprintf(...)
Definition: system.hh:100
Definition: system.hh:72
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
static arma::vec::fixed< dim > normal_vector(unsigned int sid)
Definition: ref_element.cc:109