OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
SectorMagneticFieldMap Class Reference

handles field map grids with sector geometry More...

#include <SectorMagneticFieldMap.h>

Inheritance diagram for SectorMagneticFieldMap:
Collaboration diagram for SectorMagneticFieldMap:

Classes

class  IO
 handles reading sector field maps More...

Public Member Functions

 SectorMagneticFieldMap (std::string file_name, std::string symmetry, double length_units, double field_units, int polynomial_order, int smoothing_order)
 SectorMagneticFieldMap (const SectorMagneticFieldMap &field)
 ~SectorMagneticFieldMap ()
bool getFieldstrength (const Vector_t< double, 3 > &R_c, Vector_t< double, 3 > &E_c, Vector_t< double, 3 > &B_c) const
interpolation::VectorMapgetInterpolator ()
void setInterpolator (interpolation::VectorMap *interpolator)
std::string getFieldMapFileName () const
std::string getSymmetry () const
void setSymmetry (std::string name)
bool getFieldDerivative (const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const
void swap ()
void getInfo (Inform *msg)
void print (std::ostream &out)
void readMap ()
void freeMap ()
double getFrequency () const
void setFrequency (double)
double getPhiOffset () const
void setPhiOffset (double dphi)
double getDeltaPhi () const
virtual std::vector< double > getPolarBoundingBoxMin () const
virtual std::vector< double > getPolarBoundingBoxMax () const
void getFieldDimensions (double &zBegin, double &zEnd, double &rBegin, double &rEnd) const
void getFieldDimensions (double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const
bool isInBoundingBox (const double R_p[]) const

Static Public Member Functions

static void clearFieldCache ()
static void convertToPolar (double *position)
static void convertToPolar (const double *position_polar, double *value)
static void convertToCartesian (double *position)
static void convertToCartesian (const double *position_polar, double *value)

Protected Member Functions

void setPolarBoundingBox (double bbMinR, double bbMinY, double bbMinPhi, double bbMaxR, double bbMaxY, double bbMaxPhi, double bbTolR, double bbTolY, double bbTolPhi)

Protected Attributes

std::vector< double > bbMin_m
std::vector< double > bbMax_m
std::vector< double > polarBBMin_m
std::vector< double > polarBBMax_m
std::string Filename_m

Private Types

enum  symmetry { none , dipole }

Private Member Functions

bool applySymmetry (double *R_temp) const
void Rotate (double *value, double angle)
SectorMagneticFieldMapoperator= (const SectorMagneticFieldMap &field)
std::vector< std::vector< double > > getCorners (double bbMinR, double bbMinPhi, double bbMaxR, double bbMaxPhi)

Static Private Member Functions

static symmetry StringToSymmetry (std::string name)
static std::string SymmetryToString (symmetry sym)

Private Attributes

interpolation::VectorMapinterpolator_m
symmetry symmetry_m
std::vector< double > units_m
const std::string filename_m
double phiOffset_m
int poly_order_m
int smoothing_order_m

Static Private Attributes

static const double fractionalBBPhiTolerance_m
static std::map< std::string, SectorMagneticFieldMap * > _fields

Friends

class FieldMap
class SectorMagneticFieldMapIO

Detailed Description

handles field map grids with sector geometry

SectorMagneticFieldMap provides an interface to the 3D interpolator routines for 3D field maps in a sector geometry. Interpolation is done from points in (r, y, phi) geometry off of a 3D field map stored in cartesian coordinates.

  • position coordinates are left in polar because it makes the interpolation easier

  • field coordinates are left in cartesian because it means we can avoid doing a coordinate transformation (tracking is done in cartesian coordinates)

A constructor is provided which calls the SectorMagneticFieldMapIO class to generate the field map, and it is expected that this will be the usual way to generate the map.

The SectorMagneticFieldMap class caches field maps by file name to avoid multiple loads of the same field map. This cache should be cleared after running (otherwise we have a memory leak).

Note that the coordinate system used for tracking by Ring (z is up) is a bit different to that implemented in SectorField (y is up). I perform a coordinate transformation in the getFieldstrength function to facilitate this. Note that OpalBeamline has y is up...

SectorMagneticFieldMap enforces that field is hard against the start edge with no gap. SectorMagneticFieldMap auto-detects any field phi offset and removes each time it does a field lookup (just an add operation, so fast). If a phi offset is desired, user must zero-pad field map.

Definition at line 75 of file SectorMagneticFieldMap.h.

Member Enumeration Documentation

◆ symmetry

Enumerator
none 
dipole 

Definition at line 204 of file SectorMagneticFieldMap.h.

Constructor & Destructor Documentation

◆ SectorMagneticFieldMap() [1/2]

SectorMagneticFieldMap::SectorMagneticFieldMap ( std::string file_name,
std::string symmetry,
double length_units,
double field_units,
int polynomial_order,
int smoothing_order )

Generate the field map by calling SectorMagneticFieldMap::IO

Parameters
file_namename of the file to read in
symmetryparameter that controls mirror symmetry applied to the field map - either "Dipole" or "None"
length_unitsmultiplier for lengths
field_unitsmultiplier for fields
polynomial_orderorder of polynomial fit to the mesh points
smoothing_orderorder of smoothing (should be >= polynomial_order)

Definition at line 59 of file SectorMagneticFieldMap.cpp.

References _fields, dipole, filename_m, interpolator_m, interpolation::ThreeDGrid::minZ(), phiOffset_m, poly_order_m, readMap(), SectorField::SectorField(), SectorMagneticFieldMap(), setInterpolator(), setSymmetry(), smoothing_order_m, symmetry_m, and units_m.

Referenced by operator=(), SectorMagneticFieldMap(), and SectorMagneticFieldMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SectorMagneticFieldMap() [2/2]

SectorMagneticFieldMap::SectorMagneticFieldMap ( const SectorMagneticFieldMap & field)

Copy constructor - makes a deep copy of the field map

Definition at line 95 of file SectorMagneticFieldMap.cpp.

References filename_m, interpolator_m, phiOffset_m, SectorField::SectorField(), SectorMagneticFieldMap(), setInterpolator(), symmetry_m, and units_m.

Here is the call graph for this function:

◆ ~SectorMagneticFieldMap()

SectorMagneticFieldMap::~SectorMagneticFieldMap ( )

Destructor - delete allocated memory

Definition at line 107 of file SectorMagneticFieldMap.cpp.

Member Function Documentation

◆ applySymmetry()

bool SectorMagneticFieldMap::applySymmetry ( double * R_temp) const
private

Reflect R_temp about y if below bbmin

Returns
true if symmetry transformation was applied

Definition at line 241 of file SectorMagneticFieldMap.cpp.

References dipole, SectorField::getPolarBoundingBoxMin(), and symmetry_m.

Here is the call graph for this function:

◆ clearFieldCache()

void SectorMagneticFieldMap::clearFieldCache ( )
static

Delete cached fields

Definition at line 250 of file SectorMagneticFieldMap.cpp.

References _fields.

◆ convertToCartesian() [1/2]

void SectorField::convertToCartesian ( const double * position_polar,
double * value )
staticinherited

Convert a 3 vector from polar to cartesian coordinate system

Parameters
positionposition in polar coordinates at which the value is valid
valuepointer to an allocated block of at least 3 doubles. The function will apply a rotation to the existing data to render it from polar coordinates (a_r, a_y, a_phi) to polar coordinates (a_x, a_y, a_z) appropriate for the specified position.

Definition at line 77 of file SectorField.cpp.

◆ convertToCartesian() [2/2]

void SectorField::convertToCartesian ( double * position)
staticinherited

Convert a position from polar coordinates to cartesian

Parameters
positionposition in polar coordinates to convert to cartesian polar coordinates. Input should be an allocated block of at least 3 doubles containing values (r, y, phi). This is over written with 3 double containing values (x, y, z).

Definition at line 70 of file SectorField.cpp.

Referenced by getCorners().

Here is the caller graph for this function:

◆ convertToPolar() [1/2]

void SectorField::convertToPolar ( const double * position_polar,
double * value )
staticinherited

Convert a 3 vector from cartesian to polar coordinate system

Parameters
positionposition in polar coordinates at which the value is valid
valuepointer to an allocated block of at least 3 doubles. The function will apply a rotation to the existing data to render it from cartesian coordinates (a_x, a_y, a_z) to polar coordinates (a_r, a_y, a_phi) appropriate for the specified position.

Definition at line 61 of file SectorField.cpp.

◆ convertToPolar() [2/2]

void SectorField::convertToPolar ( double * position)
staticinherited

Convert a position from cartesian to polar coordinates

Parameters
positionposition in cartesian coordinates to convert to cylindrical polar coordinates. Input should be an allocated block of at least 3 doubles containing values (x, y, z). This is over written with 3 double containing values (r, y, phi).

Definition at line 54 of file SectorField.cpp.

Referenced by SectorMagneticFieldMap::getFieldstrength(), and SectorMagneticFieldMap::IO::readLines().

Here is the caller graph for this function:

◆ freeMap()

void SectorMagneticFieldMap::freeMap ( )

Delete the field map interpolator and set pointer to nullptr

Definition at line 160 of file SectorMagneticFieldMap.cpp.

References setInterpolator().

Here is the call graph for this function:

◆ getCorners()

std::vector< std::vector< double > > SectorField::getCorners ( double bbMinR,
double bbMinPhi,
double bbMaxR,
double bbMaxPhi )
privateinherited

Definition at line 162 of file SectorField.cpp.

References convertToCartesian().

Referenced by setPolarBoundingBox().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDeltaPhi()

double SectorMagneticFieldMap::getDeltaPhi ( ) const

Get change in azimuthal angle between entrance and exit

Definition at line 287 of file SectorMagneticFieldMap.cpp.

References interpolator_m, interpolation::ThreeDGrid::maxZ(), and interpolation::ThreeDGrid::minZ().

Here is the call graph for this function:

◆ getFieldDerivative()

bool SectorMagneticFieldMap::getFieldDerivative ( const Vector_t< double, 3 > & R,
Vector_t< double, 3 > & E,
Vector_t< double, 3 > & B,
const DiffDirection & dir ) const

Not implemented - throws a LogicalError

Definition at line 278 of file SectorMagneticFieldMap.cpp.

◆ getFieldDimensions() [1/2]

void SectorField::getFieldDimensions ( double & xIni,
double & xFinal,
double & yIni,
double & yFinal,
double & zIni,
double & zFinal ) const
inherited

Fill inputs with the bounding box in Cartesian coordinates

Parameters
xInilower bound on field x-position (horizontal)
xFinalupper bound on field x-position (horizontal)
yInilower bound on field y-position (vertical)
yFinalupper bound on field y-position (vertical)
zInilower bound on field z-position (longitudinal)
zFinalupper bound on field z-position (longitudinal)

Definition at line 205 of file SectorField.cpp.

References bbMax_m, and bbMin_m.

◆ getFieldDimensions() [2/2]

void SectorField::getFieldDimensions ( double & zBegin,
double & zEnd,
double & rBegin,
double & rEnd ) const
inherited

Fill inputs with the bounding box in Polar coordinates

Parameters
zBeginlower bound on field length in phi direction (units of distance)
zEndupper bound on field length in phi direction (units of distance)
rBeginlower bound on field length in radial direction
rEndlower bound on field length in radial direction

Definition at line 197 of file SectorField.cpp.

References polarBBMax_m, and polarBBMin_m.

◆ getFieldMapFileName()

std::string SectorMagneticFieldMap::getFieldMapFileName ( ) const
inline

Get the field map file name

Definition at line 149 of file SectorMagneticFieldMap.h.

References filename_m.

◆ getFieldstrength()

bool SectorMagneticFieldMap::getFieldstrength ( const Vector_t< double, 3 > & R_c,
Vector_t< double, 3 > & E_c,
Vector_t< double, 3 > & B_c ) const
virtual

Return the field value in polar coordinates

Parameters
R_pposition in cylindrical coordinates at which to evaluate the field. Should be an array of length 3 like (r, y, phi)
E_preference to an allocated 3-vector. The function will fill the block with the value of the field in cylindrical polar coordinates, (e_r, e_y, e_phi) Overwrites any existing data
B_preference to an allocated 3-vector. The function will fill the block with the value of the field in cylindrical polar coordinates, (b_r, b_y, b_phi) Overwrites any existing data
Returns
false if R_p is inside the bounding box Get the field value in cartesian coordinates
Parameters
R_parray holding the cartesian 3-position at which the field is to be evaluated, (x, y, z)
E_parray of at 3 doubles, to which the field at point is written (ex, ey, ez) - note this field is magnetostatic so always return 0 here.
B_parray of at 3 doubles, to which the field at point is written (bx, by, bz)
Returns
false if R_c is inside the bounding box

Implements SectorField.

Definition at line 208 of file SectorMagneticFieldMap.cpp.

References SectorField::convertToPolar(), SectorField::getPolarBoundingBoxMax(), SectorField::getPolarBoundingBoxMin(), interpolator_m, SectorField::isInBoundingBox(), and phiOffset_m.

Here is the call graph for this function:

◆ getFrequency()

double SectorMagneticFieldMap::getFrequency ( ) const
inline

Magnetostatic field map - so returns 0.

Definition at line 187 of file SectorMagneticFieldMap.h.

◆ getInfo()

void SectorMagneticFieldMap::getInfo ( Inform * msg)

Print summary information about the field map to Inform

Definition at line 258 of file SectorMagneticFieldMap.cpp.

References SectorField::Filename_m, SectorField::getPolarBoundingBoxMax(), and SectorField::getPolarBoundingBoxMin().

Referenced by setInterpolator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInterpolator()

VectorMap * SectorMagneticFieldMap::getInterpolator ( )

Get a pointer to the interpolator or nullptr if it is not set

Note SectorMagneticFieldMap still owns this memory.

Definition at line 111 of file SectorMagneticFieldMap.cpp.

References interpolator_m.

Referenced by SectorMagneticFieldMap::IO::readMap().

Here is the caller graph for this function:

◆ getPhiOffset()

double SectorMagneticFieldMap::getPhiOffset ( ) const
inline

Get phi offset

Definition at line 193 of file SectorMagneticFieldMap.h.

References phiOffset_m.

◆ getPolarBoundingBoxMax()

std::vector< double > SectorField::getPolarBoundingBoxMax ( ) const
virtualinherited

Get the maximum bounding box in polar coordinates

Returns
bounding box maximum as a 3-vector like (r_max, y_max, phi_max)

Definition at line 193 of file SectorField.cpp.

References polarBBMax_m.

Referenced by SectorMagneticFieldMap::getFieldstrength(), SectorMagneticFieldMap::getInfo(), and SectorMagneticFieldMap::print().

Here is the caller graph for this function:

◆ getPolarBoundingBoxMin()

std::vector< double > SectorField::getPolarBoundingBoxMin ( ) const
virtualinherited

Get the minimum bounding box in polar coordinates

Returns
bounding box minimum as a 3-vector like (r_min, y_min, phi_min)

Definition at line 189 of file SectorField.cpp.

References polarBBMin_m.

Referenced by SectorMagneticFieldMap::applySymmetry(), SectorMagneticFieldMap::getFieldstrength(), SectorMagneticFieldMap::getInfo(), and SectorMagneticFieldMap::print().

Here is the caller graph for this function:

◆ getSymmetry()

std::string SectorMagneticFieldMap::getSymmetry ( ) const

Get a string corresponding to the field map symmetry

Returns
field map symmetry, either "None" or "Dipole"

Definition at line 145 of file SectorMagneticFieldMap.cpp.

References symmetry_m, and SymmetryToString().

Here is the call graph for this function:

◆ isInBoundingBox()

bool SectorField::isInBoundingBox ( const double R_p[]) const
inlineinherited

Return true if polar vector R_p is within polar bounding box

Parameters
R_ppolar coordinates (r, y, phi)

Definition at line 224 of file SectorField.h.

References polarBBMax_m, and polarBBMin_m.

Referenced by SectorMagneticFieldMap::getFieldstrength().

Here is the caller graph for this function:

◆ operator=()

SectorMagneticFieldMap & SectorMagneticFieldMap::operator= ( const SectorMagneticFieldMap & field)
private

References SectorMagneticFieldMap().

Here is the call graph for this function:

◆ print()

void SectorMagneticFieldMap::print ( std::ostream & out)

Print summary information about the field map to out

Definition at line 268 of file SectorMagneticFieldMap.cpp.

References SectorField::Filename_m, SectorField::getPolarBoundingBoxMax(), and SectorField::getPolarBoundingBoxMin().

Here is the call graph for this function:

◆ readMap()

void SectorMagneticFieldMap::readMap ( )

Read in the field map from the file

Definition at line 153 of file SectorMagneticFieldMap.cpp.

References filename_m, poly_order_m, SectorMagneticFieldMap::IO::readMap(), setInterpolator(), smoothing_order_m, symmetry_m, and units_m.

Referenced by SectorMagneticFieldMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Rotate()

void SectorMagneticFieldMap::Rotate ( double * value,
double angle )
private

◆ setFrequency()

void SectorMagneticFieldMap::setFrequency ( double )
inline

Magnetostatic field map - so does nothing

Definition at line 190 of file SectorMagneticFieldMap.h.

◆ setInterpolator()

void SectorMagneticFieldMap::setInterpolator ( interpolation::VectorMap * interpolator)

Set the interpolator

Parameters
interpolatorset the field map interpolator. Note SectorMagneticFieldMap now owns the memory pointed to by interpolator

Definition at line 115 of file SectorMagneticFieldMap.cpp.

References getInfo(), gmsg, interpolator_m, interpolation::ThreeDGrid::maxX(), interpolation::ThreeDGrid::maxY(), interpolation::ThreeDGrid::maxZ(), interpolation::ThreeDGrid::minX(), interpolation::ThreeDGrid::minY(), interpolation::ThreeDGrid::minZ(), and SectorField::setPolarBoundingBox().

Referenced by freeMap(), readMap(), SectorMagneticFieldMap(), and SectorMagneticFieldMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPhiOffset()

void SectorMagneticFieldMap::setPhiOffset ( double dphi)
inline

Set phi offset

Definition at line 196 of file SectorMagneticFieldMap.h.

References phiOffset_m.

◆ setPolarBoundingBox()

void SectorField::setPolarBoundingBox ( double bbMinR,
double bbMinY,
double bbMinPhi,
double bbMaxR,
double bbMaxY,
double bbMaxPhi,
double bbTolR,
double bbTolY,
double bbTolPhi )
protectedinherited

Set the bounding boxes from polar coordinates

Sets the bounding boxes, both polar and cartesian, based on a set of minimum and maximum polar coordinates. Note that MinPhi->MaxPhi are allowed in the domain -2pi to 2pi. If the difference is >= 2pi, then this will describe the full ring.

Parameters
bbMinRminimum radius - must be positive
bbMinYminimum y value
bbMinPhiminimum phi value - must be greater than -2*pi
bbMaxRmaximum radius - must be greater than minimum radius
bbMaxYmaximum y value - must be greater than minimum y value
bbMaxPhimaximum phi value - must be greater than minimum phi and less than 2*pi

Definition at line 86 of file SectorField.cpp.

References bbMax_m, bbMin_m, begin(), end(), getCorners(), polarBBMax_m, and polarBBMin_m.

Referenced by SectorMagneticFieldMap::setInterpolator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSymmetry()

void SectorMagneticFieldMap::setSymmetry ( std::string name)

Set the field map symmetry

Parameters
namefield map symmetry, either "None" or "Dipole"

Definition at line 149 of file SectorMagneticFieldMap.cpp.

References StringToSymmetry(), and symmetry_m.

Referenced by SectorMagneticFieldMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StringToSymmetry()

SectorMagneticFieldMap::symmetry SectorMagneticFieldMap::StringToSymmetry ( std::string name)
staticprivate

Definition at line 164 of file SectorMagneticFieldMap.cpp.

References dipole, and none.

Referenced by setSymmetry().

Here is the caller graph for this function:

◆ swap()

void SectorMagneticFieldMap::swap ( )

Does nothing

Definition at line 284 of file SectorMagneticFieldMap.cpp.

◆ SymmetryToString()

std::string SectorMagneticFieldMap::SymmetryToString ( SectorMagneticFieldMap::symmetry sym)
staticprivate

Definition at line 178 of file SectorMagneticFieldMap.cpp.

References dipole, and none.

Referenced by getSymmetry().

Here is the caller graph for this function:

◆ FieldMap

friend class FieldMap
friend

Definition at line 201 of file SectorMagneticFieldMap.h.

References FieldMap.

Referenced by FieldMap.

◆ SectorMagneticFieldMapIO

friend class SectorMagneticFieldMapIO
friend

Definition at line 226 of file SectorMagneticFieldMap.h.

References SectorMagneticFieldMapIO.

Referenced by SectorMagneticFieldMapIO.

Member Data Documentation

◆ _fields

std::map< std::string, SectorMagneticFieldMap * > SectorMagneticFieldMap::_fields
staticprivate

Definition at line 225 of file SectorMagneticFieldMap.h.

Referenced by clearFieldCache(), and SectorMagneticFieldMap().

◆ bbMax_m

std::vector<double> SectorField::bbMax_m
protectedinherited

bounding box maximum as a 3-vector like (x_max, y_max, z_max)

Definition at line 211 of file SectorField.h.

Referenced by getFieldDimensions(), SectorField(), and setPolarBoundingBox().

◆ bbMin_m

std::vector<double> SectorField::bbMin_m
protectedinherited

bounding box minimum as a 3-vector like (x_min, y_min, z_min)

Definition at line 209 of file SectorField.h.

Referenced by getFieldDimensions(), SectorField(), and setPolarBoundingBox().

◆ Filename_m

std::string SectorField::Filename_m
protectedinherited

Keep the filename

Definition at line 217 of file SectorField.h.

Referenced by SectorMagneticFieldMap::getInfo(), and SectorMagneticFieldMap::print().

◆ filename_m

const std::string SectorMagneticFieldMap::filename_m
private

◆ fractionalBBPhiTolerance_m

const double SectorMagneticFieldMap::fractionalBBPhiTolerance_m
staticprivate

Definition at line 224 of file SectorMagneticFieldMap.h.

◆ interpolator_m

interpolation::VectorMap* SectorMagneticFieldMap::interpolator_m
private

◆ phiOffset_m

double SectorMagneticFieldMap::phiOffset_m
private

◆ polarBBMax_m

std::vector<double> SectorField::polarBBMax_m
protectedinherited

bounding box maximum as a 3-vector like (r_max, y_max, phi_max)

Definition at line 215 of file SectorField.h.

Referenced by getFieldDimensions(), getPolarBoundingBoxMax(), isInBoundingBox(), SectorField(), and setPolarBoundingBox().

◆ polarBBMin_m

std::vector<double> SectorField::polarBBMin_m
protectedinherited

bounding box minimum as a 3-vector like (r_min, y_min, phi_min)

Definition at line 213 of file SectorField.h.

Referenced by getFieldDimensions(), getPolarBoundingBoxMin(), isInBoundingBox(), SectorField(), and setPolarBoundingBox().

◆ poly_order_m

int SectorMagneticFieldMap::poly_order_m
private

Definition at line 221 of file SectorMagneticFieldMap.h.

Referenced by readMap(), and SectorMagneticFieldMap().

◆ smoothing_order_m

int SectorMagneticFieldMap::smoothing_order_m
private

Definition at line 222 of file SectorMagneticFieldMap.h.

Referenced by readMap(), and SectorMagneticFieldMap().

◆ symmetry_m

symmetry SectorMagneticFieldMap::symmetry_m
private

◆ units_m

std::vector<double> SectorMagneticFieldMap::units_m
private

The documentation for this class was generated from the following files: