Skip to content

Commit

Permalink
add more units and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
iTitus committed Oct 19, 2021
1 parent 17493ae commit 441976b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
66 changes: 59 additions & 7 deletions src/main/java/io/github/ititus/si/quantity/Constants.java
Original file line number Diff line number Diff line change
@@ -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> SPEED_OF_LIGHT = METRES_PER_SECOND.get(299_792_458);
Expand All @@ -31,19 +34,68 @@ public final class Constants {
public static final Quantity<LuminousEfficacy> LUMINOUS_EFFICACY_OF_540_THZ_RADIATION = LUMEN_PER_WATT.get(683);


/* Other defined constants */

public static final Quantity<Acceleration> STANDARD_ACCELERATION_OF_GRAVITY = METRES_PER_SECOND_SQUARED.get(ofExp(980_665, -5));

public static final Quantity<Pressure> STANDARD_ATMOSPHERE = Units.STANDARD_ATMOSPHERE.get(1).asStandard();

public static final Quantity<Pressure> 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<ElectricConductance> JOSEPHSON_CONSTANT = ELEMENTARY_CHARGE.multiply(2).divide(PLANCK_CONSTANT).as(SIEMENS);

public static final Quantity<ElectricResistance> VON_KLITZING_CONSTANT = PLANCK_CONSTANT.divide(ELEMENTARY_CHARGE.pow(2)).as(OHM);

public static final Quantity<MagneticFlux> 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<ElectricPermittivity> VACUUM_ELECTRIC_PERMITTIVITY =
FARAD_PER_METRE.get(ofExp(88_541_878_128L, -22));
public static final Quantity<ElectricPermittivity> VACUUM_ELECTRIC_PERMITTIVITY = FARAD_PER_METRE.get(ofExp(88_541_878_128L, -22));

public static final Quantity<MagneticPermeability> VACUUM_MAGNETIC_PERMEABILITY =
HENRY_PER_METRE.get(ofExp(125_663_706_212L, -17));
public static final Quantity<MagneticPermeability> VACUUM_MAGNETIC_PERMEABILITY = HENRY_PER_METRE.get(ofExp(125_663_706_212L, -17));

public static final Quantity<Mass> ELECTRON_MASS = KILOGRAM.get(ofExp(91_093_837_015L, -41));

public static final Quantity<Mass> PROTON_MASS = KILOGRAM.get(ofExp(167_262_192_369L, -38));

public static final Quantity<Mass> 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<Dimensionless> 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() {
}
}
4 changes: 4 additions & 0 deletions src/main/java/io/github/ititus/si/quantity/Quantity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ default Quantity<Q> convertToStandard() {

<T extends QuantityType<T>> Quantity<T> as(T type);

default Quantity<Q> asStandard() {
return asStandard(getUnit().getType());
}

default <T extends QuantityType<T>> Quantity<T> asStandard(T type) {
return as(type.getStandardUnit());
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/ititus/si/quantity/QuantityImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public <T extends QuantityType<T>> Quantity<T> 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
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/ititus/si/quantity/type/Torque.java
Original file line number Diff line number Diff line change
@@ -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<Torque> {

public static final Torque TORQUE = new Torque();

private Torque() {
super(MASS.multiply(LENGTH.pow(2)).divide(TIME.pow(2)), () -> NEWTON_METER);
}
}
7 changes: 7 additions & 0 deletions src/main/java/io/github/ititus/si/unit/Units.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -148,6 +149,9 @@ public final class Units {
public static final Unit<Power> KILOWATT = WATT.prefix(KILO);
public static final Unit<Energy> KILOWATT_HOUR = KILOWATT.multiply(HOUR).as(ENERGY);

// Torque
public static final Unit<Torque> NEWTON_METER = NEWTON.multiply(METRE).as(TORQUE);

// Area
public static final Unit<Area> SQUARE_METRE = METRE.pow(2).as(AREA);

Expand All @@ -161,6 +165,9 @@ public final class Units {

// Pressure
public static final Unit<Pressure> PASCAL = NEWTON.divide(SQUARE_METRE).alternate("Pa").as(PRESSURE);
public static final Unit<Pressure> HECTOPASCAL = PASCAL.prefix(HECTO);
public static final Unit<Pressure> BAR = PASCAL.multiply(100_000).alternate("bar");
public static final Unit<Pressure> STANDARD_ATMOSPHERE = PASCAL.multiply(101_325).alternate("atm");

// Electric Charge
public static final Unit<ElectricCharge> COULOMB = AMPERE.multiply(SECOND).alternate("C").as(ELECTRIC_CHARGE);
Expand Down

0 comments on commit 441976b

Please sign in to comment.