7#include "dg/algorithm.h"
40 Psip( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip,
double psi0,
double alpha,
double sign = -1) :
41 m_ipoly( psi0, alpha, sign), m_psip(psip), m_pred(predicate)
45 double psip = m_psip(R,Z);
47 return m_ipoly( psip);
53 std::function<double(
double,
double)> m_psip;
54 std::function<bool(
double,
double)> m_pred;
58 PsipR( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip, std::function<
double(
double,
double)> psipR,
double psi0,
double alpha,
double sign = -1) :
59 m_poly( psi0, alpha, sign), m_psip(psip), m_psipR(psipR), m_pred(predicate)
63 double psip = m_psip(R,Z);
64 double psipR = m_psipR(R,Z);
66 return psipR*m_poly( psip);
72 std::function<double(
double,
double)> m_psip, m_psipR;
73 std::function<bool(
double,
double)> m_pred;
77 PsipZ( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip, std::function<
double(
double,
double)> psipZ,
double psi0,
double alpha,
double sign = -1) :
78 m_poly( psi0, alpha, sign), m_psip(psip), m_psipZ(psipZ), m_pred(predicate)
82 double psip = m_psip(R,Z);
83 double psipZ = m_psipZ(R,Z);
85 return psipZ*m_poly( psip);
91 std::function<double(
double,
double)> m_psip, m_psipZ;
92 std::function<bool(
double,
double)> m_pred;
97 PsipZZ( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip, std::function<
double(
double,
double)> psipZ, std::function<
double(
double,
double)> psipZZ,
double psi0,
double alpha,
double sign = -1) :
98 m_poly( psi0, alpha, sign), m_dpoly( psi0, alpha, sign), m_psip(psip), m_psipZ(psipZ), m_psipZZ(psipZZ), m_pred(predicate)
102 double psip = m_psip(R,Z);
103 double psipZ = m_psipZ(R,Z);
104 double psipZZ = m_psipZZ(R,Z);
106 return psipZZ*m_poly( psip) + psipZ*psipZ*m_dpoly(psip);
113 std::function<double(
double,
double)> m_psip, m_psipZ, m_psipZZ;
114 std::function<bool(
double,
double)> m_pred;
119 PsipRR( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip, std::function<
double(
double,
double)> psipR, std::function<
double(
double,
double)> psipRR,
double psi0,
double alpha,
double sign = -1) :
120 m_poly( psi0, alpha, sign), m_dpoly( psi0, alpha, sign), m_psip(psip), m_psipR(psipR), m_psipRR(psipRR), m_pred(predicate)
124 double psip = m_psip(R,Z);
125 double psipR = m_psipR(R,Z);
126 double psipRR = m_psipRR(R,Z);
128 return psipRR*m_poly( psip) + psipR*psipR*m_dpoly(psip);
135 std::function<double(
double,
double)> m_psip, m_psipR, m_psipRR;
136 std::function<bool(
double,
double)> m_pred;
140 PsipRZ( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip, std::function<
double(
double,
double)> psipR, std::function<
double(
double,
double)> psipZ, std::function<
double(
double,
double)> psipRZ,
double psi0,
double alpha,
double sign = -1) :
141 m_poly( psi0, alpha, sign), m_dpoly( psi0, alpha, sign), m_psip(psip), m_psipR(psipR), m_psipZ(psipZ), m_psipRZ(psipRZ), m_pred(predicate)
145 double psip = m_psip(R,Z);
146 double psipR = m_psipR(R,Z);
147 double psipZ = m_psipZ(R,Z);
148 double psipRZ = m_psipRZ(R,Z);
150 return psipRZ*m_poly( psip) + psipR*psipZ*m_dpoly(psip);
157 std::function<double(
double,
double)> m_psip, m_psipR, m_psipZ, m_psipRZ;
158 std::function<bool(
double,
double)> m_pred;
176 const std::function<
bool(
double,
double)> predicate,
178 double psi0,
double alpha,
double sign = -1)
181 mod::Psip(predicate,psip.
f(), psi0, alpha, sign),
193 DampingRegion( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip,
double psi0,
double alpha,
double sign = -1) :
194 m_poly( psi0, alpha, sign), m_psip(psip), m_pred(predicate)
196 double do_compute(
double R,
double Z)
const
199 return m_poly( m_psip(R,Z));
205 std::function<double(
double,
double)> m_psip;
206 std::function<bool(
double,
double)> m_pred;
208struct MagneticTransition :
public aCylindricalFunctor<MagneticTransition>
210 MagneticTransition( std::function<
bool(
double,
double)> predicate, std::function<
double(
double,
double)> psip,
double psi0,
double alpha,
double sign = -1) :
211 m_dpoly( psi0, alpha, sign), m_psip(psip), m_pred(predicate)
213 double do_compute(
double R,
double Z)
const
215 double psip = m_psip(R,Z);
217 return m_dpoly( psip);
223 std::function<double(
double,
double)> m_psip;
224 std::function<bool(
double,
double)> m_pred;
227inline constexpr bool nowhere(
double R,
double Z){
return false;}
228inline constexpr bool everywhere(
double R,
double Z){
return true;}
232 HeavisideZ(
double Z_X,
int side): m_ZX( Z_X), m_side(side) {}
233 bool operator()(
double R,
double Z)
const{
234 if( Z < m_ZX && m_side <= 0)
return true;
235 if( Z >= m_ZX && m_side > 0)
return true;
247 RightSideOf( std::array<double,2> p1, std::array<double,2> p2)
248 : RightSideOf( std::vector{p1,p2})
251 RightSideOf( std::array<double,2> p1, std::array<double,2> p2,
252 std::array<double,2> p3) : RightSideOf( std::vector{p1,p2,p3})
255 RightSideOf( std::vector<std::array<double,2>> ps): m_ps(ps)
257 if( ps.size() != 2 and ps.size() != 3)
258 throw Error( Message(_ping_) <<
"Give either 2 or 3 Points");
259 for(
unsigned u=0; u<ps.size(); u++)
260 for(
unsigned k=0; k<ps.size(); k++)
261 if( u!=k and ps[u][0] == ps[k][0] and ps[u][1] == ps[k][1])
262 throw Error( Message(_ping_) <<
"Points " <<k <<
" and "<<u<<
" must be different!");
264 bool operator() (
double R,
double Z)
const
268 std::array<double,2>
x = {R,Z};
269 std::vector<bool> right_of( m_ps.size()-1);
271 for(
unsigned u=0; u<m_ps.size()-1; u++)
273 right_of[u] = right_handed( m_ps[u], x, m_ps[u+1]);
275 if( m_ps.size() == 2)
278 if ( right_handed( m_ps[0], m_ps[2], m_ps[1]))
280 if( right_of[0] and right_of[1])
287 if( not right_of[0] and not right_of[1])
296 bool right_handed(
const std::array<double,2>& p0,
297 const std::array<double,2>& p1,
298 const std::array<double,2>& p2)
const
302 std::array<double,2> v1 = { p1[0]- p0[0], p1[1] - p0[1]};
303 std::array<double,2> v2 = { p2[0]- p0[0], p2[1] - p0[1]};
305 double v3z = v1[0]*v2[1] - v1[1]*v2[0];
309 std::vector<std::array<double,2>> m_ps;
317 Above( std::array<double,2> p0, std::array<double,2> p1,
bool above =
true)
318 : m_p0( p0), m_vec{ p1[0]-p0[0], p1[1]-p0[1]}, m_above(above){}
319 bool operator() (
double R,
double Z)
const
323 double res = m_vec[0]* R + m_vec[1]*Z;
324 return m_above == (res > 0);
327 std::array<double,2> m_p0, m_vec;
354 m_psip(mag.psip()), m_closed(closed)
356 double RO = mag.
R0(), ZO= 0.;
367 double psipO = mag.
psip()( RO, ZO);
368 m_psipO_pos = psipO > 0;
369 double RX1 = 0., ZX1 = 0., RX2 = 0., ZX2 = 0.;
378 m_above.push_back( mod::Above( {RX1, ZX1}, {RO, ZO}));
386 m_above.push_back( mod::Above( {RX2, ZX2}, {RO, ZO}));
400 for(
unsigned u=0; u<m_above.size(); u++)
401 if( not m_above[u](R,Z))
404 double psip = m_psip(R,Z);
405 if( m_psipO_pos == (psip > 0) )
412 std::vector<dg::geo::mod::Above> m_above;
440 return m_wall(R,Z) != 1 and not m_closed(R,Z);
459 std::function<
double(
double,
double)> fct1,
460 std::function<
double(
double,
double)> fct2) :
461 m_fct1(fct1), m_fct2(fct2), m_fct_mod( fct_mod)
465 return m_fct_mod( m_fct1(R,Z), m_fct2(R,Z));
468 std::function<double(
double,
double)> m_fct1, m_fct2, m_fct_mod;
478 SetUnion( std::function<
double(
double,
double)> fct1,
479 std::function<
double(
double,
double)> fct2) :
480 m_fct1(fct1), m_fct2(fct2)
484 double f1 = m_fct1(R,Z), f2 = m_fct2( R,Z);
485 return f1 + f2 - f1*f2;
488 std::function<double(
double,
double)> m_fct1, m_fct2;
499 std::function<
double(
double,
double)> fct2) :
500 m_fct1(fct1), m_fct2(fct2)
504 double f1 = m_fct1(R,Z), f2 = m_fct2( R,Z);
508 std::function<double(
double,
double)> m_fct1, m_fct2;
518 SetNot( std::function<
double(
double,
double)> fct) :
526 std::function<double(
double,
double)> m_fct;
description
How flux function looks like. Decider on whether and what flux aligned grid to construct.
Definition magnetic_field.h:50
@ none
no shaping: Purely toroidal magnetic field
@ doubleX
closed flux surfaces centered around an O-point located near (R_0, 0) and bordered by a separatrix wi...
@ centeredX
one X-point in the middle, no O-point, only open flux surfaces, X-grids cannot be constructed
@ standardX
closed flux surfaces centered around an O-point located near (R_0, 0) and bordered by a separatrix wi...
void findXpoint(const CylindricalFunctorsLvl2 &psi, double &RC, double &ZC)
This function finds X-points of psi.
Definition fluxfunctions.h:354
int findOpoint(const CylindricalFunctorsLvl2 &psi, double &RC, double &ZC)
This function finds O-points of psi.
Definition fluxfunctions.h:336
dg::geo::CylindricalFunctorsLvl2 createPsip(const std::function< bool(double, double)> predicate, const CylindricalFunctorsLvl2 &psip, double psi0, double alpha, double sign=-1)
Definition modified.h:175
This struct bundles a function and its first and second derivatives.
Definition fluxfunctions.h:223
const CylindricalFunctor & dfxy() const
Definition fluxfunctions.h:255
const CylindricalFunctor & dfy() const
Definition fluxfunctions.h:251
const CylindricalFunctor & dfx() const
Definition fluxfunctions.h:249
const CylindricalFunctor & dfxx() const
Definition fluxfunctions.h:253
const CylindricalFunctor & f() const
Definition fluxfunctions.h:247
const CylindricalFunctor & dfyy() const
Definition fluxfunctions.h:257
double a() const
The minor radius.
Definition magnetic_field.h:125
description getDescription() const
how the flux function looks
Definition magnetic_field.h:143
double elongation() const
Definition magnetic_field.h:131
double triangularity() const
Definition magnetic_field.h:137
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition magnetic_field.h:165
const CylindricalFunctorsLvl2 & get_psip() const
Definition magnetic_field.h:200
const MagneticFieldParameters & params() const
Access Meta-data of the field.
Definition magnetic_field.h:207
double R0() const
Definition magnetic_field.h:180
const CylindricalFunctor & psip() const
, where R, Z are cylindrical coordinates
Definition magnetic_field.h:182
Represent functions written in cylindrical coordinates that are independent of the angle phi serving ...
Definition fluxfunctions.h:66
Predicate identifying closed fieldline region.
Definition modified.h:347
bool operator()(double R, double Z) const
Return closed in closed fieldline region.
Definition modified.h:396
ClosedFieldlineRegion(const TokamakMagneticField &mag, bool closed=true)
Construct from magnetic field.
Definition modified.h:353
double do_compute(double R, double Z) const
Definition modified.h:43
Psip(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, double psi0, double alpha, double sign=-1)
Definition modified.h:40
PsipR(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, std::function< double(double, double)> psipR, double psi0, double alpha, double sign=-1)
Definition modified.h:58
double do_compute(double R, double Z) const
Definition modified.h:61
Definition modified.h:118
PsipRR(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, std::function< double(double, double)> psipR, std::function< double(double, double)> psipRR, double psi0, double alpha, double sign=-1)
Definition modified.h:119
double do_compute(double R, double Z) const
Definition modified.h:122
Definition modified.h:139
double do_compute(double R, double Z) const
Definition modified.h:143
PsipRZ(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, std::function< double(double, double)> psipR, std::function< double(double, double)> psipZ, std::function< double(double, double)> psipRZ, double psi0, double alpha, double sign=-1)
Definition modified.h:140
PsipZ(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, std::function< double(double, double)> psipZ, double psi0, double alpha, double sign=-1)
Definition modified.h:77
double do_compute(double R, double Z) const
Definition modified.h:80
double do_compute(double R, double Z) const
Definition modified.h:100
PsipZZ(std::function< bool(double, double)> predicate, std::function< double(double, double)> psip, std::function< double(double, double)> psipZ, std::function< double(double, double)> psipZZ, double psi0, double alpha, double sign=-1)
Definition modified.h:97
The default predicate for sheath integration.
Definition modified.h:425
SOLRegion(const TokamakMagneticField &mag, CylindricalFunctor wall)
Construct from magnetic field and wall functor.
Definition modified.h:431
bool operator()(double R, double Z)
Return true in SOL region.
Definition modified.h:438
Definition modified.h:457
SetCompose(std::function< double(double, double)> fct_mod, std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition modified.h:458
double do_compute(double R, double Z) const
Definition modified.h:463
Definition modified.h:497
SetIntersection(std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition modified.h:498
double do_compute(double R, double Z) const
Definition modified.h:502
Definition modified.h:517
double do_compute(double R, double Z) const
Definition modified.h:521
SetNot(std::function< double(double, double)> fct)
Definition modified.h:518
Definition modified.h:477
double do_compute(double R, double Z) const
Definition modified.h:482
SetUnion(std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition modified.h:478