Flow123d  release_3.0.0-1211-g84d0b74
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/side_impl.hh"
9 #include "mesh/mesh.h"
11 #include "mesh/ref_element.hh"
12 #include "mesh/accessors.hh"
13 #include "system/system.hh"
14 
15 using namespace std;
16 
17 
18 template<unsigned int N, unsigned int M>
20 { local_bcoords_A_.zeros();
21  local_bcoords_B_.zeros();
22  idx_A_ = 0;
23  idx_B_ = 0;
24  result_ = IntersectionResult::none;
25  dim_A_ = N;
26  dim_B_ = M;
27 }
28 
29 template<unsigned int N, unsigned int M>
31 {
32  clear();
33 };
34 
35 template<unsigned int N, unsigned int M>
36 IntersectionPointAux<N,M>::IntersectionPointAux(const arma::vec::fixed<N+1> &lcA,
37  const arma::vec::fixed<M+1> &lcB,
38  unsigned int dim_A,
39  unsigned int dim_B)
40  : local_bcoords_A_(lcA), local_bcoords_B_(lcB), dim_A_(dim_A), dim_B_(dim_B)
41  {};
42 
43 
44 template<unsigned int N, unsigned int M>
46  ASSERT_DBG(M>1 && M<4);
47 
50 
51  dim_A_ = IP.dim_A();
52  idx_A_ = IP.idx_A();
53  result_ = IP.result();
54 
55  /**
56  * TODO: set correct topology on B. Currently this is done ad hoc after call of this constructor.
57  * Problem, dim_B_ can not be used as template parameter. Can we have some variant of interact without
58  * template?
59  * TODO: done below, but try getting rid of the switch
60  */
61  //dim_B_ = IP.dim_B();
62  //idx_B_ =RefElement<M>::interact(Interaction<dim_B_, M-1>(IP.idx_B()));
63 
64  dim_B_ = IP.dim_B();
65  idx_B_ = idx_B;
66 
67  // possibly correct topology n-face index
68  if(dim_B_ < M-1){
69  switch(dim_B_){
71  break;
73  break;
74  default: idx_B_ = idx_B;
75  }
76  }
77 // dim_B_ = M-1;
78 // idx_B_ = idx_B;
79 };
80 
81 
82 template<unsigned int N, unsigned int M>
84  ASSERT_DBG(M == 3);
85 
88 
89  dim_A_ = IP.dim_A();
90  idx_A_ = IP.idx_A();
91  result_ = IP.result();
92 
93  // only case is M=3, so we can do:
94  dim_B_ = IP.dim_B();
95  if(dim_B_ == 0)
97  else
98  idx_B_ = idx_B;
99 };
100 
101 template<unsigned int N, unsigned int M>
103 {
107  IP.set_result(result_);
108  return IP;
109 };
110 
111 
112 template<unsigned int N, unsigned int M>
114 {
115  ASSERT_DBG(N == ele->dim());
116 
117  arma::vec::fixed< 3 > c;
118  c.zeros();
119  for(unsigned int i=0; i<N+1; i++)
120  c += local_bcoords_A_[i]*ele.node(i)->point();
121 
122  return c;
123 }
124 
125 /*
126 template<> bool IntersectionPointAux<2,3>::operator<(const IntersectionPointAux<2,3> &ip) const{
127  return local_bcoords_A_[1] < ip.local_bcoords_A()[1] || // compare by x coordinate
128  (local_bcoords_A_[1] == ip.local_bcoords_A()[1] && // in case of tie
129  local_bcoords_A_[2] < ip.local_bcoords_A()[2]); // compare by y coordinate
130 };
131 */
132 
133 template<unsigned int N, unsigned int M>
135 {
136  return
137  dim_A_ == other.dim_A() &&
138  dim_B_ == other.dim_B() &&
139  idx_A_ == other.idx_A() &&
140  idx_B_ == other.idx_B();
141 }
142 
143 
144 
145 template<unsigned int N, unsigned int M> ostream& operator<<(ostream& os, const IntersectionPointAux< N,M >& s)
146 {
147  os << "Local coords on element A(id=" << s.idx_A_ << ", dim=" << s.dim_A_ << ")" << endl;
148  s.local_bcoords_A_.print(os);
149  os << "Local coords on element B(id=" << s.idx_B_ << ", dim=" << s.dim_B_ << ")" << endl;
150  s.local_bcoords_B_.print(os);
151  os << "Result: " << int(s.result_) << endl;
152  return os;
153 }
154 
155 template class IntersectionPointAux<1,2>;
156 template class IntersectionPointAux<2,1>;
157 template class IntersectionPointAux<2,2>;
158 template class IntersectionPointAux<1,3>;
159 template class IntersectionPointAux<3,1>;
160 template class IntersectionPointAux<2,3>;
161 template class IntersectionPointAux<3,2>;
162 
163 template ostream& operator<< <1,2>(ostream &os, const IntersectionPointAux<1,2>& s);
164 template ostream& operator<< <2,1>(ostream &os, const IntersectionPointAux<2,1>& s);
165 template ostream& operator<< <2,2>(ostream &os, const IntersectionPointAux<2,2>& s);
166 template ostream& operator<< <1,3>(ostream &os, const IntersectionPointAux<1,3>& s);
167 template ostream& operator<< <3,1>(ostream &os, const IntersectionPointAux<3,1>& s);
168 template ostream& operator<< <2,3>(ostream &os, const IntersectionPointAux<2,3>& s);
169 template ostream& operator<< <3,2>(ostream &os, const IntersectionPointAux<3,2>& s);
170 
171 
172 
173 
174 
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)
IntersectionResult result() const
Result: 0 - negative sign, 1 - positive sign, 2 - degenerate (zero for all sides), 3 - none.
arma::vec::fixed< N+1 > local_bcoords_A_
Barycentric coordinates of an IP on simplex<N>.
IntersectionResult result_
Intersection result according to Plucker products.
void clear()
Resets the object to default values.
arma::vec::fixed< M+1 > local_bcoords_B_
Barycentric coordinates of an IP on simplex<M>.
template ostream & operator<< < 2, 3 >(ostream &os, const IntersectionPointAux< 2, 3 > &s)
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>.
unsigned int dim_B() const
Returns dimension of object B.
unsigned int dim() const
Definition: elements.h:124
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.
static const IdxVector< (InDim >OutDim?InDim+1:dim-InDim) > interact(TInteraction< OutDim, InDim > interaction)
unsigned int dim_A_
Dimension of the object A of intersection. Equal N, by default.
arma::vec::fixed< 3 > coords(ElementAccessor< 3 > ele) const
Computes real coordinates of IP, given the element ele in which IP lies.
template ostream & operator<< < 2, 1 >(ostream &os, const IntersectionPointAux< 2, 1 > &s)
bool topology_equal(const IntersectionPointAux< N, M > &other) const
Returns true, if other intersection point has the same topology.
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...
template ostream & operator<< < 1, 3 >(ostream &os, const IntersectionPointAux< 1, 3 > &s)
unsigned int idx_B() const
arma::vec3 & point()
Definition: nodes.hh:67
void set_result(IntersectionResult result)
Setter orientation flag.
Internal class representing intersection point.
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_.
const Node * node(unsigned int ni) const
Definition: accessors.hh:145
template ostream & operator<< < 1, 2 >(ostream &os, const IntersectionPointAux< 1, 2 > &s)