OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RealConstant.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: RealConstant.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: RealConstant
10 // Implements a REAL_CONSTANT definition.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:26:42 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
21 #include "Attributes/Attributes.h"
22 #include "Utilities/Options.h"
23 #include "Physics/Physics.h"
24 #include "OPALconfig.h"
25 
26 #include "Utility/IpplInfo.h"
27 
28 #include <cmath>
29 #include <iostream>
30 
31 // Class RealConstant
32 // ------------------------------------------------------------------------
33 
35  ValueDefinition(1, "REAL_CONSTANT",
36  "The \"REAL CONSTANT\" statement defines a global "
37  "real constant:\n"
38  "\tREAL CONSTANT <name> = <real-expression>;\n") {
39  itsAttr[0] = Attributes::makeReal("VALUE", "The constant value", 0.0);
40 
42 
43  // Define the standard constants.
45  opal->create(new RealConstant("PI", this, Physics::pi));
46  opal->create(new RealConstant("TWOPI", this, Physics::two_pi));
47  opal->create(new RealConstant("RADDEG", this, 180.0 / Physics::pi));
48  opal->create(new RealConstant("DEGRAD", this, Physics::pi / 180.0));
49  opal->create(new RealConstant("E", this, Physics::e));
50 
51  opal->create(new RealConstant("EMASS", this, Physics::m_e));
52  opal->create(new RealConstant("PMASS", this, Physics::m_p));
53  opal->create(new RealConstant("HMMASS", this, Physics::m_hm));
54  opal->create(new RealConstant("UMASS", this, Physics::m_u));
55  opal->create(new RealConstant("CMASS", this, Physics::m_c));
56  opal->create(new RealConstant("MMASS", this, Physics::m_mu));
57  opal->create(new RealConstant("DMASS", this, Physics::m_d));
58  opal->create(new RealConstant("XEMASS", this, Physics::m_xe));
59 
60  opal->create(new RealConstant("CLIGHT", this, Physics::c));
61 
62  opal->create(new RealConstant("OPALVERSION", this, OPAL_VERSION_MAJOR * 10000
63  + OPAL_VERSION_MINOR * 100
65  opal->create(new RealConstant("RANK", this, Ippl::myNode()));
66 }
67 
68 
69 RealConstant::RealConstant(const std::string &name, RealConstant *parent):
70  ValueDefinition(name, parent)
71 {}
72 
73 
74 RealConstant::RealConstant(const std::string &name, RealConstant *parent,
75  double value):
76  ValueDefinition(name, parent) {
77  Attributes::setReal(itsAttr[0], value);
78  itsAttr[0].setReadOnly(true);
79  builtin = true;
80 }
81 
82 
84 {}
85 
86 
88  return false;
89 }
90 
91 
92 RealConstant *RealConstant::clone(const std::string &name) {
93  return new RealConstant(name, this);
94 }
95 
96 
97 double RealConstant::getReal() const {
98  return Attributes::getReal(itsAttr[0]);
99 }
100 
101 
102 void RealConstant::print(std::ostream &os) const {
103  os << "REAL CONST " << getOpalName() << '=' << itsAttr[0] << ';';
104  os << std::endl;
105 }
106 
107 void RealConstant::printValue(std::ostream &os) const {
108  os << itsAttr[0];
109 }
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:236
The global OPAL structure.
Definition: OpalData.h:54
constexpr double e
The value of .
Definition: Physics.h:40
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:524
constexpr double m_hm
The H- rest mass in GeV.
Definition: Physics.h:115
virtual RealConstant * clone(const std::string &name)
Make clone.
constexpr double m_d
The deuteron rest mass in GeV.
Definition: Physics.h:124
constexpr double m_u
The uranium rest mass in GeV.
Definition: Physics.h:118
constexpr double two_pi
The value of .
Definition: Physics.h:34
virtual double getReal() const
Return value.
constexpr double m_p
The proton rest mass in GeV.
Definition: Physics.h:97
static int myNode()
Definition: IpplInfo.cpp:794
constexpr double m_mu
The muon rest mass in GeV.
Definition: Physics.h:121
virtual bool canReplaceBy(Object *object)
Test if object can be replaced.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
#define OPAL_VERSION_MINOR
Definition: OPALconfig.h:7
virtual ~RealConstant()
constexpr double m_e
The electron rest mass in GeV.
Definition: Physics.h:85
static OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
constexpr double pi
The value of .
Definition: Physics.h:31
#define OPAL_VERSION_PATCH
Definition: OPALconfig.h:8
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
The REAL CONSTANT definition.
Definition: RealConstant.h:27
#define OPAL_VERSION_MAJOR
Definition: OPALconfig.h:6
RealConstant()
Exemplar constructor.
The base class for all OPAL objects.
Definition: Object.h:48
virtual void print(std::ostream &) const
Print the constant.
The base class for all OPAL value definitions.
const std::string name
constexpr double m_xe
The xenon rest mass in GeV.
Definition: Physics.h:127
bool builtin
Built-in flag.
Definition: Object.h:231
constexpr double m_c
The carbon rest mass in GeV.
Definition: Physics.h:112
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
virtual void printValue(std::ostream &os) const
Print its value.
Inform & endl(Inform &inf)
Definition: Inform.cpp:42