summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-power
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-10-25 13:32:41 +0200
committerGitHub <noreply@github.com>2024-10-25 13:32:41 +0200
commit5a365dbc068f2a8cdfa9813c39cc84bb30e15637 (patch)
tree72716d562787b85e03cdc7fe1d30c827054d25a0 /opendc-simulator/opendc-simulator-power
parent27f5b7dcb05aefdab9b762175d538931face0aba (diff)
Rewrote the FlowEngine (#256)
* Removed unused components. Updated tests. Improved checkpointing model Improved model, started with SimPowerSource implemented FailureModels and Checkpointing First working version midway commit first update All simulation are now run with a single CPU and single MemoryUnit. multi CPUs are combined into one. This is for performance and explainability. * fixed merge conflicts * Updated M3SA paths. * Fixed small typo
Diffstat (limited to 'opendc-simulator/opendc-simulator-power')
-rw-r--r--opendc-simulator/opendc-simulator-power/build.gradle.kts34
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPdu.java141
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerInlet.java53
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerOutlet.java91
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerSource.java71
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimUps.java137
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt133
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt155
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt108
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt49
10 files changed, 0 insertions, 972 deletions
diff --git a/opendc-simulator/opendc-simulator-power/build.gradle.kts b/opendc-simulator/opendc-simulator-power/build.gradle.kts
deleted file mode 100644
index ea36ce75..00000000
--- a/opendc-simulator/opendc-simulator-power/build.gradle.kts
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-description = "Library for simulating datacenter power components"
-
-plugins {
- `kotlin-library-conventions`
-}
-
-dependencies {
- api(projects.opendcSimulator.opendcSimulatorFlow)
- implementation(projects.opendcSimulator.opendcSimulatorCore)
-
- testImplementation(libs.slf4j.simple)
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPdu.java b/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPdu.java
deleted file mode 100644
index 8790a2d7..00000000
--- a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPdu.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power;
-
-import org.jetbrains.annotations.NotNull;
-import org.opendc.simulator.flow2.FlowGraph;
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-import org.opendc.simulator.flow2.mux.FlowMultiplexer;
-import org.opendc.simulator.flow2.mux.MaxMinFlowMultiplexer;
-import org.opendc.simulator.flow2.util.FlowTransform;
-import org.opendc.simulator.flow2.util.FlowTransformer;
-
-/**
- * A model of a Power Distribution Unit (PDU).
- */
-public final class SimPdu extends SimPowerInlet {
- /**
- * The {@link FlowMultiplexer} that distributes the electricity over the PDU outlets.
- */
- private final MaxMinFlowMultiplexer mux;
-
- /**
- * A {@link FlowTransformer} that applies the power loss to the PDU's power inlet.
- */
- private final FlowTransformer transformer;
-
- /**
- * Construct a {@link SimPdu} instance.
- *
- * @param graph The underlying {@link FlowGraph} to which the PDU belongs.
- * @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 SimPdu(FlowGraph graph, float idlePower, float lossCoefficient) {
- this.mux = new MaxMinFlowMultiplexer(graph);
- this.transformer = new FlowTransformer(graph, new FlowTransform() {
- @Override
- public float apply(float value) {
- // See https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- return value * (lossCoefficient * value + 1) + idlePower;
- }
-
- @Override
- public float applyInverse(float value) {
- float c = lossCoefficient;
- if (c != 0.f) {
- return (float) (1 + Math.sqrt(4 * value * c - 4 * idlePower * c + 1)) / (2 * c);
- } else {
- return value - idlePower;
- }
- }
- });
-
- graph.connect(mux.newOutput(), transformer.getInput());
- }
-
- /**
- * Construct a {@link SimPdu} instance without any loss.
- *
- * @param graph The underlying {@link FlowGraph} to which the PDU belongs.
- */
- public SimPdu(FlowGraph graph) {
- this(graph, 0.f, 0.f);
- }
-
- /**
- * Create a new PDU outlet.
- */
- public PowerOutlet newOutlet() {
- return new PowerOutlet(mux);
- }
-
- @NotNull
- @Override
- public Outlet getFlowOutlet() {
- return transformer.getOutput();
- }
-
- @Override
- public String toString() {
- return "SimPdu";
- }
-
- /**
- * A PDU outlet.
- */
- public static final class PowerOutlet extends SimPowerOutlet implements AutoCloseable {
- private final FlowMultiplexer mux;
- private final Inlet inlet;
- private boolean isClosed;
-
- private PowerOutlet(FlowMultiplexer mux) {
- this.mux = mux;
- this.inlet = mux.newInput();
- }
-
- /**
- * Remove the outlet from the PDU.
- */
- @Override
- public void close() {
- isClosed = true;
- mux.releaseInput(inlet);
- }
-
- @Override
- public String toString() {
- return "SimPdu.Outlet";
- }
-
- @NotNull
- @Override
- protected Inlet getFlowInlet() {
- if (isClosed) {
- throw new IllegalStateException("Outlet is closed");
- }
- return inlet;
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerInlet.java b/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerInlet.java
deleted file mode 100644
index a6e167c2..00000000
--- a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerInlet.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power;
-
-import org.opendc.simulator.flow2.Outlet;
-
-/**
- * An abstract inlet that consumes electricity from a power outlet.
- */
-public abstract class SimPowerInlet {
- SimPowerOutlet outlet;
-
- /**
- * Determine whether the inlet is connected to a {@link SimPowerOutlet}.
- *
- * @return <code>true</code> if the inlet is connected to an outlet, <code>false</code> otherwise.
- */
- public boolean isConnected() {
- return outlet != null;
- }
-
- /**
- * Return the {@link SimPowerOutlet} to which the inlet is connected.
- */
- public SimPowerOutlet getOutlet() {
- return outlet;
- }
-
- /**
- * Return the flow {@link Outlet} that models the consumption of a power inlet as flow output.
- */
- protected abstract Outlet getFlowOutlet();
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerOutlet.java b/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerOutlet.java
deleted file mode 100644
index e33d35d0..00000000
--- a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerOutlet.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power;
-
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-
-/**
- * An abstract outlet that provides a source of electricity for datacenter components.
- */
-public abstract class SimPowerOutlet {
- private SimPowerInlet inlet;
-
- /**
- * Determine whether the outlet is connected to a {@link SimPowerInlet}.
- *
- * @return <code>true</code> if the outlet is connected to an inlet, <code>false</code> otherwise.
- */
- public boolean isConnected() {
- return inlet != null;
- }
-
- /**
- * Return the {@link SimPowerInlet} to which the outlet is connected.
- */
- public SimPowerInlet getInlet() {
- return inlet;
- }
-
- /**
- * Connect the specified power [inlet] to this outlet.
- *
- * @param inlet The inlet to connect to the outlet.
- */
- public void connect(SimPowerInlet inlet) {
- if (isConnected()) {
- throw new IllegalStateException("Outlet already connected");
- }
- if (inlet.isConnected()) {
- throw new IllegalStateException("Inlet already connected");
- }
-
- this.inlet = inlet;
- this.inlet.outlet = this;
-
- final Inlet flowInlet = getFlowInlet();
- final Outlet flowOutlet = inlet.getFlowOutlet();
-
- flowInlet.getGraph().connect(flowOutlet, flowInlet);
- }
-
- /**
- * Disconnect the connected power outlet from this inlet
- */
- public void disconnect() {
- SimPowerInlet inlet = this.inlet;
- if (inlet != null) {
- this.inlet = null;
- assert inlet.outlet == this : "Inlet state incorrect";
- inlet.outlet = null;
-
- final Inlet flowInlet = getFlowInlet();
- flowInlet.getGraph().disconnect(flowInlet);
- }
- }
-
- /**
- * Return the flow {@link Inlet} that models the consumption of a power outlet as flow input.
- */
- protected abstract Inlet getFlowInlet();
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerSource.java b/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerSource.java
deleted file mode 100644
index a2d62c48..00000000
--- a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimPowerSource.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power;
-
-import org.opendc.simulator.flow2.FlowGraph;
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.sink.SimpleFlowSink;
-
-/**
- * A {@link SimPowerOutlet} that represents a source of electricity with a maximum capacity.
- */
-public final class SimPowerSource extends SimPowerOutlet {
- /**
- * The resource source that drives this power source.
- */
- private final SimpleFlowSink sink;
-
- /**
- * Construct a {@link SimPowerSource} instance.
- *
- * @param graph The underlying {@link FlowGraph} to which the power source belongs.
- * @param capacity The maximum amount of power provided by the source.
- */
- public SimPowerSource(FlowGraph graph, float capacity) {
- this.sink = new SimpleFlowSink(graph, capacity);
- }
-
- /**
- * Return the capacity of the power source.
- */
- public float getCapacity() {
- return sink.getCapacity();
- }
-
- /**
- * Return the power draw at this instant.
- */
- public float getPowerDraw() {
- return sink.getRate();
- }
-
- @Override
- protected Inlet getFlowInlet() {
- return sink.getInput();
- }
-
- @Override
- public String toString() {
- return "SimPowerSource";
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimUps.java b/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimUps.java
deleted file mode 100644
index df7508d9..00000000
--- a/opendc-simulator/opendc-simulator-power/src/main/java/org/opendc/simulator/power/SimUps.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power;
-
-import org.jetbrains.annotations.NotNull;
-import org.opendc.simulator.flow2.FlowGraph;
-import org.opendc.simulator.flow2.Inlet;
-import org.opendc.simulator.flow2.Outlet;
-import org.opendc.simulator.flow2.mux.FlowMultiplexer;
-import org.opendc.simulator.flow2.mux.MaxMinFlowMultiplexer;
-import org.opendc.simulator.flow2.util.FlowTransform;
-import org.opendc.simulator.flow2.util.FlowTransformer;
-
-/**
- * A model of an Uninterruptible Power Supply (UPS).
- * <p>
- * This model aggregates multiple power sources into a single source in order to ensure that power is always available.
- */
-public final class SimUps extends SimPowerOutlet {
- /**
- * The {@link FlowMultiplexer} that distributes the electricity over the PDU outlets.
- */
- private final MaxMinFlowMultiplexer mux;
-
- /**
- * A {@link FlowTransformer} that applies the power loss to the PDU's power inlet.
- */
- private final FlowTransformer transformer;
-
- /**
- * Construct a {@link SimUps} instance.
- *
- * @param graph The underlying {@link FlowGraph} to which the UPS belongs.
- * @param idlePower The idle power consumption of the UPS independent of the load.
- * @param lossCoefficient The coefficient for the power loss of the UPS proportional to the load.
- */
- public SimUps(FlowGraph graph, float idlePower, float lossCoefficient) {
- this.mux = new MaxMinFlowMultiplexer(graph);
- this.transformer = new FlowTransformer(graph, new FlowTransform() {
- @Override
- public float apply(float value) {
- // See https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- return value * (lossCoefficient + 1) + idlePower;
- }
-
- @Override
- public float applyInverse(float value) {
- return (value - idlePower) / (lossCoefficient + 1);
- }
- });
-
- graph.connect(transformer.getOutput(), mux.newInput());
- }
-
- /**
- * Construct a {@link SimUps} instance without any loss.
- *
- * @param graph The underlying {@link FlowGraph} to which the UPS belongs.
- */
- public SimUps(FlowGraph graph) {
- this(graph, 0.f, 0.f);
- }
-
- /**
- * Create a new UPS inlet.
- */
- public PowerInlet newInlet() {
- return new PowerInlet(mux);
- }
-
- @Override
- protected Inlet getFlowInlet() {
- return transformer.getInput();
- }
-
- @Override
- public String toString() {
- return "SimUps";
- }
-
- /**
- * A UPS inlet.
- */
- public static final class PowerInlet extends SimPowerInlet implements AutoCloseable {
- private final FlowMultiplexer mux;
- private final Outlet outlet;
- private boolean isClosed;
-
- private PowerInlet(FlowMultiplexer mux) {
- this.mux = mux;
- this.outlet = mux.newOutput();
- }
-
- /**
- * Remove the inlet from the PDU.
- */
- @Override
- public void close() {
- isClosed = true;
- mux.releaseOutput(outlet);
- }
-
- @Override
- public String toString() {
- return "SimPdu.Inlet";
- }
-
- @NotNull
- @Override
- protected Outlet getFlowOutlet() {
- if (isClosed) {
- throw new IllegalStateException("Inlet is closed");
- }
- return outlet;
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
deleted file mode 100644
index 9df72c49..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimPdu] class.
- */
-internal class SimPduTest {
- @Test
- fun testZeroOutlets() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- yield()
-
- assertEquals(0.0f, source.powerDraw)
- }
-
- @Test
- fun testSingleOutlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(100.0f, source.powerDraw)
- }
-
- @Test
- fun testDoubleOutlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 200.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- pdu.newOutlet().connect(TestInlet(graph))
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(200.0f, source.powerDraw)
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 300.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- val outlet = pdu.newOutlet()
- outlet.connect(TestInlet(graph))
- outlet.disconnect()
-
- yield()
-
- assertEquals(0.0f, source.powerDraw)
- }
-
- @Test
- fun testLoss() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val pdu = SimPdu(graph, 1.5f, 0.015f)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(251.5f, source.powerDraw, 0.01f)
- }
-
- @Test
- fun testOutletClose() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- val outlet = pdu.newOutlet()
- outlet.close()
-
- yield()
-
- assertThrows<IllegalStateException> {
- outlet.connect(TestInlet(graph))
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
deleted file mode 100644
index bbc9ad92..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import io.mockk.every
-import io.mockk.mockk
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertAll
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertFalse
-import org.junit.jupiter.api.Assertions.assertNull
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertDoesNotThrow
-import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimPowerSource]
- */
-internal class SimPowerSourceTest {
- @Test
- fun testInitialState() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- yield()
-
- assertAll(
- { assertFalse(source.isConnected) },
- { assertNull(source.inlet) },
- { assertEquals(100.0f, source.capacity) },
- )
- }
-
- @Test
- fun testDisconnectIdempotent() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- assertDoesNotThrow { source.disconnect() }
- assertFalse(source.isConnected)
- }
-
- @Test
- fun testConnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
-
- yield()
-
- assertAll(
- { assertTrue(source.isConnected) },
- { assertEquals(inlet, source.inlet) },
- { assertTrue(inlet.isConnected) },
- { assertEquals(source, inlet.outlet) },
- { assertEquals(100.0f, source.powerDraw) },
- )
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
- source.disconnect()
-
- yield()
-
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
-
- @Test
- fun testDisconnectAssertion() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns false
- every { inlet.flowOutlet } returns TestInlet(graph).flowOutlet
-
- source.connect(inlet)
- inlet.outlet = null
-
- assertThrows<AssertionError> {
- source.disconnect()
- }
- }
-
- @Test
- fun testOutletAlreadyConnected() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
- assertThrows<IllegalStateException> {
- source.connect(TestInlet(graph))
- }
-
- assertEquals(inlet, source.inlet)
- }
-
- @Test
- fun testInletAlreadyConnected() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns true
-
- assertThrows<IllegalStateException> {
- source.connect(inlet)
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
deleted file mode 100644
index cbd23887..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertAll
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimUps] class.
- */
-internal class SimUpsTest {
- @Test
- fun testSingleInlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertEquals(100.0f, source.powerDraw)
- }
-
- @Test
- fun testDoubleInlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, 200.0f)
- val source2 = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
-
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertAll(
- { assertEquals(50.0f, source1.powerDraw) },
- { assertEquals(50.0f, source2.powerDraw) },
- )
- }
-
- @Test
- fun testLoss() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val ups = SimUps(graph, 4.0f, 0.05f)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertEquals(109.0f, source.powerDraw, 0.01f)
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, 200.0f)
- val source2 = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
-
- val inlet = TestInlet(graph)
-
- ups.connect(inlet)
- ups.disconnect()
-
- yield()
-
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
deleted file mode 100644
index 1c06acf4..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import org.opendc.simulator.flow2.FlowGraph
-import org.opendc.simulator.flow2.FlowStage
-import org.opendc.simulator.flow2.FlowStageLogic
-import org.opendc.simulator.flow2.Outlet
-
-/**
- * A test inlet.
- */
-class TestInlet(graph: FlowGraph) : SimPowerInlet(), FlowStageLogic {
- private val stage = graph.newStage(this)
- val flowOutlet = stage.getOutlet("out")
-
- init {
- flowOutlet.push(100.0f)
- }
-
- override fun onUpdate(
- ctx: FlowStage,
- now: Long,
- ): Long = Long.MAX_VALUE
-
- override fun getFlowOutlet(): Outlet {
- return flowOutlet
- }
-}