Skip to content

Create physical constants submodule #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Create physical constants submodule #27

wants to merge 6 commits into from

Conversation

MilesCranmer
Copy link
Member

@MilesCranmer MilesCranmer commented Jun 15, 2023

PR for #26.

  1. This creates a Constants submodule.
  2. Units and Constants are now both exported by DynamicQuantities (unsure about this, but feels right)
  3. Constants is made available within the @u_str macro for ease of access. (Some constants are treated like units)

For example:

julia> mass_energy_of_sun = 1.0 * u"Const.M_sun * Const.c^2"
1.7870936681139022e47 m² kg s⁻²

julia> q1 = 1.5u"C"; q2 = 1e-5u"C";

julia> F = Const.k_e * q1 * q2 / (1u"m")
134813.2768839176 m² kg s⁻²

julia> f = 500u"MHz"
5.0e8 s⁻¹

julia> (Constants.h * f) / Constants.eV
2.0678338484619293e-6

The following constants are included.

  • c: Speed of light in a vacuum. Standard.
  • h: Planck constant. Standard.
  • hbar: Reduced Planck constant (h/2π). Standard.
  • e: Elementary charge. Standard.
  • k_B: Boltzmann constant. Standard.
  • N_A: Avogadro constant. Standard.
  • eV: Electron volt. Standard.
  • R: Molar gas constant. Standard.
  • F: Faraday constant. Standard.
  • sigma_sb: Stefan-Boltzmann constant. Standard.
  • alpha: Fine-structure constant. Measured.
  • u: Atomic mass unit (1/12th the mass of Carbon-12). Measured.
  • G: Newtonian constant of gravitation. Measured.
  • mu_0: Vacuum magnetic permeability. Measured.
  • eps_0: Vacuum electric permittivity. Measured.
  • m_e: Electron mass. Measured.
  • m_p: Proton mass. Measured.
  • m_n: Neutron mass. Measured.
  • a_0: Bohr radius. Measured.
  • k_e: Coulomb constant (Note: SI units only!). Measured.
  • Ryd: Rydberg frequency. Measured.

I included the most common astro ones too (It might be nice if someone added similar sets of very common constants from other fields.)

  • M_earth: Earth mass. Measured.
  • M_sun: Solar mass. Measured.
  • M_jup: Jupiter mass. Measured.
  • R_earth: Nominal Earth equatorial radius. Standard.
  • R_jup: Nominal Jupiter equatorial radius. Standard.
  • R_sun: Nominal solar radius. Standard.
  • L_sun: Nominal solar luminosity. Standard.
  • L_bol0: Standard luminosity at absolute bolometric magnitude 0. Standard.
  • sigma_T: Thomson scattering cross-section. Measured.
  • au: Astronomical unit. Standard.
  • pc: Parsec. Standard.
  • ly: Light year. Standard.
  • atm: Standard atmosphere. Standard.

"Standard" means it is an exact standard, while "Measured" means there is some uncertainty associated with it.

cc @odow @ChrisRackauckas. I am eager to hear your take on this interface given your interest in using the package downstream.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2023

Benchmark Results

main a12d87a... t[main]/t[a12d87a...]
creation/Quantity(x) 3 ± 0.1 ns 3.1 ± 0.1 ns 0.968
creation/Quantity(x, length=y) 3.7 ± 0.001 ns 3.4 ± 0 ns 1.09
time_to_load 0.126 ± 0.0013 s 0.131 ± 0.00045 s 0.967
with_numbers/*real 3.4 ± 0 ns 3.4 ± 0 ns 1
with_numbers/^int 24.1 ± 2.4 ns 24.1 ± 2.4 ns 1
with_numbers/^int * real 24.1 ± 2.4 ns 24.1 ± 2.4 ns 1
with_quantity/+y 6.8 ± 0.1 ns 7.7 ± 0.001 ns 0.883
with_quantity//y 4.3 ± 0.1 ns 3.4 ± 0 ns 1.26
with_self/dimension 1.7 ± 0 ns 1.7 ± 0 ns 1
with_self/inv 3.4 ± 0 ns 3.4 ± 0 ns 1
with_self/ustrip 1.7 ± 0 ns 1.7 ± 0 ns 1

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@MilesCranmer MilesCranmer mentioned this pull request Jun 15, 2023
@odow
Copy link
Contributor

odow commented Jun 15, 2023

From JuMP's point of view, I think most people would just be using the distance, mass, and time units. No fancy physics stuff.

Co-authored-by: Oscar Dowson <odow@users.noreply.github.com>
@MilesCranmer MilesCranmer changed the base branch from main to abstract-types-2 June 24, 2023 23:30
Base automatically changed from abstract-types-2 to main June 28, 2023 13:52
[Diff since v0.4.0](v0.4.0...v0.5.0)

**Closed issues:**
- Use `Int64 / C` as default (#20)

**Merged pull requests:**
- Make `AbstractQuantity` and `AbstractDimensions` (#24) (@MilesCranmer)
@MilesCranmer
Copy link
Member Author

Combining with verbatim units branch, so closing.

@MilesCranmer
Copy link
Member Author

Continued on #32. This PR also introduces the symbolic dimensions to help with trulsf/UnitJuMP.jl#18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants