Skip to content

Commit

Permalink
Merge pull request #368 from crystal-growth/add_radioactivity
Browse files Browse the repository at this point in the history
Add quantities for radioactivity, molar radioactivity, and specific radioactivity.
  • Loading branch information
iliekturtles authored Jan 5, 2023
2 parents 77d71ee + 9b575d6 commit b71a7f3
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ system! {
molar_flux::MolarFlux,
molar_heat_capacity::MolarHeatCapacity,
molar_mass::MolarMass,
molar_radioactivity::MolarRadioactivity,
molar_volume::MolarVolume,
moment_of_inertia::MomentOfInertia,
momentum::Momentum,
power::Power,
pressure::Pressure,
radiant_exposure::RadiantExposure,
radioactivity::Radioactivity,
ratio::Ratio,
reciprocal_length::ReciprocalLength,
solid_angle::SolidAngle,
specific_area::SpecificArea,
specific_heat_capacity::SpecificHeatCapacity,
specific_radioactivity::SpecificRadioactivity,
specific_volume::SpecificVolume,
surface_electric_current_density::SurfaceElectricCurrentDensity,
temperature_coefficient::TemperatureCoefficient,
Expand Down
56 changes: 56 additions & 0 deletions src/si/molar_radioactivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Molar radioactivity (base unit becquerel per mole, s⁻¹ · mol⁻¹).
quantity! {
/// Molar radioactivity (base unit becquerel per mole, s⁻¹ · mol⁻¹).
quantity: MolarRadioactivity; "molar radioactivity";
/// Dimension of molar radioactivity, T⁻¹N⁻¹ (base unit becquerel per mole, s⁻¹ · mol⁻¹).
dimension: ISQ<
Z0, // length
Z0, // mass
N1, // time
Z0, // electric current
Z0, // thermodynamic temperature
N1, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@becquerel_per_mole: prefix!(none); "Bq/mol", "becquerel per mole", "becquerels per mole";

@curie_per_mole: 3.7_E10; "Ci/mol", "curie per mole", "curies per mole";

@disintegrations_per_minute_per_mole: 1.0 / 6.0_E1; "dpm/mol",
"disintegration per minute per mole", "disintegrations per minute per mole";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::radioactivity as rad;
use crate::si::molar_radioactivity as mrad;
use crate::si::quantities::*;
use crate::si::amount_of_substance as aos;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: MolarRadioactivity<V> = (Radioactivity::new::<rad::becquerel>(V::one())
/ AmountOfSubstance::new::<aos::mole>(V::one())).into();
}

#[test]
fn check_units() {
test::<rad::becquerel, aos::mole, mrad::becquerel_per_mole>();
test::<rad::curie, aos::mole, mrad::curie_per_mole>();
test::<rad::disintegrations_per_minute, aos::mole,
mrad::disintegrations_per_minute_per_mole>();

fn test<RAD: rad::Conversion<V>, AOS: aos::Conversion<V>, SRAD: mrad::Conversion<V>>() {
Test::assert_approx_eq(&MolarRadioactivity::new::<SRAD>(V::one()),
&(Radioactivity::new::<RAD>(V::one())
/ AmountOfSubstance::new::<AOS>(V::one())).into());
}
}
}
}
110 changes: 110 additions & 0 deletions src/si/radioactivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Radioactivity (base unit becquerel, s⁻¹).
quantity! {
/// Radioactivity (base unit becquerel, s⁻¹).
quantity: Radioactivity; "radioactivity";
/// Dimension of radioactivity, T⁻¹ (base unit becquerel, s⁻¹).
dimension: ISQ<
Z0, // length
Z0, // mass
N1, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@yottabecquerel: prefix!(yotta); "YBq", "yottabecquerel", "yottabecquerels";
@zettabecquerel: prefix!(zetta); "ZBq", "zettabecquerel", "zettabecquerels";
@exabecquerel: prefix!(exa); "EBq", "exabecquerel", "exabecquerels";
@petabecquerel: prefix!(peta); "PBq", "petabecquerel", "petabecquerels";
@terabecquerel: prefix!(tera); "TBq", "terabecquerel", "terabecquerels";
@gigabecquerel: prefix!(giga); "GBq", "gigabecquerel", "gigabecquerels";
@megabecquerel: prefix!(mega); "MBq", "megabecquerel", "megabecquerels";
@kilobecquerel: prefix!(kilo); "kBq", "kilobecquerel", "kilobecquerels";
@hectobecquerel: prefix!(hecto); "hBq", "hectobecquerel", "hectobecquerels";
@decabecquerel: prefix!(deca); "daBq", "decabecquerel", "decabecquerels";
/// The becquerel is one decay per second.
@becquerel: prefix!(none); "Bq", "becquerel", "becquerels";
@millibecquerel: prefix!(milli); "mBq", "millibecquerel", "millibecquerels";
@microbecquerel: prefix!(micro); "µBq", "microbecquerel", "microbecquerels";
@nanobecquerel: prefix!(nano); "nBq", "nanobecquerel", "nanobecquerels";

@gigacurie: prefix!(giga) * 3.7_E10; "GCi", "gigacurie", "gigacuries";
@megacurie: prefix!(mega) * 3.7_E10; "MCi", "megacurie", "megacuries";
@kilocurie: prefix!(kilo) * 3.7_E10; "kCi", "kilocurie", "kilocuries";
@curie: 3.7_E10; "Ci", "curie", "curies";
@millicurie: prefix!(milli) * 3.7_E10; "mCi", "millicurie", "millicuries";
@microcurie: prefix!(micro) * 3.7_E10; "µCi", "microcurie", "microcuries";
@nanocurie: prefix!(nano) * 3.7_E10; "nCi", "nanocurie", "nanocuries";

@disintegrations_per_minute: 1.0 / 6.0_E1; "dpm", "disintegration per minute",
"disintegrations per minute";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::radioactivity as rad;
use crate::si::quantities::*;
use crate::si::time as t;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: Time<V> = (V::one() / Radioactivity::new::<rad::becquerel>(V::one())).into();
let _: Radioactivity<V> = (V::one() / Time::new::<t::second>(V::one())).into();
}

