Skip to content
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
39 changes: 11 additions & 28 deletions _alp/Agents/GridConnection/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,10 @@

double f_operateFixedAssets(J_TimeVariables timeVariables)
{/*ALCODESTART::1668528300576*/
// Maybe we want one collection for all J_EAFixed?

for (J_EAFixed j_ea : c_petroleumFuelVehicles) {
J_FlowPacket flowPacket = j_ea.f_updateAllFlows(timeVariables);
f_addFlows(flowPacket, j_ea);
}
for (J_EAFixed j_ea : c_hydrogenVehicles) {
J_FlowPacket flowPacket = j_ea.f_updateAllFlows(timeVariables);
f_addFlows(flowPacket, j_ea);
}
for (J_EAFixed j_ea : c_consumptionAssets) {
J_FlowPacket flowPacket = j_ea.f_updateAllFlows(timeVariables);
f_addFlows(flowPacket, j_ea);
}
for (J_EAFixed j_ea : c_productionAssets) {
J_FlowPacket flowPacket = j_ea.f_updateAllFlows(timeVariables);
f_addFlows(flowPacket, j_ea);
}
for (J_EAFixed j_ea : c_profileAssets) {
for (J_EAFixed j_ea : c_fixedAssets) {
J_FlowPacket flowPacket = j_ea.f_updateAllFlows(timeVariables);
f_addFlows(flowPacket, j_ea);
}



/*ALCODEEND*/}

double f_resetStates(J_TimeVariables timeVariables)
Expand Down Expand Up @@ -1126,6 +1105,10 @@ J_ActivityTrackerTrips f_getNewTripTracker(OL_EnergyAssetType assetType,I_Vehicl
{/*ALCODESTART::1772106633559*/
c_fixedAssets.add(j_ea);

if (j_ea instanceof J_EAProfile profileAsset) {
c_profileAssets.add(profileAsset);
}

if (j_ea instanceof J_EAFuelVehicle fuelVehicle) {
c_vehicleAssets.add(fuelVehicle);

Expand Down Expand Up @@ -1175,9 +1158,9 @@ else if (productionAsset.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){
}
else if (j_ea instanceof J_EAPetroleumFuelTractor tractor) {
c_profileAssets.add(tractor);
}
else if (j_ea instanceof J_EAProfile profileAsset) {
c_profileAssets.add(profileAsset);
}
else if (j_ea instanceof J_EAProfile) {
return;
}
else{
throw new RuntimeException("Trying to connect GC with unrecognized J_EAFixed asset!");
Expand All @@ -1201,6 +1184,9 @@ else if (j_ea instanceof J_EAProfile profileAsset) {
{/*ALCODESTART::1772110066396*/
c_fixedAssets.remove(j_ea);

if (j_ea instanceof J_EAProfile profileAsset) {
c_profileAssets.remove(profileAsset);
}

if (j_ea instanceof J_EAFuelVehicle fuelVehicle) {
c_vehicleAssets.remove(fuelVehicle);
Expand Down Expand Up @@ -1257,9 +1243,6 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){

}
}
else if (j_ea instanceof J_EAProfile) {
c_profileAssets.remove((J_EAProfile)j_ea);
}
/*ALCODEEND*/}

double f_removeTheJ_EAFlex(J_EAFlex j_ea)
Expand Down
160 changes: 65 additions & 95 deletions _alp/Classes/Class.J_BatteryManagementPeakShavingForecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class J_BatteryManagementPeakShavingForecast implements I_BatteryManageme
private Agent target = parentGC;
private OL_ResultScope targetType = OL_ResultScope.GRIDCONNECTION;
List<GridConnection> c_targetGridConnections = new ArrayList<GridConnection>();
Map<String, I_HeatingAsset> heatingAssets = new HashMap<>(); // Maps GridConnectionID to heatingAsset
private J_TimeParameters timeParameters;

//Stored
Expand All @@ -39,9 +40,28 @@ public J_BatteryManagementPeakShavingForecast( GridConnection parentGC, J_TimePa
} else {
this.setTarget(parentGC);
}
this.initializeAssets();
}


public void initializeAssets() {
// This management is not able to forecast other flex assets. The only exception is a heating asset that follows a profile.
heatingAssets.clear();
for (GridConnection gc : c_targetGridConnections) {
J_EAFlex heatingAsset = null;
for (J_EAFlex flexAsset : gc.c_flexAssets) {
if (flexAsset == parentGC.p_batteryAsset) {
continue;
}
else if (flexAsset instanceof I_HeatingAsset && heatingAsset == null ) {
heatingAsset = flexAsset;
heatingAssets.put(gc.p_gridConnectionID, (I_HeatingAsset)heatingAsset);
}
else {
throw new RuntimeException("J_BatteryManagementPeakShavingForecast does not support other flex assets, multiple flex assets found in GC: " + gc.p_gridConnectionID);
}
}
}
}

public void manageBattery(J_TimeVariables timeVariables) {
if(parentGC.p_batteryAsset != null && parentGC.p_batteryAsset.getStorageCapacity_kWh() > 0) {
Expand All @@ -57,110 +77,59 @@ public void manageBattery(J_TimeVariables timeVariables) {
}
}



/*
* This method creates a 24 hour electricity load forecast based on all fixed profiles, including possible heating demand
*/
private double[] getNettoBalanceForecast_kW(J_TimeVariables timeVariables) {

double[] nettoBalanceTotal_kW = new double[96];
double energyModel_time_h = timeVariables.getT_h();

//For simulation that cross the year end
double hour_of_simulation_year = timeVariables.getAnyLogicTime_h();

int startTimeDayIndex = roundToInt(hour_of_simulation_year/timeParameters.getTimeStep_h());
int endTimeDayIndex = roundToInt((hour_of_simulation_year + 24)/timeParameters.getTimeStep_h());
double[] nettoBalanceTotal_kW = new double[roundToInt(24/timeParameters.getTimeStep_h())];
double timeAtStartForecast_h = timeVariables.getT_h();
int indexAtStartForecast = roundToInt(timeAtStartForecast_h/timeParameters.getTimeStep_h());

List<J_EAProfile> elecConsumptionProfiles = new ArrayList<J_EAProfile>(); //survey inkoop profile data
List<J_EAProfile> elecHeatPumpProfiles = new ArrayList<J_EAProfile>(); //survey WP profile data
List<J_EAProfile> elecEVProfiles = new ArrayList<J_EAProfile>(); //Custom EV profile data
List<J_EAProfile> surveyHeatDemandProfiles = new ArrayList<J_EAProfile>(); //survey gas to heat builing profiles
List<J_EAConsumption> genericHeatDemandProfiles = new ArrayList<J_EAConsumption>(); //Generic gas to heat builing profiles
List<J_EAConsumption> genericBuildingProfiles = new ArrayList<J_EAConsumption>(); //Generic inkoop builing profiles
List<J_EAProduction> productionAssetProfiles = new ArrayList<J_EAProduction>(); // Production profiles

for (GridConnection GC : c_targetGridConnections){
elecConsumptionProfiles.addAll(findAll(GC.c_profileAssets, profile -> profile.assetFlowCategory == OL_AssetFlowCategories.fixedConsumptionElectric_kW));
elecHeatPumpProfiles.addAll(findAll(GC.c_profileAssets, profile -> profile.assetFlowCategory == OL_AssetFlowCategories.heatPumpElectricityConsumption_kW));
elecEVProfiles.addAll(findAll(GC.c_profileAssets, profile -> profile.assetFlowCategory == OL_AssetFlowCategories.evChargingPower_kW));
if(GC.f_getCurrentHeatingType() == OL_GridConnectionHeatingType.ELECTRIC_HEATPUMP && !GC.f_getHeatingTypeIsGhost()) {
surveyHeatDemandProfiles.addAll(findAll(GC.c_profileAssets, profile -> profile.energyCarrier == OL_EnergyCarriers.HEAT));
genericHeatDemandProfiles.addAll(findAll(GC.c_consumptionAssets, cons -> cons.energyAssetType == OL_EnergyAssetType.HEAT_DEMAND));
}
genericBuildingProfiles.addAll(findAll(GC.c_consumptionAssets, cons -> cons.energyAssetType == OL_EnergyAssetType.ELECTRICITY_DEMAND));
productionAssetProfiles.addAll(findAll(GC.c_productionAssets, prod -> prod.energyAssetType == OL_EnergyAssetType.PHOTOVOLTAIC || prod.energyAssetType == OL_EnergyAssetType.WINDMILL));
List<J_EAProfile> electricityProfiles = new ArrayList<>();
Map<String, List<J_EAProfile>> heatProfiles = new HashMap<>(); // Key = GC ID. Because the heating asset is relevant this is stored seperately for each GC

for (GridConnection gc : c_targetGridConnections){
electricityProfiles.addAll(findAll(gc.c_profileAssets, j_ea -> j_ea.energyCarrier == OL_EnergyCarriers.ELECTRICITY));
List<J_EAProfile> heatDemandProfiles = new ArrayList<>();
heatDemandProfiles.addAll(findAll(gc.c_profileAssets, j_ea -> j_ea.energyCarrier == OL_EnergyCarriers.HEAT));
heatProfiles.put(gc.p_gridConnectionID, heatDemandProfiles);
}

for(J_EAProfile elecConsumptionProfile : elecConsumptionProfiles) {
if(elecConsumptionProfile != null){
//double[] tempNettoBalance_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(elecConsumptionProfile.a_energyProfile_kWh, startTimeDayIndex, endTimeDayIndex), elecConsumptionProfile.getProfileScaling_fr()/p_timestep_h);
double[] tempNettoBalance_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(elecConsumptionProfile.profilePointer.getAllValues(), startTimeDayIndex, endTimeDayIndex), elecConsumptionProfile.getProfileScaling_fr()*elecConsumptionProfile.getProfileUnitScaler_fr());
for (int i = 0; i < tempNettoBalance_kW.length; i++) {
nettoBalanceTotal_kW[i] += tempNettoBalance_kW[i];
}
}
}
for(J_EAProfile elecHeatPumpProfile : elecHeatPumpProfiles) {
if(elecHeatPumpProfile != null){
//double[] tempNettoBalance_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(elecHeatPumpProfile.a_energyProfile_kWh, startTimeDayIndex, endTimeDayIndex), elecHeatPumpProfile.getProfileScaling_fr()/p_timestep_h);
double[] tempNettoBalance_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(elecHeatPumpProfile.profilePointer.getAllValues(), startTimeDayIndex, endTimeDayIndex), elecHeatPumpProfile.getProfileScaling_fr()*elecHeatPumpProfile.getProfileUnitScaler_fr());
for (int i = 0; i < tempNettoBalance_kW.length; i++) {
nettoBalanceTotal_kW[i] += tempNettoBalance_kW[i];
}
for (J_EAProfile profile : electricityProfiles) {
double scalar = profile.getProfileScaling_fr()*profile.getProfileUnitScaler_fr();
if (profile instanceof J_EAProduction) {
scalar *= -1;
}
}
for(J_EAProfile elecEVProfile : elecEVProfiles) {
if(elecEVProfile != null){
double[] tempNettoBalance_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(elecEVProfile.profilePointer.getAllValues(), startTimeDayIndex, endTimeDayIndex), elecEVProfile.getProfileScaling_fr()*elecEVProfile.getProfileUnitScaler_fr());
for (int i = 0; i < tempNettoBalance_kW.length; i++) {
nettoBalanceTotal_kW[i] += tempNettoBalance_kW[i];
}
}
}
for(J_EAProfile surveyHeatDemandProfile : surveyHeatDemandProfiles) {
if(surveyHeatDemandProfile != null){
//double[] heatPower_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(surveyHeatDemandProfile.a_energyProfile_kWh, startTimeDayIndex, endTimeDayIndex), surveyHeatDemandProfile.getProfileScaling_fr()/p_timestep_h);
double[] heatPower_kW = ZeroMath.arrayMultiply(Arrays.copyOfRange(surveyHeatDemandProfile.profilePointer.getAllValues(), startTimeDayIndex, endTimeDayIndex), surveyHeatDemandProfile.getProfileScaling_fr()*surveyHeatDemandProfile.getProfileUnitScaler_fr());
//traceln(heatPower_kW);
double eta_r = parentGC.energyModel.avgc_data.p_avgEfficiencyHeatpump_fr;
double outputTemperature_degC = parentGC.energyModel.avgc_data.p_avgOutputTemperatureElectricHeatpump_degC;
for(double time = energyModel_time_h; time < energyModel_time_h + 24; time += timeParameters.getTimeStep_h()){
double baseTemperature_degC = parentGC.energyModel.pp_ambientTemperature_degC.getValue(time);
double COP_r = eta_r * ( 273.15 + outputTemperature_degC ) / ( outputTemperature_degC - baseTemperature_degC );
nettoBalanceTotal_kW[roundToInt((time-energyModel_time_h)/timeParameters.getTimeStep_h())] += heatPower_kW[roundToInt((time-energyModel_time_h)/timeParameters.getTimeStep_h())] / COP_r;
}
}
}
for(J_EAConsumption genericHeatDemandProfile : genericHeatDemandProfiles) {
if(genericHeatDemandProfile != null){

double eta_r = parentGC.energyModel.avgc_data.p_avgEfficiencyHeatpump_fr;
double outputTemperature_degC = parentGC.energyModel.avgc_data.p_avgOutputTemperatureElectricHeatpump_degC;

for(double time = energyModel_time_h; time < energyModel_time_h + 24; time += timeParameters.getTimeStep_h()){
double baseTemperature_degC = parentGC.energyModel.pp_ambientTemperature_degC.getValue(time);
double COP_r = eta_r * ( 273.15 + outputTemperature_degC ) / ( outputTemperature_degC - baseTemperature_degC );

//traceln(genericHeatDemandProfile.getProfilePointer().getValue(time)*genericHeatDemandProfile.yearlyDemand_kWh);
nettoBalanceTotal_kW[roundToInt((time-energyModel_time_h)/timeParameters.getTimeStep_h())] += genericHeatDemandProfile.getProfilePointer().getValue(time)*genericHeatDemandProfile.getBaseConsumption_kWh()*genericHeatDemandProfile.getConsumptionScaling_fr() / COP_r;
}
for (int i = 0; i < nettoBalanceTotal_kW.length; i++) {
nettoBalanceTotal_kW[i] += scalar * profile.profilePointer.getValue((i + indexAtStartForecast)*timeParameters.getTimeStep_h());
}
}
for(J_EAConsumption genericBuildingProfile : genericBuildingProfiles) {
if(genericBuildingProfile != null){ //table function
for(double time = energyModel_time_h; time < energyModel_time_h + 24; time += timeParameters.getTimeStep_h()){
nettoBalanceTotal_kW[roundToInt((time-energyModel_time_h)/timeParameters.getTimeStep_h())] += genericBuildingProfile.getProfilePointer().getValue(time)*genericBuildingProfile.getBaseConsumption_kWh()*genericBuildingProfile.getConsumptionScaling_fr();
}
}
}
for(J_EAProduction productionAssetProfile : productionAssetProfiles) {
if (productionAssetProfile != null) { //table function
for(double time = energyModel_time_h; time < energyModel_time_h + 24; time += timeParameters.getTimeStep_h()){
nettoBalanceTotal_kW[roundToInt((time-energyModel_time_h)/timeParameters.getTimeStep_h())] -= productionAssetProfile.getProfilePointer().getValue(time)*productionAssetProfile.getCapacityElectric_kW();

J_ProfilePointer ambientTemperatures = this.parentGC.energyModel.pp_ambientTemperature_degC;

for (GridConnection gc : c_targetGridConnections) {
I_HeatingAsset heatingAsset = this.heatingAssets.get(gc.p_gridConnectionID);
if (heatingAsset != null && ((J_EA)heatingAsset).activeConsumptionEnergyCarriers.contains(OL_EnergyCarriers.ELECTRICITY)) {
for (J_EAProfile profile : heatProfiles.get(gc.p_gridConnectionID)) {
for (int i = 0; i < nettoBalanceTotal_kW.length; i++) {
double t = timeAtStartForecast_h + i * timeParameters.getTimeStep_h();
double efficiency = 1.0;
if (heatingAsset instanceof J_EAConversionElectricHeater electricHeater) {
efficiency = electricHeater.getEta_r();
}
else if (heatingAsset instanceof J_EAConversionHeatPump heatPump) {
// TODO: Fix this for other ambientTempTypes
efficiency = heatPump.calculateCOP(heatPump.getOutputTemperature_degC(), ambientTemperatures.getValue(t));
}
else {
throw new RuntimeException("Unknown heating asset type in J_BatteryManagementPeakShavingForecast, GC with ID: " + gc.p_gridConnectionID + " has a heating asset of type: " + heatingAsset.getClass());
}
nettoBalanceTotal_kW[i] += profile.profilePointer.getValue((i + indexAtStartForecast)*timeParameters.getTimeStep_h()) / efficiency;
}
}
}
}


}
return nettoBalanceTotal_kW;
}

Expand Down Expand Up @@ -227,6 +196,7 @@ else if (agent instanceof EnergyCoop) {
else {
throw new RuntimeException("Not able to set " + agent + " as a target for J_BatteryPeakShaving");
}
this.initializeAssets();
}


Expand Down
6 changes: 5 additions & 1 deletion _alp/Classes/Class.J_EAConversionHeatPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,16 @@ public OL_AmbientTempType getAmbientTempType() {
return this.ambientTempType;
}

private double calculateCOP(double outputTemperature_degC, double baseTemperature_degC) {
public double calculateCOP(double outputTemperature_degC, double baseTemperature_degC) {
double deltaT = max(1,this.outputTemperature_degC - this.baseTemperature_degC); // Limit deltaT to at least 1 degree.
double COP_r = 8.74 - 0.190 * deltaT + 0.00126 * deltaT*deltaT;
return COP_r;
}


public double getOutputTemperature_degC() {
return this.outputTemperature_degC;
}
/*
@Override
public String toString() {
Expand Down
5 changes: 2 additions & 3 deletions _alp/Classes/Class.J_HeatingManagementBuildingSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public void initializeAssets() {
if (building == null) {
throw new RuntimeException(this.getClass() + " requires a building asset.");
}
J_EAConsumption heatConsumption = findFirst(gc.c_consumptionAssets, x -> x.getEAType() == OL_EnergyAssetType.HEAT_DEMAND && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT);
if (heatProfile != null || heatConsumption != null) {
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
if (heatProfile != null) {
throw new RuntimeException(this.getClass() + " does not support HEAT_DEMAND profiles.");
}
if (gc.c_heatingAssets.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ public void initializeAssets() {
if (building == null) {
throw new RuntimeException(this.getClass() + " requires a building asset.");
}
J_EAConsumption heatConsumption = findFirst(gc.c_consumptionAssets, x -> x.getEAType() == OL_EnergyAssetType.HEAT_DEMAND);
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT);
if (heatProfile != null || heatConsumption != null) {
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
if (heatProfile != null) {
throw new RuntimeException(this.getClass() + " does not support HEAT_DEMAND profiles.");
}
if (gc.c_heatingAssets.size() == 0) {
Expand Down
5 changes: 2 additions & 3 deletions _alp/Classes/Class.J_HeatingManagementCHP.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public void initializeAssets() {
if(gc.p_BuildingThermalAsset != null) {
throw new RuntimeException(this.getClass() + " does not make sense to use this heating management with heatbuffer.");
}
J_EAConsumption heatConsumption = findFirst(gc.c_consumptionAssets, x -> x.getEAType() == OL_EnergyAssetType.HEAT_DEMAND);
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT);
if (heatProfile == null && heatConsumption == null) {
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
if (heatProfile == null) {
throw new RuntimeException(this.getClass() + " requires a heat demand profile/consumption asset.");
}
if (gc.c_heatingAssets.size() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public void initializeAssets() {
if (gc.p_BuildingThermalAsset != null) {
throw new RuntimeException(this.getClass() + " does not support a building asset.");
}
J_EAConsumption heatConsumption = findFirst(gc.c_consumptionAssets, x -> x.getEAType() == OL_EnergyAssetType.HEAT_DEMAND && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.energyCarrier == OL_EnergyCarriers.HEAT);

if (heatProfile == null && heatConsumption == null) {
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
if (heatProfile == null) {
throw new RuntimeException(this.getClass() + " requires a HEAT_DEMAND profile.");
}
if (gc.c_heatingAssets.size() != 2) {
Expand Down
6 changes: 2 additions & 4 deletions _alp/Classes/Class.J_HeatingManagementProfileSimple.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public void initializeAssets() {
if (gc.p_BuildingThermalAsset != null) {
throw new RuntimeException(this.getClass() + " does not support a building asset.");
}
J_EAConsumption heatConsumption = findFirst(gc.c_consumptionAssets, x -> x.getEAType() == OL_EnergyAssetType.HEAT_DEMAND && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT);

if (heatConsumption == null && heatProfile == null) {
J_EAProfile heatProfile = findFirst(gc.c_profileAssets, x -> x.getEnergyCarrier() == OL_EnergyCarriers.HEAT && x.getEAType() != OL_EnergyAssetType.HOT_WATER_CONSUMPTION);
if (heatProfile == null) {
throw new RuntimeException(this.getClass() + " requires a HEAT_DEMAND profile.");
}
if (gc.c_heatingAssets.size() == 0) {
Expand Down
Loading
Loading