OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
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
24#include "Parser/FileStream.h"
26#include "Utilities/Options.h"
28
29#include "Utility/Inform.h"
30#include "Utility/IpplInfo.h"
32
33#include <boost/assign.hpp>
34
35#include <ctime>
36#include <cstddef>
37#include <iostream>
38#include <limits>
39
40extern Inform* gmsg;
41extern Inform* gmsgALL;
42
43using namespace Options;
44
45const boost::bimap<DumpFrame, std::string> Option::bmDumpFrameString_s =
46 boost::assign::list_of<const boost::bimap<DumpFrame, std::string>::relation>
47 (DumpFrame::GLOBAL, "GLOBAL")
48 (DumpFrame::BUNCH_MEAN, "BUNCH_MEAN")
49 (DumpFrame::REFERENCE, "REFERENCE");
50
51namespace {
52 // The attributes of class Option.
53 enum {
54 ECHO,
55 INFO,
56 TRACE,
57 WARN,
58 SEED,
59 TELL,
60 PSDUMPFREQ,
61 STATDUMPFREQ,
62 PSDUMPEACHTURN,
63 PSDUMPFRAME,
64 SPTDUMPFREQ,
65 REPARTFREQ,
66 REBINFREQ,
67 SCSOLVEFREQ,
68 MTSSUBSTEPS,
69 REMOTEPARTDEL,
70 RHODUMP,
71 EBDUMP,
72 CSRDUMP,
73 AUTOPHASE,
74 NUMBLOCKS,
75 RECYCLEBLOCKS,
76 NLHS,
77 CZERO,
78 RNGTYPE,
79 ENABLEHDF5,
80 ENABLEVTK,
81 ASCIIDUMP,
82 BOUNDPDESTROYFQ,
83 BEAMHALOBOUNDARY,
84 CLOTUNEONLY,
85 IDEALIZED,
86 LOGBENDTRAJECTORY,
87 VERSION,
88#ifdef ENABLE_AMR
89 AMR,
90 AMR_YT_DUMP_FREQ,
91 AMR_REGRID_FREQ,
92#endif
93 MEMORYDUMP,
94 HALOSHIFT,
95 DELPARTFREQ,
96 MINBINEMITTED,
97 MINSTEPFORREBIN,
98 COMPUTEPERCENTILES,
99 DUMPBEAMMATRIX,
100 SIZE
101 };
102}
103
104
106 Action(SIZE, "OPTION",
107 "The \"OPTION\" statement defines OPAL execution options.")
108 {
109
111 ("ECHO", "If true, give echo of input", echo);
112
114 ("INFO", "If true, print information messages", info);
115
117 ("TRACE", "If true, print execution trace"
118 "Must be the first option in the inputfile in "
119 "order to render correct results", mtrace);
120
122 ("WARN", "If true, print warning messages", warn);
123
125 ("SEED", "The seed for the random generator, -1 will use time(0) as seed ");
126
128 ("TELL", "If true, print the current settings. "
129 "Must be the last option in the inputfile in "
130 "order to render correct results", false);
131
132 itsAttr[PSDUMPFREQ] = Attributes::makeReal
133 ("PSDUMPFREQ", "The frequency to dump the phase space, "
134 "i.e.dump data when step%psDumpFreq==0, its default value is 10.",
135 psDumpFreq);
136
137 itsAttr[STATDUMPFREQ] = Attributes::makeReal
138 ("STATDUMPFREQ", "The frequency to dump statistical data "
139 "(e.g. RMS beam quantities), i.e. dump data when step%statDumpFreq == 0, "
140 "its default value is 10.", statDumpFreq);
141
142 itsAttr[PSDUMPEACHTURN] = Attributes::makeBool
143 ("PSDUMPEACHTURN", "If true, dump phase space after each "
144 "turn ,only aviable for OPAL-cycl, its default value is false",
146
147 itsAttr[SCSOLVEFREQ] = Attributes::makeReal
148 ("SCSOLVEFREQ", "The frequency to solve space charge fields. its default value is 1");
149
150 itsAttr[MTSSUBSTEPS] = Attributes::makeReal
151 ("MTSSUBSTEPS", "How many small timesteps "
152 "are inside the large timestep used in multiple "
153 "time stepping (MTS) integrator");
154
155 itsAttr[REMOTEPARTDEL] = Attributes::makeReal
156 ("REMOTEPARTDEL", "Artifically delete the remote particle "
157 "if its distance to the beam mass is larger than "
158 "REMOTEPARTDEL times of the beam rms size, "
159 "its default values is 0 (no delete) ",remotePartDel);
160
162 ("PSDUMPFRAME", "Controls the frame of phase space dump in "
163 "stat file and h5 file. If 'GLOBAL' OPAL will dump in the "
164 "lab (global) Cartesian frame; if 'BUNCH_MEAN' OPAL will "
165 "dump in the local Cartesian frame of the beam mean; "
166 "if 'REFERENCE' OPAL will dump in the local Cartesian "
167 "frame of the reference particle 0. Only available for "
168 "OPAL-cycl.", {"BUNCH_MEAN", "REFERENCE", "GLOBAL"}, "GLOBAL");
169
170 itsAttr[SPTDUMPFREQ] = Attributes::makeReal
171 ("SPTDUMPFREQ", "The frequency to dump single "
172 "particle trajectory of particles with ID = 0 & 1, "
173 "its default value is 1.", sptDumpFreq);
174
175 itsAttr[REPARTFREQ] = Attributes::makeReal
176 ("REPARTFREQ", "The frequency to do particles repartition "
177 "for better load balance between nodes, its "
178 "default value is " + std::to_string(repartFreq) + ".", repartFreq);
179
180 itsAttr[MINBINEMITTED] = Attributes::makeReal
181 ("MINBINEMITTED", "The number of bins that have to be emitted before the bins are squashed into "
182 "a single bin; the default value is " + std::to_string(minBinEmitted) + ".", minBinEmitted);
183
184 itsAttr[MINSTEPFORREBIN] = Attributes::makeReal
185 ("MINSTEPFORREBIN", "The number of steps into the simulation before the bins are squashed into "
186 "a single bin; the default value is " + std::to_string(minStepForRebin) + ".", minStepForRebin);
187
188 itsAttr[REBINFREQ] = Attributes::makeReal
189 ("REBINFREQ", "The frequency to reset energy bin ID for "
190 "all particles, its default value is 100.", rebinFreq);
191
193 ("RHODUMP", "If true, in addition to the phase "
194 "space the scalar rho field is also dumped (H5Block)", rhoDump);
195
197 ("EBDUMP", "If true, in addition to the phase space the "
198 "E and B field at each particle is also dumped into the H5 file)", ebDump);
199
201 ("CSRDUMP", "If true, the csr E field, line density "
202 "and the line density derivative is dumped into the "
203 "data directory)", csrDump);
204
205 itsAttr[AUTOPHASE] = Attributes::makeReal
206 ("AUTOPHASE", "If greater than zero OPAL is scanning "
207 "the phases of each rf structure in order to get maximum "
208 "acceleration. Defines the number of refinements of the "
209 "search range", autoPhase);
210
212 ("CZERO", "If set to true a symmetric distribution is "
213 "created -> centroid == 0.0", cZero);
214
216 ("RNGTYPE", "Type of pseudo- or quasi-random number generator, "
217 "see also Quasi-Random Sequences, GSL reference manual.",
218 {"RANDOM", "HALTON", "SOBOL", "NIEDERREITER"}, rngtype);
219
220 itsAttr[CLOTUNEONLY] = Attributes::makeBool
221 ("CLOTUNEONLY", "If set to true stop after "
222 "CLO and tune calculation ", cloTuneOnly);
223
224 itsAttr[NUMBLOCKS] = Attributes::makeReal
225 ("NUMBLOCKS", "Maximum number of vectors in the Krylov "
226 "space (for RCGSolMgr). Default value is 0 and BlockCGSolMgr will be used.");
227
228 itsAttr[RECYCLEBLOCKS] = Attributes::makeReal
229 ("RECYCLEBLOCKS", "Number of vectors in the recycle "
230 "space (for RCGSolMgr). Default value is 0 and BlockCGSolMgr will be used.");
231
233 ("NLHS", "Number of stored old solutions for extrapolating "
234 "the new starting vector. Default value is 1 and just the last solution is used.");
235
236 itsAttr[ENABLEHDF5] = Attributes::makeBool
237 ("ENABLEHDF5", "If true, HDF5 actions are enabled", enableHDF5);
238
239 itsAttr[ENABLEVTK] = Attributes::makeBool
240 ("ENABLEVTK", "If true, writing of VTK files are enabled", enableVTK);
241
242 itsAttr[ASCIIDUMP] = Attributes::makeBool
243 ("ASCIIDUMP", "If true, some of the elements dump in ASCII instead of HDF5", asciidump);
244
245 itsAttr[BOUNDPDESTROYFQ] = Attributes::makeReal
246 ("BOUNDPDESTROYFQ", "The frequency to do boundp_destroy to "
247 "delete lost particles. Default 10", boundpDestroyFreq);
248
249 itsAttr[BEAMHALOBOUNDARY] = Attributes::makeReal
250 ("BEAMHALOBOUNDARY", "Defines in terms of sigma where "
251 "the halo starts. Default 0.0", beamHaloBoundary);
252
253 itsAttr[IDEALIZED] = Attributes::makeBool
254 ("IDEALIZED", "Using the hard edge model for the calculation "
255 "of path length. Default: false", idealized);
256
257 itsAttr[LOGBENDTRAJECTORY] = Attributes::makeBool
258 ("LOGBENDTRAJECTORY", "Writing the trajectory of "
259 "every bend to disk. Default: false", writeBendTrajectories);
260
262 ("VERSION", "Version of OPAL for which input file was written", version);
263
264#ifdef ENABLE_AMR
266 ("AMR", "Use adaptive mesh refinement.", amr);
267
268 itsAttr[AMR_YT_DUMP_FREQ] = Attributes::makeReal("AMR_YT_DUMP_FREQ",
269 "The frequency to dump grid "
270 "and particle data "
271 "(default: 10)", amrYtDumpFreq);
272
273 itsAttr[AMR_REGRID_FREQ] = Attributes::makeReal("AMR_REGRID_FREQ",
274 "The frequency to perform a regrid "
275 "in multi-bunch mode (default: 10)",
277#endif
278
279 itsAttr[MEMORYDUMP] = Attributes::makeBool
280 ("MEMORYDUMP", "If true, write memory to SDDS file", memoryDump);
281
282 itsAttr[HALOSHIFT] = Attributes::makeReal
283 ("HALOSHIFT", "Constant parameter to shift halo value (default: 0.0)", haloShift);
284
285 itsAttr[DELPARTFREQ] = Attributes::makeReal
286 ("DELPARTFREQ", "The frequency to delete particles, "
287 "i.e. delete when step%delPartFreq == 0. Default: 1", delPartFreq);
288
289 itsAttr[COMPUTEPERCENTILES] = Attributes::makeBool
290 ("COMPUTEPERCENTILES", "Flag to control whether the 68.27 "
291 "(1 sigma for normal distribution), the 95.45 (2 sigmas), "
292 "the 99.73 (3 sigmas) and the 99.994 (4 sigmas) percentiles "
293 "for the beam size and the normalized emittance should "
294 "be computed. Default: false", computePercentiles);
295
296 itsAttr[DUMPBEAMMATRIX] = Attributes::makeBool
297 ("DUMPBEAMMATRIX", "Flag to control whether to write "
298 "the 6-dimensional beam matrix (upper triangle only) "
299 "to stat file. Default: false", dumpBeamMatrix);
300
302
304}
305
306
307Option::Option(const std::string& name, Option* parent):
308 Action(name, parent) {
332 Attributes::setPredefinedString(itsAttr[RNGTYPE], std::string(rngtype));
340 Attributes::setReal(itsAttr[BEAMHALOBOUNDARY], beamHaloBoundary);
344#ifdef ENABLE_AMR
346 Attributes::setReal(itsAttr[AMR_YT_DUMP_FREQ], amrYtDumpFreq);
347 Attributes::setReal(itsAttr[AMR_REGRID_FREQ], amrRegridFreq);
348#endif
352 Attributes::setBool(itsAttr[COMPUTEPERCENTILES], computePercentiles);
354}
355
356
359
360
361Option* Option::clone(const std::string& name) {
362 return new Option(name, this);
363}
364
365
367 // Store the option flags.
372 psDumpEachTurn = Attributes::getBool(itsAttr[PSDUMPEACHTURN]);
373 remotePartDel = Attributes::getReal(itsAttr[REMOTEPARTDEL]);
384#ifdef ENABLE_AMR
386 amrYtDumpFreq = int(Attributes::getReal(itsAttr[AMR_YT_DUMP_FREQ]));
387
388 if ( amrYtDumpFreq < 1 ) {
389 amrYtDumpFreq = std::numeric_limits<int>::max();
390 }
391
392 amrRegridFreq = int(Attributes::getReal(itsAttr[AMR_REGRID_FREQ]));
394#endif
395
399 computePercentiles = Attributes::getBool(itsAttr[COMPUTEPERCENTILES]);
400 dumpBeamMatrix = Attributes::getBool(itsAttr[DUMPBEAMMATRIX]);
401 if ( memoryDump ) {
404 memory->sample();
405 }
406
409
410 if (Options::seed == -1)
411 rangen.init55(time(0));
412 else
413 rangen.init55(seed);
414
415 gmsgALL->on(info);
416 gmsg->on(info);
417 IpplInfo::Info->on(info);
418 IpplInfo::Warn->on(warn);
419
421
424 if (itsAttr[SEED]) {
425 seed = int(Attributes::getReal(itsAttr[SEED]));
426 if (seed == -1)
427 rangen.init55(time(0));
428 else
429 rangen.init55(seed);
430 }
431
432 if (itsAttr[PSDUMPFREQ]) {
433 psDumpFreq = int(Attributes::getReal(itsAttr[PSDUMPFREQ]));
434 if (psDumpFreq==0)
435 psDumpFreq = std::numeric_limits<int>::max();
436 }
437
438 if (itsAttr[STATDUMPFREQ]) {
439 statDumpFreq = int(Attributes::getReal(itsAttr[STATDUMPFREQ]));
440 if (statDumpFreq==0)
441 statDumpFreq = std::numeric_limits<int>::max();
442 }
443
444 if (itsAttr[SPTDUMPFREQ]) {
445 sptDumpFreq = int(Attributes::getReal(itsAttr[SPTDUMPFREQ]));
446 if (sptDumpFreq==0)
447 sptDumpFreq = std::numeric_limits<int>::max();
448 }
449
450 if (itsAttr[SCSOLVEFREQ]) {
451 scSolveFreq = int(Attributes::getReal(itsAttr[SCSOLVEFREQ]));
452 scSolveFreq = ( scSolveFreq < 1 ) ? 1 : scSolveFreq;
453 }
454
455 if (itsAttr[MTSSUBSTEPS]) {
456 mtsSubsteps = int(Attributes::getReal(itsAttr[MTSSUBSTEPS]));
457 }
458
459 if (itsAttr[REPARTFREQ]) {
460 repartFreq = int(Attributes::getReal(itsAttr[REPARTFREQ]));
461 }
462
463 if (itsAttr[MINBINEMITTED]) {
464 minBinEmitted = int(Attributes::getReal(itsAttr[MINBINEMITTED]));
465 }
466
467 if (itsAttr[MINSTEPFORREBIN]) {
468 minStepForRebin = int(Attributes::getReal(itsAttr[MINSTEPFORREBIN]));
469 }
470
471 if (itsAttr[REBINFREQ]) {
472 rebinFreq = int(Attributes::getReal(itsAttr[REBINFREQ]));
473 }
474
475 if (itsAttr[AUTOPHASE]) {
476 autoPhase = int(Attributes::getReal(itsAttr[AUTOPHASE]));
477 }
478
479 if (itsAttr[NUMBLOCKS]) {
480 numBlocks = int(Attributes::getReal(itsAttr[NUMBLOCKS]));
481 }
482
483 if (itsAttr[RECYCLEBLOCKS]) {
484 recycleBlocks = int(Attributes::getReal(itsAttr[RECYCLEBLOCKS]));
485 }
486
487 if (itsAttr[NLHS]) {
488 nLHS = int(Attributes::getReal(itsAttr[NLHS]));
489 }
490
491 if (itsAttr[CZERO]) {
492 cZero = bool(Attributes::getBool(itsAttr[CZERO]));
493 }
494
495 if (itsAttr[RNGTYPE]) {
496 rngtype = std::string(Attributes::getString(itsAttr[RNGTYPE]));
497 } else {
498 rngtype = std::string("RANDOM");
499 }
500
501 if (itsAttr[BEAMHALOBOUNDARY]) {
502 beamHaloBoundary = Attributes::getReal(itsAttr[BEAMHALOBOUNDARY]);
503 } else {
505 }
506
507 if (itsAttr[CLOTUNEONLY]) {
508 cloTuneOnly = bool(Attributes::getBool(itsAttr[CLOTUNEONLY]));
509 } else {
510 cloTuneOnly = false;
511 }
512
513 // Set message flags.
515
516 if (Attributes::getBool(itsAttr[TELL])) {
517 *gmsg << "\nCurrent settings of options:\n" << *this << endl;
518 }
519
520 Option* main = dynamic_cast<Option*>(OpalData::getInstance()->find("OPTION"));
521 if (main) {
522 main->update(itsAttr);
523 }
524}
525
526void Option::handlePsDumpFrame(const std::string& dumpFrame) {
527 psDumpFrame = bmDumpFrameString_s.right.at(dumpFrame);
528}
529
530std::string Option::getDumpFrameString(const DumpFrame& df) {
531 return bmDumpFrameString_s.left.at(df);
532}
533
534void Option::update(const std::vector<Attribute>& othersAttributes) {
535 for (int i = 0; i < SIZE; ++ i) {
536 itsAttr[i] = othersAttributes[i];
537 }
538}
DumpFrame
Definition Options.h:26
@ REFERENCE
Definition Options.h:29
@ BUNCH_MEAN
Definition Options.h:28
Inform * gmsgALL
Definition Main.cpp:71
@ SIZE
Definition IndexMap.cpp:174
Inform * gmsg
Definition Main.cpp:70
int main(int argc, char *argv[])
Definition Main.cpp:139
Inform & endl(Inform &inf)
Definition Inform.cpp:42
const std::string name
Some AMR types used a lot.
Definition AmrDefs.h:33
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:111
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:107
bool writeBendTrajectories
Definition Options.cpp:95
bool mtrace
Trace flag.
Definition Options.cpp:31
int boundpDestroyFreq
Definition Options.cpp:87
bool memoryDump
Definition Options.cpp:105
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 amrRegridFreq
After how many steps the AMR grid hierarchy is updated.
Definition Options.cpp:103
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
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
int amrYtDumpFreq
The frequency to dump AMR grid data and particles into file.
Definition Options.cpp:101
unsigned int delPartFreq
The frequency to delete particles (currently: OPAL-cycl only).
Definition Options.cpp:109
bool dumpBeamMatrix
Definition Options.cpp:113
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 recycleBlocks
RCG: number of recycle blocks.
Definition Options.cpp:73
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:191
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
Object * find(const std::string &name)
Find entry.
Definition OpalData.cpp:571
static OpalData * getInstance()
Definition OpalData.cpp:196
virtual ~Option()
Definition Option.cpp:357
virtual void execute()
Execute the command.
Definition Option.cpp:366
static const boost::bimap< DumpFrame, std::string > bmDumpFrameString_s
Definition Option.h:59
virtual void update()
Update this object.
Definition Object.cpp:263
void handlePsDumpFrame(const std::string &dumpFrame)
Definition Option.cpp:526
virtual Option * clone(const std::string &name)
Make clone.
Definition Option.cpp:361
static std::string getDumpFrameString(const DumpFrame &df)
Definition Option.cpp:530
Option()
Definition Option.cpp:105
static void setEcho(bool flag)
Set echo flag.
static Inform * Warn
Definition IpplInfo.h:79
static Inform * Info
Definition IpplInfo.h:78
static IpplMemory_p getInstance(Unit unit=Unit::GB, bool reset=true)
IpplMemoryUsage * IpplMemory_p