OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SectorMagneticFieldMap.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Chris Rogers
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef _CLASSIC_FIELDS_SECTORMAGNETICFIELDMAP_HH_
29#define _CLASSIC_FIELDS_SECTORMAGNETICFIELDMAP_HH_
30
31#include <string>
32#include <vector>
33#include <map>
34#include <iostream>
35
36#include "Fields/SectorField.h"
37
38namespace interpolation {
39 class VectorMap;
40 class ThreeDGrid;
41}
42
76 public:
87 SectorMagneticFieldMap(std::string file_name,
88 std::string symmetry,
89 double length_units,
90 double field_units,
91 int polynomial_order,
92 int smoothing_order);
93
96
99
117 /* bool getFieldstrengthPolar */
118 /* (const Vector_t &R_p, Vector_t &E_p, Vector_t &B_p) const; */
119
132 (const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const;
133
139
145 void setInterpolator(interpolation::VectorMap* interpolator);
146
147
149 std::string getFieldMapFileName() const {return filename_m;}
150
155 std::string getSymmetry() const;
156
161 void setSymmetry(std::string name);
162
165 static void clearFieldCache();
166
168 bool getFieldDerivative(const Vector_t &R, Vector_t &E,
169 Vector_t &B, const DiffDirection &dir) const;
170
172 void swap();
173
175 void getInfo(Inform* msg);
176
178 void print(std::ostream& out);
179
181 void readMap();
182
184 void freeMap();
185
187 double getFrequency() const {return 0;}
188
190 void setFrequency(double) {}
191
193 double getPhiOffset() const {return phiOffset_m;}
194
196 void setPhiOffset(double dphi) {phiOffset_m = dphi;}
197
199 double getDeltaPhi() const;
200
201 friend class FieldMap;
202
203 private:
205
209 bool applySymmetry(double* R_temp) const;
210
211 static symmetry StringToSymmetry(std::string name);
212 static std::string SymmetryToString(symmetry sym);
213
214 void Rotate(double* value, double angle);
215
218 std::vector<double> units_m;
219 const std::string filename_m;
223
224 static const double fractionalBBPhiTolerance_m;
225 static std::map<std::string, SectorMagneticFieldMap*> _fields;
227
228 // disabled - dont use
230
231 class IO;
232};
233
234
243 public:
255 static interpolation::VectorMap* readMap(std::string file_name,
256 std::vector<double> units,
258 int poly_order,
259 int smoothing_order);
260
261 private:
262 static const double floatTolerance_m;
263 static const int sortOrder_m[3];
264
265 // read and sort the lines of the map file
266 static std::vector< std::vector<double> > readLines
267 (std::string file_name, std::vector<double> units);
268
269 // generate a grid based on the input map file
271 const std::vector< std::vector<double> > field_points,
273
274 // get the interpolator based on field points and grid information
276 const std::vector< std::vector<double> > field_points,
279
281 const std::vector< std::vector<double> > field_points,
284 int poly_order,
285 int smoothing_order);
286
287 // Compare two floats are same within tolerance
288 static bool floatGreaterEqual(double in1, double in2);
289
290 // comparator for sorting field_points by r, y, phi. Sort order is given by
291 // sort_order variable
292 static bool comparator
293 (std::vector<double> field_item1, std::vector<double> field_item2);
294
295 // private constructor i.e. disabled
296 IO();
297 // private copy constructor i.e. disabled
298 IO(const IO& map);
299
300 // private destructor i.e. disabled
302
303 static const std::string errMsg1;
304};
305
306#endif
DiffDirection
Definition: Fieldmap.h:54
const std::string name
handles field map grids with sector geometry
bool getFieldstrength(const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const
bool applySymmetry(double *R_temp) const
interpolation::VectorMap * interpolator_m
SectorMagneticFieldMap & operator=(const SectorMagneticFieldMap &field)
std::vector< double > units_m
void setInterpolator(interpolation::VectorMap *interpolator)
static std::string SymmetryToString(symmetry sym)
SectorMagneticFieldMap(std::string file_name, std::string symmetry, double length_units, double field_units, int polynomial_order, int smoothing_order)
bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
static symmetry StringToSymmetry(std::string name)
void setSymmetry(std::string name)
interpolation::VectorMap * getInterpolator()
static const double fractionalBBPhiTolerance_m
void Rotate(double *value, double angle)
std::string getFieldMapFileName() const
void print(std::ostream &out)
static std::map< std::string, SectorMagneticFieldMap * > _fields
handles reading sector field maps
static const std::string errMsg1
static interpolation::ThreeDGrid * generateGrid(const std::vector< std::vector< double > > field_points, SectorMagneticFieldMap::symmetry sym)
static std::vector< std::vector< double > > readLines(std::string file_name, std::vector< double > units)
static bool comparator(std::vector< double > field_item1, std::vector< double > field_item2)
static const double floatTolerance_m
static interpolation::VectorMap * getInterpolatorPolyPatch(const std::vector< std::vector< double > > field_points, interpolation::ThreeDGrid *grid, SectorMagneticFieldMap::symmetry sym, int poly_order, int smoothing_order)
static interpolation::VectorMap * getInterpolator(const std::vector< std::vector< double > > field_points, interpolation::ThreeDGrid *grid, SectorMagneticFieldMap::symmetry sym)
static bool floatGreaterEqual(double in1, double in2)
static interpolation::VectorMap * readMap(std::string file_name, std::vector< double > units, SectorMagneticFieldMap::symmetry sym, int poly_order, int smoothing_order)
Definition: Inform.h:42