#[test]
fn check_units() {
test::<t::second, rad::becquerel>();
test::<t::decisecond, rad::decabecquerel>();
test::<t::centisecond, rad::hectobecquerel>();
test::<t::millisecond, rad::kilobecquerel>();
test::<t::microsecond, rad::megabecquerel>();
test::<t::nanosecond, rad::gigabecquerel>();
test::<t::picosecond, rad::terabecquerel>();
test::<t::femtosecond, rad::petabecquerel>();
test::<t::attosecond, rad::exabecquerel>();
test::<t::zeptosecond, rad::zettabecquerel>();
test::<t::yoctosecond, rad::yottabecquerel>();

fn test<T: t::Conversion<V>, RAD: rad::Conversion<V>>() {
Test::assert_approx_eq(&(V::one() / Time::new::<T>(V::one())),
&Radioactivity::new::<RAD>(V::one()).into());
Test::assert_approx_eq(&Time::new::<T>(V::one()),
&(V::one() / Radioactivity::new::<RAD>(V::one())).into());
}
}

#[test]
fn check_curie() {
test::<rad::gigabecquerel, rad::gigacurie>();
test::<rad::megabecquerel, rad::megacurie>();
test::<rad::kilobecquerel, rad::kilocurie>();
test::<rad::becquerel, rad::curie>();
test::<rad::millibecquerel, rad::millicurie>();
test::<rad::microbecquerel, rad::microcurie>();
test::<rad::nanobecquerel, rad::nanocurie>();

fn test<RadBq: rad::Conversion<V>, RadCi: rad::Conversion<V>>() {
Test::assert_approx_eq(
&(V::one() * 3.7_E10 * Radioactivity::new::<RadBq>(V::one())),
&Radioactivity::new::<RadCi>(V::one()));
}
}

