Flow123d  release_2.2.0-26-ge868538
ref_element.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file ref_element.hh
15  * @brief Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
16  * @author Jan Stebel
17  * @todo
18  *
19  * - design interface in such a way, that we can change numbering
20  * - design numbering and orientations on ref element that is consistent (orientation and numbering od 2d el. match sides of 3d),
21  * and possibly allows permute vertices of elements so that sides sharing an edge match numbering and orientation (we dos'nt need permute faces)
22  *
23  * Proposal(prefers combinatoric order) :
24  * 1D - orientation V0 -> V1
25  *
26  * 2D - edges: E0: V0 -> V1,
27  * E1: V0 -> V2
28  * E2: V1 -> V2
29  * This maximize number of edge orientations achievable by edge permutations
30  * edge numbering edge orientation( in original numbering)
31  * 0 1 2 + + +
32  * 0 2 1 - + +
33  * 1 0 2 + + -
34  * 1 2 0 - - +
35  * 2 0 1 + - -
36  * 2 1 0 - - -
37  *
38  * vertices edges normal (out = +)
39  * 3D - sides: S0: 0 1 2 E0 E1 E3 -
40  * S1: 0 1 3 E0 E2 E4 +
41  * S2: 0 2 3 E1 E2 E5 -
42  * S3: 1 2 3 E3 E4 E5 -
43  *
44  * edges: E0: V0 -> V1 x direction
45  * E1: V0 -> V2 y direction
46  * E2: V0 -> V3 z direction
47  * E3: V1 -> V2
48  * E4: V1 -> V3
49  * E5: V2 -> V3
50  *
51  * - functions from DEAL.ii:
52  * bool is_inside_unit_cell( point )
53  * line_to_cell_vertices(line, vertex) vertex index on line to index on whole element
54  * face_to_cell_vertices(face, vertex, Orientation), Orientation should be some class describing permutation of shared face to element's face/side
55  * face_to_cel_lines
56  * standard_to_real_face_vertex(vertex, Orientation), maps vertex to permuted face
57  * real_to_standard_face_vertex - inverse
58  * ... same for line; we should need also something like standard_to_real_line_vertex; Deal dosn;t support Orientation changes for 2D element faces
59  * Point unit_cell_vertex(vertex) - coordinates
60  * project_to_unit_cell
61  * distance_to_unit_cell
62  * d_linear_shape_function
63  *
64  * - can not change numbering of element sides due to DarcyFlow, which use hardwired side numbering in construction of basis functions
65  *
66  *
67  */
68 
69 #ifndef REF_ELEMENT_HH_
70 #define REF_ELEMENT_HH_
71 
72 #include <armadillo>
73 
74 
75 /*
76  * Ordering of nodes and sides in reference elements
77  * =================================================
78  *
79  * 1D element (line segment) 2D element (triangle) 3D element (tetrahedron)
80  *
81  * y
82  * .
83  * ,/
84  * /
85  * 2
86  * y ,/|`\
87  * ^ ,/ | `\
88  * | ,/ '. `\
89  * 2 ,/ | `\
90  * |`\ ,/ | `\
91  * | `\ 0-----------'.--------1 --> x
92  * | `\ `\. | ,/
93  * | `\ `\. | ,/
94  * | `\ `\. '. ,/
95  * 0----------1 --> x 0----------1 --> x `\. |/
96  * `3
97  * `\.
98  * ` z
99  *
100  * side id node ids side id node ids side id node ids normal
101  * 0 1 0 1,2 0 1,2,3 OUT
102  * 1 0 1 0,2 1 0,2,3 IN
103  * 2 0,1 2 0,1,3 OUT
104  * 3 0,1,2 IN
105  *
106  *
107  *
108  *
109  *
110  *
111  */
112 template<unsigned int dim>
114 {
115 public:
116  typedef arma::vec::fixed<dim> LocalPoint;
117  typedef arma::vec::fixed<dim+1> BaryPoint; // barycentric coordinates
118  typedef arma::vec::fixed<dim> FaceBaryPoint;
119 
120  /**
121  * Return local coordinates of given node.
122  * @param nid Node number.
123  */
124  static LocalPoint node_coords(unsigned int nid);
125 
126  /**
127  * Return barycentric coordinates of given node.
128  * @param nid Node number.
129  */
130  static BaryPoint node_barycentric_coords(unsigned int nid);
131 
132  /**
133  * Compute normal vector to a given side.
134  * @param sid Side number.
135  */
136  static LocalPoint normal_vector(unsigned int sid);
137 
138 
139  /**
140  * If the given barycentric coordinate is in the ref. element, return unchanged.
141  * If the given barycentric coordinate is out of the ref. element,
142  * project it on the surface of the ref. element.
143  */
144  static BaryPoint clip(const BaryPoint &barycentric);
145 
146  static double side_measure(unsigned int sid);
147 
148  /**
149  * Returns index of the node that is oposite to side of given index @p sid.
150  * Note: It is dependent on current node and side numbering.
151  * @param sid Side number.
152  */
153  static unsigned int oposite_node(unsigned int sid);
154 
155  /**
156  * Return index of 1D line, shared by two faces @p f1 and @p f2 of the reference tetrahedron.
157  * Implemented only for @p dim == 3.
158  */
159  static unsigned int line_between_faces(unsigned int f1, unsigned int f2);
160 
161 
162  /**
163  * Number of sides.
164  */
165  static const unsigned int n_sides = dim + 1;
166 
167  /**
168  * Number of vertices.
169  */
170  static const unsigned int n_nodes = dim + 1;
171 
172  /**
173  * Number of nodes on one side.
174  */
175  static const unsigned int n_nodes_per_side = dim;
176 
177  /// Number of lines on boundary of one side.
178  static const unsigned int n_lines_per_side = ( dim == 3 ? 3 : 0);
179 
180  /// Number of lines, i.e. @p object of dimension @p dim-2 on the boundary of the reference element.
181  static const unsigned int n_lines = ( dim == 3 ? 6 : 0);
182 
183  /**
184  * Node numbers for each side.
185  */
186  static const unsigned int side_nodes[n_sides][n_nodes_per_side];
187 
188  /**
189  * Indices of 1D lines of the 2D sides of an tetrahedron. Nonempty only for @p dim==3.
190  */
191  static const unsigned int side_lines[n_sides][n_lines_per_side];
192 
193  /**
194  * Nodes of 1D lines of the tetrahedron.
195  */
196  static const unsigned int line_nodes[n_lines][2];
197 
198 
200 
201  /**
202  * Number of permutations of nodes on sides.
203  * dim value
204  * -----------
205  * 1 1
206  * 2 2
207  * 3 6
208  */
209  static const unsigned int n_side_permutations = (dim+1)*(2*dim*dim-5*dim+6)/6;
210 
211  /**
212  * Permutations of nodes on sides.
213  */
215 
216  /**
217  * For a given permutation @p p of nodes finds its index within @p side_permutations.
218  * @param p Permutation of nodes.
219  */
220  static unsigned int permutation_index(unsigned int p[n_nodes_per_side]);
221 
223 
224  /**
225  * Used in the clip method.
226  */
227  static BarycentricUnitVec make_bary_unit_vec();
228 
229  /**
230  * For given barycentric coordinates on the ref element returns barycentric coordinates
231  * on the ref. element of given face. Assumes that the input point is on the face.
232  * Barycentric order: (local_coords, complanatory)
233  */
234  static FaceBaryPoint barycentric_on_face(const BaryPoint &barycentric, unsigned int i_face);
235 
236  /**
237  * For given barycentric coordinates on the face returns barycentric coordinates
238  * on the ref. element.
239  * Barycentric order: (local_coords, complanatory)
240  */
241  static BaryPoint barycentric_from_face(const FaceBaryPoint &face_barycentric, unsigned int i_face);
242 
243 
245  static CentersList centers_of_subelements(unsigned int sub_dim);
246 
247 };
248 
249 
250 template<unsigned int dim>
251 inline unsigned int RefElement<dim>::oposite_node(unsigned int sid)
252 {
253  // Is dependent on current node and side numbering.
254  return n_sides - sid - 1;
255  // (sid + dim) % (dim + 1); //older numbering
256 }
257 
258 
259 
260 
261 #endif /* REF_ELEMENT_HH_ */
static LocalPoint normal_vector(unsigned int sid)
const unsigned int line_nodes[][2]
Definition: ref_element.cc:80
static LocalPoint node_coords(unsigned int nid)
Definition: ref_element.cc:110
std::vector< BaryPoint > BarycentricUnitVec
Definition: ref_element.hh:222
static unsigned int permutation_index(unsigned int p[n_nodes_per_side])
Definition: ref_element.cc:346
arma::vec::fixed< dim > LocalPoint
Definition: ref_element.hh:116
static BaryPoint barycentric_from_face(const FaceBaryPoint &face_barycentric, unsigned int i_face)
Definition: ref_element.cc:210
static const std::vector< std::vector< std::vector< unsigned int > > > nodes_of_subelements
Definition: ref_element.hh:199
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
static const unsigned int n_side_permutations
Definition: ref_element.hh:209
static unsigned int oposite_node(unsigned int sid)
Definition: ref_element.hh:251
static CentersList centers_of_subelements(unsigned int sub_dim)
Definition: ref_element.cc:277
const unsigned int side_lines[][3]
Definition: ref_element.cc:71
const unsigned int side_nodes[][1]
Definition: ref_element.cc:51
static FaceBaryPoint barycentric_on_face(const BaryPoint &barycentric, unsigned int i_face)
Definition: ref_element.cc:196
static const unsigned int n_lines_per_side
Number of lines on boundary of one side.
Definition: ref_element.hh:178
const std::vector< LocalPoint > & CentersList
Definition: ref_element.hh:244
static double side_measure(unsigned int sid)
static const unsigned int n_lines
Number of lines, i.e. object of dimension dim-2 on the boundary of the reference element.
Definition: ref_element.hh:181
const unsigned int side_permutations[][n_nodes_per_side]
Definition: ref_element.cc:37
arma::vec::fixed< dim > FaceBaryPoint
Definition: ref_element.hh:118
static const unsigned int n_sides
Definition: ref_element.hh:165
static const unsigned int n_nodes
Definition: ref_element.hh:170
static BarycentricUnitVec make_bary_unit_vec()
Definition: ref_element.cc:229
static BaryPoint clip(const BaryPoint &barycentric)
Definition: ref_element.cc:243
static BaryPoint node_barycentric_coords(unsigned int nid)
Definition: ref_element.cc:125
static const unsigned int n_nodes_per_side
Definition: ref_element.hh:175
arma::vec::fixed< dim+1 > BaryPoint
Definition: ref_element.hh:117