OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
Option.cpp
Go to the documentation of this file.
1//
2// Class Option
3// The OPTION command.
4// The user interface allowing setting of OPAL options.
5// The actual option flags are contained in namespace Options.
6//
7// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
8// All rights reserved
9//
10// This file is part of OPAL.
11//
12// OPAL is free software: you can redistribute it and/or modify
13// it under the terms of the GNU General Public License as published by
14// the Free Software Foundation, either version 3 of the License, or
15// (at your option) any later version.
16//
17// You should have received a copy of the GNU General Public License
18// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19//
20#include "BasicActions/Option.h"
21#include "Ippl.h"
22
28#include "Utilities/Options.h"
29
30#include "Utility/Inform.h"
31#include "Utility/IpplInfo.h"
32
33#include <boost/assign.hpp>
34
35#include <cstddef>
36#include <ctime>
37#include <iostream>
38#include <limits>
39
40extern Inform* gmsg;
41
42using namespace Options;
43
44const boost::bimap<DumpFrame, std::string> Option::bmDumpFrameString_s =
45 boost::assign::list_of<const boost::bimap<DumpFrame, std::string>::relation>(
46 DumpFrame::GLOBAL, "GLOBAL")(DumpFrame::BUNCH_MEAN, "BUNCH_MEAN")(
47 DumpFrame::REFERENCE, "REFERENCE");
48
49namespace {
50 // The attributes of class Option.
51 enum {
52 ECHO,
53 INFO,
54 TRACE,
55 WARN,
56 SEED,
57 TELL,
58 PSDUMPFREQ,
59 STATDUMPFREQ,
60 PSDUMPEACHTURN,
61 PSDUMPFRAME,
62 SPTDUMPFREQ,
63 REPARTFREQ,
64 REBINFREQ,
65 SCSOLVEFREQ,
66 MTSSUBSTEPS,
67 REMOTEPARTDEL,
68 RHODUMP,
69 EBDUMP,
70 CSRDUMP,
71 AUTOPHASE,
72 NUMBLOCKS,
73 RECYCLEBLOCKS,
74 NLHS,
75 CZERO,
76 RNGTYPE,
77 ENABLEHDF5,
78 ENABLEVTK,
79 ASCIIDUMP,
80 BOUNDPDESTROYFQ,
81 BEAMHALOBOUNDARY,
82 CLOTUNEONLY,
83 IDEALIZED,
84 LOGBENDTRAJECTORY,
85 VERSION,
86 MEMORYDUMP,
87 HALOSHIFT,
88 DELPARTFREQ,
89 MINBINEMITTED,
90 MINSTEPFORREBIN,
91 COMPUTEPERCENTILES,
92 MAXBINS,
93 BINNINGALPHA,
94 BINNINGBETA,
95 DESIREDWIDTH,
96 SIZE
97 };
98} // namespace
99
101 : Action(SIZE, "OPTION", "The \"OPTION\" statement defines OPAL execution options.") {
102 itsAttr[ECHO] = Attributes::makeBool("ECHO", "If true, give echo of input", echo);
103
104 itsAttr[INFO] = Attributes::makeBool("INFO", "If true, print information messages", info);
105
107 "TRACE",
108 "If true, print execution trace"
109 "Must be the first option in the inputfile in "
110 "order to render correct results",
111 mtrace);
112
113 itsAttr[WARN] = Attributes::makeBool("WARN", "If true, print warning messages", warn);
114
116 "SEED", "The seed for the random generator, -1 will use time(0) as seed ");
117
119 "TELL",
120 "If true, print the current settings. "
121 "Must be the last option in the inputfile in "
122 "order to render correct results",
123 false);
124
125 itsAttr[PSDUMPFREQ] = Attributes::makeReal(
126 "PSDUMPFREQ",
127 "The frequency to dump the phase space, "
128 "i.e.dump data when step%psDumpFreq==0, its default value is 10.",
129 psDumpFreq);
130
131 itsAttr[STATDUMPFREQ] = Attributes::makeReal(
132 "STATDUMPFREQ",
133 "The frequency to dump statistical data "
134 "(e.g. RMS beam quantities), i.e. dump data when step%statDumpFreq == 0, "
135 "its default value is 10.",
137
138 itsAttr[PSDUMPEACHTURN] = Attributes::makeBool(
139 "PSDUMPEACHTURN",
140 "If true, dump phase space after each "
141 "turn ,only aviable for OPAL-cycl, its default value is false",
143
144 itsAttr[SCSOLVEFREQ] = Attributes::makeReal(
145 "SCSOLVEFREQ", "The frequency to solve space charge fields. its default value is 1");
146
147 itsAttr[MTSSUBSTEPS] = Attributes::makeReal(
148 "MTSSUBSTEPS",
149 "How many small timesteps "
150 "are inside the large timestep used in multiple "
151 "time stepping (MTS) integrator");
152
153 itsAttr[REMOTEPARTDEL] = Attributes::makeReal(
154 "REMOTEPARTDEL",
155 "Artifically delete the remote particle "
156 "if its distance to the beam mass is larger than "
157 "REMOTEPARTDEL times of the beam rms size, "
158 "its default values is 0 (no delete) ",
160
162 "PSDUMPFRAME",
163 "Controls the frame of phase space dump in "
164 "stat file and h5 file. If 'GLOBAL' OPAL will dump in the "
165 "lab (global) Cartesian frame; if 'BUNCH_MEAN' OPAL will "
166 "dump in the local Cartesian frame of the beam mean; "
167 "if 'REFERENCE' OPAL will dump in the local Cartesian "
168 "frame of the reference particle 0. Only available for "
169 "OPAL-cycl.",
170 {"BUNCH_MEAN", "REFERENCE", "GLOBAL"}, "GLOBAL");
171
172 itsAttr[SPTDUMPFREQ] = Attributes::makeReal(
173 "SPTDUMPFREQ",
174 "The frequency to dump single "
175 "particle trajectory of particles with ID = 0 & 1, "
176 "its default value is 1.",
178
179 itsAttr[REPARTFREQ] = Attributes::makeReal(
180 "REPARTFREQ",
181 "The frequency to do particles repartition "
182 "for better load balance between nodes, its "
183 "default value is "
184 + std::to_string(repartFreq) + ".",
185 repartFreq);
186
187 itsAttr[MINBINEMITTED] = Attributes::makeReal(
188 "MINBINEMITTED",
189 "The number of bins that have to be emitted before the bins are squashed into "
190 "a single bin; the default value is "
191 + std::to_string(minBinEmitted) + ".",
193
194 itsAttr[MINSTEPFORREBIN] = Attributes::makeReal(
195 "MINSTEPFORREBIN",
196 "The number of steps into the simulation before the bins are squashed into "
197 "a single bin; the default value is "
198 + std::to_string(minStepForRebin) + ".",
200
201 itsAttr[REBINFREQ] = Attributes::makeReal(
202 "REBINFREQ",
203 "The frequency to reset energy bin ID for "
204 "all particles, its default value is 100.",
205 rebinFreq);
206
207 itsAttr[RHODUMP] = Attributes::makeBool(
208 "RHODUMP",
209 "If true, in addition to the phase "
210 "space the scalar rho field is also dumped (H5Block)",
211 rhoDump);
212
214 "EBDUMP",
215 "If true, in addition to the phase space the "
216 "E and B field at each particle is also dumped into the H5 file)",
217 ebDump);
218
219 itsAttr[CSRDUMP] = Attributes::makeBool(
220 "CSRDUMP",
221 "If true, the csr E field, line density "
222 "and the line density derivative is dumped into the "
223 "data directory)",
224 csrDump);
225
226 itsAttr[AUTOPHASE] = Attributes::makeReal(
227 "AUTOPHASE",
228 "If greater than zero OPAL is scanning "
229 "the phases of each rf structure in order to get maximum "
230 "acceleration. Defines the number of refinements of the "
231 "search range",
232 autoPhase);
233
235 "CZERO",
236 "If set to true a symmetric distribution is "
237 "created -> centroid == 0.0",
238 cZero);
239
241 "RNGTYPE",
242 "Type of pseudo- or quasi-random number generator, "
243 "see also Quasi-Random Sequences, GSL reference manual.",
244 {"RANDOM", "HALTON", "SOBOL", "NIEDERREITER"}, rngtype);
245
246 itsAttr[CLOTUNEONLY] = Attributes::makeBool(
247 "CLOTUNEONLY",
248 "If set to true stop after "
249 "CLO and tune calculation ",
251
252 itsAttr[NUMBLOCKS] = Attributes::makeReal(
253 "NUMBLOCKS",
254 "Maximum number of vectors in the Krylov "
255 "space (for RCGSolMgr). Default value is 0 and BlockCGSolMgr will be used.");
256
257 itsAttr[RECYCLEBLOCKS] = Attributes::makeReal(
258 "RECYCLEBLOCKS",
259 "Number of vectors in the recycle "
260 "space (for RCGSolMgr). Default value is 0 and BlockCGSolMgr will be used.");
261
263 "NLHS",
264 "Number of stored old solutions for extrapolating "
265 "the new starting vector. Default value is 1 and just the last solution is used.");
266
267 itsAttr[ENABLEHDF5] =
268 Attributes::makeBool("ENABLEHDF5", "If true, HDF5 actions are enabled", enableHDF5);
269
270 itsAttr[ENABLEVTK] =
271 Attributes::makeBool("ENABLEVTK", "If true, writing of VTK files are enabled", enableVTK);
272
273 itsAttr[ASCIIDUMP] = Attributes::makeBool(
274 "ASCIIDUMP", "If true, some of the elements dump in ASCII instead of HDF5", asciidump);
275
276 itsAttr[BOUNDPDESTROYFQ] = Attributes::makeReal(
277 "BOUNDPDESTROYFQ",
278 "The frequency to do boundp_destroy to "
279 "delete lost particles. Default 10",
281
282 itsAttr[BEAMHALOBOUNDARY] = Attributes::makeReal(
283 "BEAMHALOBOUNDARY",
284 "Defines in terms of sigma where "
285 "the halo starts. Default 0.0",
287
288 itsAttr[IDEALIZED] = Attributes::makeBool(
289 "IDEALIZED",
290 "Using the hard edge model for the calculation "
291 "of path length. Default: false",
292 idealized);
293
294 itsAttr[LOGBENDTRAJECTORY] = Attributes::makeBool(
295 "LOGBENDTRAJECTORY",
296 "Writing the trajectory of "
297 "every bend to disk. Default: false",
299
300 itsAttr[VERSION] = Attributes::makeReal(
301 "VERSION", "Version of OPAL for which input file was written", version);
302
303 itsAttr[MEMORYDUMP] =
304 Attributes::makeBool("MEMORYDUMP", "If true, write memory to SDDS file", memoryDump);
305
306 itsAttr[HALOSHIFT] = Attributes::makeReal(
307 "HALOSHIFT", "Constant parameter to shift halo value (default: 0.0)", haloShift);
308
309 itsAttr[DELPARTFREQ] = Attributes::makeReal(
310 "DELPARTFREQ",
311 "The frequency to delete particles, "
312 "i.e. delete when step%delPartFreq == 0. Default: 1",
314
315 itsAttr[COMPUTEPERCENTILES] = Attributes::makeBool(
316 "COMPUTEPERCENTILES",
317 "Flag to control whether the 68.27 "
318 "(1 sigma for normal distribution), the 95.45 (2 sigmas), "
319 "the 99.73 (3 sigmas) and the 99.994 (4 sigmas) percentiles "
320 "for the beam size and the normalized emittance should "
321 "be computed. Default: false",
323
324 itsAttr[MAXBINS] = Attributes::makeReal(
325 "MAXBINS",
326 "The maximum number of bins used for energy binning. Default: 128",
327 maxBins);
328
329 itsAttr[BINNINGALPHA] = Attributes::makeReal(
330 "BINNINGALPHA",
331 "A value [0, 1] that determines how aggressive the algorithm tries to reduce the number of bins.",
333
334 itsAttr[BINNINGBETA] = Attributes::makeReal(
335 "BINNINGBETA",
336 "A value [0, 1] that determines how aggressive the algorithm tries to use wider bins.",
338
339 itsAttr[DESIREDWIDTH] = Attributes::makeReal(
340 "DESIREDWIDTH",
341 "A bias [0, 1] that tries to steer the bin size to the given variable.",
343
344
346
348}
349
350Option::Option(const std::string& name, Option* parent) : Action(name, parent) {
374 Attributes::setPredefinedString(itsAttr[RNGTYPE], std::string(rngtype));
382 Attributes::setReal(itsAttr[BEAMHALOBOUNDARY], beamHaloBoundary);
389 Attributes::setBool(itsAttr[COMPUTEPERCENTILES], computePercentiles);
390
395}
396
399
400Option* Option::clone(const std::string& name) {
401 return new Option(name, this);
402}
403
405 // Store the option flags.
410 psDumpEachTurn = Attributes::getBool(itsAttr[PSDUMPEACHTURN]);
411 remotePartDel = Attributes::getReal(itsAttr[REMOTEPARTDEL]);
422
425 computePercentiles = Attributes::getBool(itsAttr[COMPUTEPERCENTILES]);
426
431
434
435 if (Options::seed == -1)
436 rangen.init55(time(0));
437 else
438 rangen.init55(seed);
439
441 /*
442 IpplInfo::Info->on(info);
443 IpplInfo::Warn->on(warn);
444 */
446
449 if (itsAttr[SEED]) {
450 seed = int(Attributes::getReal(itsAttr[SEED]));
451 if (seed == -1)
452 rangen.init55(time(0));
453 else
454 rangen.init55(seed);
455 }
456
457 if (itsAttr[PSDUMPFREQ]) {
458 psDumpFreq = int(Attributes::getReal(itsAttr[PSDUMPFREQ]));
459 if (psDumpFreq == 0)
460 psDumpFreq = std::numeric_limits<int>::max();
461 }
462
463 if (itsAttr[STATDUMPFREQ]) {
464 statDumpFreq = int(Attributes::getReal(itsAttr[STATDUMPFREQ]));
465 if (statDumpFreq == 0)
466 statDumpFreq = std::numeric_limits<int>::max();
467 }
468
469 if (itsAttr[SPTDUMPFREQ]) {
470 sptDumpFreq = int(Attributes::getReal(itsAttr[SPTDUMPFREQ]));
471 if (sptDumpFreq == 0)
472 sptDumpFreq = std::numeric_limits<int>::max();
473 }
474
475 if (itsAttr[SCSOLVEFREQ]) {
476 scSolveFreq = int(Attributes::getReal(itsAttr[SCSOLVEFREQ]));
477 scSolveFreq = (scSolveFreq < 1) ? 1 : scSolveFreq;
478 }
479
480 if (itsAttr[MTSSUBSTEPS]) {
481 mtsSubsteps = int(Attributes::getReal(itsAttr[MTSSUBSTEPS]));
482 }
483
484 if (itsAttr[REPARTFREQ]) {
485 repartFreq = int(Attributes::getReal(itsAttr[REPARTFREQ]));
486 }
487
488 if (itsAttr[MINBINEMITTED]) {
489 minBinEmitted = int(Attributes::getReal(itsAttr[MINBINEMITTED]));
490 }
491
492 if (itsAttr[MINSTEPFORREBIN]) {
493 minStepForRebin = int(Attributes::getReal(itsAttr[MINSTEPFORREBIN]));
494 }
495
496 if (itsAttr[REBINFREQ]) {
497 rebinFreq = int(Attributes::getReal(itsAttr[REBINFREQ]));
498 }
499
500 if (itsAttr[AUTOPHASE]) {
501 autoPhase = int(Attributes::getReal(itsAttr[AUTOPHASE]));
502 }
503
504 if (itsAttr[NUMBLOCKS]) {
505 numBlocks = int(Attributes::getReal(itsAttr[NUMBLOCKS]));
506 }
507
508 if (itsAttr[RECYCLEBLOCKS]) {
509 recycleBlocks = int(Attributes::getReal(itsAttr[RECYCLEBLOCKS]));
510 }
511
512 if (itsAttr[NLHS]) {
513 nLHS = int(Attributes::getReal(itsAttr[NLHS]));
514 }
515
516 if (itsAttr[CZERO]) {
517 cZero = bool(Attributes::getBool(itsAttr[CZERO]));
518 }
519
520 if (itsAttr[RNGTYPE]) {
521 rngtype = std::string(Attributes::getString(itsAttr[RNGTYPE]));
522 } else {
523 rngtype = std::string("RANDOM");
524 }
525
526 if (itsAttr[BEAMHALOBOUNDARY]) {
527 beamHaloBoundary = Attributes::getReal(itsAttr[BEAMHALOBOUNDARY]);
528 } else {
530 }
531
532 if (itsAttr[CLOTUNEONLY]) {
533 cloTuneOnly = bool(Attributes::getBool(itsAttr[CLOTUNEONLY]));
534 } else {
535 cloTuneOnly = false;
536 }
537
538 if (itsAttr[MAXBINS]) {
539 maxBins = int(Attributes::getReal(itsAttr[MAXBINS]));
540 }
541
542 if (itsAttr[BINNINGALPHA]) {
544 }
545
546 if (itsAttr[BINNINGBETA]) {
548 }
549
550 if (itsAttr[DESIREDWIDTH]) {
552 }
553
554 // Set message flags.
556
557 if (Attributes::getBool(itsAttr[TELL])) {
558 *gmsg << "\nCurrent settings of options:\n" << *this << endl;
559 }
560
561 Option* main = dynamic_cast<Option*>(OpalData::getInstance()->find("OPTION"));
562 if (main) {
563 main->update(itsAttr);
564 }
565}
566
567void Option::handlePsDumpFrame(const std::string& dumpFrame) {
568 psDumpFrame = bmDumpFrameString_s.right.at(dumpFrame);
569}
570
571std::string Option::getDumpFrameString(const DumpFrame& df) {
572 return bmDumpFrameString_s.left.at(df);
573}
574
575void Option::update(const std::vector<Attribute>& othersAttributes) {
576 for (int i = 0; i < SIZE; ++i) {
577 itsAttr[i] = othersAttributes[i];
578 }
579}
Inform * gmsg
Definition changes.cpp:7
@ SIZE
Definition IndexMap.cpp:173
DumpFrame
Definition Options.h:26
@ REFERENCE
Definition Options.h:26
@ BUNCH_MEAN
Definition Options.h:26
int main(int argc, char *argv[])
Definition Main.cpp:130
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
void setBool(Attribute &attr, bool val)
Set logical value.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
void setReal(Attribute &attr, double val)
Set real value.
void setPredefinedString(Attribute &attr, const std::string &val)
Set predefined string value.
std::string getString(const Attribute &attr)
Get string value.
bool computePercentiles
Definition Options.cpp:105
int mtsSubsteps
Definition Options.cpp:59
double remotePartDel
Definition Options.cpp:61
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
Definition Options.cpp:39
double haloShift
The constant parameter C to shift halo, by < w^4 > / < w^2 > ^2 - C (w=x,y,z).
Definition Options.cpp:101
bool writeBendTrajectories
Definition Options.cpp:95
bool mtrace
Trace flag.
Definition Options.cpp:31
double binningBeta
Definition Options.cpp:109
int boundpDestroyFreq
Definition Options.cpp:87
bool memoryDump
Definition Options.cpp:99
bool enableVTK
If true VTK files are written.
Definition Options.cpp:83
int version
opal version of input file
Definition Options.cpp:97
int minBinEmitted
The number of bins that have to be emitted before the bin are squashed into a single bin.
Definition Options.cpp:51
bool enableHDF5
If true HDF5 files are written.
Definition Options.cpp:81
bool psDumpEachTurn
phase space dump flag for OPAL-cycl
Definition Options.cpp:43
bool asciidump
Definition Options.cpp:85
int numBlocks
RCG: cycle length.
Definition Options.cpp:71
int sptDumpFreq
The frequency to dump single particle trajectory of particles with ID = 0 & 1.
Definition Options.cpp:47
int autoPhase
Definition Options.cpp:69
bool warn
Warn flag.
Definition Options.cpp:33
std::string rngtype
random number generator
Definition Options.cpp:79
double binningAlpha
Definition Options.cpp:108
bool echo
Echo flag.
Definition Options.cpp:26
bool rhoDump
Definition Options.cpp:63
int minStepForRebin
The number of steps into the simulation before the bins are squashed into a single bin.
Definition Options.cpp:53
bool cloTuneOnly
Do closed orbit and tune calculation only.
Definition Options.cpp:91
bool csrDump
Definition Options.cpp:67
bool ebDump
Definition Options.cpp:65
bool idealized
Definition Options.cpp:93
unsigned int delPartFreq
The frequency to delete particles (currently: OPAL-cycl only).
Definition Options.cpp:103
int scSolveFreq
The frequency to solve space charge fields.
Definition Options.cpp:57
int repartFreq
The frequency to do particles repartition for better load balance between nodes.
Definition Options.cpp:49
bool cZero
If true create symmetric distribution.
Definition Options.cpp:77
double beamHaloBoundary
Definition Options.cpp:89
int nLHS
number of old left hand sides used to extrapolate a new start vector
Definition Options.cpp:75
int rebinFreq
The frequency to reset energy bin ID for all particles.
Definition Options.cpp:55
bool info
Info flag.
Definition Options.cpp:28
Random rangen
Definition Options.cpp:36
int seed
The current random seed.
Definition Options.cpp:37
DumpFrame psDumpFrame
flag to decide in which coordinate frame the phase space will be dumped for OPAL-cycl
Definition Options.cpp:45
int statDumpFreq
The frequency to dump statistical values, e.e. dump data when stepstatDumpFreq==0.
Definition Options.cpp:41
int maxBins
Definition Options.cpp:107
int recycleBlocks
RCG: number of recycle blocks.
Definition Options.cpp:73
double desiredWidth
Definition Options.cpp:110
Action(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Action.cpp:54
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:189
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
Object * find(const std::string &name)
Find entry.
Definition OpalData.cpp:563
static OpalData * getInstance()
Definition OpalData.cpp:195
virtual ~Option()
Definition Option.cpp:397
virtual void execute()
Execute the command.
Definition Option.cpp:404
static const boost::bimap< DumpFrame, std::string > bmDumpFrameString_s
Definition Option.h:59
virtual void update()
Update this object.
Definition Object.cpp:261
void handlePsDumpFrame(const std::string &dumpFrame)
Definition Option.cpp:567
virtual Option * clone(const std::string &name)
Make clone.
Definition Option.cpp:400
static std::string getDumpFrameString(const DumpFrame &df)
Definition Option.cpp:571
Option()
Definition Option.cpp:100
static void setEcho(bool flag)
Set echo flag.