OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
ParticleMatterInteraction.cpp
Go to the documentation of this file.
1 //
2 // Class ParticleMatterInteraction
3 // The class for the OPAL PARTICLEMATTERINTERACTION command.
4 //
5 // Copyright (c) 2012 - 2021, Andreas Adelmann, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // Christof Metzger-Kraus, Helmholtz-Zentrum Berlin
7 // Pedro Calvo, CIEMAT, Spain
8 // All rights reserved
9 //
10 // Implemented as part of the PhD thesis
11 // "Optimizing the radioisotope production of the novel AMIT
12 // superconducting weak focusing cyclotron"
13 //
14 // This file is part of OPAL.
15 //
16 // OPAL is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
23 //
25 
28 #include "Attributes/Attributes.h"
32 #include "Utilities/Util.h"
33 
34 #include <map>
35 #include <string>
36 
37 extern Inform* gmsg;
38 
39 namespace {
40  enum {
41  // DESCRIPTION OF PARTICLE MATTER INTERACTION:
42  TYPE,
43  MATERIAL,
44  ENABLERUTHERFORD,
45  LOWENERGYTHR,
46  SIZE
47  };
48 }
49 
51  Definition(SIZE, "PARTICLEMATTERINTERACTION",
52  "The \"PARTICLEMATTERINTERACTION\" statement defines data for "
53  "the particle matter interaction handler on an element."),
54  handler_m(0) {
56  ("TYPE", "Specifies the particle matter interaction handler.",
57  {"SCATTERING", "BEAMSTRIPPING"});
58 
60  ("MATERIAL", "The material of the surface.",
61  {"AIR",
62  "ALUMINAAL2O3",
63  "ALUMINUM",
64  "BERYLLIUM",
65  "BORONCARBIDE",
66  "COPPER",
67  "GOLD",
68  "GRAPHITE",
69  "GRAPHITER6710",
70  "KAPTON",
71  "MOLYBDENUM",
72  "MYLAR",
73  "TITANIUM",
74  "WATER"});
75 
76  itsAttr[ENABLERUTHERFORD] = Attributes::makeBool
77  ("ENABLERUTHERFORD", "Enable large angle scattering", true);
78 
79  itsAttr[LOWENERGYTHR] = Attributes::makeReal
80  ("LOWENERGYTHR", "Lower Energy threshold for energy loss calculation [MeV]. Default = 0.01 MeV", 0.01);
81 
82  ParticleMatterInteraction* defParticleMatterInteraction = clone("UNNAMED_PARTICLEMATTERINTERACTION");
83  defParticleMatterInteraction->builtin = true;
84 
85  try {
86  defParticleMatterInteraction->update();
87  OpalData::getInstance()->define(defParticleMatterInteraction);
88  } catch(...) {
89  delete defParticleMatterInteraction;
90  }
91 
93 }
94 
95 
97  Definition(name, parent),
98  handler_m(parent->handler_m)
99 {}
100 
101 
103  if (handler_m)
104  delete handler_m;
105 }
106 
107 
109  // Can replace only by another PARTICLEMATTERINTERACTION.
110  return dynamic_cast<ParticleMatterInteraction*>(object) != 0;
111 }
112 
113 
115  return new ParticleMatterInteraction(name, this);
116 }
117 
118 
120  update();
121 }
122 
123 
125  ParticleMatterInteraction* parmatint =
126  dynamic_cast<ParticleMatterInteraction*>(OpalData::getInstance()->find(name));
127 
128  if (parmatint == 0) {
129  throw OpalException("ParticleMatterInteraction::find()",
130  "ParticleMatterInteraction \"" + name + "\" not found.");
131  }
132  return parmatint;
133 }
134 
135 
137  // Set default name.
138  if (getOpalName().empty()) setOpalName("UNNAMED_PARTICLEMATTERINTERACTION");
139 }
140 
142  static const std::map<std::string, ParticleMatterInteraction::InteractionType> stringInteractionType_s = {
143  {"SCATTERING", InteractionType::SCATTERING},
144  {"BEAMSTRIPPING", InteractionType::BEAMSTRIPPING}
145  };
146 
147  const std::string type = Attributes::getString(itsAttr[TYPE]);
148  if (type.empty()) {
149  throw OpalException("ParticleMatterInteraction::getInteractionType",
150  "The attribute \"TYPE\" isn't set for \"PARTICLEMATTERINTERACTION\"!");
151  } else {
152  type_m = stringInteractionType_s.at(type);
153  }
154 }
155 
157 
159 
160  switch (type_m) {
162  std::string material = Attributes::getString(itsAttr[MATERIAL]);
163  bool enableRutherford = Attributes::getBool(itsAttr[ENABLERUTHERFORD]);
164  double lowEnergyThr = Attributes::getReal(itsAttr[LOWENERGYTHR]);
165  handler_m = new ScatteringPhysics(getOpalName(), &element, material, enableRutherford, lowEnergyThr);
166  break;
167  }
169  handler_m = new BeamStrippingPhysics(getOpalName(), &element);
170  break;
171  }
172  default: {
173  throw OpalException("ParticleMatterInteraction::initParticleMatterInteractionHandler",
174  "Invalid \"TYPE\" of \"PARTICLEMATTERINTERACTION\" command");
175  }
176  }
177  *gmsg << *this << endl;
178 }
179 
181  handler_m->updateElement(element);
182 }
183 
184 void ParticleMatterInteraction::print(std::ostream& os) const {
185  os << "\n";
186  os << "* ************* P A R T I C L E M A T T E R I N T E R A C T I O N **************** " << std::endl;
187  os << "* PARTICLEMATTERINTERACTION " << getOpalName() << '\n'
188  << "* TYPE " << Attributes::getString(itsAttr[TYPE]) << '\n'
189  << "* ELEMENT " << handler_m->getElement()->getName() << '\n';
191  os << "* MATERIAL " << Attributes::getString(itsAttr[MATERIAL]) << '\n';
192  os << "* ENABLERUTHERFORD " << Util::boolToUpperString(Attributes::getBool(itsAttr[ENABLERUTHERFORD])) << '\n';
193  os << "* LOWENERGYTHR " << Attributes::getReal(itsAttr[LOWENERGYTHR]) << " [MeV]\n";
194  }
195  os << "* ********************************************************************************** " << std::endl;
196 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
static OpalData * getInstance()
Definition: OpalData.cpp:196
bool builtin
Built-in flag.
Definition: Object.h:233
void setOpalName(const std::string &name)
Set object name.
Definition: Object.cpp:331
The base class for all OPAL objects.
Definition: Object.h:48
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:489
std::string boolToUpperString(const bool &b)
Definition: Util.cpp:154
virtual void update()
Update the PARTICLEMATTERINTERACTION data.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
virtual const std::string & getName() const
Get element name.
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
void updateElement(ElementBase *element)
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual void execute()
Check the PARTICLEMATTERINTERACTION data.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Definition: Attributes.cpp:409
Definition: Inform.h:42
void initParticleMatterInteractionHandler(ElementBase &element)
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:310
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
ParticleMatterInteractionHandler * handler_m
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
The base class for all OPAL definitions.
Definition: Definition.h:30
ParticleMatterInteraction()
Exemplar constructor.
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:571
void print(std::ostream &os) const
Print the object.
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
SDDS1 &description type
Definition: test.stat:4
Inform * gmsg
Definition: Main.cpp:70