#[test]
fn check_dpm() {
test::<rad::becquerel, rad::disintegrations_per_minute>();

fn test<RadBq: rad::Conversion<V>, RadCi: rad::Conversion<V>>() {
Test::assert_approx_eq(&(V::one() / 6_E1 * Radioactivity::new::<RadBq>(V::one())),
&Radioactivity::new::<RadCi>(V::one()));
}
}
}
}
56 changes: 56 additions & 0 deletions src/si/specific_radioactivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Specific radioactivity (base unit becquerel per kilogram, kg⁻¹ · s⁻¹).
quantity! {
/// Specific radioactivity (base unit becquerel per kilogram, kg⁻¹ · s⁻¹).
quantity: SpecificRadioactivity; "specific radioactivity";
/// Dimension of specific radioactivity, M⁻¹T⁻¹ (base unit becquerel per kilogram, kg⁻¹ · s⁻¹).
dimension: ISQ<
Z0, // length
N1, // mass
N1, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@becquerel_per_kilogram: prefix!(none); "Bq/kg", "becquerel per kilogram",
"becquerels per kilogram";

@curie_per_kilogram: 3.7_E10; "Ci/kg", "curie per kilogram", "curie per kilogram";

@disintegrations_per_minute_per_kilogram: 1.0 / 6.0_E1; "dpm/kg",
"disintegration per minute per kilogram", "disintegrations per minute per kilogram";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::radioactivity as rad;
use crate::si::specific_radioactivity as srad;
use crate::si::quantities::*;
use crate::si::mass as m;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: SpecificRadioactivity<V> = (Radioactivity::new::<rad::becquerel>(V::one())
/ Mass::new::<m::kilogram>(V::one())).into();
}

#[test]
fn check_units() {
test::<rad::becquerel, m::kilogram, srad::becquerel_per_kilogram>();
test::<rad::curie, m::kilogram, srad::curie_per_kilogram>();
test::<rad::disintegrations_per_minute, m::kilogram,
srad::disintegrations_per_minute_per_kilogram>();

fn test<RAD: rad::Conversion<V>, M: m::Conversion<V>, SRAD: srad::Conversion<V>>() {
Test::assert_approx_eq(&SpecificRadioactivity::new::<SRAD>(V::one()),
&(Radioactivity::new::<RAD>(V::one()) / Mass::new::<M>(V::one())).into());
}
}
}
}
23 changes: 23 additions & 0 deletions src/si/volumetric_number_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ quantity! {
"per liter second";
@per_milliliter_second: prefix!(none) / prefix!(milli) / prefix!(milli); "mL⁻¹ · s⁻¹",
"per milliliter second", "per milliliter second";

@becquerel_per_cubic_meter: prefix!(none); "Bq/m³", "becquerel per cubic meter",
"becquerels per cubic meter";

@curie_per_cubic_meter: 3.7_E10; "Ci/m³", "curie per cubic meter", "curies per cubic meter";

@disintegrations_per_minute_per_cubic_meter: 1.0 / 6.0_E1; "dpm/m³",
"disintegration per minute per cubic meter",
"disintegrations per minute per cubic meter";
}
}

Expand All @@ -51,6 +60,7 @@ mod test {
storage_types! {
use crate::num::One;
use crate::si::volumetric_number_rate as vnr;
use crate::si::radioactivity as rad;
use crate::si::quantities::*;
use crate::si::time as t;
use crate::si::volume as vol;
Expand Down Expand Up @@ -87,5 +97,18 @@ mod test {
/ Volume::new::<VOL>(V::one())).into());
}
}

#[test]
fn check_units_volumetric_radioactivity() {
test::<rad::becquerel, vol::cubic_meter, vnr::becquerel_per_cubic_meter>();
test::<rad::curie, vol::cubic_meter, vnr::curie_per_cubic_meter>();
test::<rad::disintegrations_per_minute, vol::cubic_meter,
vnr::disintegrations_per_minute_per_cubic_meter>();

fn test<RAD: rad::Conversion<V>, VOL: vol::Conversion<V>, VNR: vnr::Conversion<V>>() {
Test::assert_approx_eq(&VolumetricNumberRate::new::<VNR>(V::one()),
&(Radioactivity::new::<RAD>(V::one()) / Volume::new::<VOL>(V::one())).into());
}
}
}
}

0 comments on commit b71a7f3

Please sign in to comment.