OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
TrimCoilBFit.cpp
Go to the documentation of this file.
1 //
2 // Class TrimCoilBFit
3 // General rational function fit
4 // https://gitlab.psi.ch/OPAL/src/issues/157
5 //
6 // Copyright (c) 2018 - 2019, Jochem Snuverink, Paul Scherrer Institut, Villigen PSI, Switzerland
7 // All rights reserved
8 //
9 // Implemented as part of the PhD thesis
10 // "Precise Simulations of Multibunches in High Intensity Cyclotrons"
11 // and the paper
12 // "Matching of turn pattern measurements for cyclotrons using multiobjective optimization"
13 // (https://doi.org/10.1103/PhysRevAccelBeams.22.064602)
14 //
15 // This file is part of OPAL.
16 //
17 // OPAL is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
24 //
25 #include "TrimCoils/TrimCoilBFit.h"
26 
28  double rmin,
29  double rmax,
30  const std::vector<double>& coefnum,
31  const std::vector<double>& coefdenom,
32  const std::vector<double>& coefnumphi,
33  const std::vector<double>& coefdenomphi):
34  TrimCoilFit(bmax, rmin, rmax, coefnum, coefdenom, coefnumphi, coefdenomphi)
35 {}
36 
37 void TrimCoilBFit::doApplyField(const double r, const double z, const double phi_rad, double *br, double *bz)
38 {
39  // check range
40  if (r < rmin_m || r > rmax_m) return;
41 
42  double btr = 0.0, dr = 0.0;
43  calculateRationalFunction(RADIUS, r, btr, dr);
44  double phi = 0.0, dphi = 0.0;
45  calculateRationalFunction(PHI, phi_rad, phi, dphi);
46 
47  //std::cout << "r " << r << " dr " << dr << std::endl;
48 
49  *bz += bmax_m * btr * phi;
50  *br += bmax_m * (dr * phi + btr*dphi) * z;
51 }
double bmax_m
Maximum B field (kG)
Definition: TrimCoil.h:40
double rmax_m
Maximum radius (m)
Definition: TrimCoil.h:49
virtual void doApplyField(const double r, const double z, const double phi_rad, double *br, double *bz)
virtual implementation of applyField
TrimCoilBFit()=delete
void calculateRationalFunction(FunctionType, double value, double &quot, double &der_quot) const
calculate rational function and its first derivative
Definition: TrimCoilFit.cpp:57