LCOV - code coverage report
Current view: top level - EnergyPlus - TARCOGCommon.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 144 149 96.6 %
Date: 2023-01-17 19:17:23 Functions: 9 10 90.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, 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 * DataGlobalConstants::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 * DataGlobalConstants::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(DataGlobalConstants::Pi * DataGlobalConstants::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      160464 :     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      782787 :         for (int i = 1; i <= nlayer + 1; ++i) {
     139      622323 :             if (qv(i) != 0) {
     140      140711 :                 hcgapMod(i) = 0.5 * hcv(i);
     141             :             } else {
     142      481612 :                 hcgapMod(i) = hcgap(i) * edgeGlCorFac;
     143             :             }
     144             :         }
     145      160464 :     }
     146             : 
     147      160464 :     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     2007900 :         for (i = 1; i <= 4 * nlayer; ++i) {
     181     1847436 :             b(i) = 0.0;
     182    24107132 :             for (j = 1; j <= 4 * nlayer; ++j) {
     183    22259696 :                 a(j, i) = 0.0;
     184             :             }
     185             :         }
     186             : 
     187      160464 :         modifyHcGap(hcgas, qv, hcv, hcgapMod, nlayer, edgeGlCorrFac);
     188             : 
     189             :         //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     190             :         //!!!!!!!!!!!!!!!!!!!!  build matrix a   !!!!!!!!!!!!!!!!!!!!!!!!!
     191             :         //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     192             : 
     193      622323 :         for (i = 1; i <= nlayer; ++i) {
     194      461859 :             k = 4 * i - 3;
     195      461859 :             front = 2 * i - 1;
     196      461859 :             back = 2 * i;
     197             : 
     198             :             // first row
     199      461859 :             if (i != 1) {
     200      301395 :                 a(k - 1, k) = -hcgapMod(i);
     201      301395 :                 a(k - 2, k) = tir(front) - 1.0;
     202             :             }
     203      461859 :             a(k, k) = hcgapMod(i) + sconScaled(i);
     204      461859 :             a(k + 1, k) = 1.0;
     205      461859 :             a(k + 3, k) = -sconScaled(i);
     206      461859 :             if (i != nlayer) {
     207      301395 :                 a(k + 5, k) = -tir(back);
     208             :             }
     209             : 
     210             :             // second row
     211      461859 :             a(k, k + 1) = emis(front) * DataGlobalConstants::StefanBoltzmann * pow_3(theta(front));
     212      461859 :             a(k + 1, k + 1) = -1.0;
     213      461859 :             if (i != 1) {
     214      301395 :                 a(k - 2, k + 1) = rir(front);
     215             :             }
     216      461859 :             if (i != nlayer) {
     217      301395 :                 a(k + 5, k + 1) = tir(back);
     218             :             }
     219             : 
     220             :             // third row
     221      461859 :             a(k + 2, k + 2) = -1.0;
     222      461859 :             a(k + 3, k + 2) = emis(back) * DataGlobalConstants::StefanBoltzmann * pow_3(theta(back));
     223      461859 :             if (i != 1) {
     224      301395 :                 a(k - 2, k + 2) = tir(front);
     225             :             }
     226      461859 :             if (i != nlayer) {
     227      301395 :                 a(k + 5, k + 2) = rir(back);
     228             :             }
     229             : 
     230             :             // fourth row
     231      461859 :             a(k, k + 3) = sconScaled(i);
     232      461859 :             a(k + 2, k + 3) = -1.0;
     233      461859 :             a(k + 3, k + 3) = -hcgapMod(i + 1) - sconScaled(i);
     234      461859 :             if (i != 1) {
     235      301395 :                 a(k - 2, k + 3) = tir(front);
     236             :             }
     237      461859 :             if (i != nlayer) {
     238      301395 :                 a(k + 4, k + 3) = hcgapMod(i + 1);
     239      301395 :                 a(k + 5, k + 3) = 1.0 - tir(back);
     240             :             }
     241             :         }
     242             : 
     243             :         // build matrix b
     244             : 
     245      622323 :         for (i = 1; i <= nlayer; ++i) {
     246      461859 :             k = 4 * i - 3;
     247      461859 :             front = 2 * i - 1;
     248      461859 :             back = 2 * i;
     249      461859 :             vent = i + 1;
     250             : 
     251      461859 :             b(k) = 0.5 * asol(i) + 0.5 * qv(vent - 1);
     252      461859 :             b(k + 3) = -0.5 * asol(i) - 0.5 * qv(vent);
     253             : 
     254      461859 :             if (i == 1) {
     255      160464 :                 b(k) = b(k) + hcgapMod(i) * Tout + Gout - tir(front) * Gout;
     256      160464 :                 b(k + 1) = b(k + 1) - rir(front) * Gout;
     257      160464 :                 b(k + 2) = b(k + 2) - tir(front) * Gout;
     258      160464 :                 b(k + 3) = b(k + 3) - tir(front) * Gout;
     259             :             }
     260             : 
     261      461859 :             if (i == nlayer) {
     262      160464 :                 b(k) = b(k) + tir(back) * Gin;
     263      160464 :                 b(k + 1) = b(k + 1) - tir(back) * Gin;
     264      160464 :                 b(k + 2) = b(k + 2) - rir(back) * Gin;
     265      160464 :                 b(k + 3) = b(k + 3) - Gin - hcgapMod(i + 1) * Tin + tir(back) * Gin;
     266             :             }
     267             :         }
     268      160464 :     }
     269             : 
     270      160464 :     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      320928 :         Array1D_int indx(n);
     288             :         Real64 d;
     289             : 
     290      160464 :         ludcmp(state, a, n, indx, d, nperr, ErrorMessage);
     291             : 
     292             :         // Exit on error
     293      160464 :         if ((nperr > 0) && (nperr <= 1000)) return;
     294             : 
     295      160464 :         lubksb(a, n, indx, b);
     296             :     }
     297             : 
     298      160464 :     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      160464 :         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      160464 :         d = 1.0;
     313     2007900 :         for (i = 1; i <= n; ++i) {
     314     1847436 :             aamax = 0.0;
     315    24107132 :             for (j = 1; j <= n; ++j) {
     316    22259696 :                 if (std::abs(a(j, i)) > aamax) aamax = std::abs(a(j, i));
     317             :             } // j
     318     1847436 :             if (aamax == 0.0) {
     319           0 :                 nperr = 13;
     320           0 :                 ErrorMessage = "Singular matrix in ludcmp.";
     321           0 :                 return;
     322             :             }
     323     1847436 :             state.dataTARCOGCommon->vv(i) = 1.0 / aamax;
     324             :         } // i
     325             : 
     326     2007900 :         for (j = 1; j <= n; ++j) {
     327    12053566 :             for (i = 1; i <= j - 1; ++i) {
     328    10206130 :                 sum = a(j, i);
     329    46240158 :                 for (k = 1; k <= i - 1; ++k) {
     330    36034028 :                     sum -= a(k, i) * a(j, k);
     331             :                 } // k
     332    10206130 :                 a(j, i) = sum;
     333             :             } // i
     334     1847436 :             aamax = 0.0;
     335    13901002 :             for (i = j; i <= n; ++i) {
     336    12053566 :                 sum = a(j, i);
     337    58293724 :                 for (k = 1; k <= j - 1; ++k) {
     338    46240158 :                     sum -= a(k, i) * a(j, k);
     339             :                 } // k
     340    12053566 :                 a(j, i) = sum;
     341    12053566 :                 dum = state.dataTARCOGCommon->vv(i) * std::abs(sum);
     342    12053566 :                 if (dum >= aamax) {
     343     2483380 :                     imax = i;
     344     2483380 :                     aamax = dum;
     345             :                 }
     346             :             } // i
     347     1847436 :             if (j != imax) {
     348     6983080 :                 for (k = 1; k <= n; ++k) {
     349     6459708 :                     dum = a(k, imax);
     350     6459708 :                     a(k, imax) = a(k, j);
     351     6459708 :                     a(k, j) = dum;
     352             :                 } // k
     353      523372 :                 d = -d;
     354      523372 :                 state.dataTARCOGCommon->vv(imax) = state.dataTARCOGCommon->vv(j);
     355             :             }
     356     1847436 :             indx(j) = imax;
     357     1847436 :             if (a(j, j) == 0.0) a(j, j) = TINY;
     358     1847436 :             if (j != n) {
     359     1686972 :                 dum = 1.0 / a(j, j);
     360    11893102 :                 for (i = j + 1; i <= n; ++i) {
     361    10206130 :                     a(j, i) *= dum;
     362             :                 } // i
     363             :             }
     364             :         } // j
     365             :     }
     366             : 
     367      160464 :     void lubksb(Array2A<Real64> const a, int const n, const Array1D_int &indx, Array1D<Real64> &b)
     368             :     {
     369             :         // Argument array dimensioning
     370      160464 :         a.dim(n, n);
     371      160464 :         EP_SIZE_CHECK(indx, n);
     372      160464 :         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      160464 :         ii = 0;
     382     2007900 :         for (i = 1; i <= n; ++i) {
     383     1847436 :             ll = indx(i);
     384     1847436 :             sum = b(ll);
     385     1847436 :             b(ll) = b(i);
     386     1847436 :             if (ii != 0) {
     387    11893102 :                 for (j = ii; j <= i - 1; ++j) {
     388    10206130 :                     sum -= a(j, i) * b(j);
     389             :                 } // j
     390      160464 :             } else if (sum != 0.0) {
     391      160464 :                 ii = i;
     392             :             }
     393     1847436 :             b(i) = sum;
     394             :         } // i
     395             : 
     396     2007900 :         for (i = n; i >= 1; --i) {
     397     1847436 :             sum = b(i);
     398    12053566 :             for (j = i + 1; j <= n; ++j) {
     399    10206130 :                 sum -= a(j, i) * b(j);
     400             :             } // j
     401     1847436 :             b(i) = sum / a(i, i);
     402             :         } // i
     403      160464 :     }
     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        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13