Extension: Geometries
#include "dg/geometries/geometries.h"
Loading...
Searching...
No Matches
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( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp), m_horner(std::make_shared<Horner2d>( gp.c, gp.M, gp.N)) {}
45 double do_compute(double R, double Z) const
46 {
47 // Optimization rationale: The way we compute magnetic field terms
48 // through the TokamakMagneticField class and e.g. the BHatR class
49 // leads to the existence of many copies of Psip in various functors.
50 // In order to make use of the optimization of the Horner2d class
51 // (which saves computations of previous calls and thus avoids costly
52 // recomputation of the same point or points with the same Z value) all
53 // copies of Psip must access the same Horner2d class. The m_horner is
54 // thus stored as a shared_ptr.
55 return m_R0*m_pp*(*m_horner)( R/m_R0,Z/m_R0);
56 }
57 private:
58 double m_R0, m_pp;
59 std::shared_ptr<Horner2d> m_horner;
60};
61
62struct PsipR: public aCylindricalFunctor<PsipR>
63{
65 PsipR( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp){
66 std::vector<double> beta ( (gp.M-1)*gp.N);
67 for( unsigned i=0; i<gp.M-1; i++)
68 for( unsigned j=0; j<gp.N; j++)
69 beta[i*gp.N+j] = (double)(i+1)*gp.c[ ( i+1)*gp.N +j];
70 m_horner = std::make_shared<Horner2d>( beta, gp.M-1, gp.N);
71 }
72 double do_compute(double R, double Z) const
73 {
74 return m_pp*(*m_horner)( R/m_R0,Z/m_R0);
75 }
76 private:
77 double m_R0, m_pp;
78 std::shared_ptr<Horner2d> m_horner;
79};
80struct PsipRR: public aCylindricalFunctor<PsipRR>
81{
83 PsipRR( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp){
84 std::vector<double> beta ( (gp.M-2)*gp.N);
85 for( unsigned i=0; i<gp.M-2; i++)
86 for( unsigned j=0; j<gp.N; j++)
87 beta[i*gp.N+j] = (double)((i+2)*(i+1))*gp.c[ (i+2)*gp.N +j];
88 m_horner = std::make_shared<Horner2d>( beta, gp.M-2, gp.N);
89 }
90 double do_compute(double R, double Z) const
91 {
92 return m_pp/m_R0*(*m_horner)( R/m_R0,Z/m_R0);
93 }
94 private:
95 double m_R0, m_pp;
96 std::shared_ptr<Horner2d> m_horner;
97};
98struct PsipZ: public aCylindricalFunctor<PsipZ>
99{
101 PsipZ( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp){
102 std::vector<double> beta ( gp.M*(gp.N-1));
103 for( unsigned i=0; i<gp.M; i++)
104 for( unsigned j=0; j<gp.N-1; j++)
105 beta[i*(gp.N-1)+j] = (double)(j+1)*gp.c[ i*gp.N +j+1];
106 m_horner = std::make_shared<Horner2d>( beta, gp.M, gp.N-1);
107 }
108 double do_compute(double R, double Z) const
109 {
110 return m_pp*(*m_horner)( R/m_R0,Z/m_R0);
111 }
112 private:
113 double m_R0, m_pp;
114 std::shared_ptr<Horner2d> m_horner;
115};
116struct PsipZZ: public aCylindricalFunctor<PsipZZ>
117{
119 PsipZZ( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp){
120 std::vector<double> beta ( gp.M*(gp.N-2));
121 for( unsigned i=0; i<gp.M; i++)
122 for( unsigned j=0; j<gp.N-2; j++)
123 beta[i*(gp.N-2)+j] = (double)((j+2)*(j+1))*gp.c[ i*gp.N +j+2];
124 m_horner = std::make_shared<Horner2d>( beta, gp.M, gp.N-2);
125 }
126 double do_compute(double R, double Z) const
127 {
128 return m_pp/m_R0*(*m_horner)(R/m_R0,Z/m_R0);
129 }
130 private:
131 double m_R0, m_pp;
132 std::shared_ptr<Horner2d> m_horner;
133};
134struct PsipRZ: public aCylindricalFunctor<PsipRZ>
135{
137 PsipRZ( const Parameters& gp ): m_R0(gp.R_0), m_pp(gp.pp){
138 std::vector<double> beta ( (gp.M-1)*(gp.N-1));
139 for( unsigned i=0; i<gp.M-1; i++)
140 for( unsigned j=0; j<gp.N-1; j++)
141 beta[i*(gp.N-1)+j] = (double)((j+1)*(i+1))*gp.c[ (i+1)*gp.N +j+1];
142 m_horner = std::make_shared<Horner2d>( beta, gp.M-1, gp.N-1);
143 }
144 double do_compute(double R, double Z) const
145 {
146 return m_pp/m_R0*(*m_horner)(R/m_R0,Z/m_R0);
147 }
148 private:
149 double m_R0, m_pp;
150 std::shared_ptr<Horner2d> m_horner;
151};
152
154{
155 return CylindricalFunctorsLvl2( Psip(gp), PsipR(gp), PsipZ(gp),
156 PsipRR(gp), PsipRZ(gp), PsipZZ(gp));
157}
162
164
165} //namespace polynomial
166
191
192} //namespace geo
193} //namespace dg
194
@ none
no modification
@ polynomial
dg::geo::polynomial::Psip
dg::geo::CylindricalFunctorsLvl2 createPsip(const Parameters &gp)
Definition polynomial.h:153
dg::geo::TokamakMagneticField createPolynomialField(const dg::geo::polynomial::Parameters &gp)
Create a Polynomial Magnetic field.
Definition polynomial.h:183
dg::geo::CylindricalFunctorsLvl1 createIpol(const Parameters &gp)
Definition polynomial.h:158
Definition fluxfunctions.h:113
This struct bundles a function and its first derivatives.
Definition fluxfunctions.h:185
This struct bundles a function and its first and second derivatives.
Definition fluxfunctions.h:222
Meta-data about the magnetic field in particular the flux function.
Definition magnetic_field.h:101
A tokamak field as given by R0, Psi and Ipol plus Meta-data like shape and equilibrium.
Definition magnetic_field.h:172
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:43
std::string description
Definition polynomial_parameters.h:53
double triangularity
triangularity of the magnetic surfaces
Definition polynomial_parameters.h:49
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:52
double R_0
major tokamak radius
Definition polynomial_parameters.h:44
double a
little tokamak radius
Definition polynomial_parameters.h:47
unsigned N
number of coefficients in Z
Definition polynomial_parameters.h:51
double elongation
elongation of the magnetic surfaces
Definition polynomial_parameters.h:48
unsigned M
number of coefficients in R
Definition polynomial_parameters.h:50
double pi
prefactor for current I
Definition polynomial_parameters.h:46
Definition polynomial.h:38
Psip(const 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:63
PsipR(const Parameters &gp)
Construct from given geometric parameters.
Definition polynomial.h:65
double do_compute(double R, double Z) const
Definition polynomial.h:72
Definition polynomial.h:81
PsipRR(const Parameters &gp)
Construct from given geometric parameters.
Definition polynomial.h:83
double do_compute(double R, double Z) const
Definition polynomial.h:90
Definition polynomial.h:135
double do_compute(double R, double Z) const
Definition polynomial.h:144
PsipRZ(const Parameters &gp)
Construct from given geometric parameters.
Definition polynomial.h:137
Definition polynomial.h:99
PsipZ(const Parameters &gp)
Construct from given geometric parameters.
Definition polynomial.h:101
double do_compute(double R, double Z) const
Definition polynomial.h:108
Definition polynomial.h:117
double do_compute(double R, double Z) const
Definition polynomial.h:126
PsipZZ(const Parameters &gp)
Construct from given geometric parameters.
Definition polynomial.h:119