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
8 changes: 6 additions & 2 deletions Zero_engine.alpx
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@
</Option>
<Option>
<Id>1725879557284</Id>
<Name><![CDATA[SIMPLE]]></Name>
<Name><![CDATA[SELF_CONSUMPTION]]></Name>
</Option>
<Option>
<Id>1734001947459</Id>
Expand Down Expand Up @@ -1103,7 +1103,11 @@
</Option>
<Option>
<Id>1722411204922</Id>
<Name><![CDATA[PRICE]]></Name>
<Name><![CDATA[MARKETPRICE]]></Name>
</Option>
<Option>
<Id>1742810522883</Id>
<Name><![CDATA[NODALPRICING]]></Name>
</Option>
</OptionList>
<OptionList>
Expand Down
59 changes: 4 additions & 55 deletions _alp/Agents/EnergyModel/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
{/*ALCODESTART::1664952601107*/
b_isDaytime = t_h % 24 > 6 && t_h % 24 < 18;
b_isWeekday = (t_h+(v_dayOfWeek1jan-1)*24) % (24*7) < (24*5);
b_isSummerWeek = t_h >= p_startHourSummerWeek && t_h < p_startHourSummerWeek + 24*7;
b_isWinterWeek = t_h >= p_startHourWinterWeek && t_h < p_startHourWinterWeek + 24*7;
b_isSummerWeek = (t_h % 8760) >= p_startHourSummerWeek && (t_h % 8760) < p_startHourSummerWeek + 24*7;
b_isWinterWeek = (t_h % 8760) >= p_startHourWinterWeek && (t_h % 8760) < p_startHourWinterWeek + 24*7;
b_isLastTimeStepOfDay = t_h % 24 == (24-p_timeStep_h);
t_hourOfDay = t_h % 24; // Assumes modelrun starts at midnight.

Expand Down Expand Up @@ -1255,8 +1255,6 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
traceln("Energy export: "+ v_totalEnergyExport_MWh + " MWh");

// *** Total energy balance ***
//double electricityProduced_MWh = 0;
//double totalDistanceTrucks_km = 0;
double deltaThermalEnergySinceStart_MWh = 0;
double totalAmbientHeating_MWh = 0;
double totalEnergyCurtailed_MWh = 0;
Expand All @@ -1266,18 +1264,8 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
double totalHeatProduced_MWh = 0;
for (J_EA e : c_energyAssets) {
if (((GridConnection) e.getParentAgent()).v_isActive ) {

double EnergyUsed_kWh = e.getEnergyUsed_kWh();
//double electricityProduced_kWh = 0;

//energyConsumed_MWh += max(0,EnergyUsed_kWh)/1000;
//energyProduced_MWh +=max(0,-EnergyUsed_kWh)/1000;
if (EnergyUsed_kWh > 0) {

/*if (e instanceof J_EAConversionCurtailer || e instanceof J_EAConversionCurtailerHeat) {
totalEnergyProduced_MWh -= EnergyUsed_kWh/1000;
totalEnergyCurtailed_MWh += EnergyUsed_kWh/1000;
} else */
if( e instanceof J_EAConversionGasCHP ) {
totalEnergyUsed_MWh += EnergyUsed_kWh/1000;
//electricityProduced_kWh = ((J_EAConversionGasCHP)e).getElectricityProduced_kWh();
Expand All @@ -1291,9 +1279,6 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
deltaThermalEnergySinceStart_MWh += ((J_EABuilding)e).getRemainingHeatBufferHeat_kWh() / 1000;
}
} else {
/*if( e.energyAssetType == OL_EnergyAssetType.PHOTOVOLTAIC || e.energyAssetType == OL_EnergyAssetType.WINDMILL){
electricityProduced_MWh -= EnergyUsed_kWh/1000;
}*/
totalEnergyProduced_MWh -= EnergyUsed_kWh/1000;
if ( e instanceof J_EABuilding ) {
traceln("Building has produced more energy than it has used?? Is lossfactor too low?");
Expand All @@ -1314,16 +1299,10 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
}
double v_totalDeltaStoredEnergy_MWh = v_batteryStoredEnergyDeltaSinceStart_MWh + deltaThermalEnergySinceStart_MWh; // Positive number means more energy stored at the end of the simulation.



//traceln("Trucks have traveled " + totalDistanceTrucks_km + " km");

//Total selfconsumption, selfsufficiency

v_totalEnergySelfConsumed_MWh = v_totalEnergyConsumed_MWh - (v_totalEnergyImport_MWh + max(0,-v_totalDeltaStoredEnergy_MWh)); // Putting positive delta-stored energy here assumes this energy was imported as opposed to self-produced. Putting negative delta-stored energy here assumes this energy was self-consumed, as opposed to exported.
//v_totalSelfConsumedEnergy_MWh = totalEnergyUsed_MWh - (v_totalImportedEnergy_MWh + max(0,-v_totalDeltaStoredEnergy_MWh)); // Putting positive delta-stored energy here assumes this energy was imported as opposed to self-produced. Putting negative delta-stored energy here assumes this energy was self-consumed, as opposed to exported.


// Export and production-based selfconsumption
if ( v_totalEnergyProduced_MWh > 0 ){
v_modelSelfConsumption_fr = v_totalEnergySelfConsumed_MWh / v_totalEnergyProduced_MWh;
Expand Down Expand Up @@ -1351,8 +1330,8 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2
// Remaining difference due to different temps of houses start vs end?
traceln("");
for (OL_EnergyCarriers EC : v_activeEnergyCarriers) {
traceln("Import " + EC.toString() + ": " + v_rapidRunData.am_totalBalanceAccumulators_kW.get(EC).getIntegralPos_kWh()/1000 + " MWh");
traceln("Export " + EC.toString() + ": " + v_rapidRunData.am_totalBalanceAccumulators_kW.get(EC).getIntegralNeg_kWh()/1000 + " MWh");
traceln("Import " + EC.toString() + ": " + v_rapidRunData.getTotalImport_MWh(EC) + " MWh");
traceln("Export " + EC.toString() + ": " + v_rapidRunData.getTotalExport_MWh(EC) + " MWh");
}

traceln("");
Expand All @@ -1377,36 +1356,6 @@ null, roundToDecimal( a.v_electricityImported_kWh-a.v_electricityExported_kWh, 2

}

/*
traceln( "import electricity: " + v_totalElectricityImport_MWh + " MWh");
traceln( "export electricity: " + v_totalElectricityExport_MWh + " MWh");
traceln( "nett import methane: " + (v_totalMethaneImport_MWh-v_totalMethaneExport_MWh) + " MWh");
traceln( "import diesel: " + v_totalDieselImport_MWh + " MWh");
traceln( "nett import hydrogen: " + (v_totalHydrogenImport_MWh-v_totalHydrogenExport_MWh) + " MWh");
*/

/*// intStream.parallel experiment works to extract daytime consumption! Now benchmark performance...
double daytimeEnergyUsed_MWh = IntStream.range(0, a_annualDaytimeIdxs.length).parallel().mapToDouble(idx -> a_annualEnergyConsumption_kW[idx]*a_annualDaytimeIdxs[idx]).sum()*p_timeStep_h/1000;
traceln("v_daytimeEnergyUsed_MWh: %s, daytimeEnergyUsed_MWh: %s", v_daytimeEnergyUsed_MWh, daytimeEnergyUsed_MWh);
*/
/*for (int i = 0; i<365; i++) { // Check if accumulator with signal resolution different from timestep still gives consistent results
if (abs(data_annualElectricityDemand_MWh.getY(i) - acc_annualDailyElectricityDemand_MWh.getTimeSeries()[i]) > 0.0001) {
traceln("Dataset and accumulator don't agree about daily electricity demand on day no. %s, dataset value: %s, accumulator value: %s", i, data_annualElectricityDemand_MWh.getY(i), acc_annualDailyElectricityDemand_MWh.getTimeSeries()[i]);
}
}*/

/*if ( abs(acc_annualElectricityBalanceDownsampled_kW.getIntegral()-acc_annualElectricityBalance_kW.getIntegral()) > 0.1 ) { // Check if reduced resolution accumulator gives same integral result!
traceln("Accumulators with different signal resolution DON'T agree on integral: full-res integral: %s, low-res integral: %s", acc_annualElectricityBalanceDownsampled_kW.getIntegral(), acc_annualElectricityBalance_kW.getIntegral());
} else {
traceln("Accumulators with different signal resolution AGREE on integral: full-res integral: %s, low-res integral: %s", acc_annualElectricityBalanceDownsampled_kW.getIntegral(), acc_annualElectricityBalance_kW.getIntegral());
}*/

//double nettElectricityArray_kWh = Arrays.stream( a_annualElectricityBalance_kW ).sum() * p_timeStep_h / 1000;
//double nettElectricityAccumulator_kWh = acc_annualElectricityBalance_kW.getSum() * p_timeStep_h / 1000;
//double importElectricityAccumulator_kWh = acc_annualElectricityBalance_kW.getSumPos() * p_timeStep_h / 1000;
//traceln("Test ZeroAccumulator: importElectricityAccumulator_kWh: %s kWh, nettElectricityAccumulator_kWh: %s kWh", importElectricityAccumulator_kWh, nettElectricityAccumulator_kWh);


/*ALCODEEND*/}

double f_resetAnnualValues()
Expand Down
4 changes: 2 additions & 2 deletions _alp/Agents/GCUtility/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
case BALANCE:
f_batteryManagementBalance(p_batteryAsset.getCurrentStateOfCharge());
break;
case SIMPLE:
f_batteryManagementSimple();
case SELF_CONSUMPTION:
f_batteryManagementSelfConsumption();
break;
case PRICE:
f_batteryManagementPrice(p_batteryAsset.getCurrentStateOfCharge());
Expand Down
38 changes: 17 additions & 21 deletions _alp/Agents/GridConnection/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,19 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.CHP) {
}
}
break;
case PRICE:
case MARKETPRICE:
if(energyModel.pp_dayAheadElectricityPricing_eurpMWh.getCurrentValue() < 0.0) {
if (fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) < 0.0) { // Feedin, bring to zero!
for (J_EAProduction j_ea : c_productionAssets) {
j_ea.curtailElectricityProduction( - fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY));
if (!(fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) < 0.0)) {
break;
}
}
}
}
break;
case NODALPRICING:
// Prevent feedin when nodal price is negative
double priceTreshold_eur = -0.0;
if(l_parentNodeElectric.getConnectedAgent().v_currentTotalNodalPrice_eurpkWh < priceTreshold_eur) {
Expand Down Expand Up @@ -2514,28 +2526,12 @@ else if (flowsMap.get(EC) > 0){

/*ALCODEEND*/}

double f_batteryManagementSimple()
double f_batteryManagementSelfConsumption()
{/*ALCODESTART::1725629047745*/
//traceln("Battery storage capacity: " + ((J_EAStorageElectric)p_batteryAsset.j_ea).getStorageCapacity_kWh());
if (p_batteryAsset.getStorageCapacity_kWh() != 0){

double safetyMargin_fr = 0.95; // fraction of connection capacity that we use
double power_fr = 0;
double capacityElectric_kW = p_batteryAsset.getCapacityElectric_kW();

if (fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) > v_liveConnectionMetaData.contractedFeedinCapacity_kW * safetyMargin_fr) {
// discharge
double dischargeNeeded_kW = fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) - v_liveConnectionMetaData.contractedFeedinCapacity_kW * safetyMargin_fr;
power_fr = - dischargeNeeded_kW / capacityElectric_kW;
}
else if (fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) < v_liveConnectionMetaData.contractedDeliveryCapacity_kW * safetyMargin_fr) {
// charge
double chargeAvailable_kW = v_liveConnectionMetaData.contractedDeliveryCapacity_kW * safetyMargin_fr - fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY);
power_fr = chargeAvailable_kW / capacityElectric_kW;
}


