//SETTINGS //----------------------------------------------------------------------------- FlowrateHeatingHTmin = 1; FlowrateHeatingLTmin = 0.8; FlowrateCoolingLTmin = 2; FlowrateCoolingHTmin = 2; FlowrateHysteresisPercentage = 20; TempATESCold = 4; TempATESHot = 18; TempATESHysteresis = 2; StorageHotTopHPon = 60; StorageHotBottomHPoff = 60; StorageColdTopHPon = 2; StorageColdBottomHPoff = 2; TempHPcondenserHot = 80; TempHPevaporatorCold = -5; FlowrateHPevaporatorMin = 45; FlowrateHPcondenserMin = 15; HPdelay = 5; ATESSoilVolumeFlowColdDeposit = 50; ATESSoilVolumeFlowColdWithdraw = 50; TempATESColdWithdrawMin = TempCoolingReturn - 2; TempATESColdWithdrawMax = TempCoolingReturn - 1; TempHPColdSupplyMin = CoolingSP - 1; TempHPColdSupplyMax = CoolingSP + 1; AEHotReleaseOn = 0; AEColdReleaseOn = 0; AEColdSupplyOn = 0; HPDirectHeatingCoolingOn = 1; StorageHotMiddleAEHotReleaseOn = 60; StorageHotTopAEHotReleaseOff = 60; StorageColdMiddleAEColdReleaseOn = 2; StorageColdTopAEColdReleaseOff = 2; ATESColdDepositLimitationHeatingOn = 0; ATESColdDepositLimitationHeatingCoolingOn = 0; ATESColdWithdrawLimitationCoolingOn = 0; ATESColdWithdrawLimitationHeatingCoolingOn = 0; ATESColdDepositLimit = 999999999999; ATESColdWithdrawLimit = 999999999999; AEColdDepositLimit = 999999999999; AEColdWithdrawLimit = 999999999999; HPActiveColdDepositLimit = 999999999999; AEColdDepositOn = 0; AEColdWithdrawOn = 0; HPActiveColdDepositOn = 0; //INPUTS //----------------------------------------------------------------------------- FlowrateHeatingHT = in1; FlowrateHeatingLT = in2; FlowrateCoolingLT = in3; FlowrateCoolingHT = in4; HTheatingSP = in5; LTheatingSP = in6; LTcoolingSP = in7; HTcoolingSP = in8; StorageHotTop = in9; StorageHotMiddle = in10; StorageHotBottom = in11; StorageColdTop = in12; StorageColdMiddle = in13; StorageColdBottom = in14; TempATESColdWell = in15; TempATESHotWell = in16; TempOutside = in17; TempCoolingReturn = in18; TempCoolingReturnAfterATES = in19; TempHPcondenser = in20; TempHPevaporator = in21; FlowrateHPcondenser = in22; FlowrateHPevaporator = in23; ColdPowerATESColdDeposit = in24; ColdPowerATESColdWithdraw = in25; ColdPowerAEColdDeposit = in26; ColdPowerAEColdWithdraw = in27; //THERMAL DEMAND //----------------------------------------------------------------------------- //HT-Heating demand on if ( FlowrateHeatingHT > (FlowrateHeatingHTmin + (FlowrateHeatingHTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { HTheatingDemand = 1; } //HT-Heating demand off if ( FlowrateHeatingHT < (FlowrateHeatingHTmin - (FlowrateHeatingHTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { HTheatingDemand = 0; } //LT-Heating demand on if ( FlowrateHeatingLT > (FlowrateHeatingLTmin + (FlowrateHeatingLTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { LTheatingDemand = 1; } //LT-Heating demand off if ( FlowrateHeatingLT < (FlowrateHeatingLTmin - (FlowrateHeatingLTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { LTheatingDemand = 0; } //Heating demand if ( HTheatingDemand == 1 || LTheatingDemand == 1 ) { HeatingDemand = 1; } else { HeatingDemand = 0; } //LT-Cooling demand on if ( FlowrateCoolingLT > (FlowrateCoolingLTmin + (FlowrateCoolingLTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { LTcoolingDemand = 1; } //LT-Cooling demand off if ( FlowrateCoolingLT < (FlowrateCoolingLTmin - (FlowrateCoolingLTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { LTcoolingDemand = 0; } //HT-Cooling demand on if ( FlowrateCoolingHT > (FlowrateCoolingHTmin + (FlowrateCoolingHTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { HTcoolingDemand = 1; } //HT-Cooling demand off if ( FlowrateCoolingHT < (FlowrateCoolingHTmin - (FlowrateCoolingHTmin * (FlowrateHysteresisPercentage / 2) / 100)) ) { HTcoolingDemand = 0; } //Cooling demand if ( LTcoolingDemand == 1 || HTcoolingDemand == 1 ) { CoolingDemand = 1; } else { CoolingDemand = 0; } //TEMPERATURE SETPOINTS //----------------------------------------------------------------------------- //HT-Heating SP if ( HTheatingDemand == 1 ) { HeatingSP = HTheatingSP; } //LT-Heating SP if ( HTheatingDemand == 0 ) { HeatingSP = LTheatingSP; } //LT-Cooling SP if ( LTcoolingDemand == 1 ) { CoolingSP = LTcoolingSP; } //LT-Heating SP if ( LTcoolingDemand == 0 ) { CoolingSP = HTcoolingSP; } //OPERATING CONDITIONS //----------------------------------------------------------------------------- //HEATING //Heat Pump Heating and ATES Cold Deposit ON if ( HeatingDemand == 1 && CoolingDemand == 0 && TempATESColdWell > (TempATESCold + (TempATESHysteresis / 2)) && TempATESHotWell < (TempATESHot - (TempATESHysteresis / 2)) && ATESColdDepositLimitationHeating == 0 ) { HPHeatingATESColdDeposit = 1; } //Heat Pump Heating and ATES Cold Deposit OFF if ( HeatingDemand == 0 || CoolingDemand == 1 || TempATESColdWell < (TempATESCold - (TempATESHysteresis / 2)) || TempATESHotWell > (TempATESHot + (TempATESHysteresis / 2)) || ATESColdDepositLimitationHeating == 1 ) { HPHeatingATESColdDeposit = 0; } //Heat Pump Heating and AE Cold Release ON (Optional) if ( HeatingDemand == 1 && CoolingDemand == 0 && HPHeatingATESColdDeposit == 0 && StorageColdTop < (TempOutside - 1) && AEColdReleaseOn == 1 ) { HPHeatingAEColdRelease = 1; } //Heat Pump Heating and AE Cold Release OFF (Optional) if ( HeatingDemand == 0 || CoolingDemand == 1 || HPHeatingATESColdDeposit == 1 || StorageColdTop > TempOutside || AEColdReleaseOn == 0 ) { HPHeatingAEColdRelease = 0; } //COOLING //ATES Cold Withdraw ON if ( HeatingDemand == 0 && CoolingDemand == 1 && TempATESColdWell > (TempATESCold + (TempATESHysteresis / 2)) && TempATESHotWell < (TempATESHot - (TempATESHysteresis / 2)) && TempATESColdWell < TempATESColdWithdrawMin && ATESColdWithdrawLimitationCooling == 0 ) { ATESCoolingColdWithdraw = 1; } //ATES Cold Withdraw OFF if ( HeatingDemand == 1 || CoolingDemand == 0 || TempATESColdWell < (TempATESCold - (TempATESHysteresis / 2)) || TempATESHotWell > (TempATESHot + (TempATESHysteresis / 2)) || TempATESColdWell > TempATESColdWithdrawMax || ATESColdWithdrawLimitationCooling == 1 ) { ATESCoolingColdWithdraw = 0; } //Heat Pump Cooling and AE Hot Release ON (Optional) if ( HeatingDemand == 0 && CoolingDemand == 1 && TempCoolingReturnAfterATES > TempHPColdSupplyMax && AEHotReleaseOn == 1 ) { HPCoolingAEHotRelease = 1; } //Heat Pump Cooling and AE Hot Release OFF (Optional) if ( HeatingDemand == 1 || CoolingDemand == 0 || TempCoolingReturnAfterATES < TempHPColdSupplyMin || AEHotReleaseOn == 0 ) { HPCoolingAEHotRelease = 0; } //Ambient Exchange Cold Supply ON (Optional) if ( HeatingDemand == 0 && CoolingDemand == 1 && TempOutside < (TempATESColdWell - 1) && TempOutside < TempATESColdWithdrawMin && AEColdSupplyOn == 1 ) { AEColdSupply = 1; } //Ambient Exchange Cold Supply OFF (Optional) if ( HeatingDemand == 1 || CoolingDemand == 0 || TempOutside > (TempATESColdWell - 1) || TempOutside > TempATESColdWithdrawMax || AEColdSupplyOn == 0 ) { AEColdSupply = 0; } //HEATING + COOLING //ATES Cold Withdraw ON if ( HeatingDemand == 1 && CoolingDemand == 1 && TempATESColdWell > (TempATESCold + (TempATESHysteresis / 2)) && TempATESHotWell < (TempATESHot - (TempATESHysteresis / 2)) && TempATESColdWell < TempATESColdWithdrawMin && ATESColdWithdrawLimitationHeatingCooling == 0 ) { ATESHeatingCoolingColdWithdraw = 1; } //ATES Cold Withdraw OFF if ( HeatingDemand == 0 || CoolingDemand == 0 || TempATESColdWell < (TempATESCold - (TempATESHysteresis / 2)) || TempATESHotWell > (TempATESHot + (TempATESHysteresis / 2)) || TempATESColdWell > TempATESColdWithdrawMax || ATESColdWithdrawLimitationHeatingCooling == 1 ) { ATESHeatingCoolingColdWithdraw = 0; } //Heat Pump Direct Heating and Cooling ON (Optional) if ( HeatingDemand == 1 && CoolingDemand == 1 && TempCoolingReturnAfterATES > TempHPColdSupplyMax && HPDirectHeatingCoolingOn == 1 ) { HPDirectHeatingCooling = 1; } //Heat Pump Direct Heating and Cooling OFF (Optional) if ( HeatingDemand == 0 || CoolingDemand == 0 || TempCoolingReturnAfterATES < TempHPColdSupplyMin || HPDirectHeatingCoolingOn == 0 ) { HPDirectHeatingCooling = 0; } //LIMITATIONS //----------------------------------------------------------------------------- //ATES Cold Deposit Limitation counter ColdStepATESColdDepositLimitation = - (ColdPowerATESColdDeposit * 30) / 3600000; ColdTotalATESColdDepositLimitation = ColdTotalATESColdDepositLimitation + ColdStepATESColdDepositLimitation; //ATES Cold Deposit Limitation for Heating if ( ColdTotalATESColdDepositLimitation >= ATESColdDepositLimit && ATESColdDepositLimitationHeatingOn == 1 ) { ATESColdDepositLimitationHeating = 1; } else { ATESColdDepositLimitationHeating = 0; } //ATES Cold Deposit Limitation for Heating and Cooling if ( ColdTotalATESColdDepositLimitation >= ATESColdDepositLimit && ATESColdDepositLimitationHeatingCoolingOn == 1 && HPIndirectHeatingCoolingOn == 1 ) { ATESColdDepositLimitationHeatingCooling = 1; } else { ATESColdDepositLimitationHeatingCooling = 0; } //ATES Cold Withdraw Limitation counter ColdStepATESColdWithdrawLimitation = - (ColdPowerATESColdWithdraw * 30) / 3600000; ColdTotalATESColdWithdrawLimitation = ColdTotalATESColdWithdrawLimitation + ColdStepATESColdWithdrawLimitation; //ATES Cold Withdraw Limitation for Cooling if ( ColdTotalATESColdWithdrawLimitation >= ATESColdWithdrawLimit && ATESColdWithdrawLimitationCoolingOn == 1 ) { ATESColdWithdrawLimitationCooling = 1; } else { ATESColdWithdrawLimitationCooling = 0; } //ATES Cold Withdraw Limitation for Heating and Cooling if ( ColdTotalATESColdWithdrawLimitation >= ATESColdWithdrawLimit && ATESColdWithdrawLimitationHeatingCoolingOn == 1 ) { ATESColdWithdrawLimitationHeatingCooling = 1; } else { ATESColdWithdrawLimitationHeatingCooling = 0; } //REGENERATIONS //----------------------------------------------------------------------------- //Ambient Exchange Cold Deposit counter ColdStepAEColdDeposit = (ColdPowerAEColdDeposit * 30) / 3600000; ColdTotalAEColdDeposit = ColdTotalAEColdDeposit + ColdStepAEColdDeposit; //Ambient Exchange Cold Deposit ON if ( HeatingDemand == 0 && CoolingDemand == 0 && TempOutside < (TempATESColdWell - 1) && AEColdDepositOn == 1 ) { AEColdDeposit = 1; } //Ambient Exchange Cold Deposit OFF if ( HeatingDemand == 1 || CoolingDemand == 1 || TempOutside > (TempATESColdWell - 1) || ColdTotalAEColdDeposit >= AEColdDepositLimit || AEColdDepositOn == 0 ) { AEColdDeposit = 0; } //Ambient Exchange Cold Withdraw counter ColdStepAEColdWithdraw = - (ColdPowerAEColdWithdraw * 30) / 3600000; ColdTotalAEColdWithdraw = ColdTotalAEColdWithdraw + ColdStepAEColdWithdraw; //Ambient Exchange Cold Withdraw ON if ( CoolingDemand == 0 && TempOutside > (TempATESColdWell + 1) && AEColdWithdrawOn == 1 ) { AEColdWithdraw = 1; } //Ambient Exchange Cold Withdraw OFF if ( CoolingDemand == 1 || TempOutside < (TempATESColdWell + 1) || ColdTotalAEColdWithdraw >= AEColdWithdrawLimit || AEColdWithdrawOn == 0 ) { AEColdWithdraw = 0; } //Heat Pump Active Cold Deposit counter if ( HPActiveColdDeposit == 1 ) { ColdStepHPActiveColdDeposit = - (ColdPowerATESColdDeposit * 30) / 3600000; ColdTotalHPActiveColdDeposit = ColdTotalHPActiveColdDeposit + ColdStepHPActiveColdDeposit; } //Heat Pump Active Cold Deposit ON if ( HeatingDemand == 0 && CoolingDemand == 0 && HPActiveColdDepositOn == 1 ) { HPActiveColdDeposit = 1; } //Heat Pump Active Cold Deposit OFF if ( HeatingDemand == 1 || CoolingDemand == 1 || ColdTotalHPActiveColdDeposit >= HPActiveColdDepositLimit || HPActiveColdDepositOn == 0 ) { HPActiveColdDeposit = 0; } //COUNTER RESET //----------------------------------------------------------------------------- //Annual reset counters AnnualResetTimer = AnnualResetTimer + (1/2); if ( AnnualResetTimer >= (8760 * 60) ) { AnnualResetTimer = 0; ColdTotalATESColdDepositLimitation = 0; ColdTotalATESColdWithdrawLimitation = 0; ColdTotalAEColdDeposit = 0; ColdTotalAEColdWithdraw = 0; ColdTotalHPActiveColdDeposit = 0; } //DELAYS //----------------------------------------------------------------------------- //HP delay if ( HPPumps == 1 ) { HPtimer = HPtimer + (1/2); } //ENABLE //----------------------------------------------------------------------------- //HP ON if ( StorageHotTop < StorageHotTopHPon && StorageColdTop > StorageColdTopHPon && (HPHeatingATESColdDeposit == 1 || HPHeatingAEColdRelease == 1 || HPCoolingAEHotRelease == 1 || HPDirectHeatingCooling == 1 || HPActiveColdDeposit == 1) && HPtimer >= HPdelay && TempHPcondenser < TempHPcondenserHot && TempHPevaporator > TempHPevaporatorCold && FlowrateHPevaporator > FlowrateHPevaporatorMin && FlowrateHPcondenser > FlowrateHPcondenserMin ) { HP = 1; HPtimer = 0; } //HP OFF if ( StorageHotBottom > StorageHotBottomHPoff || StorageColdBottom < StorageColdBottomHPoff || TempHPcondenser > TempHPcondenserHot || TempHPevaporator < TempHPevaporatorCold || FlowrateHPevaporator < FlowrateHPevaporatorMin || FlowrateHPcondenser < FlowrateHPcondenserMin ) { HP = 0; } //HP Pumps ON if ( StorageHotTop < StorageHotTopHPon && StorageColdTop > StorageColdTopHPon && (HPHeatingATESColdDeposit == 1 || HPHeatingAEColdRelease == 1 || HPCoolingAEHotRelease == 1 || HPDirectHeatingCooling == 1 || HPActiveColdDeposit == 1) && TempHPcondenser < TempHPcondenserHot && TempHPevaporator > TempHPevaporatorCold ) { HPPumps = 1; } //HP Pumps OFF if ( StorageHotBottom > StorageHotBottomHPoff || StorageColdBottom < StorageColdBottomHPoff || TempHPcondenser > TempHPcondenserHot || TempHPevaporator < TempHPevaporatorCold ) { HPPumps = 0; } //ATES Pump if ( HPHeatingATESColdDeposit == 1 || AEColdDeposit == 1 || HPActiveColdDeposit == 1 ) { ATESPump = 1; } else { ATESPump = 0; } //ATES Load and Unload Valves if ( HPHeatingATESColdDeposit == 1 || AEColdDeposit == 1 || HPActiveColdDeposit == 1 ) { ATESLoadUnloadValves = 1; } else { if ( ATESCoolingColdWithdraw == 1 || ATESHeatingCoolingColdWithdraw == 1 || AEColdWithdraw == 1 ) { ATESLoadUnloadValves = -1; } else { ATESLoadUnloadValves = 0; } } //ATES Bypass Valve if ( ATESLoadUnloadValves == -1 ) { ATESBypassValve = 0; } else { ATESBypassValve = 1; } //ATES Soil Volume Flow if ( HPHeatingATESColdDeposit == 1 || AEColdDeposit == 1 || HPActiveColdDeposit == 1 ) { ATESSoilVolumeFlow = ATESSoilVolumeFlowColdDeposit; } else { if ( ATESCoolingColdWithdraw == 1 || ATESHeatingCoolingColdWithdraw == 1 || AEColdWithdraw == 1 ) { ATESSoilVolumeFlow = -ATESSoilVolumeFlowColdWithdraw; } else { ATESSoilVolumeFlow = 0; } } //Ambient Exchange Cold Release ON if ( StorageColdMiddle < StorageColdMiddleAEColdReleaseOn && HPHeatingAEColdRelease == 1 ) { AEColdRelease = 1; } //Ambient Exchange Cold Release OFF if ( StorageColdTop > StorageColdTopAEColdReleaseOff || HPHeatingAEColdRelease == 0 ) { AEColdRelease = 0; } //Ambient Exchange Hot Release ON if ( StorageHotMiddle > StorageHotMiddleAEHotReleaseOn && (HPCoolingAEHotRelease == 1 || HPActiveColdDeposit == 1) ) { AEHotRelease = 1; } //Ambient Exchange Hot Release OFF if ( StorageHotTop < StorageHotTopAEHotReleaseOff || (HPCoolingAEHotRelease == 0 && HPActiveColdDeposit == 0) ) { AEHotRelease = 0; } //Ambient Exchange Cold Supply if ( AEColdSupply == 1 ) { AEColdSupply = 1; } else { AEColdSupply = 0; } //Ambient Exchange Cold Deposit if ( AEColdDeposit == 1 ) { AEColdDeposit = 1; } else { AEColdDeposit = 0; } //Ambient Exchange Cold Withdraw if ( AEColdWithdraw == 1 ) { AEColdWithdraw = 1; } else { AEColdWithdraw = 0; } //OUTPUTS //----------------------------------------------------------------------------- out1 = HP; out2 = HPPumps; out3 = ATESPump; out4 = ATESLoadUnloadValves; out5 = ATESBypassValve; out6 = ATESSoilVolumeFlow; out7 = AEColdRelease; out8 = AEHotRelease; out9 = AEColdSupply; out10 = AEColdDeposit; out11 = AEColdWithdraw; out12 = HeatingSP; out13 = CoolingSP; out14 = HPHeatingATESColdDeposit; out15 = HPHeatingAEColdRelease; out16 = ATESCoolingColdWithdraw; out17 = HPCoolingAEHotRelease; out18 = AEColdSupply; out19 = ATESHeatingCoolingColdWithdraw; out20 = HPDirectHeatingCooling; out21 = ATESColdDepositLimitationHeating; out22 = ATESColdDepositLimitationHeatingCooling; out23 = ATESColdWithdrawLimitationCooling; out24 = ATESColdWithdrawLimitationHeatingCooling; out25 = AEColdDeposit; out26 = AEColdWithdraw; out27 = HPActiveColdDeposit; out28 = HeatingDemand; out29 = CoolingDemand; out30 = HeatingDemand + CoolingDemand;