diff options
| author | Hongyu He <hongyuhe.cs@googlemail.com> | 2021-06-10 13:27:56 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-06-11 17:05:09 +0200 |
| commit | f0c0c6d45165ad0ce398ec7300b11bf77c7ae5a6 (patch) | |
| tree | 87cca1749779bdf34f7e7ca05ef0426caeba30b9 /opendc-simulator/opendc-simulator-power/src/main | |
| parent | b6acc74b38643615df02ef2131380c5e8eba00dd (diff) | |
simulator: Add power loss to SimPdu
This change adds a model for power loss to the Power Distribution Unit
(PDU) model in OpenDC.
Diffstat (limited to 'opendc-simulator/opendc-simulator-power/src/main')
| -rw-r--r-- | opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt index 365f3435..ed3175c7 100644 --- a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt +++ b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt @@ -28,8 +28,14 @@ import org.opendc.simulator.resources.* * A model of a Power Distribution Unit (PDU). * * @param interpreter The underlying [SimResourceInterpreter] to drive the simulation under the hood. + * @param idlePower The idle power consumption of the PDU independent of the load on the PDU. + * @param lossCoefficient The coefficient for the power loss of the PDU proportional to the square load. */ -public class SimPdu(interpreter: SimResourceInterpreter) : SimPowerInlet() { +public class SimPdu( + interpreter: SimResourceInterpreter, + public val idlePower: Double = 0.0, + public val lossCoefficient: Double = 0.0, +) : SimPowerInlet() { /** * The [SimResourceDistributor] that distributes the electricity over the PDU outlets. */ @@ -40,11 +46,41 @@ public class SimPdu(interpreter: SimResourceInterpreter) : SimPowerInlet() { */ public fun newOutlet(): Outlet = Outlet(distributor.newOutput()) - override fun createConsumer(): SimResourceConsumer = distributor + override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer by distributor { + override fun onNext(ctx: SimResourceContext): SimResourceCommand { + return when (val cmd = distributor.onNext(ctx)) { + is SimResourceCommand.Consume -> { + val duration = cmd.work / cmd.limit + val loss = computePowerLoss(cmd.limit) + val newLimit = cmd.limit + loss + + SimResourceCommand.Consume(duration * newLimit, newLimit, cmd.deadline) + } + is SimResourceCommand.Idle -> { + val loss = computePowerLoss(0.0) + if (loss > 0.0) + SimResourceCommand.Consume(Double.POSITIVE_INFINITY, loss, cmd.deadline) + else + cmd + } + else -> cmd + } + } + + override fun toString(): String = "SimPdu.Consumer" + } override fun toString(): String = "SimPdu" /** + * Compute the power loss that occurs in the PDU. + */ + private fun computePowerLoss(load: Double): Double { + // See https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN + return idlePower + lossCoefficient * (load * load) + } + + /** * A PDU outlet. */ public class Outlet(private val provider: SimResourceProvider) : SimPowerOutlet(), AutoCloseable { |
