From 20d8587552840c0379e35f70dad05c46de439122 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Mon, 10 Feb 2025 15:25:26 +0100 Subject: added embodied carbon (#303) --- .../compute/power/batteries/SimBattery.java | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'opendc-simulator/opendc-simulator-compute/src') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/batteries/SimBattery.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/batteries/SimBattery.java index d229d4b5..f09cbcee 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/batteries/SimBattery.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/batteries/SimBattery.java @@ -49,6 +49,12 @@ public class SimBattery extends FlowNode implements FlowConsumer, FlowSupplier { private final String name; private final String clusterName; + private final Double embodiedCarbonRate; // The rate of carbon emissions per millisecond + private Double embodiedCarbonEmission = 0.0; + + public Double getEmbodiedCarbonEmission() { + return embodiedCarbonEmission; + } public String getName() { return name; @@ -112,9 +118,16 @@ public class SimBattery extends FlowNode implements FlowConsumer, FlowSupplier { } /** - * Construct a new {@link FlowNode} instance. + * Construct a new {@link SimBattery} instance. * - * @param parentGraph The {@link FlowGraph} this stage belongs to. + * @param parentGraph The {@link FlowGraph} instance this battery is part of. + * @param capacity The capacity of the battery in kWh. + * @param chargingSpeed The charging speed of the battery in J. + * @param initialCharge The initial charge of the battery in kWh. + * @param name The name of the battery. + * @param clusterName The name of the cluster the battery is part of. + * @param totalEmbodiedCarbon The total embodied carbon used to manufacture the battery in kg. + * @param expectedLifeTime The expected lifetime of the battery in years. */ public SimBattery( FlowGraph parentGraph, @@ -122,15 +135,21 @@ public class SimBattery extends FlowNode implements FlowConsumer, FlowSupplier { double chargingSpeed, double initialCharge, String name, - String clusterName) { + String clusterName, + Double totalEmbodiedCarbon, + Double expectedLifeTime) { super(parentGraph); - this.capacity = capacity; + this.capacity = capacity * 3600000; this.chargingSpeed = chargingSpeed; - this.charge = initialCharge; + this.charge = initialCharge * 3600000; this.name = name; this.clusterName = clusterName; + + // TODO: maybe change this to days instead of years? + this.embodiedCarbonRate = + (totalEmbodiedCarbon * 1000) / (expectedLifeTime * 365.0 * 24.0 * 60.0 * 60.0 * 1000.0); } public void close() { @@ -188,6 +207,8 @@ public class SimBattery extends FlowNode implements FlowConsumer, FlowSupplier { long passedTime = now - lastUpdate; + this.embodiedCarbonEmission += this.embodiedCarbonRate * passedTime; + this.updateCharge(passedTime); if (passedTime > 0) { double energyUsage = (this.outgoingSupply * passedTime * 0.001); -- cgit v1.2.3