Skip to content
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

Use Macros to define new variables #102

Merged
merged 20 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
PyFormattedStrings = "5f89f4a4-a228-4886-b223-c468a82ed5b9"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
julia = "1"
Expand Down
Binary file added docs/.DS_Store
Binary file not shown.
11 changes: 7 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ using Documenter, AtomicAndPhysicalConstants

makedocs(
sitename="AtomicAndPhysicalConstants.jl",
authors = "Alex Coxe et al.",
format=Documenter.HTMLWriter.HTML(size_threshold = nothing),
pages =
authors="Alex Coxe et al.",
format=Documenter.HTMLWriter.HTML(size_threshold=nothing),
pages=
[
"Home" => "index.md",
"Set Units" => "set_units.md",
"Constants Getter Functions" => "constants.md",
"Constants Used" => "constants_used.md"
]
)

deploydocs(;
repo = "github.com/bmad-sim/AtomicAndPhysicalConstants.jl.git",
repo="github.com/bmad-sim/AtomicAndPhysicalConstants.jl.git",
)
58 changes: 58 additions & 0 deletions docs/src/constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

# Constants

Constants are accessed by a getter function. If a unit is provided, then the value with that unit is returned. If units is not provided, then the units will be in the units determined by `setunits()`. For Example:

```julia
c_light(u"km/s") # return 299792.458 km s⁻¹

setunits() # set units to ACCELERATOR unit system, where speed unit is m/s

c_light() #return 2.99792458e8 m s⁻¹
```

## Here is a list of constants getter functions:

#### Speed of light: `c_light()`
#### Planck's constant: `h_planck()`
#### Reduced Planck's constant: `h_bar_planck()`
#### Classical electron radius: `r_e()`
#### Classical proton radius: `r_p()`
#### Elementary charge: `e_charge()`
#### Vacuum permeability: `mu_0_vac()`
#### Permittivity of free space: `eps_0_vac()`
#### Classical Radius Factor: `classical_radius_factor()`
#### Fine structure constant: `fine_structure()`
#### Avogadro's constant: `N_avogadro()`

## Species Mass and Charge

To access mass or charge of a species, use `massof()` getter function for mass, and `chargeof()` getter function for charge. Similarly, if a unit is not provided, the function will return unit defined by `setunits()`. For Example:

```julia
e = Species("electron")

setunits() # set units to ACCELERATOR unit system, where mass unit is eV/c^2 and charge unit is elementary charge

massof(e) # return 510998.95069 eV c⁻²

massof(e,u"MeV/c^2") # return 0.51099895069 MeV c⁻²

chargeof(e) # return -1.0 e

chargeof(e, u"C") #return -1.602176634e-19 C
```

### Here is a list of species where you can find its mass or charge in a similar way

- "pion0"
- "neutron"
- "deuteron"
- "pion+"
- "proton"
- "photon"
- "electron"
- "anti-proton"
- "muon"
- "pion-"
- "anti-deuteron"
49 changes: 49 additions & 0 deletions docs/src/constants_used.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

# Constants Used

Here is a list of constants used in the package.
Constants are pulled from the NIST table of the **2022 CODATA release**. Note that `m_pion_0` and `m_pion_charged` are pulled from **PDG**.

## Physical Constants
#### Speed of light: `c_light` = 2.99792458e8 * u"m/s"
#### Planck's constant: `h_planck` = 4.135667696e-15 * u"eV*s"
#### Classical electron radius: `r_e` = 2.8179403205e-15 * u"m"
#### Vacuum permeability: `mu_0_vac` = 1.25663706127e-6 * u"N/A^2"
#### Elementary charge: `e_charge` = 1.602176634e-19 * u"C"
#### Avogadro's constant: `N_avogadro` = 6.02214076e23
#### Fine structure constant: `fine_structure` = 0.0072973525643

## Species Mass
#### Electron Mass: `m_electron` = 0.51099895069 * u"MeV/c^2"
#### Proton Mass: `m_proton` = 9.382720894300001e2 * u"eV/c^2"
#### Neutron Mass: `m_neutron` = 9.395654219399999e2 * u"MeV/c^2"
#### Muon Mass: `m_muon` = 1.056583755e2 * u"MeV/c^2"
#### Helion Mass He3 nucleus: `m_helion` = 2.80839161112e3 * u"MeV/c^2"
#### Deuteron Mass: `m_deuteron` = 1.875612945e3 * u"MeV/c^2"
#### uncharged pion mass: `m_pion_0` = 1.349768277676847e2 * u"MeV/c^2"
#### charged pion mass: `m_pion_charged` = 1.3957039098368132e2 * u"MeV/c^2"

