Extension: Geometries
#include "dg/geometries/geometries.h"
polynomial.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#include "modified.h"
10#include "magnetic_field.h"
11
12
17namespace dg
18{
19namespace geo
20{
24namespace polynomial
25{
28
37struct Psip: public aCylindricalFunctor<Psip>
38{
44 Psip( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp), m_horner(gp.c, gp.M, gp.N) {}
45 double do_compute(double R, double Z) const
46 {
47 return m_R0*m_pp*m_horner( R/m_R0,Z/m_R0);
48 }
49 private:
50 double m_R0, m_pp;
51 Horner2d m_horner;
52};
53
54struct PsipR: public aCylindricalFunctor<PsipR>
55{
57 PsipR( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp){
58 std::vector<double> beta ( (gp.M-1)*gp.N);
59 for( unsigned i=0; i<gp.M-1; i++)
60 for( unsigned j=0; j<gp.N; j++)
61 beta[i*gp.N+j] = (double)(i+1)*gp.c[ ( i+1)*gp.N +j];
62 m_horner = Horner2d( beta, gp.M-1, gp.N);
63 }
64 double do_compute(double R, double Z) const
65 {
66 return m_pp*m_horner( R/m_R0,Z/m_R0);
67 }
68 private:
69 double m_R0, m_pp;
70 Horner2d m_horner;
71};
72struct PsipRR: public aCylindricalFunctor<PsipRR>
73{
75 PsipRR( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp){
76 std::vector<double> beta ( (gp.M-2)*gp.N);
77 for( unsigned i=0; i<gp.M-2; i++)
78 for( unsigned j=0; j<gp.N; j++)
79 beta[i*gp.N+j] = (double)((i+2)*(i+1))*gp.c[ (i+2)*gp.N +j];
80 m_horner = Horner2d( beta, gp.M-2, gp.N);
81 }
82 double do_compute(double R, double Z) const
83 {
84 return m_pp/m_R0*m_horner( R/m_R0,Z/m_R0);
85 }
86 private:
87 double m_R0, m_pp;
88 Horner2d m_horner;
89};
90struct PsipZ: public aCylindricalFunctor<PsipZ>
91{
93 PsipZ( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp){
94 std::vector<double> beta ( gp.M*(gp.N-1));
95 for( unsigned i=0; i<gp.M; i++)
96 for( unsigned j=0; j<gp.N-1; j++)
97 beta[i*(gp.N-1)+j] = (double)(j+1)*gp.c[ i*gp.N +j+1];
98 m_horner = Horner2d( beta, gp.M, gp.N-1);
99 }
100 double do_compute(double R, double Z) const
101 {
102 return m_pp*m_horner( R/m_R0,Z/m_R0);
103 }
104 private:
105 double m_R0, m_pp;
106 Horner2d m_horner;
107};
108struct PsipZZ: public aCylindricalFunctor<PsipZZ>
109{
111 PsipZZ( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp){
112 std::vector<double> beta ( gp.M*(gp.N-2));
113 for( unsigned i=0; i<gp.M; i++)
114 for( unsigned j=0; j<gp.N-2; j++)
115 beta[i*(gp.N-2)+j] = (double)((j+2)*(j+1))*gp.c[ i*gp.N +j+2];
116 m_horner = Horner2d( beta, gp.M, gp.N-2);
117 }
118 double do_compute(double R, double Z) const
119 {
120 return m_pp/m_R0*m_horner(R/m_R0,Z/m_R0);
121 }
122 private:
123 double m_R0, m_pp;
124 Horner2d m_horner;
125};
126struct PsipRZ: public aCylindricalFunctor<PsipRZ>
127{
129 PsipRZ( Parameters gp ): m_R0(gp.R_0), m_pp(gp.pp){
130 std::vector<double> beta ( (gp.M-1)*(gp.N-1));
131 for( unsigned i=0; i<gp.M-1; i++)
132 for( unsigned j=0; j<gp.N-1; j++)
133 beta[i*(gp.N-1)+j] = (double)((j+1)*(i+1))*gp.c[ (i+1)*gp.N +j+1];
134 m_horner = Horner2d( beta, gp.M-1, gp.N-1);
135 }
136 double do_compute(double R, double Z) const
137 {
138 return m_pp/m_R0*m_horner(R/m_R0,Z/m_R0);
139 }
140 private:
141 double m_R0, m_pp;
142 Horner2d m_horner;
143};
144
146{
147 return CylindricalFunctorsLvl2( Psip(gp), PsipR(gp), PsipZ(gp),
148 PsipRR(gp), PsipRZ(gp), PsipZZ(gp));
149}
151{
153}
154
156
157} //namespace polynomial
158
169{
171 equilibrium::polynomial, modifier::none, str2description.at( gp.description));
173 polynomial::createIpol(gp), params);
174}
175
176} //namespace geo
177} //namespace dg
178
@ none
no modification
@ polynomial
dg::geo::polynomial::Psip
static dg::geo::CylindricalFunctorsLvl2 createPsip(Parameters gp)
Definition: polynomial.h:145
static dg::geo::CylindricalFunctorsLvl1 createIpol(Parameters gp)
Definition: polynomial.h:150
static dg::geo::TokamakMagneticField createPolynomialField(dg::geo::polynomial::Parameters gp)
Create a Polynomial Magnetic field.
Definition: polynomial.h:167
Definition: fluxfunctions.h:114
This struct bundles a function and its first derivatives.
Definition: fluxfunctions.h:182
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
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition: magnetic_field.h:162
Represent functions written in cylindrical coordinates that are independent of the angle phi serving ...
Definition: fluxfunctions.h:66
Constructs and display geometric parameters for the polynomial fields.
Definition: polynomial_parameters.h:46
std::string description
Definition: polynomial_parameters.h:56
double triangularity
triangularity of the magnetic surfaces
Definition: polynomial_parameters.h:52
std::vector< double > c
M*N coefficients for the polynomial equilibrium, c[i*N+j] corresponds to R^i Z^j;.
Definition: polynomial_parameters.h:55
double R_0
major tokamak radius
Definition: polynomial_parameters.h:47
double a
little tokamak radius
Definition: polynomial_parameters.h:50
unsigned N
number of coefficients in Z
Definition: polynomial_parameters.h:54
double elongation
elongation of the magnetic surfaces
Definition: polynomial_parameters.h:51
unsigned M
number of coefficients in R
Definition: polynomial_parameters.h:53
double pi
prefactor for current I
Definition: polynomial_parameters.h:49
Definition: polynomial.h:38
Psip(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:44
double do_compute(double R, double Z) const
Definition: polynomial.h:45
Definition: polynomial.h:55
PsipR(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:57
double do_compute(double R, double Z) const
Definition: polynomial.h:64
Definition: polynomial.h:73
PsipRR(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:75
double do_compute(double R, double Z) const
Definition: polynomial.h:82
Definition: polynomial.h:127
PsipRZ(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:129
double do_compute(double R, double Z) const
Definition: polynomial.h:136
Definition: polynomial.h:91
PsipZ(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:93
double do_compute(double R, double Z) const
Definition: polynomial.h:100
Definition: polynomial.h:109
double do_compute(double R, double Z) const
Definition: polynomial.h:118
PsipZZ(Parameters gp)
Construct from given geometric parameters.
Definition: polynomial.h:111