diff --git a/src/amuse/test/suite/core_tests/test_pickle.py b/src/amuse/test/suite/core_tests/test_pickle.py index eff6d02817..6b88398006 100644 --- a/src/amuse/test/suite/core_tests/test_pickle.py +++ b/src/amuse/test/suite/core_tests/test_pickle.py @@ -1,37 +1,30 @@ -from amuse.test import amusetest - +import subprocess import pickle +import sys +import os -from amuse.support.exceptions import AmuseException +from amuse.test import amusetest -from amuse.units import core from amuse.units import si from amuse.units import nbody_system -from amuse.units import generic_unit_system from amuse.units.quantities import zero -from amuse.units.units import * -from amuse.units.constants import * +from amuse.units.units import m, km, kg, parsec, stellar_type from amuse.datamodel import Particles, parameters -import subprocess -import pickle -import sys -import os - class TestPicklingOfUnitsAndQuantities(amusetest.TestCase): def test1(self): - km = 1000 * m - self.assertEqual(1000, km.value_in(m)) - pickled_km = pickle.dumps(km) - unpickled_km = pickle.loads(pickled_km) - self.assertEqual(1000, unpickled_km.value_in(m)) + kilometer = 1000 * m + self.assertEqual(1000, kilometer.value_in(m)) + pickled_kilometer = pickle.dumps(kilometer) + unpickled_kilometer = pickle.loads(pickled_kilometer) + self.assertEqual(1000, unpickled_kilometer.value_in(m)) def test2(self): - km = 1000 * m - quantity = 12.0 | km + kilometer = 1000 * m + quantity = 12.0 | kilometer self.assertEqual(12000, quantity.value_in(m)) pickled_quantity = pickle.dumps(quantity) unpickled_quantity = pickle.loads(pickled_quantity) @@ -81,7 +74,9 @@ def test8(self): def test9(self): quantity = 1.3 | nbody_system.time - path = os.path.abspath(os.path.join(self.get_path_to_results(), "test9.pickle")) + path = os.path.abspath( + os.path.join(self.get_path_to_results(), "test9.pickle") + ) with open(path, "wb") as stream: pickle.dump(quantity, stream) @@ -89,7 +84,12 @@ def test9(self): pythonpath = os.pathsep.join(sys.path) env = os.environ.copy() env['PYTHONPATH'] = pythonpath - code = "import pickle;stream = open('{0}', 'rb'); print(str(pickle.load(stream)));stream.close()".format(path) + code = ( + f"import pickle;" + f"stream = open('{path}', 'rb');" + f"print(str(pickle.load(stream)));" + f"stream.close()" + ) process = subprocess.Popen([ sys.executable, @@ -100,18 +100,28 @@ def test9(self): ) unpickled_quantity_string, error_string = process.communicate() self.assertEqual(process.returncode, 0) - self.assertEqual(str(quantity), unpickled_quantity_string.strip().decode('utf-8')) + self.assertEqual( + str(quantity), + unpickled_quantity_string.strip().decode('utf-8') + ) def test10(self): quantity = 1 | parsec - path = os.path.abspath(os.path.join(self.get_path_to_results(), "test10.pickle")) + path = os.path.abspath( + os.path.join(self.get_path_to_results(), "test10.pickle") + ) with open(path, "wb") as stream: pickle.dump(quantity, stream) pythonpath = os.pathsep.join(sys.path) env = os.environ.copy() env['PYTHONPATH'] = pythonpath - code = "import pickle;stream = open('{0}', 'rb'); print(str(pickle.load(stream)));stream.close()".format(path) + code = ( + f"import pickle;" + f"stream = open('{path}', 'rb');" + f"print(str(pickle.load(stream)));" + f"stream.close()" + ) process = subprocess.Popen([ sys.executable, @@ -122,7 +132,10 @@ def test10(self): ) unpickled_quantity_string, error_string = process.communicate() self.assertEqual(process.returncode, 0) - self.assertEqual(str(quantity), unpickled_quantity_string.strip().decode('utf-8')) + self.assertEqual( + str(quantity), + unpickled_quantity_string.strip().decode('utf-8') + ) def test11(self): value = 1 | stellar_type @@ -175,7 +188,7 @@ def test4(self): self.assertEqual(unpickled_particles.center_of_mass(), [2, 3, 0] | m) -class BaseTestModule(object): +class BaseTestModule: def before_get_parameter(self): return @@ -202,13 +215,13 @@ def set_test(self, value): self.x = value o = TestModule() - set = parameters.Parameters([definition,], o) - set.test_name = 10 | m + paramset = parameters.Parameters([definition,], o) + paramset.test_name = 10 | m self.assertEqual(o.x, 10 | m) - self.assertEqual(set.test_name, 10 | m) + self.assertEqual(paramset.test_name, 10 | m) - memento = set.copy() + memento = paramset.copy() self.assertEqual(memento.test_name, 10 | m) pickled_memento = pickle.dumps(memento) diff --git a/src/amuse/units/amuse_2010/__init__.py b/src/amuse/units/amuse_2010/__init__.py new file mode 100644 index 0000000000..066260ae03 --- /dev/null +++ b/src/amuse/units/amuse_2010/__init__.py @@ -0,0 +1 @@ +# constants as originally defined/used in AMUSE diff --git a/src/amuse/units/amuse_2010/astronomical_constants.py b/src/amuse/units/amuse_2010/astronomical_constants.py new file mode 100644 index 0000000000..febd7145ac --- /dev/null +++ b/src/amuse/units/amuse_2010/astronomical_constants.py @@ -0,0 +1,19 @@ +""" +Series of astronomical constants, which are in turn used by the units of the +same names. +""" + +import numpy as np +from amuse.units.si import m, kg +from amuse.units.derivedsi import W, km + + +au = 149597870691.0 | m +parsec = au / np.tan(np.pi / (180 * 60 * 60)) +Lsun = 3.839e26 | W +Msun = 1.98892e30 | kg +Rsun = 6.955e8 | m +Mjupiter = 1.8987e27 | kg +Rjupiter = 71492.0 | km +Mearth = 5.9722e24 | kg +Rearth = 6371.0088 | km # IUGG mean radius diff --git a/src/amuse/units/astronomical_constants.py b/src/amuse/units/astronomical_constants.py new file mode 100644 index 0000000000..5582189738 --- /dev/null +++ b/src/amuse/units/astronomical_constants.py @@ -0,0 +1,10 @@ +""" +Series of astronomical constants, which are in turn used by the units of the +same names. +""" + +# Until we have a way to select a system of constants, use the originally +# defined values. Later, we should have a way to select between different +# constants definitions. + +from amuse.units.amuse_2010.astronomical_constants import * diff --git a/src/amuse/units/constants.py b/src/amuse/units/constants.py index 113ed9682f..f44ee928f4 100644 --- a/src/amuse/units/constants.py +++ b/src/amuse/units/constants.py @@ -1,351 +1,2 @@ -""" -Physical constants -""" -# This is an auto generated file, do not change manually. Instead if you want -# to add constants or change them, change the nist.txt file and run nist.py - -import numpy -from amuse.units.si import m, kg, s, A, K, mol, none -from amuse.units.derivedsi import Hz, MHz, sr, N, Pa, J, W, F, C, V, T, ohm, S, Wb - -# BASE UNITS*********************************************** -X220X_lattice_spacing_of_silicon = 1.920155762e-10 | m -alpha_particle_mass = 6.6446562e-27 | kg -alpha_particle_mass_energy_equivalent = 5.97191917e-10 | J -Angstrom_star = 1.00001498e-10 | m -u = 1.660538782e-27 | kg -atomic_mass_constant_energy_equivalent = 1.49241783e-10 | J -atomic_mass_unit_hyphen_hertz_relationship = 2.2523427369e23 | Hz -atomic_mass_unit_hyphen_joule_relationship = 1.49241783e-10 | J -atomic_mass_unit_hyphen_kelvin_relationship = 1.0809527e13 | K -atomic_mass_unit_hyphen_kilogram_relationship = 1.660538782e-27 | kg -atomic_unit_of_charge = 1.602176487e-19 | C -atomic_unit_of_current = 0.00662361763 | A -atomic_unit_of_electric_potential = 27.21138386 | V -atomic_unit_of_energy = 4.35974394e-18 | J -atomic_unit_of_force = 8.23872206e-08 | N -atomic_unit_of_length = 5.2917720859e-11 | m -atomic_unit_of_mag_flux_density = 235051.7382 | T -atomic_unit_of_mass = 9.10938215e-31 | kg -atomic_unit_of_time = 2.4188843265e-17 | s -Bohr_radius = 5.2917720859e-11 | m -characteristic_impedance_of_vacuum = 376.730313461 | ohm -classical_electron_radius = 2.8179402894e-15 | m -Compton_wavelength = 2.4263102175e-12 | m -Compton_wavelength_over_2_pi = 3.8615926459e-13 | m -conductance_quantum = 7.7480917004e-05 | S -conventional_value_of_von_Klitzing_constant = 25812.807 | ohm -Cu_x_unit = 1.00207699e-13 | m -deuteron_mass = 3.3435832e-27 | kg -deuteron_mass_energy_equivalent = 3.00506272e-10 | J -deuteron_rms_charge_radius = 2.1402e-15 | m -electron_mass = 9.10938215e-31 | kg -electron_mass_energy_equivalent = 8.18710438e-14 | J -electron_volt = 1.602176487e-19 | J -electron_volt_hyphen_hertz_relationship = 2.417989454e14 | Hz -electron_volt_hyphen_joule_relationship = 1.602176487e-19 | J -electron_volt_hyphen_kelvin_relationship = 11604.505 | K -electron_volt_hyphen_kilogram_relationship = 1.782661758e-36 | kg -elementary_charge = 1.602176487e-19 | C -Hartree_energy = 4.35974394e-18 | J -hartree_hyphen_hertz_relationship = 6.57968392072e15 | Hz -hartree_hyphen_joule_relationship = 4.35974394e-18 | J -hartree_hyphen_kelvin_relationship = 315774.65 | K -hartree_hyphen_kilogram_relationship = 4.85086934e-35 | kg -helion_mass = 5.00641192e-27 | kg -helion_mass_energy_equivalent = 4.49953864e-10 | J -hertz_hyphen_joule_relationship = 6.62606896e-34 | J -hertz_hyphen_kelvin_relationship = 4.7992374e-11 | K -hertz_hyphen_kilogram_relationship = 7.372496e-51 | kg -inverse_meter_hyphen_hertz_relationship = 299792458.0 | Hz -inverse_meter_hyphen_joule_relationship = 1.986445501e-25 | J -inverse_meter_hyphen_kelvin_relationship = 0.014387752 | K -inverse_meter_hyphen_kilogram_relationship = 2.2102187e-42 | kg -inverse_of_conductance_quantum = 12906.4037787 | ohm -joule_hyphen_hertz_relationship = 1.50919045e33 | Hz -joule_hyphen_kelvin_relationship = 7.242963e22 | K -joule_hyphen_kilogram_relationship = 1.112650056e-17 | kg -kelvin_hyphen_hertz_relationship = 20836644000.0 | Hz -kelvin_hyphen_joule_relationship = 1.3806504e-23 | J -kelvin_hyphen_kilogram_relationship = 1.5361807e-40 | kg -kilogram_hyphen_hertz_relationship = 1.356392733e50 | Hz -kilogram_hyphen_joule_relationship = 8.987551787e16 | J -kilogram_hyphen_kelvin_relationship = 6.509651e39 | K -lattice_parameter_of_silicon = 5.43102064e-10 | m -mag_flux_quantum = 2.067833667e-15 | Wb -Mo_x_unit = 1.00209955e-13 | m -muon_Compton_wavelength = 1.173444104e-14 | m -muon_Compton_wavelength_over_2_pi = 1.867594295e-15 | m -muon_mass = 1.8835313e-28 | kg -muon_mass_energy_equivalent = 1.69283351e-11 | J -natural_unit_of_energy = 8.18710438e-14 | J -natural_unit_of_length = 3.8615926459e-13 | m -natural_unit_of_mass = 9.10938215e-31 | kg -natural_unit_of_time = 1.288088657e-21 | s -neutron_Compton_wavelength = 1.3195908951e-15 | m -neutron_Compton_wavelength_over_2_pi = 2.1001941382e-16 | m -neutron_mass = 1.674927211e-27 | kg -neutron_mass_energy_equivalent = 1.505349505e-10 | J -Planck_length = 1.616252e-35 | m -Planck_mass = 2.17644e-08 | kg -Planck_temperature = 1.416785e32 | K -Planck_time = 5.39124e-44 | s -proton_Compton_wavelength = 1.3214098446e-15 | m -proton_Compton_wavelength_over_2_pi = 2.1030890861e-16 | m -proton_mass = 1.672621637e-27 | kg -proton_mass_energy_equivalent = 1.503277359e-10 | J -proton_rms_charge_radius = 8.768e-16 | m -Rydberg_constant_times_c_in_Hz = 3.28984196036e15 | Hz -Rydberg_constant_times_hc_in_J = 2.17987197e-18 | J -standard_atmosphere = 101325.0 | Pa -tau_Compton_wavelength = 6.9772e-16 | m -tau_Compton_wavelength_over_2_pi = 1.11046e-16 | m -tau_mass = 3.16777e-27 | kg -tau_mass_energy_equivalent = 2.84705e-10 | J -triton_mass = 5.00735588e-27 | kg -triton_mass_energy_equivalent = 4.50038703e-10 | J -unified_atomic_mass_unit = 1.660538782e-27 | kg -von_Klitzing_constant = 25812.807557 | ohm -# DERIVED UNITS*********************************************** -alpha_particle_molar_mass = 0.00400150617913 | kg * mol**-1 -atomic_mass_unit_hyphen_inverse_meter_relationship = 7.513006671e14 | m**-1 -atomic_unit_of_1st_hyperpolarizablity = 3.206361533e-53 | C**3 * m**3 * J**-2 -atomic_unit_of_2nd_hyperpolarizablity = 6.23538095e-65 | C**4 * m**4 * J**-3 -atomic_unit_of_action = 1.054571628e-34 | J * s -atomic_unit_of_charge_density = 1.0812023e12 | C * m**-3 -atomic_unit_of_electric_dipole_mom = 8.47835281e-30 | C * m -atomic_unit_of_electric_field = 5.14220632e11 | V * m**-1 -atomic_unit_of_electric_field_gradient = 9.71736166e21 | V * m**-2 -atomic_unit_of_electric_polarizablity = 1.6487772536e-41 | C**2 * m**2 * J**-1 -atomic_unit_of_electric_quadrupole_mom = 4.48655107e-40 | C * m**2 -atomic_unit_of_mag_dipole_mom = 1.85480183e-23 | J * T**-1 -atomic_unit_of_magnetizability = 7.891036433e-29 | J * T**-2 -atomic_unit_of_momentum = 1.992851565e-24 | kg * m * s**-1 -atomic_unit_of_permittivity = 1.112650056e-10 | F * m**-1 -atomic_unit_of_velocity = 2187691.2541 | m * s**-1 -Avogadro_constant = 6.02214179e23 | mol**-1 -Bohr_magneton = 9.27400915e-24 | J * T**-1 -Bohr_magneton_in_Hz_div_T = 13996246040.0 | Hz * T**-1 -Bohr_magneton_in_inverse_meters_per_tesla = 46.6864515 | m**-1 * T**-1 -Bohr_magneton_in_K_div_T = 0.6717131 | K * T**-1 -kB = 1.3806504e-23 | J * K**-1 -Boltzmann_constant_in_Hz_div_K = 20836644000.0 | Hz * K**-1 -Boltzmann_constant_in_inverse_meters_per_kelvin = 69.50356 | m**-1 * K**-1 -conventional_value_of_Josephson_constant = 4.835979e14 | Hz * V**-1 -deuteron_mag_mom = 4.33073465e-27 | J * T**-1 -deuteron_molar_mass = 0.00201355321272 | kg * mol**-1 -electric_constant = 8.854187817e-12 | F * m**-1 -electron_charge_to_mass_quotient = -1.75882015e11 | C * kg**-1 -electron_gyromag_ratio = 1.76085977e11 | s**-1 * T**-1 -electron_gyromag_ratio_over_2_pi = 28024.95364 | MHz * T**-1 -electron_mag_mom = -9.28476377e-24 | J * T**-1 -electron_molar_mass = 5.4857990943e-07 | kg * mol**-1 -electron_volt_hyphen_inverse_meter_relationship = 806554.465 | m**-1 -elementary_charge_over_h = 2.417989454e14 | A * J**-1 -Faraday_constant = 96485.3399 | C * mol**-1 -first_radiation_constant = 3.74177118e-16 | W * m**2 -first_radiation_constant_for_spectral_radiance = 1.191042759e-16 | W * m**2 * sr**-1 -hartree_hyphen_inverse_meter_relationship = 21947463.137 | m**-1 -helion_molar_mass = 0.0030149322473 | kg * mol**-1 -hertz_hyphen_inverse_meter_relationship = 3.335640951e-09 | m**-1 -Josephson_constant = 4.83597891e14 | Hz * V**-1 -joule_hyphen_inverse_meter_relationship = 5.03411747e24 | m**-1 -kelvin_hyphen_inverse_meter_relationship = 69.50356 | m**-1 -kilogram_hyphen_inverse_meter_relationship = 4.52443915e41 | m**-1 -Loschmidt_constant_X27315_K_and__101325_kPaX = 2.6867774e25 | m**-3 -mag_constant = 1.2566370614e-06 | N * A**-2 -molar_gas_constant = 8.314472 | J * mol**-1 * K**-1 -molar_mass_constant = 0.001 | kg * mol**-1 -molar_mass_of_carbon_hyphen_12 = 0.012 | kg * mol**-1 -molar_Planck_constant = 3.9903126821e-10 | J * s * mol**-1 -molar_Planck_constant_times_c = 0.11962656472 | J * m * mol**-1 -molar_volume_of_ideal_gas_X27315_K_and__100_kPaX = 0.022710981 | m**3 * mol**-1 -molar_volume_of_ideal_gas_X27315_K_and__101325_kPaX = 0.022413996 | m**3 * mol**-1 -molar_volume_of_silicon = 1.20588349e-05 | m**3 * mol**-1 -muon_mag_mom = -4.49044786e-26 | J * T**-1 -muon_molar_mass = 0.0001134289256 | kg * mol**-1 -natural_unit_of_action = 1.054571628e-34 | J * s -natural_unit_of_momentum = 2.73092406e-22 | kg * m * s**-1 -natural_unit_of_velocity = 299792458.0 | m * s**-1 -neutron_gyromag_ratio = 183247185.0 | s**-1 * T**-1 -neutron_gyromag_ratio_over_2_pi = 29.1646954 | MHz * T**-1 -neutron_mag_mom = -9.6623641e-27 | J * T**-1 -neutron_molar_mass = 0.00100866491597 | kg * mol**-1 -G = 6.67428e-11 | m**3 * kg**-1 * s**-2 -nuclear_magneton = 5.05078324e-27 | J * T**-1 -nuclear_magneton_in_inverse_meters_per_tesla = 0.02542623616 | m**-1 * T**-1 -nuclear_magneton_in_K_div_T = 0.00036582637 | K * T**-1 -nuclear_magneton_in_MHz_div_T = 7.62259384 | MHz * T**-1 -h = 6.62606896e-34 | J * s -Planck_constant_over_2_pi = 1.054571628e-34 | J * s -proton_charge_to_mass_quotient = 95788339.2 | C * kg**-1 -proton_gyromag_ratio = 267522209.9 | s**-1 * T**-1 -proton_gyromag_ratio_over_2_pi = 42.5774821 | MHz * T**-1 -proton_mag_mom = 1.410606662e-26 | J * T**-1 -proton_molar_mass = 0.00100727646677 | kg * mol**-1 -quantum_of_circulation = 0.00036369475199 | m**2 * s**-1 -quantum_of_circulation_times_2 = 0.000727389504 | m**2 * s**-1 -Rydberg_constant = 10973731.5685 | m**-1 -second_radiation_constant = 0.014387752 | m * K -shielded_helion_gyromag_ratio = 203789473.0 | s**-1 * T**-1 -shielded_helion_gyromag_ratio_over_2_pi = 32.43410198 | MHz * T**-1 -shielded_helion_mag_mom = -1.074552982e-26 | J * T**-1 -shielded_proton_gyromag_ratio = 267515336.2 | s**-1 * T**-1 -shielded_proton_gyromag_ratio_over_2_pi = 42.5763881 | MHz * T**-1 -shielded_proton_mag_mom = 1.410570419e-26 | J * T**-1 -c = 299792458.0 | m * s**-1 -standard_acceleration_of_gravity = 9.80665 | m * s**-2 -Stefan_hyphen_Boltzmann_constant = 5.6704e-08 | W * m**-2 * K**-4 -tau_molar_mass = 0.00190768 | kg * mol**-1 -Thomson_cross_section = 6.652458558e-29 | m**2 -triton_mag_mom = 1.504609361e-26 | J * T**-1 -triton_molar_mass = 0.0030155007134 | kg * mol**-1 -Wien_frequency_displacement_law_constant = 58789330000.0 | Hz * K**-1 -Wien_wavelength_displacement_law_constant = 0.0028977685 | m * K -# RATIOS *********************************************** -alpha_particle_hyphen_electron_mass_ratio = 7294.2995365 | none -alpha_particle_hyphen_proton_mass_ratio = 3.97259968951 | none -deuteron_hyphen_electron_mag_mom_ratio = -0.0004664345537 | none -deuteron_hyphen_electron_mass_ratio = 3670.4829654 | none -deuteron_g_factor = 0.8574382308 | none -deuteron_mag_mom_to_Bohr_magneton_ratio = 0.0004669754556 | none -deuteron_mag_mom_to_nuclear_magneton_ratio = 0.8574382308 | none -deuteron_hyphen_neutron_mag_mom_ratio = -0.44820652 | none -deuteron_hyphen_proton_mag_mom_ratio = 0.307012207 | none -deuteron_hyphen_proton_mass_ratio = 1.99900750108 | none -electron_hyphen_deuteron_mag_mom_ratio = -2143.923498 | none -electron_hyphen_deuteron_mass_ratio = 0.00027244371093 | none -electron_g_factor = -2.00231930436 | none -electron_mag_mom_anomaly = 0.00115965218111 | none -electron_mag_mom_to_Bohr_magneton_ratio = -1.00115965218 | none -electron_mag_mom_to_nuclear_magneton_ratio = -1838.28197092 | none -electron_hyphen_muon_mag_mom_ratio = 206.7669877 | none -electron_hyphen_muon_mass_ratio = 0.00483633171 | none -electron_hyphen_neutron_mag_mom_ratio = 960.9205 | none -electron_hyphen_neutron_mass_ratio = 0.00054386734459 | none -electron_hyphen_proton_mag_mom_ratio = -658.2106848 | none -electron_hyphen_proton_mass_ratio = 0.00054461702177 | none -electron_hyphen_tau_mass_ratio = 0.000287564 | none -electron_to_alpha_particle_mass_ratio = 0.00013709335557 | none -electron_to_shielded_helion_mag_mom_ratio = 864.058257 | none -electron_to_shielded_proton_mag_mom_ratio = -658.2275971 | none -fine_hyphen_structure_constant = 0.0072973525376 | none -helion_hyphen_electron_mass_ratio = 5495.8852765 | none -helion_hyphen_proton_mass_ratio = 2.9931526713 | none -inverse_fine_hyphen_structure_constant = 137.035999679 | none -muon_hyphen_electron_mass_ratio = 206.7682823 | none -muon_g_factor = -2.0023318414 | none -muon_mag_mom_anomaly = 0.00116592069 | none -muon_mag_mom_to_Bohr_magneton_ratio = -0.00484197049 | none -muon_mag_mom_to_nuclear_magneton_ratio = -8.89059705 | none -muon_hyphen_neutron_mass_ratio = 0.1124545167 | none -muon_hyphen_proton_mag_mom_ratio = -3.183345137 | none -muon_hyphen_proton_mass_ratio = 0.1126095261 | none -muon_hyphen_tau_mass_ratio = 0.0594592 | none -neutron_hyphen_electron_mag_mom_ratio = 0.00104066882 | none -neutron_hyphen_electron_mass_ratio = 1838.6836605 | none -neutron_g_factor = -3.82608545 | none -neutron_mag_mom_to_Bohr_magneton_ratio = -0.00104187563 | none -neutron_mag_mom_to_nuclear_magneton_ratio = -1.91304273 | none -neutron_hyphen_muon_mass_ratio = 8.89248409 | none -neutron_hyphen_proton_mag_mom_ratio = -0.68497934 | none -neutron_hyphen_proton_mass_ratio = 1.00137841918 | none -neutron_hyphen_tau_mass_ratio = 0.52874 | none -neutron_to_shielded_proton_mag_mom_ratio = -0.68499694 | none -proton_hyphen_electron_mass_ratio = 1836.15267247 | none -proton_g_factor = 5.585694713 | none -proton_mag_mom_to_Bohr_magneton_ratio = 0.001521032209 | none -proton_mag_mom_to_nuclear_magneton_ratio = 2.792847356 | none -proton_mag_shielding_correction = 2.5694e-05 | none -proton_hyphen_muon_mass_ratio = 8.88024339 | none -proton_hyphen_neutron_mag_mom_ratio = -1.45989806 | none -proton_hyphen_neutron_mass_ratio = 0.99862347824 | none -proton_hyphen_tau_mass_ratio = 0.528012 | none -Sackur_hyphen_Tetrode_constant_X1_K_and__100_kPaX = -1.1517047 | none -Sackur_hyphen_Tetrode_constant_X1_K_and__101325_kPaX = -1.1648677 | none -shielded_helion_mag_mom_to_Bohr_magneton_ratio = -0.001158671471 | none -shielded_helion_mag_mom_to_nuclear_magneton_ratio = -2.127497718 | none -shielded_helion_to_proton_mag_mom_ratio = -0.761766558 | none -shielded_helion_to_shielded_proton_mag_mom_ratio = -0.7617861313 | none -shielded_proton_mag_mom_to_Bohr_magneton_ratio = 0.001520993128 | none -shielded_proton_mag_mom_to_nuclear_magneton_ratio = 2.792775598 | none -tau_hyphen_electron_mass_ratio = 3477.48 | none -tau_hyphen_muon_mass_ratio = 16.8183 | none -tau_hyphen_neutron_mass_ratio = 1.89129 | none -tau_hyphen_proton_mass_ratio = 1.8939 | none -triton_hyphen_electron_mag_mom_ratio = -0.001620514423 | none -triton_hyphen_electron_mass_ratio = 5496.9215269 | none -triton_g_factor = 5.957924896 | none -triton_mag_mom_to_Bohr_magneton_ratio = 0.001622393657 | none -triton_mag_mom_to_nuclear_magneton_ratio = 2.978962448 | none -triton_hyphen_neutron_mag_mom_ratio = -1.55718553 | none -triton_hyphen_proton_mag_mom_ratio = 1.066639908 | none -triton_hyphen_proton_mass_ratio = 2.9937170309 | none -weak_mixing_angle = 0.22255 | none -# DERIVED CONSTANTS*********************************************** -pi = numpy.pi -hbar = h / (2.0 * numpy.pi) -four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant -mu0 = 4 * numpy.pi * 1.0e-7 | N / A**2 -eps0 = mu0**-1 * c**-2 -sidereal_day = 86164.100352 | s -# machine constants -eps = numpy.finfo(numpy.double).eps -precision = int(numpy.log10(2 / eps)) -# DROPPED UNITS*********************************************** -"""alpha_particle_mass_energy_equivalent_in_MeV = 3727.379109 | MeV -alpha_particle_mass_in_u = 4.00150617913 | u -atomic_mass_constant_energy_equivalent_in_MeV = 931.494028 | MeV -atomic_mass_unit_hyphen_electron_volt_relationship = 931494028.0 | eV -atomic_mass_unit_hyphen_hartree_relationship = 34231777.149 | E_h -Bohr_magneton_in_eV_div_T = 5.7883817555e-05 | eV*T**-1 -kBeV = 8.617343e-05 | eV*K**-1 -deuteron_mass_energy_equivalent_in_MeV = 1875.612793 | MeV -deuteron_mass_in_u = 2.01355321272 | u -electron_mass_energy_equivalent_in_MeV = 0.51099891 | MeV -electron_mass_in_u = 0.00054857990943 | u -electron_volt_hyphen_atomic_mass_unit_relationship = 1.073544188e-09 | u -electron_volt_hyphen_hartree_relationship = 0.0367493254 | E_h -Faraday_constant_for_conventional_electric_current = 96485.3401 | C_90*mol**-1 -Fermi_coupling_constant = 1.16637e-05 | GeV**-2 -hartree_hyphen_atomic_mass_unit_relationship = 2.9212622986e-08 | u -hartree_hyphen_electron_volt_relationship = 27.21138386 | eV -Hartree_energy_in_eV = 27.21138386 | eV -helion_mass_energy_equivalent_in_MeV = 2808.391383 | MeV -helion_mass_in_u = 3.0149322473 | u -hertz_hyphen_atomic_mass_unit_relationship = 4.4398216294e-24 | u -hertz_hyphen_electron_volt_relationship = 4.13566733e-15 | eV -hertz_hyphen_hartree_relationship = 1.51982984601e-16 | E_h -inverse_meter_hyphen_atomic_mass_unit_relationship = 1.3310250394e-15 | u -inverse_meter_hyphen_electron_volt_relationship = 1.239841875e-06 | eV -inverse_meter_hyphen_hartree_relationship = 4.55633525276e-08 | E_h -joule_hyphen_atomic_mass_unit_relationship = 6700536410.0 | u -joule_hyphen_electron_volt_relationship = 6.24150965e+18 | eV -joule_hyphen_hartree_relationship = 2.29371269e+17 | E_h -kelvin_hyphen_atomic_mass_unit_relationship = 9.251098e-14 | u -kelvin_hyphen_electron_volt_relationship = 8.617343e-05 | eV -kelvin_hyphen_hartree_relationship = 3.1668153e-06 | E_h -kilogram_hyphen_atomic_mass_unit_relationship = 6.02214179e+26 | u -kilogram_hyphen_electron_volt_relationship = 5.60958912e+35 | eV -kilogram_hyphen_hartree_relationship = 2.06148616e+34 | E_h -muon_mass_energy_equivalent_in_MeV = 105.6583668 | MeV -muon_mass_in_u = 0.1134289256 | u -natural_unit_of_action_in_eV_s = 6.58211899e-16 | eV*s -natural_unit_of_energy_in_MeV = 0.51099891 | MeV -natural_unit_of_momentum_in_MeV_div_c = 0.51099891 | MeV/c -neutron_mass_energy_equivalent_in_MeV = 939.565346 | MeV -neutron_mass_in_u = 1.00866491597 | u -Newtonian_constant_of_gravitation_over_h_hyphen_bar_c = 6.70881e-39 | (GeV/c**2)**-2 -nuclear_magneton_in_eV_div_T = 3.1524512326e-08 | eV*T**-1 -heV = 4.13566733e-15 | eV*s -Planck_constant_over_2_pi_in_eV_s = 6.58211899e-16 | eV*s -Planck_constant_over_2_pi_times_c_in_MeV_fm = 197.3269631 | MeV*fm -Planck_mass_energy_equivalent_in_GeV = 1.220892e+19 | GeV -proton_mass_energy_equivalent_in_MeV = 938.272013 | MeV -proton_mass_in_u = 1.00727646677 | u -Rydberg_constant_times_hc_in_eV = 13.60569193 | eV -tau_mass_energy_equivalent_in_MeV = 1776.99 | MeV -tau_mass_in_u = 1.90768 | u -triton_mass_energy_equivalent_in_MeV = 2808.920906 | MeV -triton_mass_in_u = 3.0155007134 | u -""" +from .physical_constants import * +from .astronomical_constants import * diff --git a/src/amuse/units/nist.py b/src/amuse/units/nist.py index b57817efeb..ade920ebfd 100644 --- a/src/amuse/units/nist.py +++ b/src/amuse/units/nist.py @@ -1,3 +1,5 @@ +import sys + import urllib.request, urllib.error, urllib.parse, urllib.request, urllib.parse, urllib.error import difflib import os.path @@ -9,18 +11,18 @@ from amuse.units import derivedsi NIST_URL = "http://132.229.222.6:9000/nistdata" -MESSAGE = \ -""" -#This is an auto generated file, do not change manually. Instead if you want to add constants -#or change them, change the nist.txt file and run nist.py +MESSAGE = """\"\"\" +Physical constants +\"\"\" +# This is an auto generated file, do not change manually. Instead if you want +# to add constants or change them, change the nist.txt file and run nist.py import numpy -from amuse.units.si import * -from amuse.units.derivedsi import * +from amuse.units.si import m, kg, s, A, K, mol, none +from amuse.units.derivedsi import Hz, MHz, sr, N, Pa, J, W, F, C, V, T, ohm, S, Wb """ -ADDITIONAL_DERIVED_CONSTANTS = \ -""" +ADDITIONAL_DERIVED_CONSTANTS = """ pi = numpy.pi hbar = h / (2.0 * numpy.pi) four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant @@ -31,9 +33,12 @@ eps = numpy.finfo(numpy.double).eps precision = int(numpy.log10(2/eps)) """ -class GetConstantsFromFiles(object): - - def __init__(self): + + +class GetConstantsFromFiles: + + def __init__(self, filename="nist.txt"): + self.nist_filename = filename self.nist_table = "" self.local_table = "" self.translator_table = [] @@ -45,88 +50,107 @@ def get_table_from_url(self): f.close() def save_table_as(self, filename): - f = open(os.path.join(self.directory, 'nist.txt'), 'w') + f = open(os.path.join(self.directory, self.nist_filename), "w") f.write(self.nist_table) f.close() - + def get_table_from_file(self): - f = open(os.path.join(self.directory, 'nist.txt'), 'r') # CODATA 2006, for CODATA 2010 use 'nist2010.txt' - self.nist_table = f.read() - f.close() + f = open( + os.path.join(self.directory, self.nist_filename), "r" + ) # CODATA 2006, for CODATA 2010 use 'nist2010.txt' + self.nist_table = f.read() + f.close() def check_current_file_with_table(self): - md5sum_local = md5() - md5sum_local.update(self.local_table) - md5sum_local_val = md5sum_local.hexdigest() - md5sum_wgot = md5() - md5sum_wgot.update(self.nist_table) - md5sum_wgot_val = md5sum_wgot.hexdigest() - return md5sum_local_val == md5sum_wgot_val + md5sum_local = md5() + md5sum_local.update(self.local_table) + md5sum_local_val = md5sum_local.hexdigest() + md5sum_wgot = md5() + md5sum_wgot.update(self.nist_table) + md5sum_wgot_val = md5sum_wgot.hexdigest() + return md5sum_local_val == md5sum_wgot_val def compare_char_by_char(self): - self.nist_table.lstrip('\n') - mydiff = difflib.unified_diff(self.nist_table.splitlines(1), self.local_table.splitlines(1)) + self.nist_table.lstrip("\n") + mydiff = difflib.unified_diff( + self.nist_table.splitlines(1), self.local_table.splitlines(1) + ) for i in list(mydiff): print(i) - + def get_translator(self): - f = open(os.path.join(self.directory, 'translator.txt'), 'r') + f = open(os.path.join(self.directory, "translator.txt"), "r") lines = f.readlines() for i, s in enumerate(lines): - cols = s.split(',') + cols = s.split(",") self.translator_table.append(cols) - f.close() + f.close() + -class Constants(object): - def __init__(self): - self.I = GetConstantsFromFiles() - #I.get_table_from_url() +class Constants: + def __init__(self, filename="nist.txt"): + self.I = GetConstantsFromFiles(filename=filename) + # I.get_table_from_url() self.I.get_table_from_file() self.table = self.I.nist_table self.I.get_translator() self.translator = self.I.translator_table self.nistfile = MESSAGE - + self.nisttable = [] self.nisttablederivedunits = [] self.nisttablenoneunits = [] self.nisttablebaseunits = [] self.nisttabledependingunits = [] - self.siunits = dir(si)+dir(derivedsi) - + self.siunits = dir(si) + dir(derivedsi) + def test_regexp(self, regexp): - lines =self.table.splitlines(1) - for i,line in enumerate(lines): - if i>80: + lines = self.table.splitlines(1) + for i, line in enumerate(lines): + if i > 80: break print(re.findall(regexp, line)) def translate(self, to_translate): list = [s[1] for s in self.translator if to_translate == s[0]] if list == []: - return to_translate.lstrip(' ') + return to_translate.lstrip(" ") else: - return list[0].strip('\n') + return list[0].strip("\n") def list_constants(self): - error =[] + error = [] value = [] name = [] unit = [] - lines =self.table.splitlines(1) + lines = self.table.splitlines(1) for n, line in enumerate(lines): if "----------------------" in line: number_of_header_lines = n + 1 break firstline = lines[number_of_header_lines] - namestr_length = len(firstline) - len(firstline[firstline.find(" "):].lstrip()) - column_index_of_uncertainty = len(firstline) - len(firstline[namestr_length+21+firstline[namestr_length+21:].find(" "):].lstrip()) - column_index_of_unit = len(firstline) - len(firstline[column_index_of_uncertainty+21+firstline[column_index_of_uncertainty+21:].find(" "):].lstrip()) + print() + print(firstline) + namestr_length = len(firstline) - len( + firstline[firstline.find(" ") :].lstrip() + ) + column_index_of_uncertainty = len(firstline) - len( + firstline[ + namestr_length + 21 + firstline[namestr_length + 21 :].find(" ") : + ].lstrip() + ) + column_index_of_unit = len(firstline) - len( + firstline[ + column_index_of_uncertainty + + 21 + + firstline[column_index_of_uncertainty + 21 :].find(" ") : + ].lstrip() + ) for i in lines[number_of_header_lines:]: namestr = i[0:namestr_length] @@ -134,68 +158,105 @@ def list_constants(self): marker2 = column_index_of_unit while 1: - if i[marker1-1]=='\x20': + if i[marker1 - 1] == "\x20": break else: - marker1+=1 + marker1 += 1 while 1: - if i[marker2-1]=='\x20': + try: + if i[marker2 - 1] == "\x20": + break + else: + marker2 += 1 + except: break - else: - marker2+=1 + # print(f"i (length {len(i)}): {i}") + # print(f"marker2: {marker2}") + # sys.exit() - nrs=[] + nrs = [] nrs.append(i[namestr_length:marker1]) nrs.append(i[marker1:marker2]) unitstr = i[marker2:] - - unitstr = unitstr.strip().replace(' ','*').replace('^','**') - new_name = self.translate(namestr.rstrip(' ').replace(' ','_').replace('.','').replace('{','X').replace('}','X').replace('(','X').replace(')','X').replace('-','_hyphen_').replace(',','_and_').replace('/','_div_')) - error.append(nrs[1].replace(' ','')) - if len(unitstr)==1: + unitstr = unitstr.strip().replace(" ", " * ").replace("^", "**") + + new_name = self.translate( + namestr.rstrip(" ") + .replace(" ", "_") + .replace(".", "") + .replace("{", "X") + .replace("}", "X") + .replace("(", "X") + .replace(")", "X") + .replace("-", "_hyphen_") + .replace(",", "_and_") + .replace("/", "_div_") + ) + error.append(nrs[1].replace(" ", "")) + if len(unitstr) == 1: this_unit = "none\n" else: this_unit = unitstr - self.nisttable.append([new_name, float(i[namestr_length:marker1].replace(' ','').replace('...','')), unitstr]) + self.nisttable.append( + [ + new_name, + float( + i[namestr_length:marker1].replace(" ", "").replace("...", "") + ), + unitstr, + ] + ) def sort_units(self): for entry in self.nisttable: if entry[2] in self.siunits: self.nisttablebaseunits.append(entry) - elif entry[2] == '': + elif entry[2] == "": self.nisttablenoneunits.append(entry) - elif set(re.split('[*/^]',re.sub('\*\*-?[0-9.]*','',entry[2]))).issubset(set(self.siunits)): + elif set(re.split("[*/^]", re.sub("\*\*-?[0-9.]*", "", entry[2]))).issubset( + set(self.siunits) + ): self.nisttablederivedunits.append(entry) else: self.nisttabledependingunits.append(entry) - + def print_list_of_units(self, unitlist): for name, value, unit in unitlist: - self.nistfile += ("{0} = {1} | {2}\n".format(name, value, unit or "none")) + self.nistfile += "{0} = {1} | {2}\n".format(name, value, unit or "none") def generate_constants(self): self.list_constants() self.sort_units() - self.nistfile += "#BASE UNITS***********************************************\n" + self.nistfile += "# BASE UNITS***********************************************\n" self.print_list_of_units(self.nisttablebaseunits) - self.nistfile += "#DERIVED UNITS***********************************************\n" + self.nistfile += ( + "# DERIVED UNITS***********************************************\n" + ) self.print_list_of_units(self.nisttablederivedunits) - self.nistfile += "#RATIOS ***********************************************\n" + self.nistfile += "# RATIOS ***********************************************\n" self.print_list_of_units(self.nisttablenoneunits) - self.nistfile += "#DERIVED CONSTANTS***********************************************" + self.nistfile += ( + "# DERIVED CONSTANTS***********************************************" + ) self.nistfile += ADDITIONAL_DERIVED_CONSTANTS - self.nistfile += '#DROPPED UNITS***********************************************\n"""' + self.nistfile += ( + '# DROPPED UNITS***********************************************\n"""' + ) self.print_list_of_units(self.nisttabledependingunits) - self.nistfile +='"""\n' + self.nistfile += '"""\n' - - f = open(os.path.join(self.I.directory, 'constants.py'), 'w') + f = open(os.path.join(self.I.directory, "constants.py"), "w") f.write(self.nistfile) f.close() -if __name__ == "__main__": - print("Generating constants.py...", end=' ') - Constants().generate_constants() + +if __name__ == "__main__": + if len(sys.argv) > 1: + filename = sys.argv[1] + else: + filename = "nist.txt" + print("Generating constants.py...", end=" ") + Constants(filename=filename).generate_constants() print(" done!") diff --git a/src/amuse/units/physical_constants.py b/src/amuse/units/physical_constants.py new file mode 100644 index 0000000000..113ed9682f --- /dev/null +++ b/src/amuse/units/physical_constants.py @@ -0,0 +1,351 @@ +""" +Physical constants +""" +# This is an auto generated file, do not change manually. Instead if you want +# to add constants or change them, change the nist.txt file and run nist.py + +import numpy +from amuse.units.si import m, kg, s, A, K, mol, none +from amuse.units.derivedsi import Hz, MHz, sr, N, Pa, J, W, F, C, V, T, ohm, S, Wb + +# BASE UNITS*********************************************** +X220X_lattice_spacing_of_silicon = 1.920155762e-10 | m +alpha_particle_mass = 6.6446562e-27 | kg +alpha_particle_mass_energy_equivalent = 5.97191917e-10 | J +Angstrom_star = 1.00001498e-10 | m +u = 1.660538782e-27 | kg +atomic_mass_constant_energy_equivalent = 1.49241783e-10 | J +atomic_mass_unit_hyphen_hertz_relationship = 2.2523427369e23 | Hz +atomic_mass_unit_hyphen_joule_relationship = 1.49241783e-10 | J +atomic_mass_unit_hyphen_kelvin_relationship = 1.0809527e13 | K +atomic_mass_unit_hyphen_kilogram_relationship = 1.660538782e-27 | kg +atomic_unit_of_charge = 1.602176487e-19 | C +atomic_unit_of_current = 0.00662361763 | A +atomic_unit_of_electric_potential = 27.21138386 | V +atomic_unit_of_energy = 4.35974394e-18 | J +atomic_unit_of_force = 8.23872206e-08 | N +atomic_unit_of_length = 5.2917720859e-11 | m +atomic_unit_of_mag_flux_density = 235051.7382 | T +atomic_unit_of_mass = 9.10938215e-31 | kg +atomic_unit_of_time = 2.4188843265e-17 | s +Bohr_radius = 5.2917720859e-11 | m +characteristic_impedance_of_vacuum = 376.730313461 | ohm +classical_electron_radius = 2.8179402894e-15 | m +Compton_wavelength = 2.4263102175e-12 | m +Compton_wavelength_over_2_pi = 3.8615926459e-13 | m +conductance_quantum = 7.7480917004e-05 | S +conventional_value_of_von_Klitzing_constant = 25812.807 | ohm +Cu_x_unit = 1.00207699e-13 | m +deuteron_mass = 3.3435832e-27 | kg +deuteron_mass_energy_equivalent = 3.00506272e-10 | J +deuteron_rms_charge_radius = 2.1402e-15 | m +electron_mass = 9.10938215e-31 | kg +electron_mass_energy_equivalent = 8.18710438e-14 | J +electron_volt = 1.602176487e-19 | J +electron_volt_hyphen_hertz_relationship = 2.417989454e14 | Hz +electron_volt_hyphen_joule_relationship = 1.602176487e-19 | J +electron_volt_hyphen_kelvin_relationship = 11604.505 | K +electron_volt_hyphen_kilogram_relationship = 1.782661758e-36 | kg +elementary_charge = 1.602176487e-19 | C +Hartree_energy = 4.35974394e-18 | J +hartree_hyphen_hertz_relationship = 6.57968392072e15 | Hz +hartree_hyphen_joule_relationship = 4.35974394e-18 | J +hartree_hyphen_kelvin_relationship = 315774.65 | K +hartree_hyphen_kilogram_relationship = 4.85086934e-35 | kg +helion_mass = 5.00641192e-27 | kg +helion_mass_energy_equivalent = 4.49953864e-10 | J +hertz_hyphen_joule_relationship = 6.62606896e-34 | J +hertz_hyphen_kelvin_relationship = 4.7992374e-11 | K +hertz_hyphen_kilogram_relationship = 7.372496e-51 | kg +inverse_meter_hyphen_hertz_relationship = 299792458.0 | Hz +inverse_meter_hyphen_joule_relationship = 1.986445501e-25 | J +inverse_meter_hyphen_kelvin_relationship = 0.014387752 | K +inverse_meter_hyphen_kilogram_relationship = 2.2102187e-42 | kg +inverse_of_conductance_quantum = 12906.4037787 | ohm +joule_hyphen_hertz_relationship = 1.50919045e33 | Hz +joule_hyphen_kelvin_relationship = 7.242963e22 | K +joule_hyphen_kilogram_relationship = 1.112650056e-17 | kg +kelvin_hyphen_hertz_relationship = 20836644000.0 | Hz +kelvin_hyphen_joule_relationship = 1.3806504e-23 | J +kelvin_hyphen_kilogram_relationship = 1.5361807e-40 | kg +kilogram_hyphen_hertz_relationship = 1.356392733e50 | Hz +kilogram_hyphen_joule_relationship = 8.987551787e16 | J +kilogram_hyphen_kelvin_relationship = 6.509651e39 | K +lattice_parameter_of_silicon = 5.43102064e-10 | m +mag_flux_quantum = 2.067833667e-15 | Wb +Mo_x_unit = 1.00209955e-13 | m +muon_Compton_wavelength = 1.173444104e-14 | m +muon_Compton_wavelength_over_2_pi = 1.867594295e-15 | m +muon_mass = 1.8835313e-28 | kg +muon_mass_energy_equivalent = 1.69283351e-11 | J +natural_unit_of_energy = 8.18710438e-14 | J +natural_unit_of_length = 3.8615926459e-13 | m +natural_unit_of_mass = 9.10938215e-31 | kg +natural_unit_of_time = 1.288088657e-21 | s +neutron_Compton_wavelength = 1.3195908951e-15 | m +neutron_Compton_wavelength_over_2_pi = 2.1001941382e-16 | m +neutron_mass = 1.674927211e-27 | kg +neutron_mass_energy_equivalent = 1.505349505e-10 | J +Planck_length = 1.616252e-35 | m +Planck_mass = 2.17644e-08 | kg +Planck_temperature = 1.416785e32 | K +Planck_time = 5.39124e-44 | s +proton_Compton_wavelength = 1.3214098446e-15 | m +proton_Compton_wavelength_over_2_pi = 2.1030890861e-16 | m +proton_mass = 1.672621637e-27 | kg +proton_mass_energy_equivalent = 1.503277359e-10 | J +proton_rms_charge_radius = 8.768e-16 | m +Rydberg_constant_times_c_in_Hz = 3.28984196036e15 | Hz +Rydberg_constant_times_hc_in_J = 2.17987197e-18 | J +standard_atmosphere = 101325.0 | Pa +tau_Compton_wavelength = 6.9772e-16 | m +tau_Compton_wavelength_over_2_pi = 1.11046e-16 | m +tau_mass = 3.16777e-27 | kg +tau_mass_energy_equivalent = 2.84705e-10 | J +triton_mass = 5.00735588e-27 | kg +triton_mass_energy_equivalent = 4.50038703e-10 | J +unified_atomic_mass_unit = 1.660538782e-27 | kg +von_Klitzing_constant = 25812.807557 | ohm +# DERIVED UNITS*********************************************** +alpha_particle_molar_mass = 0.00400150617913 | kg * mol**-1 +atomic_mass_unit_hyphen_inverse_meter_relationship = 7.513006671e14 | m**-1 +atomic_unit_of_1st_hyperpolarizablity = 3.206361533e-53 | C**3 * m**3 * J**-2 +atomic_unit_of_2nd_hyperpolarizablity = 6.23538095e-65 | C**4 * m**4 * J**-3 +atomic_unit_of_action = 1.054571628e-34 | J * s +atomic_unit_of_charge_density = 1.0812023e12 | C * m**-3 +atomic_unit_of_electric_dipole_mom = 8.47835281e-30 | C * m +atomic_unit_of_electric_field = 5.14220632e11 | V * m**-1 +atomic_unit_of_electric_field_gradient = 9.71736166e21 | V * m**-2 +atomic_unit_of_electric_polarizablity = 1.6487772536e-41 | C**2 * m**2 * J**-1 +atomic_unit_of_electric_quadrupole_mom = 4.48655107e-40 | C * m**2 +atomic_unit_of_mag_dipole_mom = 1.85480183e-23 | J * T**-1 +atomic_unit_of_magnetizability = 7.891036433e-29 | J * T**-2 +atomic_unit_of_momentum = 1.992851565e-24 | kg * m * s**-1 +atomic_unit_of_permittivity = 1.112650056e-10 | F * m**-1 +atomic_unit_of_velocity = 2187691.2541 | m * s**-1 +Avogadro_constant = 6.02214179e23 | mol**-1 +Bohr_magneton = 9.27400915e-24 | J * T**-1 +Bohr_magneton_in_Hz_div_T = 13996246040.0 | Hz * T**-1 +Bohr_magneton_in_inverse_meters_per_tesla = 46.6864515 | m**-1 * T**-1 +Bohr_magneton_in_K_div_T = 0.6717131 | K * T**-1 +kB = 1.3806504e-23 | J * K**-1 +Boltzmann_constant_in_Hz_div_K = 20836644000.0 | Hz * K**-1 +Boltzmann_constant_in_inverse_meters_per_kelvin = 69.50356 | m**-1 * K**-1 +conventional_value_of_Josephson_constant = 4.835979e14 | Hz * V**-1 +deuteron_mag_mom = 4.33073465e-27 | J * T**-1 +deuteron_molar_mass = 0.00201355321272 | kg * mol**-1 +electric_constant = 8.854187817e-12 | F * m**-1 +electron_charge_to_mass_quotient = -1.75882015e11 | C * kg**-1 +electron_gyromag_ratio = 1.76085977e11 | s**-1 * T**-1 +electron_gyromag_ratio_over_2_pi = 28024.95364 | MHz * T**-1 +electron_mag_mom = -9.28476377e-24 | J * T**-1 +electron_molar_mass = 5.4857990943e-07 | kg * mol**-1 +electron_volt_hyphen_inverse_meter_relationship = 806554.465 | m**-1 +elementary_charge_over_h = 2.417989454e14 | A * J**-1 +Faraday_constant = 96485.3399 | C * mol**-1 +first_radiation_constant = 3.74177118e-16 | W * m**2 +first_radiation_constant_for_spectral_radiance = 1.191042759e-16 | W * m**2 * sr**-1 +hartree_hyphen_inverse_meter_relationship = 21947463.137 | m**-1 +helion_molar_mass = 0.0030149322473 | kg * mol**-1 +hertz_hyphen_inverse_meter_relationship = 3.335640951e-09 | m**-1 +Josephson_constant = 4.83597891e14 | Hz * V**-1 +joule_hyphen_inverse_meter_relationship = 5.03411747e24 | m**-1 +kelvin_hyphen_inverse_meter_relationship = 69.50356 | m**-1 +kilogram_hyphen_inverse_meter_relationship = 4.52443915e41 | m**-1 +Loschmidt_constant_X27315_K_and__101325_kPaX = 2.6867774e25 | m**-3 +mag_constant = 1.2566370614e-06 | N * A**-2 +molar_gas_constant = 8.314472 | J * mol**-1 * K**-1 +molar_mass_constant = 0.001 | kg * mol**-1 +molar_mass_of_carbon_hyphen_12 = 0.012 | kg * mol**-1 +molar_Planck_constant = 3.9903126821e-10 | J * s * mol**-1 +molar_Planck_constant_times_c = 0.11962656472 | J * m * mol**-1 +molar_volume_of_ideal_gas_X27315_K_and__100_kPaX = 0.022710981 | m**3 * mol**-1 +molar_volume_of_ideal_gas_X27315_K_and__101325_kPaX = 0.022413996 | m**3 * mol**-1 +molar_volume_of_silicon = 1.20588349e-05 | m**3 * mol**-1 +muon_mag_mom = -4.49044786e-26 | J * T**-1 +muon_molar_mass = 0.0001134289256 | kg * mol**-1 +natural_unit_of_action = 1.054571628e-34 | J * s +natural_unit_of_momentum = 2.73092406e-22 | kg * m * s**-1 +natural_unit_of_velocity = 299792458.0 | m * s**-1 +neutron_gyromag_ratio = 183247185.0 | s**-1 * T**-1 +neutron_gyromag_ratio_over_2_pi = 29.1646954 | MHz * T**-1 +neutron_mag_mom = -9.6623641e-27 | J * T**-1 +neutron_molar_mass = 0.00100866491597 | kg * mol**-1 +G = 6.67428e-11 | m**3 * kg**-1 * s**-2 +nuclear_magneton = 5.05078324e-27 | J * T**-1 +nuclear_magneton_in_inverse_meters_per_tesla = 0.02542623616 | m**-1 * T**-1 +nuclear_magneton_in_K_div_T = 0.00036582637 | K * T**-1 +nuclear_magneton_in_MHz_div_T = 7.62259384 | MHz * T**-1 +h = 6.62606896e-34 | J * s +Planck_constant_over_2_pi = 1.054571628e-34 | J * s +proton_charge_to_mass_quotient = 95788339.2 | C * kg**-1 +proton_gyromag_ratio = 267522209.9 | s**-1 * T**-1 +proton_gyromag_ratio_over_2_pi = 42.5774821 | MHz * T**-1 +proton_mag_mom = 1.410606662e-26 | J * T**-1 +proton_molar_mass = 0.00100727646677 | kg * mol**-1 +quantum_of_circulation = 0.00036369475199 | m**2 * s**-1 +quantum_of_circulation_times_2 = 0.000727389504 | m**2 * s**-1 +Rydberg_constant = 10973731.5685 | m**-1 +second_radiation_constant = 0.014387752 | m * K +shielded_helion_gyromag_ratio = 203789473.0 | s**-1 * T**-1 +shielded_helion_gyromag_ratio_over_2_pi = 32.43410198 | MHz * T**-1 +shielded_helion_mag_mom = -1.074552982e-26 | J * T**-1 +shielded_proton_gyromag_ratio = 267515336.2 | s**-1 * T**-1 +shielded_proton_gyromag_ratio_over_2_pi = 42.5763881 | MHz * T**-1 +shielded_proton_mag_mom = 1.410570419e-26 | J * T**-1 +c = 299792458.0 | m * s**-1 +standard_acceleration_of_gravity = 9.80665 | m * s**-2 +Stefan_hyphen_Boltzmann_constant = 5.6704e-08 | W * m**-2 * K**-4 +tau_molar_mass = 0.00190768 | kg * mol**-1 +Thomson_cross_section = 6.652458558e-29 | m**2 +triton_mag_mom = 1.504609361e-26 | J * T**-1 +triton_molar_mass = 0.0030155007134 | kg * mol**-1 +Wien_frequency_displacement_law_constant = 58789330000.0 | Hz * K**-1 +Wien_wavelength_displacement_law_constant = 0.0028977685 | m * K +# RATIOS *********************************************** +alpha_particle_hyphen_electron_mass_ratio = 7294.2995365 | none +alpha_particle_hyphen_proton_mass_ratio = 3.97259968951 | none +deuteron_hyphen_electron_mag_mom_ratio = -0.0004664345537 | none +deuteron_hyphen_electron_mass_ratio = 3670.4829654 | none +deuteron_g_factor = 0.8574382308 | none +deuteron_mag_mom_to_Bohr_magneton_ratio = 0.0004669754556 | none +deuteron_mag_mom_to_nuclear_magneton_ratio = 0.8574382308 | none +deuteron_hyphen_neutron_mag_mom_ratio = -0.44820652 | none +deuteron_hyphen_proton_mag_mom_ratio = 0.307012207 | none +deuteron_hyphen_proton_mass_ratio = 1.99900750108 | none +electron_hyphen_deuteron_mag_mom_ratio = -2143.923498 | none +electron_hyphen_deuteron_mass_ratio = 0.00027244371093 | none +electron_g_factor = -2.00231930436 | none +electron_mag_mom_anomaly = 0.00115965218111 | none +electron_mag_mom_to_Bohr_magneton_ratio = -1.00115965218 | none +electron_mag_mom_to_nuclear_magneton_ratio = -1838.28197092 | none +electron_hyphen_muon_mag_mom_ratio = 206.7669877 | none +electron_hyphen_muon_mass_ratio = 0.00483633171 | none +electron_hyphen_neutron_mag_mom_ratio = 960.9205 | none +electron_hyphen_neutron_mass_ratio = 0.00054386734459 | none +electron_hyphen_proton_mag_mom_ratio = -658.2106848 | none +electron_hyphen_proton_mass_ratio = 0.00054461702177 | none +electron_hyphen_tau_mass_ratio = 0.000287564 | none +electron_to_alpha_particle_mass_ratio = 0.00013709335557 | none +electron_to_shielded_helion_mag_mom_ratio = 864.058257 | none +electron_to_shielded_proton_mag_mom_ratio = -658.2275971 | none +fine_hyphen_structure_constant = 0.0072973525376 | none +helion_hyphen_electron_mass_ratio = 5495.8852765 | none +helion_hyphen_proton_mass_ratio = 2.9931526713 | none +inverse_fine_hyphen_structure_constant = 137.035999679 | none +muon_hyphen_electron_mass_ratio = 206.7682823 | none +muon_g_factor = -2.0023318414 | none +muon_mag_mom_anomaly = 0.00116592069 | none +muon_mag_mom_to_Bohr_magneton_ratio = -0.00484197049 | none +muon_mag_mom_to_nuclear_magneton_ratio = -8.89059705 | none +muon_hyphen_neutron_mass_ratio = 0.1124545167 | none +muon_hyphen_proton_mag_mom_ratio = -3.183345137 | none +muon_hyphen_proton_mass_ratio = 0.1126095261 | none +muon_hyphen_tau_mass_ratio = 0.0594592 | none +neutron_hyphen_electron_mag_mom_ratio = 0.00104066882 | none +neutron_hyphen_electron_mass_ratio = 1838.6836605 | none +neutron_g_factor = -3.82608545 | none +neutron_mag_mom_to_Bohr_magneton_ratio = -0.00104187563 | none +neutron_mag_mom_to_nuclear_magneton_ratio = -1.91304273 | none +neutron_hyphen_muon_mass_ratio = 8.89248409 | none +neutron_hyphen_proton_mag_mom_ratio = -0.68497934 | none +neutron_hyphen_proton_mass_ratio = 1.00137841918 | none +neutron_hyphen_tau_mass_ratio = 0.52874 | none +neutron_to_shielded_proton_mag_mom_ratio = -0.68499694 | none +proton_hyphen_electron_mass_ratio = 1836.15267247 | none +proton_g_factor = 5.585694713 | none +proton_mag_mom_to_Bohr_magneton_ratio = 0.001521032209 | none +proton_mag_mom_to_nuclear_magneton_ratio = 2.792847356 | none +proton_mag_shielding_correction = 2.5694e-05 | none +proton_hyphen_muon_mass_ratio = 8.88024339 | none +proton_hyphen_neutron_mag_mom_ratio = -1.45989806 | none +proton_hyphen_neutron_mass_ratio = 0.99862347824 | none +proton_hyphen_tau_mass_ratio = 0.528012 | none +Sackur_hyphen_Tetrode_constant_X1_K_and__100_kPaX = -1.1517047 | none +Sackur_hyphen_Tetrode_constant_X1_K_and__101325_kPaX = -1.1648677 | none +shielded_helion_mag_mom_to_Bohr_magneton_ratio = -0.001158671471 | none +shielded_helion_mag_mom_to_nuclear_magneton_ratio = -2.127497718 | none +shielded_helion_to_proton_mag_mom_ratio = -0.761766558 | none +shielded_helion_to_shielded_proton_mag_mom_ratio = -0.7617861313 | none +shielded_proton_mag_mom_to_Bohr_magneton_ratio = 0.001520993128 | none +shielded_proton_mag_mom_to_nuclear_magneton_ratio = 2.792775598 | none +tau_hyphen_electron_mass_ratio = 3477.48 | none +tau_hyphen_muon_mass_ratio = 16.8183 | none +tau_hyphen_neutron_mass_ratio = 1.89129 | none +tau_hyphen_proton_mass_ratio = 1.8939 | none +triton_hyphen_electron_mag_mom_ratio = -0.001620514423 | none +triton_hyphen_electron_mass_ratio = 5496.9215269 | none +triton_g_factor = 5.957924896 | none +triton_mag_mom_to_Bohr_magneton_ratio = 0.001622393657 | none +triton_mag_mom_to_nuclear_magneton_ratio = 2.978962448 | none +triton_hyphen_neutron_mag_mom_ratio = -1.55718553 | none +triton_hyphen_proton_mag_mom_ratio = 1.066639908 | none +triton_hyphen_proton_mass_ratio = 2.9937170309 | none +weak_mixing_angle = 0.22255 | none +# DERIVED CONSTANTS*********************************************** +pi = numpy.pi +hbar = h / (2.0 * numpy.pi) +four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant +mu0 = 4 * numpy.pi * 1.0e-7 | N / A**2 +eps0 = mu0**-1 * c**-2 +sidereal_day = 86164.100352 | s +# machine constants +eps = numpy.finfo(numpy.double).eps +precision = int(numpy.log10(2 / eps)) +# DROPPED UNITS*********************************************** +"""alpha_particle_mass_energy_equivalent_in_MeV = 3727.379109 | MeV +alpha_particle_mass_in_u = 4.00150617913 | u +atomic_mass_constant_energy_equivalent_in_MeV = 931.494028 | MeV +atomic_mass_unit_hyphen_electron_volt_relationship = 931494028.0 | eV +atomic_mass_unit_hyphen_hartree_relationship = 34231777.149 | E_h +Bohr_magneton_in_eV_div_T = 5.7883817555e-05 | eV*T**-1 +kBeV = 8.617343e-05 | eV*K**-1 +deuteron_mass_energy_equivalent_in_MeV = 1875.612793 | MeV +deuteron_mass_in_u = 2.01355321272 | u +electron_mass_energy_equivalent_in_MeV = 0.51099891 | MeV +electron_mass_in_u = 0.00054857990943 | u +electron_volt_hyphen_atomic_mass_unit_relationship = 1.073544188e-09 | u +electron_volt_hyphen_hartree_relationship = 0.0367493254 | E_h +Faraday_constant_for_conventional_electric_current = 96485.3401 | C_90*mol**-1 +Fermi_coupling_constant = 1.16637e-05 | GeV**-2 +hartree_hyphen_atomic_mass_unit_relationship = 2.9212622986e-08 | u +hartree_hyphen_electron_volt_relationship = 27.21138386 | eV +Hartree_energy_in_eV = 27.21138386 | eV +helion_mass_energy_equivalent_in_MeV = 2808.391383 | MeV +helion_mass_in_u = 3.0149322473 | u +hertz_hyphen_atomic_mass_unit_relationship = 4.4398216294e-24 | u +hertz_hyphen_electron_volt_relationship = 4.13566733e-15 | eV +hertz_hyphen_hartree_relationship = 1.51982984601e-16 | E_h +inverse_meter_hyphen_atomic_mass_unit_relationship = 1.3310250394e-15 | u +inverse_meter_hyphen_electron_volt_relationship = 1.239841875e-06 | eV +inverse_meter_hyphen_hartree_relationship = 4.55633525276e-08 | E_h +joule_hyphen_atomic_mass_unit_relationship = 6700536410.0 | u +joule_hyphen_electron_volt_relationship = 6.24150965e+18 | eV +joule_hyphen_hartree_relationship = 2.29371269e+17 | E_h +kelvin_hyphen_atomic_mass_unit_relationship = 9.251098e-14 | u +kelvin_hyphen_electron_volt_relationship = 8.617343e-05 | eV +kelvin_hyphen_hartree_relationship = 3.1668153e-06 | E_h +kilogram_hyphen_atomic_mass_unit_relationship = 6.02214179e+26 | u +kilogram_hyphen_electron_volt_relationship = 5.60958912e+35 | eV +kilogram_hyphen_hartree_relationship = 2.06148616e+34 | E_h +muon_mass_energy_equivalent_in_MeV = 105.6583668 | MeV +muon_mass_in_u = 0.1134289256 | u +natural_unit_of_action_in_eV_s = 6.58211899e-16 | eV*s +natural_unit_of_energy_in_MeV = 0.51099891 | MeV +natural_unit_of_momentum_in_MeV_div_c = 0.51099891 | MeV/c +neutron_mass_energy_equivalent_in_MeV = 939.565346 | MeV +neutron_mass_in_u = 1.00866491597 | u +Newtonian_constant_of_gravitation_over_h_hyphen_bar_c = 6.70881e-39 | (GeV/c**2)**-2 +nuclear_magneton_in_eV_div_T = 3.1524512326e-08 | eV*T**-1 +heV = 4.13566733e-15 | eV*s +Planck_constant_over_2_pi_in_eV_s = 6.58211899e-16 | eV*s +Planck_constant_over_2_pi_times_c_in_MeV_fm = 197.3269631 | MeV*fm +Planck_mass_energy_equivalent_in_GeV = 1.220892e+19 | GeV +proton_mass_energy_equivalent_in_MeV = 938.272013 | MeV +proton_mass_in_u = 1.00727646677 | u +Rydberg_constant_times_hc_in_eV = 13.60569193 | eV +tau_mass_energy_equivalent_in_MeV = 1776.99 | MeV +tau_mass_in_u = 1.90768 | u +triton_mass_energy_equivalent_in_MeV = 2808.920906 | MeV +triton_mass_in_u = 3.0155007134 | u +""" diff --git a/src/amuse/units/quantities.py b/src/amuse/units/quantities.py index 8bb0bd43ea..f4df1c72a4 100644 --- a/src/amuse/units/quantities.py +++ b/src/amuse/units/quantities.py @@ -103,7 +103,7 @@ def is_vector(self): return False def __repr__(self): - return "quantity<" + str(self) + ">" + return f"quantity<{self}>" def __add__(self, other): if self.unit.is_zero(): @@ -1199,7 +1199,7 @@ def __str__(self): return self.unit.value_to_string(self.value) def __repr__(self): - return f"quantity<{str(self.value)} - {str(self)}>" + return f"quantity<{self.value} - {self}>" def as_vector_with_length(self, length): return VectorQuantity(numpy.array([self.value] * length), self.unit) diff --git a/src/amuse/units/units.py b/src/amuse/units/units.py index eeab5a068f..f4f158e0aa 100644 --- a/src/amuse/units/units.py +++ b/src/amuse/units/units.py @@ -4,6 +4,8 @@ import numpy from . import constants +from . import physical_constants +from . import astronomical_constants from . import quantities # The two imports below are to explicitly expose everything directly used in @@ -43,20 +45,20 @@ # astronomical units angstrom = named("angstrom", "angstrom", 1e-10 * m) -au = named("astronomical unit", "au", 149597870691.0 * m) -aud = named("au per day", "aud", 149597870691.0 * m / day) -parsec = named("parsec", "parsec", au / numpy.tan(numpy.pi / (180 * 60 * 60))) +au = named("astronomical unit", "au", astronomical_constants.au.as_unit()) +aud = named("au per day", "aud", astronomical_constants.au.as_unit() / day) +parsec = named("parsec", "parsec", astronomical_constants.parsec.as_unit()) kpc = named("kilo parsec", "kpc", 10**3 * parsec) Mpc = named("mega parsec", "Mpc", 10**6 * parsec) Gpc = named("giga parsec", "Gpc", 10**9 * parsec) -lightyear = named("light year", "ly", 9460730472580.8 * km) -LSun = named("solar luminosity", "LSun", 3.839e26 * W) -MSun = named("solar mass", "MSun", 1.98892e30 * kg) -RSun = named("solar radius", "RSun", 6.955e8 * m) -MJupiter = named("jupiter mass", "MJupiter", 1.8987e27 * kg) -RJupiter = named("jupiter radius", "RJupiter", 71492.0 * km) -MEarth = named("earth mass", "MEarth", 5.9722e24 * kg) -REarth = named("earth radius", "REarth", 6371.0088 * km) # IUGG mean radius +lightyear = named("light year", "ly", (physical_constants.c * julianyr).as_unit()) +LSun = named("solar luminosity", "LSun", astronomical_constants.Lsun.as_unit()) +MSun = named("solar mass", "MSun", astronomical_constants.Msun.as_unit()) +RSun = named("solar radius", "RSun", astronomical_constants.Rsun.as_unit()) +MJupiter = named("jupiter mass", "MJupiter", astronomical_constants.Mjupiter.as_unit()) +RJupiter = named("jupiter radius", "RJupiter", astronomical_constants.Rjupiter.as_unit()) +MEarth = named("earth mass", "MEarth", astronomical_constants.Mearth.as_unit()) +REarth = named("earth radius", "REarth", astronomical_constants.Rearth.as_unit()) kyr = named("kilo year", "kyr", 1000 * yr) myr = named("million year", "Myr", 1000000 * yr) gyr = named("giga (billion) year", "Gyr", 1000000000 * yr)