OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Fieldmap.cpp
Go to the documentation of this file.
1 #include "Fields/Fieldmap.h"
2 #include "Fields/FM3DDynamic.h"
3 #include "Fields/FM3DH5Block.h"
8 #include "Fields/FM2DDynamic.h"
11 #include "Fields/FM1DDynamic.h"
13 #include "Fields/Astra1DDynamic.h"
23 #include "Fields/FM1DProfile1.h"
24 #include "Fields/FM1DProfile2.h"
25 #include "Fields/FMDummy.h"
27 #include "Utilities/Options.h"
29 #include "Physics/Physics.h"
30 
31 #include "H5hut.h"
32 
33 #include <boost/filesystem.hpp>
34 
35 #include <iostream>
36 #include <fstream>
37 #include <ios>
38 
39 #include <assert.h>
40 
41 namespace fs = boost::filesystem;
42 
43 #define REGISTER_PARSE_TYPE(X) template <> struct Fieldmap::TypeParseTraits<X> \
44  { static const char* name; } ; const char* Fieldmap::TypeParseTraits<X>::name = #X
45 
46 Fieldmap *Fieldmap::getFieldmap(std::string Filename, bool fast) {
48  if(position != FieldmapDictionary.end()) {
49  (*position).second.RefCounter++;
50  return (*position).second.Map;
51  } else {
52  MapType type;
54  type = readHeader(Filename);
55  switch(type) {
56  case T1DDynamic:
57  if(fast) {
58  position = FieldmapDictionary.insert(
59  std::make_pair(
60  Filename,
62  T1DDynamic, new FM1DDynamic_fast(Filename))));
63  } else {
64  position = FieldmapDictionary.insert(
65  std::make_pair(
66  Filename,
68  T1DDynamic, new FM1DDynamic(Filename))));
69  }
70  return (*position.first).second.Map;
71  break;
72 
73  case TAstraDynamic:
74  if(fast) {
75  position = FieldmapDictionary.insert(
76  std::make_pair(
77  Filename,
79  TAstraDynamic, new Astra1DDynamic_fast(Filename))));
80  } else {
81  position = FieldmapDictionary.insert(
82  std::make_pair(
83  Filename,
85  TAstraDynamic, new Astra1DDynamic(Filename))));
86  }
87  return (*position.first).second.Map;
88  break;
89 
90  case T1DElectroStatic:
91  if(fast) {
92  position = FieldmapDictionary.insert(
93  std::make_pair(
94  Filename,
96  T1DElectroStatic, new FM1DElectroStatic_fast(Filename))));
97  } else {
98  position = FieldmapDictionary.insert(
99  std::make_pair(
100  Filename,
102  T1DElectroStatic, new FM1DElectroStatic(Filename))));
103  }
104  return (*position.first).second.Map;
105  break;
106 
107  case TAstraElectroStatic:
108  if(fast) {
109  position = FieldmapDictionary.insert(
110  std::make_pair(
111  Filename,
114  } else {
115  position = FieldmapDictionary.insert(
116  std::make_pair(
117  Filename,
119  TAstraElectroStatic, new Astra1DElectroStatic(Filename))));
120  }
121  return (*position.first).second.Map;
122  break;
123 
124  case T1DMagnetoStatic:
125  if(fast) {
126  position = FieldmapDictionary.insert(
127  std::make_pair(
128  Filename,
130  T1DMagnetoStatic, new FM1DMagnetoStatic_fast(Filename))));
131  } else {
132  position = FieldmapDictionary.insert(
133  std::make_pair(
134  Filename,
136  T1DMagnetoStatic, new FM1DMagnetoStatic(Filename))));
137  }
138  return (*position.first).second.Map;
139  break;
140 
141  case TAstraMagnetoStatic:
142  if(fast) {
143  position = FieldmapDictionary.insert(
144  std::make_pair(
145  Filename,
148  } else {
149  position = FieldmapDictionary.insert(
150  std::make_pair(
151  Filename,
153  TAstraMagnetoStatic, new Astra1DMagnetoStatic(Filename))));
154  }
155  return (*position.first).second.Map;
156  break;
157 
158  case T1DProfile1:
159  position = FieldmapDictionary.insert(
160  std::make_pair(
161  Filename,
162  FieldmapDescription(T1DProfile1, new FM1DProfile1(Filename))));
163  return (*position.first).second.Map;
164  break;
165 
166  case T1DProfile2:
167  position = FieldmapDictionary.insert(
168  std::make_pair(
169  Filename,
171  T1DProfile2, new FM1DProfile2(Filename))));
172  return (*position.first).second.Map;
173  break;
174 
175  case T2DDynamic:
176  position = FieldmapDictionary.insert(
177  std::make_pair(
178  Filename,
180  T2DDynamic, new FM2DDynamic(Filename))));
181  return (*position.first).second.Map;
182  break;
183 
184  case T2DElectroStatic:
185  position = FieldmapDictionary.insert(
186  std::make_pair(
187  Filename,
189  T2DElectroStatic, new FM2DElectroStatic(Filename))));
190  return (*position.first).second.Map;
191  break;
192 
193  case T2DMagnetoStatic:
194  position = FieldmapDictionary.insert(
195  std::make_pair(
196  Filename,
198  T2DMagnetoStatic, new FM2DMagnetoStatic(Filename))));
199  return (*position.first).second.Map;
200  break;
201 
202  case T3DDynamic:
203  position = FieldmapDictionary.insert(
204  std::make_pair(
205  Filename,
207  T3DDynamic, new FM3DDynamic(Filename))));
208  return (*position.first).second.Map;
209  break;
210 
212  position = FieldmapDictionary.insert(
213  std::make_pair(
214  Filename, FieldmapDescription(
216  return (*position.first).second.Map;
217  break;
218 
219  case T3DMagnetoStatic:
220  position = FieldmapDictionary.insert(
221  std::make_pair(
222  Filename, FieldmapDescription(
223  T3DMagnetoStatic, new FM3DMagnetoStatic(Filename))));
224  return (*position.first).second.Map;
225  break;
226 
228  position = FieldmapDictionary.insert(
229  std::make_pair(
230  Filename, FieldmapDescription(
232  return (*position.first).second.Map;
233  break;
234 
235  case T3DDynamicH5Block:
236  if(fast) {
237  position = FieldmapDictionary.insert(
238  std::make_pair(
239  Filename,
241  T3DDynamic, new FM3DH5Block_nonscale(Filename))));
242  } else {
243  position = FieldmapDictionary.insert(
244  std::make_pair(
245  Filename,
247  T3DDynamic, new FM3DH5Block(Filename))));
248  }
249  return (*position.first).second.Map;
250  break;
251 
252  default:
253  throw GeneralClassicException("Fieldmap::getFieldmap()",
254  "Couldn't determine type of fieldmap in file \"" + Filename + "\"");
255  }
256  }
257 }
258 
259 std::vector<std::string> Fieldmap::getListFieldmapNames() {
260  std::vector<std::string> name_list;
261  for(std::map<std::string, FieldmapDescription>::const_iterator it = FieldmapDictionary.begin(); it != FieldmapDictionary.end(); ++ it) {
262  name_list.push_back((*it).first);
263  }
264  return name_list;
265 }
266 
267 void Fieldmap::deleteFieldmap(std::string Filename) {
268  freeMap(Filename);
269 }
270 
273  for (;it != FieldmapDictionary.end(); ++ it) {
274  delete it->second.Map;
275  it->second.Map = NULL;
276  }
277  FieldmapDictionary.clear();
278 }
279 
280 MapType Fieldmap::readHeader(std::string Filename) {
281  char magicnumber[5] = " ";
282  std::string buffer;
283  int lines_read_m = 0;
284 
285  // Check for default map(s).
286  if(Filename == "1DPROFILE1-DEFAULT")
287  return T1DProfile1;
288 
289  if (!fs::exists(Filename))
290  throw GeneralClassicException("Fieldmap::readHeader()",
291  "File \"" + Filename + "\" doesn't exist");
292 
293  std::ifstream File(Filename.c_str());
294  if(!File.good()) {
295  std::cerr << "could not open file " << Filename << std::endl;
296  return UNKNOWN;
297  }
298 
299  getLine(File, lines_read_m, buffer);
300  std::istringstream interpreter(buffer, std::istringstream::in);
301 
302  interpreter.read(magicnumber, 4);
303 
304  if(strcmp(magicnumber, "3DDy") == 0)
305  return T3DDynamic;
306 
307  if(strcmp(magicnumber, "3DMa") == 0) {
308  char tmpString[21] = " ";
309  interpreter.read(tmpString, 20);
310 
311  if(strcmp(tmpString, "gnetoStatic_Extended") == 0)
313  else
314  return T3DMagnetoStatic;
315  }
316 
317  if(strcmp(magicnumber, "3DEl") == 0)
318  return T3DElectroStatic;
319 
320  if(strcmp(magicnumber, "2DDy") == 0) {
321  // char tmpString[14] = " ";
322  // interpreter.read(tmpString, 13);
323  return T2DDynamic;
324  }
325 
326  if(strcmp(magicnumber, "2DMa") == 0) {
327  // char tmpString[20] = " ";
328  // interpreter.read(tmpString, 19);
329  return T2DMagnetoStatic;
330  }
331 
332  if(strcmp(magicnumber, "2DEl") == 0) {
333  // char tmpString[20] = " ";
334  // interpreter.read(tmpString, 19);
335  return T2DElectroStatic;
336  }
337 
338  if(strcmp(magicnumber, "1DDy") == 0)
339  return T1DDynamic;
340 
341  if(strcmp(magicnumber, "1DMa") == 0)
342  return T1DMagnetoStatic;
343 
344  if(strcmp(magicnumber, "1DPr") == 0) {
345  // char tmpString[7] = " ";
346  // interpreter.read(tmpString, 6);
347  // if(strcmp(tmpString, "ofile1") == 0)
348  return T1DProfile1;
349  // if(strcmp(tmpString, "ofile2") == 0)
350  // return T1DProfile2;
351  }
352 
353  if(strcmp(magicnumber, "1DEl") == 0)
354  return T1DElectroStatic;
355 
356  if(strcmp(magicnumber, "\211HDF") == 0) {
357  h5_err_t h5err = 0;
358 #if defined (NDEBUG)
359  // mark variable as unused
360  (void)h5err;
361 #endif
362  char name[20];
363  h5_size_t len_name = sizeof(name);
364  h5_prop_t props = H5CreateFileProp ();
365  MPI_Comm comm = Ippl::getComm();
366  h5err = H5SetPropFileMPIOCollective (props, &comm);
367  assert (h5err != H5_ERR);
368  h5_file_t file = H5OpenFile (Filename.c_str(), H5_O_RDONLY, props);
369  assert (file != (h5_file_t)H5_ERR);
370  H5CloseProp (props);
371 
372  h5err = H5SetStep(file, 0);
373  assert (h5err != H5_ERR);
374 
375  h5_int64_t num_fields = H5BlockGetNumFields(file);
376  assert (num_fields != H5_ERR);
377  MapType maptype = UNKNOWN;
378 
379  for(h5_ssize_t i = 0; i < num_fields; ++ i) {
380  h5err = H5BlockGetFieldInfo(
381  file, (h5_size_t)i, name, len_name, NULL, NULL, NULL, NULL);
382  assert (h5err != H5_ERR);
383  // using field name "Bfield" and "Hfield" to distinguish the type
384  if(strcmp(name, "Bfield") == 0) {
385  maptype = T3DMagnetoStaticH5Block;
386  break;
387  } else if(strcmp(name, "Hfield") == 0) {
388  maptype = T3DDynamicH5Block;
389  break;
390  }
391  }
392  h5err = H5CloseFile(file);
393  assert (h5err != H5_ERR);
394  if(maptype != UNKNOWN)
395  return maptype;
396  }
397 
398  if(strcmp(magicnumber, "Astr") == 0) {
399  char tmpString[3] = " ";
400  interpreter.read(tmpString, 2);
401  if(strcmp(tmpString, "aE") == 0) {
402  return TAstraElectroStatic;
403  }
404  if(strcmp(tmpString, "aM") == 0) {
405  return TAstraMagnetoStatic;
406  }
407  if(strcmp(tmpString, "aD") == 0) {
408  return TAstraDynamic;
409  }
410  }
411 
412 
413  return UNKNOWN;
414 }
415 
416 void Fieldmap::readMap(std::string Filename) {
418  if(position != FieldmapDictionary.end())
419  if(!(*position).second.read) {
420  (*position).second.Map->readMap();
421  (*position).second.read = true;
422  }
423 }
424 
425 void Fieldmap::freeMap(std::string Filename) {
427  /*
428  FIXME: find( ) make problem, crashes
429  */
430  if(position != FieldmapDictionary.end()) {
431  if((*position).second.RefCounter > 0) {
432  (*position).second.RefCounter--;
433  }
434 
435  if ((*position).second.RefCounter == 0) {
436  delete (*position).second.Map;
437  (*position).second.Map = NULL;
438  FieldmapDictionary.erase(position);
439  }
440  }
441 }
442 
443 void Fieldmap::checkMap(unsigned int accuracy,
444  std::pair<double, double> fieldDimensions,
445  double deltaZ,
446  const std::vector<double> &fourierCoefficients,
447  gsl_spline *splineCoefficients,
448  gsl_interp_accel *splineAccelerator) {
449  double length = fieldDimensions.second - fieldDimensions.first;
450  unsigned int sizeSampling = std::floor(length / deltaZ + 0.5);
451  std::vector<double> zSampling(sizeSampling);
452  zSampling[0] = fieldDimensions.first;
453  for (unsigned int i = 1; i < sizeSampling; ++ i) {
454  zSampling[i] = zSampling[i-1] + deltaZ;
455  }
456  checkMap(accuracy, length, zSampling, fourierCoefficients, splineCoefficients, splineAccelerator);
457 }
458 
459 void Fieldmap::checkMap(unsigned int accuracy,
460  double length,
461  const std::vector<double> &zSampling,
462  const std::vector<double> &fourierCoefficients,
463  gsl_spline *splineCoefficients,
464  gsl_interp_accel *splineAccelerator) {
465  double error = 0.0;
466  double maxDiff = 0.0;
467  double ezMax = 0.0;
468  double ezSquare = 0.0;
469  size_t lastDot = Filename_m.find_last_of(".");
470  size_t lastSlash = Filename_m.find_last_of("/");
471  lastSlash = (lastSlash == std::string::npos)? 0: lastSlash + 1;
472 
473  auto opal = OpalData::getInstance();
474  std::ofstream out;
475  if (Ippl::myNode() == 0 && !opal->isOptimizerRun()) {
476  out.open("data/" + Filename_m.substr(lastSlash, lastDot) + ".check");
477  out << "# z original reproduced\n";
478  }
479  auto it = zSampling.begin();
480  auto end = zSampling.end();
481  for (; it != end; ++ it) {
482  const double kz = Physics::two_pi * (*it / length + 0.5);
483  double onAxisFieldCheck = fourierCoefficients[0];
484  unsigned int n = 1;
485  for(unsigned int l = 1; l < accuracy; ++l, n += 2) {
486  double coskzl = cos(kz * l);
487  double sinkzl = sin(kz * l);
488 
489  onAxisFieldCheck += (fourierCoefficients[n] * coskzl - fourierCoefficients[n + 1] * sinkzl);
490  }
491  double ez = gsl_spline_eval(splineCoefficients, *it, splineAccelerator);
492  double difference = std::abs(ez - onAxisFieldCheck);
493  maxDiff = difference > maxDiff? difference: maxDiff;
494  ezMax = std::abs(ez) > ezMax? std::abs(ez): ezMax;
495  error += std::pow(difference, 2.0);
496  ezSquare += std::pow(ez, 2.0);
497 
498  if (Ippl::myNode() == 0 && !opal->isOptimizerRun()) {
499  out << std::setw(16) << std::setprecision(8) << *it
500  << std::setw(16) << std::setprecision(8) << ez
501  << std::setw(16) << std::setprecision(8) << onAxisFieldCheck
502  << std::endl;
503  }
504  }
505  out.close();
506 
507  if (sqrt(error / ezSquare) > 1e-1 || maxDiff > 1e-1 * ezMax) {
508  lowResolutionWarning(sqrt(error / ezSquare), maxDiff / ezMax);
509 
510  throw GeneralClassicException("Astra2DDynamic_fast::readMap()",
511  "Field map can't be reproduced properly with the given number of fourier components");
512  }
513  if (sqrt(error / ezSquare) > 1e-2 || maxDiff > 1e-2 * ezMax) {
514  lowResolutionWarning(sqrt(error / ezSquare), maxDiff / ezMax);
515  }
516 }
517 
518 void Fieldmap::setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
519 {};
520 
521 void Fieldmap::setFieldLength(const double &)
522 {};
523 
524 void Fieldmap::getLine(std::ifstream &in, int &lines_read, std::string &buffer) {
525  size_t firstof = 0;
526  size_t lastof;
527  size_t comment;
528 
529  do {
530  ++ lines_read;
531  in.getline(buffer_m, READ_BUFFER_LENGTH);
532 
533  buffer = std::string(buffer_m);
534 
535  comment = buffer.find("#");
536  buffer = buffer.substr(0, comment);
537 
538  lastof = buffer.find_last_of(alpha_numeric);
539  firstof = buffer.find_first_of(alpha_numeric);
540  } while(!in.eof() && lastof == std::string::npos);
541 
542  if(firstof != std::string::npos) {
543  buffer = buffer.substr(firstof, lastof - firstof + 1);
544  }
545 }
546 
547 bool Fieldmap::interpreteEOF(std::ifstream &in) {
548  while(!in.eof()) {
549  ++lines_read_m;
550  in.getline(buffer_m, READ_BUFFER_LENGTH);
551  std::string buffer(buffer_m);
552  size_t comment = buffer.find_first_of("#");
553  buffer = buffer.substr(0, comment);
554  size_t lasto = buffer.find_first_of(alpha_numeric);
555  if(lasto != std::string::npos) {
557  return false;
558  }
559  }
560  return true;
561 }
562 
563 void Fieldmap::interpreteWarning(const std::string &error_msg,
564  const std::string &expecting,
565  const std::string &found) {
566  std::stringstream errormsg;
567  errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
568  << "expecting: '" << expecting << "' on line " << lines_read_m << ",\n"
569  << "found instead: '" << found << "'.";
570  // std::string errormsg_str = typeset_msg(errormsg.str(), "error");
571  throw GeneralClassicException("Fieldmap::interpretWarning()",
572  errormsg.str());
573 }
574 
575 void Fieldmap::interpreteWarning(const std::ios_base::iostate &state,
576  const bool &read_all,
577  const std::string &expecting,
578  const std::string &found) {
579  std::string error_msg;
580  if(!read_all) {
581  error_msg = std::string("Didn't find enough values!");
582  } else if(state & std::ios_base::eofbit) {
583  error_msg = std::string("Found more values than expected!");
584  } else if(state & std::ios_base::failbit) {
585  error_msg = std::string("Found wrong type of values!");
586  }
587  interpreteWarning(error_msg, expecting, found);
588 }
589 
591  std::stringstream errormsg;
592  errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
593  << "There are only " << lines_read_m - 1 << " lines in the file, expecting more.\n"
594  << "Please check the section about field maps in the user manual.";
595  // std::string errormsg_str = typeset_msg(errormsg.str(), "error");
596  throw GeneralClassicException("Fieldmap::missingValuesWarning()",
597  errormsg.str());
598 }
599 
601  std::stringstream errormsg;
602  errormsg << "THERE SEEMS TO BE SOMETHING WRONG WITH YOUR FIELD MAP '" << Filename_m << "'.\n"
603  << "There are too many lines in the file, expecting only " << lines_read_m << " lines.\n"
604  << "Please check the section about field maps in the user manual.";
605  // std::string errormsg_str = typeset_msg(errormsg.str(), "error");
606  throw GeneralClassicException("Fieldmap::exceedingValuesWarning()",
607  errormsg.str());
608 }
609 
611  std::stringstream errormsg;
612  errormsg << "DISABLING FIELD MAP '" + Filename_m + "' DUE TO PARSING ERRORS." ;
613  // std::string errormsg_str = typeset_msg(errormsg.str(), "error");
614  throw GeneralClassicException("Fieldmap::disableFieldmapsWarning()",
615  errormsg.str());
616 }
617 
619  std::stringstream errormsg;
620  errormsg << "DISABLING FIELD MAP '" << Filename_m << "' SINCE FILE COULDN'T BE FOUND!";
621  // std::string errormsg_str = typeset_msg(errormsg.str(), "error");
622  throw GeneralClassicException("Fieldmap::noFieldmapsWarning()",
623  errormsg.str());
624 }
625 
626 void Fieldmap::lowResolutionWarning(double squareError, double maxError) {
627  std::stringstream errormsg;
628  errormsg << "IT SEEMS THAT YOU USE TOO FEW FOURIER COMPONENTS TO SUFFICIENTLY WELL\n"
629  << "RESOLVE THE FIELD MAP '" << Filename_m << "'.\n"
630  << "PLEASE INCREASE THE NUMBER OF FOURIER COMPONENTS!\n"
631  << "The ratio (e_i - E_i)^2 / E_i^2 is " << std::to_string(squareError) << " and\n"
632  << "the ratio (max_i(|e_i - E_i|) / max_i(|E_i|) is " << std::to_string(maxError) << ".\n"
633  << "Here E_i is the field as in the field map and e_i is the reconstructed field.\n"
634  << "The lower limit for the two ratios is 1e-2\n"
635  << "Have a look into the directory data/ for a reconstruction of the field map.\n";
636  std::string errormsg_str = typeset_msg(errormsg.str(), "warning");
637 
638  ERRORMSG(errormsg_str << "\n" << endl);
639 
640  if(Ippl::myNode() == 0) {
641  std::ofstream omsg("errormsg.txt", std::ios_base::app);
642  omsg << errormsg.str() << std::endl;
643  omsg.close();
644  }
645 }
646 
647 std::string Fieldmap::typeset_msg(const std::string &msg, const std::string &title) {
648  static std::string frame("* ******************************************************************************\n");
649  static unsigned int frame_width = frame.length() - 5;
650  static std::string closure(" *\n");
651 
652  std::string return_string("\n" + frame);
653 
654  int remaining_length = msg.length();
655  unsigned int current_position = 0;
656 
657  unsigned int ii = 0;
658  for(; ii < title.length(); ++ ii) {
659  char c = title[ii];
660  c = toupper(c);
661  return_string.replace(15 + 2 * ii, 1, " ");
662  return_string.replace(16 + 2 * ii, 1, &c, 1);
663  }
664  return_string.replace(15 + 2 * ii, 1, " ");
665 
666  while(remaining_length > 0) {
667  size_t eol = msg.find("\n", current_position);
668  std::string next_to_process;
669  if(eol != std::string::npos) {
670  next_to_process = msg.substr(current_position, eol - current_position);
671  } else {
672  next_to_process = msg.substr(current_position);
673  eol = msg.length();
674  }
675 
676  if(eol - current_position < frame_width) {
677  return_string += "* " + next_to_process + closure.substr(eol - current_position + 2);
678  } else {
679  unsigned int last_space = next_to_process.rfind(" ", frame_width);
680  if(last_space > 0) {
681  if(last_space < frame_width) {
682  return_string += "* " + next_to_process.substr(0, last_space) + closure.substr(last_space + 2);
683  } else {
684  return_string += "* " + next_to_process.substr(0, last_space) + " *\n";
685  }
686  if(next_to_process.length() - last_space + 1 < frame_width) {
687  return_string += "* " + next_to_process.substr(last_space + 1) + closure.substr(next_to_process.length() - last_space + 1);
688  } else {
689  return_string += "* " + next_to_process.substr(last_space + 1) + " *\n";
690  }
691  } else {
692  return_string += "* " + next_to_process + " *\n";
693  }
694  }
695 
696  current_position = eol + 1;
697  remaining_length = msg.length() - current_position;
698  }
699  return_string += frame;
700 
701  return return_string;
702 }
703 
704 void Fieldmap::getOnaxisEz(std::vector<std::pair<double, double> > &onaxis)
705 { }
706 
707 void Fieldmap::get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
708  std::vector<double> &engeCoeffsExit) {
709 
710 }
711 
712 void Fieldmap::get1DProfile1EntranceParam(double &entranceParameter1,
713  double &entranceParameter2,
714  double &entranceParameter3) {
715 
716 }
717 
718 void Fieldmap::get1DProfile1ExitParam(double &exitParameter1,
719  double &exitParameter2,
720  double &exitParameter3) {
721 
722 }
723 
725  return 0.0;
726 }
727 
728 void Fieldmap::setFieldGap(double gap) {
729 
730 }
731 
732 void Fieldmap::write3DField(unsigned int nx,
733  unsigned int ny,
734  unsigned int nz,
735  const std::pair<double, double> &xrange,
736  const std::pair<double, double> &yrange,
737  const std::pair<double, double> &zrange,
738  const std::vector<Vector_t> &ef,
739  const std::vector<Vector_t> &bf) {
740  const size_t numpoints = nx * ny * nz;
741  if (Ippl::myNode() != 0 ||
742  (ef.size() != numpoints && bf.size() != numpoints)) return;
743 
744  size_t extensionStart = Filename_m.find_last_of('.');
745  std::ofstream of;
746  of.open (std::string ("data/" + Filename_m.substr(0,extensionStart) + ".vtk").c_str ());
747  assert (of.is_open ());
748  of.precision (6);
749 
750  const double hx = (xrange.second - xrange.first) / (nx - 1);
751  const double hy = (yrange.second - yrange.first) / (ny - 1);
752  const double hz = (zrange.second - zrange.first) / (nz - 1);
753 
754  of << "# vtk DataFile Version 2.0" << std::endl;
755  of << "generated by 3D fieldmaps" << std::endl;
756  of << "ASCII" << std::endl << std::endl;
757  of << "DATASET RECTILINEAR_GRID" << std::endl;
758  of << "DIMENSIONS " << nx << " " << ny << " " << nz << std::endl;
759 
760  of << "X_COORDINATES " << nx << " float" << std::endl;
761  of << xrange.first;
762  for (unsigned int i = 1; i < nx - 1; ++ i) {
763  of << " " << xrange.first + i * hx;
764  }
765  of << " " << xrange.second << std::endl;
766 
767  of << "Y_COORDINATES " << ny << " float" << std::endl;
768  of << yrange.first;
769  for (unsigned int i = 1; i < ny - 1; ++ i) {
770  of << " " << yrange.first + i * hy;
771  }
772  of << " " << yrange.second << std::endl;
773 
774  of << "Z_COORDINATES " << nz << " float" << std::endl;
775  of << zrange.first;
776  for (unsigned int i = 1; i < nz - 1; ++ i) {
777  of << " " << zrange.first + i * hz;
778  }
779  of << " " << zrange.second << std::endl;
780 
781  of << "POINT_DATA " << numpoints << std::endl;
782 
783  if (ef.size() == numpoints) {
784  of << "VECTORS EField float" << std::endl;
785  // of << "LOOKUP_TABLE default" << std::endl;
786  for (size_t i = 0; i < numpoints; ++ i) {
787  of << ef[i](0) << " " << ef[i](1) << " " << ef[i](2) << std::endl;
788  }
789  // of << std::endl;
790  }
791 
792  if (bf.size() == numpoints) {
793  of << "VECTORS BField float" << std::endl;
794  // of << "LOOKUP_TABLE default" << std::endl;
795  for (size_t i = 0; i < numpoints; ++ i) {
796  of << bf[i](0) << " " << bf[i](1) << " " << bf[i](2) << std::endl;
797  }
798  // of << std::endl;
799  }
800 }
801 
803 REGISTER_PARSE_TYPE(unsigned int);
805 REGISTER_PARSE_TYPE(std::string);
806 
807 std::string Fieldmap::alpha_numeric("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+\211");
808 std::map<std::string, Fieldmap::FieldmapDescription> Fieldmap::FieldmapDictionary = std::map<std::string, Fieldmap::FieldmapDescription>();
virtual void freeMap()=0
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of .
Definition: Physics.h:40
static void clearDictionary()
Definition: Fieldmap.cpp:271
static MapType readHeader(std::string Filename)
Definition: Fieldmap.cpp:280
virtual void readMap()=0
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &onaxis)
Definition: Fieldmap.cpp:704
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
virtual double getFieldGap()
Definition: Fieldmap.cpp:724
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
constexpr double two_pi
The value of .
Definition: Physics.h:34
void disableFieldmapWarning()
Definition: Fieldmap.cpp:610
MapType
Definition: Fieldmap.h:14
static int myNode()
Definition: IpplInfo.cpp:794
FRONT * fs
Definition: hypervolume.cpp:59
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition: Fieldmap.cpp:647
static Fieldmap * getFieldmap(std::string Filename, bool fast=false)
Definition: Fieldmap.cpp:46
void noFieldmapWarning()
Definition: Fieldmap.cpp:618
static void deleteFieldmap(std::string Filename)
Definition: Fieldmap.cpp:267
int lines_read_m
Definition: Fieldmap.h:111
static OpalData * getInstance()
Definition: OpalData.cpp:209
static char buffer_m[256]
Definition: Fieldmap.h:171
void missingValuesWarning()
Definition: Fieldmap.cpp:590
virtual void setFieldGap(double gap)
Definition: Fieldmap.cpp:728
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
static std::map< std::string, FieldmapDescription > FieldmapDictionary
Definition: Fieldmap.h:187
bool interpreteEOF(std::ifstream &in)
Definition: Fieldmap.cpp:547
virtual void setFieldLength(const double &)
Definition: Fieldmap.cpp:521
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
Definition: Fieldmap.cpp:712
static MPI_Comm getComm()
Definition: IpplInfo.h:178
void interpreteWarning(const std::string &error_msg, const std::string &expecting, const std::string &found)
Definition: Fieldmap.cpp:563
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
Definition: Fieldmap.cpp:707
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
static std::vector< std::string > getListFieldmapNames()
Definition: Fieldmap.cpp:259
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
Definition: Fieldmap.cpp:518
static std::string alpha_numeric
Definition: Fieldmap.h:172
#define REGISTER_PARSE_TYPE(X)
Definition: Fieldmap.cpp:43
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
const std::string name
void getLine(std::ifstream &in, std::string &buffer)
Definition: Fieldmap.h:198
std::string Filename_m
Definition: Fieldmap.h:110
void exceedingValuesWarning()
Definition: Fieldmap.cpp:600
std::string::iterator iterator
Definition: MSLang.h:16
void checkMap(unsigned int accuracy, std::pair< double, double > fieldDimensions, double deltaZ, const std::vector< double > &fourierCoefficients, gsl_spline *splineCoefficients, gsl_interp_accel *splineAccelerator)
Definition: Fieldmap.cpp:443
void lowResolutionWarning(double squareError, double maxError)
Definition: Fieldmap.cpp:626
#define READ_BUFFER_LENGTH
Definition: Fieldmap.h:4
void write3DField(unsigned int nx, unsigned int ny, unsigned int nz, const std::pair< double, double > &xrange, const std::pair< double, double > &yrange, const std::pair< double, double > &zrange, const std::vector< Vector_t > &ef, const std::vector< Vector_t > &bf)
Definition: Fieldmap.cpp:732
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:816
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
Definition: Fieldmap.cpp:718