Hex  2.2
Hydrogen-electron collision solver
bspline.h
Go to the documentation of this file.
1 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2 // //
3 // / / / / __ \ \ / / //
4 // / /__ / / / _ \ \ \/ / //
5 // / ___ / | |/_/ / /\ \ //
6 // / / / / \_\ / / \ \ //
7 // //
8 // //
9 // Copyright (c) 2016, Jakub Benda, Charles University in Prague //
10 // //
11 // MIT License: //
12 // //
13 // Permission is hereby granted, free of charge, to any person obtaining a //
14 // copy of this software and associated documentation files (the "Software"), //
15 // to deal in the Software without restriction, including without limitation //
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, //
17 // and/or sell copies of the Software, and to permit persons to whom the //
18 // Software is furnished to do so, subject to the following conditions: //
19 // //
20 // The above copyright notice and this permission notice shall be included //
21 // in all copies or substantial portions of the Software. //
22 // //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, //
27 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF //
28 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
29 // //
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 #ifndef HEX_ECS_BSPLINE
33 #define HEX_ECS_BSPLINE
34 
35 // --------------------------------------------------------------------------------- //
36 
37 #include "hex-arrays.h"
38 #include "hex-misc.h"
39 
40 // --------------------------------------------------------------------------------- //
41 
57 class Bspline
58 {
59  public:
60 
71  Bspline
72  (
73  int order,
74  Real th,
75  rArrayView cknots1,
76  rArrayView rknots,
77  rArrayView cknots2
78  );
79 
100  Complex bspline (int i, int iknot, int k, Complex r) const;
101 
114  Complex dspline (int i, int iknot, int k, Complex r) const;
115 
129  void B (int i, int iknot, int n, const Complex* x, Complex* y) const;
130 
138  void dB (int i, int iknot, int n, const Complex* x, Complex* y) const;
139 
145  Complex rotate (Real r) const
146  {
147  // leading complex part
148  if (r < R1_)
149  return R1_ + (r - R1_) * rotation_;
150 
151  // trailing complex part
152  if (r > R2_)
153  return R2_ + (r - R2_) * rotation_;
154 
155  // real part
156  return r;
157  };
158 
164  Real unrotate (Complex z) const
165  {
166  // leading complex part
167  if (z.imag() < 0)
168  return R1_ + (z.real() - R1_) / rotation_.real();
169 
170  // trailing complex part
171  if (z.imag() > 0)
172  return R2_ + (z.real() - R2_) / rotation_.real();
173 
174  // real part
175  return z.real();
176  };
177 
186  Complex clamp (Complex z, Real a, Real b) const;
187 
197  cArray zip (const cArrayView coeff, const rArrayView grid) const;
198 
210  cArray zip (const cArrayView coeff, const rArrayView xgrid, const rArrayView ygrid) const;
211 
220  static cArray zip
221  (
222  Bspline const & bx,
223  Bspline const & by,
224  const cArrayView coeff,
225  const rArrayView xgrid,
226  const rArrayView ygrid,
227  Complex (Bspline::* evalXBSpline) (int,int,int,Complex) const = &Bspline::bspline,
228  Complex (Bspline::* evalYBSpline) (int,int,int,Complex) const = &Bspline::bspline
229  );
230 
237  int knot (Complex x) const;
238 
249  Complex eval (const cArrayView coeff, Real x) const;
250 
261  Complex eval (const cArrayView coeff, Real x, Real y) const;
262 
263  // getters
264 
266  cArrayView t () const { return t_; }
267 
269  Complex const & t (int i) const { return t_[i]; }
270 
272  int Nspline () const { return Nspline_; }
273 
275  int Nknot () const { return Nknot_; }
276 
278  int Nreknot () const { return Nreknot_; }
279 
281  int order () const { return order_; }
282 
288  int iR1 () const { return cknots1_.empty() ? 0 : cknots1_.size() - 1; }
289 
296  int iR2 () const { return cknots2_.empty() ? t_.size() - 1 : t_.size() - cknots2_.size(); }
297 
299  Real R1 () const { return R1_; }
300 
302  Real R2 () const { return R2_; }
303 
305  Real Rmin () const { return Rmin_; }
306 
308  Real Rmax () const { return Rmax_; };
309 
311  Real ECStheta () const { return theta_; }
312 
314  rArray const & rknots () const { return rknots_; }
315 
317  rArray const & cknots1 () const { return cknots1_; }
318  rArray const & cknots2 () const { return cknots2_; }
319 
326  std::size_t hash () const;
327 
328  private:
329 
331  rArray rknots_;
332 
334  rArray cknots1_, cknots2_;
335 
337  cArray t_;
338 
340  Real theta_;
341 
343  Complex rotation_;
344 
346  Real R1_;
347 
349  Real R2_;
350 
352  Real Rmin_;
353 
355  Real Rmax_;
356 
358  int Nknot_;
359 
361  int Nreknot_;
362 
364  int Nspline_;
365 
367  int Nintval_;
368 
370  int order_;
371 
373  mutable rArrays work_;
374 
376  static const std::size_t work_size_;
377 };
378 
379 // --------------------------------------------------------------------------------- //
380 
381 #endif // HEX_ECS_BSPLINE
Real R1() const
Beginning of the real grid.
Definition: bspline.h:299
rArray const & cknots1() const
complex knots
Definition: bspline.h:317
Real ECStheta() const
ECS rotation angle.
Definition: bspline.h:311
std::size_t hash() const
Return (almost) unique identification for this B-spline object.
Definition: bspline.cpp:503
Complex clamp(Complex z, Real a, Real b) const
Restrict value into a given range.
Definition: bspline.cpp:522
Real unrotate(Complex z) const
Apply the inverse ECS transformation.
Definition: bspline.h:164
int Nknot() const
Number of knots.
Definition: bspline.h:275
int order() const
B-spline order.
Definition: bspline.h:281
Real R2() const
End of the real grid.
Definition: bspline.h:302
Complex eval(const cArrayView coeff, Real x) const
Evaluate 1D B-spline expansion.
Definition: bspline.cpp:457
B-spline environment.
Definition: bspline.h:57
int knot(Complex x) const
Get knot index for coordinate.
Definition: bspline.cpp:431
cArray zip(const cArrayView coeff, const rArrayView grid) const
Zip 1D expansion.
Definition: bspline.cpp:169
void B(int i, int iknot, int n, const Complex *x, Complex *y) const
B-spline.
Definition: bspline.cpp:115
Real Rmax() const
End of the grid (unrotated).
Definition: bspline.h:308
Bspline(int order, Real th, rArrayView cknots1, rArrayView rknots, rArrayView cknots2)
Constructor.
Definition: bspline.cpp:372
Complex dspline(int i, int iknot, int k, Complex r) const
Evaluate derivative of a B-spline.
Definition: bspline.cpp:96
int Nreknot() const
Number of real knots.
Definition: bspline.h:278
int Nspline() const
Number of B-splines.
Definition: bspline.h:272
Complex bspline(int i, int iknot, int k, Complex r) const
Evaluate B-spline.
Definition: bspline.cpp:62
rArray const & rknots() const
real knots
Definition: bspline.h:314
rArray const & cknots2() const
Definition: bspline.h:318
cArrayView t() const
B-spline knot sequence.
Definition: bspline.h:266
Complex rotate(Real r) const
Apply the ECS transformation.
Definition: bspline.h:145
int iR2() const
Index of knot between real grid and trailing complex grid.
Definition: bspline.h:296
int iR1() const
Index of knot between leading complex grid and real grid.
Definition: bspline.h:288
Complex const & t(int i) const
B-spline knot sequence.
Definition: bspline.h:269
Real Rmin() const
Beginning of the grid (unrotated).
Definition: bspline.h:305
void dB(int i, int iknot, int n, const Complex *x, Complex *y) const
Derivative of a B-spline.
Definition: bspline.cpp:157