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