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 : #ifndef HeatBalFiniteDiffManager_hh_INCLUDED
49 : #define HeatBalFiniteDiffManager_hh_INCLUDED
50 :
51 : // ObjexxFCL Headers
52 : #include <ObjexxFCL/Array1D.hh>
53 : #include <ObjexxFCL/Array2D.hh>
54 :
55 : // EnergyPlus Headers
56 : #include <EnergyPlus/Data/BaseData.hh>
57 : #include <EnergyPlus/DataGlobals.hh>
58 : #include <EnergyPlus/DataHeatBalance.hh>
59 : #include <EnergyPlus/EnergyPlus.hh>
60 : #include <EnergyPlus/Material.hh>
61 : #include <EnergyPlus/PhaseChangeModeling/HysteresisModel.hh>
62 :
63 : namespace EnergyPlus {
64 :
65 : // Forward declarations
66 : struct EnergyPlusData;
67 :
68 : namespace HeatBalFiniteDiffManager {
69 :
70 : Real64 constexpr TempInitValue(23.0); // Initialization value for Temperature
71 : Real64 constexpr RhovInitValue(0.0115); // Initialization value for Rhov
72 : Real64 constexpr EnthInitValue(100.0); // Initialization value for Enthalpy
73 : constexpr Real64 smalldiff(1.e-8); // Used in places where "equality" tests should not be used.
74 : constexpr Real64 MinTempLimit = -100.0; // lower limit check, degree C
75 : constexpr Real64 MaxTempLimit = 100.0; // upper limit check, degree C
76 :
77 : enum class CondFDScheme
78 : {
79 : Invalid = -1,
80 : CrankNicholsonSecondOrder, // original CondFD scheme. semi implicit, second order in time
81 : FullyImplicitFirstOrder, // fully implicit scheme, first order in time.
82 : Num
83 : };
84 :
85 : static constexpr std::array<std::string_view, static_cast<int>(CondFDScheme::Num)> CondFDSchemeTypeNamesCC = {"CrankNicholsonSecondOrder",
86 : "FullyImplicitFirstOrder"};
87 : static constexpr std::array<std::string_view, static_cast<int>(CondFDScheme::Num)> CondFDSchemeTypeNamesUC = {"CRANKNICHOLSONSECONDORDER",
88 : "FULLYIMPLICITFIRSTORDER"};
89 :
90 : struct ConstructionDataFD
91 : {
92 : // Members
93 : Array1D_string Name; // Name of construction
94 : Array1D<Real64> DelX;
95 : Array1D<Real64> TempStability;
96 : Array1D<Real64> MoistStability;
97 : Array1D_int NodeNumPoint;
98 : Array1D<Real64> Thickness;
99 : Array1D<Real64> NodeXlocation; // sized to TotNode, contains X distance in m from outside face
100 : int TotNodes;
101 : int DeltaTime;
102 :
103 : // Default Constructor
104 10 : ConstructionDataFD() : TotNodes(0), DeltaTime(0)
105 : {
106 10 : }
107 : };
108 :
109 : struct MaterialActuatorData
110 : {
111 : std::string actuatorName;
112 : bool isActuated;
113 : Real64 actuatedValue;
114 :
115 102 : MaterialActuatorData() : isActuated(false), actuatedValue(0.0)
116 : {
117 102 : }
118 : };
119 :
120 : struct SurfaceDataFD
121 : {
122 : // Members
123 : Array1D<Real64> T;
124 : Array1D<Real64> TOld;
125 : Array1D<Real64> TT;
126 : Array1D<Real64> Rhov;
127 : Array1D<Real64> RhovOld;
128 : Array1D<Real64> RhoT;
129 : Array1D<Real64> TD;
130 : Array1D<Real64> TDT;
131 : Array1D<Real64> TDTLast;
132 : Array1D<Real64> TDOld;
133 : Array1D<Real64> TDreport; // Node temperatures for reporting [C]
134 : Array1D<Real64> RH;
135 : Array1D<Real64> RHreport;
136 : Array1D<Real64> EnthOld; // Current node enthalpy
137 : Array1D<Real64> EnthNew; // Node enthalpy at new time
138 : Array1D<Real64> EnthLast;
139 : Array1D<Real64> QDreport; // Node heat flux for reporting [W/m2] positive is flow towards inside face of surface
140 : Array1D<Real64> CpDelXRhoS1; // Current outer half-node Cp * DelX * RhoS / Delt
141 : Array1D<Real64> CpDelXRhoS2; // Current inner half-node Cp * DelX * RhoS / Delt
142 : Array1D<Real64> TDpriortimestep; // Node temperatures from previous timestep
143 : int SourceNodeNum; // Node number for internal source layer (zero if no source)
144 : Real64 QSource; // Internal source flux [W/m2]
145 : int GSloopCounter; // count of inner loop iterations
146 : Real64 MaxNodeDelTemp; // largest change in node temps after calc
147 : int indexNodeMaxTempLimit = 0; // index for recurring error message if node temperature exceeds maximum node temperature for this surface
148 : int indexNodeMinTempLimit = 0; // index for recurring error message if node temperature is below minimum node temperature for this surfac
149 : Real64 EnthalpyM; // Melting enthalpy at a particular temperature
150 : Real64 EnthalpyF; // Freezing enthalpy at a particular temperature
151 : Array1D<Material::Phase> PhaseChangeState;
152 : Array1D<Material::Phase> PhaseChangeStateOld;
153 : Array1D<Material::Phase> PhaseChangeStateOldOld;
154 : Array1D<int> PhaseChangeStateRep;
155 : Array1D<int> PhaseChangeStateOldRep;
156 : Array1D<int> PhaseChangeStateOldOldRep;
157 : Array1D<Real64> PhaseChangeTemperatureReverse;
158 : Array1D<MaterialActuatorData> condMaterialActuators;
159 : Array1D<MaterialActuatorData> specHeatMaterialActuators;
160 : Array1D<MaterialActuatorData> heatSourceFluxMaterialActuators;
161 : Array1D<Real64> condNodeReport;
162 : Array1D<Real64> specHeatNodeReport;
163 : // Includes the internal heat source
164 : Array1D<Real64> heatSourceInternalFluxLayerReport;
165 : Array1D<Real64> heatSourceInternalFluxEnergyLayerReport;
166 : // Includes the EMS heat source
167 : Array1D<Real64> heatSourceEMSFluxLayerReport;
168 : Array1D<Real64> heatSourceEMSFluxEnergyLayerReport;
169 :
170 : // Default Constructor
171 18 : SurfaceDataFD() : SourceNodeNum(0), QSource(0.0), GSloopCounter(0), MaxNodeDelTemp(0.0), EnthalpyM(0.0), EnthalpyF(0.0), PhaseChangeState(0)
172 : {
173 18 : }
174 :
175 293832 : inline void UpdateMoistureBalance()
176 : {
177 : // Based on UpdateMoistureBalanceFD by Richard Liesen
178 : // Brought into class for performance
179 293832 : TOld = T;
180 293832 : RhovOld = Rhov;
181 293832 : TDOld = TDreport;
182 293832 : }
183 : };
184 :
185 : struct MaterialDataFD
186 : {
187 : // Members
188 : Real64 tk1; // Temperature coefficient for thermal conductivity
189 : int numTempEnth; // number of Temperature/Enthalpy pairs
190 : int numTempCond; // number of Temperature/Conductivity pairs
191 : Array2D<Real64> TempEnth; // Temperature enthalpy Function Pairs,
192 : // TempEnth(1,1)= first Temp, TempEnth(1,2) = First Enthalpy,
193 : // TempEnth(2,1) = secomd Temp, etc.
194 : Array2D<Real64> TempCond; // Temperature thermal conductivity Function Pairs,
195 : // TempCond(1,1)= first Temp, Tempcond(1,2) = First conductivity,
196 : // TempEnth(2,1) = secomd Temp, etc.
197 :
198 : // Default Constructor
199 16 : MaterialDataFD() : tk1(0.0), numTempEnth(0), numTempCond(0)
200 : {
201 16 : }
202 : };
203 :
204 : void ManageHeatBalFiniteDiff(EnergyPlusData &state,
205 : int SurfNum,
206 : Real64 &SurfTempInTmp, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
207 : Real64 &TempSurfOutTmp // Outside Surface Temperature of each Heat Transfer Surface
208 : );
209 :
210 : void GetCondFDInput(EnergyPlusData &state);
211 :
212 : int setSizeMaxProperties(EnergyPlusData &state);
213 :
214 : void InitHeatBalFiniteDiff(EnergyPlusData &state);
215 :
216 : void InitialInitHeatBalFiniteDiff(EnergyPlusData &state);
217 :
218 : int numNodesInMaterialLayer(EnergyPlusData &state, std::string const &surfName, std::string const &matName);
219 :
220 : void CalcHeatBalFiniteDiff(EnergyPlusData &state,
221 : int Surf,
222 : Real64 &SurfTempInTmp, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
223 : Real64 &TempSurfOutTmp // Outside Surface Temperature of each Heat Transfer Surface
224 : );
225 :
226 : void ReportFiniteDiffInits(EnergyPlusData &state);
227 :
228 : void CalcNodeHeatFlux(EnergyPlusData &state,
229 : int Surf, // surface number
230 : int TotNodes // number of nodes in surface
231 : );
232 :
233 : Real64 terpld(Array2<Real64> const &a, Real64 x1, int nind, int ndep);
234 :
235 : void ExteriorBCEqns(EnergyPlusData &state,
236 : int Delt, // Time Increment
237 : int i, // Node Index
238 : int Lay, // Layer Number for Construction
239 : int Surf, // Surface number
240 : Array1D<Real64> const &T, // Old node Temperature in MFD finite difference solution
241 : Array1D<Real64> &TT, // New node Temperature in MFD finite difference solution.
242 : Array1D<Real64> const &Rhov, // MFD Nodal Vapor Density[kg/m3] and is the old or last time step result.
243 : Array1D<Real64> &RhoT, // MFD vapor density for the new time step.
244 : Array1D<Real64> &RH, // Nodal relative humidity
245 : Array1D<Real64> const &TD, // The old dry Temperature at each node for the CondFD algorithm..
246 : Array1D<Real64> &TDT, // The current or new Temperature at each node location for the CondFD solution..
247 : Array1D<Real64> &EnthOld, // Old Nodal enthalpy
248 : Array1D<Real64> &EnthNew, // New Nodal enthalpy
249 : int TotNodes, // Total nodes in layer
250 : Real64 HMovInsul // Conductance of movable(transparent) insulation.
251 : );
252 :
253 : void InteriorNodeEqns(EnergyPlusData &state,
254 : int Delt, // Time Increment
255 : int i, // Node Index
256 : int Lay, // Layer Number for Construction
257 : int Surf, // Surface number
258 : Array1D<Real64> const &T, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
259 : Array1D<Real64> &TT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
260 : Array1D<Real64> const &Rhov, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
261 : Array1D<Real64> &RhoT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
262 : Array1D<Real64> &RH, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
263 : Array1D<Real64> const &TD, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
264 : Array1D<Real64> &TDT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
265 : Array1D<Real64> &EnthOld, // Old Nodal enthalpy
266 : Array1D<Real64> &EnthNew // New Nodal enthalpy
267 : );
268 :
269 : void IntInterfaceNodeEqns(EnergyPlusData &state,
270 : int Delt, // Time Increment
271 : int i, // Node Index
272 : int Lay, // Layer Number for Construction
273 : int Surf, // Surface number
274 : Array1D<Real64> const &T, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
275 : Array1D<Real64> &TT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
276 : Array1D<Real64> const &Rhov, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
277 : Array1D<Real64> &RhoT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
278 : Array1D<Real64> &RH, // RELATIVE HUMIDITY.
279 : Array1D<Real64> const &TD, // OLD NODE TEMPERATURES OF EACH HEAT TRANSFER SURF IN CONDFD.
280 : Array1D<Real64> &TDT, // NEW NODE TEMPERATURES OF EACH HEAT TRANSFER SURF IN CONDFD.
281 : Array1D<Real64> const &EnthOld, // Old Nodal enthalpy
282 : Array1D<Real64> &EnthNew, // New Nodal enthalpy
283 : int GSiter // Iteration number of Gauss Seidell iteration
284 : );
285 :
286 : void InteriorBCEqns(EnergyPlusData &state,
287 : int Delt, // Time Increment
288 : int i, // Node Index
289 : int Lay, // Layer Number for Construction
290 : int Surf, // Surface number
291 : Array1D<Real64> const &T, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF (Old).
292 : Array1D<Real64> &TT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF (New).
293 : Array1D<Real64> const &Rhov, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
294 : Array1D<Real64> &RhoT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
295 : Array1D<Real64> &RH, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
296 : Array1D<Real64> const &TD, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
297 : Array1D<Real64> &TDT, // INSIDE SURFACE TEMPERATURE OF EACH HEAT TRANSFER SURF.
298 : Array1D<Real64> &EnthOld, // Old Nodal enthalpy
299 : Array1D<Real64> &EnthNew, // New Nodal enthalpy
300 : Array1D<Real64> &TDreport // Temperature value from previous HeatSurfaceHeatManager titeration's value
301 : );
302 :
303 : void CheckFDSurfaceTempLimits(EnergyPlusData &state,
304 : int SurfNum, // surface number
305 : Real64 CheckTemperature // calculated temperature, not reset
306 : );
307 :
308 : void CheckFDNodeTempLimits(EnergyPlusData &state,
309 : int surfNum, // surface number
310 : int nodeNum, // node number
311 : Real64 &nodeTemp // calculated temperature, not reset
312 : );
313 :
314 : void adjustPropertiesForPhaseChange(EnergyPlusData &state,
315 : int finiteDifferenceLayerIndex,
316 : int surfaceIndex,
317 : Material::MaterialPhaseChange *mat,
318 : Real64 temperaturePrevious,
319 : Real64 temperatureUpdated,
320 : Real64 &updatedSpecificHeat,
321 : Real64 &updatedDensity,
322 : Real64 &updatedThermalConductivity);
323 :
324 : bool findAnySurfacesUsingConstructionAndCondFD(EnergyPlusData const &state, int const constructionNum);
325 :
326 : } // namespace HeatBalFiniteDiffManager
327 :
328 : struct HeatBalFiniteDiffMgr : BaseGlobalStruct
329 : {
330 : Array1D<Real64> SigmaR; // Total Resistance of construction layers
331 : Array1D<Real64> SigmaC; // Total Capacitance of construction layers
332 :
333 : Array1D<Real64> QHeatInFlux; // HeatFlux on Surface for reporting
334 : Array1D<Real64> QHeatOutFlux; // HeatFlux on Surface for reporting
335 :
336 : HeatBalFiniteDiffManager::CondFDScheme CondFDSchemeType =
337 : HeatBalFiniteDiffManager::CondFDScheme::FullyImplicitFirstOrder; // solution scheme for CondFD - default
338 : Real64 SpaceDescritConstant = 3.0; // spatial descritization constant,
339 : int MaxGSiter = 30; // maximum number of Gauss Seidel iterations
340 : Real64 fracTimeStepZone_Hour = 0.0;
341 : bool GetHBFiniteDiffInputFlag = true;
342 : int WarmupSurfTemp = 0;
343 :
344 : // Object Data
345 : Array1D<HeatBalFiniteDiffManager::ConstructionDataFD> ConstructFD;
346 : Array1D<HeatBalFiniteDiffManager::SurfaceDataFD> SurfaceFD;
347 : Array1D<HeatBalFiniteDiffManager::MaterialDataFD> MaterialFD;
348 : bool MyEnvrnFlag = true;
349 :
350 2126 : void init_constant_state([[maybe_unused]] EnergyPlusData &state) override
351 : {
352 2126 : }
353 :
354 1152 : void init_state([[maybe_unused]] EnergyPlusData &state) override
355 : {
356 1152 : }
357 :
358 2100 : void clear_state() override
359 : {
360 2100 : this->SigmaR.deallocate();
361 2100 : this->SigmaC.deallocate();
362 2100 : this->QHeatInFlux.deallocate();
363 2100 : this->QHeatOutFlux.deallocate();
364 2100 : this->CondFDSchemeType = HeatBalFiniteDiffManager::CondFDScheme::FullyImplicitFirstOrder;
365 2100 : this->SpaceDescritConstant = 3.0;
366 2100 : this->MaxGSiter = 30;
367 2100 : this->fracTimeStepZone_Hour = 0.0;
368 2100 : this->GetHBFiniteDiffInputFlag = true;
369 2100 : this->WarmupSurfTemp = 0;
370 2100 : this->ConstructFD.deallocate();
371 2100 : this->SurfaceFD.deallocate();
372 2100 : this->MaterialFD.deallocate();
373 2100 : this->MyEnvrnFlag = true;
374 2100 : }
375 : };
376 :
377 : } // namespace EnergyPlus
378 :
379 : #endif
|