BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldFormat.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSFieldFormat.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh"
24#include "G4String.hh"
25
26#include <map>
27#include <string>
28
29// dictionary for BDSFieldFormat for reflexivity
30template<>
31std::map<BDSFieldFormat, std::string>* BDSFieldFormat::dictionary =
32 new std::map<BDSFieldFormat, std::string> ({
33 {BDSFieldFormat::none, "none"},
34 {BDSFieldFormat::bdsim1d, "bdsim1d"},
35 {BDSFieldFormat::bdsim2d, "bdsim2d"},
36 {BDSFieldFormat::bdsim3d, "bdsim3d"},
37 {BDSFieldFormat::bdsim4d, "bdsim4d"},
38 {BDSFieldFormat::poisson2d, "poisson2d"},
39 {BDSFieldFormat::poisson2dquad, "poisson2dquad"},
40 {BDSFieldFormat::poisson2ddipole, "poisson2ddipole"}
41});
42
44{
45 std::map<G4String, BDSFieldFormat> formats;
46 formats["none"] = BDSFieldFormat::none;
47 formats["bdsim1d"] = BDSFieldFormat::bdsim1d;
48 formats["bdsim2d"] = BDSFieldFormat::bdsim2d;
49 formats["bdsim3d"] = BDSFieldFormat::bdsim3d;
50 formats["bdsim4d"] = BDSFieldFormat::bdsim4d;
51 formats["poisson2d"] = BDSFieldFormat::poisson2d;
52 formats["poisson2dquad"] = BDSFieldFormat::poisson2dquad;
53 formats["poisson2ddipole"] = BDSFieldFormat::poisson2ddipole;
54
55 bFormat = BDS::LowerCase(bFormat);
56
57 auto result = formats.find(bFormat);
58 if (result == formats.end())
59 {
60 // it's not a valid key
61 G4cerr << __METHOD_NAME__ << "\"" << bFormat
62 << "\" is not a valid field format" << G4endl;
63 G4cout << "Available field formats are:" << G4endl;
64 for (auto it : formats)
65 {G4cout << "\"" << it.first << "\"" << G4endl;}
66 throw BDSException(__METHOD_NAME__, "can't determine field type");
67 }
68
69#ifdef BDSDEBUG
70 G4cout << __METHOD_NAME__ << "determined field format to be " << result->second << G4endl;
71#endif
72 return result->second;
73}
74
76{
77 G4int result = 0;
78 switch (ff.underlying())
79 {
80 case BDSFieldFormat::bdsim1d:
81 {result = 1; break;}
82 case BDSFieldFormat::bdsim2d:
83 case BDSFieldFormat::poisson2d:
84 case BDSFieldFormat::poisson2dquad:
85 case BDSFieldFormat::poisson2ddipole:
86 {result = 2; break;}
87 case BDSFieldFormat::bdsim3d:
88 {result = 3; break;}
89 case BDSFieldFormat::bdsim4d:
90 {result = 4; break;}
91 case BDSFieldFormat::none:
92 default:
93 {result = 0; break;}
94 }
95 return result;
96}
General exception with possible name of object and message.
static std::map< BDSTypeSafeEnum< fieldformats_def, int >, std::string > * dictionary
type underlying() const
return underlying value (can be used in switch statement)
BDSFieldFormat DetermineFieldFormat(G4String fieldformat)
Function that gives corresponding enum value for string (case-insensitive)
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
G4int NDimensionsOfFieldFormat(const BDSFieldFormat &ff)
Report the number of dimensions for that format.