NREL / EnergyPlus

EnergyPlus™ is a whole building energy simulation program that engineers, architects, and researchers use to model both energy consumption and water use in buildings.
https://energyplus.net
Other
1.14k stars 390 forks source link

WaterHeater:Stratified with autosized height: Severe error calculated density of air is negative (v8.7) and hard crash in v9.4 #8412

Open jmarrec opened 3 years ago

jmarrec commented 3 years ago

Issue overview

user reported on unmet hours that he got the following error:

** Severe  ** PsyRhoAirFnPbTdbW: RhoAir (Density of Air) is calculated <= 0 [-9.04677].
**   ~~~   ** pb =[101100.00], tdb=[-312.09], w=[0.0000000].
**   ~~~   **  Routine=CorrectZoneHumRat, During Warmup, Environment=DSDAYTANGIER COOLING 0.4%, at Simulation time=08/21 00:12 - 00:13
**  Fatal  ** Program terminates due to preceding condition.

user supplied the file, which was at E+ 8.7. I updated the file to v9.4 and instead of getting this severe I am getting an actual crash, which isn't something we want to happen, even if it is later found the defect file had problems.

Performing Zone Sizing Simulation
...for Sizing Period: #1 DSDAYTANGIER COOLING 0.4%
Warming up
Warming up
Warming up
Performing Zone Sizing Simulation
...for Sizing Period: #2 DSDAYTANGIER HEATING 99.6%
Calculating System sizing
...for Sizing Period: #1 DSDAYTANGIER COOLING 0.4%
Calculating System sizing
...for Sizing Period: #2 DSDAYTANGIER HEATING 99.6%
Adjusting Air System Sizing
Adjusting Standard 62.1 Ventilation Sizing
Initializing Simulation
double free or corruption (out)
Aborted (core dumped)

Details

Some additional details for this issue (if relevant):

Backtrace

