Flow123d  release_2.2.0-914-gf1a3a4f
simplex.cc
Go to the documentation of this file.
1 #include "simplex.hh"
2 #include <iostream>
3 #include <armadillo>
4 #include "system/system.hh"
5 #include "mesh/ref_element.hh"
6 
7 using namespace std;
8 
9 
10 template<unsigned int N> void Simplex<N>::set_simplices(arma::vec3 **field_of_pointers_to_coordinates)
11 {
12  ASSERT_DBG(field_of_pointers_to_coordinates !=nullptr);
13  arma::vec3 *temporary_pointers[N];
14 
15  // filling temporary array of size N from array of size (N+1)
16  for (unsigned int i = 0; i < N; i++) {
17  temporary_pointers[i] = field_of_pointers_to_coordinates[i];
18  };
19  // Creating sub-simplices in lexicografic order
20  simplices_[0].set_simplices(temporary_pointers);
21  for (unsigned int i = 1; i < N + 1; i++) {
22  temporary_pointers[N - i] = field_of_pointers_to_coordinates[N - i + 1];
23  simplices_[i].set_simplices(temporary_pointers);
24  }
25 }
26 
27 const static std::vector<unsigned int> face_edge = {0,0,1,2,1,2};
28 template<> Simplex<1> &Simplex<3>::abscissa(unsigned int idx) {
29  ASSERT_DBG(idx < 6);
30  /* we need the first sub-simplex for getting first three abscissas
31  * the second sub-simplex for other two abscissas
32  * the third sub-simplex for the last abscissa
33  */
34 
35  unsigned int face = RefElement<3>::interact(Interaction<2,1>(idx))[0];
36  return simplices_[face][face_edge[idx]];
37 }
38 
39 
40 template<> Simplex<1> &Simplex<2>::abscissa(unsigned int idx) {
41  ASSERT_DBG(idx < 3);
42  return simplices_[idx];
43 }
44 
45 template<> Simplex<0> &Simplex<1>::node(unsigned int idx) {
46  ASSERT_DBG(idx < 2);
47  return simplices_[idx];
48 }
49 
50 template<> Simplex<0> &Simplex<2>::node(unsigned int idx) {
51  ASSERT_DBG(idx < 3);
52  if(idx == 2) return simplices_[1][1];
53  else return simplices_[0][idx];
54 }
55 
56 template<> Simplex<0> &Simplex<3>::node(unsigned int idx) {
57  ASSERT_DBG(idx < 4);
58  if(idx == 3) return simplices_[1][1][1];
59  else return simplices_[0].node(idx);
60 }
61 
62 template<> ostream& operator<< <0>(ostream& os, const Simplex< 0 >& s)
63 {
64  ASSERT_DBG(s.coords_ != nullptr);
65  os << "Simplex<0>(" << (*(s.coords_))[0] << "," << (*(s.coords_))[1] << "," << (*(s.coords_))[2] << ")";
66  return os;
67 }
68 
69 template<unsigned int N> ostream& operator<<(ostream& os, const Simplex< N >& s)
70 {
71  os << "Simplex<" << N << ">:" << endl;
72  for (unsigned int i = 0; i < N + 1; i++) {
73  for (unsigned int j = 3; N <= j; j--) {
74  os << " ";
75  }
76  os << s.simplices_[i] << endl;
77  }
78  return os;
79 }
80 
81 
82 template class Simplex<1>;
83 template class Simplex<2>;
84 template class Simplex<3>;
85 
86 template ostream& operator<< <1>(ostream &os, const Simplex<1>& s);
87 template ostream& operator<< <2>(ostream &os, const Simplex<2>& s);
88 template ostream& operator<< <3>(ostream &os, const Simplex<3>& s);
89 
90 
template ostream & operator<< < 1 >(ostream &os, const Simplex< 1 > &s)
void set_simplices(arma::vec3 **field_of_pointers_to_coordinates)
Creating sub-simplices in lexicografic order.
Definition: simplex.cc:10
ostream & operator<< < 0 >(ostream &os, const Simplex< 0 > &s)
Definition: simplex.cc:62
Simplex< 0 > & node(unsigned int idx)
Simplex< 1 > & abscissa(unsigned int idx)
Get simplex of abscissa from different simplices - if it has own implementation in ...
template ostream & operator<< < 3 >(ostream &os, const Simplex< 3 > &s)
static const IdxVector< (InDim >OutDim?InDim+1:dim-InDim) > interact(TInteraction< OutDim, InDim > interaction)
template ostream & operator<< < 2 >(ostream &os, const Simplex< 2 > &s)
static const std::vector< unsigned int > face_edge
Definition: simplex.cc:27
#define ASSERT_DBG(expr)
Definition: asserts.hh:349
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...