From 0f835d57b0e989e25aa0b71fe374a0fb1a94e86f Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 5 Nov 2024 14:17:08 +0100 Subject: Documentation update (#261) * Updated a lot of documentation, added a new get-started tutorial. * Applied Spotless * Applied Spotless Java * Added bitbrains workload to site --- .../simulator/compute/power/CarbonFragment.java | 63 ++++++++++++++++++++++ .../simulator/compute/power/CarbonFragmentNew.java | 59 -------------------- .../simulator/compute/power/CarbonModel.java | 38 ++++++++----- .../simulator/compute/power/SimPowerSource.java | 3 +- 4 files changed, 88 insertions(+), 75 deletions(-) create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragment.java delete mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragmentNew.java (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragment.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragment.java new file mode 100644 index 00000000..2563a61d --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragment.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 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.compute.power; + +/** + * An object holding the carbon intensity during a specific time frame. + * Used by {@link CarbonModel}. + */ +public class CarbonFragment { + private long startTime; + private long endTime; + private double carbonIntensity; + + public CarbonFragment(long startTime, long endTime, double carbonIntensity) { + this.setStartTime(startTime); + this.setEndTime(endTime); + this.setCarbonIntensity(carbonIntensity); + } + + public double getCarbonIntensity() { + return carbonIntensity; + } + + public void setCarbonIntensity(double carbonIntensity) { + this.carbonIntensity = carbonIntensity; + } + + public long getEndTime() { + return endTime; + } + + public void setEndTime(long endTime) { + this.endTime = endTime; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } +} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragmentNew.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragmentNew.java deleted file mode 100644 index 78281a77..00000000 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonFragmentNew.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2024 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.compute.power; - -public class CarbonFragmentNew { - private long endTime; - private long startTime; - private double carbonIntensity; - - public CarbonFragmentNew(long startTime, long endTime, double carbonIntensity) { - this.setStartTime(startTime); - this.setEndTime(endTime); - this.setCarbonIntensity(carbonIntensity); - } - - public double getCarbonIntensity() { - return carbonIntensity; - } - - public void setCarbonIntensity(double carbonIntensity) { - this.carbonIntensity = carbonIntensity; - } - - public long getEndTime() { - return endTime; - } - - public void setEndTime(long endTime) { - this.endTime = endTime; - } - - public long getStartTime() { - return startTime; - } - - public void setStartTime(long startTime) { - this.startTime = startTime; - } -} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java index 87ced77a..98ef2b72 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CarbonModel.java @@ -26,26 +26,32 @@ import java.util.List; import org.opendc.simulator.engine.FlowGraph; import org.opendc.simulator.engine.FlowNode; +/** + * CarbonModel used to provide the Carbon Intensity of a {@link SimPowerSource} + * A CarbonModel is based on a list of {@link CarbonFragment} that define the carbon intensity at specific time frames. + */ public class CarbonModel extends FlowNode { private SimPowerSource powerSource; private long startTime = 0L; // The absolute timestamp on which the workload started - private List fragments; - private CarbonFragmentNew current_fragment; + private List fragments; + private CarbonFragment current_fragment; private int fragment_index; + /** - * Construct a new {@link FlowNode} instance. + * Construct a CarbonModel * - * @param parentGraph The {@link FlowGraph} this stage belongs to. + * @param parentGraph The active FlowGraph which should be used to make the new FlowNode + * @param powerSource The Power Source which should be updated with the carbon intensity + * @param carbonFragments A list of Carbon Fragments defining the carbon intensity at different time frames + * @param startTime The start time of the simulation. This is used to go from relative time (used by the clock) + * to absolute time (used by carbon fragments). */ public CarbonModel( - FlowGraph parentGraph, - SimPowerSource powerSource, - List carbonFragments, - long startTime) { + FlowGraph parentGraph, SimPowerSource powerSource, List carbonFragments, long startTime) { super(parentGraph); this.powerSource = powerSource; @@ -62,27 +68,31 @@ public class CarbonModel extends FlowNode { } /** - * Convert the given time to the absolute time by adding the start of workload - * - * @param time + * Convert the given relative time to the absolute time by adding the start of workload */ private long getAbsoluteTime(long time) { return time + startTime; } + /** + * Convert the given absolute time to the relative time by subtracting the start of workload + */ private long getRelativeTime(long time) { return time - startTime; } - private void findCorrectFragment(long absolute_time) { + /** + * Traverse the fragments to find the fragment that matches the given absoluteTime + */ + private void findCorrectFragment(long absoluteTime) { // Traverse to the previous fragment, until you reach the correct fragment - while (absolute_time < this.current_fragment.getStartTime()) { + while (absoluteTime < this.current_fragment.getStartTime()) { this.current_fragment = fragments.get(--this.fragment_index); } // Traverse to the next fragment, until you reach the correct fragment - while (absolute_time >= this.current_fragment.getEndTime()) { + while (absoluteTime >= this.current_fragment.getEndTime()) { this.current_fragment = fragments.get(++this.fragment_index); } } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java index 03d54ad3..2c953d06 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java @@ -100,8 +100,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { // Constructors //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public SimPowerSource( - FlowGraph graph, double max_capacity, List carbonFragments, long startTime) { + public SimPowerSource(FlowGraph graph, double max_capacity, List carbonFragments, long startTime) { super(graph); this.capacity = max_capacity; -- cgit v1.2.3