(lldb) bt
* thread #1, name = 'energyplus', stop reason = hit program assert
    frame #0: 0x00007ffff11c7fb7 libc.so.6`__GI_raise(sig=<unavailable>) at raise.c:51
    frame #1: 0x00007ffff11c9921 libc.so.6`__GI_abort at abort.c:79
    frame #2: 0x00007ffff11b948a libc.so.6`__assert_fail_base(fmt="%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion="contains( i )", file="/home/julien/Software/Others/EnergyPlus/third_party/ObjexxFCL/src/ObjexxFCL/Array1.hh", line=1172, function="T& ObjexxFCL::Array1< <template-parameter-1-1> >::operator()(int) [with T = EnergyPlus::WaterThermalTanks::StratifiedNodeData]") at assert.c:92
    frame #3: 0x00007ffff11b9502 libc.so.6`__GI___assert_fail(assertion=<unavailable>, file=<unavailable>, line=<unavailable>, function=<unavailable>) at assert.c:101
  * frame #4: 0x00007ffff4d1a4b1 libenergyplusapi.so.9.4.0`ObjexxFCL::Array1<EnergyPlus::WaterThermalTanks::StratifiedNodeData>::operator(this=0x00005555564ff530, i=0)(int) at Array1.hh:1172
    frame #5: 0x00007ffff4cea195 libenergyplusapi.so.9.4.0`EnergyPlus::WaterThermalTanks::WaterThermalTankData::CalcWaterThermalTankStratified(this=0x00005555564ff100, state=0x00007fffffffbdf0) at WaterThermalTanks.cc:7218
    frame #6: 0x00007ffff4d11882 libenergyplusapi.so.9.4.0`EnergyPlus::WaterThermalTanks::WaterThermalTankData::CalcStandardRatings(this=0x00005555564ff100, state=0x00007fffffffbdf0) at WaterThermalTanks.cc:11451
    frame #7: 0x00007ffff4ce47d4 libenergyplusapi.so.9.4.0`EnergyPlus::WaterThermalTanks::WaterThermalTankData::initialize(this=0x00005555564ff100, state=0x00007fffffffbdf0, FirstHVACIteration=true) at WaterThermalTanks.cc:6183
    frame #8: 0x00007ffff4c8c218 libenergyplusapi.so.9.4.0`EnergyPlus::WaterThermalTanks::WaterThermalTankData::onInitLoopEquip(this=0x00005555564ff100, state=0x00007fffffffbdf0, calledFromLocation=0x0000555555e45098) at WaterThermalTanks.cc:164
    frame #9: 0x00007ffff5ffa702 libenergyplusapi.so.9.4.0`EnergyPlus::DataPlant::CompData::simulate(this=0x0000555555e44f00, state=0x00007fffffffbdf0, FirstHVACIteration=true, InitLoopEquip=0x00007ffff7d6fbdf, GetCompSizFac=true) at Component.cc:119
    frame #10: 0x00007ffff5cf1f1a libenergyplusapi.so.9.4.0`EnergyPlus::PlantManager::InitializeLoops(state=0x00007fffffffbdf0, FirstHVACIteration=true) at PlantManager.cc:2204
    frame #11: 0x00007ffff5cdbd1a libenergyplusapi.so.9.4.0`EnergyPlus::PlantManager::ManagePlantLoops(state=0x00007fffffffbdf0, FirstHVACIteration=true, SimAirLoops=0x00007ffff7d77439, SimZoneEquipment=0x00007ffff7d7743c, SimNonZoneEquipment=0x00007ffff7d7743d, SimPlantLoops=0x00007ffff7d7743b, SimElecCircuits=0x00007ffff7d7743a) at PlantManager.cc:222
    frame #12: 0x00007ffff5827b00 libenergyplusapi.so.9.4.0`EnergyPlus::HVACManager::SimSelectedEquipment(state=0x00007fffffffbdf0, SimAirLoops=0x00007ffff7d77439, SimZoneEquipment=0x00007ffff7d7743c, SimNonZoneEquipment=0x00007ffff7d7743d, SimPlantLoops=0x00007ffff7d7743b, SimElecCircuits=0x00007ffff7d7743a, FirstHVACIteration=0x00007fffffffae2e, LockPlantFlows=false) at HVACManager.cc:1832
    frame #13: 0x00007ffff581d054 libenergyplusapi.so.9.4.0`EnergyPlus::HVACManager::SimHVAC(state=0x00007fffffffbdf0) at HVACManager.cc:842
    frame #14: 0x00007ffff58197f4 libenergyplusapi.so.9.4.0`EnergyPlus::HVACManager::ManageHVAC(state=0x00007fffffffbdf0) at HVACManager.cc:358
    frame #15: 0x00007ffff5a1457a libenergyplusapi.so.9.4.0`EnergyPlus::HeatBalanceAirManager::CalcHeatBalanceAir(state=0x00007fffffffbdf0) at HeatBalanceAirManager.cc:4356
    frame #16: 0x00007ffff59b9f7f libenergyplusapi.so.9.4.0`EnergyPlus::HeatBalanceAirManager::ManageAirHeatBalance(state=0x00007fffffffbdf0) at HeatBalanceAirManager.cc:204
    frame #17: 0x00007ffff3e451ee libenergyplusapi.so.9.4.0`EnergyPlus::HeatBalanceSurfaceManager::ManageSurfaceHeatBalance(state=0x00007fffffffbdf0) at HeatBalanceSurfaceManager.cc:281
    frame #18: 0x00007ffff5a33c72 libenergyplusapi.so.9.4.0`EnergyPlus::HeatBalanceManager::ManageHeatBalance(state=0x00007fffffffbdf0) at HeatBalanceManager.cc:363
    frame #19: 0x00007ffff47f9269 libenergyplusapi.so.9.4.0`EnergyPlus::SimulationManager::SetupSimulation(state=0x00007fffffffbdf0, ErrorsFound=0x00007fffffffbc23) at SimulationManager.cc:2111
    frame #20: 0x00007ffff47ea196 libenergyplusapi.so.9.4.0`EnergyPlus::SimulationManager::ManageSimulation(state=0x00007fffffffbdf0) at SimulationManager.cc:366
    frame #21: 0x00007ffff3a08570 libenergyplusapi.so.9.4.0`RunEnergyPlus(state=0x00007fffffffbdf0, filepath="\xe0\xbd\xff\xff\xff\U0000007f"...) at EnergyPlusPgm.cc:400
    frame #22: 0x00007ffff3a07a17 libenergyplusapi.so.9.4.0`EnergyPlusPgm(state=0x00007fffffffbdf0, filepath="\xe0\xbd\xff\xff\xff\U0000007f"...) at EnergyPlusPgm.cc:224
    frame #23: 0x000055555578ef66 energyplus`main(argc=6, argv=0x00007fffffffccc8) at main.cc:60
    frame #24: 0x00007ffff11aabf7 libc.so.6`__libc_start_main(main=(energyplus`main at main.cc:56), argc=6, argv=0x00007fffffffccc8, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffccb8) at libc-start.c:310
    frame #25: 0x000055555578ec8a energyplus`_start + 42

