Skip to content

Commit

Permalink
Transferring aggregation tests for random model
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Peter <[email protected]>
  • Loading branch information
sebastian-peter committed Dec 11, 2024
1 parent 55104d2 commit 5e60447
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ trait LoadModelTestHelper {
): Dimensionless =
Each((expectedResult - actualResult).abs / expectedResult)

protected def get95Quantile[V](sortedArray: Array[V]): V = sortedArray(
(sortedArray.length * 0.95).toInt
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ProfileLoadModelSpec

}

"reach the targeted annual energy consumption" in {
"reach the targeted annual energy consumption in a simulated year" in {
forAll(
Table("profile", H0, L0, G0)
) { profile =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ import edu.ie3.simona.model.participant.load.random.RandomLoadParameters
import edu.ie3.simona.test.common.UnitSpec
import edu.ie3.util.TimeUtil
import edu.ie3.util.quantities.PowerSystemUnits
import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes}
import edu.ie3.util.scala.quantities.{
ApparentPower,
Kilovoltamperes,
Voltamperes,
}
import squants.Percent
import squants.energy.KilowattHours
import tech.units.indriya.quantity.Quantities

import java.util.UUID

class RandomLoadModelSpec extends UnitSpec {
class RandomLoadModelSpec extends UnitSpec with LoadModelTestHelper {

implicit val powerTolerance: ApparentPower = Voltamperes(1e-2)
private implicit val doubleTolerance: Double = 1e-6

private val simulationStartDate =
TimeUtil.withDefaults.toZonedDateTime("2019-01-01T00:00:00Z")

"A random load model" should {

val loadInput = new LoadInput(
Expand Down Expand Up @@ -158,11 +167,69 @@ class RandomLoadModelSpec extends UnitSpec {
secondHit shouldBe firstHit
}

}
}
"reach the targeted annual energy consumption in a simulated year" in {
val config = LoadRuntimeConfig(
calculateMissingReactivePowerWithModel = false,
scaling = 1.0,
uuids = List.empty,
modelBehaviour = "random",
reference = "energy",
)

val model = RandomLoadModel(
loadInput,
config,
)

val targetEnergyConsumption = KilowattHours(
loadInput
.geteConsAnnual()
.to(PowerSystemUnits.KILOWATTHOUR)
.getValue
.doubleValue
)

object RandomLoadModelSpec {
def get95Quantile[V](sortedArray: Array[V]): V = sortedArray(
(sortedArray.length * 0.95).toInt
)
calculateEnergyDiffForYear(
model,
simulationStartDate,
targetEnergyConsumption,
) should be < Percent(1d)
}

"approximately reach the maximum power in a simulated year" in {
val config = LoadRuntimeConfig(
calculateMissingReactivePowerWithModel = false,
scaling = 1.0,
uuids = List.empty,
modelBehaviour = "random",
reference = "power",
)

val model = RandomLoadModel(
loadInput,
config,
)

val targetMaximumPower = Kilovoltamperes(
loadInput
.getsRated()
.to(PowerSystemUnits.KILOVOLTAMPERE)
.getValue
.doubleValue
).toActivePower(loadInput.getCosPhiRated)

val powers = calculatePowerForYear(
model,
simulationStartDate,
).toIndexedSeq.sorted.toArray

val quantile95 = get95Quantile(powers)

getRelativeDifference(
quantile95,
targetMaximumPower,
) should be < Percent(2d)
}

}
}

0 comments on commit 5e60447

Please sign in to comment.