OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
StringConstant.cpp
Go to the documentation of this file.
1 //
2 // Class StringConstant
3 // The STRING CONSTANT definition.
4 //
5 // Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
19 
21 #include "Attributes/Attributes.h"
22 #include "Utilities/Util.h"
23 
24 #include <iostream>
25 
26 #define CREATE_STRINGCONSTANT(x) \
27  opal->create(new StringConstant(x, this, x));
28 
29 
31  ValueDefinition(1, "STRING_CONSTANT",
32  "The \"STRING CONSTANT\" statement defines a global "
33  "string constant:\n"
34  "\tSTRING CONSTANT <name> = <String-expression>;\n") {
35  itsAttr[0] = Attributes::makeString("VALUE", "The constant value");
36 
38 
40  opal->create(new StringConstant("GITREVISION", this, Util::getGitRevision()));
41 
42  // NOTE: Strings that contain a hyphen can't be written without quotes and
43  // no string constant should be defined for them
44 
45  // Element / TYPE
46  CREATE_STRINGCONSTANT("RING");
47  CREATE_STRINGCONSTANT("CARBONCYCL");
48  CREATE_STRINGCONSTANT("CYCIAE");
49  CREATE_STRINGCONSTANT("AVFEQ");
50  CREATE_STRINGCONSTANT("FFA");
51  CREATE_STRINGCONSTANT("BANDRF");
52  CREATE_STRINGCONSTANT("SYNCHROCYCLOTRON");
53  CREATE_STRINGCONSTANT("SINGLEGAP");
54  CREATE_STRINGCONSTANT("STANDING");
55  CREATE_STRINGCONSTANT("TEMPORAL");
56  CREATE_STRINGCONSTANT("SPATIAL");
57  // Beam / PARTICLE
58  CREATE_STRINGCONSTANT("ELECTRON");
59  CREATE_STRINGCONSTANT("PROTON");
60  CREATE_STRINGCONSTANT("POSITRON");
61  CREATE_STRINGCONSTANT("ANTIPROTON");
62  CREATE_STRINGCONSTANT("CARBON");
63  CREATE_STRINGCONSTANT("HMINUS");
64  CREATE_STRINGCONSTANT("URANIUM");
65  CREATE_STRINGCONSTANT("MUON");
66  CREATE_STRINGCONSTANT("DEUTERON");
67  CREATE_STRINGCONSTANT("XENON");
68  CREATE_STRINGCONSTANT("H2P");
69  CREATE_STRINGCONSTANT("ALPHA");
70  // Distribution / TYPE
71  CREATE_STRINGCONSTANT("FROMFILE");
72  CREATE_STRINGCONSTANT("GAUSS");
73  CREATE_STRINGCONSTANT("BINOMIAL");
74  CREATE_STRINGCONSTANT("FLATTOP");
75  CREATE_STRINGCONSTANT("MULTIGAUSS");
76  CREATE_STRINGCONSTANT("GUNGAUSSFLATTOPTH");
77  CREATE_STRINGCONSTANT("ASTRAFLATTOPTH");
78  CREATE_STRINGCONSTANT("GAUSSMATCHED");
79 
80  // Distribution / INPUTMOUNITS
81  CREATE_STRINGCONSTANT("NONE");
82  CREATE_STRINGCONSTANT("EVOVERC");
83 
84  // Distribution / EMISSIONMODEL
85  CREATE_STRINGCONSTANT("ASTRA");
86  CREATE_STRINGCONSTANT("NONEQUIL");
87  // additionally: NONE
88 
89  // TrimCoil / TYPE
90  // CREATE_STRINGCONSTANT("PSI-BFIELD");
91  // CREATE_STRINGCONSTANT("PSI-PHASE");
92  // CREATE_STRINGCONSTANT("PSI-BFIELD-MIRRORED");
93 
94  // OptimizeCmd / CROSSOVER
95  CREATE_STRINGCONSTANT("BLEND");
96  CREATE_STRINGCONSTANT("NAIVEONEPOINT");
97  CREATE_STRINGCONSTANT("NAIVEUNIFORM");
98  CREATE_STRINGCONSTANT("SIMULATEDBINARY");
99 
100  // OptimizeCmd / MUTATION
101  CREATE_STRINGCONSTANT("ONEBIT");
102  CREATE_STRINGCONSTANT("INDEPENDENTBIT");
103 
104  // OpalSample / TYPE
105  CREATE_STRINGCONSTANT("UNIFORM");
106  CREATE_STRINGCONSTANT("UNIFORM_INT");
107  CREATE_STRINGCONSTANT("GAUSSIAN");
108  CREATE_STRINGCONSTANT("LATIN_HYPERCUBE");
109 
110  // Option / RNGTYPE
111  CREATE_STRINGCONSTANT("RANDOM");
112  CREATE_STRINGCONSTANT("HALTON");
113  CREATE_STRINGCONSTANT("SOBOL");
114  CREATE_STRINGCONSTANT("NIEDERREITER");
115 
116  // OpalWake / TYPE
117  // CREATE_STRINGCONSTANT("1D-CSR");
118  // CREATE_STRINGCONSTANT("1D-CSR-IGF");
119  // CREATE_STRINGCONSTANT("LONG-SHORT-RANGE");
120  // CREATE_STRINGCONSTANT("TRANSV-SHORT-RANGE");
121 
122  // OpalWake / CONDUCT
123  CREATE_STRINGCONSTANT("AC");
124  CREATE_STRINGCONSTANT("DC");
125 
126  // ParticleMatterInteraction / TYPE
127  CREATE_STRINGCONSTANT("SCATTERING");
128  CREATE_STRINGCONSTANT("BEAMSTRIPPING");
129 
130  // FieldSolver / FSTYPE
131  CREATE_STRINGCONSTANT("FFT");
132  CREATE_STRINGCONSTANT("FFTPERIODIC");
133  CREATE_STRINGCONSTANT("SAAMG");
134  // additionally: NONE
135 
136  // FieldSolver / BCFFT
137  CREATE_STRINGCONSTANT("OPEN");
138  CREATE_STRINGCONSTANT("DIRICHLET");
139  CREATE_STRINGCONSTANT("PERIODIC");
140 
141  // FieldSolver / GREENSF
142  CREATE_STRINGCONSTANT("STANDARD");
143  CREATE_STRINGCONSTANT("INTEGRATED");
144 
145  // FieldSolver / ITSOLVER
146  CREATE_STRINGCONSTANT("CG");
147  CREATE_STRINGCONSTANT("BICGSTAB");
148  CREATE_STRINGCONSTANT("GMRES");
149 
150  // FieldSolver / INTERPL
151  CREATE_STRINGCONSTANT("CONSTANT");
152  CREATE_STRINGCONSTANT("LINEAR");
153  CREATE_STRINGCONSTANT("QUADRATIC");
154 
155  // FieldSolver / PRECMODE
156  CREATE_STRINGCONSTANT("STD");
157  CREATE_STRINGCONSTANT("HIERARCHY");
158  CREATE_STRINGCONSTANT("REUSE");
159 
160  // FieldSolver / AMR_MG_SMOOTHER
161  CREATE_STRINGCONSTANT("GS");
162  CREATE_STRINGCONSTANT("SGS");
163  CREATE_STRINGCONSTANT("JACOBI");
164 
165  // FieldSolver / AMR_MG_PREC
166  CREATE_STRINGCONSTANT("ILUT");
167  CREATE_STRINGCONSTANT("CHEBYSHEV");
168  CREATE_STRINGCONSTANT("RILUK");
169  CREATE_STRINGCONSTANT("BLOCK_JACOBI");
170  CREATE_STRINGCONSTANT("BLOCK_GS");
171  CREATE_STRINGCONSTANT("SA");
172  // additionally: NONE, JACOBI, GS
173 
174  // FieldSolver / AMR_MG_INTERP
175  CREATE_STRINGCONSTANT("TRILINEAR");
176  CREATE_STRINGCONSTANT("LAGRANGE");
177  CREATE_STRINGCONSTANT("PC");
178 
179  // FieldSolver / AMR_MG_NORM
180  CREATE_STRINGCONSTANT("L1_NORM");
181  CREATE_STRINGCONSTANT("L2_NORM");
182  CREATE_STRINGCONSTANT("LINF_NORM");
183 
184  // FieldSolver / AMR_MG_REUSE
185  CREATE_STRINGCONSTANT("RP");
186  CREATE_STRINGCONSTANT("RAP");
187  // additionally: NONE
188 
189  // Option / PSDUMPFRAME
190  CREATE_STRINGCONSTANT("GLOBAL");
191  CREATE_STRINGCONSTANT("BUNCH_MEAN");
192  CREATE_STRINGCONSTANT("REFERENCE");
193 
194  // OpalFilter / TYPE
195  // CREATE_STRINGCONSTANT("SAVITZKY-GOLAY");
196  CREATE_STRINGCONSTANT("FIXEDFFTLOWPASS");
197  CREATE_STRINGCONSTANT("RELATIVEFFTLOWPASS");
198  CREATE_STRINGCONSTANT("STENCIL");
199 
200  // TrackRun / METHOD
201  CREATE_STRINGCONSTANT("THICK");
202  // CREATE_STRINGCONSTANT("OPAL-T");
203  // CREATE_STRINGCONSTANT("PARALLEL-T");
204  // CREATE_STRINGCONSTANT("OPAL-CYCL");
205  // CREATE_STRINGCONSTANT("CYCLOTRON-T");
206 
207  // TrackRun / MBMODE
208  CREATE_STRINGCONSTANT("FORCE");
209  CREATE_STRINGCONSTANT("AUTO");
210 
211  // TrackRun / MB_BINNING
212  CREATE_STRINGCONSTANT("GAMMA_BINNING");
213  CREATE_STRINGCONSTANT("BUNCH_BINNING");
214 
215  // ParticleMatterInteraction / MATERIAL
216  CREATE_STRINGCONSTANT("AIR");
217  CREATE_STRINGCONSTANT("ALUMINAAL2O3");
218  CREATE_STRINGCONSTANT("ALUMINUM");
219  CREATE_STRINGCONSTANT("BERYLLIUM");
220  CREATE_STRINGCONSTANT("BORONCARBIDE");
221  CREATE_STRINGCONSTANT("COPPER");
222  CREATE_STRINGCONSTANT("GOLD");
223  CREATE_STRINGCONSTANT("GRAPHITE");
224  CREATE_STRINGCONSTANT("GRAPHITER6710");
225  CREATE_STRINGCONSTANT("KAPTON");
226  CREATE_STRINGCONSTANT("MOLYBDENUM");
227  CREATE_STRINGCONSTANT("MYLAR");
228  CREATE_STRINGCONSTANT("TITANIUM");
229  CREATE_STRINGCONSTANT("WATER");
230 
231  // TrackCmd / TIMEINTEGRATOR
232  CREATE_STRINGCONSTANT("RK_4");
233  CREATE_STRINGCONSTANT("LF_2");
234  CREATE_STRINGCONSTANT("MTS");
235 
236  // OpalVacuum / GAS
237  CREATE_STRINGCONSTANT("H2");
238  // additionally: AIR
239 
240  // BoundaryGeometry / TOPO
241  CREATE_STRINGCONSTANT("RECTANGULAR");
242  CREATE_STRINGCONSTANT("BOXCORNER");
243  CREATE_STRINGCONSTANT("ELLIPTIC");
244 
245  // DumpEMFields / COORDINATE_SYSTEM
246  CREATE_STRINGCONSTANT("CARTESIAN");
247  CREATE_STRINGCONSTANT("CYLINDRICAL");
248 }
249 
251  ValueDefinition(name, parent)
252 {}
253 
254 
255 StringConstant::StringConstant(const std::string &name, StringConstant *parent, const std::string &value):
256  ValueDefinition(name, parent)
257 {
259  itsAttr[0].setReadOnly(true);
260  builtin = true;
261 }
262 
263 
265 {}
266 
267 
269  return false;
270 }
271 
272 
274  return new StringConstant(name, this);
275 }
276 
277 
278 std::string StringConstant::getString() const {
279  return Attributes::getString(itsAttr[0]);
280 }
281 
282 
283 void StringConstant::print(std::ostream &os) const {
284  os << "STRING " << getOpalName() << '=' << itsAttr[0] << ';';
285  os << std::endl;
286 }
287 
288 void StringConstant::printValue(std::ostream &os) const {
289  os << itsAttr[0];
290 }
#define CREATE_STRINGCONSTANT(x)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
void setString(Attribute &attr, const std::string &val)
Set string value.
Definition: Attributes.cpp:391
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
std::string getGitRevision()
Definition: Util.cpp:18
The base class for all OPAL objects.
Definition: Object.h:48
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
bool builtin
Built-in flag.
Definition: Object.h:233
The global OPAL structure.
Definition: OpalData.h:49
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:475
static OpalData * getInstance()
Definition: OpalData.cpp:195
The base class for all OPAL value definitions.
Attribute & value()
Return the attribute representing the value of the definition.
virtual std::string getString() const
Return value.
virtual StringConstant * clone(const std::string &name)
Make clone.
virtual void print(std::ostream &) const
Print the constant.
virtual ~StringConstant()
StringConstant()
Exemplar constructor.
virtual void printValue(std::ostream &os) const
Print its value.
virtual bool canReplaceBy(Object *object)
Test if object can be replaced.