OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RealConstant.cpp
Go to the documentation of this file.
1//
2// Class RealConstant
3// The REAL 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
22#include "OPALconfig.h"
23#include "Physics/Physics.h"
24#include "Physics/Units.h"
25#include "Utilities/Options.h"
26#include "Utility/IpplInfo.h"
27
28#include <cmath>
29#include <iostream>
30
31
33 ValueDefinition(1, "REAL_CONSTANT",
34 "The \"REAL CONSTANT\" statement defines a global "
35 "real constant:\n"
36 "\tREAL CONSTANT <name> = <real-expression>;\n") {
37 itsAttr[0] = Attributes::makeReal("VALUE", "The constant value", 0.0);
38
40
41 // Define the standard constants.
43 opal->create(new RealConstant("PI", this, Physics::pi));
44 opal->create(new RealConstant("TWOPI", this, Physics::two_pi));
45 opal->create(new RealConstant("RADDEG", this, Units::rad2deg));
46 opal->create(new RealConstant("DEGRAD", this, Units::deg2rad));
47 opal->create(new RealConstant("E", this, Physics::e));
48
49 opal->create(new RealConstant("MUMASS", this, Physics::m_mu));
50 opal->create(new RealConstant("EMASS", this, Physics::m_e));
51 opal->create(new RealConstant("PMASS", this, Physics::m_p));
52 opal->create(new RealConstant("HMMASS", this, Physics::m_hm));
53 opal->create(new RealConstant("H2PMASS", this, Physics::m_h2p));
54 opal->create(new RealConstant("DMASS", this, Physics::m_d));
55 opal->create(new RealConstant("ALPHAMASS", this, Physics::m_alpha));
56 opal->create(new RealConstant("CMASS", this, Physics::m_c));
57 opal->create(new RealConstant("XEMASS", this, Physics::m_xe));
58 opal->create(new RealConstant("UMASS", this, Physics::m_u));
59
60 opal->create(new RealConstant("CLIGHT", this, Physics::c));
61 opal->create(new RealConstant("AMU", this, Physics::amu));
62
63 opal->create(new RealConstant("OPALVERSION", this, OPAL_VERSION_MAJOR * 10000
64 + OPAL_VERSION_MINOR * 100
66 opal->create(new RealConstant("RANK", this, Ippl::myNode()));
67}
68
69
70RealConstant::RealConstant(const std::string &name, RealConstant *parent):
71 ValueDefinition(name, parent)
72{}
73
74
75RealConstant::RealConstant(const std::string &name, RealConstant *parent,
76 double value):
77 ValueDefinition(name, parent) {
79 itsAttr[0].setReadOnly(true);
80 builtin = true;
81}
82
83
85{}
86
87
89 return false;
90}
91
92
94 return new RealConstant(name, this);
95}
96
97
98double RealConstant::getReal() const {
100}
101
102
103void RealConstant::print(std::ostream &os) const {
104 os << "REAL CONST " << getOpalName() << '=' << itsAttr[0] << ';';
105 os << std::endl;
106}
107
108void RealConstant::printValue(std::ostream &os) const {
109 os << itsAttr[0];
110}
#define OPAL_VERSION_PATCH
Definition: OPALconfig.h:8
#define OPAL_VERSION_MINOR
Definition: OPALconfig.h:7
#define OPAL_VERSION_MAJOR
Definition: OPALconfig.h:6
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:271
constexpr double m_xe
The xenon-129 (fully-stripped) rest mass in GeV.
Definition: Physics.h:120
constexpr double m_alpha
The alpha particle rest mass in GeV.
Definition: Physics.h:123
constexpr double m_u
The uranium-238 (fully-stripped) rest mass in GeV.
Definition: Physics.h:111
constexpr double amu
The atomic mass unit energy equivalent in GeV.
Definition: Physics.h:75
constexpr double two_pi
The value of.
Definition: Physics.h:33
constexpr double m_p
The proton rest mass in GeV.
Definition: Physics.h:90
constexpr double m_h2p
The H2+ rest mass in GeV.
Definition: Physics.h:129
constexpr double m_e
The electron rest mass in GeV.
Definition: Physics.h:78
constexpr double m_hm
The H- rest mass in GeV.
Definition: Physics.h:108
constexpr double m_mu
The muon rest mass in GeV.
Definition: Physics.h:114
constexpr double e
The value of.
Definition: Physics.h:39
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
constexpr double m_c
The carbon-12 (fully-stripped) rest mass in GeV.
Definition: Physics.h:105
constexpr double m_d
The deuteron rest mass in GeV.
Definition: Physics.h:117
constexpr double pi
The value of.
Definition: Physics.h:30
constexpr double rad2deg
Definition: Units.h:146
constexpr double deg2rad
Definition: Units.h:143
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:310
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:476
static OpalData * getInstance()
Definition: OpalData.cpp:196
The base class for all OPAL value definitions.
Attribute & value()
Return the attribute representing the value of the definition.
virtual void print(std::ostream &) const
Print the constant.
virtual ~RealConstant()
RealConstant()
Exemplar constructor.
virtual double getReal() const
Return value.
virtual void printValue(std::ostream &os) const
Print its value.
virtual bool canReplaceBy(Object *object)
Test if object can be replaced.
virtual RealConstant * clone(const std::string &name)
Make clone.
static int myNode()
Definition: IpplInfo.cpp:691