49 using namespace interpolation;
65 :
SectorField(file_name), interpolator_m(nullptr), symmetry_m(dipole),
66 units_m(6, 1.), filename_m(file_name), phiOffset_m(0.),
67 poly_order_m(polynomial_order), smoothing_order_m(smoothing_order) {
84 "SectorMagneticFieldMap::SectorMagneticFieldMap",
85 "Attempt to construct different SectorFieldMaps with same "+
86 std::string(
"file but different settings")
104 setInterpolator(interpolator);
123 "SectorMagneticFieldMap::setInterpolator",
124 "Attempt to load interpolator with PointDimension != 3")
128 "SectorMagneticFieldMap::setInterpolator",
129 "Attempt to load interpolator with ValueDimension != 3"
134 "SectorMagneticFieldMap::setInterpolator",
135 "Attempt to load interpolator with grid not ThreeDGrid"
169 if (sym ==
"Dipole") {
173 "SectorMagneticFieldMap::StringToSymmetry",
174 "Didn't recognise symmetry type "+sym
187 "SectorMagneticFieldMap::SymmetryToString",
188 "Didn't recognise symmetry type " + std::to_string(sym)
215 double R_temp[3] = {R_c(0)+radius, R_c(1), R_c(2)};
216 double B_temp[3] = {0., 0., 0.};
218 bool mirror = R_temp[1] < midplane;
220 R_temp[1] = midplane + (midplane - R_temp[1]);
244 R_temp[1] = 2*ymin-R_temp[1];
255 _fields = std::map<std::string, SectorMagneticFieldMap*>();
261 (*msg) <<
Filename_m <<
" (3D Sector Magnetostatic);\n"
262 <<
" zini= " << bbmin[1] <<
" mm; zfinal= " << bbmax[1] <<
" mm;\n"
263 <<
" phiini= " << bbmin[2] <<
" rad; phifinal= " << bbmax[2] <<
" rad;\n"
264 <<
" rini= " << bbmin[0] <<
" mm; rfinal= " << bbmax[0] <<
" mm;"
271 out <<
Filename_m <<
" (3D Sector Magnetostatic);\n"
272 <<
" zini= " << bbmin[1] <<
" m; zfinal= " << bbmax[1] <<
" mm;\n"
273 <<
" phiini= " << bbmin[2] <<
" rad; phifinal= " << bbmax[2] <<
" rad;\n"
274 <<
" rini= " << bbmin[0] <<
" m; rfinal= " << bbmax[0] <<
" mm;\n"
280 throw(
LogicalError(
"SectorMagneticFieldMap::getFieldDerivative",
281 "Field map derivatives not implemented"));
296 std::string file_name,
297 std::vector<double>
units,
299 int polynomial_order,
300 int smoothing_order) {
302 *
gmsg <<
"* Opening sector field map " << file_name
303 <<
" fit order " << polynomial_order
304 <<
" smoothing order " << smoothing_order <<
endl;
306 std::vector< std::vector<double> > field_points =
readLines
311 if (polynomial_order == 1 && smoothing_order == 1) {
325 "SectorMagneticFieldMap::IO::ReadMap",
326 "Failed to read file "+file_name+
" with "+(&exc)->what()
333 std::vector< std::vector<double> > field_points,
336 int polynomial_order,
337 int smoothing_order) {
341 "SectorMagneticFieldMap::IO::getInterpolatorPolyPatch",
342 "Failed to recognise symmetry type"
345 std::vector< std::vector<double> > data(field_points.size(),
346 std::vector<double>(3));
347 for (
size_t i = 0; i < field_points.size(); ++i) {
348 data[i][0] = field_points[i][3];
349 data[i][1] = field_points[i][4];
350 data[i][2] = field_points[i][5];
354 *
gmsg <<
"Calculating polynomials..." <<
endl;
355 PPSolveFactory solver(grid, data, polynomial_order, smoothing_order);
366 std::string(
"field points during read ")+
367 std::string(
"operation; this could mean that the field ")+
368 std::string(
"map was not complete, or that OPAL could ")+
369 std::string(
"not calculate regular grid spacings properly. ")+
370 std::string(
"Check that the field map is on a cylindrical ")+
371 std::string(
"grid written in Cartesian coordinates and the ")+
372 std::string(
"grid points are written with enough precision (")+
373 std::string(
"check the grid size information above).");
376 (
const std::vector< std::vector<double> > field_points,
380 double *** Bx, *** By, *** Bz;
382 Bx =
new double**[grid->
xSize()];
383 By =
new double**[grid->
xSize()];
384 Bz =
new double**[grid->
xSize()];
385 for (
int i = 0; i < grid->
xSize(); ++i) {
386 Bx[i] =
new double*[grid->
ySize()];
387 By[i] =
new double*[grid->
ySize()];
388 Bz[i] =
new double*[grid->
ySize()];
389 for (
int j = 0; j < grid->
ySize(); ++j) {
390 Bx[i][j] =
new double[grid->
zSize()];
391 By[i][j] =
new double[grid->
zSize()];
392 Bz[i][j] =
new double[grid->
zSize()];
393 for (
int k = 0; k < grid->
zSize(); ++k) {
394 if (index >=
int(field_points.size())) {
397 "SectorMagneticFieldMap::IO::getInterpolator",
398 "Ran out of "+errMsg1)
401 Bx[i][j][k] = field_points[index][3];
402 By[i][j][k] = field_points[index][4];
403 Bz[i][j][k] = field_points[index][5];
408 if (index !=
int(field_points.size())) {
410 "SectorMagneticFieldMap::IO::getInterpolator",
416 return interpolatorMap;
420 std::vector<double> field_item2) {
421 const int* order = sortOrder_m;
422 if (
std::abs(field_item1[order[0]] - field_item2[order[0]]) > floatTolerance_m) {
423 return field_item1[order[0]] < field_item2[order[0]];
425 if (
std::abs(field_item1[order[1]] - field_item2[order[1]]) > floatTolerance_m) {
426 return field_item1[order[1]] < field_item2[order[1]];
428 return field_item1[order[2]] < field_item2[order[2]];
432 (std::string file_name, std::vector<double>
units) {
433 std::vector< std::vector<double> > field_points;
435 if (units.size() != 6) {
437 "SectorMagneticFieldMap::IO::ReadLines",
438 "Units should be of length 6"
442 std::ifstream fin(file_name.c_str());
443 if (!fin || !fin.is_open()) {
445 "SectorMagneticFieldMap::IO::ReadLines",
446 "Failed to open file "+file_name
450 *
gmsg <<
"* Opened "+file_name <<
endl;
451 for (
size_t i = 0; i < 8; ++i) {
452 std::getline(fin, line);
457 std::vector<double> field(6);
458 fin >> field[0] >> field[1] >> field[2] >> field[3] >> field[4]
461 for (
size_t i = 0; i < 6; ++i) {
462 field[i] *= units[i];
464 field_points.push_back(field);
468 *
gmsg <<
"* Read " << line_number <<
" lines" <<
endl;
471 for (
size_t i = 0; i < field_points.size(); ++i) {
476 std::sort(field_points.begin(), field_points.end(),
482 in2 = in2*(1+floatTolerance_m)+floatTolerance_m;
487 (
const std::vector< std::vector<double> > field_points,
489 std::vector<double> r_grid(1, field_points[0][0]);
490 std::vector<double> y_grid(1, field_points[0][1]);
491 std::vector<double> phi_grid(1, field_points[0][2]);
492 for (
size_t i = 0; i < field_points.size(); ++i) {
493 if (floatGreaterEqual(field_points[i][0], r_grid.back())) {
494 r_grid.push_back(field_points[i][0]);
496 if (floatGreaterEqual(field_points[i][1], y_grid.back())) {
497 y_grid.push_back(field_points[i][1]);
499 if (floatGreaterEqual(field_points[i][2], phi_grid.back())) {
500 phi_grid.push_back(field_points[i][2]);
505 *
gmsg <<
"* Grid size (r, y, phi) = ("
506 << r_grid.size() <<
", " << y_grid.size() <<
", " << phi_grid.size()
508 *
gmsg <<
"* Grid min (r [mm], y [mm], phi [rad]) = ("
509 << r_grid[0] <<
", " << y_grid[0] <<
", " << phi_grid[0]
511 *
gmsg <<
"* Grid max (r [mm], y [mm], phi [rad]) = ("
512 << r_grid.back() <<
", " << y_grid.back() <<
", " << phi_grid.back()
virtual unsigned int getValueDimension() const =0
void setInterpolator(interpolation::VectorMap *interpolator)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
static const std::string errMsg1
bool getFieldstrength(const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const
std::vector< double > units_m
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
SectorMagneticFieldMap(std::string file_name, std::string symmetry, double length_units, double field_units, int polynomial_order, int smoothing_order)
double getDeltaPhi() const
bool applySymmetry(double *R_temp) const
static void clearFieldCache()
static interpolation::VectorMap * getInterpolator(const std::vector< std::vector< double > > field_points, interpolation::ThreeDGrid *grid, SectorMagneticFieldMap::symmetry sym)
void setConstantSpacing(bool spacing)
void setSymmetry(std::string name)
virtual std::vector< double > getPolarBoundingBoxMax() const
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 bool comparator(std::vector< double > field_item1, std::vector< double > field_item2)
Inform & endl(Inform &inf)
static interpolation::ThreeDGrid * generateGrid(const std::vector< std::vector< double > > field_points, SectorMagneticFieldMap::symmetry sym)
virtual void function(const double *point, double *value) const =0
interpolation::VectorMap * interpolator_m
std::string::iterator iterator
bool isInBoundingBox(const double R_p[]) const
static const double fractionalBBPhiTolerance_m
bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
static const int sortOrder_m[3]
PPSolveFactory solves the system of linear equations to interpolate from a grid of points using highe...
static const double floatTolerance_m
virtual std::vector< double > getPolarBoundingBoxMin() const
static std::vector< std::vector< double > > readLines(std::string file_name, std::vector< double > units)
PolynomialPatch * solve()
static std::string SymmetryToString(symmetry sym)
const std::string filename_m
~SectorMagneticFieldMap()
handles field map grids with sector geometry
void setPolarBoundingBox(double bbMinR, double bbMinY, double bbMinPhi, double bbMaxR, double bbMaxY, double bbMaxPhi, double bbTolR, double bbTolY, double bbTolPhi)
Tps< T > cos(const Tps< T > &x)
Cosine.
virtual Mesh * getMesh() const
void print(std::ostream &out)
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special exception
static symmetry StringToSymmetry(std::string name)
interpolation::VectorMap * getInterpolator()
static void convertToPolar(double *position)
Patches together many SquarePolynomialVectors to make a multidimensional polynomial spline...
std::string getSymmetry() const
virtual unsigned int getPointDimension() const =0
constexpr double e
The value of .
Tps< T > sin(const Tps< T > &x)
Sine.
static std::map< std::string, SectorMagneticFieldMap * > _fields
static bool floatGreaterEqual(double in1, double in2)
void getInfo(Inform *msg)
static interpolation::VectorMap * readMap(std::string file_name, std::vector< double > units, SectorMagneticFieldMap::symmetry sym, int poly_order, int smoothing_order)