Commit 9f764907 authored by frey_m's avatar frey_m

Matched-Gauss: Used interpolation of Cyclotron.h

parent 598d1782
......@@ -561,21 +561,7 @@ void ParallelCyclotronTracker::visitCyclotron(const Cyclotron &cycl) {
* fieldflag = 6, readin both median plane B field map and 3D E field map of RF cavity for compact cyclotron
* fieldflag = 7, read in fields for Daniel's synchrocyclotron simulations
*/
int fieldflag;
if(type == std::string("CARBONCYCL")) {
fieldflag = 2;
} else if(type == std::string("CYCIAE")) {
fieldflag = 3;
} else if(type == std::string("AVFEQ")) {
fieldflag = 4;
} else if(type == std::string("FFAG")) {
fieldflag = 5;
} else if(type == std::string("BANDRF")) {
fieldflag = 6;
} else if(type == std::string("SYNCHROCYCLOTRON")) {
fieldflag = 7;
} else //(type == "RING")
fieldflag = 1;
int fieldflag = elptr->getFieldFlag(type);
// Read in cyclotron field maps (midplane + 3D fields if desired).
elptr->initialise(itsBunch_m, fieldflag, elptr->getBScale());
......
This diff is collapsed.
......@@ -119,6 +119,8 @@ public:
void setRfFieldMapFN(std::vector<std::string> rffmapfn);
void setRFFCoeffFN(std::vector<std::string> rff_coeff_fn);
void setRFVCoeffFN(std::vector<std::string> rfv_coeff_fn);
int getFieldFlag(const std::string& type) const;
void setType(std::string t);
const std::string &getCyclotronType() const;
......@@ -201,7 +203,18 @@ public:
virtual double getRmin() const;
bool interpolate(const double& rad,
const double& tet_rad,
double& br,
double& bt,
double& bz);
void read(const int &fieldflag, const double &scaleFactor);
protected:
void getdiffs();
double gutdf5d(double *f, double dx, const int kor, const int krl, const int lpr);
......
......@@ -266,10 +266,26 @@ ClosedOrbitFinder<Value_type,
size_type nSector, const std::string& fmapfn,
value_type rguess, const std::string& type,
value_type scaleFactor, bool domain)
: nxcross_m(0), nzcross_m(0), E_m(E), E0_m(E0), wo_m(wo), N_m(N), dtheta_m(Physics::two_pi/value_type(N)),
gamma_m(E/E0+1.0), ravg_m(0), phase_m(0), converged_m(false), Emin_m(Emin), Emax_m(Emax), nSector_m(nSector),
lastOrbitVal_m(0.0), lastMomentumVal_m(0.0),
vertOscDone_m(false), domain_m(domain), stepper_m(), rguess_m(rguess), bField_m(fmapfn, nSector)
: nxcross_m(0)
, nzcross_m(0)
, E_m(E)
, E0_m(E0)
, wo_m(wo)
, N_m(N)
, dtheta_m(Physics::two_pi/value_type(N))
, gamma_m(E/E0+1.0)
, ravg_m(0)
, phase_m(0)
, converged_m(false)
, Emin_m(Emin)
, Emax_m(Emax)
, nSector_m(nSector)
, lastOrbitVal_m(0.0)
, lastMomentumVal_m(0.0)
, vertOscDone_m(false)
, domain_m(domain)
, stepper_m()
, rguess_m(rguess)
{
if ( Emin_m > Emax_m )
......@@ -306,7 +322,10 @@ ClosedOrbitFinder<Value_type,
fidx_m.reserve(N_m);
// read in magnetic fieldmap
bField_m.read(type, scaleFactor);
bField_m.setFieldMapFN(type);
bField_m.setSymmetry(nSector_m);
int fieldflag = bField_m.getFieldFlag(type);
bField_m.read(fieldflag, scaleFactor);
// compute closed orbit
converged_m = findOrbit(accuracy, maxit);
......@@ -489,7 +508,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
invptheta = 1.0 / ptheta;
// interpolate values of magnetic field
bField_m.interpolate(bint, brint, btint, y[0], theta);
bField_m.interpolate(y[0], theta, brint, btint, bint);
bint *= invbcon;
brint *= invbcon;
......@@ -731,7 +750,7 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeOrbitProperties()
for (size_type i = 0; i < N_m; ++i) {
// interpolate magnetic field
bField_m.interpolate(bint, brint, btint, r_m[i], theta);
bField_m.interpolate(r_m[i], theta, brint, btint, bint);
bint *= invbcon;
brint *= invbcon;
btint *= invbcon;
......@@ -789,7 +808,7 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeVerticalOscillati
invptheta = 1.0 / ptheta;
// intepolate values of magnetic field
bField_m.interpolate(bint, brint, btint, y[0], theta);
bField_m.interpolate(y[0], theta, brint, btint, bint);
bint *= invbcon;
brint *= invbcon;
......
#include "MagneticField.h"
MagneticField::MagneticField(const std::string fmapfn,
const double& symmetry) :
Cyclotron(),
nullGeom_m(NullGeometry()),
nullField_m(NullField())
MagneticField::MagneticField()
: Cyclotron()
, nullGeom_m(NullGeometry())
, nullField_m(NullField())
{
this->setFieldMapFN(fmapfn);
this->setSymmetry(symmetry);
}
void MagneticField::read(const std::string& type,
const double& scaleFactor) {
if ( type == "CARBONCYCL" )
this->getFieldFromFile_Carbon(scaleFactor);
else if ( type == "CYCIAE" )
this->getFieldFromFile_CYCIAE(scaleFactor);
else if ( type == "AVFEQ" )
this->getFieldFromFile_AVFEQ(scaleFactor);
else if ( type == "FFAG" )
this->getFieldFromFile_FFAG(scaleFactor);
else if ( type == "BANDRF" )
this->getFieldFromFile_BandRF(scaleFactor);
else if ( type == "SYNCHROCYCLOTRON" )
this->getFieldFromFile_Synchrocyclotron(scaleFactor);
else
this->getFieldFromFile(scaleFactor);
if ( BP.rarr.empty() ) {
// calculate the radii of initial grid.
this->initR(BP.rmin, BP.delr, Bfield.nrad);
}
if ( Bfield.dbr.empty() || Bfield.dbt.empty() ) {
// calculate the remaining derivatives
this->getdiffs();
}
}
void MagneticField::interpolate(double& bint,
double& brint,
double& btint,
const double& rad,
const double& theta
)
{
// x horizontal
// y longitudinal
// z is vertical
const double xir = (rad - BP.rmin) / (BP.delr);
// ir : the number of path whose radius is less than the 4 points of cell which surround the particle.
const int ir = (int)xir;
// wr1 : the relative distance to the inner path radius
const double wr1 = xir - (double)ir;
// wr2 : the relative distance to the outer path radius
const double wr2 = 1.0 - wr1;
double tet_rad = theta;
// the actual angle of particle
// tet_rad = theta / Physics::pi * 180.0;
// the corresponding angle on the field map
// Note: this does not work if the start point of field map does not equal zero.
double tet_map = fmod(tet_rad, 360.0 / this->getSymmetry());
double xit = tet_map / BP.dtet;
int it = (int) xit;
const double wt1 = xit - (double)it;
const double wt2 = 1.0 - wt1;
// it : the number of point on the inner path whose angle is less than the particle' corresponding angle.
// include zero degree point
it = it + 1;
int r1t1, r2t1, r1t2, r2t2;
// int ntetS = Bfield.ntet + 1;
// r1t1 : the index of the "min angle, min radius" point in the 2D field array.
// considering the array start with index of zero, minus 1.
// if(myBFieldType_m != FFAGBF) {
/*
For FFAG this does not work
*/
// r1t1 = it + ntetS * ir - 1;
// r1t2 = r1t1 + 1;
// r2t1 = r1t1 + ntetS;
// r2t2 = r2t1 + 1 ;
// } else {
// /*
// With this we have B-field AND this is far more
// intuitive for me ....
// */
r1t1 = idx(ir, it);
r2t1 = idx(ir + 1, it);
r1t2 = idx(ir, it + 1);
r2t2 = idx(ir + 1, it + 1);
// }
bint = 0.0;
brint = 0.0;
btint = 0.0;
if((it >= 0) && (ir >= 0) && (it < Bfield.ntetS) && (ir < Bfield.nrad)) {
// dB_{z}/dr
brint = (Bfield.dbr[r1t1] * wr2 * wt2 +
Bfield.dbr[r2t1] * wr1 * wt2 +
Bfield.dbr[r1t2] * wr2 * wt1 +
Bfield.dbr[r2t2] * wr1 * wt1);
// dB_{z}/dtheta
btint = Bfield.dbt[r1t1] * wr2 * wt2 +
Bfield.dbt[r2t1] * wr1 * wt2 +
Bfield.dbt[r1t2] * wr2 * wt1 +
Bfield.dbt[r2t2] * wr1 * wt1;
// B_{z}
bint = Bfield.bfld[r1t1] * wr2 * wt2 +
Bfield.bfld[r2t1] * wr1 * wt2 +
Bfield.bfld[r1t2] * wr2 * wt1 +
Bfield.bfld[r2t2] * wr1 * wt1;
}
}
double MagneticField::getSlices() const {
......
......@@ -25,33 +25,7 @@
class MagneticField : public Cyclotron {
public:
/*!
* @param fmapfn specifies the fieldmap file. We support only
* the CARBONCYCL format at the moment.
*/
MagneticField(const std::string fmapfn, const double& symmetry);
/*!
* @param type of the magnetic field file (e.g. CARBONCYCL)
* @param scaleFactor for the magnetic field.
*/
void read(const std::string& type,const double& scaleFactor);
/*!
* Get the value of B_{z}, dB_{z}/dr and dB_{z}/dtheta
* where theta is the azimuth angle and r the radius.
* @param bint is the magnetic field B_{z} [kG]
* @param brint is dB_{z}/dr [kG/m]
* @param btint is dB_{z}/dtheta [kG/deg]
* @param r is the radial interpolation point [m]
* @param theta is the azimuthal interpolation point [deg]
*/
void interpolate(double& bint,
double& brint,
double& btint,
const double& r,
const double& theta);
MagneticField();
/*! Do not call.
* @returns a dummy value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment