Line data Source code
1 : // EnergyPlus, Copyright (c) 1996-2024, 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/Array1D.hh>
50 : #include <ObjexxFCL/Fmath.hh>
51 :
52 : // EnergyPlus Headers
53 : #include <EnergyPlus/Data/EnergyPlusData.hh>
54 : #include <EnergyPlus/DataGlobals.hh>
55 : #include <EnergyPlus/TARCOGCommon.hh>
56 : #include <EnergyPlus/TARCOGParams.hh>
57 :
58 : namespace EnergyPlus {
59 :
60 : namespace TARCOGCommon {
61 :
62 : // MODULE INFORMATION:
63 : // AUTHOR Simon Vidanovic
64 : // DATE WRITTEN June/22/2010
65 : // MODIFIED na
66 : // RE-ENGINEERED na
67 : // Revision: 6.0.36 (June/22/2010)
68 : // - Initial setup, extracted from TARCOG.for
69 :
70 : // PURPOSE OF THIS MODULE:
71 : // A module which contains common TARCOG functions and subroutines
72 :
73 4036 : Real64 LDSumMax(Real64 const Width, Real64 const Height)
74 : {
75 : // LDSumMax function calculates sum part of equation for maximum deflection
76 : // Width - glazing system width
77 : // Height - glazing system height
78 :
79 : // Using/Aliasing
80 : using namespace TARCOGParams;
81 :
82 : // Return value
83 : Real64 LDSumMax;
84 :
85 : // Locals
86 : int i;
87 : int j;
88 :
89 4036 : LDSumMax = 0.0;
90 16144 : for (i = 1; i <= TARCOGParams::MMax; i += 2) {
91 12108 : Real64 const sin_i(std::sin(i * Constant::PiOvr2));
92 12108 : Real64 const pow_i_W(pow_2(i / Width));
93 48432 : for (j = 1; j <= TARCOGParams::NMax; j += 2) {
94 36324 : LDSumMax += (sin_i * std::sin(j * Constant::PiOvr2)) / (i * j * pow_2(pow_i_W + pow_2(j / Height)));
95 : } // do j = 1, DeflectionParameters::NMax, 2
96 : } // do i = 1, DeflectionParameters::MMax, 2
97 :
98 4036 : return LDSumMax;
99 : }
100 :
101 4036 : Real64 LDSumMean(Real64 const Width, Real64 const Height)
102 : {
103 : // LDSumMean function calculates sum part of equation for mean deflection
104 : // Width - glazing system width
105 : // Height - glazing system height
106 :
107 : // Using/Aliasing
108 : using namespace TARCOGParams;
109 :
110 : // Return value
111 : Real64 LDSumMean;
112 :
113 : // Locals
114 4036 : Real64 constexpr Pi_squared(Constant::Pi * Constant::Pi);
115 : int i;
116 : int j;
117 :
118 4036 : LDSumMean = 0.0;
119 16144 : for (i = 1; i <= TARCOGParams::MMax; i += 2) {
120 12108 : Real64 const pow_i_Pi_2(i * i * Pi_squared);
121 12108 : Real64 const pow_i_W(pow_2(i / Width));
122 48432 : for (j = 1; j <= TARCOGParams::NMax; j += 2) {
123 36324 : LDSumMean += 4.0 / (pow_i_Pi_2 * pow_2(j) * pow_2(pow_i_W + pow_2(j / Height)));
124 : } // do j = 1, DeflectionParameters::NMax, 2
125 : } // do i = 1, MMax, 2
126 :
127 4036 : return LDSumMean;
128 : }
129 :
130 160608 : void modifyHcGap(Array1D<Real64> const &hcgap, // Convective coefficient for gap
131 : Array1D<Real64> const &qv, // Heat flow from ventilation [W/m2]
132 : Array1D<Real64> const &hcv, // Convective heat flow coefficient due to ventilation
133 : Array1D<Real64> &hcgapMod, // Modified heat flow coefficient for gap
134 : int const nlayer, // Number of layers
135 : Real64 const edgeGlCorFac // Edge of glass correction factor
136 : )
137 : {
138 783660 : for (int i = 1; i <= nlayer + 1; ++i) {
139 623052 : if (qv(i) != 0) {
140 140671 : hcgapMod(i) = 0.5 * hcv(i);
141 : } else {
142 482381 : hcgapMod(i) = hcgap(i) * edgeGlCorFac;
143 : }
144 : }
145 160608 : }
146 :
147 160608 : void matrixQBalance(int const nlayer,
148 : Array2<Real64> &a,
149 : Array1D<Real64> &b,
150 : Array1D<Real64> const &sconScaled, // Solid layer coduction coefficient divided by thickness
151 : Array1D<Real64> const &hcgas,
152 : Array1D<Real64> &hcgapMod, // Modified heat flow coefficient for gap
153 : Array1D<Real64> const &asol,
154 : Array1D<Real64> const &qv,
155 : Array1D<Real64> const &hcv, // Convective heat flow coefficient due to ventilation
156 : Real64 const Tin,
157 : Real64 const Tout,
158 : Real64 const Gin,
159 : Real64 const Gout,
160 : Array1D<Real64> const &theta,
161 : Array1D<Real64> const &tir,
162 : Array1D<Real64> const &rir,
163 : Array1D<Real64> const &emis,
164 : Real64 const edgeGlCorrFac // Edge of glass correction factor
165 : )
166 : {
167 :
168 : // Using/Aliasing
169 : using namespace TARCOGParams;
170 :
171 : // Locals
172 : // local variables
173 : int i;
174 : int j;
175 : int k;
176 : int front;
177 : int back;
178 : int vent;
179 :
180 2010384 : for (i = 1; i <= 4 * nlayer; ++i) {
181 1849776 : b(i) = 0.0;
182 24147216 : for (j = 1; j <= 4 * nlayer; ++j) {
183 22297440 : a(j, i) = 0.0;
184 : }
185 : }
186 :
187 160608 : modifyHcGap(hcgas, qv, hcv, hcgapMod, nlayer, edgeGlCorrFac);
188 :
189 : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
190 : //!!!!!!!!!!!!!!!!!!!! build matrix a !!!!!!!!!!!!!!!!!!!!!!!!!
191 : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
192 :
193 623052 : for (i = 1; i <= nlayer; ++i) {
194 462444 : k = 4 * i - 3;
195 462444 : front = 2 * i - 1;
196 462444 : back = 2 * i;
197 :
198 : // first row
199 462444 : if (i != 1) {
200 301836 : a(k - 1, k) = -hcgapMod(i);
201 301836 : a(k - 2, k) = tir(front) - 1.0;
202 : }
203 462444 : a(k, k) = hcgapMod(i) + sconScaled(i);
204 462444 : a(k + 1, k) = 1.0;
205 462444 : a(k + 3, k) = -sconScaled(i);
206 462444 : if (i != nlayer) {
207 301836 : a(k + 5, k) = -tir(back);
208 : }
209 :
210 : // second row
211 462444 : a(k, k + 1) = emis(front) * Constant::StefanBoltzmann * pow_3(theta(front));
212 462444 : a(k + 1, k + 1) = -1.0;
213 462444 : if (i != 1) {
214 301836 : a(k - 2, k + 1) = rir(front);
215 : }
216 462444 : if (i != nlayer) {
217 301836 : a(k + 5, k + 1) = tir(back);
218 : }
219 :
220 : // third row
221 462444 : a(k + 2, k + 2) = -1.0;
222 462444 : a(k + 3, k + 2) = emis(back) * Constant::StefanBoltzmann * pow_3(theta(back));
223 462444 : if (i != 1) {
224 301836 : a(k - 2, k + 2) = tir(front);
225 : }
226 462444 : if (i != nlayer) {
227 301836 : a(k + 5, k + 2) = rir(back);
228 : }
229 :
230 : // fourth row
231 462444 : a(k, k + 3) = sconScaled(i);
232 462444 : a(k + 2, k + 3) = -1.0;
233 462444 : a(k + 3, k + 3) = -hcgapMod(i + 1) - sconScaled(i);
234 462444 : if (i != 1) {
235 301836 : a(k - 2, k + 3) = tir(front);
236 : }
237 462444 : if (i != nlayer) {
238 301836 : a(k + 4, k + 3) = hcgapMod(i + 1);
239 301836 : a(k + 5, k + 3) = 1.0 - tir(back);
240 : }
241 : }
242 :
243 : // build matrix b
244 :
245 623052 : for (i = 1; i <= nlayer; ++i) {
246 462444 : k = 4 * i - 3;
247 462444 : front = 2 * i - 1;
248 462444 : back = 2 * i;
249 462444 : vent = i + 1;
250 :
251 462444 : b(k) = 0.5 * asol(i) + 0.5 * qv(vent - 1);
252 462444 : b(k + 3) = -0.5 * asol(i) - 0.5 * qv(vent);
253 :
254 462444 : if (i == 1) {
255 160608 : b(k) = b(k) + hcgapMod(i) * Tout + Gout - tir(front) * Gout;
256 160608 : b(k + 1) = b(k + 1) - rir(front) * Gout;
257 160608 : b(k + 2) = b(k + 2) - tir(front) * Gout;
258 160608 : b(k + 3) = b(k + 3) - tir(front) * Gout;
259 : }
260 :
261 462444 : if (i == nlayer) {
262 160608 : b(k) = b(k) + tir(back) * Gin;
263 160608 : b(k + 1) = b(k + 1) - tir(back) * Gin;
264 160608 : b(k + 2) = b(k + 2) - rir(back) * Gin;
265 160608 : b(k + 3) = b(k + 3) - Gin - hcgapMod(i + 1) * Tin + tir(back) * Gin;
266 : }
267 : }
268 160608 : }
269 :
270 160608 : void EquationsSolver(EnergyPlusData &state, Array2<Real64> &a, Array1D<Real64> &b, int const n, int &nperr, std::string &ErrorMessage)
271 : {
272 : //***********************************************************************
273 : // Purpose: solves the main system of energy balance equations
274 : //***********************************************************************
275 : // Input:
276 : // a - matrix, radiositied
277 : // b - vector of known quantities
278 : // n - ???
279 : // Output:
280 : // b - solutions
281 : // nperr - error code
282 :
283 : // Using/Aliasing
284 : using namespace TARCOGParams;
285 :
286 : // Locals
287 160608 : Array1D_int indx(n);
288 : Real64 d;
289 :
290 160608 : ludcmp(state, a, n, indx, d, nperr, ErrorMessage);
291 :
292 : // Exit on error
293 160608 : if ((nperr > 0) && (nperr <= 1000)) return;
294 :
295 160608 : lubksb(a, n, indx, b);
296 160608 : }
297 :
298 160608 : void ludcmp(EnergyPlusData &state, Array2<Real64> &a, int const n, Array1D_int &indx, Real64 &d, int &nperr, std::string &ErrorMessage)
299 : {
300 :
301 : // Locals
302 160608 : Real64 constexpr TINY(1.0e-20);
303 :
304 : int i;
305 : int imax;
306 : int j;
307 : int k;
308 : Real64 aamax;
309 : Real64 dum;
310 : Real64 sum;
311 :
312 160608 : d = 1.0;
313 2010384 : for (i = 1; i <= n; ++i) {
314 1849776 : aamax = 0.0;
315 24147216 : for (j = 1; j <= n; ++j) {
316 22297440 : if (std::abs(a(j, i)) > aamax) aamax = std::abs(a(j, i));
317 : } // j
318 1849776 : if (aamax == 0.0) {
319 0 : nperr = 13;
320 0 : ErrorMessage = "Singular matrix in ludcmp.";
321 0 : return;
322 : }
323 1849776 : state.dataTARCOGCommon->vv(i) = 1.0 / aamax;
324 : } // i
325 :
326 2010384 : for (j = 1; j <= n; ++j) {
327 12073608 : for (i = 1; i <= j - 1; ++i) {
328 10223832 : sum = a(j, i);
329 46340856 : for (k = 1; k <= i - 1; ++k) {
330 36117024 : sum -= a(k, i) * a(j, k);
331 : } // k
332 10223832 : a(j, i) = sum;
333 : } // i
334 1849776 : aamax = 0.0;
335 13923384 : for (i = j; i <= n; ++i) {
336 12073608 : sum = a(j, i);
337 58414464 : for (k = 1; k <= j - 1; ++k) {
338 46340856 : sum -= a(k, i) * a(j, k);
339 : } // k
340 12073608 : a(j, i) = sum;
341 12073608 : dum = state.dataTARCOGCommon->vv(i) * std::abs(sum);
342 12073608 : if (dum >= aamax) {
343 2486530 : imax = i;
344 2486530 : aamax = dum;
345 : }
346 : } // i
347 1849776 : if (j != imax) {
348 6996525 : for (k = 1; k <= n; ++k) {
349 6472336 : dum = a(k, imax);
350 6472336 : a(k, imax) = a(k, j);
351 6472336 : a(k, j) = dum;
352 : } // k
353 524189 : d = -d;
354 524189 : state.dataTARCOGCommon->vv(imax) = state.dataTARCOGCommon->vv(j);
355 : }
356 1849776 : indx(j) = imax;
357 1849776 : if (a(j, j) == 0.0) a(j, j) = TINY;
358 1849776 : if (j != n) {
359 1689168 : dum = 1.0 / a(j, j);
360 11913000 : for (i = j + 1; i <= n; ++i) {
361 10223832 : a(j, i) *= dum;
362 : } // i
363 : }
364 : } // j
365 : }
366 :
367 160608 : void lubksb(Array2A<Real64> const a, int const n, const Array1D_int &indx, Array1D<Real64> &b)
368 : {
369 : // Argument array dimensioning
370 160608 : a.dim(n, n);
371 160608 : EP_SIZE_CHECK(indx, n);
372 160608 : EP_SIZE_CHECK(b, n);
373 :
374 : // Locals
375 : int i;
376 : int ii;
377 : int j;
378 : int ll;
379 : Real64 sum;
380 :
381 160608 : ii = 0;
382 2010384 : for (i = 1; i <= n; ++i) {
383 1849776 : ll = indx(i);
384 1849776 : sum = b(ll);
385 1849776 : b(ll) = b(i);
386 1849776 : if (ii != 0) {
387 11913000 : for (j = ii; j <= i - 1; ++j) {
388 10223832 : sum -= a(j, i) * b(j);
389 : } // j
390 160608 : } else if (sum != 0.0) {
391 160608 : ii = i;
392 : }
393 1849776 : b(i) = sum;
394 : } // i
395 :
396 2010384 : for (i = n; i >= 1; --i) {
397 1849776 : sum = b(i);
398 12073608 : for (j = i + 1; j <= n; ++j) {
399 10223832 : sum -= a(j, i) * b(j);
400 : } // j
401 1849776 : b(i) = sum / a(i, i);
402 : } // i
403 160608 : }
404 :
405 0 : Real64 pos(Real64 const x)
406 : {
407 0 : return (x + std::abs(x)) / 2.0;
408 : }
409 :
410 : } // namespace TARCOGCommon
411 :
412 : } // namespace EnergyPlus
|