Flow123d  JS_before_hm-2154-g185f171e0
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/mesh.h"
10 #include "mesh/ref_element.hh"
11 #include "mesh/accessors.hh"
12 #include "system/system.hh"
13 
14 using namespace std;
15 
16 
17 template<unsigned int N, unsigned int M>
19 { local_bcoords_A_.zeros();
20  local_bcoords_B_.zeros();
21  idx_A_ = 0;
22  idx_B_ = 0;
23  result_ = IntersectionResult::none;
24  dim_A_ = N;
25  dim_B_ = M;
26 }
27 
28 template<unsigned int N, unsigned int M>
30 {
31  clear();
32 }
33 
34 template<unsigned int N, unsigned int M>
35 IntersectionPointAux<N,M>::IntersectionPointAux(const arma::vec::fixed<N+1> &lcA,
36  const arma::vec::fixed<M+1> &lcB,
37  unsigned int dim_A,
38  unsigned int dim_B)
39  : local_bcoords_A_(lcA), local_bcoords_B_(lcB), dim_A_(dim_A), dim_B_(dim_B)
40  {}
41 
42 
43 template<unsigned int N, unsigned int M>
45  ASSERT_DBG(M>1 && M<4);
46 
47  local_bcoords_A_ = IP.local_bcoords_A();
48  local_bcoords_B_ = RefElement<M>::template interpolate<M-1>(IP.local_bcoords_B(), idx_B);
49 
50  dim_A_ = IP.dim_A();
51  idx_A_ = IP.idx_A();
52  result_ = IP.result();
53 
54  /**
55  * TODO: set correct topology on B. Currently this is done ad hoc after call of this constructor.
56  * Problem, dim_B_ can not be used as template parameter. Can we have some variant of interact without
57  * template?
58  * TODO: done below, but try getting rid of the switch
59  */
60  //dim_B_ = IP.dim_B();
61  //idx_B_ =RefElement<M>::interact(Interaction<dim_B_, M-1>(IP.idx_B()));
62 
63  dim_B_ = IP.dim_B();
64  idx_B_ = idx_B;
65 
66  // possibly correct topology n-face index
67  if(dim_B_ < M-1){
68  switch(dim_B_){
69  case 0: idx_B_ = RefElement<M>::interact(Interaction<0, M-1>(idx_B))[IP.idx_B()];
70  break;
71  case 1: idx_B_ = RefElement<M>::interact(Interaction<1, M-1>(idx_B))[IP.idx_B()];
72  break;
73  default: idx_B_ = idx_B;
74  }
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 
85  local_bcoords_A_ = IP.local_bcoords_A();
86  local_bcoords_B_ = RefElement<3>::interpolate<1>(IP.local_bcoords_B(), idx_B);
87 
88  dim_A_ = IP.dim_A();
89  idx_A_ = IP.idx_A();
90  result_ = IP.result();
91 
92  // only case is M=3, so we can do:
93  dim_B_ = IP.dim_B();
94  if(dim_B_ == 0)
95  idx_B_ = RefElement<3>::interact(Interaction<0,1>(idx_B))[IP.idx_B()];
96  else
97  idx_B_ = idx_B;
98 }
99 
100 template<unsigned int N, unsigned int M>
102 {
104  IP.set_coordinates(local_bcoords_B_,local_bcoords_A_);
105  IP.set_topology(idx_B_,dim_B_,idx_A_, dim_A_);
106  IP.set_result(result_);
107  return IP;
108 }
109 
110 
111 template<unsigned int N, unsigned int M>
113 {
114  ASSERT_DBG(N == ele->dim());
115 
116  arma::vec::fixed< 3 > c;
117  c.zeros();
118  for(unsigned int i=0; i<N+1; i++)
119  c += local_bcoords_A_[i]**ele.node(i);
120 
121  return c;
122 }
123 
124 /*
125 template<> bool IntersectionPointAux<2,3>::operator<(const IntersectionPointAux<2,3> &ip) const{
126  return local_bcoords_A_[1] < ip.local_bcoords_A()[1] || // compare by x coordinate
127  (local_bcoords_A_[1] == ip.local_bcoords_A()[1] && // in case of tie
128  local_bcoords_A_[2] < ip.local_bcoords_A()[2]); // compare by y coordinate
129 };
130 */
131 
132 template<unsigned int N, unsigned int M>
134 {
135  return
136  dim_A_ == other.dim_A() &&
137  dim_B_ == other.dim_B() &&
138  idx_A_ == other.idx_A() &&
139  idx_B_ == other.idx_B();
140 }
141 
142 
143 
144 template<unsigned int N, unsigned int M> ostream& operator<<(ostream& os, const IntersectionPointAux< N,M >& s)
145 {
146  os << "Local coords on element A(id=" << s.idx_A_ << ", dim=" << s.dim_A_ << ")" << endl;
147  s.local_bcoords_A_.print(os);
148  os << "Local coords on element B(id=" << s.idx_B_ << ", dim=" << s.dim_B_ << ")" << endl;
149  s.local_bcoords_B_.print(os);
150  os << "Result: " << int(s.result_) << endl;
151  return os;
152 }
153 
154 template class IntersectionPointAux<1,2>;
155 template class IntersectionPointAux<2,1>;
156 template class IntersectionPointAux<2,2>;
157 template class IntersectionPointAux<1,3>;
158 template class IntersectionPointAux<3,1>;
159 template class IntersectionPointAux<2,3>;
160 template class IntersectionPointAux<3,2>;
161 
162 template ostream& operator<< <1,2>(ostream &os, const IntersectionPointAux<1,2>& s);
163 template ostream& operator<< <2,1>(ostream &os, const IntersectionPointAux<2,1>& s);
164 template ostream& operator<< <2,2>(ostream &os, const IntersectionPointAux<2,2>& s);
165 template ostream& operator<< <1,3>(ostream &os, const IntersectionPointAux<1,3>& s);
166 template ostream& operator<< <3,1>(ostream &os, const IntersectionPointAux<3,1>& s);
167 template ostream& operator<< <2,3>(ostream &os, const IntersectionPointAux<2,3>& s);
168 template ostream& operator<< <3,2>(ostream &os, const IntersectionPointAux<3,2>& s);
169 
170 
171 
172 
173 
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
IntersectionPointAux::idx_A_
unsigned int idx_A_
Local indices of element objects that intersects.
Definition: intersection_point_aux.hh:74
IntersectionPointAux::IntersectionPointAux
IntersectionPointAux()
Default constructor.
Definition: intersection_point_aux.cc:29
RefElement
Definition: ref_element.hh:339
RefElement::interact
static const IdxVector<(InDim >OutDim ? InDim+1 :dim-InDim) > interact(TInteraction< OutDim, InDim > interaction, bool inv=false)
Element::dim
unsigned int dim() const
Definition: elements.h:120
operator<<< 2, 1 >
template ostream & operator<<< 2, 1 >(ostream &os, const IntersectionPointAux< 2, 1 > &s)
IntersectionPointAux::set_result
void set_result(IntersectionResult result)
Setter orientation flag.
Definition: intersection_point_aux.hh:209
IntersectionPointAux::idx_B_
unsigned int idx_B_
Definition: intersection_point_aux.hh:75
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
ElementAccessor< 3 >
system.hh
operator<<< 3, 1 >
template ostream & operator<<< 3, 1 >(ostream &os, const IntersectionPointAux< 3, 1 > &s)
IntersectionPointAux::topology_equal
bool topology_equal(const IntersectionPointAux< N, M > &other) const
Returns true, if other intersection point has the same topology.
Definition: intersection_point_aux.cc:133
operator<<
ostream & operator<<(ostream &os, const IntersectionPointAux< N, M > &s)
Definition: intersection_point_aux.cc:144
IntersectionPointAux::local_bcoords_A
const arma::vec::fixed< N+1 > & local_bcoords_A() const
Returns barycentric coordinates in the Simplex<N>.
Definition: intersection_point_aux.hh:221
accessors.hh
operator<<< 2, 3 >
template ostream & operator<<< 2, 3 >(ostream &os, const IntersectionPointAux< 2, 3 > &s)
IntersectionPointAux::dim_B_
unsigned int dim_B_
Dimension of the object B of intersection. Equal M, by default.
Definition: intersection_point_aux.hh:88
IntersectionPointAux::idx_A
unsigned int idx_A() const
Returns the index of Simplex<N>.
Definition: intersection_point_aux.hh:239
IntersectionPointAux::dim_A_
unsigned int dim_A_
Dimension of the object A of intersection. Equal N, by default.
Definition: intersection_point_aux.hh:87
IntersectionPointAux
Internal auxiliary class represents an intersection point of simplex<N> and simplex<M>.
Definition: compute_intersection.hh:50
IntersectionPointAux::dim_A
unsigned int dim_A() const
Returns dimension of object A.
Definition: intersection_point_aux.hh:213
operator<<< 3, 2 >
template ostream & operator<<< 3, 2 >(ostream &os, const IntersectionPointAux< 3, 2 > &s)
IntersectionPointAux::local_bcoords_B
const arma::vec::fixed< M+1 > & local_bcoords_B() const
Returns barycentric coordinates in the Simplex<M>.
Definition: intersection_point_aux.hh:225
mesh.h
IntersectionPointAux::clear
void clear()
Resets the object to default values.
Definition: intersection_point_aux.cc:18
ElementAccessor::node
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:233
IntersectionPointAux::set_topology
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_.
Definition: intersection_point_aux.hh:201
IntersectionPointAux::local_bcoords_B_
arma::vec::fixed< M+1 > local_bcoords_B_
Barycentric coordinates of an IP on simplex<M>.
Definition: intersection_point_aux.hh:61
Interaction
Definition: ref_element.hh:286
operator<<< 1, 2 >
template ostream & operator<<< 1, 2 >(ostream &os, const IntersectionPointAux< 1, 2 > &s)
IntersectionPointAux::switch_objects
IntersectionPointAux< M, N > switch_objects() const
Switches the object A and B.
Definition: intersection_point_aux.cc:101
IntersectionPointAux::local_bcoords_A_
arma::vec::fixed< N+1 > local_bcoords_A_
Barycentric coordinates of an IP on simplex<N>.
Definition: intersection_point_aux.hh:60
IntersectionPointAux::coords
arma::vec::fixed< 3 > coords(ElementAccessor< 3 > ele) const
Computes real coordinates of IP, given the element ele in which IP lies.
Definition: intersection_point_aux.cc:112
std
Definition: doxy_dummy_defs.hh:5
operator<<< 2, 2 >
template ostream & operator<<< 2, 2 >(ostream &os, const IntersectionPointAux< 2, 2 > &s)
IntersectionPointAux::set_coordinates
void set_coordinates(const arma::vec::fixed< N+1 > &lcA, const arma::vec::fixed< M+1 > &lcB)
Setter for coordinates.
Definition: intersection_point_aux.hh:196
IntersectionPointAux::idx_B
unsigned int idx_B() const
Returns the index of Simplex<M>.
Definition: intersection_point_aux.hh:243
IntersectionPointAux::result
IntersectionResult result() const
Result: 0 - negative sign, 1 - positive sign, 2 - degenerate (zero for all sides),...
Definition: intersection_point_aux.hh:247
IntersectionPointAux::result_
IntersectionResult result_
Intersection result according to Plucker products.
Definition: intersection_point_aux.hh:85
operator<<< 1, 3 >
template ostream & operator<<< 1, 3 >(ostream &os, const IntersectionPointAux< 1, 3 > &s)
IntersectionPointAux::dim_B
unsigned int dim_B() const
Returns dimension of object B.
Definition: intersection_point_aux.hh:217
IntersectionResult::none
@ none
intersection_point_aux.hh
Internal class representing intersection point.