From ec5b7f6b7c0183c3e6949ea9cd6694326bd486a6 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Thu, 2 Jan 2025 21:11:33 -0500 Subject: [PATCH 01/15] Unstate some variables --- src/EnergyPlus/WindowManager.cc | 170 +++++++++++++------------------- src/EnergyPlus/WindowManager.hh | 51 +++------- 2 files changed, 83 insertions(+), 138 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 7027514f6ab..144d97642f8 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -371,16 +371,19 @@ namespace Window { BGBlind = false; ExtScreen = false; StormWinConst = false; - wm->lSimpleGlazingSystem = false; - + + bool lSimpleGlazingSystem = false; + Real64 SimpleGlazingSHGC = 0.0; + Real64 SimpleGlazingU = 0.0; + if (mat->group == Material::Group::GlassSimple) { auto const *matWin = dynamic_cast(mat); assert(matWin != nullptr); // what if outside layer is shade, blind, or screen? - wm->lSimpleGlazingSystem = true; - wm->SimpleGlazingSHGC = matWin->SimpleWindowSHGC; - wm->SimpleGlazingU = matWin->SimpleWindowUfactor; + lSimpleGlazingSystem = true; + SimpleGlazingSHGC = matWin->SimpleWindowSHGC; + SimpleGlazingU = matWin->SimpleWindowUfactor; } if (has_prefix(thisConstruct.Name, "BARECONSTRUCTIONWITHSTORMWIN") || has_prefix(thisConstruct.Name, "SHADEDCONSTRUCTIONWITHSTORMWIN")) @@ -482,7 +485,8 @@ namespace Window { lquasi = false; AllGlassIsSpectralAverage = true; - wm->LayerNum = {0}; + + std::array LayerNum = {0}; // Glass layer number // Loop over glass layers in the construction for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { @@ -498,7 +502,7 @@ namespace Window { } } - wm->LayerNum[IGlass - 1] = LayNum; + LayerNum[IGlass - 1] = LayNum; LayPtr = thisConstruct.LayerPoint(LayNum); auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); @@ -540,25 +544,12 @@ namespace Window { ShowContinueError(state, "then make a duplicate material (with new name) if you want to model those windows (and reference the new " "material) using the full spectral data."); - // calc Trans, TransVis, ReflectSolBeamFront, ReflectSolBeamBack, ReflectVisBeamFront, ReflectVisBeamBack - // assuming wlt same as wle - wm->tmpTrans = solarSpectrumAverage(state, t[0]); - wm->tmpReflectSolBeamFront = solarSpectrumAverage(state, rff[0]); - wm->tmpReflectSolBeamBack = solarSpectrumAverage(state, rbb[0]); - - // visible properties - wm->tmpTransVis = visibleSpectrumAverage(state, t[0]); - wm->tmpReflectVisBeamFront = visibleSpectrumAverage(state, rff[0]); - wm->tmpReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); // set this material to average spectral data matGlass->GlassSpectralDataPtr = 0; - matGlass->Trans = wm->tmpTrans; - matGlass->TransVis = wm->tmpTransVis; - matGlass->ReflectSolBeamFront = wm->tmpReflectSolBeamFront; - matGlass->ReflectSolBeamBack = wm->tmpReflectSolBeamBack; - matGlass->ReflectVisBeamFront = wm->tmpReflectVisBeamFront; - matGlass->ReflectVisBeamBack = wm->tmpReflectVisBeamBack; + matGlass->Trans = matGlass->TransVis = solarSpectrumAverage(state, t[0]); + matGlass->ReflectSolBeamFront = matGlass->ReflectVisBeamFront = solarSpectrumAverage(state, rff[0]); + matGlass->ReflectSolBeamBack = matGlass->ReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); SpecDataNum = 0; } } @@ -605,23 +596,12 @@ namespace Window { rff[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, 0.0, lam); rbb[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, 0.0, lam); } - wm->tmpTrans = solarSpectrumAverage(state, t[0]); - wm->tmpReflectSolBeamFront = solarSpectrumAverage(state, rff[0]); - wm->tmpReflectSolBeamBack = solarSpectrumAverage(state, rbb[0]); - - // visible properties - wm->tmpTransVis = visibleSpectrumAverage(state, t[0]); - wm->tmpReflectVisBeamFront = visibleSpectrumAverage(state, rff[0]); - wm->tmpReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); - + // set this material to average spectral data matGlass->windowOpticalData = Window::OpticalDataModel::SpectralAverage; - matGlass->Trans = wm->tmpTrans; - matGlass->TransVis = wm->tmpTransVis; - matGlass->ReflectSolBeamFront = wm->tmpReflectSolBeamFront; - matGlass->ReflectSolBeamBack = wm->tmpReflectSolBeamBack; - matGlass->ReflectVisBeamFront = wm->tmpReflectVisBeamFront; - matGlass->ReflectVisBeamBack = wm->tmpReflectVisBeamBack; + matGlass->Trans = matGlass->TransVis = visibleSpectrumAverage(state, t[0]); + matGlass->ReflectSolBeamFront = matGlass->ReflectVisBeamFront = solarSpectrumAverage(state, rff[0]); + matGlass->ReflectSolBeamBack = matGlass->ReflectVisBeamBack = solarSpectrumAverage(state, rbb[0]); SpecDataNum = 0; } } @@ -631,9 +611,9 @@ namespace Window { // Get glass layer properties, then glazing system properties (which include the // effect of inter-reflection among glass layers) at each incidence angle. - // Apparently, using pre-calcaulated and hard-coded cosPhis (e.g., Window::cosPhis) causes a bunch of - // diffs, including some big ones - std::array cosPhisLocal; + // Apparently, using pre-calcaulated and hard-coded cosPhis (e.g., Window::cosPhis) causes a bunch of + // diffs, including some big ones + std::array cosPhisLocal; for (int iPhi = 0; iPhi < numPhis; ++iPhi) cosPhisLocal[iPhi] = std::cos((double)iPhi * dPhiDeg * Constant::DegToRad); @@ -641,7 +621,7 @@ namespace Window { // For each wavelength, get glass layer properties at this angle of incidence // from properties at normal incidence for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - LayPtr = thisConstruct.LayerPoint(wm->LayerNum[IGlass - 1]); + LayPtr = thisConstruct.LayerPoint(LayerNum[IGlass - 1]); auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { @@ -653,9 +633,9 @@ namespace Window { tPhi[IGlass - 1][ILam - 1], rfPhi[IGlass - 1][ILam - 1], rbPhi[IGlass - 1][ILam - 1], - wm->lSimpleGlazingSystem, - wm->SimpleGlazingSHGC, - wm->SimpleGlazingU); + lSimpleGlazingSystem, + SimpleGlazingSHGC, + SimpleGlazingU); } } else { for (int ILam = 1; ILam <= (int)wm->wle.size(); ++ILam) { @@ -769,7 +749,7 @@ namespace Window { //------------------------------------------------------------------------------------------ lquasi = false; - wm->LayerNum = {0}; + LayerNum = {0}; // Glass layer number // Loop over glass layers in the construction. for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { @@ -785,7 +765,7 @@ namespace Window { if (IGlass == 3) LayNum = 1; } } - wm->LayerNum[IGlass - 1] = LayNum; + LayerNum[IGlass - 1] = LayNum; LayPtr = thisConstruct.LayerPoint(LayNum); auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); @@ -837,7 +817,7 @@ namespace Window { // For each wavelength, get glass layer properties at this angle of incidence // from properties at normal incidence for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - LayPtr = thisConstruct.LayerPoint(wm->LayerNum[IGlass - 1]); + LayPtr = thisConstruct.LayerPoint(LayerNum[IGlass - 1]); auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { @@ -850,9 +830,9 @@ namespace Window { tPhi[IGlass - 1][ILam - 1], rfPhi[IGlass - 1][ILam - 1], rbPhi[IGlass - 1][ILam - 1], - wm->lSimpleGlazingSystem, - wm->SimpleGlazingSHGC, - wm->SimpleGlazingU); + lSimpleGlazingSystem, + SimpleGlazingSHGC, + SimpleGlazingU); } } else { @@ -1733,6 +1713,10 @@ namespace Window { // back reflectance at angle of incidence std::array, maxGlassLayers> rbadjPhi = {0.0}; + std::array, maxGlassLayers> top = {0.0}; // Transmittance matrix for subr. op + std::array, maxGlassLayers> rfop = {0.0}; // Front reflectance matrix for subr. op + std::array, maxGlassLayers> rbop = {0.0}; // Back transmittance matrix for subr. op + auto const &wm = state.dataWindowManager; // For each glass layer find tPhi, rfPhi, and rbPhi at each wavelength @@ -1762,20 +1746,20 @@ namespace Window { // Set diagonal of matrix for subroutine SystemPropertiesAtLambdaAndPhi for (int i = 1; i <= ngllayer; ++i) { - wm->top[i - 1][i - 1] = tadjPhi[i - 1][j - 1]; - wm->rfop[i - 1][i - 1] = rfadjPhi[i - 1][j - 1]; - wm->rbop[i - 1][i - 1] = rbadjPhi[i - 1][j - 1]; + top[i - 1][i - 1] = tadjPhi[i - 1][j - 1]; + rfop[i - 1][i - 1] = rfadjPhi[i - 1][j - 1]; + rbop[i - 1][i - 1] = rbadjPhi[i - 1][j - 1]; } // Calculate glazing system properties if (ngllayer == 1) { // Single-layer system - stPhi[j - 1] = wm->top[0][0]; - srfPhi[j - 1] = wm->rfop[0][0]; - srbPhi[j - 1] = wm->rbop[0][0]; + stPhi[j - 1] = top[0][0]; + srfPhi[j - 1] = rfop[0][0]; + srbPhi[j - 1] = rbop[0][0]; sabsPhi(1) = 1.0 - stPhi[j - 1] - srfPhi[j - 1]; } else { // Multilayer system // Get glazing system properties stPhi, etc., at this wavelength and incidence angle - SystemPropertiesAtLambdaAndPhi(state, ngllayer, stPhi[j - 1], srfPhi[j - 1], srbPhi[j - 1], sabsPhi); + SystemPropertiesAtLambdaAndPhi(state, ngllayer, stPhi[j - 1], srfPhi[j - 1], srbPhi[j - 1], top, rfop, rbop, sabsPhi); } for (int i = 1; i <= ngllayer; ++i) { @@ -1792,6 +1776,9 @@ namespace Window { Real64 &tt, // System transmittance Real64 &rft, // System front and back reflectance Real64 &rbt, + std::array, maxGlassLayers> &top, + std::array, maxGlassLayers> &rfop, + std::array, maxGlassLayers> &rbop, Array1A aft // System absorptance of each glass layer ) { @@ -1824,22 +1811,22 @@ namespace Window { // Calculate perimeter elements of rt matrix for (int i = 1; i <= n - 1; ++i) { for (int j = i + 1; j <= n; ++j) { - denom = 1.0 - wm->rfop[j - 1][j - 1] * wm->rbop[i - 1][j - 2]; + denom = 1.0 - rfop[j - 1][j - 1] * rbop[i - 1][j - 2]; if (denom == 0.0) { - wm->top[j - 1][i - 1] = 0.0; - wm->rfop[j - 1][i - 1] = 1.0; - wm->rbop[i - 1][j - 1] = 1.0; + top[j - 1][i - 1] = 0.0; + rfop[j - 1][i - 1] = 1.0; + rbop[i - 1][j - 1] = 1.0; } else { - wm->top[j - 1][i - 1] = wm->top[j - 2][i - 1] * wm->top[j - 1][j - 1] / denom; - wm->rfop[j - 1][i - 1] = wm->rfop[j - 2][i - 1] + pow_2(wm->top[j - 2][i - 1]) * wm->rfop[j - 1][j - 1] / denom; - wm->rbop[i - 1][j - 1] = wm->rbop[j - 1][j - 1] + pow_2(wm->top[j - 1][j - 1]) * wm->rbop[i - 1][j - 2] / denom; + top[j - 1][i - 1] = top[j - 2][i - 1] * top[j - 1][j - 1] / denom; + rfop[j - 1][i - 1] = rfop[j - 2][i - 1] + pow_2(top[j - 2][i - 1]) * rfop[j - 1][j - 1] / denom; + rbop[i - 1][j - 1] = rbop[j - 1][j - 1] + pow_2(top[j - 1][j - 1]) * rbop[i - 1][j - 2] / denom; } } } // System properties: transmittance, front and back reflectance - tt = wm->top[n - 1][0]; - rft = wm->rfop[n - 1][0]; - rbt = wm->rbop[0][n - 1]; + tt = top[n - 1][0]; + rft = rfop[n - 1][0]; + rbt = rbop[0][n - 1]; // Absorptance in each layer for (int j = 1; j <= n; ++j) { @@ -1847,25 +1834,25 @@ namespace Window { t0 = 1.0; rb0 = 0.0; } else { - t0 = wm->top[j - 2][0]; - rb0 = wm->rbop[0][j - 2]; + t0 = top[j - 2][0]; + rb0 = rbop[0][j - 2]; } if (j == n) { rf0 = 0.0; } else { - rf0 = wm->rfop[n - 1][j]; + rf0 = rfop[n - 1][j]; } - af = 1.0 - wm->top[j - 1][j - 1] - wm->rfop[j - 1][j - 1]; - ab = 1.0 - wm->top[j - 1][j - 1] - wm->rbop[j - 1][j - 1]; - denom1 = 1.0 - wm->rfop[n - 1][j - 1] * rb0; - denom2 = 1.0 - wm->rbop[0][j - 1] * rf0; + af = 1.0 - top[j - 1][j - 1] - rfop[j - 1][j - 1]; + ab = 1.0 - top[j - 1][j - 1] - rbop[j - 1][j - 1]; + denom1 = 1.0 - rfop[n - 1][j - 1] * rb0; + denom2 = 1.0 - rbop[0][j - 1] * rf0; if (denom1 == 0.0 || denom2 == 0.0) { aft(j) = 0.0; } else { - aft(j) = (t0 * af) / denom1 + (wm->top[j - 1][0] * rf0 * ab) / denom2; + aft(j) = (t0 * af) / denom1 + (top[j - 1][0] * rf0 * ab) / denom2; } } } // SystemPropertiesAtLambdaAndPhi() @@ -3553,7 +3540,6 @@ namespace Window { Real64 CVGap; // VGap-independent term in pressure balance equation Real64 GapHeightChar; // Characteristic height of the gap air temperature profile (m) Real64 TAve; // Average of TGlass and TShade (K) - // REAL(r64) :: AirProps(8) ! Air properties int TotGaps; // Glass/glass gaps + glass-shade/blind gap Real64 con; // Gap conductivity and derivative Real64 gr; // glass-shade/blind gap Grashof number @@ -3567,10 +3553,6 @@ namespace Window { auto &surf = s_surf->Surface(SurfNum); - // Air properties - // Dens dDens/dT Con dCon/dT Vis dVis/dT Prandtl dPrandtl/dT - // DATA AirProps / 1.29, -0.4d-2, 2.41d-2, 7.6d-5, 1.73d-5, 1.0d-7, 0.72, 1.8d-3 / - ConstrNumSh = s_surf->SurfWinActiveShadedConstruction(SurfNum); ShadeFlag = s_surf->SurfWinShadingFlag(SurfNum); nglassfaces = 2 * state.dataConstruction->Construct(ConstrNumSh).TotGlassLayers; @@ -3630,8 +3612,8 @@ namespace Window { AHolesGap = matShadingDevice->airFlowPermeability * GapHeight * surf.Width; } - RhoAir = wm->AirProps[0] + wm->AirProps[1] * (TGapOld - Constant::Kelvin); - ViscAir = wm->AirProps[4] + wm->AirProps[5] * (TGapOld - Constant::Kelvin); + RhoAir = AirDens + AirDDensDT * (TGapOld - Constant::Kelvin); + ViscAir = AirVis + AirDVisDT * (TGapOld - Constant::Kelvin); // The factor 12 in the next line is based on the solution of steady laminar flow between fixed // parallel plates given in Sec. 6.9.1 of Fundamentals of Fluid Mechanics, Munson/Young/Okishi, Third Edition // Update, John Wiley & Sons, 1998; ISO 15099 has 8 for this factor, which is for flow through a tube. @@ -3655,7 +3637,7 @@ namespace Window { Zinlet = pow_2(AGap / (0.6 * AEqInlet + 0.000001) - 1.0); Zoutlet = pow_2(AGap / (0.6 * AEqOutlet + 0.000001) - 1.0); AVGap = 0.5 * RhoAir * (1 + Zinlet + Zoutlet); - RhoTRef = wm->AirProps[0] * Constant::Kelvin; + RhoTRef = AirDens * Constant::Kelvin; CVGap = RhoTRef * 9.81 * GapHeight * s_surf->Surface(SurfNum).SinTilt * (TGapOld - TGapInlet) / (TGapOld * TGapInlet); // Solution of quadratic equation in VGap @@ -3674,7 +3656,7 @@ namespace Window { // Convective heat flow from gap to room air for interior shade or blind if (ANY_INTERIOR_SHADE_BLIND(ShadeFlag)) { - RhoAir = wm->AirProps[0] + wm->AirProps[1] * (TGapNew - Constant::Kelvin); + RhoAir = AirDens + AirDens * (TGapNew - Constant::Kelvin); QConvGap = RhoAir * AGap * VGap * 1008.0 * (TGapOutlet - TGapInlet); // Exclude convection to gap due to divider, if present; divider convection handled // separately in CalcWinFrameAndDividerTemps @@ -3928,16 +3910,11 @@ namespace Window { // is in horizontal plane normal to window. Real64 GapHeightChar; // Characteristic height of the airflow gap air temperature profile (m) Real64 TAve; // Average of TGlassFace1 and TGlassFace2 (K) - // REAL(r64) :: AirProps(8) ! Air properties Real64 con; // Gap conductivity and derivative Real64 gr; // Gap air Grashof number Real64 pr; // Gap air Prandtl number Real64 nu; // Gap air Nusselt number - // Air properties - // Dens dDens/dT Con dCon/dT Vis dVis/dT Prandtl dPrandtl/dT - // DATA AirProps / 1.29, -0.4d-2, 2.41d-2, 7.6d-5, 1.73d-5, 1.0d-7, 0.72, 1.8d-3 / - auto &s_mat = state.dataMaterial; auto &s_surf = state.dataSurface; auto const &wm = state.dataWindowManager; @@ -3972,7 +3949,7 @@ namespace Window { AGap = GapDepth * surf.Width; VGap = s_surf->SurfWinAirflowThisTS(SurfNum) / GapDepth; hcv = 2.0 * hGapStill + 4.0 * VGap; - RhoAir = wm->AirProps[0] + wm->AirProps[1] * (TGapOld - Constant::Kelvin); + RhoAir = AirDens + AirDDensDT * (TGapOld - Constant::Kelvin); GapHeightChar = RhoAir * 1008.0 * GapDepth * VGap / (2.0 * hcv); // The following avoids divide by zero and exponential underflow if (GapHeightChar == 0.0) { @@ -3984,7 +3961,7 @@ namespace Window { } TGapNew = TAve - (GapHeightChar / GapHeight) * (TGapOutlet - TGapInlet); // Convective heat flow from gap [W] - RhoAir = wm->AirProps[0] + wm->AirProps[1] * (TGapNew - Constant::Kelvin); + RhoAir = AirDens + AirDDensDT * (TGapNew - Constant::Kelvin); QConvGap = RhoAir * AGap * VGap * 1008.0 * (TGapOutlet - TGapInlet); } // BetweenGlassForcedFlow() @@ -4050,15 +4027,10 @@ namespace Window { Real64 nu; // Gap air Nusselt number WinShadingType ShadeFlag; // Shading flag int IGapInc; // Gap increment; =0, double glass, =1, triple glass - // REAL(r64) :: AirProps(8) ! Air properties auto &s_surf = state.dataSurface; auto const &wm = state.dataWindowManager; - // Air properties - // Dens dDens/dT Con dCon/dT Vis dVis/dT Prandtl dPrandtl/dT - // DATA AirProps / 1.29, -0.4d-2, 2.41d-2, 7.6d-5, 1.73d-5, 1.0d-7, 0.72, 1.8d-3 / - ConstrNumSh = s_surf->Surface(SurfNum).activeShadedConstruction; ShadeFlag = s_surf->SurfWinShadingFlag(SurfNum); @@ -4101,7 +4073,7 @@ namespace Window { hGapStill(IGap) = con / wm->gaps[IGap + IGapInc - 1].width * nu; // Shade/blind or glass surface to air convection coefficient hcv(IGap) = 2.0 * hGapStill(IGap) + 4.0 * VGap; - RhoAir(IGap) = wm->AirProps[0] + wm->AirProps[1] * (TGapOld(IGap) - Constant::Kelvin); + RhoAir(IGap) = AirDens + AirDDensDT * (TGapOld(IGap) - Constant::Kelvin); hcv(IGap) = 2.0 * hGapStill(IGap) + 4.0 * VGap; GapHeightChar(IGap) = RhoAir(IGap) * 1008.0 * GapDepth * VGap / (2.0 * hcv(IGap)); // The following avoids divide by zero and exponential underflow @@ -4114,7 +4086,7 @@ namespace Window { } TGapNew(IGap) = TAve(IGap) - (GapHeightChar(IGap) / GapHeight) * (TGapOutlet(IGap) - TGapInlet); // Convective heat flow from gap [W] - RhoAir(IGap) = wm->AirProps[0] + wm->AirProps[1] * (TGapNew(IGap) - Constant::Kelvin); + RhoAir(IGap) = AirDens + AirDDensDT * (TGapNew(IGap) - Constant::Kelvin); QConvGap(IGap) = RhoAir(IGap) * AGap * VGap * 1008.0 * (TGapOutlet(IGap) - TGapInlet); } diff --git a/src/EnergyPlus/WindowManager.hh b/src/EnergyPlus/WindowManager.hh index 988f50a4865..0e9f40ed94f 100644 --- a/src/EnergyPlus/WindowManager.hh +++ b/src/EnergyPlus/WindowManager.hh @@ -69,6 +69,15 @@ struct EnergyPlusData; namespace Window { + Real64 constexpr AirDens = 1.29; + Real64 constexpr AirDDensDT = - 0.4e-2; + Real64 constexpr AirCon = 2.41e-2; + Real64 constexpr AirDConDT = 7.6e-5; + Real64 constexpr AirVis = 1.73e-5; + Real64 constexpr AirDVisDT = 1.0e-7; + Real64 constexpr AirPrandtl = 0.72; + Real64 constexpr AirDPrandtlDT = 1.8e-3; + int constexpr nume = 107; // Number of wavelength values in solar spectrum int constexpr numt3 = 81; // Number of wavelength values in the photopic response @@ -120,6 +129,9 @@ namespace Window { Real64 &tt, // System transmittance Real64 &rft, // System front and back reflectance Real64 &rbt, + std::array, maxGlassLayers> &top, + std::array, maxGlassLayers> &rfop, + std::array, maxGlassLayers> &rbop, Array1A aft // System absorptance of each glass layer ); @@ -415,10 +427,6 @@ namespace Window { struct WindowManagerData : BaseGlobalStruct { - - // Dens dDens/dT Con dCon/dT Vis dVis/dT Prandtl dPrandtl/dT - std::array const AirProps = {1.29, -0.4e-2, 2.41e-2, 7.6e-5, 1.73e-5, 1.0e-7, 0.72, 1.8e-3}; - // Air mass 1.5 terrestrial solar global spectral irradiance (W/m2-micron) // on a 37 degree tilted surface; corresponds // to wavelengths (microns) in following data block (ISO 9845-1 and ASTM E 892; @@ -503,33 +511,16 @@ struct WindowManagerData : BaseGlobalStruct Real64 A67 = 0.0; // TEMP MOVED FROM DataHeatBalance.hh -BLB - - // for each wavelenth in wle - std::array, Window::maxGlassLayers> top = {0.0}; // Transmittance matrix for subr. op - std::array, Window::maxGlassLayers> rfop = {0.0}; // Front reflectance matrix for subr. op - std::array, Window::maxGlassLayers> rbop = {0.0}; // Back transmittance matrix for subr. op - std::unique_ptr inExtWindowModel; // Information about windows model (interior or exterior) std::unique_ptr winOpticalModel; // Information about windows optical model (Simplified or BSDF) bool RunMeOnceFlag = false; - bool lSimpleGlazingSystem = false; // true if using simple glazing system block model bool BGFlag = false; // True if between-glass shade or blind bool locTCFlag = false; // True if this surface is a TC window bool DoReport = false; bool HasWindows = false; bool HasComplexWindows = false; bool HasEQLWindows = false; // equivalent layer window defined - Real64 SimpleGlazingSHGC = 0.0; // value of SHGC for simple glazing system block model - Real64 SimpleGlazingU = 0.0; // value of U-factor for simple glazing system block model - Real64 tmpTrans = 0.0; // solar transmittance calculated from spectral data - Real64 tmpTransVis = 0.0; // visible transmittance calculated from spectral data - Real64 tmpReflectSolBeamFront = 0.0; - Real64 tmpReflectSolBeamBack = 0.0; - Real64 tmpReflectVisBeamFront = 0.0; - Real64 tmpReflectVisBeamBack = 0.0; - - std::array LayerNum = {0}; // Glass layer number void init_state([[maybe_unused]] EnergyPlusData &state) override { @@ -569,37 +560,19 @@ struct WindowManagerData : BaseGlobalStruct this->A23 = 0.0; this->A45 = 0.0; this->A67 = 0.0; - this->top = {0.0}; - this->rfop = {0.0}; - this->rbop = {0.0}; Window::CWindowConstructionsSimplified::clearState(); this->RunMeOnceFlag = false; - this->lSimpleGlazingSystem = false; // true if using simple glazing system block model this->BGFlag = false; // True if between-glass shade or blind this->locTCFlag = false; // True if this surface is a TC window this->DoReport = false; this->HasWindows = false; this->HasComplexWindows = false; this->HasEQLWindows = false; // equivalent layer window defined - this->SimpleGlazingSHGC = 0.0; - this->SimpleGlazingU = 0.0; - this->tmpTrans = 0.0; // solar transmittance calculated from spectral data - this->tmpTransVis = 0.0; // visible transmittance calculated from spectral data - this->tmpReflectSolBeamFront = 0.0; - this->tmpReflectSolBeamBack = 0.0; - this->tmpReflectVisBeamFront = 0.0; - this->tmpReflectVisBeamBack = 0.0; } // Default Constructor WindowManagerData() { - SimpleGlazingSHGC = 0.0; - SimpleGlazingU = 0.0; - tmpReflectSolBeamFront = 0.0; - tmpReflectSolBeamBack = 0.0; - tmpReflectVisBeamFront = 0.0; - tmpReflectVisBeamBack = 0.0; } }; From 296003f7adc635876eb6a846a345ff5b7e50f6ab Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Fri, 3 Jan 2025 17:03:52 -0500 Subject: [PATCH 02/15] Move wavelength based calculations to std::array --- src/EnergyPlus/WindowManager.cc | 127 +++++++++++++++++--------------- src/EnergyPlus/WindowManager.hh | 2 +- 2 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 144d97642f8..51a5c3886aa 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -190,17 +190,20 @@ namespace Window { int BlNum; // Blind number auto &wm = state.dataWindowManager; - Array1D sabsPhi(nume); // Glazing system absorptance for a glass layer + std::array sabsPhi; // Glazing system absorptance for a glass layer // and angle of incidence, for each wavelength // glass layer for an angle of incidence, for each wavelength // Glazing system layer solar absorptance for each glass layer Array1D solabsDiff(maxGlassLayers); // Glazing system solar absorptance for a layer at each incidence angle std::array solabsPhiLay; +#ifdef GET_OUT // Glazing system solar transmittance from fit at each incidence angle std::array tsolPhiFit; // Glazing system visible transmittance from fit at each incidence angle std::array tvisPhiFit; +#endif // GET_OUT + // Isolated glass solar transmittance for each incidence angle Array1D> tBareSolPhi(maxGlassLayers); Real64 t1; // = tBareSolPhi(,1)(,2) @@ -589,12 +592,12 @@ namespace Window { "material) using the full spectral data."); // calc Trans, TransVis, ReflectSolBeamFront, ReflectSolBeamBack, ReflectVisBeamFront, ReflectVisBeamBack // assuming wlt same as wle - for (int ILam = 1; ILam <= (int)wm->wle.size(); ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - t[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, 0.0, lam); - rff[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, 0.0, lam); - rbb[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, 0.0, lam); + for (int iLam = 0; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + t[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, 0.0, lam); + rff[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, 0.0, lam); + rbb[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, 0.0, lam); } // set this material to average spectral data @@ -638,12 +641,12 @@ namespace Window { SimpleGlazingU); } } else { - for (int ILam = 1; ILam <= (int)wm->wle.size(); ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - tPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, iPhi * dPhiDeg, lam); + for (int iLam = 0; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + tPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, iPhi * dPhiDeg, lam); } } // For use with between-glass shade/blind, save angular properties of isolated glass @@ -670,7 +673,8 @@ namespace Window { std::array srfPhi = {0.0}; // Glazing system front reflectance at angle of incidence for each wavelength in wle std::array srbPhi = {0.0}; // Glazing system back reflectance at angle of incidence for each wavelength in wle // For each layer, glazing system absorptance at angle of incidence - Array2D saPhi(maxGlassLayers, nume, 0.0); + Array1D> saPhi(maxGlassLayers); + for (int IGlass = 1; IGlass <= maxGlassLayers; ++IGlass) std::fill(saPhi(IGlass).begin(), saPhi(IGlass).end(), 0.0); SystemSpectralPropertiesAtPhi(state, 1, NGlass, 0.0, 2.54, numpt, wlt, tPhi, rfPhi, rbPhi, stPhi, srfPhi, srbPhi, saPhi); @@ -681,8 +685,8 @@ namespace Window { rbsolPhi[iPhi] = solarSpectrumAverage(state, srbPhi); for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - for (int ILam = 1; ILam <= nume; ++ILam) { - sabsPhi(ILam) = saPhi(IGlass, ILam); + for (int iLam = 0; iLam < nume; ++iLam) { + sabsPhi[iLam] = saPhi(IGlass)[iLam]; } solabsPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); } @@ -803,7 +807,7 @@ namespace Window { // Using SpectralAndAngle here } else { - numptDAT = wm->wle.size(); + numptDAT = nume; numpt[IGlass - 1] = numptDAT; } } // End of loop over glass layers in the construction for back calculation @@ -836,12 +840,12 @@ namespace Window { } } else { - for (int ILam = 1; ILam <= (int)wm->wle.size(); ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - tPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][ILam - 1] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, iPhi * dPhiDeg, lam); + for (int iLam = 0; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + tPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngTransDataPtr, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngFRefleDataPtr, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][iLam] = Curve::CurveValue(state, matGlass->GlassSpecAngBRefleDataPtr, iPhi * dPhiDeg, lam); } } } @@ -852,7 +856,8 @@ namespace Window { std::array srfPhi = {0.0}; // Glazing system front reflectance at angle of incidence for each wavelength in wle std::array srbPhi = {0.0}; // Glazing system back reflectance at angle of incidence for each wavelength in wle // For each layer, glazing system absorptance at angle of incidence - Array2D saPhi(maxGlassLayers, nume, 0.0); + Array1D> saPhi(maxGlassLayers); + for (int iGlass = 1; iGlass <= maxGlassLayers; ++iGlass) std::fill(saPhi(iGlass).begin(), saPhi(iGlass).end(), 0.0); SystemSpectralPropertiesAtPhi(state, 1, NGlass, 0.0, 2.54, numpt, wlt, tPhi, rfPhi, rbPhi, stPhi, srfPhi, srbPhi, saPhi); @@ -860,8 +865,8 @@ namespace Window { // For now it is assumed that the exterior and interior irradiance spectra are the same. for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - for (int j = 1; j <= nume; ++j) { - sabsPhi(j) = saPhi(IGlass, j); + for (int j = 0; j < nume; ++j) { + sabsPhi[j] = saPhi(IGlass)[j]; } solabsBackPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); } @@ -1403,6 +1408,7 @@ namespace Window { W5LsqFit(cosPhisLocal, solabsBackPhi(IGlassBack), thisConstruct.AbsBeamBackCoef(IGlass)); } +#ifdef GET_OUT // To check goodness of fit //Tuned for (int iPhi = 0; iPhi < numPhis; ++iPhi) { @@ -1414,6 +1420,7 @@ namespace Window { tvisPhiFit[iPhi] += thisConstruct.TransVisBeamCoef[CoefNum] * cosPhisLocal[iPhi]; } } +#endif // GET_OUT } if (ShadeOn) W5LsqFit(cosPhisLocal, solabsShadePhi, thisConstruct.AbsBeamShadeCoef); @@ -1682,7 +1689,7 @@ namespace Window { std::array &stPhi, std::array &srfPhi, std::array &srbPhi, - Array2D &saPhi) + Array1D> &saPhi) { // SUBROUTINE INFORMATION: @@ -1703,7 +1710,7 @@ namespace Window { // srbPhi back reflectance of system at each wavelength in swl // sabsPhi absorptance by layer at each wavelength in swl - Array1D sabsPhi(5); // System solar absorptance in each glass layer for + Array1D sabsPhi(maxGlassLayers); // System solar absorptance in each glass layer for // particular angle of incidence // transmittance at angle of incidence @@ -1721,49 +1728,49 @@ namespace Window { // For each glass layer find tPhi, rfPhi, and rbPhi at each wavelength for (int in = 1; in <= ngllayer; ++in) { - for (int iwl = 1; iwl <= nume; ++iwl) { - Real64 wl = wm->wle[iwl - 1]; + for (int iwl = 0; iwl < nume; ++iwl) { + Real64 wl = wm->wle[iwl]; if (wl < wlbot || wl > wltop) continue; // In the following numpt is the number of spectral data points for each layer; // numpt = 2 if there is no spectral data for a layer. if (numpt[in - 1] <= 2) { - tadjPhi[in - 1][iwl - 1] = tPhi[in - 1][iquasi - 1]; - rfadjPhi[in - 1][iwl - 1] = rfPhi[in - 1][iquasi - 1]; - rbadjPhi[in - 1][iwl - 1] = rbPhi[in - 1][iquasi - 1]; + tadjPhi[in - 1][iwl] = tPhi[in - 1][iquasi - 1]; + rfadjPhi[in - 1][iwl] = rfPhi[in - 1][iquasi - 1]; + rbadjPhi[in - 1][iwl] = rbPhi[in - 1][iquasi - 1]; } else { // Interpolate to get properties at the solar spectrum wavelengths - tadjPhi[in - 1][iwl - 1] = Interpolate(wlt[in - 1], tPhi[in - 1], numpt[in - 1], wl); - rfadjPhi[in - 1][iwl - 1] = Interpolate(wlt[in - 1], rfPhi[in - 1], numpt[in - 1], wl); - rbadjPhi[in - 1][iwl - 1] = Interpolate(wlt[in - 1], rbPhi[in - 1], numpt[in - 1], wl); + tadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], tPhi[in - 1], numpt[in - 1], wl); + rfadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], rfPhi[in - 1], numpt[in - 1], wl); + rbadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], rbPhi[in - 1], numpt[in - 1], wl); } } } // Calculate system properties at each wavelength - for (int j = 1; j <= nume; ++j) { - Real64 wl = wm->wle[j - 1]; + for (int j = 0; j < nume; ++j) { + Real64 wl = wm->wle[j]; if (wl < wlbot || wl > wltop) continue; // Set diagonal of matrix for subroutine SystemPropertiesAtLambdaAndPhi for (int i = 1; i <= ngllayer; ++i) { top[i - 1][i - 1] = tadjPhi[i - 1][j - 1]; - rfop[i - 1][i - 1] = rfadjPhi[i - 1][j - 1]; - rbop[i - 1][i - 1] = rbadjPhi[i - 1][j - 1]; + rfop[i - 1][i - 1] = rfadjPhi[i - 1][j]; + rbop[i - 1][i - 1] = rbadjPhi[i - 1][j]; } // Calculate glazing system properties if (ngllayer == 1) { // Single-layer system - stPhi[j - 1] = top[0][0]; - srfPhi[j - 1] = rfop[0][0]; - srbPhi[j - 1] = rbop[0][0]; - sabsPhi(1) = 1.0 - stPhi[j - 1] - srfPhi[j - 1]; + stPhi[j] = top[0][0]; + srfPhi[j] = rfop[0][0]; + srbPhi[j] = rbop[0][0]; + sabsPhi(1) = 1.0 - stPhi[j] - srfPhi[j]; } else { // Multilayer system // Get glazing system properties stPhi, etc., at this wavelength and incidence angle - SystemPropertiesAtLambdaAndPhi(state, ngllayer, stPhi[j - 1], srfPhi[j - 1], srbPhi[j - 1], top, rfop, rbop, sabsPhi); + SystemPropertiesAtLambdaAndPhi(state, ngllayer, stPhi[j], srfPhi[j], srbPhi[j], top, rfop, rbop, sabsPhi); } for (int i = 1; i <= ngllayer; ++i) { - saPhi(i, j) = sabsPhi(i); + saPhi(i)[j] = sabsPhi(i); } } // End of wavelength loop @@ -1863,9 +1870,9 @@ namespace Window { Real64 denom = 0.0; auto const &wm = state.dataWindowManager; - for (int i = 1; i <= nume - 1; ++i) { - Real64 const esol = (wm->wle[i] - wm->wle[i - 1]) * 0.5 * (wm->e[i - 1] + wm->e[i]); - num += 0.5 * (p[i - 1] + p[i]) * esol; + for (int i = 0; i < nume - 1; ++i) { + Real64 const esol = (wm->wle[i+1] - wm->wle[i]) * 0.5 * (wm->e[i] + wm->e[i+1]); + num += 0.5 * (p[i] + p[i+1]) * esol; denom += esol; } return num / denom; // dangerous, doesn't check for zero denominator @@ -1887,13 +1894,13 @@ namespace Window { auto const &wm = state.dataWindowManager; - for (int i = 2; i <= nume; ++i) { // Autodesk:BoundsViolation e|wle|p(i-1) @ i=1: Changed start index from 1 to 2: wle + for (int i = 1; i < nume; ++i) { // Autodesk:BoundsViolation e|wle|p(i-1) @ i=1: Changed start index from 1 to 2: wle // values prevented this violation from occurring in practice // Restrict to visible range - if (wm->wle[i - 1] >= 0.37 && wm->wle[i - 1] <= 0.78) { - y30new = Interpolate(wm->wlt3, wm->y30, numt3, wm->wle[i - 1]); - Real64 evis = wm->e[i - 2] * 0.5 * (y30new + y30ils1) * (wm->wle[i - 1] - wm->wle[i - 2]); - num += 0.5 * (p[i - 1] + p[i - 2]) * evis; + if (wm->wle[i] >= 0.37 && wm->wle[i] <= 0.78) { + y30new = Interpolate(wm->wlt3, wm->y30, numt3, wm->wle[i]); + Real64 evis = wm->e[i - 1] * 0.5 * (y30new + y30ils1) * (wm->wle[i] - wm->wle[i - 1]); + num += 0.5 * (p[i] + p[i - 1]) * evis; denom += evis; y30ils1 = y30new; } @@ -8219,13 +8226,13 @@ namespace Window { ErrorsFound = true; } else { // Step 3 - overwrite default solar spectrum data - for (int iTmp = 1; iTmp <= nume; ++iTmp) { - if (iTmp <= NumNumbers / 2) { - wm->wle[iTmp - 1] = state.dataIPShortCut->rNumericArgs(2 * iTmp - 1); - wm->e[iTmp - 1] = state.dataIPShortCut->rNumericArgs(2 * iTmp); + for (int iTmp = 0; iTmp < nume; ++iTmp) { + if (iTmp < NumNumbers / 2) { + wm->wle[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp); + wm->e[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp + 1); } else { - wm->wle[iTmp - 1] = 0.0; - wm->e[iTmp - 1] = 0.0; + wm->wle[iTmp] = 0.0; + wm->e[iTmp] = 0.0; } } } diff --git a/src/EnergyPlus/WindowManager.hh b/src/EnergyPlus/WindowManager.hh index 0e9f40ed94f..4e290a13d13 100644 --- a/src/EnergyPlus/WindowManager.hh +++ b/src/EnergyPlus/WindowManager.hh @@ -122,7 +122,7 @@ namespace Window { std::array &stPhi, std::array &srfPhi, std::array &srbPhi, - Array2D &saPhi); + Array1D> &saPhi); void SystemPropertiesAtLambdaAndPhi(EnergyPlusData &state, int n, // Number of glass layers From 211a553ec9fbba061449f7be5294da0248753fbc Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 8 Jan 2025 14:13:31 -0500 Subject: [PATCH 03/15] Wavelength indices --- src/EnergyPlus/WindowManager.cc | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 51a5c3886aa..5b28a440f2a 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -521,13 +521,13 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int ILam = 1; ILam <= numptDAT; ++ILam) { - wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); - t[IGlass - 1][ILam - 1] = specData.Trans(ILam); + for (int iLam = 0; iLam < numptDAT; ++iLam) { + wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); + t[IGlass - 1][iLam] = specData.Trans(iLam+1); if ((IGlass == 1 || (IGlass == 2 && StormWinConst)) && (!wm->BGFlag)) - t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); - rbb[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); + t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][iLam] = specData.ReflFront(iLam+1); + rbb[IGlass - 1][iLam] = specData.ReflBack(iLam+1); } // If there is spectral data for between-glass shades or blinds, calc the average spectral properties for use. @@ -628,14 +628,14 @@ namespace Window { auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { + for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][ILam - 1], - rff[IGlass - 1][ILam - 1], - rbb[IGlass - 1][ILam - 1], - tPhi[IGlass - 1][ILam - 1], - rfPhi[IGlass - 1][ILam - 1], - rbPhi[IGlass - 1][ILam - 1], + t[IGlass - 1][iLam], + rff[IGlass - 1][iLam], + rbb[IGlass - 1][iLam], + tPhi[IGlass - 1][iLam], + rfPhi[IGlass - 1][iLam], + rbPhi[IGlass - 1][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); @@ -784,12 +784,12 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int ILam = 1; ILam <= numptDAT; ++ILam) { - wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); - t[IGlass - 1][ILam - 1] = specData.Trans(ILam); - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); - rbb[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); + for (int iLam = 0; iLam < numptDAT; ++iLam) { + wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); + t[IGlass - 1][iLam] = specData.Trans(iLam+1); + if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][iLam] = specData.ReflBack(iLam+1); + rbb[IGlass - 1][iLam] = specData.ReflFront(iLam+1); } // No spectral data for this layer; use spectral average values @@ -825,15 +825,15 @@ namespace Window { auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { + for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][ILam - 1], - rff[IGlass - 1][ILam - 1], - rbb[IGlass - 1][ILam - 1], - tPhi[IGlass - 1][ILam - 1], - rfPhi[IGlass - 1][ILam - 1], - rbPhi[IGlass - 1][ILam - 1], + t[IGlass - 1][iLam], + rff[IGlass - 1][iLam], + rbb[IGlass - 1][iLam], + tPhi[IGlass - 1][iLam], + rfPhi[IGlass - 1][iLam], + rbPhi[IGlass - 1][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); From c372bf633db849d39120832939e4bf909d17e1a4 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Mon, 23 Feb 2026 19:18:33 -0500 Subject: [PATCH 04/15] Fix some indexing issues --- src/EnergyPlus/WindowManager.cc | 116 +++++++++++++++++--------------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 7008584c141..2d8beddcce9 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -552,13 +552,13 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int iLam = 0; iLam < numptDAT; ++iLam) { - wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); - t[IGlass - 1][iLam] = specData.Trans(iLam+1); + for (int ILam = 1; ILam <= numptDAT; ++ILam) { + wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); + t[IGlass - 1][ILam - 1] = specData.Trans(ILam); if ((IGlass == 1 || (IGlass == 2 && StormWinConst)) && (!wm->BGFlag)) - t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][iLam] = specData.ReflFront(iLam+1); - rbb[IGlass - 1][iLam] = specData.ReflBack(iLam+1); + t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); + rbb[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); } // If there is spectral data for between-glass shades or blinds, calc the average spectral properties for use. @@ -581,9 +581,12 @@ namespace Window { // set this material to average spectral data matGlass->GlassSpectralDataPtr = 0; - matGlass->Trans = matGlass->TransVis = solarSpectrumAverage(state, t[0]); - matGlass->ReflectSolBeamFront = matGlass->ReflectVisBeamFront = solarSpectrumAverage(state, rff[0]); - matGlass->ReflectSolBeamBack = matGlass->ReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); + matGlass->Trans = solarSpectrumAverage(state, t[0]); + matGlass->TransVis = visibleSpectrumAverage(state, t[0]); + matGlass->ReflectSolBeamFront = solarSpectrumAverage(state, rff[0]); + matGlass->ReflectSolBeamBack = solarSpectrumAverage(state, rbb[0]); + matGlass->ReflectVisBeamFront = visibleSpectrumAverage(state, rff[0]); + matGlass->ReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); SpecDataNum = 0; } } @@ -630,19 +633,22 @@ namespace Window { // calc Trans, TransVis, ReflectSolBeamFront, ReflectSolBeamBack, ReflectVisBeamFront, ReflectVisBeamBack // assuming wlt same as wle - for (int iLam = 0; iLam < nume; ++iLam) { - Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - t[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); - rff[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); - rbb[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); + for (int ILam = 1; ILam <= nume; ++ILam) { + Real64 lam = wm->wle[ILam - 1]; + wlt[IGlass - 1][ILam - 1] = lam; + t[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); + rff[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); + rbb[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); } // set this material to average spectral data matGlass->windowOpticalData = Window::OpticalDataModel::SpectralAverage; - matGlass->Trans = matGlass->TransVis = visibleSpectrumAverage(state, t[0]); - matGlass->ReflectSolBeamFront = matGlass->ReflectVisBeamFront = solarSpectrumAverage(state, rff[0]); - matGlass->ReflectSolBeamBack = matGlass->ReflectVisBeamBack = solarSpectrumAverage(state, rbb[0]); + matGlass->Trans = solarSpectrumAverage(state, t[0]); + matGlass->TransVis = visibleSpectrumAverage(state, t[0]); + matGlass->ReflectSolBeamFront = solarSpectrumAverage(state, rff[0]); + matGlass->ReflectSolBeamBack = solarSpectrumAverage(state, rbb[0]); + matGlass->ReflectVisBeamFront = visibleSpectrumAverage(state, rff[0]); + matGlass->ReflectVisBeamBack = visibleSpectrumAverage(state, rbb[0]); SpecDataNum = 0; } } @@ -668,26 +674,26 @@ namespace Window { auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { + for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][iLam], - rff[IGlass - 1][iLam], - rbb[IGlass - 1][iLam], - tPhi[IGlass - 1][iLam], - rfPhi[IGlass - 1][iLam], - rbPhi[IGlass - 1][iLam], + t[IGlass - 1][ILam - 1], + rff[IGlass - 1][ILam - 1], + rbb[IGlass - 1][ILam - 1], + tPhi[IGlass - 1][ILam - 1], + rfPhi[IGlass - 1][ILam - 1], + rbPhi[IGlass - 1][ILam - 1], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); } } else { - for (int iLam = 0; iLam < nume; ++iLam) { - Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + for (int ILam = 1; ILam <= nume; ++ILam) { + Real64 lam = wm->wle[ILam - 1]; + wlt[IGlass - 1][ILam - 1] = lam; + tPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } // For use with between-glass shade/blind, save angular properties of isolated glass @@ -726,8 +732,8 @@ namespace Window { rbsolPhi[iPhi] = solarSpectrumAverage(state, srbPhi); for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - for (int iLam = 0; iLam < nume; ++iLam) { - sabsPhi[iLam] = saPhi(IGlass)[iLam]; + for (int ILam = 1; ILam <= nume; ++ILam) { + sabsPhi[ILam - 1] = saPhi(IGlass)[ILam - 1]; } solabsPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); } @@ -839,12 +845,12 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int iLam = 0; iLam < numptDAT; ++iLam) { - wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); - t[IGlass - 1][iLam] = specData.Trans(iLam+1); - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][iLam] = specData.ReflBack(iLam+1); - rbb[IGlass - 1][iLam] = specData.ReflFront(iLam+1); + for (int ILam = 1; ILam <= numptDAT; ++ILam) { + wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); + t[IGlass - 1][ILam - 1] = specData.Trans(ILam); + if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); + rbb[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); } // No spectral data for this layer; use spectral average values @@ -894,15 +900,15 @@ namespace Window { auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { + for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][iLam], - rff[IGlass - 1][iLam], - rbb[IGlass - 1][iLam], - tPhi[IGlass - 1][iLam], - rfPhi[IGlass - 1][iLam], - rbPhi[IGlass - 1][iLam], + t[IGlass - 1][ILam - 1], + rff[IGlass - 1][ILam - 1], + rbb[IGlass - 1][ILam - 1], + tPhi[IGlass - 1][ILam - 1], + rfPhi[IGlass - 1][ILam - 1], + rbPhi[IGlass - 1][ILam - 1], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); @@ -910,12 +916,12 @@ namespace Window { } else { - for (int iLam = 0; iLam < nume; ++iLam) { - Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + for (int ILam = 1; ILam <= nume; ++ILam) { + Real64 lam = wm->wle[ILam - 1]; + wlt[IGlass - 1][ILam - 1] = lam; + tPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } } @@ -1870,7 +1876,7 @@ namespace Window { // Set diagonal of matrix for subroutine SystemPropertiesAtLambdaAndPhi for (int i = 1; i <= ngllayer; ++i) { - top[i - 1][i - 1] = tadjPhi[i - 1][j - 1]; + top[i - 1][i - 1] = tadjPhi[i - 1][j]; rfop[i - 1][i - 1] = rfadjPhi[i - 1][j]; rbop[i - 1][i - 1] = rbadjPhi[i - 1][j]; } @@ -8471,8 +8477,8 @@ namespace Window { // Step 3 - overwrite default solar spectrum data for (int iTmp = 0; iTmp < nume; ++iTmp) { if (iTmp < NumNumbers / 2) { - wm->wle[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp); - wm->e[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp + 1); + wm->wle[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp + 1); + wm->e[iTmp] = state.dataIPShortCut->rNumericArgs(2 * iTmp + 2); } else { wm->wle[iTmp] = 0.0; wm->e[iTmp] = 0.0; From 5ee544bda27490743b8b44cb454ae44eccd8593c Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Tue, 24 Feb 2026 19:26:27 -0500 Subject: [PATCH 05/15] Fix AirDDensDT issue --- src/EnergyPlus/WindowManager.cc | 94 ++++++++++++++++----------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 2d8beddcce9..9ac13db5689 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -552,13 +552,13 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int ILam = 1; ILam <= numptDAT; ++ILam) { - wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); - t[IGlass - 1][ILam - 1] = specData.Trans(ILam); + for (int iLam = 0; iLam < numptDAT; ++iLam) { + wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); + t[IGlass - 1][iLam] = specData.Trans(iLam+1); if ((IGlass == 1 || (IGlass == 2 && StormWinConst)) && (!wm->BGFlag)) - t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); - rbb[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); + t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][iLam] = specData.ReflFront(iLam+1); + rbb[IGlass - 1][iLam] = specData.ReflBack(iLam+1); } // If there is spectral data for between-glass shades or blinds, calc the average spectral properties for use. @@ -633,12 +633,12 @@ namespace Window { // calc Trans, TransVis, ReflectSolBeamFront, ReflectSolBeamBack, ReflectVisBeamFront, ReflectVisBeamBack // assuming wlt same as wle - for (int ILam = 1; ILam <= nume; ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - t[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); - rff[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); - rbb[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); + for (int iLam = 0; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + t[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); + rff[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); + rbb[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); } // set this material to average spectral data @@ -674,26 +674,26 @@ namespace Window { auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { + for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][ILam - 1], - rff[IGlass - 1][ILam - 1], - rbb[IGlass - 1][ILam - 1], - tPhi[IGlass - 1][ILam - 1], - rfPhi[IGlass - 1][ILam - 1], - rbPhi[IGlass - 1][ILam - 1], + t[IGlass - 1][iLam], + rff[IGlass - 1][iLam], + rbb[IGlass - 1][iLam], + tPhi[IGlass - 1][iLam], + rfPhi[IGlass - 1][iLam], + rbPhi[IGlass - 1][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); } } else { - for (int ILam = 1; ILam <= nume; ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - tPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + for (int iLam = 0; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } // For use with between-glass shade/blind, save angular properties of isolated glass @@ -732,8 +732,8 @@ namespace Window { rbsolPhi[iPhi] = solarSpectrumAverage(state, srbPhi); for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - for (int ILam = 1; ILam <= nume; ++ILam) { - sabsPhi[ILam - 1] = saPhi(IGlass)[ILam - 1]; + for (int iLam = 0; iLam < nume; ++iLam) { + sabsPhi[iLam] = saPhi(IGlass)[iLam]; } solabsPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); } @@ -845,12 +845,12 @@ namespace Window { numptDAT = specData.NumOfWavelengths; numpt[IGlass - 1] = numptDAT; - for (int ILam = 1; ILam <= numptDAT; ++ILam) { - wlt[IGlass - 1][ILam - 1] = specData.WaveLength(ILam); - t[IGlass - 1][ILam - 1] = specData.Trans(ILam); - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][ILam - 1] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][ILam - 1] = specData.ReflBack(ILam); - rbb[IGlass - 1][ILam - 1] = specData.ReflFront(ILam); + for (int iLam = 0; iLam < numptDAT; ++iLam) { + wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); + t[IGlass - 1][iLam] = specData.Trans(iLam+1); + if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; + rff[IGlass - 1][iLam] = specData.ReflBack(iLam+1); + rbb[IGlass - 1][iLam] = specData.ReflFront(iLam+1); } // No spectral data for this layer; use spectral average values @@ -900,15 +900,15 @@ namespace Window { auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int ILam = 1; ILam <= numpt[IGlass - 1]; ++ILam) { + for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][ILam - 1], - rff[IGlass - 1][ILam - 1], - rbb[IGlass - 1][ILam - 1], - tPhi[IGlass - 1][ILam - 1], - rfPhi[IGlass - 1][ILam - 1], - rbPhi[IGlass - 1][ILam - 1], + t[IGlass - 1][iLam], + rff[IGlass - 1][iLam], + rbb[IGlass - 1][iLam], + tPhi[IGlass - 1][iLam], + rfPhi[IGlass - 1][iLam], + rbPhi[IGlass - 1][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); @@ -916,12 +916,12 @@ namespace Window { } else { - for (int ILam = 1; ILam <= nume; ++ILam) { - Real64 lam = wm->wle[ILam - 1]; - wlt[IGlass - 1][ILam - 1] = lam; - tPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][ILam - 1] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + for (int iLam = 1; iLam < nume; ++iLam) { + Real64 lam = wm->wle[iLam]; + wlt[IGlass - 1][iLam] = lam; + tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } } @@ -3804,7 +3804,7 @@ namespace Window { // Convective heat flow from gap to room air for interior shade or blind if (ANY_INTERIOR_SHADE_BLIND(ShadeFlag)) { - RhoAir = AirDens + AirDens * (TGapNew - Constant::Kelvin); + RhoAir = AirDens + AirDDensDT * (TGapNew - Constant::Kelvin); QConvGap = RhoAir * AGap * VGap * 1008.0 * (TGapOutlet - TGapInlet); // Exclude convection to gap due to divider, if present; divider convection handled // separately in CalcWinFrameAndDividerTemps From 714f6d1d2644c79f1f200c3f459ee85d1457e504 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Tue, 24 Feb 2026 20:02:14 -0500 Subject: [PATCH 06/15] Move maxGlassLayers arrays from Array1D to std::array --- src/EnergyPlus/WindowManager.cc | 299 ++++++++++++++++---------------- 1 file changed, 150 insertions(+), 149 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 9ac13db5689..8ddd4286e3f 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -194,7 +194,7 @@ namespace Window { // and angle of incidence, for each wavelength // glass layer for an angle of incidence, for each wavelength // Glazing system layer solar absorptance for each glass layer - Array1D solabsDiff(maxGlassLayers); + std::array solabsDiff; // Glazing system solar absorptance for a layer at each incidence angle std::array solabsPhiLay; #ifdef GET_OUT @@ -205,32 +205,32 @@ namespace Window { #endif // GET_OUT // Isolated glass solar transmittance for each incidence angle - Array1D> tBareSolPhi(maxGlassLayers); + std::array, maxGlassLayers> tBareSolPhi; Real64 t1; // = tBareSolPhi(,1)(,2) Real64 t2; // Isolated glass visible transmittance for each incidence angle - Array1D> tBareVisPhi(maxGlassLayers); + std::array, maxGlassLayers> tBareVisPhi; Real64 t1v; // = tBareVisPhi(,1)(,2) Real64 t2v; // Isolated glass front solar reflectance for each incidence angle - Array1D> rfBareSolPhi(maxGlassLayers); + std::array, maxGlassLayers> rfBareSolPhi; // Isolated glass front visible reflectance for each incidence angle - Array1D> rfBareVisPhi(maxGlassLayers); + std::array, maxGlassLayers> rfBareVisPhi; // Isolated glass back solar reflectance for each incidence angle - Array1D> rbBareSolPhi(maxGlassLayers); + std::array, maxGlassLayers> rbBareSolPhi; // Isolated glass back visible reflectance for each incidence angle - Array1D> rbBareVisPhi(maxGlassLayers); + std::array, maxGlassLayers> rbBareVisPhi; // Isolated glass front solar absorptance for each incidence angle - Array1D> afBareSolPhi(maxGlassLayers); + std::array, maxGlassLayers> afBareSolPhi; Real64 af1; // = afBareSolPhi(,1)(,2) Real64 af2; Real64 rbmf2; // Isolated glass #2 front beam reflectance // Isolated glass back solar absorptance for each incidence angle - Array1D> abBareSolPhi(maxGlassLayers); + std::array, maxGlassLayers> abBareSolPhi; // Glazing system solar absorptance for each angle of incidence - Array1D> solabsPhi(maxGlassLayers); + std::array, maxGlassLayers> solabsPhi; // Glazing system back solar absorptance for each angle of incidence - Array1D> solabsBackPhi(maxGlassLayers); + std::array, maxGlassLayers> solabsBackPhi; // Glazing system interior shade solar absorptance for each angle of incidence std::array solabsShadePhi; @@ -277,7 +277,6 @@ namespace Window { int LayPtr; // Material number corresponding to LayNum Real64 tsolDiff; // Glazing system diffuse solar transmittance Real64 tvisDiff; // Glazing system diffuse visible transmittance - int IGlassBack; // Glass layer number counted from back of window Real64 ShadeAbs; // Solar absorptance of isolated shade Real64 ash; // = ShadeAbs Real64 afsh; // Diffuse solar front absorptance of isolated blind @@ -669,19 +668,19 @@ namespace Window { for (int iPhi = 0; iPhi < numPhis; ++iPhi) { // For each wavelength, get glass layer properties at this angle of incidence // from properties at normal incidence - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - LayPtr = thisConstruct.LayerPoint(LayerNum[IGlass - 1]); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + LayPtr = thisConstruct.LayerPoint(LayerNum[iGlass]); auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { + for (int iLam = 0; iLam < numpt[iGlass]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][iLam], - rff[IGlass - 1][iLam], - rbb[IGlass - 1][iLam], - tPhi[IGlass - 1][iLam], - rfPhi[IGlass - 1][iLam], - rbPhi[IGlass - 1][iLam], + t[iGlass][iLam], + rff[iGlass][iLam], + rbb[iGlass][iLam], + tPhi[iGlass][iLam], + rfPhi[iGlass][iLam], + rbPhi[iGlass][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); @@ -690,24 +689,24 @@ namespace Window { for (int iLam = 0; iLam < nume; ++iLam) { Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + wlt[iGlass][iLam] = lam; + tPhi[iGlass][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[iGlass][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[iGlass][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } // For use with between-glass shade/blind, save angular properties of isolated glass // for case that all glass layers were input with spectral-average properties // only used by between-glass shades or blinds if (AllGlassIsSpectralAverage) { - tBareSolPhi(IGlass)[iPhi] = tPhi[IGlass - 1][0]; - tBareVisPhi(IGlass)[iPhi] = tPhi[IGlass - 1][1]; - rfBareSolPhi(IGlass)[iPhi] = rfPhi[IGlass - 1][0]; - rfBareVisPhi(IGlass)[iPhi] = rfPhi[IGlass - 1][1]; - rbBareSolPhi(IGlass)[iPhi] = rbPhi[IGlass - 1][0]; - rbBareVisPhi(IGlass)[iPhi] = rbPhi[IGlass - 1][1]; - afBareSolPhi(IGlass)[iPhi] = max(0.0, 1.0 - (tBareSolPhi(IGlass)[iPhi] + rfBareSolPhi(IGlass)[iPhi])); - abBareSolPhi(IGlass)[iPhi] = max(0.0, 1.0 - (tBareSolPhi(IGlass)[iPhi] + rbBareSolPhi(IGlass)[iPhi])); + tBareSolPhi[iGlass][iPhi] = tPhi[iGlass][0]; + tBareVisPhi[iGlass][iPhi] = tPhi[iGlass][1]; + rfBareSolPhi[iGlass][iPhi] = rfPhi[iGlass][0]; + rfBareVisPhi[iGlass][iPhi] = rfPhi[iGlass][1]; + rbBareSolPhi[iGlass][iPhi] = rbPhi[iGlass][0]; + rbBareVisPhi[iGlass][iPhi] = rbPhi[iGlass][1]; + afBareSolPhi[iGlass][iPhi] = max(0.0, 1.0 - (tBareSolPhi[iGlass][iPhi] + rfBareSolPhi[iGlass][iPhi])); + abBareSolPhi[iGlass][iPhi] = max(0.0, 1.0 - (tBareSolPhi[iGlass][iPhi] + rbBareSolPhi[iGlass][iPhi])); } } @@ -731,11 +730,11 @@ namespace Window { rfsolPhi[iPhi] = solarSpectrumAverage(state, srfPhi); rbsolPhi[iPhi] = solarSpectrumAverage(state, srbPhi); - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { for (int iLam = 0; iLam < nume; ++iLam) { - sabsPhi[iLam] = saPhi(IGlass)[iLam]; + sabsPhi[iLam] = saPhi[iGlass][iLam]; } - solabsPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); + solabsPhi[iGlass][iPhi] = solarSpectrumAverage(state, sabsPhi); } // Get visible properties of system by integrating over solar irradiance @@ -756,15 +755,15 @@ namespace Window { // only used by between-glass shades or blinds if (AllGlassIsSpectralAverage) { - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - W5LsqFit(cosPhisLocal, tBareSolPhi(IGlass), thisConstruct.tBareSolCoef(IGlass)); - W5LsqFit(cosPhisLocal, tBareVisPhi(IGlass), thisConstruct.tBareVisCoef(IGlass)); - W5LsqFit(cosPhisLocal, rfBareSolPhi(IGlass), thisConstruct.rfBareSolCoef(IGlass)); - W5LsqFit(cosPhisLocal, rfBareVisPhi(IGlass), thisConstruct.rfBareVisCoef(IGlass)); - W5LsqFit(cosPhisLocal, rbBareSolPhi(IGlass), thisConstruct.rbBareSolCoef(IGlass)); - W5LsqFit(cosPhisLocal, rbBareVisPhi(IGlass), thisConstruct.rbBareVisCoef(IGlass)); - W5LsqFit(cosPhisLocal, afBareSolPhi(IGlass), thisConstruct.afBareSolCoef(IGlass)); - W5LsqFit(cosPhisLocal, abBareSolPhi(IGlass), thisConstruct.abBareSolCoef(IGlass)); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + W5LsqFit(cosPhisLocal, tBareSolPhi[iGlass], thisConstruct.tBareSolCoef[iGlass]); + W5LsqFit(cosPhisLocal, tBareVisPhi[iGlass], thisConstruct.tBareVisCoef[iGlass]); + W5LsqFit(cosPhisLocal, rfBareSolPhi[iGlass], thisConstruct.rfBareSolCoef[iGlass]); + W5LsqFit(cosPhisLocal, rfBareVisPhi[iGlass], thisConstruct.rfBareVisCoef[iGlass]); + W5LsqFit(cosPhisLocal, rbBareSolPhi[iGlass], thisConstruct.rbBareSolCoef[iGlass]); + W5LsqFit(cosPhisLocal, rbBareVisPhi[iGlass], thisConstruct.rbBareVisCoef[iGlass]); + W5LsqFit(cosPhisLocal, afBareSolPhi[iGlass], thisConstruct.afBareSolCoef[iGlass]); + W5LsqFit(cosPhisLocal, abBareSolPhi[iGlass], thisConstruct.abBareSolCoef[iGlass]); } } @@ -777,23 +776,23 @@ namespace Window { tvisDiff = DiffuseAverage(tvisPhi); thisConstruct.TransDiff = tsolDiff; thisConstruct.TransDiffVis = tvisDiff; - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - solabsPhiLay = solabsPhi(IGlass); // Is this a deep copy? - solabsDiff(IGlass) = DiffuseAverage(solabsPhiLay); - thisConstruct.AbsDiff(IGlass) = solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + solabsPhiLay = solabsPhi[iGlass]; // Is this a deep copy? + solabsDiff[iGlass] = DiffuseAverage(solabsPhiLay); + thisConstruct.AbsDiff(iGlass+1) = solabsDiff[iGlass]; // For use with between-glass shade/blind, get diffuse properties of isolated glass for case when // all glass layers were input with spectral-average properties // only used by between-glass shades or blinds if (AllGlassIsSpectralAverage) { - thisConstruct.tBareSolDiff(IGlass) = DiffuseAverage(tBareSolPhi(IGlass)); - thisConstruct.tBareVisDiff(IGlass) = DiffuseAverage(tBareVisPhi(IGlass)); - thisConstruct.rfBareSolDiff(IGlass) = DiffuseAverage(rfBareSolPhi(IGlass)); - thisConstruct.rfBareVisDiff(IGlass) = DiffuseAverage(rfBareVisPhi(IGlass)); - thisConstruct.rbBareSolDiff(IGlass) = DiffuseAverage(rbBareSolPhi(IGlass)); - thisConstruct.rbBareVisDiff(IGlass) = DiffuseAverage(rbBareVisPhi(IGlass)); - thisConstruct.afBareSolDiff(IGlass) = max(0.0, 1.0 - (thisConstruct.tBareSolDiff(IGlass) + thisConstruct.rfBareSolDiff(IGlass))); - thisConstruct.abBareSolDiff(IGlass) = max(0.0, 1.0 - (thisConstruct.tBareSolDiff(IGlass) + thisConstruct.rbBareSolDiff(IGlass))); + thisConstruct.tBareSolDiff[iGlass] = DiffuseAverage(tBareSolPhi[iGlass]); + thisConstruct.tBareVisDiff[iGlass] = DiffuseAverage(tBareVisPhi[iGlass]); + thisConstruct.rfBareSolDiff[iGlass] = DiffuseAverage(rfBareSolPhi[iGlass]); + thisConstruct.rfBareVisDiff[iGlass] = DiffuseAverage(rfBareVisPhi[iGlass]); + thisConstruct.rbBareSolDiff[iGlass] = DiffuseAverage(rbBareSolPhi[iGlass]); + thisConstruct.rbBareVisDiff[iGlass] = DiffuseAverage(rbBareVisPhi[iGlass]); + thisConstruct.afBareSolDiff[iGlass] = max(0.0, 1.0 - (thisConstruct.tBareSolDiff[iGlass] + thisConstruct.rfBareSolDiff[iGlass])); + thisConstruct.abBareSolDiff[iGlass] = max(0.0, 1.0 - (thisConstruct.tBareSolDiff[iGlass] + thisConstruct.rbBareSolDiff[iGlass])); } } @@ -805,32 +804,29 @@ namespace Window { LayerNum = {0}; // Glass layer number // Loop over glass layers in the construction. - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - int LayNum = 1 + (NGlass - IGlass) * 2; + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + int LayNum = 1 + (NGlass - iGlass - 1) * 2; if (ExtShade || ExtBlind || ExtScreen) { - LayNum = 2 + (NGlass - IGlass) * 2; + LayNum = 2 + (NGlass - iGlass - 1) * 2; } if (BGShade || BGBlind) { if (NGlass == 2) { - if (IGlass == 1) { + if (iGlass == 0) { LayNum = 5; - } - if (IGlass == 2) { + } else if (iGlass == 1) { LayNum = 1; } } else { // NGlass = 3 - if (IGlass == 1) { + if (iGlass == 0) { LayNum = 7; - } - if (IGlass == 2) { + } else if (iGlass == 1) { LayNum = 3; - } - if (IGlass == 3) { + } else if (iGlass == 2) { LayNum = 1; } } } - LayerNum[IGlass - 1] = LayNum; + LayerNum[iGlass] = LayNum; LayPtr = thisConstruct.LayerPoint(LayNum); auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); @@ -843,37 +839,42 @@ namespace Window { // means incident from the outside. numptDAT = specData.NumOfWavelengths; - numpt[IGlass - 1] = numptDAT; + numpt[iGlass] = numptDAT; for (int iLam = 0; iLam < numptDAT; ++iLam) { - wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); - t[IGlass - 1][iLam] = specData.Trans(iLam+1); - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][iLam] = specData.ReflBack(iLam+1); - rbb[IGlass - 1][iLam] = specData.ReflFront(iLam+1); + wlt[iGlass][iLam] = specData.WaveLength(iLam+1); + t[iGlass][iLam] = specData.Trans(iLam+1); + if ((iGlass + 1) == NGlass || + ((iGlass + 1) == (NGlass - 1) && StormWinConst)) { + t[iGlass][iLam] *= matGlass->GlassTransDirtFactor; + } + rff[iGlass][iLam] = specData.ReflBack(iLam+1); + rbb[iGlass][iLam] = specData.ReflFront(iLam+1); } // No spectral data for this layer; use spectral average values } else if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { lquasi = true; - numpt[IGlass - 1] = 2; - t[IGlass - 1][0] = matGlass->Trans; - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) { - t[IGlass - 1][0] *= matGlass->GlassTransDirtFactor; + numpt[iGlass] = 2; + t[iGlass][0] = matGlass->Trans; + if ((iGlass + 1) == NGlass || + ((iGlass + 1) == (NGlass - 1) && StormWinConst)) { + t[iGlass][0] *= matGlass->GlassTransDirtFactor; } - t[IGlass - 1][1] = matGlass->TransVis; - if (IGlass == NGlass || (IGlass == (NGlass - 1) && StormWinConst)) { - t[IGlass - 1][1] *= matGlass->GlassTransDirtFactor; + t[iGlass][1] = matGlass->TransVis; + if ((iGlass + 1) == NGlass || + ((iGlass + 1) == (NGlass - 1) && StormWinConst)) { + t[iGlass][1] *= matGlass->GlassTransDirtFactor; } - rff[IGlass - 1][0] = matGlass->ReflectSolBeamBack; - rbb[IGlass - 1][0] = matGlass->ReflectSolBeamFront; - rff[IGlass - 1][1] = matGlass->ReflectVisBeamBack; - rbb[IGlass - 1][1] = matGlass->ReflectVisBeamFront; + rff[iGlass][0] = matGlass->ReflectSolBeamBack; + rbb[iGlass][0] = matGlass->ReflectSolBeamFront; + rff[iGlass][1] = matGlass->ReflectVisBeamBack; + rbb[iGlass][1] = matGlass->ReflectVisBeamFront; // Using SpectralAndAngle here } else { numptDAT = nume; - numpt[IGlass - 1] = numptDAT; + numpt[iGlass] = numptDAT; } } // End of loop over glass layers in the construction for back calculation @@ -895,20 +896,20 @@ namespace Window { // >>>>>>> origin/develop // For each wavelength, get glass layer properties at this angle of incidence // from properties at normal incidence - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - LayPtr = thisConstruct.LayerPoint(LayerNum[IGlass - 1]); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + LayPtr = thisConstruct.LayerPoint(LayerNum[iGlass]); auto const *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); if (matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { - for (int iLam = 0; iLam < numpt[IGlass - 1]; ++iLam) { + for (int iLam = 0; iLam < numpt[iGlass]; ++iLam) { TransAndReflAtPhi(cosPhisLocal[iPhi], - t[IGlass - 1][iLam], - rff[IGlass - 1][iLam], - rbb[IGlass - 1][iLam], - tPhi[IGlass - 1][iLam], - rfPhi[IGlass - 1][iLam], - rbPhi[IGlass - 1][iLam], + t[iGlass][iLam], + rff[iGlass][iLam], + rbb[iGlass][iLam], + tPhi[iGlass][iLam], + rfPhi[iGlass][iLam], + rbPhi[iGlass][iLam], lSimpleGlazingSystem, SimpleGlazingSHGC, SimpleGlazingU); @@ -918,10 +919,10 @@ namespace Window { for (int iLam = 1; iLam < nume; ++iLam) { Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - tPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); - rfPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); - rbPhi[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); + wlt[iGlass][iLam] = lam; + tPhi[iGlass][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); + rfPhi[iGlass][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, iPhi * dPhiDeg, lam); + rbPhi[iGlass][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, iPhi * dPhiDeg, lam); } } } @@ -940,18 +941,18 @@ namespace Window { // Get back absorptance properties of system by integrating over solar irradiance spectrum. // For now it is assumed that the exterior and interior irradiance spectra are the same. - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { for (int j = 0; j < nume; ++j) { - sabsPhi[j] = saPhi(IGlass)[j]; + sabsPhi[j] = saPhi[iGlass][j]; } - solabsBackPhi(IGlass)[iPhi] = solarSpectrumAverage(state, sabsPhi); + solabsBackPhi[iGlass][iPhi] = solarSpectrumAverage(state, sabsPhi); } } // End of loop over incidence angles for back calculation - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - IGlassBack = NGlass - IGlass + 1; - thisConstruct.AbsDiffBack(IGlass) = DiffuseAverage(solabsBackPhi(IGlassBack)); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + int iGlassBack = NGlass - iGlass - 1; // Was NGlass - IGlass + 1 when IGlass was 1-based + thisConstruct.AbsDiffBack(iGlass+1) = DiffuseAverage(solabsBackPhi[iGlassBack]); } //----------------------------------------------------------------------- @@ -990,8 +991,8 @@ namespace Window { // Front incident solar, beam, interior shade for (int iPhi = 0; iPhi < numPhis; ++iPhi) { - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - solabsPhi(IGlass)[iPhi] += tsolPhi[iPhi] * ShadeRefl * ShadeReflFac * constr.AbsDiffBack(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + solabsPhi[iGlass][iPhi] += tsolPhi[iPhi] * ShadeRefl * ShadeReflFac * constr.AbsDiffBack(iGlass+1); } solabsShadePhi[iPhi] = tsolPhi[iPhi] * ShadeReflFac * ShadeAbs; tsolPhi[iPhi] *= ShadeReflFac * ShadeTrans; @@ -999,8 +1000,8 @@ namespace Window { } // Front incident solar, diffuse, interior shade - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - constr.AbsDiff(IGlass) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + constr.AbsDiff(iGlass+1) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff[iGlass]; } constr.AbsDiffShade = tsolDiff * ShadeReflFac * ShadeAbs; @@ -1039,8 +1040,8 @@ namespace Window { ShadeReflFacVis = 1.0 / (1.0 - ShadeReflVis * constr.ReflectVisDiffFront); for (int iPhi = 0; iPhi < numPhis; ++iPhi) { - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - solabsPhi(IGlass)[iPhi] = ShadeTrans * solabsDiff(IGlass) * ShadeReflFac; + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + solabsPhi[iGlass][iPhi] = ShadeTrans * solabsDiff[iGlass] * ShadeReflFac; } tsolPhi[iPhi] = ShadeTrans * ShadeReflFac * tsolDiff; tvisPhi[iPhi] = ShadeTransVis * ShadeReflFacVis * tvisDiff; @@ -1048,8 +1049,8 @@ namespace Window { } // Front incident solar, diffuse, exterior shade/screen/blind - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - constr.AbsDiff(IGlass) = ShadeTrans * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + constr.AbsDiff(iGlass+1) = ShadeTrans * ShadeReflFac * solabsDiff[iGlass]; } // Front incident solar, diffuse, exterior shade/screen @@ -1060,8 +1061,8 @@ namespace Window { constr.ReflectVisDiffFront = ShadeReflVis + pow_2(ShadeTransVis) * constr.ReflectVisDiffFront * ShadeReflFacVis; // Back incident solar, diffuse, exterior shade/screen - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - constr.AbsDiffBack(IGlass) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + constr.AbsDiffBack(iGlass+1) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff[iGlass]; } constr.AbsDiffBackShade = tsolDiff * ShadeReflFac * ShadeAbs; constr.ReflectSolDiffBack += tsolDiff_2 * ShadeRefl * ShadeReflFac; @@ -1107,15 +1108,15 @@ namespace Window { // Front incident solar, beam, between-glass shade, NGlass = 2 for (int iPhi = 0; iPhi < numPhis; ++iPhi) { - t1 = tBareSolPhi(1)[iPhi]; - t1v = tBareVisPhi(1)[iPhi]; - af1 = afBareSolPhi(1)[iPhi]; - ab1 = abBareSolPhi(1)[iPhi]; + t1 = tBareSolPhi[0][iPhi]; + t1v = tBareVisPhi[0][iPhi]; + af1 = afBareSolPhi[0][iPhi]; + ab1 = abBareSolPhi[0][iPhi]; tsolPhi[iPhi] = t1 * (tsh + rsh * rb1 * tsh + tsh * rf2 * rsh) * td2; tvisPhi[iPhi] = t1v * (tshv + rshv * rb1v * tshv + tshv * rf2v * rshv) * td2v; solabsShadePhi[iPhi] = t1 * (ash + rsh * rb1 + tsh * rf2) * ash; - solabsPhi(1)[iPhi] = af1 + t1 * (rsh + rsh * rb1 * rsh + tsh * rf2 * tsh) * abd1; - solabsPhi(2)[iPhi] = t1 * (tsh + rsh * rb1 * tsh + tsh * rf2 * rsh) * afd2; + solabsPhi[0][iPhi] = af1 + t1 * (rsh + rsh * rb1 * rsh + tsh * rf2 * tsh) * abd1; + solabsPhi[1][iPhi] = t1 * (tsh + rsh * rb1 * tsh + tsh * rf2 * rsh) * afd2; } // End of loop over incidence angles // Front incident solar, diffuse, between-glass shade, NGlass = 2 @@ -1150,22 +1151,22 @@ namespace Window { // Front incident solar, beam, between-glass shade, NGlass = 3 for (int iPhi = 0; iPhi < numPhis; ++iPhi) { - t1 = tBareSolPhi(1)[iPhi]; - t1v = tBareVisPhi(1)[iPhi]; - t2 = tBareSolPhi(2)[iPhi]; - t2v = tBareVisPhi(2)[iPhi]; - af1 = afBareSolPhi(1)[iPhi]; - af2 = afBareSolPhi(2)[iPhi]; - ab1 = abBareSolPhi(1)[iPhi]; - ab2 = abBareSolPhi(2)[iPhi]; + t1 = tBareSolPhi[0][iPhi]; + t1v = tBareVisPhi[0][iPhi]; + t2 = tBareSolPhi[1][iPhi]; + t2v = tBareVisPhi[1][iPhi]; + af1 = afBareSolPhi[0][iPhi]; + af2 = afBareSolPhi[1][iPhi]; + ab1 = abBareSolPhi[0][iPhi]; + ab2 = abBareSolPhi[1][iPhi]; rbmf2 = max(0.0, 1.0 - (t2 + af2)); tsolPhi[iPhi] = t1 * t2 * (tsh + tsh * rf3 * rsh + rsh * td2 * rb1 * td2 * tsh + rsh * rb2 * tsh) * td3; tvisPhi[iPhi] = t1v * t2v * (tshv + tshv * rf3v * rshv + rshv * td2v * rb1v * td2v * tshv + rshv * rb2v * tshv) * td3v; solabsShadePhi[iPhi] = t1 * t2 * (1 + rsh * td2 * rb1 * td2 + rsh * rb2) * ash; - solabsPhi(1)[iPhi] = af1 + rbmf2 * ab1 + t1 * t2 * rsh * (1 + rf3 * tsh + rb2 * rsh + td2 * rb1 * td2 * rsh) * td2 * abd1; - solabsPhi(2)[iPhi] = t1 * af2 + t1 * t2 * ((rsh + tsh * rf3 * tsh + rsh * rb2 * rsh) * abd2 + rsh * td2 * rb1 * afd2); - solabsPhi(3)[iPhi] = t1 * t2 * (tsh + rsh * (rb2 * tsh + td2 * rb2 * td2 * tsh + rf3 * rsh)) * afd3; + solabsPhi[0][iPhi] = af1 + rbmf2 * ab1 + t1 * t2 * rsh * (1 + rf3 * tsh + rb2 * rsh + td2 * rb1 * td2 * rsh) * td2 * abd1; + solabsPhi[1][iPhi] = t1 * af2 + t1 * t2 * ((rsh + tsh * rf3 * tsh + rsh * rb2 * rsh) * abd2 + rsh * td2 * rb1 * afd2); + solabsPhi[2][iPhi] = t1 * t2 * (tsh + rsh * (rb2 * tsh + td2 * rb2 * td2 * tsh + rf3 * rsh)) * afd3; } // End of loop over incidence angle // Front incident solar, diffuse, between-glass shade, NGlass = 3 @@ -1265,11 +1266,11 @@ namespace Window { ShadeReflFac = 1.0 / (1.0 - ShadeRefl * constr.ReflectSolDiffFront); ShadeReflFacVis = 1.0 / (1.0 - ShadeReflVis * constr.ReflectVisDiffFront); - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - auto &dfAbs = constr.layerSlatBlindDfAbs(IGlass)[iSlatAng]; - dfAbs.Sol.Ft.Df.Abs = ShadeTrans * ShadeReflFac * solabsDiff(IGlass); - dfAbs.Sol.Ft.Df.AbsGnd = ShadeTransGnd * ShadeReflFac * solabsDiff(IGlass); - dfAbs.Sol.Ft.Df.AbsSky = ShadeTransSky * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 1; iGlass < NGlass; ++iGlass) { + auto &dfAbs = constr.layerSlatBlindDfAbs(iGlass+1)[iSlatAng]; + dfAbs.Sol.Ft.Df.Abs = ShadeTrans * ShadeReflFac * solabsDiff[iGlass]; + dfAbs.Sol.Ft.Df.AbsGnd = ShadeTransGnd * ShadeReflFac * solabsDiff[iGlass]; + dfAbs.Sol.Ft.Df.AbsSky = ShadeTransSky * ShadeReflFac * solabsDiff[iGlass]; } auto &cbtar = constr.blindTARs[iSlatAng]; @@ -1284,9 +1285,9 @@ namespace Window { cbtar.Vis.Ft.Df.Ref = ShadeReflVis + pow_2(ShadeTransVis) * thisConstruct.ReflectVisDiffFront * ShadeReflFacVis; // Back incident solar, diffuse, exterior shade/blind - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - auto &dfAbs = constr.layerSlatBlindDfAbs(IGlass)[iSlatAng]; - dfAbs.Sol.Bk.Df.Abs = constr.AbsDiffBack(IGlass) + tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + auto &dfAbs = constr.layerSlatBlindDfAbs(iGlass+1)[iSlatAng]; + dfAbs.Sol.Bk.Df.Abs = constr.AbsDiffBack(iGlass+1) + tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff[iGlass]; } cbtar.Sol.Bk.Df.Abs = tsolDiff * ShadeReflFac * ShadeAbs; @@ -1446,8 +1447,8 @@ namespace Window { ShadeReflFacVis = 1.0 / (1.0 - ShadeReflVis * constr.ReflectVisDiffFront); // Front incident solar, diffuse, exterior shade/screen/blind - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - constr.AbsDiff(IGlass) = ShadeTrans * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + constr.AbsDiff(iGlass+1) = ShadeTrans * ShadeReflFac * solabsDiff[iGlass]; } // Front incident solar, diffuse, exterior shade/screen @@ -1458,8 +1459,8 @@ namespace Window { constr.ReflectVisDiffFront = ShadeReflVis + pow_2(ShadeTransVis) * constr.ReflectVisDiffFront * ShadeReflFacVis; // Back incident solar, diffuse, exterior shade/screen - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - constr.AbsDiffBack(IGlass) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff(IGlass); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + constr.AbsDiffBack(iGlass+1) += tsolDiff * ShadeRefl * ShadeReflFac * solabsDiff[iGlass]; } constr.AbsDiffBackShade = tsolDiff * ShadeReflFac * ShadeAbs; constr.ReflectSolDiffBack += tsolDiff_2 * ShadeRefl * ShadeReflFac; @@ -1475,13 +1476,13 @@ namespace Window { W5LsqFit(cosPhisLocal, rbsolPhi, thisConstruct.ReflSolBeamBackCoef); W5LsqFit(cosPhisLocal, tvisPhi, thisConstruct.TransVisBeamCoef); - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { // Front absorptance coefficients for glass layers - W5LsqFit(cosPhisLocal, solabsPhi(IGlass), thisConstruct.AbsBeamCoef(IGlass)); + W5LsqFit(cosPhisLocal, solabsPhi[iGlass], thisConstruct.AbsBeamCoef(iGlass+1)); // Back absorptance coefficients for glass layers - IGlassBack = NGlass - IGlass + 1; - W5LsqFit(cosPhisLocal, solabsBackPhi(IGlassBack), thisConstruct.AbsBeamBackCoef(IGlass)); + int iGlassBack = NGlass - iGlass - 1; // Was NGlass - IGlass + 1; + W5LsqFit(cosPhisLocal, solabsBackPhi[iGlassBack], thisConstruct.AbsBeamBackCoef(iGlass+1)); } #ifdef GET_OUT From 85a2b926ee1f7f93f4b48efde9221bc9b47b3c95 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Tue, 24 Feb 2026 21:15:37 -0500 Subject: [PATCH 07/15] Some more transitions, trying to bisect an issue --- src/EnergyPlus/WindowManager.cc | 61 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 8ddd4286e3f..0a1bf955c4c 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -512,28 +512,27 @@ namespace Window { std::array LayerNum = {0}; // Glass layer number // Loop over glass layers in the construction - for (int IGlass = 1; IGlass <= NGlass; ++IGlass) { - int LayNum = 1 + 2 * (IGlass - 1); + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { + int LayNum = 1 + 2 * iGlass; if (ExtShade || ExtBlind || ExtScreen) { - LayNum = 2 + 2 * (IGlass - 1); + LayNum = 2 + 2 * iGlass; } if (BGShade || BGBlind) { LayNum = 1; if (NGlass == 2) { - if (IGlass == 2) { + if (iGlass == 1) { LayNum = 5; } } else { // NGlass = 3 - if (IGlass == 2) { + if (iGlass == 1) { LayNum = 3; - } - if (IGlass == 3) { + } else if (iGlass == 2) { LayNum = 7; } } } - LayerNum[IGlass - 1] = LayNum; + LayerNum[iGlass] = LayNum; LayPtr = thisConstruct.LayerPoint(LayNum); auto *matGlass = dynamic_cast(s_mat->materials(LayPtr)); assert(matGlass != nullptr); @@ -549,15 +548,15 @@ namespace Window { // In this case, "front" means incident from the outside and "back" // means incident from the inside. numptDAT = specData.NumOfWavelengths; - numpt[IGlass - 1] = numptDAT; + numpt[iGlass] = numptDAT; for (int iLam = 0; iLam < numptDAT; ++iLam) { - wlt[IGlass - 1][iLam] = specData.WaveLength(iLam+1); - t[IGlass - 1][iLam] = specData.Trans(iLam+1); - if ((IGlass == 1 || (IGlass == 2 && StormWinConst)) && (!wm->BGFlag)) - t[IGlass - 1][iLam] *= matGlass->GlassTransDirtFactor; - rff[IGlass - 1][iLam] = specData.ReflFront(iLam+1); - rbb[IGlass - 1][iLam] = specData.ReflBack(iLam+1); + wlt[iGlass][iLam] = specData.WaveLength(iLam+1); + t[iGlass][iLam] = specData.Trans(iLam+1); + if ((iGlass == 0 || (iGlass == 1 && StormWinConst)) && (!wm->BGFlag)) + t[iGlass][iLam] *= matGlass->GlassTransDirtFactor; + rff[iGlass][iLam] = specData.ReflFront(iLam+1); + rbb[iGlass][iLam] = specData.ReflBack(iLam+1); } // If there is spectral data for between-glass shades or blinds, calc the average spectral properties for use. @@ -593,19 +592,19 @@ namespace Window { // No spectral data for this layer; use spectral average values if (SpecDataNum == 0 && matGlass->windowOpticalData != Window::OpticalDataModel::SpectralAndAngle) { lquasi = true; - numpt[IGlass - 1] = 2; - t[IGlass - 1][0] = matGlass->Trans; - if (IGlass == 1 || (IGlass == 2 && StormWinConst)) { - t[IGlass - 1][0] *= matGlass->GlassTransDirtFactor; + numpt[iGlass] = 2; + t[iGlass][0] = matGlass->Trans; + if (iGlass == 0 || (iGlass == 1 && StormWinConst)) { + t[iGlass][0] *= matGlass->GlassTransDirtFactor; } - t[IGlass - 1][1] = matGlass->TransVis; - if (IGlass == 1 || (IGlass == 2 && StormWinConst)) { - t[IGlass - 1][1] *= matGlass->GlassTransDirtFactor; + t[iGlass][1] = matGlass->TransVis; + if (iGlass == 0 || (iGlass == 1 && StormWinConst)) { + t[iGlass][1] *= matGlass->GlassTransDirtFactor; } - rff[IGlass - 1][0] = matGlass->ReflectSolBeamFront; - rbb[IGlass - 1][0] = matGlass->ReflectSolBeamBack; - rff[IGlass - 1][1] = matGlass->ReflectVisBeamFront; - rbb[IGlass - 1][1] = matGlass->ReflectVisBeamBack; + rff[iGlass][0] = matGlass->ReflectSolBeamFront; + rbb[iGlass][0] = matGlass->ReflectSolBeamBack; + rff[iGlass][1] = matGlass->ReflectVisBeamFront; + rbb[iGlass][1] = matGlass->ReflectVisBeamBack; } if (matGlass->windowOpticalData == Window::OpticalDataModel::SpectralAndAngle) { @@ -613,7 +612,7 @@ namespace Window { AllGlassIsSpectralAverage = false; } numptDAT = wm->wle.size(); - numpt[IGlass - 1] = numptDAT; + numpt[iGlass] = numptDAT; if (wm->BGFlag) { // 5/16/2012 CR 8793. Add warning message for the glazing defined with full spectral data. ShowWarningError(state, @@ -634,10 +633,10 @@ namespace Window { for (int iLam = 0; iLam < nume; ++iLam) { Real64 lam = wm->wle[iLam]; - wlt[IGlass - 1][iLam] = lam; - t[IGlass - 1][iLam] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); - rff[IGlass - 1][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); - rbb[IGlass - 1][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); + wlt[iGlass][iLam] = lam; + t[iGlass][iLam] = matGlass->GlassSpecAngTransCurve->value(state, 0.0, lam); + rff[iGlass][iLam] = matGlass->GlassSpecAngFReflCurve->value(state, 0.0, lam); + rbb[iGlass][iLam] = matGlass->GlassSpecAngBReflCurve->value(state, 0.0, lam); } // set this material to average spectral data From 3a00ad8fcf26a64d68513ccf78140c507581ce84 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 09:07:49 -0500 Subject: [PATCH 08/15] More bisection --- src/EnergyPlus/WindowManager.cc | 49 +++++++++++++++------------------ src/EnergyPlus/WindowManager.hh | 4 +-- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 0a1bf955c4c..50dbe378476 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -718,8 +718,7 @@ namespace Window { std::array srfPhi = {0.0}; // Glazing system front reflectance at angle of incidence for each wavelength in wle std::array srbPhi = {0.0}; // Glazing system back reflectance at angle of incidence for each wavelength in wle // For each layer, glazing system absorptance at angle of incidence - Array1D> saPhi(maxGlassLayers); - for (int IGlass = 1; IGlass <= maxGlassLayers; ++IGlass) std::fill(saPhi(IGlass).begin(), saPhi(IGlass).end(), 0.0); + std::array, maxGlassLayers> saPhi = {{0.0}}; SystemSpectralPropertiesAtPhi(state, 1, NGlass, 0.0, 2.54, numpt, wlt, tPhi, rfPhi, rbPhi, stPhi, srfPhi, srbPhi, saPhi); @@ -932,8 +931,7 @@ namespace Window { std::array srfPhi = {0.0}; // Glazing system front reflectance at angle of incidence for each wavelength in wle std::array srbPhi = {0.0}; // Glazing system back reflectance at angle of incidence for each wavelength in wle // For each layer, glazing system absorptance at angle of incidence - Array1D> saPhi(maxGlassLayers); - for (int iGlass = 1; iGlass <= maxGlassLayers; ++iGlass) std::fill(saPhi(iGlass).begin(), saPhi(iGlass).end(), 0.0); + std::array, maxGlassLayers> saPhi = {{0.0}}; SystemSpectralPropertiesAtPhi(state, 1, NGlass, 0.0, 2.54, numpt, wlt, tPhi, rfPhi, rbPhi, stPhi, srfPhi, srbPhi, saPhi); @@ -1808,7 +1806,7 @@ namespace Window { std::array &stPhi, std::array &srfPhi, std::array &srbPhi, - Array1D> &saPhi) + std::array, maxGlassLayers> &saPhi) { // SUBROUTINE INFORMATION: @@ -1829,7 +1827,7 @@ namespace Window { // srbPhi back reflectance of system at each wavelength in swl // sabsPhi absorptance by layer at each wavelength in swl - Array1D sabsPhi(maxGlassLayers); // System solar absorptance in each glass layer for + std::array sabsPhi = {0.0}; // System solar absorptance in each glass layer for // particular angle of incidence // transmittance at angle of incidence @@ -1846,7 +1844,7 @@ namespace Window { auto const &wm = state.dataWindowManager; // For each glass layer find tPhi, rfPhi, and rbPhi at each wavelength - for (int in = 1; in <= ngllayer; ++in) { + for (int in = 0; in < ngllayer; ++in) { for (int iwl = 0; iwl < nume; ++iwl) { Real64 wl = wm->wle[iwl]; if (wl < wlbot || wl > wltop) { @@ -1854,15 +1852,15 @@ namespace Window { } // In the following numpt is the number of spectral data points for each layer; // numpt = 2 if there is no spectral data for a layer. - if (numpt[in - 1] <= 2) { - tadjPhi[in - 1][iwl] = tPhi[in - 1][iquasi - 1]; - rfadjPhi[in - 1][iwl] = rfPhi[in - 1][iquasi - 1]; - rbadjPhi[in - 1][iwl] = rbPhi[in - 1][iquasi - 1]; + if (numpt[in] <= 2) { + tadjPhi[in][iwl] = tPhi[in][iquasi - 1]; + rfadjPhi[in][iwl] = rfPhi[in][iquasi - 1]; + rbadjPhi[in][iwl] = rbPhi[in][iquasi - 1]; } else { // Interpolate to get properties at the solar spectrum wavelengths - tadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], tPhi[in - 1], numpt[in - 1], wl); - rfadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], rfPhi[in - 1], numpt[in - 1], wl); - rbadjPhi[in - 1][iwl] = Interpolate(wlt[in - 1], rbPhi[in - 1], numpt[in - 1], wl); + tadjPhi[in][iwl] = Interpolate(wlt[in], tPhi[in], numpt[in], wl); + rfadjPhi[in][iwl] = Interpolate(wlt[in], rfPhi[in], numpt[in], wl); + rbadjPhi[in][iwl] = Interpolate(wlt[in], rbPhi[in], numpt[in], wl); } } } @@ -1875,10 +1873,10 @@ namespace Window { } // Set diagonal of matrix for subroutine SystemPropertiesAtLambdaAndPhi - for (int i = 1; i <= ngllayer; ++i) { - top[i - 1][i - 1] = tadjPhi[i - 1][j]; - rfop[i - 1][i - 1] = rfadjPhi[i - 1][j]; - rbop[i - 1][i - 1] = rbadjPhi[i - 1][j]; + for (int i = 0; i < ngllayer; ++i) { + top[i][i] = tadjPhi[i][j]; + rfop[i][i] = rfadjPhi[i][j]; + rbop[i][i] = rbadjPhi[i][j]; } // Calculate glazing system properties @@ -1886,14 +1884,14 @@ namespace Window { stPhi[j] = top[0][0]; srfPhi[j] = rfop[0][0]; srbPhi[j] = rbop[0][0]; - sabsPhi(1) = 1.0 - stPhi[j] - srfPhi[j]; + sabsPhi[0] = 1.0 - stPhi[j] - srfPhi[j]; } else { // Multilayer system // Get glazing system properties stPhi, etc., at this wavelength and incidence angle SystemPropertiesAtLambdaAndPhi(state, ngllayer, stPhi[j], srfPhi[j], srbPhi[j], top, rfop, rbop, sabsPhi); } - for (int i = 1; i <= ngllayer; ++i) { - saPhi(i)[j] = sabsPhi(i); + for (int i = 0; i < ngllayer; ++i) { + saPhi[i][j] = sabsPhi[i]; } } // End of wavelength loop @@ -1909,7 +1907,7 @@ namespace Window { std::array, maxGlassLayers> &top, std::array, maxGlassLayers> &rfop, std::array, maxGlassLayers> &rbop, - Array1A aft // System absorptance of each glass layer + std::array &aft // System absorptance of each glass layer ) { @@ -1924,9 +1922,6 @@ namespace Window { // For a given angle of incidence, finds the overall properties of // of a series of layers at a particular wavelength - // Argument array dimensioning - aft.dim(5); - Real64 denom; // Intermediate variables Real64 denom1; Real64 denom2; @@ -1979,9 +1974,9 @@ namespace Window { denom2 = 1.0 - rbop[0][j - 1] * rf0; if (denom1 == 0.0 || denom2 == 0.0) { - aft(j) = 0.0; + aft[j - 1] = 0.0; } else { - aft(j) = (t0 * af) / denom1 + (top[j - 1][0] * rf0 * ab) / denom2; + aft[j - 1] = (t0 * af) / denom1 + (top[j - 1][0] * rf0 * ab) / denom2; } } } // SystemPropertiesAtLambdaAndPhi() diff --git a/src/EnergyPlus/WindowManager.hh b/src/EnergyPlus/WindowManager.hh index cc65f5a8ba1..4df0c359fa8 100644 --- a/src/EnergyPlus/WindowManager.hh +++ b/src/EnergyPlus/WindowManager.hh @@ -129,7 +129,7 @@ namespace Window { std::array &stPhi, std::array &srfPhi, std::array &srbPhi, - Array1D> &saPhi); + std::array, maxGlassLayers> &saPhi); void SystemPropertiesAtLambdaAndPhi(EnergyPlusData &state, int n, // Number of glass layers @@ -139,7 +139,7 @@ namespace Window { std::array, maxGlassLayers> &top, std::array, maxGlassLayers> &rfop, std::array, maxGlassLayers> &rbop, - Array1A aft // System absorptance of each glass layer + std::array &aft // System absorptance of each glass layer ); Real64 solarSpectrumAverage(EnergyPlusData const &state, gsl::span p); From f462e2814e757def6101f4874f1054ca0266b6ef Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 09:22:03 -0500 Subject: [PATCH 09/15] Bisect, bisect, bisect --- src/EnergyPlus/WindowManager.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 50dbe378476..bc35109fdc5 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -1953,30 +1953,30 @@ namespace Window { rbt = rbop[0][n - 1]; // Absorptance in each layer - for (int j = 1; j <= n; ++j) { - if (j == 1) { + for (int j = 0; j < n; ++j) { + if (j == 0) { t0 = 1.0; rb0 = 0.0; } else { - t0 = top[j - 2][0]; - rb0 = rbop[0][j - 2]; + t0 = top[j - 1][0]; + rb0 = rbop[0][j - 1]; } - if (j == n) { + if (j == n - 1) { rf0 = 0.0; } else { - rf0 = rfop[n - 1][j]; + rf0 = rfop[n - 1][j + 1]; } - af = 1.0 - top[j - 1][j - 1] - rfop[j - 1][j - 1]; - ab = 1.0 - top[j - 1][j - 1] - rbop[j - 1][j - 1]; - denom1 = 1.0 - rfop[n - 1][j - 1] * rb0; - denom2 = 1.0 - rbop[0][j - 1] * rf0; + af = 1.0 - top[j][j] - rfop[j][j]; + ab = 1.0 - top[j][j] - rbop[j][j]; + denom1 = 1.0 - rfop[n - 1][j] * rb0; + denom2 = 1.0 - rbop[0][j] * rf0; if (denom1 == 0.0 || denom2 == 0.0) { - aft[j - 1] = 0.0; + aft[j] = 0.0; } else { - aft[j - 1] = (t0 * af) / denom1 + (top[j - 1][0] * rf0 * ab) / denom2; + aft[j] = (t0 * af) / denom1 + (top[j][0] * rf0 * ab) / denom2; } } } // SystemPropertiesAtLambdaAndPhi() From 6593884dce4151ef2d354494f4b8bdc61948b972 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 09:25:22 -0500 Subject: [PATCH 10/15] Found it --- src/EnergyPlus/WindowManager.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index bc35109fdc5..349a3952785 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -1933,17 +1933,17 @@ namespace Window { Real64 ab; // Calculate perimeter elements of rt matrix - for (int i = 1; i <= n - 1; ++i) { - for (int j = i + 1; j <= n; ++j) { - denom = 1.0 - rfop[j - 1][j - 1] * rbop[i - 1][j - 2]; + for (int i = 0; i < n - 1; ++i) { + for (int j = i + 1; j < n; ++j) { + denom = 1.0 - rfop[j][j] * rbop[i][j - 1]; if (denom == 0.0) { - top[j - 1][i - 1] = 0.0; - rfop[j - 1][i - 1] = 1.0; - rbop[i - 1][j - 1] = 1.0; + top[j][i] = 0.0; + rfop[j][i] = 1.0; + rbop[i][j] = 1.0; } else { - top[j - 1][i - 1] = top[j - 2][i - 1] * top[j - 1][j - 1] / denom; - rfop[j - 1][i - 1] = rfop[j - 2][i - 1] + pow_2(top[j - 2][i - 1]) * rfop[j - 1][j - 1] / denom; - rbop[i - 1][j - 1] = rbop[j - 1][j - 1] + pow_2(top[j - 1][j - 1]) * rbop[i - 1][j - 2] / denom; + top[j][i] = top[j - 1][i] * top[j][j] / denom; + rfop[j][i] = rfop[j - 1][i] + pow_2(top[j - 1][i]) * rfop[j][j] / denom; + rbop[i][j] = rbop[j][j] + pow_2(top[j][j]) * rbop[i][j - 1] / denom; } } } From 2bf8e0ed4ce5c99cada895744922b2e65ffb6873 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 12:38:33 -0500 Subject: [PATCH 11/15] Is this the cause of the small diffs? --- src/EnergyPlus/WindowManager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 349a3952785..b563d030620 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -915,7 +915,7 @@ namespace Window { } else { - for (int iLam = 1; iLam < nume; ++iLam) { + for (int iLam = 0; iLam < nume; ++iLam) { Real64 lam = wm->wle[iLam]; wlt[iGlass][iLam] = lam; tPhi[iGlass][iLam] = matGlass->GlassSpecAngTransCurve->value(state, iPhi * dPhiDeg, lam); From e5150368ead26693c72092df2a08a18d831e60b9 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 14:55:50 -0500 Subject: [PATCH 12/15] Taking a stab --- src/EnergyPlus/WindowManager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index b563d030620..ac3bc100565 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -1948,9 +1948,9 @@ namespace Window { } } // System properties: transmittance, front and back reflectance - tt = top[n - 1][0]; - rft = rfop[n - 1][0]; - rbt = rbop[0][n - 1]; + tt = top[n - 2][0]; + rft = rfop[n - 2][0]; + rbt = rbop[0][n - 2]; // Absorptance in each layer for (int j = 0; j < n; ++j) { From 56f9f744577c20bd51be75bc160ba0523c3d83f1 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 15:43:03 -0500 Subject: [PATCH 13/15] Undo attempted fix --- src/EnergyPlus/WindowManager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index ac3bc100565..b563d030620 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -1948,9 +1948,9 @@ namespace Window { } } // System properties: transmittance, front and back reflectance - tt = top[n - 2][0]; - rft = rfop[n - 2][0]; - rbt = rbop[0][n - 2]; + tt = top[n - 1][0]; + rft = rfop[n - 1][0]; + rbt = rbop[0][n - 1]; // Absorptance in each layer for (int j = 0; j < n; ++j) { From bd6f67326719170c12413d70aa96881a2643e177 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 15:56:33 -0500 Subject: [PATCH 14/15] Trying a more obvious and promising fix --- src/EnergyPlus/WindowManager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index b563d030620..03969907851 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -1263,7 +1263,7 @@ namespace Window { ShadeReflFac = 1.0 / (1.0 - ShadeRefl * constr.ReflectSolDiffFront); ShadeReflFacVis = 1.0 / (1.0 - ShadeReflVis * constr.ReflectVisDiffFront); - for (int iGlass = 1; iGlass < NGlass; ++iGlass) { + for (int iGlass = 0; iGlass < NGlass; ++iGlass) { auto &dfAbs = constr.layerSlatBlindDfAbs(iGlass+1)[iSlatAng]; dfAbs.Sol.Ft.Df.Abs = ShadeTrans * ShadeReflFac * solabsDiff[iGlass]; dfAbs.Sol.Ft.Df.AbsGnd = ShadeTransGnd * ShadeReflFac * solabsDiff[iGlass]; From 696ba395351a0343d84bd8378e3f46af485e06d1 Mon Sep 17 00:00:00 2001 From: Amir Roth Date: Wed, 25 Feb 2026 20:45:08 -0500 Subject: [PATCH 15/15] Not sure what this is about --- src/EnergyPlus/WindowManager.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/EnergyPlus/WindowManager.cc b/src/EnergyPlus/WindowManager.cc index 03969907851..21f96ce8c08 100644 --- a/src/EnergyPlus/WindowManager.cc +++ b/src/EnergyPlus/WindowManager.cc @@ -314,11 +314,11 @@ namespace Window { bool StormWinConst; // True if a construction with a storm window bool Triangle; // True if window is triangular bool Rectangle; // True if window is rectangular - Vector3 W1; // Window vertices (m) - Vector3 W2; - Vector3 W3; - Vector3 W21; // W1-W2, W3-W2, resp. (m) - Vector3 W23; + Vector3 W1 = {0.0, 0.0, 0.0}; // Window vertices (m) + Vector3 W2 = {0.0, 0.0, 0.0}; + Vector3 W3 = {0.0, 0.0, 0.0}; + Vector3 W21 = {0.0, 0.0, 0.0}; // W1-W2, W3-W2, resp. (m) + Vector3 W23 = {0.0, 0.0, 0.0}; // Spectral data wavelengths for each glass layer in a glazing system std::array, maxGlassLayers> wlt = {0.0};