OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
33 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(
64 "OPALVERSION", this,
66 opal->create(new RealConstant("RANK", this, ippl::Comm->rank()));
67}
68
69RealConstant::RealConstant(const std::string& name, RealConstant* parent)
70 : ValueDefinition(name, parent) {
71}
72
73RealConstant::RealConstant(const std::string& name, RealConstant* parent, double value)
74 : ValueDefinition(name, parent) {
76 itsAttr[0].setReadOnly(true);
77 builtin = true;
78}
79
82
84 return false;
85}
86
87RealConstant* RealConstant::clone(const std::string& name) {
88 return new RealConstant(name, this);
89}
90
91double RealConstant::getReal() const {
93}
94
95void RealConstant::print(std::ostream& os) const {
96 os << "REAL CONST " << getOpalName() << '=' << itsAttr[0] << ';';
97 os << std::endl;
98}
99
100void RealConstant::printValue(std::ostream& os) const {
101 os << itsAttr[0];
102}
#define OPAL_VERSION_PATCH
Definition OPALconfig.h:8
#define OPAL_VERSION_MINOR
Definition OPALconfig.h:7
#define OPAL_VERSION_MAJOR
Definition OPALconfig.h:6
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
void setReal(Attribute &attr, double val)
Set real value.
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
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:189
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:308
Object(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Object.cpp:354
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:45
void create(Object *newObject)
Create new object.
Definition OpalData.cpp:473
static OpalData * getInstance()
Definition OpalData.cpp:195
ValueDefinition(int size, const char *name, const char *help)
Constructor for exemplars.
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.