From 5ab6a534e300e3bcc2e9b8ebaf5661735fc745ec Mon Sep 17 00:00:00 2001 From: Ate Hempenius Date: Thu, 7 Aug 2025 18:33:27 +0200 Subject: [PATCH 1/2] fixing v2g data management and cleanup --- _alp/Agents/GCHouse/Code/Functions.java | 474 +----------------- _alp/Agents/GCHouse/Code/Functions.xml | 165 +----- _alp/Agents/GCHouse/Variables.xml | 69 --- .../Agents/GridConnection/Code/Functions.java | 247 +++------ _alp/Agents/GridConnection/Code/Functions.xml | 39 +- _alp/Agents/GridConnection/Variables.xml | 109 ++-- _alp/Classes/Class.J_EACharger.java | 32 +- _alp/Classes/Class.J_EAEV.java | 55 +- 8 files changed, 221 insertions(+), 969 deletions(-) diff --git a/_alp/Agents/GCHouse/Code/Functions.java b/_alp/Agents/GCHouse/Code/Functions.java index f09ca3d6..91a4bcdd 100644 --- a/_alp/Agents/GCHouse/Code/Functions.java +++ b/_alp/Agents/GCHouse/Code/Functions.java @@ -1,60 +1,3 @@ -double f_manageHeatingAssets_overwrite() -{/*ALCODESTART::1664441996771*/ -v_hotwaterDemand_kW = p_DHWAsset != null ? p_DHWAsset.getLastFlows().get(OL_EnergyCarriers.HEAT) : 0; - -//Check if there is hot water being produced by the pt -double ptProduction_kW = 0; //NEEDS TO BE A LOCAL -/*for (J_EA j_ea : c_ptAssets) { - ptProduction_kW -= j_ea.getLastFlows().get(OL_EnergyCarriers.HEAT); -}*/ -v_hotwaterDemand_kW = max(0, v_hotwaterDemand_kW - ptProduction_kW); // Need to do this, because pt has already compensated the hot water demand in the gc flows, so just need to update this value - -if(p_heatBuffer != null){ - double chargeSetpoint_kW = -fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT); - p_heatBuffer.v_powerFraction_fr = chargeSetpoint_kW / p_heatBuffer.getCapacityHeat_kW(); - p_heatBuffer.f_updateAllFlows(p_heatBuffer.v_powerFraction_fr); - - if(v_hotwaterDemand_kW > 0){//Only if the current pt production, wasnt enough, adjust the hotwater demand with the buffer, cause then the buffer will have discharged - double heatBufferDischarge_kW = -p_heatBuffer.getLastFlows().get(OL_EnergyCarriers.HEAT); - v_hotwaterDemand_kW = max(0, v_hotwaterDemand_kW - heatBufferDischarge_kW); - } -} - -setHeatingTargetTemp(); - -switch (p_heatingType) { - case GASBURNER: - f_heatWithGasburner( ); - break; - case HEATPUMP_AIR: - f_heatWithHeatpump( ); - break; - case HEATPUMP_GASPEAK: - f_heatWithHybridHeatpump(); - break; - case HEATPUMP_BOILERPEAK: - traceln("House " + p_gridConnectionID + " has an unsupported heating asset!"); - break; - case DISTRICTHEAT: - f_heatWithDistrictHeat(); - break; - case LT_DISTRICTHEAT: - f_heatWithLTDistrictHeat(); - break; - default: - traceln("Unsupported heatingtype in household"); - break; -} - -f_manageCookingTracker(); -f_manageAirco(); - -if (p_BuildingThermalAsset != null && p_primaryHeatingAsset != null) { - p_primaryHeatingAsset.f_updateAllFlows(p_primaryHeatingAsset.v_powerFraction_fr); - p_BuildingThermalAsset.f_updateAllFlows(p_BuildingThermalAsset.v_powerFraction_fr); -} -/*ALCODEEND*/} - double f_operateFlexAssets_overwrite() {/*ALCODESTART::1664963959146*/ double availablePowerAtPrice_kW = v_liveConnectionMetaData.contractedDeliveryCapacity_kW; @@ -97,165 +40,6 @@ f_manageBattery(); /*ALCODEEND*/} -double f_connectToChild_overwrite(Agent ConnectingParentNode) -{/*ALCODESTART::1665498948452*/ -//assetLinks.connectTo(ConnectingParentNode); -EnergyAsset EA = (EnergyAsset) ConnectingParentNode; -J_EA j_instance = EA.j_ea; - -//dont add asset to list if it is not a tangible asset (i.e. a heating model for buildings) [GH] How is this not a tangible asset?? -//if(! (j_instance instanceof J_EAStorageHeat && ((J_EAStorageHeat)j_instance).heatStorageType == OL_EAStorageTypes.HEATMODEL_BUILDING)) { - c_energyAssets.add(EA); -//} - -if (j_instance instanceof J_EAConsumption) { - //c_consumptionAssets.add(EA); - if( EA.p_energyAssetType == OL_EnergyAssetType.HOT_WATER_CONSUMPTION ){ - //p_DHWAsset = EA; - } - else if (EA.j_ea instanceof J_EADieselVehicle) { - //c_vehicleAssets.add( EA ); - //c_dieselVehicles.add( EA ); - //c_vehicleAssets.get( v_vehicleIndex ).v_powerFraction_fr = 1; // what's this?? - /*if (c_mobilityTrackers.size() == 0) { - MobilityTracker m = main.add_mobilityTrackers(); - c_mobilityTrackers.add( m ); - m.p_gridConnection = this; - m.p_mobilityPatternType = OL_MobilityPatternType.PRIVATE_VEHICLE; - m.p_vehicleIndex = v_vehicleIndex; - m.p_energyAsset = c_vehicleAssets.get( v_vehicleIndex ); - m.p_vehicleInstance = (J_EADieselVehicle)EA.j_ea; - //m.p_vehicleInstance = (J_EADieselVehicle)m.p_vehicleInstance; - - m.f_getData(); - } else { - c_mobilityTrackers.get(v_vehicleIndex).p_vehicleIndex = v_vehicleIndex; - c_mobilityTrackers.get(v_vehicleIndex).p_energyAsset = c_vehicleAssets.get( v_vehicleIndex ); - c_mobilityTrackers.get(v_vehicleIndex).p_vehicleInstance = (J_EADieselVehicle)EA.j_ea; - } - ((J_EADieselVehicle)EA.j_ea).setMobilityTracker( c_mobilityTrackers.get(v_vehicleIndex) ); - */ - - //v_vehicleIndex ++; - } - } -else if (j_instance instanceof J_EAProduction ) { - //c_productionAssets.add(EA); - if (EA.p_energyAssetType == OL_EnergyAssetType.PHOTOVOLTAIC) { - v_hasPV = true; - traceln("PV system connected to House!"); - } -} -else if (j_instance instanceof J_EAStorage ) { - //traceln("storage asset type connecting to House: " + j_instance); - if (j_instance instanceof J_EABuilding) { - - //p_BuildingThermalAsset = EA; - - if ( p_isolationLabel != null & p_gridConnectionType != null){ // Get building thermals from lookup table when isolation label and house type are available - double lossFactor_WpK2 = main.v_buildingThermalPars.path( p_gridConnectionType.name() ).path(p_isolationLabel.name()).path("lossFactor_WpK").doubleValue(); - double heatCapacity_JpK2 = main.v_buildingThermalPars.path( p_gridConnectionType.name() ).path(p_isolationLabel.name()).path("heatCapacity_JpK").doubleValue(); - ((J_EABuilding)EA.j_ea).lossFactor_WpK = lossFactor_WpK2; - ((J_EABuilding)EA.j_ea).heatCapacity_JpK = heatCapacity_JpK2; - traceln("House thermal model updated!"); - traceln("House type: %s, energy label: %s", p_gridConnectionType, p_isolationLabel); - traceln("lossfactor %s, heatcapacity %s", lossFactor_WpK2, heatCapacity_JpK2); - } - //traceln( "Household heat model has kWh: " + ((J_EAStorageHeat) j_instance).getStorageCapacity()); - } - else if (j_instance instanceof J_EAEV) { - //c_storageAssets.add(EA); - //c_vehicleAssets.add( j_instance ); - //EA.v_powerFraction_fr = 1; - /*if (c_mobilityTrackers.size() == 0) { - MobilityTracker m = main.add_mobilityTrackers(); - c_mobilityTrackers.add( m ); - m.p_vehicleIndex = v_vehicleIndex; - m.p_gridConnection = this; - m.p_energyAsset = EA; - m.p_vehicleInstance = (J_EAEV)EA.j_ea; - - m.p_mobilityPatternType = PRIVATE_VEHICLE; - m.f_getData(); - } else { - traceln("Vehicle index in House " + p_gridConnectionID + " is: " + v_vehicleIndex); - c_mobilityTrackers.get(v_vehicleIndex).p_vehicleIndex = v_vehicleIndex; - c_mobilityTrackers.get(v_vehicleIndex).p_energyAsset = c_vehicleAssets.get( v_vehicleIndex ); - c_mobilityTrackers.get(v_vehicleIndex).p_vehicleInstance = EA.j_ea; - } - ((J_EAEV)EA.j_ea).setMobilityTracker( c_mobilityTrackers.get(v_vehicleIndex) ); - */ - //p_householdEV = EA; - //v_vehicleIndex ++; - } - else if(j_instance instanceof J_EAStorageElectric && ((J_EAStorageElectric)j_instance).getStorageCapacity_kWh() !=0) { - //p_batteryAsset = EA; - //c_storageAssets.add(EA); - v_batterySOC_fr = p_batteryAsset.getCurrentStateOfCharge(); - } - else if ( j_instance instanceof J_EAStorageHeat ) { - if ( ((J_EAStorageHeat)j_instance).heatStorageType == OL_EAStorageTypes.HEATBUFFER ) { - //c_storageAssets.add(EA); - //p_heatBuffer = EA; - //traceln( "Heatbuffer has kWH: " +((J_EAStorageHeat) j_instance).getStorageCapacity()); - } - } - else{ - traceln(getName() + "storage asset create that cannot be identified (i.e. its not an EV and not an heatstorage"); - } -} -else if (j_instance instanceof J_EAConversion) { - c_conversionAssets.add((J_EAConversion)EA.j_ea ); - if (EA.p_energyAssetType == OL_EnergyAssetType.GAS_BURNER || EA.j_ea instanceof J_EAConversionHeatPump || EA.j_ea instanceof J_EAConversionHeatDeliverySet || EA.j_ea instanceof J_EAConversionElectricHeater ) { - switch (p_heatingType) { - case HEATPUMP_AIR: - p_primaryHeatingAsset = (J_EAConversion)EA.j_ea; - break; - case HEATPUMP_GASPEAK: - p_primaryHeatingAsset = p_primaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionHeatPump? (J_EAConversion)EA.j_ea : p_primaryHeatingAsset; - p_secondaryHeatingAsset = p_secondaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionGasBurner? (J_EAConversion)EA.j_ea : p_secondaryHeatingAsset; - break; - case HEATPUMP_BOILERPEAK: // ambigue wat we met boiler bedoelen; eboiler of grootschalige DH_boiler = gasburner! - p_primaryHeatingAsset = p_primaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionHeatPump? (J_EAConversion)EA.j_ea : p_primaryHeatingAsset; - p_secondaryHeatingAsset = p_secondaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionGasBurner? (J_EAConversion)EA.j_ea : p_secondaryHeatingAsset; - p_secondaryHeatingAsset = p_secondaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionElectricHeater? (J_EAConversion)EA.j_ea : p_secondaryHeatingAsset; - break; - case GASBURNER: - p_primaryHeatingAsset = p_primaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionGasBurner? (J_EAConversion)EA.j_ea : p_primaryHeatingAsset; - p_secondaryHeatingAsset = p_secondaryHeatingAsset == null && EA.j_ea instanceof J_EAConversionGasCHP? (J_EAConversion)EA.j_ea : p_secondaryHeatingAsset; - break; - case DISTRICTHEAT: - if( EA.j_ea instanceof J_EAConversionHeatDeliverySet ){ - p_primaryHeatingAsset = (J_EAConversion)EA.j_ea; - } - else { - p_secondaryHeatingAsset = (J_EAConversion)EA.j_ea; - // set water/water heatpump source energy-asset - //if( EA.j_ea instanceof J_EAConversionHeatPump && ((J_EAConversionHeatPump)EA.j_ea).getAmbientTempType().equals("WATER") && p_primaryHeatingAsset.j_ea instanceof J_EAConversionHeatDeliverySet ) { - if( EA.j_ea instanceof J_EAConversionHeatPump ){ - //EA.p_linkedSourceEnergyAsset = p_primaryHeatingAsset; Still need to rebuild link with class-based energy assets!! - //EA.j_ea.updateAmbientTemperature( EA.p_linkedSourceEnergyAsset.j_ea.getCurrentTemperature() ); - } - } - break; - default: throw new IllegalStateException("Invalid DistrictHeating HeatingType: " + p_heatingType); - } - } - else if ( EA.p_energyAssetType == OL_EnergyAssetType.GAS_PIT){ - //f_connectToJ_EA(EA.j_ea); - //p_hasElectricHob = false; - } - else if (EA.p_energyAssetType == OL_EnergyAssetType.ELECTRIC_HOB) { - //f_connectToJ_EA(EA.j_ea); - //p_hasElectricHob = true; - } -} - -else { - traceln("f_connectToChild in EnergyAsset: Exception! EnergyAsset " + ConnectingParentNode.getId() + " is of unknown type or null! "); -} -/*ALCODEEND*/} - double f_createThermalStorageModel() {/*ALCODESTART::1669203453155*/ OL_EAPresetStorageAssets isolationLevel; @@ -440,6 +224,10 @@ else if (lastLoopsPriceLevel.equals("low") && powerAvailableAtLastLoop_kW > p_mi case SIMPLE: f_simpleCharging(); break; + case V1G: + case MAX_SPREAD: + f_maxSpreadCharging(); + break; case CHEAP: f_chargeOnPrice( v_currentElectricityPriceConsumption_eurpkWh, max(0, availableChargingCapacity)); break; @@ -502,173 +290,6 @@ else if (energyModel.t_h*60 < chargeDeadline_min ){ v_vehicleChargingNeed = p_householdEV.chargingNeed; } -/*ALCODEEND*/} - -double f_heatWithHeatpump() -{/*ALCODESTART::1676477303264*/ -double powerFraction_heatBuffer_fr = 0; -//double powerFraction_heatPump_fr = 0; -double avgElectricityPrice_eurpkWh = 10; -J_EAConversionHeatPump hp = (J_EAConversionHeatPump)p_primaryHeatingAsset; -v_copHeatpump = hp.getCOP(); - -/* -if ( p_smartHeatingEnabled ) { - if ( p_owner != null) { - avgElectricityPrice_eurpkWh = p_owner.f_getAveragedElectricityPrice( (fm_currentConsumptionFlows_kW.get(OL_EnergyCarriers.ELECTRICITY) - fm_currentProductionFlows_kW.get(OL_EnergyCarriers.ELECTRICITY)), hp.getInputCapacity_kW() ); - //traceln("avg electircity rprice for HP: " + avgElectricityPrice_eurpkWh); - } -} - -//heat the buffer if it requires heat -if ( p_heatBuffer != null ){ - if ( p_heatBuffer.requiresHeat ){ - powerFraction_heatPump_fr = 1; - powerFraction_heatBuffer_fr = hp.getOutputCapacity_kW() / p_heatBuffer.getCapacityHeat_kW() ; - //traceln(getName() + " heat buffer cus of need"); - } else if( p_smartHeatingEnabled && avgElectricityPrice_eurpkWh < v_electricityPriceLowPassed_eurpkWh - p_pricelevelLowDifFromAvg_eurpkWh - //also heat the buffer if the price is cheap, the buffer has some room and the vehicle does not need charging - && p_heatBuffer.getCurrentStateOfCharge() < 0.7) - { - if( p_householdEV == null ){ - powerFraction_heatPump_fr = 1; - powerFraction_heatBuffer_fr = hp.getOutputCapacity_kW() / p_heatBuffer.getCapacityHeat_kW(); - } else if (p_householdEV.chargingNeed != OL_EVChargingNeed.HIGH){ - powerFraction_heatPump_fr = 1; - //traceln("heat buffer cus cheap"); - powerFraction_heatBuffer_fr = hp.getOutputCapacity_kW() / p_heatBuffer.getCapacityHeat_kW(); - } - } - //reduce the powerfraction in the buffer with the hot water demand. - powerFraction_heatBuffer_fr += -v_hotwaterDemand_kW / p_heatBuffer.getCapacityHeat_kW(); -} -*/ - -//heat the house -//if( powerFraction_heatPump_fr == 0 ){ // Why this check? <- to make sure the heatpump is only used for househeating if it is not ALREADY heating the buffer (Peter) - if (p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC - p_heatingKickinTreshold_degC ) { - hp.v_powerFraction_fr = 1; - p_BuildingThermalAsset.v_powerFraction_fr = (hp.getOutputCapacity_kW() - v_hotwaterDemand_kW) / p_BuildingThermalAsset.getCapacityHeat_kW(); - } - if (v_hotwaterDemand_kW > p_primaryHeatingAsset.getOutputCapacity_kW() ) { - traceln("Warning! Hotwaterdemand exceeds available heating power of house! Will lead to shortage of heat on GC!"); - } - /* - else if( p_smartHeatingEnabled && avgElectricityPrice_eurpkWh < v_electricityPriceLowPassed_eurpkWh - p_pricelevelLowDifFromAvg_eurpkWh - && p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC + 1) { - //also heat the house if the price is cheap, the the house is colder than desired + 1 and the vehicle does not need charging - if( p_householdEV == null ){ - powerFraction_heatPump_fr = 1; - p_BuildingThermalAsset.v_powerFraction_fr = hp.getOutputCapacity_kW() / p_BuildingThermalAsset.getCapacityHeat_kW(); - } - else if (p_householdEV.chargingNeed != OL_EVChargingNeed.HIGH){ // only use heatpump if the vehicle is not about to charge - powerFraction_heatPump_fr = 1; - //traceln("heat house cus of cheap"); - p_BuildingThermalAsset.v_powerFraction_fr = hp.getOutputCapacity_kW() / p_BuildingThermalAsset.getCapacityHeat_kW(); - } - }*/ - else { - hp.v_powerFraction_fr = v_hotwaterDemand_kW/hp.getOutputCapacity_kW(); - p_BuildingThermalAsset.v_powerFraction_fr = 0; - } -//} -/* -else { - p_BuildingThermalAsset.v_powerFraction_fr = 0; // Whut? -} -if ( p_heatBuffer != null ){ - p_heatBuffer.v_powerFraction_fr = powerFraction_heatBuffer_fr; - p_heatBuffer.f_updateAllFlows(powerFraction_heatBuffer_fr); -}*/ -//p_primaryHeatingAsset.v_powerFraction_fr = powerFraction_heatPump_fr; -//traceln( "heatpump power fraction: " + hp.v_powerFraction_fr ); - -/*ALCODEEND*/} - -double f_heatWithHybridHeatpump() -{/*ALCODESTART::1676976246060*/ -if ( p_primaryHeatingAsset instanceof J_EAConversionHeatPump & p_secondaryHeatingAsset instanceof J_EAConversionGasBurner) { // Heatpump and gasburner, switch based on heatpump COP) - J_EAConversionHeatPump HP = (J_EAConversionHeatPump)p_primaryHeatingAsset; - v_copHeatpump = HP.getCOP(); - if (p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC - p_heatingKickinTreshold_degC) { - //HP.updateAmbientTemp(main.v_currentAmbientTemperature_degC); // update heatpump temp levels! <-- waarom dit gebeurt al in de main (peter 21-02-23) - boolean gasCheaper = f_calcCheapestHeatingPrice(); - if ( gasCheaper ) { // heat with gas - traceln("gas is cheaper"); - double powerDemand_kW = v_hotwaterDemand_kW + (v_tempSetpoint_degC - p_BuildingThermalAsset.getCurrentTemperature()) * p_BuildingThermalAsset.getHeatCapacity_JpK() / 3.6e6; - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_secondaryHeatingAsset.v_powerFraction_fr = min(1, powerDemand_kW / p_secondaryHeatingAsset.getOutputCapacity_kW()); - p_BuildingThermalAsset.v_powerFraction_fr = (p_secondaryHeatingAsset.v_powerFraction_fr * p_secondaryHeatingAsset.getOutputCapacity_kW() - v_hotwaterDemand_kW ) / p_BuildingThermalAsset.getCapacityHeat_kW(); - } else { // heat with heatpump - //double powerDemand_kW = (v_tempSetpoint_degC - houseTemp) * ((J_EAStorageHeat)p_BuildingThermalAsset.j_ea).getHeatCapacity_JpK() / 3.6e6; - p_primaryHeatingAsset.v_powerFraction_fr = 1;//min(1,powerDemand_kW / p_primaryHeatingAsset.j_ea.getHeatCapacity_kW()); - p_secondaryHeatingAsset.v_powerFraction_fr = min(1,v_hotwaterDemand_kW / p_secondaryHeatingAsset.getOutputCapacity_kW()); - p_BuildingThermalAsset.v_powerFraction_fr = HP.getOutputCapacity_kW() / p_BuildingThermalAsset.getCapacityHeat_kW(); - traceln("HP is cheaper"); - } - } else { // Just supply DHW demand with gas burner - p_secondaryHeatingAsset.v_powerFraction_fr = v_hotwaterDemand_kW / p_secondaryHeatingAsset.getOutputCapacity_kW(); - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_BuildingThermalAsset.v_powerFraction_fr = 0; - traceln("just DHW"); - } - p_secondaryHeatingAsset.f_updateAllFlows( p_secondaryHeatingAsset.v_powerFraction_fr ); -} else if( p_primaryHeatingAsset instanceof J_EAConversionHeatDeliverySet && ( p_secondaryHeatingAsset instanceof J_EAConversionElectricHeater || p_secondaryHeatingAsset instanceof J_EAConversionHeatPump ) && p_heatBuffer instanceof J_EAStorageHeat ) { // Heat Delivery Set and booster water/water heatpump with buffer for hotwater, ) - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_secondaryHeatingAsset.v_powerFraction_fr = 0; - p_heatBuffer.v_powerFraction_fr = 0; - - traceln("bivalent DH system with buffer operating mode"); - double v_bufferTemp_degC = p_heatBuffer.getCurrentTemperature(); - double houseTemperature_degC = p_BuildingThermalAsset.getCurrentTemperature(); - - // buffer instead of heatpump! TODO: change to refill buffer! double secondaryDemand_kW = v_hotwaterDemand_kW; - traceln(" thermalstoragetemp "+ p_BuildingThermalAsset.getCurrentTemperature() + ", v_setpoint_degC " + v_tempSetpoint_degC); - - // 1) w/w heatpump feeds (only) the local heat buffer for tapwater when temperature is beneath buffer setpoint: - boolean b_bufferTempBelowSetpoint = v_bufferTemp_degC < p_heatBuffer.getSetTemperature_degC(); - - p_secondaryHeatingAsset.v_powerFraction_fr = b_bufferTempBelowSetpoint ? 1 : 0; - p_secondaryHeatingAsset.f_updateAllFlows( p_secondaryHeatingAsset.v_powerFraction_fr ); - - double heatSupplyToBuffer_kW = -p_secondaryHeatingAsset.getLastFlows().get(OL_EnergyCarriers.HEAT); - - // 2) supply tapwater from local heatbuffer on demand, AND take in heat from the heatpump - p_heatBuffer.v_powerFraction_fr = ( - v_hotwaterDemand_kW + heatSupplyToBuffer_kW ) / p_heatBuffer.getCapacityHeat_kW(); - p_heatBuffer.f_updateAllFlows( p_heatBuffer.v_powerFraction_fr ); - - // 3) heat the house from heat delivery set directly, and take care to add this heat load to the existing heat flow from w/w heatpump consumption! - boolean b_houseTempBelowSetpoint = houseTemperature_degC < v_tempSetpoint_degC? true : false; - - p_primaryHeatingAsset.v_powerFraction_fr += b_houseTempBelowSetpoint? 1 : 0; // maybe cap for maximum 1? - //p_primaryHeatingAsset.f_updateAllFlows( p_primaryHeatingAsset.v_powerFraction_fr ); - - double heatFlowToHouse_kW = p_primaryHeatingAsset.getOutputCapacity_kW() * p_primaryHeatingAsset.v_powerFraction_fr - p_secondaryHeatingAsset.getLastFlows().get(OL_EnergyCarriers.HEAT); - p_BuildingThermalAsset.v_powerFraction_fr = (heatFlowToHouse_kW / p_BuildingThermalAsset.getCapacityHeat_kW() ); - //p_primaryHeatingAsset.v_powerFraction_fr = p_BuildingThermalAsset.j_ea.getCurrentTemperature() < v_tempSetpoint_degC ? 1 : 0; - //traceln("b_primaryOperate = "+ b_primaryOperate + ", GCHouse f_heatWithHybridHeatpump: p_secondaryHeatingAsset.j_ea.capacityHeat_kW = " + p_secondaryHeatingAsset.j_ea.capacityHeat_kW + ". p_secondaryHeatingAsset.j_ea = "+p_secondaryHeatingAsset.j_ea.toString()); - - //boolean b_primaryOperate = houseTemperature_degC < v_tempSetpoint_degC ? true : false; - - - //p_secondaryHeatingAsset.v_powerFraction_fr = secondaryDemand_kW / p_secondaryHeatingAsset.j_ea.getHeatCapacity_kW(); - - - //p_BuildingThermalAsset.v_powerFraction_fr = p_primaryHeatingAsset.j_ea.capacityHeat_kW * p_primaryHeatingAsset.v_powerFraction_fr; - - //traceln("GCHouse f_heatwithhybrid... -> p_primaryHeatingAsset.v_powerFraction_fr = " + p_primaryHeatingAsset.v_powerFraction_fr + ", p_secondaryHeatingAsset.v_powerFraction_fr = " + p_secondaryHeatingAsset.v_powerFraction_fr + ", p_BuildingThermalAsset.v_powerFraction_fr" + p_BuildingThermalAsset.v_powerFraction_fr); - //p_secondaryHeatingAsset.f_updateAllFlows(p_secondaryHeatingAsset.v_powerFraction_fr); - //p_primaryHeatingAsset.f_updateAllFlows(p_primaryHeatingAsset.v_powerFraction_fr); - //p_BuildingThermalAsset.f_updateAllFlows(p_BuildingThermalAsset.v_powerFraction_fr); - -} else { - traceln("**** EXCEPTION ****: Unsupported combination of heatings systems in house " + p_gridConnectionID); - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_secondaryHeatingAsset.v_powerFraction_fr = 0; - p_BuildingThermalAsset.v_powerFraction_fr = 0; -} - - /*ALCODEEND*/} double f_chargeOnPriceSimpler(double availablePowerOnGc_kW) @@ -787,30 +408,6 @@ else if ( v_batterySOC_fr < 0.6 && v_currentPowerElectricity_kW < 1 && v_current traceln("Placeholder function f_setEnergyLabel called! Nothing will happen."); /*ALCODEEND*/} -double setHeatingTargetTemp() -{/*ALCODESTART::1702369252216*/ -if ( energyModel.t_hourOfDay > v_heatingOn_time && energyModel.t_hourOfDay < v_heatingOff_time){ - v_tempSetpoint_degC = v_dayTempSetpoint_degC ; -} -else { - v_tempSetpoint_degC = v_nightTempSetpoint_degC; -} -/*ALCODEEND*/} - -boolean f_calcCheapestHeatingPrice() -{/*ALCODESTART::1702369294416*/ -double HP_COP = ((J_EAConversionHeatPump)p_primaryHeatingAsset).getCOP(); -boolean isGasCheaper = false; - -if( p_owner != null ) { - v_gasHeatingCost_eurpkWh_TEMPORARY = p_owner.f_getMethanePrice(); - v_eHeatingCost_eurpkWh_TEMPORARY = p_owner.f_getAveragedElectricityPrice( fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY), p_primaryHeatingAsset.getInputCapacity_kW() ) / HP_COP; - isGasCheaper = v_gasHeatingCost_eurpkWh_TEMPORARY < v_eHeatingCost_eurpkWh_TEMPORARY ? true:false; -} - -return isGasCheaper; -/*ALCODEEND*/} - double f_removeCurrentHeatingSystem() {/*ALCODESTART::1726129903799*/ p_heatingType = OL_GridConnectionHeatingType.NONE; @@ -826,50 +423,6 @@ boolean f_calcCheapestHeatingPrice() } /*ALCODEEND*/} -double f_heatWithGasburner() -{/*ALCODESTART::1726301776809*/ -if ( p_primaryHeatingAsset instanceof J_EAConversionGasBurner && p_BuildingThermalAsset != null) { - if (p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC - p_heatingKickinTreshold_degC) { - double powerDemand_kW = v_hotwaterDemand_kW + (v_tempSetpoint_degC - p_BuildingThermalAsset.getCurrentTemperature()) * p_BuildingThermalAsset.getHeatCapacity_JpK() / 3.6e6; - p_primaryHeatingAsset.v_powerFraction_fr = min(1, powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW() ); - p_BuildingThermalAsset.v_powerFraction_fr = max(0, (p_primaryHeatingAsset.v_powerFraction_fr * p_primaryHeatingAsset.getOutputCapacity_kW() - v_hotwaterDemand_kW) / p_BuildingThermalAsset.getCapacityHeat_kW() ); - if (v_hotwaterDemand_kW > p_primaryHeatingAsset.getOutputCapacity_kW() ) { - traceln("Warning! Hotwaterdemand exceeds available heating power of house! Will lead to shortage of heat on GC!"); - } - } - else { // Just supply DHW - p_primaryHeatingAsset.v_powerFraction_fr = v_hotwaterDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW(); - p_BuildingThermalAsset.v_powerFraction_fr = 0; - } -} -else if (p_primaryHeatingAsset instanceof J_EAConversionGasBurner && p_BuildingThermalAsset == null){ - double powerDemand_kW = fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT); //TODO Where does this v_currentPowerHeat_kW come from? (Peter 14-09-2024), - p_primaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW()); - traceln("Household is heating with gasburner without thermal building asset, check if this is correct @f_heatWithGasBurner"); - //p_primaryHeatingAsset.v_powerFraction_fr = v_hotwaterDemand_kW / p_primaryHeatingAsset.getHeatCapacity_kW(); -} - -/*ALCODEEND*/} - -double f_heatWithDistrictHeat() -{/*ALCODESTART::1726301785545*/ -if ( p_primaryHeatingAsset instanceof J_EAConversionHeatDeliverySet && p_BuildingThermalAsset != null) { - if (p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC - p_heatingKickinTreshold_degC) { - double powerDemand_kW = v_hotwaterDemand_kW + (v_tempSetpoint_degC - p_BuildingThermalAsset.getCurrentTemperature()) * p_BuildingThermalAsset.getHeatCapacity_JpK() / 3.6e6; - p_primaryHeatingAsset.v_powerFraction_fr = min(1, powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW() ); - p_BuildingThermalAsset.v_powerFraction_fr = max(0, ( p_primaryHeatingAsset.v_powerFraction_fr * p_primaryHeatingAsset.getOutputCapacity_kW() - v_hotwaterDemand_kW ) / p_BuildingThermalAsset.getCapacityHeat_kW()); - } - else { - p_primaryHeatingAsset.v_powerFraction_fr = v_hotwaterDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW(); - p_BuildingThermalAsset.v_powerFraction_fr = 0; - } - v_districtHeatDelivery_kW = p_primaryHeatingAsset.v_powerFraction_fr * p_primaryHeatingAsset.getOutputCapacity_kW(); -} -else { - traceln("House " + p_gridConnectionID + " has heatingtype DISTRICT HEAT, but no delivery set or building asset!"); -} -/*ALCODEEND*/} - double f_manageCookingTracker() {/*ALCODESTART::1726334759211*/ // Add heat from cooking assets to house @@ -938,22 +491,3 @@ else if (p_primaryHeatingAsset instanceof J_EAConversionGasBurner && p_BuildingT } /*ALCODEEND*/} -double f_heatWithLTDistrictHeat() -{/*ALCODESTART::1752073360816*/ -if ( p_primaryHeatingAsset instanceof J_EAConversionHeatPump && p_BuildingThermalAsset != null) { - // The only supported combination is currently a heatpump as booster and heatdemand from a building asset (and hot water) - if (p_BuildingThermalAsset.getCurrentTemperature() < v_tempSetpoint_degC - p_heatingKickinTreshold_degC) { - double powerDemand_kW = v_hotwaterDemand_kW + (v_tempSetpoint_degC - p_BuildingThermalAsset.getCurrentTemperature()) * p_BuildingThermalAsset.getHeatCapacity_JpK() / 3.6e6; - p_primaryHeatingAsset.v_powerFraction_fr = min(1, powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW() ); - p_BuildingThermalAsset.v_powerFraction_fr = max(0, ( p_primaryHeatingAsset.v_powerFraction_fr * p_primaryHeatingAsset.getOutputCapacity_kW() - v_hotwaterDemand_kW ) / p_BuildingThermalAsset.getCapacityHeat_kW()); - } - else { - p_primaryHeatingAsset.v_powerFraction_fr = v_hotwaterDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW(); - p_BuildingThermalAsset.v_powerFraction_fr = 0; - } -} -else { - throw new RuntimeException("House " + p_gridConnectionID + " has heatingtype LT DISTRICTHEAT, but no booster or building asset!"); -} -/*ALCODEEND*/} - diff --git a/_alp/Agents/GCHouse/Code/Functions.xml b/_alp/Agents/GCHouse/Code/Functions.xml index 8d9f4951..1b859245 100644 --- a/_alp/Agents/GCHouse/Code/Functions.xml +++ b/_alp/Agents/GCHouse/Code/Functions.xml @@ -1,22 +1,5 @@ - - VOID - double - 1664441996771 - - true - 920 - 420 - - false - true - true - - VOID double @@ -33,35 +16,14 @@ true - - VOID - double - 1665498948452 - - true - 820 - -100 - - false - true - true - - - - - - VOID double 1669203453155 true - 820 - -210 + 940 + -90 - - VOID - double - 1676477303264 - - true - 1700 - 110 - - false - true - true - - - - VOID - double - 1676976246060 - - true - 1700 - 170 - - false - true - true - - VOID double @@ -270,40 +198,6 @@ true - - VOID - double - 1702369252216 - - true - 1700 - 90 - - false - true - true - - - - RETURNS_VALUE - boolean - 1702369294416 - - true - 1720 - 190 - - false - true - true - - VOID double @@ -321,40 +215,6 @@ true - - VOID - double - 1726301776809 - - true - 1700 - 130 - - false - true - true - - - - VOID - double - 1726301785545 - - true - 1700 - 150 - - false - true - true - - VOID double @@ -407,21 +267,4 @@ - - VOID - double - 1752073360816 - - true - 1700 - 210 - - false - true - true - - diff --git a/_alp/Agents/GCHouse/Variables.xml b/_alp/Agents/GCHouse/Variables.xml index 1df4fb8c..6ce592a0 100644 --- a/_alp/Agents/GCHouse/Variables.xml +++ b/_alp/Agents/GCHouse/Variables.xml @@ -202,75 +202,6 @@ - - 1704447555067 - - true - 1460 - 210 - - false - true - true - - - - - - - - - 1704447555069 - - true - 1460 - -40 - - false - true - true - - - - - - - - - 1704447555071 - - true - 1460 - -20 - - false - true - true - - - - - - - 1704447555073 diff --git a/_alp/Agents/GridConnection/Code/Functions.java b/_alp/Agents/GridConnection/Code/Functions.java index 019521e3..3d585b80 100644 --- a/_alp/Agents/GridConnection/Code/Functions.java +++ b/_alp/Agents/GridConnection/Code/Functions.java @@ -207,122 +207,35 @@ /*ALCODEEND*/} -double f_manageHeatingAssets_OLD() -{/*ALCODESTART::1669025846794*/ -// TODO: This only works for fixed heat demands; also need to implement heating of a building modeled as a ThermalStorageAsset! [GH 21/11/2022] -if(p_heatBuffer != null){ - double chargeSetpoint_kW = -fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT); - p_heatBuffer.v_powerFraction_fr = chargeSetpoint_kW / p_heatBuffer.getCapacityHeat_kW(); - p_heatBuffer.f_updateAllFlows(p_heatBuffer.v_powerFraction_fr); -} - -double powerDemand_kW = fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT); - -if(powerDemand_kW < 0 && v_liveAssetsMetaData.activeAssetFlows.contains(OL_AssetFlowCategories.ptProductionHeat_kW)){//If there is 'overproduction' of heat, that can not be collected by the heat buffer: no power demand -> will be curtailed. - powerDemand_kW = 0; -} - -if ( p_BuildingThermalAsset == null ) { - if ( p_secondaryHeatingAsset == null ) { // Just one heating asset - if ( p_primaryHeatingAsset== null ) { - if (powerDemand_kW > 0) { - traceln("No heating assets for GridConnection " + p_gridConnectionID); - } - } else { - if ( p_primaryHeatingAsset instanceof J_EAConversionGasBurner || p_primaryHeatingAsset instanceof J_EAConversionHeatDeliverySet || p_primaryHeatingAsset instanceof J_EAConversionHydrogenBurner || p_primaryHeatingAsset instanceof J_EAConversionHeatPump) { // when there is only a gas burner or DH set - p_primaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW()); - } - else if(p_primaryHeatingAsset instanceof J_EAConversionGasCHP){ - p_primaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / ((J_EAConversionGasCHP)p_primaryHeatingAsset).getOutputHeatCapacity_kW()); - } - else { - traceln("GridConnection " + p_gridConnectionID + " has a single unsupported heating asset!"); - } - } - } - else if (p_primaryHeatingAsset== null && p_secondaryHeatingAsset != null && v_hasQuarterHourlyValues){ - if(p_secondaryHeatingAsset instanceof J_EAConversionGasBurner){ - p_secondaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / p_secondaryHeatingAsset.getOutputCapacity_kW()); - p_secondaryHeatingAsset.f_updateAllFlows(p_secondaryHeatingAsset.v_powerFraction_fr); - } else { - traceln("GridConnection " + p_gridConnectionID + " has a single unsupported secondary heating asset!"); - } - } else { // Two heating assets - if ( p_primaryHeatingAsset instanceof J_EAConversionHeatPump && p_secondaryHeatingAsset instanceof J_EAConversionGasBurner) { // Heatpump and gasburner, switch based on heatpump COP) - //((J_EAConversionHeatPump)p_primaryHeatingAsset.j_ea).updateAmbientTemp(main.v_currentAmbientTemperature_degC); // update heatpump temp levels! <-- waarom dit gebeurt al in de main (peter 21-02-23) - double HP_COP = ((J_EAConversionHeatPump)p_primaryHeatingAsset).getCOP(); - double COP_tres = 3.5; // TODO: Make data agnostic! Also, this line doesn't have to be evaluated every timestep. - if ( HP_COP < COP_tres ) { // switch to gasburner when HP COP is below treshold - //traceln("Hybrid HP: Switching to gas burner"); - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_secondaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / p_secondaryHeatingAsset.getOutputCapacity_kW()); - } else { // heatpump when COP is above treshold - //traceln("Hybrid HP: Using heatpump with COP " + HP_COP); - p_primaryHeatingAsset.v_powerFraction_fr = min(1,powerDemand_kW / p_primaryHeatingAsset.getOutputCapacity_kW()); - p_secondaryHeatingAsset.v_powerFraction_fr = 0;//min(1,currentDHWdemand_kW / p_secondaryHeatingAsset.j_ea.getHeatCapacity_kW()); - } - } else { - traceln("**** EXCEPTION ****: Unsupported combination of heatings systems in house " + p_gridConnectionID); - p_primaryHeatingAsset.v_powerFraction_fr = 0; - p_secondaryHeatingAsset.v_powerFraction_fr = 0; - //p_BuildingThermalAsset.v_powerFraction_fr = 0; - } - p_secondaryHeatingAsset.f_updateAllFlows(p_secondaryHeatingAsset.v_powerFraction_fr); - //v_conversionPowerElectric_kW += p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW;// traceln("heatpump electricity consumption: " + (p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW)); - /*if (p_secondaryHeatingAsset instanceof J_EAConversionHeatPump) { - v_heatPumpElectricityConsumption_kW += p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW; - }*/ - } - if (p_primaryHeatingAsset != null) { - p_primaryHeatingAsset.f_updateAllFlows(p_primaryHeatingAsset.v_powerFraction_fr); - //v_conversionPowerElectric_kW += flowsArray[4] - flowsArray[0]; //p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW; - /*if (p_primaryHeatingAsset instanceof J_EAConversionHeatPump) { - v_heatPumpElectricityConsumption_kW += flowsArray[4] - flowsArray[0]; - }*/ - } -} else { // TODO: Implement thermostat functionality for thermal storage asset. Where to get temp setpoint? - traceln("No thermostat functionality available to manage p_BuildingThermalAsset!!"); - p_primaryHeatingAsset.f_updateAllFlows(0); - /* v_conversionPowerElectric_kW += flowsArray[4] - flowsArray[0]; //p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW; - if (p_primaryHeatingAsset instanceof J_EAConversionHeatPump) { - v_heatPumpElectricityConsumption_kW += flowsArray[4] - flowsArray[0]; - }*/ - p_secondaryHeatingAsset.f_updateAllFlows(0); - /*v_conversionPowerElectric_kW += flowsArray[4] - flowsArray[0]; //p_primaryHeatingAsset.electricityConsumption_kW - p_primaryHeatingAsset.electricityProduction_kW; - if (p_secondaryHeatingAsset instanceof J_EAConversionHeatPump) { - v_heatPumpElectricityConsumption_kW += flowsArray[4] - flowsArray[0]; - }*/ - p_BuildingThermalAsset.f_updateAllFlows(0); -} -/*ALCODEEND*/} - double f_manageCharging() {/*ALCODESTART::1671095995172*/ -double availableCapacityFromBatteries = p_batteryAsset == null ? 0 : p_batteryAsset.getCapacityAvailable_kW(); -//double availableChargingCapacity = v_allowedCapacity_kW + availableCapacityFromBatteries - v_currentPowerElectricity_kW; -double availableChargingCapacity = v_liveConnectionMetaData.contractedDeliveryCapacity_kW + availableCapacityFromBatteries - fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY); -switch (p_chargingAttitudeVehicles) { - case SIMPLE: - f_simpleCharging(); - break; - case MAX_SPREAD: - f_maxSpreadCharging(); - break; - case MAX_POWER: - f_maxPowerCharging( max(0, availableChargingCapacity)); - break; - case CHEAP: - v_currentElectricityPriceConsumption_eurpkWh = p_owner.f_getElectricityPrice(v_liveConnectionMetaData.contractedDeliveryCapacity_kW); - v_electricityPriceLowPassed_eurpkWh += v_lowPassFactor_fr * ( v_currentElectricityPriceConsumption_eurpkWh - v_electricityPriceLowPassed_eurpkWh ); - f_chargeOnPrice( v_currentElectricityPriceConsumption_eurpkWh, max(0, availableChargingCapacity)); - break; - case V2G: - v_currentElectricityPriceConsumption_eurpkWh = p_owner.f_getElectricityPrice(v_liveConnectionMetaData.contractedDeliveryCapacity_kW); - v_electricityPriceLowPassed_eurpkWh += v_lowPassFactor_fr * ( v_currentElectricityPriceConsumption_eurpkWh - v_electricityPriceLowPassed_eurpkWh ); - f_chargeOnPrice_V2G( v_currentElectricityPriceConsumption_eurpkWh, max(0, availableChargingCapacity)); - break; +if(c_electricVehicles.size() > 0){ + double availableCapacityFromBatteries = p_batteryAsset == null ? 0 : p_batteryAsset.getCapacityAvailable_kW(); + //double availableChargingCapacity = v_allowedCapacity_kW + availableCapacityFromBatteries - v_currentPowerElectricity_kW; + double availableChargingCapacity = v_liveConnectionMetaData.contractedDeliveryCapacity_kW + availableCapacityFromBatteries - fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.ELECTRICITY); + + switch (p_chargingAttitudeVehicles) { + case SIMPLE: + f_simpleCharging(); + break; + case MAX_SPREAD: + f_maxSpreadCharging(); + break; + case MAX_POWER: + f_maxPowerCharging( max(0, availableChargingCapacity)); + break; + case CHEAP: + v_currentElectricityPriceConsumption_eurpkWh = p_owner.f_getElectricityPrice(v_liveConnectionMetaData.contractedDeliveryCapacity_kW); + v_electricityPriceLowPassed_eurpkWh += v_lowPassFactor_fr * ( v_currentElectricityPriceConsumption_eurpkWh - v_electricityPriceLowPassed_eurpkWh ); + f_chargeOnPrice( v_currentElectricityPriceConsumption_eurpkWh, max(0, availableChargingCapacity)); + break; + case V2G: + v_currentElectricityPriceConsumption_eurpkWh = p_owner.f_getElectricityPrice(v_liveConnectionMetaData.contractedDeliveryCapacity_kW); + v_electricityPriceLowPassed_eurpkWh += v_lowPassFactor_fr * ( v_currentElectricityPriceConsumption_eurpkWh - v_electricityPriceLowPassed_eurpkWh ); + f_chargeOnPrice_V2G( v_currentElectricityPriceConsumption_eurpkWh, max(0, availableChargingCapacity)); + break; + } } - /*ALCODEEND*/} double f_simpleCharging() @@ -553,9 +466,7 @@ else if (p_primaryHeatingAsset== null && p_secondaryHeatingAsset != null && v_ha OL_AssetFlowCategories AC = j_ea.assetFlowCategory; v_liveAssetsMetaData.activeAssetFlows.add(AC); if (energyModel.b_isInitialized && v_isActive) { - f_addAssetFlow(AC); - energyModel.f_addAssetFlow(AC); - c_parentCoops.forEach(x->x.f_addAssetFlow(AC)); + f_addAssetFlow(AC); } } @@ -569,9 +480,9 @@ else if (p_primaryHeatingAsset== null && p_secondaryHeatingAsset != null && v_ha } else if (vehicle instanceof J_EAHydrogenVehicle) { c_hydrogenVehicles.add((J_EAHydrogenVehicle)vehicle); } else if (vehicle instanceof J_EAEV) { + c_electricVehicles.add((J_EAEV)vehicle); c_vehiclesAvailableForCharging.add((J_EAEV)vehicle); energyModel.c_EVs.add((J_EAEV)vehicle); - //c_EvAssets.add(j_ea); } c_vehicleAssets.add(vehicle); J_ActivityTrackerTrips tripTracker = vehicle.getTripTracker(); @@ -602,17 +513,13 @@ else if (p_primaryHeatingAsset== null && p_secondaryHeatingAsset != null && v_ha p_DHWAsset = (J_EAConsumption)j_ea; } if( j_ea.energyAssetType == OL_EnergyAssetType.ELECTRICITY_DEMAND ) { - //c_fixedConsumptionElectricAssets.add(j_ea); } if( j_ea.energyAssetType == OL_EnergyAssetType.ELECTRIC_HOB ) { - //c_electricHobAssets.add(j_ea); } } else if (j_ea instanceof J_EAProduction) { c_productionAssets.add((J_EAProduction)j_ea); - //energyModel.c_productionAssets.add((J_EAProduction)j_ea); - + if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOVOLTAIC) { - //v_liveAssetsMetaData.hasPV = true; double capacity_kW = ((J_EAProduction)j_ea).getCapacityElectric_kW(); v_liveAssetsMetaData.totalInstalledPVPower_kW += capacity_kW; if ( p_parentNodeElectric != null ) { @@ -620,10 +527,8 @@ else if (p_primaryHeatingAsset== null && p_secondaryHeatingAsset != null && v_ha } c_parentCoops.forEach( coop -> coop.v_liveAssetsMetaData.totalInstalledPVPower_kW += capacity_kW); energyModel.v_liveAssetsMetaData.totalInstalledPVPower_kW += capacity_kW; - //c_pvAssets.add(j_ea); } else if (j_ea.energyAssetType == OL_EnergyAssetType.WINDMILL) { - //v_liveAssetsMetaData.hasWindturbine = true; double capacity_kW = ((J_EAProduction)j_ea).getCapacityElectric_kW(); v_liveAssetsMetaData.totalInstalledWindPower_kW += capacity_kW; if ( p_parentNodeElectric != null ) { @@ -631,11 +536,8 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.WINDMILL) { } c_parentCoops.forEach( coop -> coop.v_liveAssetsMetaData.totalInstalledWindPower_kW += capacity_kW); energyModel.v_liveAssetsMetaData.totalInstalledWindPower_kW += capacity_kW; - //c_windAssets.add(j_ea); } else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ - //v_liveAssetsMetaData.hasPT = true; - //c_ptAssets.add(j_ea); if (p_heatingManagement != null) { p_heatingManagement.notInitialized(); } @@ -645,8 +547,6 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ // Non Heating Assets if ( j_ea.energyAssetType == OL_EnergyAssetType.GAS_PIT || j_ea.energyAssetType == OL_EnergyAssetType.ELECTRIC_HOB){ if (j_ea.energyAssetType == OL_EnergyAssetType.ELECTRIC_HOB) { - //c_electricHobAssets.add(j_ea); - //c_conversionElectricAssets.add(j_ea); } if (p_cookingTracker == null) { int rowIndex = uniform_discr(2, 300); @@ -654,8 +554,6 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ } else { p_cookingTracker.HOB = (J_EAConversion)j_ea; } - //} else if (j_ea instanceof J_EAConversionElectrolyser) { - //c_electrolyserAssets.add(j_ea); } else { // Heating Assets c_heatingAssets.add((J_EAConversion)j_ea); @@ -665,9 +563,7 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ // Special Heating Assets if (j_ea instanceof J_EAConversionHeatPump) { energyModel.c_ambientDependentAssets.add(j_ea); - //c_electricHeatpumpAssets.add(j_ea); } else if (j_ea instanceof J_EAConversionGasCHP) { - //c_chpAssets.add(j_ea); } } } else if (j_ea instanceof J_EAStorage) { @@ -691,7 +587,6 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ p_gasBuffer = (J_EAStorageGas)j_ea; } else if (j_ea instanceof J_EAStorageElectric) { p_batteryAsset = (J_EAStorageElectric)j_ea; - //c_batteryAssets.add(j_ea); double capacity_MWh = ((J_EAStorageElectric)j_ea).getStorageCapacity_kWh()/1000; v_liveAssetsMetaData.totalInstalledBatteryStorageCapacity_MWh += capacity_MWh; c_parentCoops.forEach( coop -> coop.v_liveAssetsMetaData.totalInstalledBatteryStorageCapacity_MWh += capacity_MWh); @@ -699,13 +594,11 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ } } else if (j_ea instanceof J_EAProfile) { - //p_energyProfile = (J_EAProfile)j_ea; c_profileAssets.add((J_EAProfile)j_ea); } else if (j_ea instanceof J_EADieselTractor) { c_profileAssets.add((J_EAProfile)j_ea); } else if (j_ea instanceof J_EACharger) { c_chargers.add((J_EACharger)j_ea); - //c_EvAssets.add(j_ea); } else { if (!(this instanceof GCHouse && j_ea instanceof J_EAAirco)) { traceln("Unrecognized energy asset %s in gridconnection %s", j_ea, this); @@ -759,7 +652,7 @@ else if (j_ea.energyAssetType == OL_EnergyAssetType.PHOTOTHERMAL){ double V2G_WTR_offset_eurpkWh = 0.05; double chargeSetpoint_kW = 0; - if ( energyModel.t_h*60 >= chargeDeadline_min & chargeNeedForNextTrip_kWh > 0) { // Must-charge time at max charging power + if ( energyModel.t_h*60 >= chargeDeadline_min - 30 & chargeNeedForNextTrip_kWh > 0) { // Must-charge time at max charging power //traceln("Urgency charging! May exceed connection capacity!"); chargeSetpoint_kW = maxChargingPower_kW; } else if ( vehicle.getCurrentStateOfCharge_fr() < 0.15 ) { @@ -1315,7 +1208,8 @@ else if (flowsMap.get(EC) > 0){ v_isActive = setActive; // v_isActive must be true before calling updateActiveAssetData! v_liveAssetsMetaData.updateActiveAssetData(new ArrayList<>(List.of(this))); v_liveAssetsMetaData.activeAssetFlows.forEach(x->energyModel.f_addAssetFlow(x)); - + v_liveAssetsMetaData.activeAssetFlows.forEach(x-> c_parentCoops.forEach(coop -> coop.f_addAssetFlow(x))); + // update GN parents' wind / solar totals (will be wrong if you changed your totals while paused) p_parentNodeElectric.f_updateTotalInstalledProductionAssets(OL_EnergyAssetType.PHOTOVOLTAIC, v_liveAssetsMetaData.totalInstalledPVPower_kW, true); p_parentNodeElectric.f_updateTotalInstalledProductionAssets(OL_EnergyAssetType.WINDMILL, v_liveAssetsMetaData.totalInstalledWindPower_kW, true); @@ -1333,11 +1227,7 @@ else if (flowsMap.get(EC) > 0){ double startTime = energyModel.v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMin(); double endTime = energyModel.v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMax(); v_liveData.resetLiveDatasets(startTime, endTime, energyModel.p_timeStep_h); - //v_isActive = setActive; // } - -//Update the 'isActive' variable - /*ALCODEEND*/} double f_getChargeDeadline(J_EAEV ev) @@ -1355,20 +1245,11 @@ else if (flowsMap.get(EC) > 0){ v_liveData.dsm_liveSupply_kW.createEmptyDataSets(v_activeProductionEnergyCarriers, (int)(168 / energyModel.p_timeStep_h)); v_liveData.dsm_liveAssetFlows_kW.createEmptyDataSets(v_liveData.assetsMetaData.activeAssetFlows, (int)(168 / energyModel.p_timeStep_h)); -/* -dsm_dailyAverageDemandDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, 365); -dsm_dailyAverageSupplyDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, 365); - -dsm_summerWeekDemandDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, (int)(168 / energyModel.p_timeStep_h)); -dsm_summerWeekSupplyDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, (int)(168 / energyModel.p_timeStep_h)); -dsm_winterWeekDemandDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, (int)(168 / energyModel.p_timeStep_h)); -dsm_winterWeekSupplyDataSets_kW.createEmptyDataSets(v_activeEnergyCarriers, (int)(168 / energyModel.p_timeStep_h)); -*/ /*ALCODEEND*/} double f_manageChargers() {/*ALCODESTART::1750258434630*/ -if ( c_chargers.size() > 0 ) { // && v_isActiveCharger ) { +if ( c_chargers.size() > 0 ) { switch (p_chargingAttitudeVehicles) { case V1G: case MAX_POWER: @@ -1497,29 +1378,53 @@ EnergyCoop f_addProductionEnergyCarrier(OL_EnergyCarriers EC) EnergyCoop f_addAssetFlow(OL_AssetFlowCategories AC) {/*ALCODESTART::1754380684467*/ -DataSet dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); -double startTime = v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMin(); -double endTime = v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMax(); -for (double t = startTime; t <= endTime; t += energyModel.p_timeStep_h) { - dsAsset.add( t, 0); -} -v_liveData.dsm_liveAssetFlows_kW.put( AC, dsAsset); - -if (AC == OL_AssetFlowCategories.batteriesChargingPower_kW) { // also add batteriesDischarging! - v_liveAssetsMetaData.activeAssetFlows.add(OL_AssetFlowCategories.batteriesDischargingPower_kW); - dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); +if (!v_liveAssetsMetaData.activeAssetFlows.contains(AC)) { + DataSet dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); + double startTime = v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMin(); + double endTime = v_liveData.dsm_liveDemand_kW.get(OL_EnergyCarriers.ELECTRICITY).getXMax(); for (double t = startTime; t <= endTime; t += energyModel.p_timeStep_h) { dsAsset.add( t, 0); } - v_liveData.dsm_liveAssetFlows_kW.put( OL_AssetFlowCategories.batteriesDischargingPower_kW, dsAsset); -} -if (AC == OL_AssetFlowCategories.V2GPower_kW) { // also add evCharging! - v_liveAssetsMetaData.activeAssetFlows.add(OL_AssetFlowCategories.evChargingPower_kW); - dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); - for (double t = startTime; t <= endTime; t += energyModel.p_timeStep_h) { - dsAsset.add( t, 0); + v_liveData.dsm_liveAssetFlows_kW.put( AC, dsAsset); + + traceln("Adding AC flow: " + AC); + + if (AC == OL_AssetFlowCategories.batteriesChargingPower_kW) { // also add batteriesDischarging! + v_liveAssetsMetaData.activeAssetFlows.add(OL_AssetFlowCategories.batteriesDischargingPower_kW); + dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); + for (double t = startTime; t <= endTime; t += energyModel.p_timeStep_h) { + dsAsset.add( t, 0); + } + v_liveData.dsm_liveAssetFlows_kW.put( OL_AssetFlowCategories.batteriesDischargingPower_kW, dsAsset); + } + if (AC == OL_AssetFlowCategories.V2GPower_kW && !v_liveAssetsMetaData.activeAssetFlows.contains(OL_AssetFlowCategories.evChargingPower_kW)) { // also add evCharging! + v_liveAssetsMetaData.activeAssetFlows.add(OL_AssetFlowCategories.evChargingPower_kW); + dsAsset = new DataSet( (int)(168 / energyModel.p_timeStep_h) ); + for (double t = startTime; t <= endTime; t += energyModel.p_timeStep_h) { + dsAsset.add( t, 0); + } + v_liveData.dsm_liveAssetFlows_kW.put( OL_AssetFlowCategories.evChargingPower_kW, dsAsset); } - v_liveData.dsm_liveAssetFlows_kW.put( OL_AssetFlowCategories.evChargingPower_kW, dsAsset); + + //Add asset flow also to aggregators + c_parentCoops.forEach(x -> x.f_addAssetFlow(OL_AssetFlowCategories.V2GPower_kW)); + energyModel.f_addAssetFlow(OL_AssetFlowCategories.V2GPower_kW); } /*ALCODEEND*/} +double f_activateV2GChargingMode() +{/*ALCODESTART::1754582754934*/ +if(energyModel.b_isInitialized){ + //Check needed to make sure v2g is displayed correctly in the graphs + if(p_chargingAttitudeVehicles == OL_ChargingAttitude.V2G){ + c_electricVehicles.forEach(ev -> ev.setV2GActive(true)); + c_chargers.forEach(charger -> charger.setV2GActive(true)); + f_addAssetFlow(OL_AssetFlowCategories.V2GPower_kW); + } + else{ + c_electricVehicles.forEach(ev -> ev.setV2GActive(false)); + c_chargers.forEach(charger -> charger.setV2GActive(false)); + } +} +/*ALCODEEND*/} + diff --git a/_alp/Agents/GridConnection/Code/Functions.xml b/_alp/Agents/GridConnection/Code/Functions.xml index f9ee7253..1e788c39 100644 --- a/_alp/Agents/GridConnection/Code/Functions.xml +++ b/_alp/Agents/GridConnection/Code/Functions.xml @@ -96,23 +96,6 @@ true - - VOID - double - 1669025846794 - - true - 920 - 290 - - false - true - true - - VOID double @@ -619,7 +602,7 @@ 1753099764237 920 - 400 + 290 + + VOID + double + 1754582754934 + + 290 + 140 + + false + true + true + + diff --git a/_alp/Agents/GridConnection/Variables.xml b/_alp/Agents/GridConnection/Variables.xml index e6e28bfa..9359f3d9 100644 --- a/_alp/Agents/GridConnection/Variables.xml +++ b/_alp/Agents/GridConnection/Variables.xml @@ -607,29 +607,6 @@ - - 1722584654288 - - true - 370 - 380 - - false - true - true - - - - - - - 1725968910310 @@ -1032,29 +1009,6 @@ - - 1753110629668 - - true - 570 - 840 - - false - true - true - - - - - - - 1753970741239 @@ -1278,6 +1232,7 @@ + f_activateV2GChargingMode() 1668693393496 TEXT_BOX @@ -1291,7 +1246,7 @@ 1668695364192 600 - 450 + 490