Line data Source code
1 : // EnergyPlus, Copyright (c) 1996-2025, The Board of Trustees of the University of Illinois,
2 : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
3 : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
4 : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
5 : // contributors. All rights reserved.
6 : //
7 : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
8 : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
9 : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
10 : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
11 : // derivative works, and perform publicly and display publicly, and to permit others to do so.
12 : //
13 : // Redistribution and use in source and binary forms, with or without modification, are permitted
14 : // provided that the following conditions are met:
15 : //
16 : // (1) Redistributions of source code must retain the above copyright notice, this list of
17 : // conditions and the following disclaimer.
18 : //
19 : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
20 : // conditions and the following disclaimer in the documentation and/or other materials
21 : // provided with the distribution.
22 : //
23 : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
24 : // the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
25 : // used to endorse or promote products derived from this software without specific prior
26 : // written permission.
27 : //
28 : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
29 : // without changes from the version obtained under this License, or (ii) Licensee makes a
30 : // reference solely to the software portion of its product, Licensee must refer to the
31 : // software as "EnergyPlus version X" software, where "X" is the version number Licensee
32 : // obtained under this License and may not use a different name for the software. Except as
33 : // specifically required in this Section (4), Licensee shall not use in a company name, a
34 : // product name, in advertising, publicity, or other promotional activities any name, trade
35 : // name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
36 : // similar designation, without the U.S. Department of Energy's prior written consent.
37 : //
38 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
39 : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
40 : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
41 : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
43 : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
45 : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 : // POSSIBILITY OF SUCH DAMAGE.
47 :
48 : // ObjexxFCL Headers
49 : #include <ObjexxFCL/Array.functions.hh>
50 : #include <ObjexxFCL/Array1D.hh>
51 : #include <ObjexxFCL/ArrayS.functions.hh>
52 : // #include <ObjexxFCL/Fmath.hh>
53 : #include <ObjexxFCL/member.functions.hh>
54 :
55 : // EnergyPlus Headers
56 : #include <EnergyPlus/Data/EnergyPlusData.hh>
57 : #include <EnergyPlus/DataEnvironment.hh>
58 : #include <EnergyPlus/DataErrorTracking.hh>
59 : #include <EnergyPlus/DataHVACGlobals.hh>
60 : #include <EnergyPlus/DataHeatBalFanSys.hh>
61 : #include <EnergyPlus/DataHeatBalance.hh>
62 : #include <EnergyPlus/DataLoopNode.hh>
63 : #include <EnergyPlus/DataRoomAirModel.hh>
64 : #include <EnergyPlus/DataSurfaces.hh>
65 : #include <EnergyPlus/DataZoneEnergyDemands.hh>
66 : #include <EnergyPlus/DataZoneEquipment.hh>
67 : #include <EnergyPlus/FluidProperties.hh>
68 : #include <EnergyPlus/General.hh>
69 : #include <EnergyPlus/InternalHeatGains.hh>
70 : #include <EnergyPlus/OutputProcessor.hh>
71 : #include <EnergyPlus/Psychrometrics.hh>
72 : #include <EnergyPlus/RoomAirModelUserTempPattern.hh>
73 : #include <EnergyPlus/ScheduleManager.hh>
74 : #include <EnergyPlus/UtilityRoutines.hh>
75 : #include <EnergyPlus/ZoneTempPredictorCorrector.hh>
76 :
77 : namespace EnergyPlus::RoomAir {
78 :
79 : // MODULE INFORMATION:
80 : // AUTHOR Brent Griffith
81 : // DATE WRITTEN August 2005 (started in January 2004)
82 : // RE-ENGINEERED
83 :
84 : // PURPOSE OF THIS MODULE:
85 : // This module is the main module for running the
86 : // user-defined temperature pattern model.
87 : // This "air model" doesn't predict anything about the room air
88 : // but provides a method for users to model the
89 : // impact of non-uniform air temps. the distribution of air temperatures
90 : // is defined by the user and referred to as a "pattern"
91 :
92 : // METHODOLOGY EMPLOYED:
93 : // This module contains all subroutines required by the
94 : // user defined temperature pattern roomair modeling.
95 : // See DataRoomAir.cc for variable declarations
96 :
97 : // Functions
98 :
99 0 : void ManageUserDefinedPatterns(EnergyPlusData &state, int const ZoneNum) // index number for the specified zone
100 : {
101 :
102 : // SUBROUTINE INFORMATION:
103 : // AUTHOR Brent Griffith
104 : // DATE WRITTEN January 2004/Aug 2005
105 : // MODIFIED na
106 : // RE-ENGINEERED na
107 :
108 : // PURPOSE OF THIS SUBROUTINE:
109 : // manage the user-defined air temp. distribution model
110 :
111 : // transfer data from surface domain to air domain for the specified zone
112 0 : InitTempDistModel(state, ZoneNum);
113 :
114 0 : GetSurfHBDataForTempDistModel(state, ZoneNum);
115 :
116 : // perform TempDist model calculations
117 0 : CalcTempDistModel(state, ZoneNum);
118 :
119 : // transfer data from air domain back to surface domain for the specified zone
120 0 : SetSurfHBDataForTempDistModel(state, ZoneNum);
121 0 : }
122 :
123 : //****************************************************
124 :
125 0 : void InitTempDistModel(EnergyPlusData &state, int const ZoneNum) // index number for the specified zone
126 : {
127 :
128 : // SUBROUTINE INFORMATION:
129 : // AUTHOR <author>
130 : // DATE WRITTEN <date_written>
131 :
132 0 : if (state.dataRoomAirModelTempPattern->MyOneTimeFlag) {
133 0 : state.dataRoomAirModelTempPattern->MyEnvrnFlag.dimension(state.dataGlobal->NumOfZones, true);
134 0 : state.dataRoomAirModelTempPattern->MyOneTimeFlag = false;
135 : }
136 :
137 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
138 0 : if (state.dataGlobal->BeginEnvrnFlag && state.dataRoomAirModelTempPattern->MyEnvrnFlag(ZoneNum)) {
139 0 : patternZoneInfo.TairMean = 23.0;
140 0 : patternZoneInfo.Tstat = 23.0;
141 0 : patternZoneInfo.Tleaving = 23.0;
142 0 : patternZoneInfo.Texhaust = 23.0;
143 0 : patternZoneInfo.Gradient = 0.0;
144 0 : for (int SurfNum = 1; SurfNum <= patternZoneInfo.totNumSurfs; ++SurfNum) {
145 0 : patternZoneInfo.Surf(SurfNum).TadjacentAir = 23.0;
146 : }
147 0 : state.dataRoomAirModelTempPattern->MyEnvrnFlag(ZoneNum) = false;
148 : }
149 :
150 0 : if (!state.dataGlobal->BeginEnvrnFlag) state.dataRoomAirModelTempPattern->MyEnvrnFlag(ZoneNum) = true;
151 :
152 : // init report variable
153 0 : patternZoneInfo.Gradient = 0.0;
154 0 : }
155 :
156 0 : void GetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // index number for the specified zone
157 : {
158 :
159 : // SUBROUTINE INFORMATION:
160 : // AUTHOR B. Griffith
161 : // DATE WRITTEN August 2005
162 :
163 : // PURPOSE OF THIS SUBROUTINE:
164 : // map data from Heat Balance domain to Room Air Modeling Domain
165 : // for the current zone, (only need mean air temp)
166 : // also acts as an init routine
167 :
168 : // METHODOLOGY EMPLOYED:
169 : // use ZT from DataHeatBalFanSys
170 :
171 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
172 0 : auto const &zoneHeatBal = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
173 : // initialize in preparation for calculations
174 0 : patternZoneInfo.Tstat = zoneHeatBal.MAT;
175 0 : patternZoneInfo.Tleaving = zoneHeatBal.MAT;
176 0 : patternZoneInfo.Texhaust = zoneHeatBal.MAT;
177 0 : for (auto &e : patternZoneInfo.Surf)
178 0 : e.TadjacentAir = zoneHeatBal.MAT;
179 :
180 : // the only input this method needs is the zone MAT or ZT or ZTAV ? (original was ZT)
181 0 : patternZoneInfo.TairMean = zoneHeatBal.MAT; // this is lagged from previous corrector result
182 0 : }
183 :
184 : //*****************************************************************************************
185 :
186 0 : void CalcTempDistModel(EnergyPlusData &state, int const ZoneNum) // index number for the specified zone
187 : {
188 :
189 : // SUBROUTINE INFORMATION:
190 : // AUTHOR Brent Griffith
191 : // DATE WRITTEN August 2005
192 : // MODIFIED
193 : // RE-ENGINEERED
194 :
195 : // PURPOSE OF THIS SUBROUTINE:
196 : // figure out which pattern is scheduled and call
197 : // appropriate subroutine
198 :
199 : // Using/Aliasing
200 : using General::FindNumberInList;
201 :
202 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
203 : // first determine availability
204 0 : Real64 AvailTest = patternZoneInfo.availSched->getCurrentVal();
205 :
206 0 : if ((AvailTest != 1.0) || (!patternZoneInfo.IsUsed)) {
207 : // model not to be used. Use complete mixing method
208 :
209 0 : patternZoneInfo.Tstat = patternZoneInfo.TairMean;
210 0 : patternZoneInfo.Tleaving = patternZoneInfo.TairMean;
211 0 : patternZoneInfo.Texhaust = patternZoneInfo.TairMean;
212 0 : for (auto &e : patternZoneInfo.Surf)
213 0 : e.TadjacentAir = patternZoneInfo.TairMean;
214 :
215 0 : return;
216 :
217 : } else { // choose pattern and call subroutine
218 :
219 0 : int CurntPatternKey = patternZoneInfo.patternSched->getCurrentVal();
220 :
221 0 : int CurPatrnID = FindNumberInList(CurntPatternKey, state.dataRoomAir->AirPattern, &TemperaturePattern::PatrnID);
222 :
223 0 : if (CurPatrnID == 0) {
224 : // throw error here ? way to test schedules before getting to this point?
225 0 : ShowFatalError(state, format("User defined room air pattern index not found: {}", CurntPatternKey));
226 0 : return;
227 : }
228 :
229 0 : switch (state.dataRoomAir->AirPattern(CurPatrnID).PatternMode) {
230 0 : case UserDefinedPatternType::ConstGradTemp: {
231 0 : FigureConstGradPattern(state, CurPatrnID, ZoneNum);
232 0 : } break;
233 0 : case UserDefinedPatternType::TwoGradInterp: {
234 0 : FigureTwoGradInterpPattern(state, CurPatrnID, ZoneNum);
235 0 : } break;
236 0 : case UserDefinedPatternType::NonDimenHeight: {
237 0 : FigureHeightPattern(state, CurPatrnID, ZoneNum);
238 0 : } break;
239 0 : case UserDefinedPatternType::SurfMapTemp: {
240 0 : FigureSurfMapPattern(state, CurPatrnID, ZoneNum);
241 0 : } break;
242 0 : default: {
243 0 : assert(false);
244 : } break;
245 : }
246 : } // availability control construct
247 : }
248 :
249 0 : void FigureSurfMapPattern(EnergyPlusData &state, int const PattrnID, int const ZoneNum)
250 : {
251 :
252 : // SUBROUTINE INFORMATION:
253 : // AUTHOR B Griffith
254 : // DATE WRITTEN August 2005
255 : // MODIFIED na
256 : // RE-ENGINEERED na
257 :
258 : // PURPOSE OF THIS SUBROUTINE:
259 : // main calculation routine for surface pattern
260 :
261 : // METHODOLOGY EMPLOYED:
262 : // simple polling and applying prescribed
263 : // delta Tai's to current mean air temp
264 : // on a surface by surface basis
265 :
266 : // Using/Aliasing
267 : using General::FindNumberInList;
268 :
269 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
270 0 : auto &pattern = state.dataRoomAir->AirPattern(PattrnID);
271 0 : Real64 Tmean = patternZoneInfo.TairMean;
272 :
273 0 : for (int i = 1; i <= patternZoneInfo.totNumSurfs; ++i) {
274 : // cycle through zone surfaces and look for match
275 0 : int found = FindNumberInList(patternZoneInfo.Surf(i).SurfID, pattern.MapPatrn.SurfID, pattern.MapPatrn.NumSurfs);
276 0 : if (found != 0) { // if surf is in map then assign, else give it MAT
277 0 : patternZoneInfo.Surf(i).TadjacentAir = pattern.MapPatrn.DeltaTai(found) + Tmean;
278 : } else {
279 0 : patternZoneInfo.Surf(i).TadjacentAir = Tmean;
280 : }
281 : }
282 :
283 0 : patternZoneInfo.Tstat = pattern.DeltaTstat + Tmean;
284 0 : patternZoneInfo.Tleaving = pattern.DeltaTleaving + Tmean;
285 0 : patternZoneInfo.Texhaust = pattern.DeltaTexhaust + Tmean;
286 0 : }
287 :
288 0 : void FigureHeightPattern(EnergyPlusData &state, int const PattrnID, int const ZoneNum)
289 : {
290 :
291 : // SUBROUTINE INFORMATION:
292 : // AUTHOR B Griffith
293 : // DATE WRITTEN August 2005
294 :
295 : // PURPOSE OF THIS SUBROUTINE:
296 : // calculate the pattern for non-dimensional vertical profile
297 :
298 : // METHODOLOGY EMPLOYED:
299 : // treat profile as lookup table and interpolate
300 :
301 : // Using/Aliasing
302 : using Fluid::FindArrayIndex;
303 :
304 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
305 :
306 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
307 0 : auto &pattern = state.dataRoomAir->AirPattern(PattrnID);
308 0 : Real64 tmpDeltaTai = 0.0;
309 0 : Real64 Tmean = patternZoneInfo.TairMean;
310 :
311 0 : for (int i = 1; i <= patternZoneInfo.totNumSurfs; ++i) {
312 :
313 0 : Real64 zeta = patternZoneInfo.Surf(i).Zeta;
314 0 : int lowSideID = FindArrayIndex(zeta, pattern.VertPatrn.ZetaPatrn);
315 0 : int highSideID = lowSideID + 1;
316 0 : if (lowSideID == 0) lowSideID = 1; // protect against array bounds
317 :
318 0 : Real64 lowSideZeta = pattern.VertPatrn.ZetaPatrn(lowSideID);
319 0 : Real64 hiSideZeta = (highSideID <= isize(pattern.VertPatrn.ZetaPatrn)) ? pattern.VertPatrn.ZetaPatrn(highSideID) : lowSideZeta;
320 :
321 0 : if ((hiSideZeta - lowSideZeta) != 0.0) {
322 0 : Real64 fractBtwn = (zeta - lowSideZeta) / (hiSideZeta - lowSideZeta);
323 0 : tmpDeltaTai = pattern.VertPatrn.DeltaTaiPatrn(lowSideID) +
324 0 : fractBtwn * (pattern.VertPatrn.DeltaTaiPatrn(highSideID) - pattern.VertPatrn.DeltaTaiPatrn(lowSideID));
325 :
326 : } else { // would divide by zero, using low side value
327 :
328 0 : tmpDeltaTai = pattern.VertPatrn.DeltaTaiPatrn(lowSideID);
329 : }
330 :
331 0 : patternZoneInfo.Surf(i).TadjacentAir = tmpDeltaTai + Tmean;
332 :
333 : } // surfaces in this zone
334 :
335 0 : patternZoneInfo.Tstat = pattern.DeltaTstat + Tmean;
336 0 : patternZoneInfo.Tleaving = pattern.DeltaTleaving + Tmean;
337 0 : patternZoneInfo.Texhaust = pattern.DeltaTexhaust + Tmean;
338 0 : }
339 :
340 0 : void FigureTwoGradInterpPattern(EnergyPlusData &state, int const PattrnID, int const ZoneNum)
341 : {
342 :
343 : // SUBROUTINE INFORMATION:
344 : // AUTHOR B Griffith
345 : // DATE WRITTEN Aug 2005
346 :
347 : // PURPOSE OF THIS SUBROUTINE:
348 : // calculate two gradient interpolation pattern
349 :
350 : // METHODOLOGY EMPLOYED:
351 : // Case statement controls how interpolations are done
352 : // based on user selected mode.
353 : // calculations vary by mode
354 :
355 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
356 : Real64 Grad; // vertical temperature gradient C/m
357 :
358 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
359 0 : auto const &pattern = state.dataRoomAir->AirPattern(PattrnID);
360 :
361 0 : if (state.dataRoomAirModelTempPattern->MyOneTimeFlag2) {
362 0 : state.dataRoomAirModelTempPattern->SetupOutputFlag.dimension(state.dataGlobal->NumOfZones, true); // init
363 0 : state.dataRoomAirModelTempPattern->MyOneTimeFlag2 = false;
364 : }
365 :
366 0 : if (state.dataRoomAirModelTempPattern->SetupOutputFlag(ZoneNum)) {
367 0 : SetupOutputVariable(state,
368 : "Room Air Zone Vertical Temperature Gradient",
369 : Constant::Units::K_m,
370 0 : patternZoneInfo.Gradient,
371 : OutputProcessor::TimeStepType::System,
372 : OutputProcessor::StoreType::Average,
373 0 : patternZoneInfo.ZoneName);
374 :
375 0 : state.dataRoomAirModelTempPattern->SetupOutputFlag(ZoneNum) = false;
376 : }
377 :
378 0 : Real64 Tmean = patternZoneInfo.TairMean;
379 :
380 0 : auto const &twoGrad = pattern.TwoGradPatrn;
381 : // determine gradient depending on mode
382 0 : switch (pattern.TwoGradPatrn.InterpolationMode) {
383 0 : case UserDefinedPatternMode::OutdoorDryBulb: {
384 0 : Grad = OutdoorDryBulbGrad(state.dataHeatBal->Zone(ZoneNum).OutDryBulbTemp,
385 0 : twoGrad.UpperBoundTempScale,
386 0 : twoGrad.HiGradient,
387 0 : twoGrad.LowerBoundTempScale,
388 0 : twoGrad.LowGradient);
389 0 : } break;
390 0 : case UserDefinedPatternMode::ZoneAirTemp: {
391 0 : if (Tmean >= twoGrad.UpperBoundTempScale) {
392 0 : Grad = twoGrad.HiGradient;
393 0 : } else if (Tmean <= twoGrad.LowerBoundTempScale) {
394 0 : Grad = twoGrad.LowGradient;
395 0 : } else if ((twoGrad.UpperBoundTempScale - twoGrad.LowerBoundTempScale) == 0.0) {
396 : // bad user input, trapped during get input
397 0 : Grad = twoGrad.LowGradient;
398 : } else {
399 0 : Grad = twoGrad.LowGradient + ((Tmean - twoGrad.LowerBoundTempScale) / (twoGrad.UpperBoundTempScale - twoGrad.LowerBoundTempScale)) *
400 0 : (twoGrad.HiGradient - twoGrad.LowGradient);
401 : }
402 0 : } break;
403 0 : case UserDefinedPatternMode::DeltaOutdoorZone: {
404 0 : Real64 DeltaT = state.dataHeatBal->Zone(ZoneNum).OutDryBulbTemp - Tmean;
405 0 : if (DeltaT >= twoGrad.UpperBoundTempScale) {
406 0 : Grad = twoGrad.HiGradient;
407 0 : } else if (DeltaT <= twoGrad.LowerBoundTempScale) {
408 0 : Grad = twoGrad.LowGradient;
409 0 : } else if ((twoGrad.UpperBoundTempScale - twoGrad.LowerBoundTempScale) == 0.0) {
410 0 : Grad = twoGrad.LowGradient;
411 : } else {
412 0 : Grad = twoGrad.LowGradient + ((DeltaT - twoGrad.LowerBoundTempScale) / (twoGrad.UpperBoundTempScale - twoGrad.LowerBoundTempScale)) *
413 0 : (twoGrad.HiGradient - twoGrad.LowGradient);
414 : }
415 0 : } break;
416 0 : case UserDefinedPatternMode::SensibleCooling: {
417 0 : Real64 CoolLoad = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).airSysCoolRate;
418 0 : if (CoolLoad >= twoGrad.UpperBoundHeatRateScale) {
419 0 : Grad = twoGrad.HiGradient;
420 :
421 0 : } else if (CoolLoad <= twoGrad.LowerBoundHeatRateScale) {
422 :
423 0 : Grad = twoGrad.LowGradient;
424 : } else { // interpolate
425 0 : if ((twoGrad.UpperBoundHeatRateScale - twoGrad.LowerBoundHeatRateScale) == 0.0) {
426 0 : Grad = twoGrad.LowGradient;
427 : } else {
428 :
429 0 : Grad = twoGrad.LowGradient +
430 0 : ((CoolLoad - twoGrad.LowerBoundHeatRateScale) / (twoGrad.UpperBoundHeatRateScale - twoGrad.LowerBoundHeatRateScale)) *
431 0 : (twoGrad.HiGradient - twoGrad.LowGradient);
432 : }
433 : }
434 0 : } break;
435 0 : case UserDefinedPatternMode::SensibleHeating: {
436 0 : Real64 HeatLoad = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).airSysHeatRate;
437 0 : if (HeatLoad >= twoGrad.UpperBoundHeatRateScale) {
438 0 : Grad = twoGrad.HiGradient;
439 0 : } else if (HeatLoad <= twoGrad.LowerBoundHeatRateScale) {
440 0 : Grad = twoGrad.LowGradient;
441 0 : } else if ((twoGrad.UpperBoundHeatRateScale - twoGrad.LowerBoundHeatRateScale) == 0.0) {
442 0 : Grad = twoGrad.LowGradient;
443 : } else {
444 0 : Grad = twoGrad.LowGradient +
445 0 : ((HeatLoad - twoGrad.LowerBoundHeatRateScale) / (twoGrad.UpperBoundHeatRateScale - twoGrad.LowerBoundHeatRateScale)) *
446 0 : (twoGrad.HiGradient - twoGrad.LowGradient);
447 : }
448 0 : } break;
449 0 : default:
450 0 : break;
451 : }
452 :
453 0 : Real64 ZetaTmean = 0.5; // by definition,
454 :
455 0 : for (int i = 1; i <= patternZoneInfo.totNumSurfs; ++i) {
456 0 : Real64 zeta = patternZoneInfo.Surf(i).Zeta;
457 0 : Real64 DeltaHeight = -1.0 * (ZetaTmean - zeta) * patternZoneInfo.ZoneHeight;
458 0 : patternZoneInfo.Surf(i).TadjacentAir = (DeltaHeight * Grad) + Tmean;
459 : }
460 :
461 0 : patternZoneInfo.Tstat = -1.0 * (0.5 * patternZoneInfo.ZoneHeight - twoGrad.TstatHeight) * Grad + Tmean;
462 0 : patternZoneInfo.Tleaving = -1.0 * (0.5 * patternZoneInfo.ZoneHeight - twoGrad.TleavingHeight) * Grad + Tmean;
463 0 : patternZoneInfo.Texhaust = -1.0 * (0.5 * patternZoneInfo.ZoneHeight - twoGrad.TexhaustHeight) * Grad + Tmean;
464 0 : patternZoneInfo.Gradient = Grad;
465 0 : }
466 :
467 4 : Real64 OutdoorDryBulbGrad(Real64 DryBulbTemp, // Zone(ZoneNum).OutDryBulbTemp
468 : Real64 UpperBound, // RoomAirPattern(PattrnID).TwoGradPatrn.UpperBoundTempScale
469 : Real64 HiGradient, // RoomAirPattern(PattrnID).TwoGradPatrn.HiGradient
470 : Real64 LowerBound, // RoomAirPattern(PattrnID).TwoGradPatrn.LowerBoundTempScale
471 : Real64 LowGradient // RoomAirPattern(PattrnID).TwoGradPatrn.LowGradient
472 : )
473 : {
474 4 : if (DryBulbTemp >= UpperBound) {
475 1 : return HiGradient;
476 3 : } else if (DryBulbTemp <= LowerBound) {
477 2 : return LowGradient;
478 1 : } else if ((UpperBound - LowerBound) == 0.0) {
479 0 : return LowGradient;
480 : } else {
481 1 : return LowGradient + ((DryBulbTemp - LowerBound) / (UpperBound - LowerBound)) * (HiGradient - LowGradient);
482 : }
483 : }
484 :
485 0 : void FigureConstGradPattern(EnergyPlusData &state, int const PattrnID, int const ZoneNum)
486 : {
487 :
488 : // SUBROUTINE INFORMATION:
489 : // AUTHOR B. Griffith
490 : // DATE WRITTEN August 2005
491 :
492 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
493 0 : auto const &pattern = state.dataRoomAir->AirPattern(PattrnID);
494 0 : Real64 Tmean = patternZoneInfo.TairMean; // MAT
495 0 : Real64 Grad = pattern.GradPatrn.Gradient; // Vertical temperature gradient
496 :
497 0 : Real64 ZetaTmean = 0.5; // non-dimensional height for MAT
498 :
499 0 : for (int i = 1; i <= patternZoneInfo.totNumSurfs; ++i) {
500 0 : Real64 zeta = patternZoneInfo.Surf(i).Zeta;
501 0 : Real64 DeltaHeight = -1.0 * (ZetaTmean - zeta) * patternZoneInfo.ZoneHeight;
502 0 : patternZoneInfo.Surf(i).TadjacentAir = DeltaHeight * Grad + Tmean;
503 : }
504 :
505 0 : patternZoneInfo.Tstat = pattern.DeltaTstat + Tmean;
506 0 : patternZoneInfo.Tleaving = pattern.DeltaTleaving + Tmean;
507 0 : patternZoneInfo.Texhaust = pattern.DeltaTexhaust + Tmean;
508 0 : }
509 :
510 : //*****************************************************************************************
511 :
512 0 : Real64 FigureNDheightInZone(EnergyPlusData &state, int const thisHBsurf) // index in main Surface array
513 : {
514 : // FUNCTION INFORMATION:
515 : // AUTHOR B.Griffith
516 : // DATE WRITTEN aug 2005, Jan2004
517 :
518 : // PURPOSE OF THIS FUNCTION:
519 : // return a non-dimensional height zeta
520 :
521 : // METHODOLOGY EMPLOYED:
522 : // figure average floor height (follows code in surfacegeometry.cc
523 : // use ceiling height from Zone structure
524 : // non dimensionalize surface's centroid's Z value
525 :
526 : // FUNCTION PARAMETER DEFINITIONS:
527 0 : Real64 constexpr TolValue(0.0001);
528 :
529 : // Get the centroid height for the surface
530 0 : Real64 Zcm = state.dataSurface->Surface(thisHBsurf).Centroid.z;
531 0 : auto &zone = state.dataHeatBal->Zone(state.dataSurface->Surface(thisHBsurf).Zone);
532 :
533 : // this next Do block is copied from SurfaceGeometry.cc with modification for just floor Z
534 : // used find floor z.
535 0 : int FloorCount = 0;
536 0 : Real64 ZFlrAvg = 0.0;
537 0 : Real64 ZMax = 0.0;
538 0 : Real64 ZMin = 0.0;
539 0 : int Count = 0;
540 0 : for (int spaceNum : zone.spaceIndexes) {
541 0 : auto const &thisSpace = state.dataHeatBal->space(spaceNum);
542 0 : for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) {
543 0 : auto const &surf = state.dataSurface->Surface(SurfNum);
544 0 : if (surf.Class == DataSurfaces::SurfaceClass::Floor) {
545 : // Use Average Z for surface, more important for roofs than floors...
546 0 : ++FloorCount;
547 0 : Real64 Z1 = minval(surf.Vertex, &Vector3<Real64>::z);
548 0 : Real64 Z2 = maxval(surf.Vertex, &Vector3<Real64>::z);
549 0 : ZFlrAvg += (Z1 + Z2) / 2.0;
550 0 : } else if (surf.Class == DataSurfaces::SurfaceClass::Wall) {
551 : // Use Wall calculation in case no floor in zone
552 0 : ++Count;
553 0 : if (Count == 1) {
554 0 : ZMax = surf.Vertex(1).z;
555 0 : ZMin = ZMax;
556 : }
557 0 : ZMax = max(ZMax, maxval(surf.Vertex, &Vector3<Real64>::z));
558 0 : ZMin = min(ZMin, minval(surf.Vertex, &Vector3<Real64>::z));
559 : }
560 : }
561 : }
562 :
563 0 : ZFlrAvg = (FloorCount > 0.0) ? (ZFlrAvg / FloorCount) : ZMin;
564 :
565 0 : Real64 ZoneZorig = ZFlrAvg; // Z floor [M]
566 0 : Real64 ZoneCeilHeight = zone.CeilingHeight;
567 :
568 : // first check if some basic things are reasonable
569 :
570 0 : Real64 SurfMinZ = minval(state.dataSurface->Surface(thisHBsurf).Vertex, &Vector3<Real64>::z);
571 0 : Real64 SurfMaxZ = maxval(state.dataSurface->Surface(thisHBsurf).Vertex, &Vector3<Real64>::z);
572 :
573 0 : if (SurfMinZ < (ZoneZorig - TolValue)) {
574 0 : if (state.dataGlobal->DisplayExtraWarnings) {
575 0 : ShowWarningError(state, "RoomAirModelUserTempPattern: Problem in non-dimensional height calculation");
576 0 : ShowContinueError(state, format("too low surface: {} in zone: {}", state.dataSurface->Surface(thisHBsurf).Name, zone.Name));
577 0 : ShowContinueError(state, format("**** Average floor height of zone is: {:.3R}", ZoneZorig));
578 0 : ShowContinueError(state, format("**** Surface minimum height is: {:.3R}", SurfMinZ));
579 : } else {
580 0 : ++state.dataErrTracking->TotalRoomAirPatternTooLow;
581 : }
582 : }
583 :
584 0 : if (SurfMaxZ > (ZoneZorig + ZoneCeilHeight + TolValue)) {
585 0 : if (state.dataGlobal->DisplayExtraWarnings) {
586 0 : ShowWarningError(state, "RoomAirModelUserTempPattern: Problem in non-dimensional height calculation");
587 0 : ShowContinueError(state, format(" too high surface: {} in zone: {}", state.dataSurface->Surface(thisHBsurf).Name, zone.Name));
588 0 : ShowContinueError(state, format("**** Average Ceiling height of zone is: {:.3R}", (ZoneZorig + ZoneCeilHeight)));
589 0 : ShowContinueError(state, format("**** Surface Maximum height is: {:.3R}", SurfMaxZ));
590 : } else {
591 0 : ++state.dataErrTracking->TotalRoomAirPatternTooHigh;
592 : }
593 : }
594 :
595 : // non dimensionalize.
596 0 : Real64 Zeta = (Zcm - ZoneZorig) / ZoneCeilHeight;
597 0 : if (Zeta > 0.99)
598 0 : Zeta = 0.99;
599 0 : else if (Zeta < 0.01)
600 0 : Zeta = 0.01;
601 :
602 0 : return Zeta;
603 : }
604 :
605 : //***************************************************
606 :
607 0 : void SetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // index number for the specified zone
608 : {
609 :
610 : // SUBROUTINE INFORMATION:
611 : // AUTHOR Brent Griffith
612 : // DATE WRITTEN August 2005,Feb. 2004
613 :
614 : // PURPOSE OF THIS SUBROUTINE:
615 : // map data from air domain back to surface domain for each zone
616 : // collects code couples to remote data structures
617 :
618 : // METHODOLOGY EMPLOYED:
619 : // sets values in Heat balance variables
620 :
621 : // Using/Aliasing
622 : using HVAC::RetTempMax;
623 : using HVAC::RetTempMin;
624 : using InternalHeatGains::SumAllReturnAirLatentGains;
625 : using Psychrometrics::PsyCpAirFnW;
626 : using Psychrometrics::PsyHFnTdbW;
627 : using Psychrometrics::PsyHgAirFnWTdb;
628 : using Psychrometrics::PsyRhoAirFnPbTdbW;
629 :
630 : // set air system leaving node conditions
631 : // this is not so easy. THis task is normally done in CalcZoneLeavingConditions
632 : // but efforts to do this update there were not successful.
633 : // Need to revisit how to best implement this. Ended up taking code from CalcZoneLeavingConditions
634 : // ZoneNum is already equal to ActualZoneNum , changed block of source
635 :
636 0 : auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum);
637 :
638 0 : if (patternZoneInfo.ZoneNodeID != 0) {
639 : // the zone system node should get the conditions leaving the zone (but before return air heat gains are added).
640 0 : state.dataLoopNodes->Node(patternZoneInfo.ZoneNodeID).Temp = patternZoneInfo.Tleaving;
641 : }
642 :
643 : // What if ZoneNodeID is 0?
644 :
645 0 : auto &zoneNode = state.dataLoopNodes->Node(patternZoneInfo.ZoneNodeID);
646 0 : auto const &zone = state.dataHeatBal->Zone(ZoneNum);
647 0 : auto &zoneHeatBal = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
648 :
649 0 : int ZoneMult = zone.Multiplier * zone.ListMultiplier;
650 :
651 0 : for (int returnNodeNum : state.dataZoneEquip->ZoneEquipConfig(ZoneNum).ReturnNode) {
652 : // BEGIN BLOCK of code from CalcZoneLeavingConditions*********************************
653 0 : auto &returnNode = state.dataLoopNodes->Node(returnNodeNum);
654 :
655 : // RETURN AIR HEAT GAIN from the Lights statement; this heat gain is stored in
656 : // Add sensible heat gain from refrigerated cases with under case returns
657 0 : Real64 QRetAir = InternalHeatGains::zoneSumAllReturnAirConvectionGains(state, ZoneNum, returnNodeNum);
658 :
659 0 : Real64 CpAir = PsyCpAirFnW(zoneNode.HumRat);
660 :
661 : // Need to add the energy to the return air from lights and from airflow windows. Where the heat
662 : // is added depends on if there is system flow or not. If there is system flow the heat is added
663 : // to the Zone Return Node. If there is no system flow then the heat is added back to the zone in the
664 : // Correct step through the SysDepZoneLoads variable.
665 :
666 0 : Real64 MassFlowRA = returnNode.MassFlowRate / ZoneMult;
667 0 : Real64 TempZoneAir = patternZoneInfo.Tleaving; // key difference from
668 0 : Real64 TempRetAir = TempZoneAir;
669 0 : Real64 WinGapFlowToRA = 0.0;
670 0 : Real64 WinGapTtoRA = 0.0;
671 0 : Real64 WinGapFlowTtoRA = 0.0;
672 :
673 0 : if (zone.HasAirFlowWindowReturn) {
674 0 : for (int spaceNum : zone.spaceIndexes) {
675 0 : auto const &thisSpace = state.dataHeatBal->space(spaceNum);
676 0 : for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) {
677 0 : if (state.dataSurface->SurfWinAirflowThisTS(SurfNum) > 0.0 &&
678 0 : state.dataSurface->SurfWinAirflowDestination(SurfNum) == DataSurfaces::WindowAirFlowDestination::Return) {
679 : Real64 FlowThisTS =
680 0 : PsyRhoAirFnPbTdbW(
681 0 : state, state.dataEnvrn->OutBaroPress, state.dataSurface->SurfWinTAirflowGapOutlet(SurfNum), zoneNode.HumRat) *
682 0 : state.dataSurface->SurfWinAirflowThisTS(SurfNum) * state.dataSurface->Surface(SurfNum).Width;
683 0 : WinGapFlowToRA += FlowThisTS;
684 0 : WinGapFlowTtoRA += FlowThisTS * state.dataSurface->SurfWinTAirflowGapOutlet(SurfNum);
685 : }
686 : }
687 : }
688 : }
689 0 : if (WinGapFlowToRA > 0.0) WinGapTtoRA = WinGapFlowTtoRA / WinGapFlowToRA;
690 :
691 0 : if (!zone.NoHeatToReturnAir) {
692 0 : if (MassFlowRA > 0.0) {
693 0 : if (WinGapFlowToRA > 0.0) {
694 : // Add heat-to-return from window gap airflow
695 0 : if (MassFlowRA >= WinGapFlowToRA) {
696 0 : TempRetAir = (WinGapFlowTtoRA + (MassFlowRA - WinGapFlowToRA) * TempZoneAir) / MassFlowRA;
697 : } else {
698 : // All of return air comes from flow through airflow windows
699 0 : TempRetAir = WinGapTtoRA;
700 : // Put heat from window airflow that exceeds return air flow into zone air
701 0 : zoneHeatBal.SysDepZoneLoads += (WinGapFlowToRA - MassFlowRA) * CpAir * (WinGapTtoRA - TempZoneAir);
702 : }
703 : }
704 : // Add heat-to-return from lights
705 0 : TempRetAir += QRetAir / (MassFlowRA * CpAir);
706 0 : if (TempRetAir > RetTempMax) {
707 0 : returnNode.Temp = RetTempMax;
708 0 : if (!state.dataGlobal->ZoneSizingCalc) {
709 0 : zoneHeatBal.SysDepZoneLoads += CpAir * MassFlowRA * (TempRetAir - RetTempMax);
710 : }
711 0 : } else if (TempRetAir < RetTempMin) {
712 0 : returnNode.Temp = RetTempMin;
713 0 : if (!state.dataGlobal->ZoneSizingCalc) {
714 0 : zoneHeatBal.SysDepZoneLoads += CpAir * MassFlowRA * (TempRetAir - RetTempMin);
715 : }
716 : } else {
717 0 : returnNode.Temp = TempRetAir;
718 : }
719 : } else { // No return air flow
720 : // Assign all heat-to-return from window gap airflow to zone air
721 0 : if (WinGapFlowToRA > 0.0) zoneHeatBal.SysDepZoneLoads += WinGapFlowToRA * CpAir * (WinGapTtoRA - TempZoneAir);
722 : // Assign all heat-to-return from lights to zone air
723 0 : if (QRetAir > 0.0) zoneHeatBal.SysDepZoneLoads += QRetAir;
724 0 : returnNode.Temp = zoneNode.Temp;
725 : }
726 : } else {
727 0 : returnNode.Temp = zoneNode.Temp;
728 : }
729 :
730 : // Update the rest of the Return Air Node conditions, if the return air system exists!
731 0 : returnNode.Press = zoneNode.Press;
732 :
733 0 : Real64 H2OHtOfVap = PsyHgAirFnWTdb(zoneNode.HumRat, returnNode.Temp);
734 :
735 : // Include impact of under case returns for refrigerated display cases when updating return node
736 : // humidity ratio
737 0 : if (!zone.NoHeatToReturnAir) {
738 0 : if (MassFlowRA > 0) {
739 0 : Real64 SumRetAirLatentGainRate = SumAllReturnAirLatentGains(state, ZoneNum, returnNodeNum);
740 0 : returnNode.HumRat = zoneNode.HumRat + (SumRetAirLatentGainRate / (H2OHtOfVap * MassFlowRA));
741 : } else {
742 : // If no mass flow rate exists, include the latent HVAC case credit with the latent Zone case credit
743 0 : returnNode.HumRat = zoneNode.HumRat;
744 0 : state.dataHeatBal->RefrigCaseCredit(ZoneNum).LatCaseCreditToZone += state.dataHeatBal->RefrigCaseCredit(ZoneNum).LatCaseCreditToHVAC;
745 : // shouldn't the HVAC term be zeroed out then?
746 0 : Real64 SumRetAirLatentGainRate = SumAllReturnAirLatentGains(state, ZoneNum, 0);
747 0 : zoneHeatBal.latentGain += SumRetAirLatentGainRate;
748 : }
749 : } else {
750 0 : returnNode.HumRat = zoneNode.HumRat;
751 0 : state.dataHeatBal->RefrigCaseCredit(ZoneNum).LatCaseCreditToZone += state.dataHeatBal->RefrigCaseCredit(ZoneNum).LatCaseCreditToHVAC;
752 : // shouldn't the HVAC term be zeroed out then?
753 :
754 0 : zoneHeatBal.latentGain += SumAllReturnAirLatentGains(state, ZoneNum, returnNodeNum);
755 : }
756 :
757 0 : returnNode.Enthalpy = PsyHFnTdbW(returnNode.Temp, returnNode.HumRat);
758 :
759 : // END BLOCK of code from CalcZoneLeavingConditions*********************************
760 : }
761 :
762 : // set exhaust node leaving temp if present
763 0 : if (allocated(patternZoneInfo.ExhaustAirNodeID)) {
764 0 : for (int exhaustAirNodeID : patternZoneInfo.ExhaustAirNodeID) {
765 0 : state.dataLoopNodes->Node(exhaustAirNodeID).Temp = patternZoneInfo.Texhaust;
766 : }
767 : }
768 :
769 : // set thermostat reading for air system .
770 0 : state.dataHeatBalFanSys->TempTstatAir(ZoneNum) = patternZoneInfo.Tstat;
771 :
772 : // set results for all surface
773 0 : for (int spaceNum : zone.spaceIndexes) {
774 0 : auto const &thisSpace = state.dataHeatBal->space(spaceNum);
775 0 : for (int i = thisSpace.HTSurfaceFirst, j = 0; i <= thisSpace.HTSurfaceLast; ++i) {
776 0 : state.dataHeatBal->SurfTempEffBulkAir(i) = patternZoneInfo.Surf(++j).TadjacentAir;
777 : }
778 : }
779 :
780 : // set flag for reference air temperature mode
781 0 : for (int spaceNum : zone.spaceIndexes) {
782 0 : auto const &thisSpace = state.dataHeatBal->space(spaceNum);
783 0 : for (int i = thisSpace.HTSurfaceFirst; i <= thisSpace.HTSurfaceLast; ++i) {
784 0 : state.dataSurface->SurfTAirRef(i) = DataSurfaces::RefAirTemp::AdjacentAirTemp;
785 0 : state.dataSurface->SurfTAirRefRpt(i) = DataSurfaces::SurfTAirRefReportVals[state.dataSurface->SurfTAirRef(i)];
786 : }
787 : }
788 0 : }
789 :
790 : //*****************************************************************************************
791 :
792 : } // namespace EnergyPlus::RoomAir
|