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.06k stars 379 forks source link

Duplicate code calculating surface reference air temperature #8945

Closed matthew-larson closed 2 years ago

matthew-larson commented 2 years ago

Issue overview

The same surface reference air temperature calculation was found to be done in multiple locations (WindowManager.cc, WindowComplexManager.cc, WindowEquivalentLayer.cc, and ZoneTempPredictorCorrector.cc) after the initial calculation in HeatBalanceSurfaceManager.cc. The results from HeatBalanceSurfaceManager.cc (state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) and state.dataHeatBal->SurfTempEffBulkAir(SurfNum)) should be able to be referenced and used in the other locations without having to redo the calculation over again.

        {
            auto const SELECT_CASE_var(state.dataSurface->SurfTAirRef(SurfNum));
            if (SELECT_CASE_var == ZoneMeanAirTemp) {
                state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) = state.dataHeatBalFanSys->MAT(ZoneNum);
                state.dataHeatBal->SurfTempEffBulkAir(SurfNum) = state.dataHeatBalFanSys->MAT(ZoneNum); // for reporting surf adjacent air temp
            } else if (SELECT_CASE_var == AdjacentAirTemp) {
                state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) = state.dataHeatBal->SurfTempEffBulkAir(SurfNum);
            } else if (SELECT_CASE_var == ZoneSupplyAirTemp) {
                // determine ZoneEquipConfigNum for this zone
                int ZoneEquipConfigNum = ZoneNum;
                // check whether this zone is a controlled zone or not
                if (!state.dataHeatBal->Zone(ZoneNum).IsControlled) {
                    ShowFatalError(state,
                                   "Zones must be controlled for Ceiling-Diffuser Convection model. No system serves zone " +
                                       state.dataHeatBal->Zone(ZoneNum).Name);
                    return;
                }
                // determine supply air conditions
                Real64 SumSysMCp = 0.0;
                Real64 SumSysMCpT = 0.0;
                Real64 const CpAir = Psychrometrics::PsyCpAirFnW(state.dataHeatBalFanSys->ZoneAirHumRat(ZoneNum));
                for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(ZoneEquipConfigNum).NumInletNodes; ++NodeNum) {
                    Real64 NodeTemp = state.dataLoopNodes->Node(state.dataZoneEquip->ZoneEquipConfig(ZoneEquipConfigNum).InletNode(NodeNum)).Temp;
                    Real64 MassFlowRate =
                        state.dataLoopNodes->Node(state.dataZoneEquip->ZoneEquipConfig(ZoneEquipConfigNum).InletNode(NodeNum)).MassFlowRate;
                    // Real64 CpAir2 = PsyCpAirFnW(ZoneAirHumRat(ZoneNum), NodeTemp);
                    SumSysMCp += MassFlowRate * CpAir;
                    SumSysMCpT += MassFlowRate * CpAir * NodeTemp;
                }
                // a weighted average of the inlet temperatures.
                if (SumSysMCp > 0.0) {                                                      // protect div by zero
                    state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) = SumSysMCpT / SumSysMCp; // BG changed 02-16-2005 to add index (SurfNum)
                } else {
                    state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) = state.dataHeatBalFanSys->MAT(ZoneNum);
                }
                state.dataHeatBal->SurfTempEffBulkAir(SurfNum) =
                    state.dataHeatBalSurfMgr->RefAirTemp(SurfNum); // for reporting surf adjacent air temp
            } else {
                // currently set to mean air temp but should add error warning here
                state.dataHeatBalSurfMgr->RefAirTemp(SurfNum) = state.dataHeatBalFanSys->MAT(ZoneNum);
                state.dataHeatBal->SurfTempEffBulkAir(SurfNum) = state.dataHeatBalFanSys->MAT(ZoneNum); // for reporting surf adjacent air temp
            }
        }

Details

Some additional details for this issue (if relevant):

Checklist

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

mjwitte commented 2 years ago

There may be a reason for some of these to recalc with updated air temperatures during the system timesteps, just guessing. For sure the blocks of code for this in CalcHeatBalanceInsideSurf2 and CalcHeatBalanceInsideSurf2CTFOnly can be pulled out into a common function.

matthew-larson commented 2 years ago

That was my thought too so I'll double check for necessary recalcs.

amirroth commented 2 years ago

This was put in as part of the EnergyPlus 0.01X project.