## Species Magnetic Momoments
#### Deuteron magnetic moment: `mu_deuteron` = 4.330735087e-27 * u"J/T"
#### Electron magnetic moment: `mu_electron` = -9.2847646917e-24 * u"J/T"
#### Helion magnetic moment: `mu_helion` = -1.07461755198e-26 * u"J/T"
#### Muon magnetic moment: `mu_muon` = -4.4904483e-26 * u"J/T"
#### Neutron magnetic moment: `mu_neutron` = -9.6623653e-27 * u"J/T"
#### Proton magnetic moment: `mu_proton` = 1.41060679545e-26 * u"J/T"
#### Triton magnetic moment: `mu_triton` = 1.5046095178e-26 * u"J/T"


## Conversion Factors
#### kg per standard atomic mass unit: `kg_per_amu` = 1.66053906892e-27
#### eV per standard atomic mass unit: `eV_per_amu` = 9.3149410372e8
#### Joules per eV: `J_per_eV` = 1.602176634e-19










9 changes: 4 additions & 5 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# AtomicAndPhysicalConstants.jl

Hi!
Look at my equation:

```math
\langle P \rangle_t = 0.75
```
`AtomicAndPhysicalConstants.jl` provides a quick way to store informations about different atomic species and other physical constants

## Basic Usage
Call function `setunits()` to initialize the constants to your preferred units.
38 changes: 38 additions & 0 deletions docs/src/set_units.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# setunits()
## Description

`setunits()` should be called at the initialization of the package. `setunits()` sets the units for physical constants, species mass and charge.

The user have the freedom to choice the unit they want for `mass`, `length`, `time`, `energy`, and `charge`. Or, they can use our predefined unitsystems `ACCELERATOR` (default), `MKS`, and `CGS` to quickly setup the units. The units are of type `Unitful.FreeUnits`. See more about `Unitful` [here](#unitful).

`setunits()` will return an array with units for each dimension.


## Syntax
```julia
setunits(unitsystem;
mass_unit,
length_unit,
time_unit,
energy_unit,
charge_unit,
)
```
## Options

## Examples
```julia
setunits() #sets unit system to ACCELERATOR (default).
```
```julia
setunits(mass_unit=u"kg", charge=u"e") #sets unit system to ACCELERATOR (default), but mass unit in "kg".
```
```julia
setunits(MKS) #sets unit system to MKS.
```
```julia
setunits(CGS, mass_unit=u"kg", charge=u"e") #sets unit system to CGS, but mass unit in "kg" and charge unit in elementary charge.
```
## Unitful


4 changes: 1 addition & 3 deletions src/AtomicAndPhysicalConstants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ include("update_isos.jl")
include("particle_functions.jl")
include("set_units.jl")

export setunits
export @APCdef
export ACCELERATOR, MKS, CGS
export massof, chargeof
export C_LIGHT, H_PLANCK, H_BAR_PLANCK, R_E, R_P, E_CHARGE, MU_0_VAC, EPS_0_VAC, CLASSICAL_RADIUS_FACTOR, FINE_STRUCTURE, N_AVOGADRO
export SubatomicSpecies
export AtomicSpecies
export SUBATOMIC_SPECIES
Expand Down
8 changes: 4 additions & 4 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# constants with dimension [mass]
#####################################################################

const __b_m_electron = .51099895069 * u"MeV/c^2"
const __b_m_electron = 0.51099895069 * u"MeV/c^2"
# Electron Mass [MeV]/c^2
const __b_m_proton = 9.382720894300001e2 * u"eV/c^2"
# Proton Mass [MeV]/c^2
Expand Down Expand Up @@ -84,15 +84,15 @@ const __b_e_charge = 1.602176634e-19 * u"C";
# elementary charge [C]
const __b_r_e = 2.8179403205e-15 * u"m";
# classical electron radius [m]
const __b_r_p = __b_r_e * __b_m_electron / __b_m_proton *u"m";
const __b_r_p = __b_r_e * __b_m_electron / __b_m_proton;
# classical proton radius [m]
const __b_c_light = 2.99792458e8 * u"m/s";
# speed of light [m/s]
const __b_h_planck = 4.135667696e-15 * u"eV*s";
# Planck's constant [eV*s]
const __b_h_bar_planck = __b_h_planck / 2pi * u"eV*s";
const __b_h_bar_planck = __b_h_planck / 2pi;
# h_planck/twopi [eV*s]
const __b_classical_radius_factor = __b_r_e * __b_m_electron * u"MeV*m/c^2";
const __b_classical_radius_factor = __b_r_e * __b_m_electron;
# e^2 / (4 pi eps_0) = classical_radius * mass * c^2.
# Is same for all particles of charge +/- 1.

Expand Down
Loading
Loading