OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 "BuildInfo.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,
65 buildinfo::version_major * 10000 + buildinfo::version_minor * 100
66 + buildinfo::version_patch));
67 opal->create(new RealConstant("RANK", this, ippl::Comm->rank()));
68}
69
70RealConstant::RealConstant(const std::string& name, RealConstant* parent)
71 : ValueDefinition(name, parent) {}
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
81
82bool RealConstant::canReplaceBy(Object*) { return false; }
83
84RealConstant* RealConstant::clone(const std::string& name) { return new RealConstant(name, this); }
85
87
88void RealConstant::print(std::ostream& os) const {
89 os << "REAL CONST " << getOpalName() << '=' << itsAttr[0] << ';';
90 os << std::endl;
91}
92
93void RealConstant::printValue(std::ostream& os) const { os << itsAttr[0]; }
The base class for all OPAL objects.
Definition Object.h:45
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:169
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
bool builtin
Built-in flag.
Definition Object.h:226
The global OPAL structure.
Definition OpalData.h:45
void create(Object *newObject)
Create new object.
Definition OpalData.cpp:387
static OpalData * getInstance()
Definition OpalData.cpp:193
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.
The base class for all OPAL value definitions.
Attribute & value()
Return the attribute representing the value of the definition.
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:147
constexpr double m_alpha
The alpha particle rest mass in GeV.
Definition Physics.h:150
constexpr double m_u
The uranium-238 (fully-stripped) rest mass in GeV.
Definition Physics.h:126
constexpr double amu
The atomic mass unit energy equivalent in GeV.
Definition Physics.h:90
constexpr double two_pi
The value of.
Definition Physics.h:40
constexpr double m_p
The proton rest mass in GeV.
Definition Physics.h:105
constexpr double m_h2p
The H2+ rest mass in GeV.
Definition Physics.h:156
constexpr double m_e
The electron rest mass in GeV.
Definition Physics.h:93
constexpr double m_hm
The H- rest mass in GeV.
Definition Physics.h:123
constexpr double m_mu
The muon rest mass in GeV.
Definition Physics.h:129
constexpr double e
The value of.
Definition Physics.h:49
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60
constexpr double m_c
The carbon-12 (fully-stripped) rest mass in GeV.
Definition Physics.h:120
constexpr double m_d
The deuteron rest mass in GeV.
Definition Physics.h:144
constexpr double pi
The value of.
Definition Physics.h:36
constexpr double rad2deg
Definition Units.h:146
constexpr double deg2rad
Definition Units.h:143