Flow123d  JS_before_hm-1884-g94bc49f8c
intersection_point_aux.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 intersection_point_aux.hh
15  * @brief Internal class representing intersection point.
16  * @author Viktor Fris, Pavel Exner
17  *
18  */
19 
20 #ifndef INTERSECTIONPOINT_H_
21 #define INTERSECTIONPOINT_H_
22 
23 #include <armadillo>
24 template <int spacedim> class ElementAccessor;
25 
26 
27 
28 static const double geometry_epsilon = 1e-9;
29 
30 //http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
31 // static const double rounding_epsilon = 8*std::numeric_limits<double>::epsilon();
32 
33 //forward declare
34 template<unsigned int N, unsigned int M> class IntersectionPointAux;
35 template<unsigned int N, unsigned int M> std::ostream& operator<<(std::ostream& os, const IntersectionPointAux<N,M>& IP);
36 
37 
38 enum class IntersectionResult {
39  positive = 1,
40  negative = 0,
41  degenerate = 2,
42  none = 3
43 };
44 
46  return int(a) < int(b);
47 }
48 
49 /** @brief Internal auxiliary class represents an intersection point of simplex<N> and simplex<M>.
50  *
51  * It contains barycentric coordinates of the point on both simplices.
52  * Further, it contains topology information of the intersection point.
53  * Namely its orientation (according to Plucker coordinates product),
54  * pathologic flag, local indices and dimension of element objects (node/line/triangle).
55  * Refered as 'IP' in further documentation.
56  */
57 template<unsigned int N, unsigned int M>
59 
60  arma::vec::fixed<N+1> local_bcoords_A_; ///< Barycentric coordinates of an IP on simplex<N>.
61  arma::vec::fixed<M+1> local_bcoords_B_; ///< Barycentric coordinates of an IP on simplex<M>.
62 
63  /** @brief Local indices of element objects that intersects.
64  *
65  * Can be indices of point (vertex), lines (edge), triangle (side) in intersecting element,
66  * depending on the dimensions \p dim_A_, resp. \p dim_B_.
67  *
68  * Examples:
69  * dim_A=0, N=2 -> idx_A is local node index of triangle
70  * dim_B=2, N=3 -> idx_B is local side index of tetrahedron
71  * dim_B=1, N=3 -> idx_B is local line index of tetrahedron
72  */
73  //@{
74  unsigned int idx_A_;
75  unsigned int idx_B_;
76  //@}
77 
78  /** @brief Intersection result according to Plucker products.
79  *
80  * All Plucker products > 0 then @b positive.
81  * All Plucker products < 0 then @b negative.
82  * @b degenerate case.
83  * @b none - no intersection.
84  */
86 
87  unsigned int dim_A_; ///< Dimension of the object A of intersection. Equal \p N, by default.
88  unsigned int dim_B_; ///< Dimension of the object B of intersection. Equal \p M, by default.
89 
90 public:
91 
92  IntersectionPointAux(); ///< Default constructor.
93  ~IntersectionPointAux(){}; ///< Destructor.
94 
95  /** @brief Constructor taking barycentric coordinates on simplices as input parameters.
96  * @param lcA barycentric coordinates of IP in Simplex<N>
97  * @param lcB barycentric coordinates of IP in Simplex<M>
98  * @param dim_A dimension of object A
99  * @param dim_B dimension of object B
100  */
101  IntersectionPointAux(const arma::vec::fixed<N+1> &lcA, const arma::vec::fixed<M+1> &lcB,
102  unsigned int dim_A = N, unsigned int dim_B = M);
103 
104  /** @brief Constructor interpolates the second bary coords
105  * of IntersectionPointAux<N,M-1> to IntersectionPointAux<N,M>
106  *
107  * Allowed only from dimension \p M 1 to 2 and from 2 to 3.
108  * @param IP intersection point of lower dimension of object B
109  * @param idx_B is the index of object B of IntersectionPointAux<N,M-1> in object B of IntersectionPointAux<N,M>
110  */
111  IntersectionPointAux(const IntersectionPointAux<N,M-1> &IP, unsigned int idx_B);
112 
113  /** @brief Constructor interpolates the second bary coords
114  * of IntersectionPointAux<N,M-2> to IntersectionPointAux<N,M>
115  *
116  * Allowed only from dimension \p M 1 to 3.
117  * @param IP intersection point of lower dimension of object B
118  * @param idx_B is the index of object B of IntersectionPointAux<N,M-2> in object B of IntersectionPointAux<N,M>
119  */
120  IntersectionPointAux(const IntersectionPointAux<N,M-2> &IP, unsigned int idx_B);
121 
122  /// Resets the object to default values.
123  void clear();
124 
125  /// Switches the object A and B.
127 
128  ///@name Setters.
129  //@{
130  /** @brief Setter for coordinates.
131  * @param lcA braycentric coordinates of A
132  * @param lcB braycentric coordinates of B
133  */
134  void set_coordinates(const arma::vec::fixed<N+1> &lcA, const arma::vec::fixed<M+1> &lcB);
135 
136  /// Setter for topology data. See description of @p idx_A_ and @p dim_A_.
137  void set_topology(unsigned int idx_A, unsigned int dim_A,
138  unsigned int idx_B, unsigned int dim_B);
139 
140  void set_topology_A(unsigned int idx, unsigned int dim_A); ///< Sets the topology of object A in Simplex<N>.
141  void set_topology_B(unsigned int idx, unsigned int dim_B); ///< Sets the topology of object B in Simplex<M>.
142  void set_result(IntersectionResult result); ///< Setter orientation flag.
143 
144  //@}
145 
146 
147  ///@name Getters.
148  //@{
149  /// Returns barycentric coordinates in the Simplex<N>.
150  const arma::vec::fixed<N+1> &local_bcoords_A() const;
151 
152  /// Returns barycentric coordinates in the Simplex<M>.
153  const arma::vec::fixed<M+1> &local_bcoords_B() const;
154 
155  /**
156  * The dimension of the X-face the IP lies on within the A Simplex<N>. E.g. IP on and edge of tetrahedra (N=3)
157  * have dim_A = 1.
158  */
159  unsigned int dim_A() const; ///< Returns dimension of object A.
160  /**
161  * Same for the B Simplex<M>.
162  */
163  unsigned int dim_B() const; ///< Returns dimension of object B.
164  /**
165  * Index of the X-face of the simplex A.
166  */
167  unsigned int idx_A() const; ///< Returns the index of Simplex<N>.
168  /**
169  * Index of the X-face of the simplex B.
170  */
171  unsigned int idx_B() const; ///< Returns the index of Simplex<M>.
172 
173  /// Result: 0 - negative sign, 1 - positive sign, 2 - degenerate (zero for all sides), 3 - none
174  IntersectionResult result() const; ///< Returns the orientation.
175  //@}
176 
177  /// Computes real coordinates of IP, given the element @p ele in which IP lies.
178  arma::vec::fixed<3> coords(ElementAccessor<3> ele) const;
179 
180  /// Returns true, if @p other intersection point has the same topology.
181  bool topology_equal(const IntersectionPointAux<N,M> &other) const;
182 
183  /** @brief Comparison operator for sorting the IPs in convex hull tracing algorithm.
184  * Compares the points by x-coordinate (in case of a tie, compares by y-coordinate).
185  */
186  //bool operator<(const IntersectionPointAux<N,M> &ip) const;
187 
188  /// Friend output operator.
189  friend std::ostream& operator<< <>(std::ostream& os, const IntersectionPointAux<N,M>& IP);
190 };
191 
192 
193 /********************************************* IMPLEMENTATION ***********************************************/
194 
195 template<unsigned int N, unsigned int M>
196 void IntersectionPointAux<N,M>::set_coordinates(const arma::vec::fixed< N + 1 >& lcA, const arma::vec::fixed< M + 1 >& lcB)
197 { local_bcoords_A_ = lcA;
198  local_bcoords_B_ = lcB; }
199 
200 template<unsigned int N, unsigned int M>
201 void IntersectionPointAux<N,M>::set_topology(unsigned int idx_A,unsigned int dim_A, unsigned int idx_B, unsigned int dim_B)
202 { idx_A_ = idx_A;
203  idx_B_ = idx_B;
204  dim_A_ = dim_A;
205  dim_B_ = dim_B;
206 }
207 
208 template<unsigned int N, unsigned int M>
210 { result_ = res; }
211 
212 template<unsigned int N, unsigned int M>
214 { return dim_A_; }
215 
216 template<unsigned int N, unsigned int M>
218 { return dim_B_; }
219 
220 template<unsigned int N, unsigned int M>
221 const arma::vec::fixed< N + 1 >& IntersectionPointAux<N,M>::local_bcoords_A() const
222 { return local_bcoords_A_; }
223 
224 template<unsigned int N, unsigned int M>
225 const arma::vec::fixed< M + 1 >& IntersectionPointAux<N,M>::local_bcoords_B() const
226 { return local_bcoords_B_; }
227 
228 template<unsigned int N, unsigned int M>
229 void IntersectionPointAux<N,M>::set_topology_A(unsigned int idx_A, unsigned int dim_A)
230 { idx_A_ = idx_A;
231  dim_A_ = dim_A; }
232 
233 template<unsigned int N, unsigned int M>
234 void IntersectionPointAux<N,M>::set_topology_B(unsigned int idx_B, unsigned int dim_B)
235 { idx_B_ = idx_B;
236  dim_B_ = dim_B; }
237 
238 template<unsigned int N, unsigned int M>
240 { return idx_A_; }
241 
242 template<unsigned int N, unsigned int M>
244 { return idx_B_; }
245 
246 template<unsigned int N, unsigned int M>
248 { return result_; }
249 
250 #endif /* INTERSECTIONPOINT_H_ */
IntersectionPointAux::set_topology_B
void set_topology_B(unsigned int idx, unsigned int dim_B)
Sets the topology of object B in Simplex<M>.
Definition: intersection_point_aux.hh:234
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
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
geometry_epsilon
static const double geometry_epsilon
Definition: intersection_point_aux.hh:28
ElementAccessor
Definition: dh_cell_accessor.hh:32
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
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
operator<<
std::ostream & operator<<(std::ostream &os, const IntersectionPointAux< N, M > &IP)
Definition: intersection_point_aux.cc:144
IntersectionPointAux::~IntersectionPointAux
~IntersectionPointAux()
Definition: intersection_point_aux.hh:93
IntersectionPointAux::set_topology_A
void set_topology_A(unsigned int idx, unsigned int dim_A)
Sets the topology of object A in Simplex<N>.
Definition: intersection_point_aux.hh:229
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
IntersectionResult
IntersectionResult
Definition: intersection_point_aux.hh:38
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
IntersectionPointAux::clear
void clear()
Resets the object to default values.
Definition: intersection_point_aux.cc:18
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
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
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
IntersectionResult::positive
@ positive
IntersectionResult::negative
@ negative
IntersectionResult::degenerate
@ degenerate
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<
bool operator<(IntersectionResult a, IntersectionResult b)
Definition: intersection_point_aux.hh:45
IntersectionPointAux::dim_B
unsigned int dim_B() const
Returns dimension of object B.
Definition: intersection_point_aux.hh:217
IntersectionResult::none
@ none