Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/to/#108-pimp-my-double' into to/#…
Browse files Browse the repository at this point in the history
…115-biogas-conversion

# Conflicts:
#	src/test/scala/edu/ie3/powerFactory2psdm/common/ConverterTestData.scala
  • Loading branch information
t-ober committed Sep 9, 2021
2 parents 6426956 + a6457d6 commit 67955f4
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +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.util.quantities.PowerSystemUnits.PU
import edu.ie3.powerFactory2psdm.util.QuantityUtils.RichQuantityDouble
import org.locationtech.jts.geom.Point
import tech.units.indriya.quantity.Quantities

import java.util.UUID

Expand All @@ -35,15 +34,14 @@ 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(
UUID.randomUUID(),
node.id,
OperatorInput.NO_OPERATOR_ASSIGNED,
OperationTime.notLimited(),
vTarget,
node.vTarget.toPu,
slack,
geoPosition,
voltLvl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.QuantityUtils.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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.QuantityUtils.RichQuantityDouble
import math.{pow, sqrt}
import java.util.UUID
import javax.measure.MetricPrefix

object TransformerType2WConverter {

Expand Down Expand Up @@ -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,
Expand Down
137 changes: 137 additions & 0 deletions src/main/scala/edu/ie3/powerFactory2psdm/util/QuantityUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* © 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._
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
}

@deprecated("This class will be moved to the PowerSystemUtils")
object QuantityUtils {

/** Implicit class to enrich the [[Double]] with [[ComparableQuantity]]
* conversion capabilities
*
* @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
)

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
)

}
}
Loading

0 comments on commit 67955f4

Please sign in to comment.