OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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"
29 #include "Physics/Physics.h"
33 #include "Utilities/Util.h"
34 
35 extern Inform* gmsg;
36 
37 namespace {
38  enum {
39  // DESCRIPTION OF PARTICLE MATTER INTERACTION:
40  TYPE,
41  MATERIAL,
42  ENABLERUTHERFORD,
43  LOWENERGYTHR,
44  SIZE
45  };
46 }
47 
49  Definition(SIZE, "PARTICLEMATTERINTERACTION",
50  "The \"PARTICLEMATTERINTERACTION\" statement defines data for "
51  "the particle matter interaction handler on an element."),
52  handler_m(0) {
54  ("TYPE", "Specifies the particle matter interaction handler.", {"SCATTERING", "BEAMSTRIPPING"});
55 
57  ("MATERIAL", "The material of the surface.",
58  {"AIR",
59  "ALUMINAAL2O3",
60  "ALUMINUM",
61  "BERYLLIUM",
62  "BORONCARBIDE",
63  "COPPER",
64  "GOLD",
65  "GRAPHITE",
66  "GRAPHITER6710",
67  "KAPTON",
68  "MOLYBDENUM",
69  "MYLAR",
70  "TITANIUM",
71  "WATER"});
72  itsAttr[ENABLERUTHERFORD] = Attributes::makeBool
73  ("ENABLERUTHERFORD", "Enable large angle scattering", true);
74 
75  itsAttr[LOWENERGYTHR] = Attributes::makeReal
76  ("LOWENERGYTHR", "Lower Energy threshold for energy loss calculation [MeV]. Default = 0.01 MeV", 0.01);
77 
78  ParticleMatterInteraction* defParticleMatterInteraction = clone("UNNAMED_PARTICLEMATTERINTERACTION");
79  defParticleMatterInteraction->builtin = true;
80 
81  try {
82  defParticleMatterInteraction->update();
83  OpalData::getInstance()->define(defParticleMatterInteraction);
84  } catch(...) {
85  delete defParticleMatterInteraction;
86  }
87 
89 }
90 
91 
93  Definition(name, parent),
94  handler_m(parent->handler_m)
95 {}
96 
97 
99  if (handler_m)
100  delete handler_m;
101 }
102 
103 
105  // Can replace only by another PARTICLEMATTERINTERACTION.
106  return dynamic_cast<ParticleMatterInteraction*>(object) != 0;
107 }
108 
109 
111  return new ParticleMatterInteraction(name, this);
112 }
113 
114 
116  update();
117 }
118 
119 
122 
123  if (parmatint == 0) {
124  throw OpalException("ParticleMatterInteraction::find()", "ParticleMatterInteraction \"" + name + "\" not found.");
125  }
126  return parmatint;
127 }
128 
129 
131  // Set default name.
132  if (getOpalName().empty()) setOpalName("UNNAMED_PARTICLEMATTERINTERACTION");
133 }
134 
135 
137 
138  const std::string type = Attributes::getString(itsAttr[TYPE]);
139  std::string material = Attributes::getString(itsAttr[MATERIAL]);
140  bool enableRutherford = Attributes::getBool(itsAttr[ENABLERUTHERFORD]);
141  double lowEnergyThr = Attributes::getReal(itsAttr[LOWENERGYTHR]);
142 
143  if (type.empty()) {
144  throw OpalException("ParticleMatterInteraction::initParticleMatterInteractionHandler",
145  "TYPE is not defined for PARTICLEMATTERINTERACTION");
146  } else if (type == "SCATTERING") {
147  handler_m = new ScatteringPhysics(getOpalName(), &element, material, enableRutherford, lowEnergyThr);
148  *gmsg << *this << endl;
149  } else if (type == "BEAMSTRIPPING") {
150  handler_m = new BeamStrippingPhysics(getOpalName(), &element);
151  *gmsg << *this << endl;
152  }
153 }
154 
156  handler_m->updateElement(element);
157 }
158 
159 void ParticleMatterInteraction::print(std::ostream& os) const {
160  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;
161  os << "* PARTICLEMATTERINTERACTION " << getOpalName() << '\n'
162  << "* TYPE " << Attributes::getString(itsAttr[TYPE]) << '\n'
163  << "* ELEMENT " << handler_m->getElement()->getName() << '\n';
164  if ( Attributes::getString(itsAttr[TYPE]) == "SCATTERING" ) {
165  os << "* MATERIAL " << Attributes::getString(itsAttr[MATERIAL]) << '\n';
166  os << "* LOWENERGYTHR " << Attributes::getReal(itsAttr[LOWENERGYTHR]) << " MeV\n";
167  }
168  os << "* ********************************************************************************** " << std::endl;
169 }
@ SIZE
Definition: IndexMap.cpp:174
Inform * gmsg
Definition: Main.cpp:62
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
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
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
The base class for all OPAL definitions.
Definition: Definition.h:30
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
void setOpalName(const std::string &name)
Set object name.
Definition: Object.cpp:302
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
bool builtin
Built-in flag.
Definition: Object.h:233
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:565
static OpalData * getInstance()
Definition: OpalData.cpp:195
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:488
virtual const std::string & getName() const
Get element name.
virtual void execute()
Check the PARTICLEMATTERINTERACTION data.
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
virtual void update()
Update the PARTICLEMATTERINTERACTION data.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
ParticleMatterInteractionHandler * handler_m
ParticleMatterInteraction()
Exemplar constructor.
void initParticleMatterInteractionHandler(ElementBase &element)
void print(std::ostream &os) const
Print the object.
void updateElement(ElementBase *element)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:42