p_batteryAsset.v_powerFraction_fr = max(-1,min(1, power_fr));
double chargeSetpoint_kW = - fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY);
// limit charging power to battery max power.
p_batteryAsset.v_powerFraction_fr = max(-1,min(1, chargeSetpoint_kW / p_batteryAsset.getCapacityElectric_kW()));
}
/*ALCODEEND*/}

Expand Down
6 changes: 3 additions & 3 deletions _alp/Agents/GridConnection/Code/Functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@
<ReturnModificator>VOID</ReturnModificator>
<ReturnType>double</ReturnType>
<Id>1725629047745</Id>
<Name><![CDATA[f_batteryManagementSimple]]></Name>
<X>1230</X>
<Y>820</Y>
<Name><![CDATA[f_batteryManagementSelfConsumption]]></Name>
<X>920</X>
<Y>260</Y>
<Label>
<X>10</X>
<Y>0</Y>
Expand Down
10 changes: 5 additions & 5 deletions _alp/Agents/GridNode/Code/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@
data_totalLoad_kW.add(energyModel.t_h, v_currentLoad_kW);
}
// SummerWeek
if (energyModel.t_h > energyModel.p_startHourSummerWeek && energyModel.t_h <= energyModel.p_startHourSummerWeek+24*7) {
if (energyModel.b_isSummerWeek) {
v_summerWeekImport_MWh += currentImport_MWh;
v_summerWeekExport_MWh += currentExport_MWh;
v_summerWeekExcessImport_MWh += currentExcessImport_MWh;
v_summerWeekExcessExport_MWh += currentExcessExport_MWh;

data_summerWeekLoad_kW.add(energyModel.t_h, v_currentLoad_kW);
data_summerWeekLoad_kW.add(energyModel.t_h-energyModel.p_runStartTime_h, v_currentLoad_kW);
}
// Winterweek
if (energyModel.t_h > energyModel.p_startHourWinterWeek && energyModel.t_h <= energyModel.p_startHourWinterWeek+24*7) {
if (energyModel.b_isWinterWeek) {
v_winterWeekImport_MWh += currentImport_MWh;
v_winterWeekExport_MWh += currentExport_MWh;
v_winterWeekExcessImport_MWh += currentExcessImport_MWh;
v_winterWeekExcessExport_MWh += currentExcessExport_MWh;

data_winterWeekLoad_kW.add(energyModel.t_h, v_currentLoad_kW);
data_winterWeekLoad_kW.add(energyModel.t_h-energyModel.p_runStartTime_h, v_currentLoad_kW);
}
// Daytime
if (energyModel.t_h % 24 > 6 && energyModel.t_h % 24 < 18) {
Expand Down Expand Up @@ -371,7 +371,7 @@

double f_calculateKPIs()
{/*ALCODESTART::1713181018774*/
//f_duurkrommes();
f_getDuurkromme();

// Calcs nighttime
v_nighttimeImport_MWh = v_totalImport_MWh - v_daytimeExcessImport_MWh;
Expand Down