Extension: Geometries
#include "dg/geometries/geometries.h"
modified.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <cmath>
5#include <vector>
6
7#include "dg/algorithm.h"
8
9#include "magnetic_field.h"
10
11
16namespace dg
17{
18namespace geo
19{
23namespace mod
24{
25//modify with a polynomial Heaviside function
28
38struct Psip: public aCylindricalFunctor<Psip>
39{
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)
42 { }
43 double do_compute(double R, double Z) const
44 {
45 double psip = m_psip(R,Z);
46 if( m_pred( R,Z))
47 return m_ipoly( psip);
48 else
49 return psip;
50 }
51 private:
53 std::function<double(double,double)> m_psip;
54 std::function<bool(double,double)> m_pred;
55};
56struct PsipR: public aCylindricalFunctor<PsipR>
57{
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)
60 { }
61 double do_compute(double R, double Z) const
62 {
63 double psip = m_psip(R,Z);
64 double psipR = m_psipR(R,Z);
65 if( m_pred( R,Z))
66 return psipR*m_poly( psip);
67 else
68 return psipR;
69 }
70 private:
72 std::function<double(double,double)> m_psip, m_psipR;
73 std::function<bool(double,double)> m_pred;
74};
75struct PsipZ: public aCylindricalFunctor<PsipZ>
76{
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)
79 { }
80 double do_compute(double R, double Z) const
81 {
82 double psip = m_psip(R,Z);
83 double psipZ = m_psipZ(R,Z);
84 if( m_pred( R,Z))
85 return psipZ*m_poly( psip);
86 else
87 return psipZ;
88 }
89 private:
91 std::function<double(double,double)> m_psip, m_psipZ;
92 std::function<bool(double,double)> m_pred;
93};
94
95struct PsipZZ: public aCylindricalFunctor<PsipZZ>
96{
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)
99 { }
100 double do_compute(double R, double Z) const
101 {
102 double psip = m_psip(R,Z);
103 double psipZ = m_psipZ(R,Z);
104 double psipZZ = m_psipZZ(R,Z);
105 if( m_pred( R,Z))
106 return psipZZ*m_poly( psip) + psipZ*psipZ*m_dpoly(psip);
107 else
108 return psipZZ;
109 }
110 private:
113 std::function<double(double,double)> m_psip, m_psipZ, m_psipZZ;
114 std::function<bool(double,double)> m_pred;
115};
116
117struct PsipRR: public aCylindricalFunctor<PsipRR>
118{
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)
121 { }
122 double do_compute(double R, double Z) const
123 {
124 double psip = m_psip(R,Z);
125 double psipR = m_psipR(R,Z);
126 double psipRR = m_psipRR(R,Z);
127 if( m_pred( R,Z))
128 return psipRR*m_poly( psip) + psipR*psipR*m_dpoly(psip);
129 else
130 return psipRR;
131 }
132 private:
135 std::function<double(double,double)> m_psip, m_psipR, m_psipRR;
136 std::function<bool(double,double)> m_pred;
137};
138struct PsipRZ: public aCylindricalFunctor<PsipRZ>
139{
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)
142 { }
143 double do_compute(double R, double Z) const
144 {
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);
149 if( m_pred( R,Z))
150 return psipRZ*m_poly( psip) + psipR*psipZ*m_dpoly(psip);
151 else
152 return psipRZ;
153 }
154 private:
157 std::function<double(double,double)> m_psip, m_psipR, m_psipZ, m_psipRZ;
158 std::function<bool(double,double)> m_pred;
159};
160
161
176 const std::function<bool(double,double)> predicate,
177 const CylindricalFunctorsLvl2& psip,
178 double psi0, double alpha, double sign = -1)
179{
181 mod::Psip(predicate,psip.f(), psi0, alpha, sign),
182 mod::PsipR(predicate,psip.f(), psip.dfx(), psi0, alpha, sign),
183 mod::PsipZ(predicate,psip.f(), psip.dfy(), psi0, alpha, sign),
184 mod::PsipRR(predicate,psip.f(), psip.dfx(), psip.dfxx(), psi0, alpha, sign),
185 mod::PsipRZ(predicate,psip.f(), psip.dfx(), psip.dfy(), psip.dfxy(), psi0, alpha, sign),
186 mod::PsipZZ(predicate,psip.f(), psip.dfy(), psip.dfyy(), psi0, alpha, sign));
187}
188
191struct DampingRegion : public aCylindricalFunctor<DampingRegion>
192{
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)
195 { }
196 double do_compute(double R, double Z) const
197 {
198 if( m_pred( R,Z))
199 return m_poly( m_psip(R,Z));
200 else
201 return 0;
202 }
203 private:
205 std::function<double(double,double)> m_psip;
206 std::function<bool(double,double)> m_pred;
207};
208struct MagneticTransition : public aCylindricalFunctor<MagneticTransition>
209{
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)
212 { }
213 double do_compute(double R, double Z) const
214 {
215 double psip = m_psip(R,Z);
216 if( m_pred( R,Z))
217 return m_dpoly( psip);
218 else
219 return 0;
220 }
221 private:
223 std::function<double(double,double)> m_psip;
224 std::function<bool(double,double)> m_pred;
225};
226//some possible predicates
227static bool nowhere( double R, double Z){return false;}
228static bool everywhere( double R, double Z){return !nowhere(R,Z);}
229struct HeavisideZ{
230 HeavisideZ( double Z_X, int side): m_ZX( Z_X), m_side(side) {}
231 bool operator()(double R, double Z){
232 if( Z < m_ZX && m_side <= 0) return true;
233 if( Z >= m_ZX && m_side > 0) return true;
234 return false;
235 }
236 private:
237 double m_ZX;
238 int m_side;
239};
241
244
250struct SetCompose : public aCylindricalFunctor<SetCompose>
251{
252 SetCompose( std::function<double(double,double)> fct_mod,
253 std::function<double(double,double)> fct1,
254 std::function<double(double,double)> fct2) :
255 m_fct1(fct1), m_fct2(fct2), m_fct_mod( fct_mod)
256 { }
257 double do_compute(double R, double Z) const
258 {
259 return m_fct_mod( m_fct1(R,Z), m_fct2(R,Z));
260 }
261 private:
262 std::function<double(double,double)> m_fct1, m_fct2, m_fct_mod;
263};
270struct SetUnion : public aCylindricalFunctor<SetUnion>
271{
272 SetUnion( std::function<double(double,double)> fct1,
273 std::function<double(double,double)> fct2) :
274 m_fct1(fct1), m_fct2(fct2)
275 { }
276 double do_compute(double R, double Z) const
277 {
278 double f1 = m_fct1(R,Z), f2 = m_fct2( R,Z);
279 return f1 + f2 - f1*f2;
280 }
281 private:
282 std::function<double(double,double)> m_fct1, m_fct2;
283};
290struct SetIntersection : public aCylindricalFunctor<SetIntersection>
291{
292 SetIntersection( std::function<double(double,double)> fct1,
293 std::function<double(double,double)> fct2) :
294 m_fct1(fct1), m_fct2(fct2)
295 { }
296 double do_compute(double R, double Z) const
297 {
298 double f1 = m_fct1(R,Z), f2 = m_fct2( R,Z);
299 return f1*f2;
300 }
301 private:
302 std::function<double(double,double)> m_fct1, m_fct2;
303};
310struct SetNot : public aCylindricalFunctor<SetNot>
311{
312 SetNot( std::function<double(double,double)> fct) :
313 m_fct(fct)
314 { }
315 double do_compute(double R, double Z) const
316 {
317 return 1-m_fct(R,Z);
318 }
319 private:
320 std::function<double(double,double)> m_fct;
321};
322
324
325} //namespace mod
326
327} //namespace geo
328} //namespace dg
static 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:219
const CylindricalFunctor & dfxy() const
Definition: fluxfunctions.h:251
const CylindricalFunctor & dfy() const
Definition: fluxfunctions.h:247
const CylindricalFunctor & dfx() const
Definition: fluxfunctions.h:245
const CylindricalFunctor & dfxx() const
Definition: fluxfunctions.h:249
const CylindricalFunctor & f() const
Definition: fluxfunctions.h:243
const CylindricalFunctor & dfyy() const
Definition: fluxfunctions.h:253
Represent functions written in cylindrical coordinates that are independent of the angle phi serving ...
Definition: fluxfunctions.h:66
Definition: modified.h:39
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
Definition: modified.h:57
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
Definition: modified.h:76
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
Definition: modified.h:96
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
Definition: modified.h:251
SetCompose(std::function< double(double, double)> fct_mod, std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition: modified.h:252
double do_compute(double R, double Z) const
Definition: modified.h:257
Definition: modified.h:291
SetIntersection(std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition: modified.h:292
double do_compute(double R, double Z) const
Definition: modified.h:296
Definition: modified.h:311
double do_compute(double R, double Z) const
Definition: modified.h:315
SetNot(std::function< double(double, double)> fct)
Definition: modified.h:312
Definition: modified.h:271
double do_compute(double R, double Z) const
Definition: modified.h:276
SetUnion(std::function< double(double, double)> fct1, std::function< double(double, double)> fct2)
Definition: modified.h:272