Stellarator-Tools
grid_quantity.hpp
Go to the documentation of this file.
1 //******************************************************************************
4 //******************************************************************************
5 
6 #ifndef grid_quantity_hpp
7 #define grid_quantity_hpp
8 
9 #include <vector>
10 #include <cmath>
11 #include <cstddef>
12 
13 #include "parity.hpp"
14 
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 public:
21  const std::vector<double> buffer;
23  const double ds;
24 
25 //------------------------------------------------------------------------------
29 //------------------------------------------------------------------------------
30  radial_quantity(const std::vector<double> &buffer);
31 
32 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38  virtual double get(const double s) const=0;
39 };
40 
41 class half_grid;
42 
43 //------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------
49 class full_grid : public radial_quantity {
50 public:
51 //------------------------------------------------------------------------------
55 //------------------------------------------------------------------------------
56  full_grid(const std::vector<double> &buffer);
57 
58 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64  double get(const double s) const final;
65 
66 //------------------------------------------------------------------------------
70 //------------------------------------------------------------------------------
71  half_grid get_prime() const;
72 };
73 
74 //------------------------------------------------------------------------------
79 //------------------------------------------------------------------------------
80 class half_grid : public radial_quantity {
81 public:
82 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87  half_grid(const std::vector<double> &buffer);
88 
89 //------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------
95  double get(const double s) const final;
96 
97 //------------------------------------------------------------------------------
102 //------------------------------------------------------------------------------
103  full_grid get_prime(const double m) const;
104 };
105 
106 //------------------------------------------------------------------------------
111 //------------------------------------------------------------------------------
112 template <class GRID_CLASS> class vmec_grid {
113 public:
115  const GRID_CLASS grid;
116 
117 //------------------------------------------------------------------------------
121 //------------------------------------------------------------------------------
122  vmec_grid(const std::vector<double> &buffer) : grid(buffer) {}
123 
124 //------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------
129  vmec_grid(const GRID_CLASS &grid) : grid(grid.buffer) {}
130 
131 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
137  double get(const double s) const {
138  return grid.get(s);
139  }
140 };
141 
142 //------------------------------------------------------------------------------
147 //------------------------------------------------------------------------------
148 template <class GRID_CLASS> class siesta_grid {
149 public:
151  const GRID_CLASS grid;
152 
153 //------------------------------------------------------------------------------
157 //------------------------------------------------------------------------------
158  siesta_grid(const std::vector<double> &buffer) : grid(buffer) {}
159 
160 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165  siesta_grid(const GRID_CLASS &grid) : grid(grid.buffer) {}
166 
167 //------------------------------------------------------------------------------
174 //------------------------------------------------------------------------------
175  double get(const double s) const {
176  return grid.get(sqrt(s));
177  }
178 };
179 
180 //------------------------------------------------------------------------------
182 //------------------------------------------------------------------------------
183 template<class GRID_CLASS> using vmec_quantity = std::vector<vmec_grid<GRID_CLASS> >;
184 
185 //------------------------------------------------------------------------------
187 //------------------------------------------------------------------------------
188 template <class GRID_CLASS, class PARITY> class vmec_fourier {
189 public:
191  const std::vector<double> m;
193  const std::vector<double> n;
197  const PARITY func;
198 
199 //------------------------------------------------------------------------------
203 //------------------------------------------------------------------------------
205  const std::vector<double> &m,
206  const std::vector<double> &n) :
207  quantity(buffer), m(m), n(n) {}
208 
209 //------------------------------------------------------------------------------
218 //------------------------------------------------------------------------------
219  double get(const double s,
220  const double u,
221  const double v) const {
222  double temp = 0.0;
223 
224  for (size_t i = 0, e = m.size(); i < e; i++) {
225  temp += quantity[i].get(s)*func.f(m[i]*u - n[i]*v);
226  }
227 
228  return temp;
229  }
230 
231 //------------------------------------------------------------------------------
240 //------------------------------------------------------------------------------
241  double get_du(const double s,
242  const double u,
243  const double v) const {
244  double temp = 0.0;
245 
246  for (size_t i = 0, e = m.size(); i < e; i++) {
247  temp += m[i]*quantity[i].get(s)*func.df(m[i]*u - n[i]*v);
248  }
249 
250  return temp;
251  }
252 
253 //------------------------------------------------------------------------------
262 //------------------------------------------------------------------------------
263  double get_dv(const double s,
264  const double u,
265  const double v) const {
266  double temp = 0.0;
267 
268  for (size_t i = 0, e = m.size(); i < e; i++) {
269  temp -= n[i]*quantity[i].get(s)*func.df(m[i]*u - n[i]*v);
270  }
271 
272  return temp;
273  }
274 };
275 
276 //------------------------------------------------------------------------------
278 //------------------------------------------------------------------------------
279 template<class GRID_CLASS> using siesta_quantity_1d = std::vector<siesta_grid<GRID_CLASS> >;
280 //------------------------------------------------------------------------------
282 //------------------------------------------------------------------------------
283 template<class GRID_CLASS> using siesta_quantity = std::vector<siesta_quantity_1d<GRID_CLASS> >;
284 
285 //------------------------------------------------------------------------------
287 //------------------------------------------------------------------------------
288 template <class GRID_CLASS, class PARITY> class siesta_fourier {
289 public:
291  const size_t mpol;
293  const size_t ntor;
295  const std::vector<int> tor_modes;
297  const size_t nfp;
301  const PARITY func;
302 
303 //------------------------------------------------------------------------------
311 //------------------------------------------------------------------------------
313  const size_t mpol,
314  const size_t ntor,
315  const std::vector<int> &tor_modes,
316  const size_t nfp) :
317  quantity(buffer), mpol(mpol), ntor(ntor), tor_modes(tor_modes), nfp(nfp) {}
318 
319 //------------------------------------------------------------------------------
328 //------------------------------------------------------------------------------
329  double get(const double s,
330  const double u,
331  const double v) const {
332  double temp = 0.0;
333 
334  for (size_t m = 0, em = mpol; m <= em; m++) {
335  for (long n = -ntor, en = ntor; n <= en; n++) {
336  const size_t ni = n + ntor;
337  temp += quantity[m][ni].get(s)*func.f(m*u + tor_modes[ni]*(nfp*v));
338  }
339  }
340 
341  return temp;
342  }
343 
344 //------------------------------------------------------------------------------
353 //------------------------------------------------------------------------------
354  double get_du(const double s,
355  const double u,
356  const double v) const {
357  double temp = 0.0;
358 
359  for (size_t m = 0, em = mpol; m <= em; m++) {
360  for (long n = -ntor, en = ntor; n <= en; n++) {
361  const size_t ni = n + ntor;
362  temp += m*quantity[m][ni].get(s)*func.df(m*u + tor_modes[ni]*(nfp*v));
363  }
364  }
365 
366  return temp;
367  }
368 
369 //------------------------------------------------------------------------------
378 //------------------------------------------------------------------------------
379  double get_dv(const double s,
380  const double u,
381  const double v) const {
382  double temp = 0.0;
383 
384  for (size_t m = 0, em = mpol; m <= em; m++) {
385  for (long n = -ntor, en = ntor; n <= en; n++) {
386  const size_t ni = n + ntor;
387  temp += tor_modes[ni]*(nfp*quantity[m][ni].get(s))*func.df(m*u + tor_modes[ni]*(nfp*v));
388  }
389  }
390 
391  return temp;
392  }
393 };
394 
395 #endif
A full grid quantity.
Definition: grid_quantity.hpp:49
half_grid get_prime() const
Get a radial derivative at a s position.
Definition: grid_quantity.cpp:59
full_grid(const std::vector< double > &buffer)
Construct a full grid quantity.
Definition: grid_quantity.cpp:27
double get(const double s) const final
Get a value at a radial s position.
Definition: grid_quantity.cpp:36
A half grid quantity.
Definition: grid_quantity.hpp:80
full_grid get_prime(const double m) const
Get a radial derivative at a s position.
Definition: grid_quantity.cpp:111
double get(const double s) const final
Get a value at a radial s position.
Definition: grid_quantity.cpp:86
half_grid(const std::vector< double > &buffer)
Construct a half grid quantity.
Definition: grid_quantity.cpp:77
A radial quantity.
Definition: grid_quantity.hpp:18
const double ds
Grid spacing in s.
Definition: grid_quantity.hpp:23
radial_quantity(const std::vector< double > &buffer)
Construct a radial quantity.
Definition: grid_quantity.cpp:16
virtual double get(const double s) const =0
vitual interface to get a value at a radial s position.
const std::vector< double > buffer
Buffer containing radial quantity.
Definition: grid_quantity.hpp:21
A cosine parity vmec quantity.
Definition: grid_quantity.hpp:288
const size_t nfp
Number of field periods.
Definition: grid_quantity.hpp:297
const size_t mpol
M modes.
Definition: grid_quantity.hpp:291
siesta_fourier(const siesta_quantity< GRID_CLASS > &buffer, const size_t mpol, const size_t ntor, const std::vector< int > &tor_modes, const size_t nfp)
Siesta radial quantity.
Definition: grid_quantity.hpp:312
double get(const double s, const double u, const double v) const
Get a value at a radial s position.
Definition: grid_quantity.hpp:329
double get_du(const double s, const double u, const double v) const
Get a poloidal derivative at a radial s position.
Definition: grid_quantity.hpp:354
const size_t ntor
N modes.
Definition: grid_quantity.hpp:293
const PARITY func
Parity function.
Definition: grid_quantity.hpp:301
double get_dv(const double s, const double u, const double v) const
Get a toroidal derivative at a radial s position.
Definition: grid_quantity.hpp:379
const siesta_quantity< GRID_CLASS > quantity
Mode amplitudes.
Definition: grid_quantity.hpp:299
const std::vector< int > tor_modes
Toroidal modes.
Definition: grid_quantity.hpp:295
A radial siesta quantity.
Definition: grid_quantity.hpp:148
const GRID_CLASS grid
Radial grid buffer.
Definition: grid_quantity.hpp:151
siesta_grid(const std::vector< double > &buffer)
Siesta radial quantity.
Definition: grid_quantity.hpp:158
double get(const double s) const
Get a value at a radial s position.
Definition: grid_quantity.hpp:175
siesta_grid(const GRID_CLASS &grid)
Siesta radial quantity.
Definition: grid_quantity.hpp:165
A cosine parity vmec quantity.
Definition: grid_quantity.hpp:188
const PARITY func
Parity function.
Definition: grid_quantity.hpp:197
const std::vector< double > m
M modes.
Definition: grid_quantity.hpp:191
const vmec_quantity< GRID_CLASS > quantity
Mode amplitudes.
Definition: grid_quantity.hpp:195
double get_du(const double s, const double u, const double v) const
Get a poloidal derivative at a radial s position.
Definition: grid_quantity.hpp:241
double get(const double s, const double u, const double v) const
Get a value at a radial s position.
Definition: grid_quantity.hpp:219
vmec_fourier(const vmec_quantity< GRID_CLASS > &buffer, const std::vector< double > &m, const std::vector< double > &n)
Siesta radial quantity.
Definition: grid_quantity.hpp:204
const std::vector< double > n
N modes.
Definition: grid_quantity.hpp:193
double get_dv(const double s, const double u, const double v) const
Get a toroidal derivative at a radial s position.
Definition: grid_quantity.hpp:263
A radial vmec quantity.
Definition: grid_quantity.hpp:112
const GRID_CLASS grid
Radial grid buffer.
Definition: grid_quantity.hpp:115
vmec_grid(const GRID_CLASS &grid)
Vmec radial quantity.
Definition: grid_quantity.hpp:129
double get(const double s) const
Get a value at a radial s position.
Definition: grid_quantity.hpp:137
vmec_grid(const std::vector< double > &buffer)
Vmec radial quantity.
Definition: grid_quantity.hpp:122
std::vector< vmec_grid< GRID_CLASS > > vmec_quantity
Type for vmec fourier quantities.
Definition: grid_quantity.hpp:183
std::vector< siesta_grid< GRID_CLASS > > siesta_quantity_1d
Type for siesta fourier quantities for a single dimension.
Definition: grid_quantity.hpp:279
std::vector< siesta_quantity_1d< GRID_CLASS > > siesta_quantity
Type for siesta fourier quantities.
Definition: grid_quantity.hpp:283
Contains classes to control sine and cosine parity of fourier quantites.