Flow123d  DF_patch_fe_data_tables-6bd0dc8
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  * TODO: reconsider following whether it is actual...
20  * - design interface in such a way, that we can change numbering
21  * - design numbering and orientations on ref element that is consistent (orientation and numbering od 2d el. match sides of 3d),
22  * and possibly allows permute vertices of elements so that sides sharing an edge match numbering and orientation (we dos'nt need permute faces)
23  *
24  * Proposal(prefers combinatoric order) :
25  * 1D - orientation V0 -> V1
26  *
27  * 2D - edges: E0: V0 -> V1,
28  * E1: V0 -> V2
29  * E2: V1 -> V2
30  * This maximize number of edge orientations achievable by edge permutations
31  * edge numbering edge orientation( in original numbering)
32  * 0 1 2 + + +
33  * 0 2 1 - + +
34  * 1 0 2 + + -
35  * 1 2 0 - - +
36  * 2 0 1 + - -
37  * 2 1 0 - - -
38  *
39  * vertices edges normal (out = +)
40  * 3D - sides: S0: 0 1 2 E0 E1 E3 -
41  * S1: 0 1 3 E0 E2 E4 +
42  * S2: 0 2 3 E1 E2 E5 -
43  * S3: 1 2 3 E3 E4 E5 -
44  *
45  * edges: E0: V0 -> V1 x direction
46  * E1: V0 -> V2 y direction
47  * E2: V0 -> V3 z direction
48  * E3: V1 -> V2
49  * E4: V1 -> V3
50  * E5: V2 -> V3
51 
52  *
53  * - functions from DEAL.ii:
54  * bool is_inside_unit_cell( point )
55  * line_to_cell_vertices(line, vertex) vertex index on line to index on whole element
56  * face_to_cell_vertices(face, vertex, Orientation), Orientation should be some class describing permutation of shared face to element's face/side
57  * face_to_cel_lines
58  * standard_to_real_face_vertex(vertex, Orientation), maps vertex to permuted face
59  * real_to_standard_face_vertex - inverse
60  * ... same for line; we should need also something like standard_to_real_line_vertex; Deal dosn;t support Orientation changes for 2D element faces
61  * Point unit_cell_vertex(vertex) - coordinates
62  * project_to_unit_cell
63  * distance_to_unit_cell
64  * d_linear_shape_function
65  *
66  * - can not change numbering of element sides due to DarcyFlow, which use hardwired side numbering in construction of basis functions
67  * - any change of side numbering requires also change in flow/old_bcd.cc
68  *
69  *
70  */
71 
72 #ifndef REF_ELEMENT_HH_
73 #define REF_ELEMENT_HH_
74 
75 #include <vector> // for vector
76 #include <array>
77 #include <armadillo>
78 #include "system/armor.hh"
79 #include "system/asserts.hh"
80 #include <Eigen/Core>
81 #include <Eigen/Dense>
82 
83 
84 /*
85  * Ordering of nodes and sides in reference elements
86  * =================================================
87  *
88  * TODO we want the following (22.10.):
89  *
90  * 1D element (line segment) 2D element (triangle) 3D element (tetrahedron)
91  *
92  * z
93  * .
94  * ,/
95  * /
96  * 3
97  * y ,/|`\
98  * ^ ,/ | `\
99  * | ,/ '. `\
100  * 2 ,/ | `\
101  * |`\ ,/ | `\
102  * | `\ 0-----------'.--------1 --> x
103  * | `\ `\. | ,/
104  * | `\ `\. | ,/
105  * | `\ `\. '. ,/
106  * 0----------1 --> x 0----------1 --> x `\. |/
107  * `2
108  * `\.
109  * `y
110  *
111  * side id node ids side id node ids side id node ids normal
112  * 0 0 0 0,1 0 0,1,2 OUT
113  * 1 1 1 0,2 1 0,1,3 IN
114  * 2 1,2 2 0,2,3 OUT
115  * 3 1,2,3 IN
116  *
117  *
118  * nodes coordinates:
119  * 0 [0] 0 [0,0] 0 [0,0,0]
120  * 1 [1] 1 [1,0] 1 [1,0,0]
121  * 2 [0,1] 2 [0,1,0]
122  * 3 [0,0,1]
123  *
124  * barycentric coordinates of nodes:
125  * 0 [1,0] 0 [1,0,0] 0 [1,0,0,0]
126  * 1 [0,1] 1 [0,1,0] 1 [0,1,0,0]
127  * 2 [0,0,1] 2 [0,0,1,0]
128  * 3 [0,0,0,1]
129  *
130  *
131  *
132  * Element node permutation for matching sides
133  *
134  * 1. 2D case: Can add mesh elements in "layers" so that at most toe edges are prescribed and one is free.
135  * possible cases, two edges A and B considered counter clockwise around a node:
136  * A out, B out : vertex 0 to node, regular orientation (normal up)
137  * A out, B in : vertex 1 to node, regular orientation
138  * A in , B out : vertex 1 to node, inverted orientation (normal down)
139  * A in , B in : vertex 2 to node regular orientation
140  *
141  * Result: can be matched using two element orientations, element inversion in 1/3 of cases
142  *
143  * 2. 3d elements around an oriented edge
144  * a. possible face configurations
145  * U: side 0 attached to the edge, positive; face vertices: 0 (edge 0), 1 (edge 1), 2
146  * V: side 1 attached to the edge, negative; face vertices: 0 (edge 0), 2 (edge 1), 1
147  * W: side 2 attached to the edge, positive; face vertices: 1 (edge 0), 2 (edge 1), 0
148  *
149  * b. faces of the element edges, configuration of faces attached to the element edge; edge pointing up, looking from outside position, face A on right, face B on left
150  * E0: A (side 0) in U, B (side 1) in U
151  * E1: A (side 2) in U, B (side 0) in V
152  * E2: A (side 1) in V, B (side 2) in V
153  * E3. A (side 0) in W, B (side 3) in U
154  * E4: A (side 3) in V, B (side 1) in W
155  * E5: A (side 2) in W, B (side 3) in W
156  * not presented combination:
157  * A in U, B in W = E3 inverted
158  * A in V, B in U = E1 inverted
159  * A in W, b in V = E4 inverted
160  *
161  * Result can permute element veritices to arrange elements around an edge, possibly element inversion in 1/3 of cases
162  *
163  * 3. 3d elements around a node, up to 3 given faces, one free face
164  * denote V0, V1, V2 vertices of the free face, V3 common vertex of given faces
165  * Denote edges of this element ABCDEF with +- orientation
166  * a. orientation of edges of the vertices
167  * V0: E0+ >V1, E1+ >V2, E2+ >V3 +++
168  * V1: E0- >V0, E3+ >V2, E4+ >V3 -++
169  * V2: E1- >V0, E3- >V1, E5+ >V3 --+
170  * V3: E2- >V0, E4- >V1, E5- >V2 ---
171  *
172 * vertices edges normal (out = +)
173  * 3D - sides: S0: 0 1 2 E0 E1 E3 -
174  * S1: 0 1 3 E0 E2 E4 +
175  * S2: 0 2 3 E1 E2 E5 -
176  * S3: 1 2 3 E3 E4 E5 -
177  *
178  * edges: A E0: V0 -> V1 x direction
179  * B E1: V0 -> V2 y direction
180  * C E2: V0 -> V3 z direction
181  * D E3: V1 -> V2
182  * E E4: V1 -> V3
183  * F E5: V2 -> V3
184 
185  CE -> A
186  EF -> D
187  FC -> B
188  *
189  * with edges DEF, other three edges ABC
190  * configuration given by orientation of edges ABC and possibly by orientation of edges DEF
191  * ABC orientation + down, - up; DEF orientation positive if match side 0, i.e. D (AB), E (AC), F (BC)
192  * faces denoted fD,fE,fF, their configurations considered with respect to the edges DEF respectively
193  * front face denoted: ff
194  * vertices V0, V1, V2 top vertices with edges D (V0V1) E (V0V2) F (V1V2); V3 bottom
195  * invalid = corner case, can not continue must either modify one of the faces, or introduce unmatching face
196  * impossible = combination of edges that can not happen
197  * edge cases arranged for the vertex 3
198  *
199  * CEF ABD face config: fD fE fF ff
200  * +++ +++ U U U
201  * +++ ++- U U U-
202  * +++ +-+ invalid
203  * +++ +-- U U U
204  * +++ -++ U U U
205  * +++ -+- invalid U U U-
206  * +++ --+
207  * +++ --- U U U
208  *
209  * ++- +++ impossible U U U
210  * ++- ++- impossible U U U-
211  * ++- +-+ impossible
212  * ++- +-- U U U
213  * ++- -++ impossible U U U
214  * ++- -+- impossible U U U-
215  * ++- --+ impossible
216  * ++- --- U U U
217 
218  * +-+ +++ impossible U U U
219  * +-+ ++- impossible U U U-
220  * +-+ +-+ impossible
221  * +-+ +-- U U U
222  * +-+ -++ impossible U U U
223  * +-+ -+- impossible U U U-
224  * +-+ --+ impossible
225  * +-+ --- U U U
226 
227  * +-- +++ impossible U U U
228  * +-- ++- impossible U U U-
229  * +-- +-+ impossible
230  * +-- +-- U U U
231  * +-- -++ impossible U U U
232  * +-- -+- impossible U U U-
233  * +-- --+ impossible
234  * +-- --- U U U
235 
236  * -++ +++ impossible U U U
237  * -++ ++- impossible U U U-
238  * -++ +-+ impossible
239  * -++ +-- U U U
240  * -++ -++ impossible U U U
241  * -++ -+- impossible U U U-
242  * -++ --+ impossible
243  * -++ --- U U U
244 
245  * -+- +++ impossible U U U
246  * -+- ++- impossible U U U-
247  * -+- +-+ impossible
248  * -+- +-- U U U
249  * -+- -++ impossible U U U
250  * -+- -+- impossible U U U-
251  * -+- --+ impossible
252  * -+- --- U U U
253 
254  * --+ +++ impossible U U U
255  * --+ ++- impossible U U U-
256  * --+ +-+ impossible
257  * --+ +-- U U U
258  * --+ -++ impossible U U U
259  * --+ -+- impossible U U U-
260  * --+ --+ impossible
261  * --+ --- U U U
262 
263  * --- +++ U U U
264  * --- ++- U U U-
265  * --- +-+ invalid
266  * --- +-- U U U
267  * --- -++ U U U
268  * --- -+- invalid U U U-
269  * --- --+
270  * --- --- U U U
271  *
272  *
273  *
274  */
275 
276 
277 template<std::size_t Size>
278 using IdxVector = std::array<unsigned int, Size>;
279 
280 
281 /** Auxilliary structure that is used to pass template arguments into interact function of RefElement:
282  * RefElement<dim>::interact( Interaction<OutDim,InDim>(i) )
283  *
284  * This enables automatic deduction of dimensional template arguments.
285  * @see @p RefElement<dim>::interact
286  */
287 template <unsigned int OutDim, unsigned int InDim>
288 struct Interaction {
289  Interaction(unsigned int i) : i_(i) {}
290  unsigned int i_;
291 };
292 
293 
294 
296 public:
297  // Order clockwise, faces opposite to the lines from node_lines.
298  // !! dependes on S3 inversion
299  static constexpr IdxVector<3> S3_node_sides [2][4]
300  = { { { 2, 1, 0 },
301  { 3, 0, 1 },
302  { 3, 2, 0 },
303  { 3, 1, 2 }},
304  { { 2, 0, 1 },
305  { 3, 1, 0 },
306  { 3, 0, 2 },
307  { 3, 2, 1 }}};
308 
309  // faces adjecent to given edge, first is the right face when looking form outside with the edge pointing up.
310  // !! dependes on S3 inversion
311  static constexpr IdxVector<2> S3_line_sides [2][6]
312  = { { {0,1},
313  {2,0},
314  {1,2},
315  {0,3},
316  {3,1},
317  {2,3}},
318  { {1,0},
319  {0,2},
320  {2,1},
321  {3,0},
322  {1,3},
323  {3,2}}};
324 
325  // Order clockwise looking over the vertex to center; smallest index first
326  // !! dependes on S3 inversion
327  static constexpr IdxVector<3> S3_node_lines [2][4]
328  = { { {0,1,2},
329  {0,4,3},
330  {1,3,5},
331  {2,5,4}},
332  { {0,2,1},
333  {0,3,4},
334  {1,5,3},
335  {2,4,5}}};
336 
337 };
338 
339 
340 template<unsigned int dim>
342 {
343 public:
344  typedef arma::vec::fixed<dim> LocalPoint;
345  /**
346  * Barycentric coordinates.
347  *
348  * e.g. coordinates (a,b,c) on triangle with vertices X, Y, Z
349  * represents a point: a*X+b*Y+c*Z
350  */
353 
354  //// For computing vectorized normal_vector
355  typedef Eigen::Array<double,Eigen::Dynamic,1> ArrayDbl;
356 
357  DECLARE_EXCEPTION( ExcInvalidPermutation, << "Side permutation not found.\n" );
358 
359  /**
360  * Return coordinates of given node.
361  * @see the class documentation @p RefElement
362  * @param nid Node number.
363  * NOTE: Implementation is dependent on current node and side numbering.
364  */
365  static LocalPoint node_coords(unsigned int nid);
366 
367  /**
368  * Compute normal vector to a given side.
369  * @param sid Side number.
370  */
371  static LocalPoint normal_vector(unsigned int sid);
372 
373 
374  /**
375  * Compute normal vector to a given side.
376  * @param sid Side number.
377  */
378  static Eigen::Vector<ArrayDbl,dim> normal_vector_array(Eigen::Array<uint,Eigen::Dynamic,1> loc_side_idx_array);
379 
380 
381  /**
382  * If the given barycentric coordinate is in the ref. element, return unchanged.
383  * If the given barycentric coordinate is out of the ref. element,
384  * project it on the surface of the ref. element.
385  */
386  static BaryPoint clip(const BaryPoint &barycentric);
387 
388  /** Returns orientation of the normal of side @p sid. 0 -> OUT, 1 -> IN.
389  * NOTE: Implementation is dependent on current node and side numbering.
390  */
391  static unsigned int normal_orientation(unsigned int sid);
392 
393  static double side_measure(unsigned int sid);
394 
395  /**
396  * Returns index of the node that is oposite to side of given index @p sid.
397  * Note: It is dependent on current node and side numbering.
398  * @param sid Side number.
399  * NOTE: Implementation is dependent on current node and side numbering.
400  */
401  static unsigned int oposite_node(unsigned int sid);
402 
403  /**
404  * Return index of 1D line, shared by two faces @p f1 and @p f2 of the reference tetrahedron.
405  * Implemented only for @p dim == 3.
406  */
407  static unsigned int line_between_faces(unsigned int f1, unsigned int f2);
408 
409 
410  static const unsigned int n_sides = dim + 1; ///< Number of sides.
411  static const unsigned int n_nodes = dim + 1; ///< Number of nodes.
412  static const unsigned int n_nodes_per_side = dim; ///< Number of nodes on one side.
413  static const unsigned int n_lines_per_node = dim; ///< Number of lines with one common node.
414  static const unsigned int n_nodes_per_line = 2; ///< Number of nodes in one line.
415  static const unsigned int n_sides_per_line = 2; ///< Number of sides with one common line. @p dim == 3.
416  static const unsigned int n_sides_per_node = dim; ///< Number of sides with one common line.
417 
418  /// Number of lines on boundary of one side.
419  static const unsigned int n_lines_per_side = (unsigned int)((dim * (dim - 1)) / 2);//( dim == 3 ? 3 : 0);// Kombinační číslo dim nad dvěma
420 
421  /// Number of lines, i.e. @p object of dimension @p dim-2 on the boundary of the reference element.
422  static const unsigned int n_lines = (unsigned int)((dim * (dim + 1)) / 2); //( dim == 3 ? 6 : dim == 2 ? 3 : dim == 1 ? 1 : 0); součet posloupnosti
423 
424 
426 
427 
428  /** @brief Converts from local to barycentric coordinates.
429  * @param lp point in local coordinates (x,y)
430  * @return point in barycentric coordinates (1-x-y, x, y)
431  */
432  static BaryPoint local_to_bary(const LocalPoint& lp);
433 
434  /** @brief Converts from barycentric to local coordinates.
435  * @param bp point in barycentric coordinates
436  * @return point in local coordinates
437  */
438  static LocalPoint bary_to_local(const BaryPoint& bp);
439 
441 
442  /**
443  * Used in the clip method.
444  */
446 
447  /**
448  * For given barycentric coordinates on the ref element returns barycentric coordinates
449  * on the ref. element of given face. Assumes that the input point is on the face.
450  * Barycentric order: (complanatory, local_coords )
451  */
452  static FaceBaryPoint barycentric_on_face(const BaryPoint &barycentric, unsigned int i_face);
453 
454 
456  static CentersList centers_of_subelements(unsigned int sub_dim);
457 
458  /**
459  * Return (1) number of zeros and (2) positions of zeros in barycentric coordinates.
460  * @p tolerance serves for testing zero values of @p barycentric coordinates.
461  */
462  static std::pair<unsigned int, unsigned int> zeros_positions(const BaryPoint &barycentric,
463  double tolerance = std::numeric_limits<double>::epsilon()*2);
464 
465  /**
466  * According to positions of zeros in barycentric coordinates, it gives the index of subdim-simplex
467  * in the reference element. Number of zeros must be equal to (3-subdim).
468  * e.g.:
469  * if 1 zeros, return index of side (subdim 2)
470  * if 2 zeros, return index of edge (subdim 1)
471  * if 3 zeros, return index of vertex (subdim 0)
472  */
473  template<unsigned int subdim> static unsigned int topology_idx(unsigned int zeros_positions);
474 
475  /** Function returns number of subdim-simplices inside dim-simplex.
476  * The aim is covering all the n_**** members with a single function.
477  * TODO: think of generalization for n_****_per_**** members, like function @p interact:
478  * template<unsigned int subdimA, unsigned int subdimB> static unsigned int count();
479  */
480  template<unsigned int subdim> static unsigned int count();
481 
482  /**
483  * @param sid - index of a sub-simplex in a simplex
484  * return an array of barycentric coordinates on <dim> simplex from <subdim> simplex
485  * for example: simplex<3> - ABCD and its subsubsimplex<1> AD (line index: 3)
486  * AD has barycoords for A (1,0), for D (0,1), but A in ABCD is (1,0,0,0) and D is (0,0,0,1)
487  * this method creates array ((1,0,0,0),(0,0,0,1))
488  */
489  template<unsigned int subdim> static arma::mat::fixed<dim+1,subdim+1> bary_coords(unsigned int sid);
490 
491  /** Interpolate barycentric coords to a higher dimension of a simplex.
492  * @param coord - barycentric coords of a point on a sub-simplex
493  * @param sub_simplex_idx - id of sub-simplex on a simplex
494  */
495  template<unsigned int subdim> static BaryPoint interpolate(arma::vec::fixed<subdim+1> coord, int sub_simplex_idx);
496 
497 
498  /**
499  * Basic line interpolation.
500  */
502  BaryPoint second_coords,
503  double first_theta, double second_theta, double theta);
504 
505  /**
506  * Usage:
507  * RefElement<3>::interact(Interaction<2,0>(1))
508  * (means: In tetrahedron <3>, give indices of sides <2>, connected by node <0> with index 1)
509  * RefElement<3>::interact(Interaction<2,0>(1))[1]
510  * (as above, but give only the side with index 1)
511  *
512  * Template usage: RefElement<dim>::interact(Interaction<OutDim, InDim>(i))[j]
513  * (means: on dim-dimensional reference element, go on InDim-dimensional subelement with index i,
514  * which connects OutDim-dimnesional subelements and select the one with index j)
515  *
516  * This method serves as an interface to topology information of the reference element.
517  * It returns indices of OutDim-dimensional object
518  * of InDim-dimnesional object of given index
519  * in dim-dimnesional reference element.
520  * @tparam interaction - auxilliary object carying the index and the template arguments OutDim and InDim
521  * @tparam OutDim - output dimension (give me node-0, line-1, side-2), <= dim
522  * @tparam InDim - input dimension (for node-0, line-1, side-2), <= dim
523  * @return vector of indices of OutDim-dimensional subelements represented by @p IdxVector object.
524  *
525  * possible calls:
526  * dim OutDim InDim return
527  * 1,2,3 0 1 InDim+1 - give me indices of nodes of line of given index
528  * 3 0 2 InDim+1 - give me indices of nodes of a side (triangle) of given index
529  * 3 1 2 InDim+1 - give me indices of lines of side (triangle) of given index
530  *
531  * 1,2,3 1 0 dim-InDim - give me indices of lines with common node of given index
532  * 3 2 0 dim-InDim - give me indices of sides (triangles) with common node of given index
533  * 3 2 1 dim-InDim - give me indices of sides (triangles) with common line of given index
534  *
535  */
536  template < template <unsigned int OutDim, unsigned int InDim> class TInteraction, unsigned int OutDim, unsigned int InDim>
537  static const IdxVector< (InDim>OutDim ? InDim+1 : dim-InDim) > interact( TInteraction<OutDim,InDim> interaction, bool inv = false );
538 
539 
540 private:
541  /// Internal part of the interact function.
542  template<unsigned int OutDim, unsigned int InDim>
543  static const IdxVector< (InDim>OutDim ? InDim+1 : dim-InDim) > interact_(unsigned int index, bool inv = false);
544 
545  static const std::vector<IdxVector<n_nodes_per_line>> line_nodes_; ///< [n_lines] For given line, returns its nodes indices.
546  static const std::vector<IdxVector<n_lines_per_node>> node_lines_; ///< [n_nodes] For given node, returns lines indices.
547  static const std::vector<IdxVector<n_nodes_per_side>> side_nodes_; ///< [n_sides] For given side, returns nodes indices. For @p dim == 3.
548  static const std::vector<IdxVector<n_sides_per_node>> node_sides_; ///< [n_nodes] For given node, returns sides indices. For @p dim == 3.
549  static const std::vector<IdxVector<n_sides_per_line>> line_sides_; ///< [n_lines] For given line, returns sides indices. For @p dim == 3.
550  static const std::vector<IdxVector<n_lines_per_side>> side_lines_; ///< [n_sides] For given side, returns lines indices. For @p dim == 3.
551 
552  //TODO: implement for 1d and 2d
553  /**
554  * Consider an n-face (node, edge, face, bulk) with dimension `subdim` and
555  * index within subdimension `idx`. Barycentric coordinates of all points
556  * on the n-face have unique pattern of zero coordinates.
557  *
558  * topology_zeros_[subdim][idx] is a bitfield with '1' where the pattern have zeros.
559  */
560  static const IdxVector<(n_lines > n_nodes) ? n_lines : n_nodes> topology_zeros_[dim+1];
561 };
562 
563 
564 // Declarations of explicit specialization of static memebers.
565 
570 
571 
577 
583 
584 
589 
590 
591 
592 
593 
594 
595 // 0: nodes of nodes
596 // 1: nodes of lines
597 // 2: nodes of sides
598 // 3: nodes of tetrahedron
603 
604 
605 
606 
607 
608 
609 
610 
611 
612 /************************* template implementation ****************************/
613 
614 template<unsigned int dim>
615 template<unsigned int subdim> inline
616 arma::mat::fixed<dim+1,subdim+1> RefElement<dim>::bary_coords(unsigned int sid){
617  ASSERT_LT(subdim, dim).error("Dimension mismatch!");
618  arma::mat::fixed<dim+1,subdim+1> bary_c;
619 
620  for(unsigned int i = 0; i < subdim+1; i++){
621  unsigned int nid = interact_<0,subdim>(sid)[i];
622  bary_c.col(i).zeros();
623  bary_c.col(i)(nid) = 1;
624  }
625 
626  return bary_c;
627 }
628 
629 
630 template<unsigned int dim> inline
631 arma::vec::fixed<dim> RefElement<dim>::node_coords(unsigned int nid)
632 {
633  ASSERT_LT(nid, n_nodes).error("Node number is out of range!");
634 
635  arma::vec::fixed<dim> p;
636  p.zeros();
637 
638  if (nid > 0)
639  p(nid-1) = 1;
640 
641  return p;
642 }
643 
644 
645 template<unsigned int dim>
646 template<unsigned int subdim>
647 auto RefElement<dim>::interpolate(arma::vec::fixed<subdim+1> coord, int sub_simplex_idx) -> BaryPoint
648 {
649  return RefElement<dim>::bary_coords<subdim>(sub_simplex_idx)*coord;
650 }
651 
652 
653 template<> template<> inline unsigned int RefElement<3>::count<0>()
654 { return n_nodes; }
655 template<> template<> inline unsigned int RefElement<3>::count<1>()
656 { return n_lines; }
657 template<> template<> inline unsigned int RefElement<3>::count<2>()
658 { return n_sides; }
659 template<> template<> inline unsigned int RefElement<3>::count<3>()
660 { return 1; }
661 template<> template<> inline unsigned int RefElement<2>::count<0>()
662 { return n_nodes; }
663 template<> template<> inline unsigned int RefElement<2>::count<1>()
664 { return n_lines; }
665 template<> template<> inline unsigned int RefElement<2>::count<2>()
666 { return 1; }
667 template<> template<> inline unsigned int RefElement<2>::count<3>()
668 { return 0; }
669 template<> template<> inline unsigned int RefElement<1>::count<0>()
670 { return n_nodes; }
671 template<> template<> inline unsigned int RefElement<1>::count<1>()
672 { return 1; }
673 template<> template<> inline unsigned int RefElement<1>::count<2>()
674 { return 0; }
675 template<> template<> inline unsigned int RefElement<1>::count<3>()
676 { return 0; }
677 template<> template<> inline unsigned int RefElement<0>::count<0>()
678 { return 1; }
679 template<> template<> inline unsigned int RefElement<0>::count<1>()
680 { return 0; }
681 template<> template<> inline unsigned int RefElement<0>::count<2>()
682 { return 0; }
683 template<> template<> inline unsigned int RefElement<0>::count<3>()
684 { return 0; }
685 
686 template<unsigned int dim>
687 template<unsigned int subdim>
688 unsigned int RefElement<dim>::topology_idx(unsigned int zeros_positions)
689 {
690  for(unsigned int i=0; i < RefElement<dim>::count<subdim>(); i++){
691  if(zeros_positions == topology_zeros_[subdim][i]) return i;
692  }
693  ASSERT_PERMANENT(0).error("Undefined zero pattern.");
694  return -1;
695 }
696 
697 
698 /// This function is for "side_nodes" - for given side, give me nodes (0->0, 1->1).
699 template<> template<> inline const IdxVector<1> RefElement<1>::interact_<0,0>(unsigned int i, bool inv)
700 { ASSERT_LT(i, RefElement<1>::n_nodes)(inv).error("Index out of bounds.");
701  return IdxVector<1>({i});}
702 
703 /// For line i {0}, give me indices of its nodes.
704 template<> template<> inline const IdxVector<2> RefElement<1>::interact_<0,1>(unsigned int i, bool inv)
705 { ASSERT_LT(i, RefElement<1>::n_lines)(inv).error("Index out of bounds.");
706  return line_nodes_[i];}
707 
708 /// For line i {0,1,2}, give me indices of its nodes.
709 template<> template<> inline const IdxVector<2> RefElement<2>::interact_<0,1>(unsigned int i, bool inv)
710 { ASSERT_LT(i, RefElement<2>::n_lines)(inv).error("Index out of bounds.");
711  return line_nodes_[i];}
712 
713 /// For line i {0,1,2,3,4,5}, give me indices of its nodes.
714 template<> template<> inline const IdxVector<2> RefElement<3>::interact_<0,1>(unsigned int i, bool inv)
715 { ASSERT_LT(i, RefElement<3>::n_lines)(inv).error("Index out of bounds.");
716  return line_nodes_[i];}
717 
718 /// For node i {0,1}, give me indices of lines.
719 template<> template<> inline const IdxVector<1> RefElement<1>::interact_<1,0>(unsigned int i, bool inv)
720 { ASSERT_LT(i, RefElement<1>::n_nodes)(inv).error("Index out of bounds.");
721  return node_lines_[i];}
722 
723 /// For node i {0,1,2}, give me indices of lines.
724 template<> template<> inline const IdxVector<2> RefElement<2>::interact_<1,0>(unsigned int i, bool inv)
725 { ASSERT_LT(i, RefElement<2>::n_nodes)(inv).error("Index out of bounds.");
726  return node_lines_[i];}
727 
728 /// For node i {0,1,2,3}, give me indices of lines.
729 template<> template<> inline const IdxVector<3> RefElement<3>::interact_<1,0>(unsigned int i, bool inv)
730 { ASSERT_LT(i, RefElement<3>::n_nodes).error("Index out of bounds.");
731  return _AuxInteract::S3_node_lines[inv][i];}
732 
733 /// For side i {0,1,2}, give me indices of its nodes.
734 template<> template<> inline const IdxVector<3> RefElement<3>::interact_<0,2>(unsigned int i, bool inv)
735 { ASSERT_LT(i, RefElement<3>::n_sides)(inv).error("Index out of bounds.");
736  return side_nodes_[i];}
737 
738 /// For node i {0,1,2,3}, give me indices of sides.
739 template<> template<> inline const IdxVector<3> RefElement<3>::interact_<2,0>(unsigned int i, bool inv)
740 { ASSERT_LT(i, RefElement<3>::n_sides).error("Index out of bounds.");
741  return _AuxInteract::S3_node_sides[inv][i];}
742 
743 /// For line i {0,1,2,3}, give me indices of sides.
744 template<> template<> inline const IdxVector<2> RefElement<3>::interact_<2,1>(unsigned int i, bool inv)
745 { ASSERT_LT(i, RefElement<3>::n_lines).error("Index out of bounds.");
746  return _AuxInteract::S3_line_sides[inv][i];}
747 
748 /// For side i {0,1,2}, give me indices of its lines.
749 template<> template<> inline const IdxVector<3> RefElement<3>::interact_<1,2>(unsigned int i, bool inv)
750 { ASSERT_LT(i, RefElement<3>::n_sides)(inv).error("Index out of bounds.");
751  return side_lines_[i];}
752 
753 template<unsigned int dim> template<unsigned int OutDim, unsigned int InDim>
754 inline const IdxVector< (InDim>OutDim ? InDim+1 : dim-InDim) > RefElement<dim>::interact_(unsigned int i, bool inv)
755 {
756  ASSERT_PERMANENT(false)(dim)(OutDim)(InDim)(i)(inv).error("Not implemented.");
757  //ASSERT_LT(OutDim, dim);
758  //ASSERT_LT(InDim, dim);
759  return IdxVector< (InDim>OutDim ? InDim+1 : dim-InDim) >(); // just to avoid warning for missing return
760 }
761 
762 
763 template<unsigned int dim>
764 template < template <unsigned int OutDim, unsigned int InDim> class TInteraction, unsigned int OutDim, unsigned int InDim>
765 inline const IdxVector< (InDim>OutDim ? InDim+1 : dim-InDim) > RefElement<dim>::interact( TInteraction<OutDim,InDim> interaction , bool inv)
766 {
767  return interact_<OutDim,InDim>(interaction.i_, inv);
768 }
769 
770 #endif /* REF_ELEMENT_HH_ */
Definitions of ASSERTS.
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
static const std::vector< IdxVector< n_lines_per_side > > side_lines_
[n_sides] For given side, returns lines indices. For dim == 3.
Definition: ref_element.hh:550
static CentersList centers_of_subelements(unsigned int sub_dim)
Definition: ref_element.cc:391
static const std::vector< IdxVector< n_nodes_per_line > > line_nodes_
[n_lines] For given line, returns its nodes indices.
Definition: ref_element.hh:545
static LocalPoint bary_to_local(const BaryPoint &bp)
Converts from barycentric to local coordinates.
Definition: ref_element.cc:201
static unsigned int normal_orientation(unsigned int sid)
Definition: ref_element.cc:216
static const unsigned int n_lines_per_node
Number of lines with one common node.
Definition: ref_element.hh:413
Armor::ArmaVec< double, dim > FaceBaryPoint
Definition: ref_element.hh:352
Armor::ArmaVec< double, dim+1 > BaryPoint
Definition: ref_element.hh:351
static FaceBaryPoint barycentric_on_face(const BaryPoint &barycentric, unsigned int i_face)
Definition: ref_element.cc:304
const std::vector< LocalPoint > & CentersList
Definition: ref_element.hh:455
static Eigen::Vector< ArrayDbl, dim > normal_vector_array(Eigen::Array< uint, Eigen::Dynamic, 1 > loc_side_idx_array)
Definition: ref_element.cc:279
std::vector< BaryPoint > BarycentricUnitVec
Definition: ref_element.hh:440
static BaryPoint line_barycentric_interpolation(BaryPoint first_coords, BaryPoint second_coords, double first_theta, double second_theta, double theta)
Definition: ref_element.cc:462
static const unsigned int n_sides
Number of sides.
Definition: ref_element.hh:410
static const std::vector< IdxVector< n_sides_per_line > > line_sides_
[n_lines] For given line, returns sides indices. For dim == 3.
Definition: ref_element.hh:549
static const IdxVector<(n_lines > n_nodes) ? n_lines :n_nodes > topology_zeros_[dim+1]
Definition: ref_element.hh:560
Eigen::Array< double, Eigen::Dynamic, 1 > ArrayDbl
Definition: ref_element.hh:355
static const std::vector< IdxVector< n_lines_per_node > > node_lines_
[n_nodes] For given node, returns lines indices.
Definition: ref_element.hh:546
arma::vec::fixed< dim > LocalPoint
Definition: ref_element.hh:344
static BaryPoint local_to_bary(const LocalPoint &lp)
Converts from local to barycentric coordinates.
Definition: ref_element.cc:187
static const unsigned int n_lines_per_side
Number of lines on boundary of one side.
Definition: ref_element.hh:419
static BarycentricUnitVec make_bary_unit_vec()
Definition: ref_element.cc:343
static std::pair< unsigned int, unsigned int > zeros_positions(const BaryPoint &barycentric, double tolerance=std::numeric_limits< double >::epsilon() *2)
Definition: ref_element.cc:319
static const unsigned int n_nodes
Number of nodes.
Definition: ref_element.hh:411
DECLARE_EXCEPTION(ExcInvalidPermutation,<< "Side permutation not found.\n")
static const unsigned int n_nodes_per_side
Number of nodes on one side.
Definition: ref_element.hh:412
static const IdxVector<(InDim >OutDim ? InDim+1 :dim-InDim) > interact_(unsigned int index, bool inv=false)
Internal part of the interact function.
static arma::mat::fixed< dim+1, subdim+1 > bary_coords(unsigned int sid)
Definition: ref_element.hh:616
static const unsigned int n_sides_per_node
Number of sides with one common line.
Definition: ref_element.hh:416
static const unsigned int n_nodes_per_line
Number of nodes in one line.
Definition: ref_element.hh:414
static unsigned int line_between_faces(unsigned int f1, unsigned int f2)
static unsigned int topology_idx(unsigned int zeros_positions)
Definition: ref_element.hh:688
static const std::vector< IdxVector< n_sides_per_node > > node_sides_
[n_nodes] For given node, returns sides indices. For dim == 3.
Definition: ref_element.hh:548
static const unsigned int n_sides_per_line
Number of sides with one common line. dim == 3.
Definition: ref_element.hh:415
static BaryPoint interpolate(arma::vec::fixed< subdim+1 > coord, int sub_simplex_idx)
static LocalPoint node_coords(unsigned int nid)
Definition: ref_element.hh:631
static BaryPoint clip(const BaryPoint &barycentric)
Definition: ref_element.cc:357
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:422
static unsigned int count()
static LocalPoint normal_vector(unsigned int sid)
static const IdxVector<(InDim >OutDim ? InDim+1 :dim-InDim) > interact(TInteraction< OutDim, InDim > interaction, bool inv=false)
static unsigned int oposite_node(unsigned int sid)
Definition: ref_element.cc:209
static const std::vector< std::vector< std::vector< unsigned int > > > nodes_of_subelements
Definition: ref_element.hh:425
static const std::vector< IdxVector< n_nodes_per_side > > side_nodes_
[n_sides] For given side, returns nodes indices. For dim == 3.
Definition: ref_element.hh:547
static constexpr IdxVector< 3 > S3_node_sides[2][4]
Definition: ref_element.hh:300
static constexpr IdxVector< 3 > S3_node_lines[2][4]
Definition: ref_element.hh:328
static constexpr IdxVector< 2 > S3_line_sides[2][6]
Definition: ref_element.hh:312
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
std::array< unsigned int, Size > IdxVector
Definition: ref_element.hh:278
Interaction(unsigned int i)
Definition: ref_element.hh:289
unsigned int i_
Definition: ref_element.hh:290