From 441976bb93f6c6660c09fbb56f64b699b0389778 Mon Sep 17 00:00:00 2001 From: iTitus Date: Tue, 19 Oct 2021 23:25:27 +0200 Subject: [PATCH] add more units and constants --- .../github/ititus/si/quantity/Constants.java | 66 +++++++++++++++++-- .../github/ititus/si/quantity/Quantity.java | 4 ++ .../ititus/si/quantity/QuantityImpl.java | 8 +-- .../ititus/si/quantity/type/Torque.java | 13 ++++ .../java/io/github/ititus/si/unit/Units.java | 7 ++ 5 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 src/main/java/io/github/ititus/si/quantity/type/Torque.java diff --git a/src/main/java/io/github/ititus/si/quantity/Constants.java b/src/main/java/io/github/ititus/si/quantity/Constants.java index c137251..d33f19b 100644 --- a/src/main/java/io/github/ititus/si/quantity/Constants.java +++ b/src/main/java/io/github/ititus/si/quantity/Constants.java @@ -1,13 +1,16 @@ package io.github.ititus.si.quantity; import io.github.ititus.si.quantity.type.*; +import io.github.ititus.si.unit.Units; import static io.github.ititus.math.number.BigRational.ofExp; +import static io.github.ititus.math.number.BigRationalConstants.PI; +import static io.github.ititus.math.number.BigRationalConstants.TWO_PI; import static io.github.ititus.si.unit.Units.*; public final class Constants { - /* Defined (exact) constants */ + /* Defined (exact) constants used for the definition of the base units */ // Length public static final Quantity SPEED_OF_LIGHT = METRES_PER_SECOND.get(299_792_458); @@ -31,19 +34,68 @@ public final class Constants { public static final Quantity LUMINOUS_EFFICACY_OF_540_THZ_RADIATION = LUMEN_PER_WATT.get(683); + /* Other defined constants */ + + public static final Quantity STANDARD_ACCELERATION_OF_GRAVITY = METRES_PER_SECOND_SQUARED.get(ofExp(980_665, -5)); + + public static final Quantity STANDARD_ATMOSPHERE = Units.STANDARD_ATMOSPHERE.get(1).asStandard(); + + public static final Quantity STANDARD_STATE_PRESSURE = BAR.get(1).asStandard(); + + + /* Constants derived from defined constants */ + + public static final Quantity REDUCED_PLANCK_CONSTANT = PLANCK_CONSTANT.divide(TWO_PI); + + public static final Quantity CONDUCTANCE_QUANTUM = ELEMENTARY_CHARGE.pow(2).multiply(2).divide(PLANCK_CONSTANT); + + public static final Quantity JOSEPHSON_CONSTANT = ELEMENTARY_CHARGE.multiply(2).divide(PLANCK_CONSTANT).as(SIEMENS); + + public static final Quantity VON_KLITZING_CONSTANT = PLANCK_CONSTANT.divide(ELEMENTARY_CHARGE.pow(2)).as(OHM); + + public static final Quantity MAGNETIC_FLUX_QUANTUM = PLANCK_CONSTANT.divide(ELEMENTARY_CHARGE.multiply(2)).as(WEBER); + + public static final Quantity INVERSE_CONDUCTANCE_QUANTUM = PLANCK_CONSTANT.divide(ELEMENTARY_CHARGE.pow(2).multiply(2)).as(OHM); + + public static final Quantity FARADAY_CONSTANT = AVOGADRO_CONSTANT.multiply(ELEMENTARY_CHARGE); + + /** + * Also known as the universal gas constant + */ + public static final Quantity MOLAR_GAS_CONSTANT = AVOGADRO_CONSTANT.multiply(BOLTZMANN_CONSTANT); + + public static final Quantity FIRST_RADIATION_CONSTANT = PLANCK_CONSTANT.multiply(SPEED_OF_LIGHT.pow(2)).multiply(TWO_PI); + + public static final Quantity FIRST_RADIATION_CONSTANT_FOR_SPECTRAL_RADIANCE = FIRST_RADIATION_CONSTANT.divide(STERADIAN.get(1)); + + public static final Quantity MOLAR_PLANCK_CONSTANT = AVOGADRO_CONSTANT.multiply(PLANCK_CONSTANT); + + public static final Quantity SECOND_RADIATION_CONSTANT = PLANCK_CONSTANT.multiply(SPEED_OF_LIGHT).divide(BOLTZMANN_CONSTANT); + + /* Measured constants */ - public static final Quantity GRAVITATIONAL_CONSTANT = - METRE.pow(3).divide(KILOGRAM.multiply(SECOND.pow(2))).get(ofExp(667_430, -16)); + public static final Quantity GRAVITATIONAL_CONSTANT = METRE.pow(3).divide(KILOGRAM.multiply(SECOND.pow(2))).get(ofExp(667_430, -16)); - public static final Quantity VACUUM_ELECTRIC_PERMITTIVITY = - FARAD_PER_METRE.get(ofExp(88_541_878_128L, -22)); + public static final Quantity VACUUM_ELECTRIC_PERMITTIVITY = FARAD_PER_METRE.get(ofExp(88_541_878_128L, -22)); - public static final Quantity VACUUM_MAGNETIC_PERMEABILITY = - HENRY_PER_METRE.get(ofExp(125_663_706_212L, -17)); + public static final Quantity VACUUM_MAGNETIC_PERMEABILITY = HENRY_PER_METRE.get(ofExp(125_663_706_212L, -17)); public static final Quantity ELECTRON_MASS = KILOGRAM.get(ofExp(91_093_837_015L, -41)); + public static final Quantity PROTON_MASS = KILOGRAM.get(ofExp(167_262_192_369L, -38)); + + public static final Quantity NEUTRON_MASS = KILOGRAM.get(ofExp(167_492_749_804L, -38)); + + /* Constants derived from measured constants */ + + /** + * Proportionality constant in Coulomb's law + */ + public static final Quantity COULOMB_CONSTANT = VACUUM_ELECTRIC_PERMITTIVITY.multiply(PI).multiply(4).inverse(); + + public static final Quantity FINE_STRUCTURE_CONSTANT = ELEMENTARY_CHARGE.pow(2).divide(VACUUM_ELECTRIC_PERMITTIVITY.multiply(REDUCED_PLANCK_CONSTANT).multiply(SPEED_OF_LIGHT).multiply(PI).multiply(4)).asStandard(Dimensionless.DIMENSIONLESS); + private Constants() { } } diff --git a/src/main/java/io/github/ititus/si/quantity/Quantity.java b/src/main/java/io/github/ititus/si/quantity/Quantity.java index 6f5afd4..ab92803 100644 --- a/src/main/java/io/github/ititus/si/quantity/Quantity.java +++ b/src/main/java/io/github/ititus/si/quantity/Quantity.java @@ -26,6 +26,10 @@ default Quantity convertToStandard() { > Quantity as(T type); + default Quantity asStandard() { + return asStandard(getUnit().getType()); + } + default > Quantity asStandard(T type) { return as(type.getStandardUnit()); } diff --git a/src/main/java/io/github/ititus/si/quantity/QuantityImpl.java b/src/main/java/io/github/ititus/si/quantity/QuantityImpl.java index ab85122..34f062e 100644 --- a/src/main/java/io/github/ititus/si/quantity/QuantityImpl.java +++ b/src/main/java/io/github/ititus/si/quantity/QuantityImpl.java @@ -44,12 +44,12 @@ public > Quantity as(T type) { public boolean equals(Object o) { if (this == o) { return true; - } - if (!(o instanceof QuantityImpl)) { + } else if (!(o instanceof Quantity)) { return false; } - QuantityImpl quantity = (QuantityImpl) o; - return value.equals(quantity.value) && unit.equals(quantity.unit); + + Quantity quantity = (Quantity) o; + return value.equals(quantity.getValue()) && unit.equals(quantity.getUnit()); } @Override diff --git a/src/main/java/io/github/ititus/si/quantity/type/Torque.java b/src/main/java/io/github/ititus/si/quantity/type/Torque.java new file mode 100644 index 0000000..3fe4cb6 --- /dev/null +++ b/src/main/java/io/github/ititus/si/quantity/type/Torque.java @@ -0,0 +1,13 @@ +package io.github.ititus.si.quantity.type; + +import static io.github.ititus.si.dimension.BaseDimension.*; +import static io.github.ititus.si.unit.Units.NEWTON_METER; + +public final class Torque extends AbstractQuantityType { + + public static final Torque TORQUE = new Torque(); + + private Torque() { + super(MASS.multiply(LENGTH.pow(2)).divide(TIME.pow(2)), () -> NEWTON_METER); + } +} diff --git a/src/main/java/io/github/ititus/si/unit/Units.java b/src/main/java/io/github/ititus/si/unit/Units.java index e01d6d0..fb51898 100644 --- a/src/main/java/io/github/ititus/si/unit/Units.java +++ b/src/main/java/io/github/ititus/si/unit/Units.java @@ -45,6 +45,7 @@ import static io.github.ititus.si.quantity.type.SubstanceAmount.SUBSTANCE_AMOUNT; import static io.github.ititus.si.quantity.type.Temperature.TEMPERATURE; import static io.github.ititus.si.quantity.type.Time.TIME; +import static io.github.ititus.si.quantity.type.Torque.TORQUE; import static io.github.ititus.si.quantity.type.Volume.VOLUME; public final class Units { @@ -148,6 +149,9 @@ public final class Units { public static final Unit KILOWATT = WATT.prefix(KILO); public static final Unit KILOWATT_HOUR = KILOWATT.multiply(HOUR).as(ENERGY); + // Torque + public static final Unit NEWTON_METER = NEWTON.multiply(METRE).as(TORQUE); + // Area public static final Unit SQUARE_METRE = METRE.pow(2).as(AREA); @@ -161,6 +165,9 @@ public final class Units { // Pressure public static final Unit PASCAL = NEWTON.divide(SQUARE_METRE).alternate("Pa").as(PRESSURE); + public static final Unit HECTOPASCAL = PASCAL.prefix(HECTO); + public static final Unit BAR = PASCAL.multiply(100_000).alternate("bar"); + public static final Unit STANDARD_ATMOSPHERE = PASCAL.multiply(101_325).alternate("atm"); // Electric Charge public static final Unit COULOMB = AMPERE.multiply(SECOND).alternate("C").as(ELECTRIC_CHARGE);