1#ifdef JSONCPP_VERSION_STRING
8#include <dg/file/json_utilities.h>
77 std::string e = gs.get(
"equilibrium",
"solovev" ).asString();
80 equi = str2equilibrium.at( e);
81 }
catch ( std::out_of_range& err)
83 std::string message =
"ERROR: Key \"" + e
84 +
"\" not valid in field:\n\t"
85 + gs.access_string() +
"\"equilibrium\" \n";
86 throw std::out_of_range(message);
96 double R0 = gs.get(
"R_0", 10.0).asDouble();
101 double I0 = gs.get(
"I_0", 20.0).asDouble();
102 double R0 = gs.get(
"R_0", 10.0).asDouble();
107 double I0 = gs.get(
"I_0", 20.0).asDouble();
108 double R0 = gs.get(
"R_0", 10.0).asDouble();
109 double a = gs.get(
"a", 1.0).asDouble();
110 double b = gs.get(
"b", 1.0).asDouble();
131void transform_psi( TokamakMagneticField mag,
double& psi0,
double& alpha0,
double& sign0)
133 double RO=mag.R0(), ZO=0.;
135 double psipO = mag.psip()( RO, ZO);
136 double wall_psi0p = (1.-psi0*psi0)*psipO;
137 double wall_alpha0p = -(2.*psi0+alpha0)*alpha0*psipO;
138 psi0 = wall_psi0p + sign0*wall_alpha0p/2.;
139 alpha0 = fabs( wall_alpha0p/2.);
140 sign0 = sign0*((psipO>0)-(psipO<0));
183 dg::file::WrappedJsonValue gs, dg::file::WrappedJsonValue jsmod,
190 std::string m = jsmod.get(
"type",
"heaviside" ).asString();
198 wall = mod::DampingRegion( mod::nowhere, mag.
psip(), 0, 1, -1);
199 transition = mod::MagneticTransition( mod::nowhere, mag.
psip(),
205 double psi0 = jsmod.get(
"boundary", 1.1 ).asDouble();
206 double alpha = jsmod.get(
"alpha", 0.2 ).asDouble();
210 detail::transform_psi( mag, psi0, alpha, sign);
212 sign = jsmod.get(
"sign", -1. ).asDouble();
215 wall = mod::DampingRegion( mod::everywhere, mag.
psip(), psi0, alpha, -sign);
216 transition = mod::MagneticTransition( mod::everywhere, mag.
psip(), psi0, alpha, sign);
221 double psi0 = jsmod[
"boundary"].get( 0, 1.1 ).asDouble();
222 double alpha0 = jsmod[
"alpha"].get(0, 0.2 ).asDouble();
223 double psi1 = jsmod[
"boundary"].get(1, 0.97 ).asDouble();
224 double alpha1 = jsmod[
"alpha"].get(1, 0.2 ).asDouble();
228 double sign0 = +1., sign1 = -1.;
229 detail::transform_psi( mag, psi0, alpha0, sign0);
230 detail::transform_psi( mag, psi1, alpha1, sign1);
237 mod::everywhere, mag.
get_psip(), psi0, alpha0, sign0);
239 mod::HeavisideZ( ZX, -1), mod0_psip, psi1, alpha1, sign1);
241 CylindricalFunctor transition0 = mod::MagneticTransition( mod::everywhere, mag.
psip(), psi0, alpha0, sign0);
242 CylindricalFunctor wall1 = mod::DampingRegion( mod::HeavisideZ(ZX, -1), mag.
psip(), psi1, alpha1, -sign1);
243 CylindricalFunctor transition1 = mod::MagneticTransition( mod::HeavisideZ(ZX, -1), mag.
psip(), psi1, alpha1, sign1);
250 double sign0 = +1., sign1 = -1.;
251 detail::transform_psi( mag, psi0, alpha0, sign0);
252 detail::transform_psi( mag, psi1, alpha1, sign1);
262 mod::everywhere, mag.
get_psip(), psi0, alpha0, sign0);
264 mod::HeavisideZ( ZX1, -1), mod0_psip, psi1, alpha1, sign1);
266 mod::HeavisideZ( ZX2, +1), mod1_psip, psi1, alpha1, sign1);
268 CylindricalFunctor wall1 = mod::DampingRegion( mod::HeavisideZ(ZX1, -1), mag.
psip(), psi1, alpha1, -sign1);
269 CylindricalFunctor wall2 = mod::DampingRegion( mod::HeavisideZ(ZX2, +1), mag.
psip(), psi1, alpha1, -sign1);
270 CylindricalFunctor transition0 = mod::MagneticTransition( mod::everywhere, mag.
psip(), psi0, alpha0, sign0);
271 CylindricalFunctor transition1 = mod::MagneticTransition( mod::HeavisideZ(ZX1, -1), mag.
psip(), psi1, alpha1, sign1);
272 CylindricalFunctor transition2 = mod::MagneticTransition( mod::HeavisideZ(ZX2, +1), mag.
psip(), psi1, alpha1, sign1);
279 double sign0 = jsmod[
"sign"].get( 0, -1. ).asDouble();
280 double sign1 = jsmod[
"sign"].get( 1, +1. ).asDouble();
283 mod::everywhere, mag.
get_psip(), psi0, alpha0, sign0);
285 mod::everywhere, mod0_psip, psi1, alpha1, sign1);
287 CylindricalFunctor transition0 = mod::MagneticTransition( mod::everywhere, mag.
psip(), psi0, alpha0, sign0);
289 CylindricalFunctor transition1 = mod::MagneticTransition( mod::everywhere, mag.
psip(), psi1, alpha1, sign1);
355 double R0 = sheath_walls.
x0(), R1 = sheath_walls.
x1();
356 double Z0 = sheath_walls.
y0(), Z1 = sheath_walls.
y1();
357 Grid1d gR1d ( R0, R1, 1, 100);
358 Grid1d gZ1d ( Z0, Z1, 1, 100);
359 std::array<bool,2> sheathR = {
false,
false}, sheathZ = {
false,
false};
360 for (
unsigned i=0; i<100; i++)
362 if( wall( R0+i*gR1d.
h(), Z0) == 0)
364 if( wall( R0+i*gR1d.
h(), Z1) == 0)
366 if( wall( R0, Z0 + i*gZ1d.
h()) == 0)
368 if( wall( R1, Z0 + i*gZ1d.
h()) == 0)
371 if(
false == sheathR[0]) Z0 = -1e10;
372 if(
false == sheathR[1]) Z1 = 1e10;
373 if(
false == sheathZ[0]) R0 = -1e10;
374 if(
false == sheathZ[1]) R1 = 1e10;
375 sheath_walls =
dg::Grid2d( R0, R1, Z0, Z1, 1,1,1);
376 double boundary = jsmod.get(
"boundary", 0.0625 ).asDouble();
377 double alpha = jsmod.get(
"alpha", 0.015625 ).asDouble();
379 mag), sheath_walls, (-boundary-1e-3)*2.0*
M_PI,
382 mag), sheath_walls, (+boundary+1e-3)*2.0*
M_PI,
static dg::geo::TokamakMagneticField createCircularField(double R0, double I0, double a=1, double b=1)
Definition: toroidal.h:136
auto compose(UnaryOp f, Functor g)
static TokamakMagneticField createMagneticField(dg::file::WrappedJsonValue gs)
Create a Magnetic field based on the given parameters.
Definition: make_field.h:75
dg::RealGrid2d< double > Grid2d
static dg::geo::TokamakMagneticField createGuenterField(double R_0, double I_0)
Create a Guenter Magnetic field.
Definition: guenter.h:158
modifier
How flux-function is modified.
Definition: magnetic_field.h:36
equilibrium
How flux-function is computed. Decides how to construct magnetic field.
Definition: magnetic_field.h:26
description
How flux function looks like. Decider on whether and what flux aligned grid to construct.
Definition: magnetic_field.h:48
CylindricalVectorLvl1 createBHat(const TokamakMagneticField &mag)
Contravariant components of the magnetic unit vector field and its Divergence and derivative in cylin...
Definition: magnetic_field.h:931
@ sol_pfr
Psip is dampened in the SOL and PFR regions but not in the closed field line region.
@ heaviside
Psip is dampened to a constant outside a critical value.
@ solovev
dg::geo::solovev::Psip
@ taylor
dg::geo::taylor::Psip
@ polynomial
dg::geo::polynomial::Psip
@ guenter
dg::geo::guenter::Psip
@ toroidal
dg::geo::createToroidalField
@ circular
dg::geo::circular::Psip
@ standardO
closed flux surfaces centered around an O-point located near (R_0, 0); flux-aligned grids can be cons...
@ doubleX
closed flux surfaces centered around an O-point located near (R_0, 0) and bordered by a separatrix wi...
@ standardX
closed flux surfaces centered around an O-point located near (R_0, 0) and bordered by a separatrix wi...
static void findXpoint(const CylindricalFunctorsLvl2 &psi, double &RC, double &ZC)
This function finds X-points of psi.
Definition: fluxfunctions.h:350
static int findOpoint(const CylindricalFunctorsLvl2 &psi, double &RC, double &ZC)
This function finds O-points of psi.
Definition: fluxfunctions.h:332
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
static dg::geo::TokamakMagneticField createPolynomialField(dg::geo::polynomial::Parameters gp)
Create a Polynomial Magnetic field.
Definition: polynomial.h:167
static dg::geo::CylindricalFunctorsLvl1 createIpol(const Parameters &gp, const CylindricalFunctorsLvl1 &psip)
Definition: solovev.h:354
static dg::geo::TokamakMagneticField createSolovevField(dg::geo::solovev::Parameters gp)
Create a Solovev Magnetic field.
Definition: solovev.h:375
static dg::geo::TokamakMagneticField createTaylorField(dg::geo::solovev::Parameters gp)
Create a Taylor Magnetic field.
Definition: taylor.h:314
static dg::geo::TokamakMagneticField createToroidalField(double R0)
Create a Toroidal Magnetic field.
Definition: toroidal.h:118
static TokamakMagneticField createModifiedField(dg::file::WrappedJsonValue gs, dg::file::WrappedJsonValue jsmod, CylindricalFunctor &wall, CylindricalFunctor &transition)
Modify Magnetic Field and create wall above or below certain Psi values according to given parameters...
Definition: make_field.h:182
static void createSheathRegion(dg::file::WrappedJsonValue jsmod, TokamakMagneticField mag, CylindricalFunctor wall, dg::Grid2d &sheath_walls, CylindricalFunctor &sheath)
Create the sheath region where fieldlines intersect the boundary.
Definition: make_field.h:350
static CylindricalFunctor createWallRegion(dg::file::WrappedJsonValue gs, dg::file::WrappedJsonValue jsmod)
A convenience function call for dg::geo::createModifiedField that ignores the transition parameter an...
Definition: make_field.h:314
This struct bundles a function and its first and second derivatives.
Definition: fluxfunctions.h:219
Meta-data about the magnetic field in particular the flux function.
Definition: magnetic_field.h:91
double a() const
The minor radius.
Definition: magnetic_field.h:122
description getDescription() const
how the flux function looks
Definition: magnetic_field.h:140
double elongation() const
Definition: magnetic_field.h:128
double triangularity() const
Definition: magnetic_field.h:134
equilibrium getEquilibrium() const
the way the flux function is computed
Definition: magnetic_field.h:136
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition: magnetic_field.h:162
const CylindricalFunctorsLvl2 & get_psip() const
Definition: magnetic_field.h:197
const CylindricalFunctorsLvl1 & get_ipol() const
Definition: magnetic_field.h:198
const MagneticFieldParameters & params() const
Access Meta-data of the field.
Definition: magnetic_field.h:204
double R0() const
Definition: magnetic_field.h:177
const CylindricalFunctor & psip() const
, where R, Z are cylindrical coordinates
Definition: magnetic_field.h:179
Distance to wall along fieldline in phi or s coordinate
Definition: fieldaligned.h:221
Definition: modified.h:291
Definition: modified.h:311
Definition: modified.h:271
Constructs and display geometric parameters for the polynomial fields.
Definition: polynomial_parameters.h:46
Constructs and display geometric parameters for the solovev and taylor fields.
Definition: solovev_parameters.h:46
double R_0
major tokamak radius
Definition: solovev_parameters.h:48