From 535e47b572527183a0d1659859a36e8c0f815584 Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Wed, 1 Sep 2021 15:22:29 +0200 Subject: [PATCH 1/5] add double type enrichment --- .../converter/NodeConverter.scala | 4 +- .../converter/types/LineTypeConverter.scala | 47 ++------ .../types/TransformerType2WConverter.scala | 24 ++--- .../util/TypeEnrichments.scala | 102 ++++++++++++++++++ .../common/ConverterTestData.scala | 67 ++++-------- 5 files changed, 140 insertions(+), 104 deletions(-) create mode 100644 src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala index 19359ce4..4e907198 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala @@ -11,6 +11,7 @@ import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} import edu.ie3.datamodel.models.voltagelevels.VoltageLevel import edu.ie3.powerFactory2psdm.exception.pf.GridConfigurationException import edu.ie3.powerFactory2psdm.model.entity.Node +import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble import edu.ie3.util.quantities.PowerSystemUnits.PU import org.locationtech.jts.geom.Point import tech.units.indriya.quantity.Quantities @@ -35,7 +36,6 @@ object NodeConverter { subnetId: Int, voltLvl: VoltageLevel ): NodeInput = { - val vTarget = Quantities.getQuantity(node.vTarget, PU) val geoPosition: Point = CoordinateConverter.convert(node.lat, node.lon) val slack = isSlack(node) new NodeInput( @@ -43,7 +43,7 @@ object NodeConverter { node.id, OperatorInput.NO_OPERATOR_ASSIGNED, OperationTime.notLimited(), - vTarget, + node.vTarget.toPu, slack, geoPosition, voltLvl, diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala index ebec8a1b..2ca15faa 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala @@ -7,57 +7,24 @@ package edu.ie3.powerFactory2psdm.converter.types import edu.ie3.datamodel.models.input.connector.`type`.LineTypeInput import edu.ie3.powerFactory2psdm.model.entity.types.LineType -import tech.units.indriya.quantity.Quantities -import edu.ie3.util.quantities.PowerSystemUnits.{ - KILOVOLT, - OHM_PER_KILOMETRE, - SIEMENS_PER_KILOMETRE -} -import tech.units.indriya.unit.Units.AMPERE - +import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble import java.util.UUID -import javax.measure.MetricPrefix /** Functionality to translate a [[LineType]] to a [[LineTypeInput]] */ object LineTypeConverter { def convert(input: LineType): LineTypeInput = { - val b = Quantities.getQuantity( - input.b, - MetricPrefix.MICRO(SIEMENS_PER_KILOMETRE) - ) - val g = Quantities.getQuantity( - input.g, - MetricPrefix.MICRO(SIEMENS_PER_KILOMETRE) - ) - val r = Quantities.getQuantity( - input.r, - OHM_PER_KILOMETRE - ) - val x = Quantities.getQuantity( - input.x, - OHM_PER_KILOMETRE - ) - val iMax = Quantities.getQuantity( - input.iMax, - MetricPrefix.KILO(AMPERE) - ) - val vRated = - Quantities.getQuantity( - input.vRated, - KILOVOLT - ) new LineTypeInput( UUID.randomUUID(), input.id, - b, - g, - r, - x, - iMax, - vRated + input.b.toMicroSiemensPerKilometre, + input.g.toMicroSiemensPerKilometre, + input.r.toOhmPerKilometre, + input.x.toOhmPerKilometre, + input.iMax.toKiloAmpere, + input.vRated.toKiloVolt ) } } diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala index 1ba607ea..528f35aa 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala @@ -12,13 +12,9 @@ import edu.ie3.powerFactory2psdm.exception.pf.{ ElementConfigurationException } import edu.ie3.powerFactory2psdm.model.entity.types.TransformerType2W -import tech.units.indriya.quantity.Quantities -import tech.units.indriya.unit.Units.{OHM, PERCENT, SIEMENS, VOLT} -import edu.ie3.util.quantities.PowerSystemUnits.{DEGREE_GEOM, VOLTAMPERE} - +import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble import math.{pow, sqrt} import java.util.UUID -import javax.measure.MetricPrefix object TransformerType2WConverter { @@ -67,15 +63,15 @@ object TransformerType2WConverter { new Transformer2WTypeInput( UUID.randomUUID(), input.id, - Quantities.getQuantity(rSc, OHM), - Quantities.getQuantity(xSc, OHM), - Quantities.getQuantity(input.sRated, MetricPrefix.MEGA(VOLTAMPERE)), - Quantities.getQuantity(vRatedA, VOLT), - Quantities.getQuantity(vRatedB, VOLT), - Quantities.getQuantity(gNoLoad, SIEMENS), - Quantities.getQuantity(bNoLoad, SIEMENS), - Quantities.getQuantity(input.dV, PERCENT), - Quantities.getQuantity(input.dPhi, DEGREE_GEOM), + rSc.toOhm, + xSc.toOhm, + sRated.toMegaVoltAmpere, + vRatedA.toVolt, + vRatedB.toVolt, + gNoLoad.toSiemens, + bNoLoad.toSiemens, + input.dV.toPercent, + input.dPhi.toDegreeGeom, tapSide, input.tapNeutr.toInt, input.tapMin.toInt, diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala b/src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala new file mode 100644 index 00000000..aa58023b --- /dev/null +++ b/src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala @@ -0,0 +1,102 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.powerFactory2psdm.util + +import edu.ie3.util.quantities.PowerSystemUnits.{ + DEGREE_GEOM, + KILOVOLT, + OHM_PER_KILOMETRE, + PU, + SIEMENS_PER_KILOMETRE, + VOLTAMPERE +} +import edu.ie3.util.quantities.interfaces.{ + SpecificConductance, + SpecificResistance +} +import tech.units.indriya.ComparableQuantity +import tech.units.indriya.quantity.Quantities +import tech.units.indriya.unit.Units.{AMPERE, OHM, PERCENT, SIEMENS, VOLT} + +import javax.measure.MetricPrefix +import javax.measure.quantity.{ + Angle, + Dimensionless, + ElectricConductance, + ElectricCurrent, + ElectricPotential, + ElectricResistance, + Power +} + +object TypeEnrichments { + + /** Implicit class to enrich the [[Double]] with [[ComparableQuantity]] + * conversion + * + * @param value + * the actual double value + */ + implicit class RichQuantityDouble(value: Double) { + + def toPercent: ComparableQuantity[Dimensionless] = + Quantities.getQuantity(value, PERCENT) + + def toPu: ComparableQuantity[Dimensionless] = + Quantities.getQuantity(value, PU) + + def toDegreeGeom: ComparableQuantity[Angle] = + Quantities.getQuantity(value, DEGREE_GEOM) + + def toSiemens: ComparableQuantity[ElectricConductance] = + Quantities.getQuantity(value, SIEMENS) + + def toNanoSiemens: ComparableQuantity[ElectricConductance] = + Quantities.getQuantity(value, MetricPrefix.NANO(SIEMENS)) + + def toMicroSiemensPerKilometre: ComparableQuantity[SpecificConductance] = + Quantities.getQuantity( + value, + MetricPrefix.MICRO(SIEMENS_PER_KILOMETRE) + ) + + def toOhm: ComparableQuantity[ElectricResistance] = Quantities.getQuantity( + value, + OHM + ) + + def toMilliOhm: ComparableQuantity[ElectricResistance] = + Quantities.getQuantity(value, MetricPrefix.MILLI(OHM)) + + def toOhmPerKilometre: ComparableQuantity[SpecificResistance] = + Quantities.getQuantity( + value, + OHM_PER_KILOMETRE + ) + + def toMegaVoltAmpere: ComparableQuantity[Power] = Quantities.getQuantity( + value, + MetricPrefix.MEGA(VOLTAMPERE) + ) + + def toKiloAmpere: ComparableQuantity[ElectricCurrent] = + Quantities.getQuantity( + value, + MetricPrefix.KILO(AMPERE) + ) + + def toVolt: ComparableQuantity[ElectricPotential] = + Quantities.getQuantity(value, VOLT) + + def toKiloVolt: ComparableQuantity[ElectricPotential] = + Quantities.getQuantity( + value, + KILOVOLT + ) + + } +} diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala index 7a8d583a..08011e87 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala @@ -11,11 +11,10 @@ import edu.ie3.datamodel.models.input.connector.`type`.{ LineTypeInput, Transformer2WTypeInput } -import edu.ie3.datamodel.models.{OperationTime, StandardUnits, UniqueEntity} +import edu.ie3.datamodel.models.{OperationTime, UniqueEntity} import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils.LV import edu.ie3.powerFactory2psdm.config.ConversionConfig - import java.io.File import edu.ie3.powerFactory2psdm.exception.io.GridParsingException import edu.ie3.powerFactory2psdm.exception.pf.TestException @@ -31,20 +30,12 @@ import edu.ie3.powerFactory2psdm.model.entity.types.{ TransformerType2W } import edu.ie3.powerFactory2psdm.model.PreprocessedPfGridModel -import edu.ie3.util.quantities.PowerSystemUnits.PU +import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble import org.locationtech.jts.geom.{Coordinate, GeometryFactory} import pureconfig.ConfigSource -import tech.units.indriya.quantity.Quantities -import tech.units.indriya.unit.Units.{OHM, PERCENT, SIEMENS} -import edu.ie3.util.quantities.PowerSystemUnits.{ - DEGREE_GEOM, - KILOVOLT, - VOLTAMPERE -} import pureconfig.generic.auto._ import java.util.UUID -import javax.measure.MetricPrefix object ConverterTestData extends LazyLogging { @@ -158,7 +149,7 @@ object ConverterTestData extends LazyLogging { "someNode", OperatorInput.NO_OPERATOR_ASSIGNED, OperationTime.notLimited(), - Quantities.getQuantity(1d, PU), + 1d.toPu, false, geometryFactory.createPoint(new Coordinate(11.1123, 52.1425)), LV, @@ -184,7 +175,7 @@ object ConverterTestData extends LazyLogging { "someSlackNode", OperatorInput.NO_OPERATOR_ASSIGNED, OperationTime.notLimited(), - Quantities.getQuantity(1d, PU), + 1d.toPu, true, geometryFactory.createPoint(new Coordinate(11.1123, 52.1425)), LV, @@ -230,30 +221,12 @@ object ConverterTestData extends LazyLogging { new LineTypeInput( UUID.randomUUID(), "someLineType", - Quantities.getQuantity( - 151.51515197753906, - StandardUnits.ADMITTANCE_PER_LENGTH - ), - Quantities.getQuantity( - 1.543, - StandardUnits.ADMITTANCE_PER_LENGTH - ), - Quantities.getQuantity( - 6.753542423248291, - StandardUnits.IMPEDANCE_PER_LENGTH - ), - Quantities.getQuantity( - 20.61956214904785, - StandardUnits.IMPEDANCE_PER_LENGTH - ), - Quantities.getQuantity( - 1000, - StandardUnits.ELECTRIC_CURRENT_MAGNITUDE - ), - Quantities.getQuantity( - 132.0, - StandardUnits.RATED_VOLTAGE_MAGNITUDE - ) + 151.51515197753906.toMicroSiemensPerKilometre, + 1.543.toMicroSiemensPerKilometre, + 6.753542423248291.toOhmPerKilometre, + 20.61956214904785.toOhmPerKilometre, + 1.toKiloAmpere, + 132.0.toKiloVolt ) ) ) @@ -288,17 +261,15 @@ object ConverterTestData extends LazyLogging { new Transformer2WTypeInput( UUID.randomUUID(), "SomeTrafo2wType", - Quantities.getQuantity(45.375, MetricPrefix.MILLI(OHM)), - Quantities.getQuantity(15.1249319, OHM), - Quantities.getQuantity(40d, MetricPrefix.MEGA(VOLTAMPERE)), - Quantities.getQuantity(110d, KILOVOLT), - Quantities.getQuantity(10d, KILOVOLT), - Quantities.getQuantity(826.4462809, MetricPrefix.NANO(SIEMENS)), - Quantities - .getQuantity(33047.519046, MetricPrefix.NANO(SIEMENS)) - .to(MetricPrefix.NANO(SIEMENS)), - Quantities.getQuantity(2.5, PERCENT), - Quantities.getQuantity(5d, DEGREE_GEOM), + 45.375.toMilliOhm, + 15.1249319.toOhm, + 40d.toMegaVoltAmpere, + 110d.toKiloVolt, + 10d.toKiloVolt, + 826.4462809.toNanoSiemens, + 33047.519046.toNanoSiemens, + 2.5.toPercent, + 5d.toDegreeGeom, false, 0, -10, From 5aaaf0764db9e55bf2f30b264f294bd568c7c310 Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:07:23 +0200 Subject: [PATCH 2/5] add testing --- .../converter/NodeConverter.scala | 4 +- .../converter/types/LineTypeConverter.scala | 2 +- .../types/TransformerType2WConverter.scala | 2 +- ...peEnrichments.scala => QuantityUtil.scala} | 5 +- .../common/ConverterTestData.scala | 2 +- .../util/QuantityUtilSpec.scala | 123 ++++++++++++++++++ 6 files changed, 130 insertions(+), 8 deletions(-) rename src/main/scala/edu/ie3/powerFactory2psdm/util/{TypeEnrichments.scala => QuantityUtil.scala} (95%) create mode 100644 src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala index 4e907198..83ca258c 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala @@ -11,10 +11,8 @@ import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} import edu.ie3.datamodel.models.voltagelevels.VoltageLevel import edu.ie3.powerFactory2psdm.exception.pf.GridConfigurationException import edu.ie3.powerFactory2psdm.model.entity.Node -import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble -import edu.ie3.util.quantities.PowerSystemUnits.PU +import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble import org.locationtech.jts.geom.Point -import tech.units.indriya.quantity.Quantities import java.util.UUID diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala index 2ca15faa..4546d6da 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala @@ -7,7 +7,7 @@ package edu.ie3.powerFactory2psdm.converter.types import edu.ie3.datamodel.models.input.connector.`type`.LineTypeInput import edu.ie3.powerFactory2psdm.model.entity.types.LineType -import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble import java.util.UUID /** Functionality to translate a [[LineType]] to a [[LineTypeInput]] diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala index 528f35aa..cfc2438f 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala @@ -12,7 +12,7 @@ import edu.ie3.powerFactory2psdm.exception.pf.{ ElementConfigurationException } import edu.ie3.powerFactory2psdm.model.entity.types.TransformerType2W -import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble import math.{pow, sqrt} import java.util.UUID diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala similarity index 95% rename from src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala rename to src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala index aa58023b..eb24571e 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/util/TypeEnrichments.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala @@ -33,10 +33,11 @@ import javax.measure.quantity.{ Power } -object TypeEnrichments { +@deprecated("This class will be moved to the PowerSystemUtils") +object QuantityUtil { /** Implicit class to enrich the [[Double]] with [[ComparableQuantity]] - * conversion + * conversion capabilities * * @param value * the actual double value diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala index 08011e87..72abfa16 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala @@ -30,7 +30,7 @@ import edu.ie3.powerFactory2psdm.model.entity.types.{ TransformerType2W } import edu.ie3.powerFactory2psdm.model.PreprocessedPfGridModel -import edu.ie3.powerFactory2psdm.util.TypeEnrichments.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble import org.locationtech.jts.geom.{Coordinate, GeometryFactory} import pureconfig.ConfigSource import pureconfig.generic.auto._ diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala new file mode 100644 index 00000000..ea9ba012 --- /dev/null +++ b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala @@ -0,0 +1,123 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.powerFactory2psdm.util + +import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.scalatest.QuantityMatchers.equalWithTolerance +import edu.ie3.util.quantities.PowerSystemUnits.{ + DEGREE_GEOM, + KILOVOLT, + OHM_PER_KILOMETRE, + PU, + SIEMENS_PER_KILOMETRE, + VOLTAMPERE +} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpecLike +import tech.units.indriya.quantity.Quantities +import tech.units.indriya.unit.Units.{AMPERE, OHM, PERCENT, SIEMENS, VOLT} + +import javax.measure.MetricPrefix + +class QuantityUtilSpec extends Matchers with AnyWordSpecLike { + "A rich quantity util" should { + implicit val quantityTolerance: Double = 1e-9 + val value = 10.123154122 + + "convert a double to a percent quantity" in { + value.toPercent should equalWithTolerance( + Quantities.getQuantity(value, PERCENT) + ) + } + + "convert a double to a pu value" in { + value.toPu should equalWithTolerance(Quantities.getQuantity(value, PU)) + } + + "convert a double to degree geom" in { + value.toDegreeGeom should equalWithTolerance( + Quantities.getQuantity(value, DEGREE_GEOM) + ) + } + + "convert a double to siemens" in { + value.toSiemens should equalWithTolerance( + Quantities.getQuantity(value, SIEMENS) + ) + } + + "convert a double to nano siemens" in { + value.toNanoSiemens should equalWithTolerance( + Quantities.getQuantity(value, MetricPrefix.NANO(SIEMENS)) + ) + } + + "convert a double to micro siemens per kilometre" in { + value.toMicroSiemensPerKilometre should equalWithTolerance( + Quantities.getQuantity(value, MetricPrefix.MICRO(SIEMENS_PER_KILOMETRE)) + ) + } + + "convert a double to ohm" in { + value.toOhm should equalWithTolerance( + Quantities.getQuantity( + value, + OHM + ) + ) + } + + "convert a double to milli ohm" in { + value.toMilliOhm should equalWithTolerance( + Quantities.getQuantity(value, MetricPrefix.MILLI(OHM)) + ) + } + + "convert a double to ohm per kilometre" in { + value.toOhmPerKilometre should equalWithTolerance( + Quantities.getQuantity( + value, + OHM_PER_KILOMETRE + ) + ) + } + + "convert a double to mega volt ampere" in { + value.toMegaVoltAmpere should equalWithTolerance( + Quantities.getQuantity( + value, + MetricPrefix.MEGA(VOLTAMPERE) + ) + ) + } + + "convert a double to kilo ampere" in { + value.toKiloAmpere should equalWithTolerance( + Quantities.getQuantity( + value, + MetricPrefix.KILO(AMPERE) + ) + ) + } + + "convert a double to volt" in { + value.toVolt should equalWithTolerance( + Quantities.getQuantity(value, VOLT) + ) + } + + "convert a double to kilo volt" in { + value.toKiloVolt should equalWithTolerance( + Quantities.getQuantity( + value, + KILOVOLT + ) + ) + } + + } +} From 12c04e570e9bc64bf40415d746542aa0c80b13e0 Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:09:05 +0200 Subject: [PATCH 3/5] ssss --- .../edu/ie3/powerFactory2psdm/converter/NodeConverter.scala | 2 +- .../powerFactory2psdm/converter/types/LineTypeConverter.scala | 2 +- .../converter/types/TransformerType2WConverter.scala | 2 +- .../util/{QuantityUtil.scala => QuantityUtils.scala} | 2 +- .../edu/ie3/powerFactory2psdm/common/ConverterTestData.scala | 2 +- .../util/{QuantityUtilSpec.scala => QuantityUtilsSpec.scala} | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename src/main/scala/edu/ie3/powerFactory2psdm/util/{QuantityUtil.scala => QuantityUtils.scala} (99%) rename src/test/scala/edu/ie3/powerFactory2psdm/util/{QuantityUtilSpec.scala => QuantityUtilsSpec.scala} (95%) diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala index 83ca258c..21cb60a4 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/NodeConverter.scala @@ -11,7 +11,7 @@ import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput} import edu.ie3.datamodel.models.voltagelevels.VoltageLevel import edu.ie3.powerFactory2psdm.exception.pf.GridConfigurationException import edu.ie3.powerFactory2psdm.model.entity.Node -import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import org.locationtech.jts.geom.Point import java.util.UUID diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala index 4546d6da..6a8e28eb 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/LineTypeConverter.scala @@ -7,7 +7,7 @@ package edu.ie3.powerFactory2psdm.converter.types import edu.ie3.datamodel.models.input.connector.`type`.LineTypeInput import edu.ie3.powerFactory2psdm.model.entity.types.LineType -import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import java.util.UUID /** Functionality to translate a [[LineType]] to a [[LineTypeInput]] diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala index cfc2438f..8b8f943b 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/converter/types/TransformerType2WConverter.scala @@ -12,7 +12,7 @@ import edu.ie3.powerFactory2psdm.exception.pf.{ ElementConfigurationException } import edu.ie3.powerFactory2psdm.model.entity.types.TransformerType2W -import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import math.{pow, sqrt} import java.util.UUID diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala similarity index 99% rename from src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala rename to src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala index eb24571e..55b9ef01 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtil.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala @@ -34,7 +34,7 @@ import javax.measure.quantity.{ } @deprecated("This class will be moved to the PowerSystemUtils") -object QuantityUtil { +object QuantityUtils { /** Implicit class to enrich the [[Double]] with [[ComparableQuantity]] * conversion capabilities diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala index 72abfa16..f86421b5 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala @@ -30,7 +30,7 @@ import edu.ie3.powerFactory2psdm.model.entity.types.{ TransformerType2W } import edu.ie3.powerFactory2psdm.model.PreprocessedPfGridModel -import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import org.locationtech.jts.geom.{Coordinate, GeometryFactory} import pureconfig.ConfigSource import pureconfig.generic.auto._ diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala similarity index 95% rename from src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala rename to src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala index ea9ba012..c24cb723 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilSpec.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala @@ -6,7 +6,7 @@ package edu.ie3.powerFactory2psdm.util -import edu.ie3.powerFactory2psdm.util.QuantityUtil.RichQuantityDouble +import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import edu.ie3.scalatest.QuantityMatchers.equalWithTolerance import edu.ie3.util.quantities.PowerSystemUnits.{ DEGREE_GEOM, @@ -23,7 +23,7 @@ import tech.units.indriya.unit.Units.{AMPERE, OHM, PERCENT, SIEMENS, VOLT} import javax.measure.MetricPrefix -class QuantityUtilSpec extends Matchers with AnyWordSpecLike { +class QuantityUtilsSpec extends Matchers with AnyWordSpecLike { "A rich quantity util" should { implicit val quantityTolerance: Double = 1e-9 val value = 10.123154122 From 60ebb9e648ae5aa9373a76946050a527dc25b06b Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Thu, 9 Sep 2021 09:51:13 +0200 Subject: [PATCH 4/5] some more conversions --- .../util/QuantityUtils.scala | 62 +++++++++++------- .../util/QuantityUtilsSpec.scala | 65 ++++++++++++++++--- 2 files changed, 96 insertions(+), 31 deletions(-) diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala index 55b9ef01..c4c442aa 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala @@ -6,32 +6,14 @@ package edu.ie3.powerFactory2psdm.util -import edu.ie3.util.quantities.PowerSystemUnits.{ - DEGREE_GEOM, - KILOVOLT, - OHM_PER_KILOMETRE, - PU, - SIEMENS_PER_KILOMETRE, - VOLTAMPERE -} -import edu.ie3.util.quantities.interfaces.{ - SpecificConductance, - SpecificResistance -} +import edu.ie3.util.quantities.PowerSystemUnits._ +import edu.ie3.util.quantities.interfaces.{Currency, DimensionlessRate, EnergyPrice, SpecificConductance, SpecificResistance} import tech.units.indriya.ComparableQuantity import tech.units.indriya.quantity.Quantities -import tech.units.indriya.unit.Units.{AMPERE, OHM, PERCENT, SIEMENS, VOLT} +import tech.units.indriya.unit.Units.{AMPERE, HOUR, OHM, PERCENT, SIEMENS, VOLT} import javax.measure.MetricPrefix -import javax.measure.quantity.{ - Angle, - Dimensionless, - ElectricConductance, - ElectricCurrent, - ElectricPotential, - ElectricResistance, - Power -} +import javax.measure.quantity.{Angle, Dimensionless, ElectricConductance, ElectricCurrent, ElectricPotential, ElectricResistance, Energy, Power, Time} @deprecated("This class will be moved to the PowerSystemUtils") object QuantityUtils { @@ -99,5 +81,41 @@ object QuantityUtils { KILOVOLT ) + def toEuro: ComparableQuantity[Currency] = + Quantities.getQuantity( + value, + EURO + ) + + def toEuroPerMegaWattHour: ComparableQuantity[EnergyPrice] = + Quantities.getQuantity( + value, + EURO_PER_MEGAWATTHOUR + ) + + def toKiloWattHour: ComparableQuantity[Energy] = + Quantities.getQuantity( + value, + KILOWATTHOUR + ) + + def toPercentPerHour: ComparableQuantity[DimensionlessRate] = + Quantities.getQuantity( + value, + PERCENT_PER_HOUR + ) + + def toHour: ComparableQuantity[Time] = + Quantities.getQuantity( + value, + HOUR + ) + + def toKiloWatt: ComparableQuantity[Power] = + Quantities.getQuantity( + value, + KILOWATT + ) + } } diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala index c24cb723..38d1deaf 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala @@ -8,18 +8,11 @@ package edu.ie3.powerFactory2psdm.util import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import edu.ie3.scalatest.QuantityMatchers.equalWithTolerance -import edu.ie3.util.quantities.PowerSystemUnits.{ - DEGREE_GEOM, - KILOVOLT, - OHM_PER_KILOMETRE, - PU, - SIEMENS_PER_KILOMETRE, - VOLTAMPERE -} +import edu.ie3.util.quantities.PowerSystemUnits.{DEGREE_GEOM, EURO, EURO_PER_MEGAWATTHOUR, KILOVOLT, KILOWATT, KILOWATTHOUR, OHM_PER_KILOMETRE, PERCENT_PER_HOUR, PU, SIEMENS_PER_KILOMETRE, VOLTAMPERE} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike import tech.units.indriya.quantity.Quantities -import tech.units.indriya.unit.Units.{AMPERE, OHM, PERCENT, SIEMENS, VOLT} +import tech.units.indriya.unit.Units.{AMPERE, HOUR, OHM, PERCENT, SIEMENS, VOLT} import javax.measure.MetricPrefix @@ -119,5 +112,59 @@ class QuantityUtilsSpec extends Matchers with AnyWordSpecLike { ) } + "convert a double to euro" in { + value.toEuro should equalWithTolerance( + Quantities.getQuantity( + value, + EURO + ) + ) + } + + "convert a double to euro per megawatt hour" in { + value.toEuroPerMegaWattHour should equalWithTolerance( + Quantities.getQuantity( + value, + EURO_PER_MEGAWATTHOUR + ) + ) + } + + "convert a double to euro per kilowatt hour" in { + value.toKiloWattHour should equalWithTolerance( + Quantities.getQuantity( + value, + KILOWATTHOUR + ) + ) + } + + "convert a double to percent per hour" in { + value.toPercentPerHour should equalWithTolerance( + Quantities.getQuantity( + value, + PERCENT_PER_HOUR + ) + ) + } + + "convert a double to hour" in { + value.toHour should equalWithTolerance( + Quantities.getQuantity( + value, + HOUR + ) + ) + } + + "convert a double to kilowatt" in { + value.toKiloWatt should equalWithTolerance( + Quantities.getQuantity( + value, + KILOWATT + ) + ) + } + } } From a6457d6233efa291f55ac9ab16cfe9fea6bf6c9a Mon Sep 17 00:00:00 2001 From: t-ober <63147366+t-ober@users.noreply.github.com> Date: Thu, 9 Sep 2021 09:51:51 +0200 Subject: [PATCH 5/5] fmt --- .../util/QuantityUtils.scala | 20 +++++++++++++++++-- .../util/QuantityUtilsSpec.scala | 14 ++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala index c4c442aa..cf267053 100644 --- a/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala +++ b/src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala @@ -7,13 +7,29 @@ package edu.ie3.powerFactory2psdm.util import edu.ie3.util.quantities.PowerSystemUnits._ -import edu.ie3.util.quantities.interfaces.{Currency, DimensionlessRate, EnergyPrice, SpecificConductance, SpecificResistance} +import edu.ie3.util.quantities.interfaces.{ + Currency, + DimensionlessRate, + EnergyPrice, + SpecificConductance, + SpecificResistance +} import tech.units.indriya.ComparableQuantity import tech.units.indriya.quantity.Quantities import tech.units.indriya.unit.Units.{AMPERE, HOUR, OHM, PERCENT, SIEMENS, VOLT} import javax.measure.MetricPrefix -import javax.measure.quantity.{Angle, Dimensionless, ElectricConductance, ElectricCurrent, ElectricPotential, ElectricResistance, Energy, Power, Time} +import javax.measure.quantity.{ + Angle, + Dimensionless, + ElectricConductance, + ElectricCurrent, + ElectricPotential, + ElectricResistance, + Energy, + Power, + Time +} @deprecated("This class will be moved to the PowerSystemUtils") object QuantityUtils { diff --git a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala index 38d1deaf..45120fd6 100644 --- a/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala +++ b/src/test/scala/edu/ie3/powerFactory2psdm/util/QuantityUtilsSpec.scala @@ -8,7 +8,19 @@ package edu.ie3.powerFactory2psdm.util import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble import edu.ie3.scalatest.QuantityMatchers.equalWithTolerance -import edu.ie3.util.quantities.PowerSystemUnits.{DEGREE_GEOM, EURO, EURO_PER_MEGAWATTHOUR, KILOVOLT, KILOWATT, KILOWATTHOUR, OHM_PER_KILOMETRE, PERCENT_PER_HOUR, PU, SIEMENS_PER_KILOMETRE, VOLTAMPERE} +import edu.ie3.util.quantities.PowerSystemUnits.{ + DEGREE_GEOM, + EURO, + EURO_PER_MEGAWATTHOUR, + KILOVOLT, + KILOWATT, + KILOWATTHOUR, + OHM_PER_KILOMETRE, + PERCENT_PER_HOUR, + PU, + SIEMENS_PER_KILOMETRE, + VOLTAMPERE +} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike import tech.units.indriya.quantity.Quantities