Extension: Geometries
#include "dg/geometries/geometries.h"
ds_generator.h
Go to the documentation of this file.
1#pragma once
2
3#include "dg/functors.h"
4#include "magnetic_field.h"
5
10namespace dg {
11namespace geo{
14namespace detail{
15struct DSMetricCylindrical
16{
17 DSMetricCylindrical( const dg::geo::TokamakMagneticField& mag):
18 m_bR(mag),
19 m_bZ(mag),
20 m_bP(mag),
21 m_bRR(mag),
22 m_bZR(mag),
23 m_bPR(mag),
24 m_bRZ(mag),
25 m_bZZ(mag),
26 m_bPZ(mag)
27 {}
28 void operator()( double t, const std::array<double,6>& y,
29 std::array<double,6>& yp) const {
30 double R = y[0], Z = y[1];
31 double vx = m_bR(R,Z);
32 double vy = m_bZ(R,Z);
33 double vz = m_bP(R,Z);
34 double vxx = m_bRR(R,Z);
35 double vyx = m_bZR(R,Z);
36 double vzx = m_bPR(R,Z);
37 double vxy = m_bRZ(R,Z);
38 double vyy = m_bZZ(R,Z);
39 double vzy = m_bPZ(R,Z);
40 yp[0] = vx/vz;
41 yp[1] = vy/vz;
42 double vxzx = (vxx/vz - vx*vzx/vz/vz);
43 double vyzx = (vyx/vz - vy*vzx/vz/vz);
44 double vxzy = (vxy/vz - vx*vzy/vz/vz);
45 double vyzy = (vyy/vz - vy*vzy/vz/vz);
46 yp[2] = - vxzx*y[2] - vyzx*y[3];
47 yp[3] = - vxzy*y[2] - vyzy*y[3];
48 yp[4] = - vxzx*y[4] - vyzx*y[5];
49 yp[5] = - vxzy*y[4] - vyzy*y[5];
50 }
51 private:
52 BHatR m_bR;
53 BHatZ m_bZ;
54 BHatP m_bP;
55 BHatRR m_bRR;
56 BHatZR m_bZR;
57 BHatPR m_bPR;
58 BHatRZ m_bRZ;
59 BHatZZ m_bZZ;
60 BHatPZ m_bPZ;
61};
62template<class real_type>
63inline real_type ds_metric_norm( const std::array<real_type,6>& x0){
64 return sqrt( x0[0]*x0[0] +x0[1]*x0[1] );
65}
66}//namespace detail
68
79{
90 DSPGenerator( const dg::geo::TokamakMagneticField& mag, double R0, double R1, double Z0, double Z1, double deltaPhi):
91 m_R0(R0), m_R1(R1), m_Z0(Z0), m_Z1(Z1), m_deltaPhi(deltaPhi), m_dsmetric( mag)
92 {
93
94 }
95
96 virtual DSPGenerator* clone() const override final{return new DSPGenerator(*this);}
97
98 private:
99 virtual double do_width() const override final{return m_R1-m_R0;}
100 virtual double do_height() const override final{return m_Z1-m_Z0;}
101 virtual void do_generate(
102 const thrust::host_vector<double>& zeta1d,
103 const thrust::host_vector<double>& eta1d,
104 thrust::host_vector<double>& x,
105 thrust::host_vector<double>& y,
106 thrust::host_vector<double>& zetaX,
107 thrust::host_vector<double>& zetaY,
108 thrust::host_vector<double>& etaX,
109 thrust::host_vector<double>& etaY) const override final
110 {
111 unsigned Nx = zeta1d.size(), Ny = eta1d.size();
112 unsigned size = Nx*Ny;
113 for( unsigned k=0; k<Ny; k++)
114 for( unsigned i=0; i<Nx; i++)
115 {
116 x[k*Nx+i] = m_R0 + zeta1d[i];
117 y[k*Nx+i] = m_Z0 + eta1d[k];
118 }
119
120 for( unsigned i=0; i<size; i++)
121 {
122 std::array<double,6> coords{x[i],y[i],1, 0,0,1}, coordsP;
123 double phi1 = m_deltaPhi;
124 //x,y,s
125 using Vec = std::array<double,6>;
126 dg::Adaptive<dg::ERKStep<Vec>> adapt( "Dormand-Prince-7-4-5", coords);
127 dg::AdaptiveTimeloop<Vec> loop( adapt, m_dsmetric, dg::pid_control,
128 detail::ds_metric_norm, 1e-8, 1e-10, 2);
129 loop.set_dt( m_deltaPhi/2.);
130 loop.integrate( 0, coords, phi1, coordsP);
131
132 x[i] = coordsP[0];
133 y[i] = coordsP[1];
134 zetaX[i] = coordsP[2];
135 zetaY[i] = coordsP[3];
136 etaX[i] = coordsP[4];
137 etaY[i] = coordsP[5];
138 }
139 }
140 double m_R0, m_R1, m_Z0, m_Z1, m_deltaPhi;
141 dg::geo::detail::DSMetricCylindrical m_dsmetric;
142};
143}//namespace geo
144}//namespace dg
static auto pid_control
A transformed field grid generator.
Definition: ds_generator.h:79
virtual DSPGenerator * clone() const override final
Abstract clone method that returns a copy on the heap.
Definition: ds_generator.h:96
DSPGenerator(const dg::geo::TokamakMagneticField &mag, double R0, double R1, double Z0, double Z1, double deltaPhi)
Only magnetic fields are admissable vector fields.
Definition: ds_generator.h:90
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition: magnetic_field.h:162
The abstract generator base class.
Definition: generator.h:20