summaryrefslogtreecommitdiff
path: root/opendc-simulator
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator')
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt19
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt13
2 files changed, 23 insertions, 9 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 b0ea7f0a..e5fcd938 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
@@ -37,18 +37,27 @@ public class SimPdu(
private val lossCoefficient: Double = 0.0,
) : SimPowerInlet() {
/**
- * The [SimResourceDistributor] that distributes the electricity over the PDU outlets.
+ * The [SimResourceSwitch] that distributes the electricity over the PDU outlets.
*/
- private val distributor = SimResourceDistributorMaxMin(interpreter)
+ private val switch = SimResourceSwitchMaxMin(interpreter)
+
+ /**
+ * The [SimResourceTransformer] that represents the input of the PDU.
+ */
+ private val forwarder = SimResourceForwarder()
/**
* Create a new PDU outlet.
*/
- public fun newOutlet(): Outlet = Outlet(distributor.newOutput())
+ public fun newOutlet(): Outlet = Outlet(switch.newOutput())
+
+ init {
+ switch.addInput(forwarder)
+ }
- override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer by distributor {
+ override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer by forwarder {
override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): Long {
- val duration = distributor.onNext(ctx, now, delta)
+ val duration = forwarder.onNext(ctx, now, delta)
val loss = computePowerLoss(ctx.demand)
val newLimit = ctx.demand + loss
diff --git a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
index 59006dfc..79c1b37d 100644
--- a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
+++ b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
@@ -41,20 +41,25 @@ public class SimUps(
/**
* The resource aggregator used to combine the input sources.
*/
- private val aggregator = SimResourceAggregatorMaxMin(interpreter)
+ private val switch = SimResourceSwitchMaxMin(interpreter)
+
+ /**
+ * The [SimResourceProvider] that represents the output of the UPS.
+ */
+ private val provider = switch.newOutput()
/**
* Create a new UPS outlet.
*/
public fun newInlet(): SimPowerInlet {
val forward = SimResourceForwarder(isCoupled = true)
- aggregator.addInput(forward)
+ switch.addInput(forward)
return Inlet(forward)
}
override fun onConnect(inlet: SimPowerInlet) {
val consumer = inlet.createConsumer()
- aggregator.startConsumer(object : SimResourceConsumer by consumer {
+ provider.startConsumer(object : SimResourceConsumer by consumer {
override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): Long {
val duration = consumer.onNext(ctx, now, delta)
val loss = computePowerLoss(ctx.demand)
@@ -67,7 +72,7 @@ public class SimUps(
}
override fun onDisconnect(inlet: SimPowerInlet) {
- aggregator.cancel()
+ provider.cancel()
}
/**