diff --git a/CHANGELOG.md b/CHANGELOG.md index e53329f6..2891f340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added implicit classes for `loactiontec.jts` Geometries that represent geographical geometries with functionality before located in `GeoUtils` [#163](https://github.com/ie3-institute/PowerSystemUtils/issues/163) - `OsmEntity` and `OsmContainer` to provide a simple, lightweight representation of openstreetmap data - QuantityUtils previously implemented in SIMONA [#288](https://github.com/ie3-institute/PowerSystemUtils/issues/288) -- Enhanced `RichQuantityDouble` with new units and generic method [#312](https://github.com/ie3-institute/PowerSystemUtils/issues/312) +- Enhanced `RichQuantityDouble` with new units and generic method [#312](https://github.com/ie3-institute/PowerSystemUtils/issues/312), [#322](https://github.com/ie3-institute/PowerSystemUtils/issues/322) ### Changed - Refactored `GeoUtils`, moved them to the scala package and tailored them toward the `loactiontec.jts` Geometries used in the `OsmContainer` [#163](https://github.com/ie3-institute/PowerSystemUtils/issues/163) diff --git a/src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala b/src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala index f52716c2..9144a292 100644 --- a/src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala +++ b/src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala @@ -39,7 +39,9 @@ import javax.measure.quantity.{ Energy, Length, Power, - Time + Temperature, + Time, + Volume } import scala.math.BigDecimal.RoundingMode import scala.math.BigDecimal.RoundingMode.RoundingMode @@ -211,6 +213,20 @@ object QuantityUtils { def asMicroFarradPerKilometre: ComparableQuantity[SpecificCapacitance] = as(MICROFARAD_PER_KILOMETRE) + /* ==== Thermal ==== */ + + def asKelvin: ComparableQuantity[Temperature] = as( + KELVIN + ) + + def asDegreeCelsius: ComparableQuantity[Temperature] = as( + CELSIUS + ) + + def asKiloWattPerKelvin: ComparableQuantity[ThermalConductance] = as( + KILOWATT_PER_KELVIN + ) + def asKiloWattHourPerKelvin: ComparableQuantity[HeatCapacity] = as(KILOWATTHOUR_PER_KELVIN) @@ -218,11 +234,13 @@ object QuantityUtils { : ComparableQuantity[SpecificHeatCapacity] = as(KILOWATTHOUR_PER_KELVIN_TIMES_CUBICMETRE) - /* ==== Thermal Conductance ==== */ + /* ==== Volume ==== */ - def asKiloWattPerKelvin: ComparableQuantity[ThermalConductance] = as( - KILOWATT_PER_KELVIN - ) + def asCubicMetre: ComparableQuantity[Volume] = + as(CUBIC_METRE) + + def asLitre: ComparableQuantity[Volume] = + as(LITRE) /** Create a quantity from the double with given unit * @param unit diff --git a/src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala b/src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala index 08aea295..cd918028 100644 --- a/src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala +++ b/src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala @@ -381,6 +381,32 @@ class QuantityUtilsSpec ) } + /* ==== Thermal ==== */ + + "convert a double to kelvin quantity" in { + value.asKelvin should equalWithTolerance( + Quantities.getQuantity( + value, + KELVIN + ) + ) + } + + "convert a double to a degree celsius quantity" in { + value.asDegreeCelsius should equalWithTolerance( + Quantities.getQuantity( + value, + CELSIUS + ) + ) + } + + "convert a double to a kilowatt per kelvin quantity" in { + value.asKiloWattPerKelvin should equalWithTolerance( + Quantities.getQuantity(value, KILOWATT_PER_KELVIN) + ) + } + "convert a double to a kilowatthour per kelvin quantity" in { value.asKiloWattHourPerKelvin should equalWithTolerance( Quantities.getQuantity(value, KILOWATTHOUR_PER_KELVIN) @@ -396,11 +422,23 @@ class QuantityUtilsSpec ) } - /* ==== Thermal Conductance ==== */ + /* ==== Volume ==== */ - "convert a double to a kilowatt per kelvin quantity" in { - value.asKiloWattPerKelvin should equalWithTolerance( - Quantities.getQuantity(value, KILOWATT_PER_KELVIN) + "convert a double to a cubic metre quantity" in { + value.asCubicMetre should equalWithTolerance( + Quantities.getQuantity( + value, + CUBIC_METRE + ) + ) + } + + "convert a double to a litre quantity" in { + value.asLitre should equalWithTolerance( + Quantities.getQuantity( + value, + LITRE + ) ) } }