OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
TrimCoil.cpp
Go to the documentation of this file.
1 //
2 // Class TrimCoil
3 // Abstract TrimCoil class.
4 //
5 // Copyright (c) 2018 - 2019, Matthias Frey and Jochem Snuverink,
6 // 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 "TrimCoil.h"
26 
27 #include <cmath>
28 
29 #include "Physics/Units.h"
30 #include "Utilities/Util.h"
31 
32 TrimCoil::TrimCoil(double bmax,
33  double rmin,
34  double rmax)
35 {
36  // convert to m
37  rmin_m = rmin * Units::mm2m;
38  rmax_m = rmax * Units::mm2m;
39  // convert to kG
40  bmax_m = bmax * Units::T2kG;
41 }
42 
43 void TrimCoil::applyField(const double r, const double z, const double phi_rad, double *br, double *bz)
44 {
45  if (std::abs(bmax_m) < 1e-20) return;
46 
47  double phi = Util::angle_0to2pi(phi_rad);
48  // check if phi is inside [phimin_m, phimax_m]
50  doApplyField(r,z,phi_rad,br,bz);
51 }
52 
53 void TrimCoil::setAzimuth(const double phimin, const double phimax)
54 {
55  // phi convert to rad
57  phimax_m = Util::angle_0to2pi(phimax * Units::deg2rad);
58 }
double angle_0to2pi(double angle)
convert angle (in rad) to [0,2pi) range, from https://stackoverflow.com/a/29721295 ...
Definition: Util.h:199
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
bool angleBetweenAngles(const double angle, const double min, const double max)
check if angle (in rad and in range [0,2pi]) is within [min, max]
Definition: Util.h:206
constexpr double T2kG
Definition: Units.h:56
double rmax_m
Maximum radius (m)
Definition: TrimCoil.h:49
void setAzimuth(const double phimin, const double phimax)
Set azimuthal range where trim coil acts: [phimin, phimax] (also when phimin &gt; phimax) ...
Definition: TrimCoil.cpp:53
double phimin_m
Minimal azimuth (rad)
Definition: TrimCoil.h:51
constexpr double deg2rad
Definition: Units.h:143
constexpr double mm2m
Definition: Units.h:29
double bmax_m
Maximum B field (kG)
Definition: TrimCoil.h:40
double rmin_m
Minimum radius (m)
Definition: TrimCoil.h:47
double phimax_m
Maximal azimuth (rad)
Definition: TrimCoil.h:53
void applyField(const double r, const double z, const double phi_rad, double *br, double *bz)
Definition: TrimCoil.cpp:43
constexpr double e
The value of .
Definition: Physics.h:39
TrimCoil(double bmax, double rmin, double rmax)
Definition: TrimCoil.cpp:32
virtual void doApplyField(const double r, const double z, const double phi_rad, double *br, double *bz)=0
virtual implementation of applyField