Flow123d  release_2.2.0-914-gf1a3a4f
intersection_point_aux.cc
Go to the documentation of this file.
1 /*
2  * intersectionpoint.cpp
3  *
4  * Created on: 11.4.2014
5  * Author: viktor
6  */
7 
8 // #include "mesh/elements.h"
9 #include "mesh/mesh.h"
11 #include "mesh/ref_element.hh"
12 // #include "mesh/elements.h" //TODO what is the best way of include to use ElementFullIter ?
13 #include "mesh/mesh.h"
14 #include "system/system.hh"
15 
16 using namespace std;
17 
18 
19 template<unsigned int N, unsigned int M>
21 { local_bcoords_A_.zeros();
22  local_bcoords_B_.zeros();
23  idx_A_ = 0;
24  idx_B_ = 0;
25  orientation_ = IntersectionResult::none;
26  dim_A_ = N;
27  dim_B_ = M;
28 }
29 
30 template<unsigned int N, unsigned int M>
32 {
33  clear();
34 };
35 
36 template<unsigned int N, unsigned int M>
37 IntersectionPointAux<N,M>::IntersectionPointAux(const arma::vec::fixed<N+1> &lcA,
38  const arma::vec::fixed<M+1> &lcB,
39  unsigned int dim_A,
40  unsigned int dim_B)
41  : local_bcoords_A_(lcA), local_bcoords_B_(lcB), dim_A_(dim_A), dim_B_(dim_B)
42  {};
43 
44 
45 // template<unsigned int N, unsigned int M>
46 // IntersectionPointAux<N,M>::IntersectionPointAux(IntersectionPointAux<M, N> &IP){
47 // local_bcoords_A_ = IP.local_bcoords_B();
48 // local_bcoords_B_ = IP.local_bcoords_A();
49 // idx_A_ = IP.idx_B();
50 // idx_B_ = IP.idx_A();
51 // orientation_ = IP.orientation();
52 // dim_A_ = IP.dim_B();
53 // dim_B_ = IP.dim_A();
54 // };
55 
56 
57 template<unsigned int N, unsigned int M>
59  ASSERT_DBG(M>1 && M<4);
60 
63 
64  dim_A_ = IP.dim_A();
65  idx_A_ = IP.idx_A();
67 
68  /**
69  * TODO: set correct topology on B. Currently this is done ad hoc after call of this constructor.
70  * Problem, dim_B_ can not be used as template parameter. Can we have some variant of interact without
71  * template?
72  */
73  //dim_B_ = IP.dim_B();
74  //idx_B_ =RefElement<M>::interact(Interaction<dim_B_, M-1>(IP.idx_B()));
75 
76  dim_B_ = M-1;
77  idx_B_ = idx_B;
78 };
79 
80 
81 template<unsigned int N, unsigned int M>
83  ASSERT_DBG(M == 3);
84 
87 
88  idx_A_ = IP.idx_A();
89  idx_B_ = idx_B;
91  dim_A_ = IP.dim_A();
92  dim_B_ = M-2;
93 };
94 
95 template<unsigned int N, unsigned int M>
97 {
102  return IP;
103 };
104 
105 
106 template<unsigned int N, unsigned int M>
107 arma::vec::fixed< 3 > IntersectionPointAux<N,M>::coords(ElementFullIter ele) const
108 {
109  ASSERT_DBG(N == ele->dim());
110 
111  arma::vec::fixed< 3 > c;
112  c.zeros();
113  for(unsigned int i=0; i<N+1; i++)
114  c += local_bcoords_A_[i]*ele->node[i]->point();
115 
116  return c;
117 }
118 
119 /*
120 template<> bool IntersectionPointAux<2,3>::operator<(const IntersectionPointAux<2,3> &ip) const{
121  return local_bcoords_A_[1] < ip.local_bcoords_A()[1] || // compare by x coordinate
122  (local_bcoords_A_[1] == ip.local_bcoords_A()[1] && // in case of tie
123  local_bcoords_A_[2] < ip.local_bcoords_A()[2]); // compare by y coordinate
124 };
125 */
126 
127 
128 
129 template<unsigned int N, unsigned int M> ostream& operator<<(ostream& os, const IntersectionPointAux< N,M >& s)
130 {
131  os << "Local coords on element A(id=" << s.idx_A_ << ", dim=" << s.dim_A_ << ")" << endl;
132  s.local_bcoords_A_.print(os);
133  os << "Local coords on element B(id=" << s.idx_B_ << ", dim=" << s.dim_B_ << ")" << endl;
134  s.local_bcoords_B_.print(os);
135  os << "Orientation: " << int(s.orientation_) << " Patological: " << s.is_pathologic() << endl;
136  return os;
137 }
138 
139 template class IntersectionPointAux<1,2>;
140 template class IntersectionPointAux<2,1>;
141 template class IntersectionPointAux<2,2>;
142 template class IntersectionPointAux<1,3>;
143 template class IntersectionPointAux<3,1>;
144 template class IntersectionPointAux<2,3>;
145 template class IntersectionPointAux<3,2>;
146 
147 template ostream& operator<< <1,2>(ostream &os, const IntersectionPointAux<1,2>& s);
148 template ostream& operator<< <2,1>(ostream &os, const IntersectionPointAux<2,1>& s);
149 template ostream& operator<< <2,2>(ostream &os, const IntersectionPointAux<2,2>& s);
150 template ostream& operator<< <1,3>(ostream &os, const IntersectionPointAux<1,3>& s);
151 template ostream& operator<< <3,1>(ostream &os, const IntersectionPointAux<3,1>& s);
152 template ostream& operator<< <2,3>(ostream &os, const IntersectionPointAux<2,3>& s);
153 template ostream& operator<< <3,2>(ostream &os, const IntersectionPointAux<3,2>& s);
154 
155 
156 
157 
158 
template ostream & operator<< < 2, 2 >(ostream &os, const IntersectionPointAux< 2, 2 > &s)
unsigned int dim_A() const
Returns dimension of object A.
template ostream & operator<< < 3, 2 >(ostream &os, const IntersectionPointAux< 3, 2 > &s)
arma::vec::fixed< N+1 > local_bcoords_A_
Barycentric coordinates of an IP on simplex<N>.
void clear()
Resets the object to default values.
arma::vec::fixed< M+1 > local_bcoords_B_
Barycentric coordinates of an IP on simplex<M>.
void set_orientation(IntersectionResult orientation)
Setter orientation flag.
template ostream & operator<< < 2, 3 >(ostream &os, const IntersectionPointAux< 2, 3 > &s)
arma::vec::fixed< 3 > coords(ElementFullIter ele) const
Computes real coordinates of IP, given the element ele in which IP lies.
const arma::vec::fixed< N+1 > & local_bcoords_A() const
Returns barycentric coordinates in the Simplex<N>.
const arma::vec::fixed< M+1 > & local_bcoords_B() const
Returns barycentric coordinates in the Simplex<M>.
unsigned int idx_A() const
Returns the index of Simplex<N>.
void set_coordinates(const arma::vec::fixed< N+1 > &lcA, const arma::vec::fixed< M+1 > &lcB)
Setter for coordinates.
unsigned int idx_A_
Local indices of element objects that intersects.
IntersectionPointAux()
Default constructor.
unsigned int dim_A_
Dimension of the object A of intersection. Equal N, by default.
template ostream & operator<< < 2, 1 >(ostream &os, const IntersectionPointAux< 2, 1 > &s)
IntersectionResult orientation_
Orientation according to Plucker products.
IntersectionPointAux< M, N > switch_objects() const
Switches the object A and B.
#define ASSERT_DBG(expr)
Definition: asserts.hh:349
unsigned int dim_B_
Dimension of the object B of intersection. Equal M, by default.
Internal auxiliary class represents an intersection point of simplex<N> and simplex<M>.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
IntersectionResult orientation() const
Returns the orientation.
template ostream & operator<< < 1, 3 >(ostream &os, const IntersectionPointAux< 1, 3 > &s)
unsigned int idx_B() const
Returns the index of Simplex<M>.
Internal class representing intersection point.
IntersectionPoint * interpolate(const IntersectionPoint &A1, const IntersectionPoint &A2, double t)
template ostream & operator<< < 3, 1 >(ostream &os, const IntersectionPointAux< 3, 1 > &s)
void set_topology(unsigned int idx_A, unsigned int dim_A, unsigned int idx_B, unsigned int dim_B)
Setter for topology data. See description of idx_A_ and dim_A_.
template ostream & operator<< < 1, 2 >(ostream &os, const IntersectionPointAux< 1, 2 > &s)