Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 23 additions & 5 deletions src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,18 +213,34 @@ 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)

def asKiloWattHourPerKelvinTimesCubicMetre
: 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
Expand Down
46 changes: 42 additions & 4 deletions src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
)
}
}
Expand Down