Checklist

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

jmarrec commented 3 years ago

The problem is that SetupStratifiedNodes is called before Sizing has occurred (eg: SizeTankForSupplySide / SizeTankForDemandSide)

https://github.com/NREL/EnergyPlus/blob/7f35ab639d5a75b6e090a0db19ec83c3f0199025/src/EnergyPlus/WaterThermalTanks.cc#L3196

so since Tank.Height is autosized, you end up with a -9999 lurking in all calcs, which gives bogus results through, and it never initializes the Heater1Node :

https://github.com/NREL/EnergyPlus/blob/7f35ab639d5a75b6e090a0db19ec83c3f0199025/src/EnergyPlus/WaterThermalTanks.cc#L5332-L5338

* thread #1, name = 'energyplus_test', stop reason = breakpoint 4.1
    frame #0: 0x00007ffff4ce9296 libenergyplusapi.so.9.4.0`EnergyPlus::WaterThermalTanks::WaterThermalTankData::SetupStratifiedNodes(this=0x0000555559462e80, state=0x0000555559ee1e60) at WaterThermalTanks.cc:5333
   5330             }
   5331 
   5332             // Assign heater elements to the nodes at the specified heights
-> 5333             if ((this->HeaterHeight1 <= H0) && (this->HeaterHeight1 > H)) {
   5334                 //       sensor node will not get set if user enters 0 for this heater capacity
   5335                 //       (Tank%MaxCapacity > 0.0d0)) THEN
   5336                 this->HeaterNode1 = NodeNum;
(lldb) p this->HeaterHeight1
(Real64) $8 = 1
(lldb) p H0
(Real64) $9 = -99999
(lldb) p H
(Real64) $10 = -83332.5
(lldb) 
mjwitte commented 3 years ago

@nmerket FYI. Any insight to offer @jmarrec ?

nmerket commented 3 years ago

Good sleuthing @jmarrec. Sorry this took so long for me to see. The "obvious" solution is to run SetupStratifiedNodes after sizing. As long as you don't need to call CalcWaterThermalTankStratified during sizing, that should be fine. Otherwise we'll have to come up with some sort of iteration.

jmarrec commented 3 years ago

Thanks @nmerket. I looked into where I could insert that call, but I'm having a hard time finding a right slot.

The Height param is set in SizeTankForSupplySide. That's called in onInitLoopEquip

https://github.com/NREL/EnergyPlus/blob/ad0249bc3ec63e73513039d0ac0e18e22d31649d/src/EnergyPlus/WaterThermalTanks.cc#L158-L185

The thing is, the this->initialize tries to call CalcStandardRatings, which needs the nodes. Even if try to protect against it by adding a this->Height > 0 on https://github.com/NREL/EnergyPlus/blob/ad0249bc3ec63e73513039d0ac0e18e22d31649d/src/EnergyPlus/WaterThermalTanks.cc#L11397,

I still get a crash because it tries to call WaterThermalTankData::CalcWaterThermalTankStratified while Nodes aren't initialized.

I pushed a branch where I added a unit test that exhibits the crash, and a broken WIP of one of my attempt at delaying the call. If you could nudge me in the right direction I'd highly appreciate it. If you think this would take too long, then perhaps I could transfer the pivotal ticket over to you.

https://github.com/NREL/EnergyPlus/compare/8412_Crash_AirDensity_StratifiedTank?expand=1

mjwitte commented 3 years ago

@nmerket Any advice for @jmarrec

I pushed a branch where I added a unit test that exhibits the crash, and a broken WIP of one of my attempt at delaying the call. If you could nudge me in the right direction I'd highly appreciate it. If you think this would take too long, then perhaps I could transfer the pivotal ticket over to you.

nmerket commented 3 years ago

@jmarrec @mjwitte So sorry I dropped this. I'll pull your branch and take a crack at fixing it. Thanks for making the unit test!

Myoldmopar commented 3 years ago

@nmerket I'm going to assign this to you in Pivotal as well so it shows up properly assigned on the iteration calls.