Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added embodied carbon to batteries #303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class HostsProvisioningStep internal constructor(
cluster.battery!!.initialCharge,
cluster.battery!!.name,
cluster.name,
cluster.battery!!.embodiedCarbon,
cluster.battery!!.expectedLifetime,
)
graph.addEdge(battery, batteryDistributor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public object DfltBatteryExportColumns {
field = Types.required(FLOAT).named("energy_usage"),
) { it.energyUsage }

public val EMBODIED_CARBON: ExportColumn<BatteryTableReader> =
ExportColumn(
field = Types.required(FLOAT).named("embodied_carbon_emission"),
) { it.embodiedCarbonEmission }

public val CHARGE: ExportColumn<BatteryTableReader> =
ExportColumn(
field = Types.required(FLOAT).named("charge"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public interface BatteryTableReader : Exportable {
*/
public val timestampAbsolute: Instant

/**
* The number of connected hosts
*/
public val hostsConnected: Int

/**
* The current power draw of the host in W.
*/
Expand All @@ -65,9 +60,23 @@ public interface BatteryTableReader : Exportable {
*/
public val energyUsage: Double

/**
* The embodied carbon cost of the Battery in kg
*/
public val embodiedCarbonEmission: Double

/**
* The current state of the battery
*/
public val batteryState: BatteryState

/**
* The current charge of the battery in J
*/
public val charge: Double

/**
* The capacity of the battery in J
*/
public val capacity: Double
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class BatteryTableReaderImpl(
_timestamp = table.timestamp
_timestampAbsolute = table.timestampAbsolute

_hostsConnected = table.hostsConnected
_powerDraw = table.powerDraw
_energyUsage = table.energyUsage
_embodiedCarbonEmission = table.embodiedCarbonEmission
_charge = table.charge
_capacity = table.capacity
_batteryState = table.batteryState
Expand All @@ -72,10 +72,6 @@ public class BatteryTableReaderImpl(
override val timestampAbsolute: Instant
get() = _timestampAbsolute

override val hostsConnected: Int
get() = _hostsConnected
private var _hostsConnected: Int = 0

override val powerDraw: Double
get() = _powerDraw
private var _powerDraw = 0.0
Expand All @@ -85,6 +81,11 @@ public class BatteryTableReaderImpl(
private var _energyUsage = 0.0
private var previousEnergyUsage = 0.0

override val embodiedCarbonEmission: Double
get() = _embodiedCarbonEmission - previousEmbodiedCarbonEmission
private var _embodiedCarbonEmission = 0.0
private var previousEmbodiedCarbonEmission = 0.0

override val charge: Double
get() = _charge
private var _charge = 0.0
Expand All @@ -104,11 +105,10 @@ public class BatteryTableReaderImpl(
_timestamp = now
_timestampAbsolute = now + startTime

_hostsConnected = 0

battery.updateCounters()
_powerDraw = battery.outgoingSupply
_energyUsage = battery.totalEnergyUsage
_embodiedCarbonEmission = battery.embodiedCarbonEmission

_charge = battery.charge
_capacity = battery.capacity
Expand All @@ -120,10 +120,11 @@ public class BatteryTableReaderImpl(
*/
override fun reset() {
previousEnergyUsage = _energyUsage
previousEmbodiedCarbonEmission = _embodiedCarbonEmission

_hostsConnected = 0
_powerDraw = 0.0
_energyUsage = 0.0
_embodiedCarbonEmission = 0.0
_charge = 0.0
_capacity = 0.0
_batteryState = BatteryState.IDLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ private fun ClusterJSONSpec.toClusterSpec(): ClusterSpec {
this.battery.chargingSpeed,
this.battery.batteryPolicy,
this.battery.initialCharge,
this.battery.embodiedCarbon,
this.battery.expectedLifetime,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public data class BatterySpec(
val chargingSpeed: Double,
val batteryPolicy: BatteryPolicyJSONSpec,
val initialCharge: Double,
val embodiedCarbon: Double,
val expectedLifetime: Double,
)
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public data class PowerSourceJSONSpec(
* @property chargingSpeed The charging speed of the battery in J
* @property batteryPolicy The policy used to decide when the battery charges and discharges
* @property initialCharge The initial charge in the battery
* @property embodiedCarbon The embodied carbon needed to create the battery in gram
* @property expectedLifetime The expected lifetime of the battery in years
*
*/
@Serializable
public data class BatteryJSONSpec(
Expand All @@ -174,12 +177,9 @@ public data class BatteryJSONSpec(
val chargingSpeed: Double,
val batteryPolicy: BatteryPolicyJSONSpec,
var initialCharge: Double = 0.0,
) {
init {
this.capacity *= 3600000
this.initialCharge *= 3600000
}
}
var embodiedCarbon: Double = 0.0,
var expectedLifetime: Double = 0.0,
)

@Serializable
public data class BatteryPolicyJSONSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,25 +118,38 @@ public boolean isEmpty() {
}

/**
* 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,
double capacity,
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() {
Expand Down Expand Up @@ -188,6 +207,8 @@ public void updateCounters(long now) {

long passedTime = now - lastUpdate;

this.embodiedCarbonEmission += this.embodiedCarbonRate * passedTime;

this.updateCharge(passedTime);
if (passedTime > 0) {
double energyUsage = (this.outgoingSupply * passedTime * 0.001);
Expand Down
Loading