votca 2024-dev
Loading...
Searching...
No Matches
unitconverter.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17#pragma once
18#ifndef VOTCA_TOOLS_UNITCONVERTER_H
19#define VOTCA_TOOLS_UNITCONVERTER_H
20
21// Standard includes
22#include <map>
23
24namespace votca {
25namespace tools {
26
28
34 grams_per_mole, // the same as atomic mass units
36 grams
37};
38
40
41// Extrinsic Energy Units
48};
49
50// Intrinsic Energy Units
57};
58
60
65};
66
67// Extrinsic Force Units
74};
75
76// Intrinsic Force Units
83};
84
89 private:
91 constexpr double getDistanceValue_(
92 const DistanceUnit& enum_type) const noexcept {
93 switch (enum_type) {
95 return 1E-10;
97 return 1E-8;
99 return 0.1;
101 return 1.0;
103 return 1.8897161646321;
104 }
105 return 0.0;
106 }
107
109 constexpr double getTimeValue_(const TimeUnit& enum_type) const noexcept {
110 switch (enum_type) {
112 return 1E-12;
114 return 1E-6;
116 return 1E-3;
118 return 1.0;
120 return 1000;
121 }
122 return 0.0;
123 }
124
126 constexpr double getMassValue_(const MassUnit& enum_type) const noexcept {
127 switch (enum_type) {
129 return 1.6605402E-27;
130 case MassUnit::grams:
131 return 1.6605402E-24;
133 return 1.6605402E-12;
135 return 1.6605402E-9;
137 return 1.66054019E-6;
139 return 1.0;
141 return 1.0;
142 }
143 return 0.0;
144 }
145
147 constexpr double getEnergyValue_(const EnergyUnit& enum_type) const noexcept {
148 switch (enum_type) {
150 return 3.82929389E-23;
152 return 1.602176634E-22;
154 return 1.602176634E-19;
156 return 0.0367493;
158 return 1.0;
159 }
160 return 0.0;
161 }
162
163 // All molar energies in terms of eV_per_mole
164 constexpr double getMolarEnergyValue_(
165 const MolarEnergyUnit& enum_type) const noexcept {
166 switch (enum_type) {
168 return 1.602176634E-22;
170 return 1.602176634E-19;
172 return 3.82929389E-23;
174 return 0.0367493;
176 return 1.0;
177 }
178 return 0.0;
179 }
181 constexpr double getChargeValue_(const ChargeUnit& enum_type) const noexcept {
182 switch (enum_type) {
183 case ChargeUnit::e:
184 return 1;
186 return 1.602176565E-19;
187 }
188 return 0.0;
189 }
190
192 constexpr double getVelocityValue_(
193 const VelocityUnit& enum_type) const noexcept {
194 switch (enum_type) {
196 return 1.0;
202 }
203 return 0.0;
204 }
205
207 constexpr double getForceValue_(const ForceUnit& enum_type) const noexcept {
208 switch (enum_type) {
216 return 1.0;
218 return (1.0) /
223 }
224 return 0.0;
225 }
226
228 constexpr double getMolarForceValue_(
229 const MolarForceUnit& enum_type) const noexcept {
230 switch (enum_type) {
240 return 1.0;
242 return (1.0) /
248 }
249 return 0.0;
250 }
251
252 public:
253 constexpr double convert(const DistanceUnit& from,
254 const DistanceUnit& to) const noexcept {
255 return getDistanceValue_(to) / getDistanceValue_(from);
256 }
257 constexpr double convert(const TimeUnit& from,
258 const TimeUnit& to) const noexcept {
259 return getTimeValue_(to) / getTimeValue_(from);
260 }
261 constexpr double convert(const MassUnit& from,
262 const MassUnit& to) const noexcept {
263 return getMassValue_(to) / getMassValue_(from);
264 }
265 constexpr double convert(const EnergyUnit& from,
266 const EnergyUnit& to) const noexcept {
267 return getEnergyValue_(to) / getEnergyValue_(from);
268 }
269 constexpr double convert(const MolarEnergyUnit& from,
270 const MolarEnergyUnit& to) const noexcept {
272 }
273 constexpr double convert(const ChargeUnit& from,
274 const ChargeUnit& to) const noexcept {
275 return getChargeValue_(to) / getChargeValue_(from);
276 }
277 constexpr double convert(const VelocityUnit& from,
278 const VelocityUnit& to) const noexcept {
279 return getVelocityValue_(to) / getVelocityValue_(from);
280 }
281 constexpr double convert(const ForceUnit& from,
282 const ForceUnit& to) const noexcept {
283 return (getForceValue_(to)) / (getForceValue_(from));
284 }
285 constexpr double convert(const MolarForceUnit& from,
286 const MolarForceUnit& to) const noexcept {
287 return (getMolarForceValue_(to)) / (getMolarForceValue_(from));
288 }
289};
290} // namespace tools
291} // namespace votca
292
293#endif // VOTCA_TOOLS_UNITCONVERTER_H
Class converts between different unit types.
constexpr double convert(const TimeUnit &from, const TimeUnit &to) const noexcept
constexpr double convert(const ForceUnit &from, const ForceUnit &to) const noexcept
constexpr double getEnergyValue_(const EnergyUnit &enum_type) const noexcept
All energies in terms of electron volts.
constexpr double getDistanceValue_(const DistanceUnit &enum_type) const noexcept
All distances with respect to Ang.
constexpr double convert(const MassUnit &from, const MassUnit &to) const noexcept
constexpr double getMolarEnergyValue_(const MolarEnergyUnit &enum_type) const noexcept
constexpr double convert(const EnergyUnit &from, const EnergyUnit &to) const noexcept
constexpr double convert(const MolarEnergyUnit &from, const MolarEnergyUnit &to) const noexcept
constexpr double getMassValue_(const MassUnit &enum_type) const noexcept
All masses with respect to atomic mass units.
constexpr double getChargeValue_(const ChargeUnit &enum_type) const noexcept
All charge in terms of elementary charge e.
constexpr double getForceValue_(const ForceUnit &enum_type) const noexcept
Default force unit is the kilojoules per nanometer.
constexpr double getVelocityValue_(const VelocityUnit &enum_type) const noexcept
All velocities in terms of nanometers per picosecond.
constexpr double convert(const DistanceUnit &from, const DistanceUnit &to) const noexcept
constexpr double convert(const MolarForceUnit &from, const MolarForceUnit &to) const noexcept
constexpr double getTimeValue_(const TimeUnit &enum_type) const noexcept
All times with respect to pico seconds.
constexpr double getMolarForceValue_(const MolarForceUnit &enum_type) const noexcept
Default force unit is the kilojoules per mole nanometer.
constexpr double convert(const VelocityUnit &from, const VelocityUnit &to) const noexcept
constexpr double convert(const ChargeUnit &from, const ChargeUnit &to) const noexcept
@ kilojoules_per_mole_angstrom
@ kilocalories_per_mole_angstrom
@ kilojoules_per_mole_nanometer
@ kilocalories_per_angstrom
@ nanometers_per_picosecond
@ angstroms_per_femtosecond
base class for all analysis tools
Definition basebead.h:33