LCOV - code coverage report
Current view: top level - EnergyPlus - TarcogShading.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 88.4 % 327 289
Test Date: 2025-06-02 07:23:51 Functions: 80.0 % 5 4

            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/Array1D.hh>
      50              : 
      51              : // EnergyPlus Headers
      52              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      53              : #include <EnergyPlus/DataGlobals.hh>
      54              : #include <EnergyPlus/TARCOGCommon.hh>
      55              : #include <EnergyPlus/TARCOGGasses90.hh>
      56              : #include <EnergyPlus/TARCOGGassesParams.hh>
      57              : #include <EnergyPlus/TARCOGParams.hh>
      58              : #include <EnergyPlus/TarcogShading.hh>
      59              : 
      60              : namespace EnergyPlus {
      61              : 
      62              : namespace TarcogShading {
      63              : 
      64              :     // MODULE INFORMATION:
      65              :     //       AUTHOR         Simon Vidanovic
      66              :     //       DATE WRITTEN   June/22/2010
      67              :     //       MODIFIED       na
      68              :     //       RE-ENGINEERED  na
      69              :     //  Revision: 6.0.36  (June/22/2010)
      70              :     //   - Initial setup, extracted from TARCOG.for
      71              : 
      72              :     // PURPOSE OF THIS MODULE:
      73              :     // Module which contains subroutines used for handling shading
      74              :     // device layers according to ISO15099
      75              : 
      76              :     // METHODOLOGY EMPLOYED:
      77              :     // <description>
      78              : 
      79              :     // REFERENCES:
      80              :     // na
      81              : 
      82              :     // OTHER NOTES:
      83              :     // na
      84              : 
      85              :     // USE STATEMENTS:
      86              : 
      87              :     // Using/Aliasing
      88              :     using namespace TARCOGGassesParams;
      89              :     using namespace TARCOGGasses90;
      90              :     using namespace TARCOGParams;
      91              : 
      92              :     enum class CalcForcedVentilation
      93              :     {
      94              :         Invalid = -1,
      95              :         Skip,
      96              :         Allow,
      97              :         Num
      98              :     };
      99              : 
     100              :     // Functions
     101              : 
     102       198609 :     void shading(EnergyPlusData &state,
     103              :                  Array1D<Real64> const &theta,
     104              :                  Array1D<Real64> const &gap,
     105              :                  Array1D<Real64> &hgas,
     106              :                  Array1D<Real64> &hcgas,
     107              :                  Array1D<Real64> &hrgas,
     108              :                  Array2<Real64> const &frct,
     109              :                  Array2_int const &iprop,
     110              :                  Array1D<Real64> const &pressure,
     111              :                  Array1D_int const &nmix,
     112              :                  const Array1D<Real64> &xwght,
     113              :                  Array2<Real64> const &xgcon,
     114              :                  Array2<Real64> const &xgvis,
     115              :                  Array2<Real64> const &xgcp,
     116              :                  int const nlayer,
     117              :                  Real64 const width,
     118              :                  Real64 const height,
     119              :                  Real64 const angle,
     120              :                  Real64 const Tout,
     121              :                  Real64 const Tin,
     122              :                  Array1D<Real64> const &Atop,
     123              :                  Array1D<Real64> const &Abot,
     124              :                  Array1D<Real64> const &Al,
     125              :                  Array1D<Real64> const &Ar,
     126              :                  Array1D<Real64> const &Ah,
     127              :                  Array1D<Real64> const &vvent,
     128              :                  Array1D<Real64> const &tvent,
     129              :                  Array1D<TARCOGLayerType> LayerType,
     130              :                  Array1D<Real64> &Tgaps,
     131              :                  Array1D<Real64> &qv,
     132              :                  Array1D<Real64> &hcv, // Heat transfer coefficient in gaps including airflow
     133              :                  int &nperr,
     134              :                  std::string &ErrorMessage,
     135              :                  Array1D<Real64> &vfreevent)
     136              :     {
     137              :         //**************************************************************************************************************
     138              :         //  Input:
     139              :         // theta   Vector of average temperatures
     140              :         //  gap      Vector of gap widths (maxlay) [m]
     141              :         //  hgas    Convective part of gap effective conductivity
     142              :         //  frct    Fraction of gasses in a mixture (maxlay1,maxgas)
     143              :         //  iprop    Vector of gas identifiers (maxlay1,maxgas)
     144              :         //  pressure  Vector of gas pressures [N/m^2]
     145              :         //  nmix    Vector of number of gasses for each mixture (maxgas=10)
     146              :         //  nlayer  Number of glazing layers
     147              :         //  width    IGU cavity width [m]
     148              :         //  height  IGU cavity height [m]
     149              :         //  angle    Window angle [degrees]
     150              :         //  Tout    Outdoor temperature [K]
     151              :         //  Tin      Indoor temperature [K]
     152              :         //  Atop    Opening between top of shading device and top of glazing cavity [m^2]
     153              :         //  Abot    Opening between bottom of shading device and bottom of glazing cavity [m^2]
     154              :         //  Al      Opening between left of shading device and left end of glazing cavity [m^2]
     155              :         //  Ar      Opening between right of shading device and right end of glazing cavity [m^2]
     156              :         //  Ah      Total area holes in the shading device [m^2]
     157              :         //  LayerType    Vector of layer types (0 - glazing; 1 - shading)
     158              :         //  Ebf      Vector of emissive power of the front surface (# of layers)
     159              :         //  Input/Output:
     160              :         //  Tgaps    Vector of gap temperatures [K]
     161              :         //  Output:
     162              :         //  qv      Vector of heat transfer to the gap by ventilation [W/m^2]
     163              :         //  hhatv    Vector of all film coefficients for vented cavities (maxlay3)
     164              :         //  hcv      Vector of surface-to-air heat transfer coefficients by conduction/convection for vented cavities [W/(m^2*K)]
     165              :         //  Ebgap    Vector of emissive power of the vented cavities (maxlay3)
     166              :         //  nperr    Error flag
     167              :         // vfreevent   Vector of free ventilation velocities in gaps
     168              :         //**************************************************************************************************************
     169              : 
     170              :         // Using/Aliasing
     171              :         using namespace TARCOGCommon;
     172              : 
     173              :         // Locals
     174              :         // REAL(r64), intent(in) :: Ebf(maxlay)
     175              : 
     176              :         Real64 Atops;
     177              :         Real64 Abots;
     178              :         Real64 Als;
     179              :         Real64 Ars;
     180              :         Real64 Ahs;
     181              :         Real64 press1;
     182              :         Real64 press2;
     183              :         Real64 s1;
     184              :         Real64 s2;
     185              :         Real64 s;
     186              :         Real64 hcvs;
     187              :         Real64 qvs;
     188              :         Real64 hc;
     189              :         Real64 hc1;
     190              :         Real64 hc2;
     191              :         Real64 speed;
     192              :         Real64 Tav;
     193              :         Real64 Tgap;
     194              :         Real64 Temp;
     195              :         Real64 speed1;
     196              :         Real64 speed2;
     197              :         Real64 Tav1;
     198              :         Real64 Tav2;
     199              :         Real64 Tgap1;
     200              :         Real64 Tgap2;
     201              :         Real64 hcv1;
     202              :         Real64 hcv2;
     203              :         Real64 qv1;
     204              :         Real64 qv2;
     205              : 
     206              :         int i;
     207              :         int j;
     208              :         int k;
     209              :         int nmix1;
     210              :         int nmix2;
     211              : 
     212              :         // init vectors:
     213       198609 :         qv = 0.0;
     214       198609 :         hcv = 0.0;
     215              :         // hhatv = 0.0d0
     216              :         // Ebgap = 0.0d0
     217              :         // hcv = 0.0d0
     218              : 
     219              :         // main loop:
     220       767655 :         for (i = 1; i <= nlayer; ++i) {
     221       569046 :             k = 2 * i + 1;
     222              :             // if (LayerType(i).eq.VENETBLIND) then
     223       569046 :             if (IsShadingLayer(LayerType(i))) {
     224              :                 // dr.........set Shading device geometry
     225       154643 :                 Atops = Atop(i);
     226       154643 :                 Abots = Abot(i);
     227       154643 :                 Als = Al(i);
     228       154643 :                 Ars = Ar(i);
     229       154643 :                 Ahs = Ah(i);
     230              : 
     231              :                 // dr.....setting gas properties for two adjacent gaps (or environment)
     232       154643 :                 nmix1 = nmix(i);
     233       154643 :                 nmix2 = nmix(i + 1);
     234       154643 :                 press1 = pressure(i);
     235       154643 :                 press2 = pressure(i + 1);
     236      1701073 :                 for (j = 1; j <= maxgas; ++j) {
     237      1546430 :                     state.dataTarcogShading->iprop1(j) = iprop(j, i);
     238      1546430 :                     state.dataTarcogShading->iprop2(j) = iprop(j, i + 1);
     239      1546430 :                     state.dataTarcogShading->frct1(j) = frct(j, i);
     240      1546430 :                     state.dataTarcogShading->frct2(j) = frct(j, i + 1);
     241              :                 } // j
     242              : 
     243              :                 // dr.......shading on outdoor side
     244       154643 :                 if (i == 1) {
     245        52663 :                     s = gap(1);
     246        52663 :                     hc = hcgas(2);
     247              :                     // Tenv = tvent(1)
     248        52663 :                     Tav = (theta(2) + theta(3)) / 2.0;
     249        52663 :                     Tgap = Tgaps(2);
     250              : 
     251              :                     // bi......use Tout as temp of the air at inlet
     252       105326 :                     shadingedge(state,
     253        52663 :                                 state.dataTarcogShading->iprop1,
     254        52663 :                                 state.dataTarcogShading->frct1,
     255              :                                 press1,
     256              :                                 nmix1,
     257        52663 :                                 state.dataTarcogShading->iprop2,
     258        52663 :                                 state.dataTarcogShading->frct2,
     259              :                                 press2,
     260              :                                 nmix2,
     261              :                                 xwght,
     262              :                                 xgcon,
     263              :                                 xgvis,
     264              :                                 xgcp,
     265              :                                 Atops,
     266              :                                 Abots,
     267              :                                 Als,
     268              :                                 Ars,
     269              :                                 Ahs,
     270              :                                 s,
     271              :                                 height,
     272              :                                 width,
     273              :                                 angle,
     274        52663 :                                 vvent(2),
     275              :                                 hc,
     276              :                                 Tout,
     277              :                                 Tav,
     278              :                                 Tgap,
     279              :                                 hcvs,
     280              :                                 qvs,
     281              :                                 nperr,
     282              :                                 ErrorMessage,
     283              :                                 speed);
     284              : 
     285              :                     // exit on error
     286        52663 :                     if ((nperr > 0) && (nperr < 1000)) {
     287            0 :                         return;
     288              :                     }
     289              : 
     290        52663 :                     Tgaps(2) = Tgap;
     291              :                     // Ebgap(3) = sigma * Tgap ** 4
     292              : 
     293        52663 :                     hcgas(2) = hcvs / 2.0;
     294        52663 :                     hgas(2) = hcgas(2) + hrgas(2);
     295        52663 :                     hcv(2) = hcvs;
     296        52663 :                     qv(2) = qvs;
     297              : 
     298              :                     // bi.........Add free ventilation velocity
     299        52663 :                     vfreevent(2) = speed;
     300              :                 } // if (i.eq.1) then
     301              : 
     302              :                 // dr.......shading on indoor side
     303       154643 :                 if (i == nlayer) {
     304        81835 :                     if (nlayer > 1) {
     305        81835 :                         s = gap(nlayer - 1); // Autodesk:BoundsViolation gap(nlayer - 1) @ nlayer=1: Fixed with if block
     306        81835 :                         Tav = (theta(2 * nlayer - 1) + theta(2 * nlayer - 2)) /
     307              :                               2.0; // Autodesk:BoundsViolation theta(2 * nlayer - 2) @ nlayer=1: Fixed with if block in 8.2
     308              :                     } else {
     309            0 :                         s = 0.0;
     310            0 :                         Tav = 273.15;
     311              :                     }
     312        81835 :                     hc = hcgas(nlayer);
     313              :                     // Tenv = tvent(nlayer + 1)
     314              : 
     315        81835 :                     Tgap = Tgaps(nlayer);
     316              : 
     317              :                     // bi.........use Tin as temp of the air at inlet
     318       163670 :                     shadingedge(state,
     319        81835 :                                 state.dataTarcogShading->iprop2,
     320        81835 :                                 state.dataTarcogShading->frct2,
     321              :                                 press2,
     322              :                                 nmix2,
     323        81835 :                                 state.dataTarcogShading->iprop1,
     324        81835 :                                 state.dataTarcogShading->frct1,
     325              :                                 press1,
     326              :                                 nmix1,
     327              :                                 xwght,
     328              :                                 xgcon,
     329              :                                 xgvis,
     330              :                                 xgcp,
     331              :                                 Atops,
     332              :                                 Abots,
     333              :                                 Als,
     334              :                                 Ars,
     335              :                                 Ahs,
     336              :                                 s,
     337              :                                 height,
     338              :                                 width,
     339              :                                 angle,
     340        81835 :                                 vvent(nlayer),
     341              :                                 hc,
     342              :                                 Tin,
     343              :                                 Tav,
     344              :                                 Tgap,
     345              :                                 hcvs,
     346              :                                 qvs,
     347              :                                 nperr,
     348              :                                 ErrorMessage,
     349              :                                 speed);
     350              : 
     351              :                     // exit on error
     352        81835 :                     if ((nperr > 0) && (nperr < 1000)) {
     353            0 :                         return;
     354              :                     }
     355              : 
     356        81835 :                     Tgaps(nlayer) = Tgap;
     357        81835 :                     hcgas(nlayer) = hcvs / 2.0;
     358        81835 :                     hgas(nlayer) = hcgas(nlayer) + hrgas(nlayer);
     359        81835 :                     hcv(nlayer) = hcvs;
     360        81835 :                     qv(nlayer) = qvs;
     361              : 
     362              :                     // bi.........Add free ventilation velocity
     363        81835 :                     vfreevent(i) = speed;
     364              :                 } // if (i.eq.nlayer) then
     365              : 
     366              :                 // dr.......shading between glass layers
     367       154643 :                 if ((i > 1) && (i < nlayer)) {
     368              :                     // dr.........average temperatures
     369        20145 :                     Tav1 = (theta(2 * i - 2) + theta(2 * i - 1)) / 2.0;
     370        20145 :                     Tav2 = (theta(2 * i) + theta(2 * i + 1)) / 2.0;
     371        20145 :                     Tgap1 = Tgaps(i);
     372        20145 :                     Tgap2 = Tgaps(i + 1);
     373              : 
     374        20145 :                     hc1 = hcgas(i);
     375        20145 :                     hc2 = hcgas(i + 1);
     376        20145 :                     if (i > 1) {
     377        20145 :                         s1 = gap(i - 1);
     378              :                     }
     379        20145 :                     s2 = gap(i);
     380              : 
     381              :                     // speed1 = vvent(i)
     382              :                     // speed2 = vvent(i+1)
     383              : 
     384        20145 :                     if ((static_cast<int>(CalcForcedVentilation::Allow)) && ((vvent(i) != 0) || (vvent(i + 1) != 0))) {
     385            0 :                         forcedventilation(state,
     386            0 :                                           state.dataTarcogShading->iprop1,
     387            0 :                                           state.dataTarcogShading->frct1,
     388              :                                           press1,
     389              :                                           nmix1,
     390              :                                           xwght,
     391              :                                           xgcon,
     392              :                                           xgvis,
     393              :                                           xgcp,
     394              :                                           s1,
     395              :                                           height,
     396              :                                           hc1,
     397            0 :                                           vvent(i),
     398            0 :                                           tvent(i),
     399              :                                           Temp,
     400              :                                           Tav1,
     401              :                                           hcv1,
     402              :                                           qv1,
     403              :                                           nperr,
     404              :                                           ErrorMessage);
     405            0 :                         forcedventilation(state,
     406            0 :                                           state.dataTarcogShading->iprop2,
     407            0 :                                           state.dataTarcogShading->frct2,
     408              :                                           press2,
     409              :                                           nmix1,
     410              :                                           xwght,
     411              :                                           xgcon,
     412              :                                           xgvis,
     413              :                                           xgcp,
     414              :                                           s2,
     415              :                                           height,
     416              :                                           hc1,
     417            0 :                                           vvent(i + 1),
     418            0 :                                           tvent(i + 1),
     419              :                                           Temp,
     420              :                                           Tav2,
     421              :                                           hcv2,
     422              :                                           qv2,
     423              :                                           nperr,
     424              :                                           ErrorMessage);
     425              :                     } else {
     426        40290 :                         shadingin(state,
     427        20145 :                                   state.dataTarcogShading->iprop1,
     428        20145 :                                   state.dataTarcogShading->frct1,
     429              :                                   press1,
     430              :                                   nmix1,
     431        20145 :                                   state.dataTarcogShading->iprop2,
     432        20145 :                                   state.dataTarcogShading->frct2,
     433              :                                   press2,
     434              :                                   nmix2,
     435              :                                   xwght,
     436              :                                   xgcon,
     437              :                                   xgvis,
     438              :                                   xgcp,
     439              :                                   Atops,
     440              :                                   Abots,
     441              :                                   Als,
     442              :                                   Ars,
     443              :                                   Ahs,
     444              :                                   s1,
     445              :                                   s2,
     446              :                                   height,
     447              :                                   width,
     448              :                                   angle,
     449              :                                   hc1,
     450              :                                   hc2,
     451              :                                   speed1,
     452              :                                   speed2,
     453              :                                   Tgap1,
     454              :                                   Tgap2,
     455              :                                   Tav1,
     456              :                                   Tav2,
     457              :                                   hcv1,
     458              :                                   hcv2,
     459              :                                   qv1,
     460              :                                   qv2,
     461              :                                   nperr,
     462              :                                   ErrorMessage);
     463              :                     }
     464              : 
     465              :                     // exit on error
     466        20145 :                     if ((nperr > 0) && (nperr < 1000)) {
     467            0 :                         return;
     468              :                     }
     469              : 
     470              :                     // if (vvent(i).gt.0) then !not implemented for inside shading yet
     471              :                     //  nperr = 1006
     472              :                     //  ErrorMessage = 'Forced ventilation not implemented for internal SD layers.'
     473              :                     //  return
     474              :                     // end if
     475              : 
     476        20145 :                     hcgas(i) = hcv1 / 2.0;
     477        20145 :                     hcgas(i + 1) = hcv2 / 2.0;
     478        20145 :                     hgas(i) = hcgas(i) + hrgas(i);
     479        20145 :                     hgas(i + 1) = hcgas(i + 1) + hrgas(i + 1);
     480        20145 :                     hcv(i) = hcv1;
     481        20145 :                     hcv(i + 1) = hcv2;
     482        20145 :                     qv(i) = qv1;
     483        20145 :                     qv(i + 1) = qv2;
     484        20145 :                     Tgaps(i) = Tgap1;
     485        20145 :                     Tgaps(i + 1) = Tgap2;
     486              :                     // bi.........Add free ventilation velocity
     487        20145 :                     vfreevent(i) = speed1;
     488        20145 :                     vfreevent(i + 1) = speed2;
     489              :                 } // if ((i.gt.1).and.(i.lt.nlayer)) then
     490              :             } // if (LayerType(i).eq.SHADING) then
     491              :         }
     492              :     }
     493              : 
     494            0 :     void forcedventilation(EnergyPlusData &state,
     495              :                            const Array1D_int &iprop,
     496              :                            const Array1D<Real64> &frct,
     497              :                            Real64 const press,
     498              :                            int const nmix,
     499              :                            const Array1D<Real64> &xwght,
     500              :                            Array2A<Real64> const xgcon,
     501              :                            Array2A<Real64> const xgvis,
     502              :                            Array2A<Real64> const xgcp,
     503              :                            Real64 const s,
     504              :                            Real64 const H,
     505              :                            Real64 const hc,
     506              :                            Real64 const forcedspeed,
     507              :                            Real64 const Tinlet,
     508              :                            Real64 &Toutlet,
     509              :                            Real64 const Tav,
     510              :                            Real64 &hcv,
     511              :                            Real64 &qv,
     512              :                            int &nperr,
     513              :                            std::string &ErrorMessage)
     514              :     {
     515              :         //**************************************************************************************************************
     516              :         //  Input:
     517              :         //  iprop      Vector of gas identifiers
     518              :         //  frct      Fraction of gasses in a mixture
     519              :         //  nmix      Number of gasses in a mixture
     520              :         //  press      Pressure in mixture
     521              :         //  s1        Gap width [m]
     522              :         //  H          IGU cavity height [m]
     523              :         //  L          IGU cavity width [m]
     524              :         //  hc        Convective/conductive coefficient for non-vented gap
     525              :         //  Tav        Average temperature of gap surfaces
     526              :         // Tinlet    Temperature of inlet air
     527              :         //  Output:
     528              :         //  hcv    Convective/conductive coefficient for vented gap
     529              :         //  qv    Heat transfer to the gap by ventilation [W/m^2]
     530              :         //  nperr      Error flag
     531              :         // ErrorMessage string containing error message
     532              :         //**************************************************************************************************************
     533              : 
     534              :         // Argument array dimensioning
     535            0 :         EP_SIZE_CHECK(iprop, maxgas);
     536            0 :         EP_SIZE_CHECK(frct, maxgas);
     537            0 :         EP_SIZE_CHECK(xwght, maxgas);
     538            0 :         xgcon.dim(3, maxgas);
     539            0 :         xgvis.dim(3, maxgas);
     540            0 :         xgcp.dim(3, maxgas);
     541              : 
     542              :         // Locals
     543              :         Real64 H0;
     544              :         Real64 dens;
     545              :         Real64 cp;
     546              :         Real64 pr;
     547              :         Real64 con;
     548              :         Real64 visc;
     549              : 
     550            0 :         GASSES90(state,
     551              :                  Tav,
     552              :                  iprop,
     553              :                  frct,
     554              :                  press,
     555              :                  nmix,
     556              :                  xwght,
     557              :                  xgcon,
     558              :                  xgvis,
     559              :                  xgcp,
     560              :                  con,
     561              :                  visc,
     562              :                  dens,
     563              :                  cp,
     564              :                  pr,
     565              :                  TARCOGGassesParams::Stdrd::ISO15099,
     566              :                  nperr,
     567              :                  ErrorMessage);
     568              : 
     569            0 :         H0 = (dens * cp * s * forcedspeed) / (4.0 * hc + 8.0 * forcedspeed);
     570              : 
     571            0 :         Toutlet = Tav - (Tav - Tinlet) * std::pow(e, -H / H0);
     572              : 
     573            0 :         qv = -dens * cp * forcedspeed * s * (Toutlet - Tinlet) / H;
     574              : 
     575              :         // Need to calculate surface-to-air convection heat transfer coefficient.  This is needed later to calculate layer
     576              :         // to gap thermal resistance
     577            0 :         hcv = 2.0 * hc + 4.0 * forcedspeed;
     578            0 :     }
     579              : 
     580        20145 :     void shadingin(EnergyPlusData &state,
     581              :                    const Array1D_int &iprop1,
     582              :                    const Array1D<Real64> &frct1,
     583              :                    Real64 const press1,
     584              :                    int const nmix1,
     585              :                    const Array1D_int &iprop2,
     586              :                    const Array1D<Real64> &frct2,
     587              :                    Real64 const press2,
     588              :                    int const nmix2,
     589              :                    const Array1D<Real64> &xwght,
     590              :                    Array2A<Real64> const xgcon,
     591              :                    Array2A<Real64> const xgvis,
     592              :                    Array2A<Real64> const xgcp,
     593              :                    Real64 &Atop,
     594              :                    Real64 &Abot,
     595              :                    Real64 const Al,
     596              :                    Real64 const Ar,
     597              :                    Real64 const Ah,
     598              :                    Real64 const s1,
     599              :                    Real64 const s2,
     600              :                    Real64 const H,
     601              :                    Real64 const L,
     602              :                    Real64 const angle,
     603              :                    Real64 const hc1,
     604              :                    Real64 const hc2,
     605              :                    Real64 &speed1,
     606              :                    Real64 &speed2,
     607              :                    Real64 &Tgap1,
     608              :                    Real64 &Tgap2,
     609              :                    Real64 const Tav1,
     610              :                    Real64 const Tav2,
     611              :                    Real64 &hcv1,
     612              :                    Real64 &hcv2,
     613              :                    Real64 &qv1,
     614              :                    Real64 &qv2,
     615              :                    int &nperr,
     616              :                    std::string &ErrorMessage)
     617              :     {
     618              :         //**************************************************************************************************************
     619              :         //  Input:
     620              :         //  iprop1      Vector of gas identifiers
     621              :         //  frct1      Fraction of gasses in a mixture
     622              :         //  nmix1      Number of gasses in a mixture
     623              :         //  press1      Pressure in mixture
     624              :         //  iprop2      Vector of gas identifiers
     625              :         //  frct2      Fraction of gasses in a mixture
     626              :         //  nmix2      Number of gasses in a mixture
     627              :         //  press2      Pressure in mixture
     628              :         //  Atop      Opening between top of shading device and top of glazing cavity [m^2]
     629              :         //  Abot      Opening between bottom of shading device and bottom of glazing cavity [m^2]
     630              :         //  Al        Opening between left of shading device and left end of glazing cavity [m^2]
     631              :         //  Ar        Opening between right of shading device and right end of glazing cavity [m^2]
     632              :         //  Ah        Total area holes in the shading device [m^2]
     633              :         //  s1, s2      Gap width [m]
     634              :         //  H        IGU cavity height [m]
     635              :         //  L        IGU cavity width [m]
     636              :         //  angle      Window angle [degrees]
     637              :         //  hc1, hc2    Convective/conductive coefficient for non-vented gap
     638              :         //  Tav1, Tav2    Average temperature of gap surfaces
     639              :         //  Output:
     640              :         //  Tgap1, Tgap2  Temperature of vented gap
     641              :         //  hcv1, hcv2    Convective/conductive coefficient for vented gap
     642              :         //  qv1, qv2    Heat transfer to the gap by ventilation [W/m^2]
     643              :         //  speed1, speed2  Air/gas velocities in gaps around SD layer
     644              :         //  nperr      Error flag
     645              :         //**************************************************************************************************************
     646              : 
     647              :         // Using/Aliasing
     648              :         // Argument array dimensioning
     649        20145 :         EP_SIZE_CHECK(iprop1, maxgas);
     650        20145 :         EP_SIZE_CHECK(frct1, maxgas);
     651        20145 :         EP_SIZE_CHECK(iprop2, maxgas);
     652        20145 :         EP_SIZE_CHECK(frct2, maxgas);
     653        20145 :         EP_SIZE_CHECK(xwght, maxgas);
     654        20145 :         xgcon.dim(3, maxgas);
     655        20145 :         xgvis.dim(3, maxgas);
     656        20145 :         xgcp.dim(3, maxgas);
     657              : 
     658              :         // Locals
     659              :         Real64 A;
     660              :         Real64 A1;
     661              :         Real64 A2;
     662              :         Real64 B1;
     663              :         Real64 B2;
     664              :         Real64 C1;
     665              :         Real64 C2;
     666              :         Real64 D1;
     667              :         Real64 D2;
     668              :         Real64 Zin1;
     669              :         Real64 Zin2;
     670              :         Real64 Zout1;
     671              :         Real64 Zout2;
     672              :         Real64 A1eqin;
     673              :         Real64 A1eqout;
     674              :         Real64 A2eqin;
     675              :         Real64 A2eqout;
     676              :         Real64 T0;
     677              :         Real64 tilt;
     678              :         Real64 dens0;
     679              :         Real64 visc0;
     680              :         Real64 con0;
     681              :         Real64 pr0;
     682              :         Real64 cp0;
     683              :         Real64 dens1;
     684              :         Real64 visc1;
     685              :         Real64 con1;
     686              :         Real64 pr1;
     687              :         Real64 cp1;
     688              :         Real64 dens2;
     689              :         Real64 visc2;
     690              :         Real64 con2;
     691              :         Real64 pr2;
     692              :         Real64 cp2;
     693              :         Real64 Tup;
     694              :         Real64 Tdown;
     695              :         Real64 H01;
     696              :         Real64 H02;
     697              :         Real64 beta1;
     698              :         Real64 beta2;
     699              :         Real64 alpha1;
     700              :         Real64 alpha2;
     701              :         Real64 P1;
     702              :         Real64 P2;
     703              :         Real64 qsmooth;
     704              : 
     705              :         // iteration parameters
     706              :         int iter;
     707              :         Real64 TGapOld1;
     708              :         Real64 TGapOld2;
     709              :         Real64 Temp1;
     710              :         Real64 Temp2;
     711              :         bool converged;
     712              : 
     713        20145 :         TGapOld1 = 0.0;
     714        20145 :         TGapOld2 = 0.0;
     715        20145 :         tilt = Constant::Pi / 180 * (angle - 90);
     716        20145 :         T0 = 0.0 + Constant::Kelvin;
     717        20145 :         A1eqin = 0.0;
     718        20145 :         A2eqout = 0.0;
     719        20145 :         A1eqout = 0.0;
     720        20145 :         A2eqin = 0.0;
     721        20145 :         P1 = 0.0;
     722        20145 :         P2 = 0.0;
     723              : 
     724        20145 :         GASSES90(state,
     725              :                  T0,
     726              :                  iprop1,
     727              :                  frct1,
     728              :                  press1,
     729              :                  nmix1,
     730              :                  xwght,
     731              :                  xgcon,
     732              :                  xgvis,
     733              :                  xgcp,
     734              :                  con0,
     735              :                  visc0,
     736              :                  dens0,
     737              :                  cp0,
     738              :                  pr0,
     739              :                  TARCOGGassesParams::Stdrd::ISO15099,
     740              :                  nperr,
     741              :                  ErrorMessage);
     742              : 
     743              :         // exit on error:
     744        20145 :         if ((nperr > 0) && (nperr < 1000)) {
     745           73 :             return;
     746              :         }
     747              : 
     748              :         // dr...check for error messages
     749        20145 :         if ((Tgap1 * Tgap2) == 0) {
     750            0 :             nperr = 15;
     751            0 :             ErrorMessage = "Temperature of vented gap must be greater than 0 [K].";
     752            0 :             return;
     753              :         }
     754              : 
     755        20145 :         if ((Atop + Abot) == 0) {
     756              :             //    nperr = 16
     757              :             //    return
     758        20145 :             Atop = 0.000001;
     759        20145 :             Abot = 0.000001;
     760              :         }
     761              : 
     762        20145 :         converged = false;
     763        20145 :         iter = 0;
     764        20145 :         Real64 const s1_2 = pow_2(s1);
     765        20145 :         Real64 const s2_2 = pow_2(s2);
     766        20145 :         Real64 const s1_s2_2 = pow_2(s1 / s2);
     767        20145 :         Real64 const cos_Tilt = std::cos(tilt);
     768        49056 :         while (!converged) {
     769        28984 :             ++iter;
     770        28984 :             GASSES90(state,
     771              :                      Tgap1,
     772              :                      iprop1,
     773              :                      frct1,
     774              :                      press1,
     775              :                      nmix1,
     776              :                      xwght,
     777              :                      xgcon,
     778              :                      xgvis,
     779              :                      xgcp,
     780              :                      con1,
     781              :                      visc1,
     782              :                      dens1,
     783              :                      cp1,
     784              :                      pr1,
     785              :                      TARCOGGassesParams::Stdrd::ISO15099,
     786              :                      nperr,
     787              :                      ErrorMessage);
     788        28984 :             GASSES90(state,
     789              :                      Tgap2,
     790              :                      iprop2,
     791              :                      frct2,
     792              :                      press2,
     793              :                      nmix2,
     794              :                      xwght,
     795              :                      xgcon,
     796              :                      xgvis,
     797              :                      xgcp,
     798              :                      con2,
     799              :                      visc2,
     800              :                      dens2,
     801              :                      cp2,
     802              :                      pr2,
     803              :                      TARCOGGassesParams::Stdrd::ISO15099,
     804              :                      nperr,
     805              :                      ErrorMessage);
     806              : 
     807              :             //  A = dens0 * T0 * GravityConstant * ABS(cos(tilt)) * ABS(Tgap1 - Tgap2) / (Tgap1 * Tgap2)
     808              : 
     809              :             // bi...Bug fix #00005:
     810        28984 :             A = dens0 * T0 * Constant::Gravity * H * std::abs(cos_Tilt) * std::abs(Tgap1 - Tgap2) / (Tgap1 * Tgap2);
     811              : 
     812        28984 :             if (A == 0.0) {
     813           73 :                 qv1 = 0.0;
     814           73 :                 qv2 = 0.0;
     815           73 :                 speed1 = 0.0;
     816           73 :                 speed2 = 0.0;
     817           73 :                 hcv1 = 2.0 * hc1;
     818           73 :                 hcv2 = 2.0 * hc2;
     819           73 :                 return;
     820              :             }
     821              : 
     822        28911 :             B1 = dens1 / 2;
     823        28911 :             B2 = (dens2 / 2) * s1_s2_2;
     824              : 
     825        28911 :             C1 = 12 * visc1 * H / s1_2;
     826        28911 :             C2 = 12 * visc2 * (H / s2_2) * (s1 / s2);
     827              : 
     828        28911 :             if (Tgap1 >= Tgap2) {
     829          537 :                 A1eqin = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
     830          537 :                 A2eqout = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
     831          537 :                 A1eqout = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
     832          537 :                 A2eqin = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
     833        28374 :             } else if (Tgap1 < Tgap2) {
     834        28374 :                 A1eqout = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
     835        28374 :                 A2eqin = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
     836        28374 :                 A1eqin = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
     837        28374 :                 A2eqout = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
     838              :             }
     839              : 
     840        28911 :             Zin1 = pow_2((s1 * L / (0.6 * A1eqin)) - 1.0);
     841        28911 :             Zin2 = pow_2((s2 * L / (0.6 * A2eqin)) - 1.0);
     842        28911 :             Zout1 = pow_2((s1 * L / (0.6 * A1eqout)) - 1.0);
     843        28911 :             Zout2 = pow_2((s2 * L / (0.6 * A2eqout)) - 1.0);
     844              : 
     845        28911 :             D1 = (dens1 / 2.0) * (Zin1 + Zout1);
     846        28911 :             D2 = (dens2 / 2.0) * s1_s2_2 * (Zin2 + Zout2);
     847              : 
     848        28911 :             A1 = B1 + D1 + B2 + D2;
     849        28911 :             A2 = C1 + C2;
     850              : 
     851        28911 :             speed1 = (std::sqrt(pow_2(A2) + std::abs(4.0 * A * A1)) - A2) / (2.0 * A1);
     852        28911 :             speed2 = speed1 * s1 / s2;
     853              : 
     854        28911 :             H01 = (dens1 * cp1 * s1 * speed1) / (4.0 * hc1 + 8.0 * speed1);
     855        28911 :             H02 = (dens2 * cp2 * s2 * speed2) / (4.0 * hc2 + 8.0 * speed2);
     856              : 
     857        28911 :             if ((H01 != 0.0) && (H02 != 0.0)) {
     858        28911 :                 P1 = -H / H01;
     859        28911 :                 P2 = -H / H02;
     860              :             }
     861              : 
     862        28911 :             beta1 = std::pow(e, P1);
     863        28911 :             beta2 = std::pow(e, P2);
     864              : 
     865        28911 :             alpha1 = 1.0 - beta1;
     866        28911 :             alpha2 = 1.0 - beta2;
     867              : 
     868        28911 :             if (Tgap1 > Tgap2) {
     869          537 :                 Tup = (alpha1 * Tav1 + beta1 * alpha2 * Tav2) / (1.0 - beta1 * beta2);
     870          537 :                 Tdown = alpha2 * Tav2 + beta2 * Tup;
     871        28374 :             } else if (Tgap2 >= Tgap1) {
     872        28374 :                 Tdown = (alpha1 * Tav1 + beta1 * alpha2 * Tav2) / (1.0 - beta1 * beta2);
     873        28374 :                 Tup = alpha2 * Tav2 + beta2 * Tdown;
     874              :             }
     875              : 
     876        28911 :             TGapOld1 = Tgap1;
     877        28911 :             TGapOld2 = Tgap2;
     878              : 
     879        28911 :             if (Tgap1 > Tgap2) {
     880          537 :                 Temp1 = Tav1 - (H01 / H) * (Tup - Tdown);
     881          537 :                 Temp2 = Tav2 - (H02 / H) * (Tdown - Tup);
     882        28374 :             } else if (Tgap2 >= Tgap1) {
     883        28374 :                 Temp1 = Tav1 - (H01 / H) * (Tdown - Tup);
     884        28374 :                 Temp2 = Tav2 - (H02 / H) * (Tup - Tdown);
     885              :             }
     886              : 
     887        28911 :             Tgap1 = AirflowRelaxationParameter * Temp1 + (1.0 - AirflowRelaxationParameter) * TGapOld1;
     888        28911 :             Tgap2 = AirflowRelaxationParameter * Temp2 + (1.0 - AirflowRelaxationParameter) * TGapOld2;
     889              : 
     890        28911 :             converged = false;
     891        28911 :             if ((std::abs(Tgap1 - TGapOld1) < AirflowConvergenceTolerance) || (iter >= NumOfIterations)) {
     892        22070 :                 if (std::abs(Tgap2 - TGapOld2) < AirflowConvergenceTolerance) {
     893        20072 :                     converged = true;
     894              :                 }
     895              :             }
     896              :         }
     897              : 
     898        20072 :         hcv1 = 2.0 * hc1 + 4.0 * speed1;
     899        20072 :         hcv2 = 2.0 * hc2 + 4.0 * speed2;
     900              : 
     901        20072 :         if (Tgap2 >= Tgap1) {
     902        19722 :             qv1 = -dens1 * cp1 * speed1 * s1 * L * (Tdown - Tup) / (H * L);
     903        19722 :             qv2 = -dens2 * cp2 * speed2 * s2 * L * (Tup - Tdown) / (H * L);
     904          350 :         } else if (Tgap2 < Tgap1) {
     905          350 :             qv1 = dens1 * cp1 * speed1 * s1 * L * (Tdown - Tup) / (H * L);
     906          350 :             qv2 = dens2 * cp2 * speed2 * s2 * L * (Tup - Tdown) / (H * L);
     907              :         }
     908              : 
     909              :         //  write(*, *) Tup-Tdown
     910              :         //  write(*, 998) Tup - Tdown, qv1, qv2
     911              : 
     912              :         // 998  format(f15.9, f15.9, f15.9)
     913              : 
     914              :         // bi..  testing - velocities output file
     915              :         // bi      open(unit = 33, file = 'velocities.out', status='unknown', form='formatted', iostat = er)
     916              : 
     917              :         // bi  write(33, 987) speed1
     918              : 
     919        20072 :         qsmooth = (std::abs(qv1) + std::abs(qv2)) / 2.0;
     920              : 
     921        20072 :         if (qv1 > 0.0) {
     922        19722 :             qv1 = qsmooth;
     923        19722 :             qv2 = -qsmooth;
     924              :         } else {
     925          350 :             qv1 = -qsmooth;
     926          350 :             qv2 = qsmooth;
     927              :         }
     928              :     }
     929              : 
     930       134498 :     void shadingedge(EnergyPlusData &state,
     931              :                      const Array1D_int &iprop1,
     932              :                      const Array1D<Real64> &frct1,
     933              :                      Real64 const press1,
     934              :                      int const nmix1,
     935              :                      const Array1D_int &iprop2,
     936              :                      const Array1D<Real64> &frct2,
     937              :                      Real64 const press2,
     938              :                      int const nmix2,
     939              :                      const Array1D<Real64> &xwght,
     940              :                      Array2A<Real64> const xgcon,
     941              :                      Array2A<Real64> const xgvis,
     942              :                      Array2A<Real64> const xgcp,
     943              :                      Real64 &Atop,
     944              :                      Real64 &Abot,
     945              :                      Real64 const Al,
     946              :                      Real64 const Ar,
     947              :                      Real64 &Ah,
     948              :                      Real64 const s,
     949              :                      Real64 const H,
     950              :                      Real64 const L,
     951              :                      Real64 const angle,
     952              :                      Real64 const forcedspeed,
     953              :                      Real64 const hc,
     954              :                      Real64 const Tenv,
     955              :                      Real64 const Tav,
     956              :                      Real64 &Tgap,
     957              :                      Real64 &hcv,
     958              :                      Real64 &qv,
     959              :                      int &nperr,
     960              :                      std::string &ErrorMessage,
     961              :                      Real64 &speed)
     962              :     {
     963              :         //**************************************************************************************************************
     964              :         //  Input:
     965              :         //  iprop1      Vector of gas identifiers
     966              :         //  frct1      Fraction of gasses in a mixture
     967              :         //  nmix1      Number of gasses in a mixture
     968              :         //  press1      Pressure in mixture
     969              :         //  iprop2      Vector of gas identifiers
     970              :         //  frct2      Fraction of gasses in a mixture
     971              :         //  nmix2      Number of gasses in a mixture
     972              :         //  press2      Pressure in mixture
     973              :         //  Atop      Opening between top of shading device and top of glazing cavity [m^2]
     974              :         //  Abot      Opening between bottom of shading device and bottom of glazing cavity [m^2]
     975              :         //  Al        Opening between left of shading device and left end of glazing cavity [m^2]
     976              :         //  Ar        Opening between right of shading device and right end of glazing cavity [m^2]
     977              :         //  Ah        Total area holes in the shading device [m^2]
     978              :         //  s        Gap width [m]
     979              :         //  H        IGU cavity height [m]
     980              :         //  L        IGU cavity width [m]
     981              :         //  angle      Window angle [degrees]
     982              :         //  forcedspeed    Speed of forced ventilation [m/s]
     983              :         //  hc        Convective/conductive coefficient for non-vented gap
     984              :         //  Tenv      Environmental temperature
     985              :         //  Tav        Average temperature of gap surfaces
     986              :         //  Output:
     987              :         //  Tgap      Temperature of vented gap
     988              :         //  hcv        Convective/conductive coefficient for vented gap
     989              :         //  qv        Heat transfer to the gap by ventilation [W/m^2]
     990              :         //  nperr      Error flag
     991              :         //  speed      Air velocity
     992              :         //**************************************************************************************************************
     993              : 
     994              :         // Using/Aliasing
     995              :         // Argument array dimensioning
     996       134498 :         EP_SIZE_CHECK(iprop1, maxgas);
     997       134498 :         EP_SIZE_CHECK(frct1, maxgas);
     998       134498 :         EP_SIZE_CHECK(iprop2, maxgas);
     999       134498 :         EP_SIZE_CHECK(frct2, maxgas);
    1000       134498 :         EP_SIZE_CHECK(xwght, maxgas);
    1001       134498 :         xgcon.dim(3, maxgas);
    1002       134498 :         xgvis.dim(3, maxgas);
    1003       134498 :         xgcp.dim(3, maxgas);
    1004              : 
    1005              :         // Locals
    1006              :         Real64 A;
    1007              :         Real64 A1;
    1008              :         Real64 A2;
    1009              :         Real64 B1;
    1010              :         Real64 C1;
    1011              :         Real64 D1;
    1012              :         Real64 Zin1;
    1013              :         Real64 Zout1;
    1014              :         Real64 A1eqin;
    1015              :         Real64 A1eqout;
    1016              :         Real64 T0;
    1017              :         Real64 tilt;
    1018              :         Real64 dens0;
    1019              :         Real64 visc0;
    1020              :         Real64 con0;
    1021              :         Real64 pr0;
    1022              :         Real64 cp0;
    1023              :         // REAL(r64) :: dens1, visc1, con1, pr1, cp1
    1024              :         Real64 dens2;
    1025              :         Real64 visc2;
    1026              :         Real64 con2;
    1027              :         Real64 pr2;
    1028              :         Real64 cp2;
    1029              :         Real64 Tgapout;
    1030              :         Real64 H0;
    1031              :         Real64 P;
    1032              :         Real64 beta;
    1033              : 
    1034              :         // iteration parameters
    1035              :         int iter;
    1036              :         Real64 TGapOld;
    1037              :         bool converged;
    1038              : 
    1039       134498 :         tilt = Constant::Pi / 180.0 * (angle - 90.0);
    1040       134498 :         T0 = 0.0 + Constant::Kelvin;
    1041              : 
    1042       134498 :         GASSES90(state,
    1043              :                  T0,
    1044              :                  iprop1,
    1045              :                  frct1,
    1046              :                  press1,
    1047              :                  nmix1,
    1048              :                  xwght,
    1049              :                  xgcon,
    1050              :                  xgvis,
    1051              :                  xgcp,
    1052              :                  con0,
    1053              :                  visc0,
    1054              :                  dens0,
    1055              :                  cp0,
    1056              :                  pr0,
    1057              :                  TARCOGGassesParams::Stdrd::ISO15099,
    1058              :                  nperr,
    1059              :                  ErrorMessage);
    1060              :         // call gasses90(Tenv, iprop1, frct1, press1, nmix1, xwght, xgcon, xgvis, xgcp, con1, visc1, dens1, cp1, pr1, 1, &
    1061              :         //                nperr, ErrorMessage)
    1062              : 
    1063              :         // exit on error:
    1064       134498 :         if ((nperr > 0) && (nperr < 1000)) {
    1065            0 :             return;
    1066              :         }
    1067              : 
    1068              :         // dr...check for error messages
    1069       134498 :         if ((Tgap * Tenv) == 0.0) {
    1070            0 :             nperr = 15;
    1071            0 :             ErrorMessage = "Temperature of vented air must be greater then 0 [K].";
    1072            0 :             return;
    1073              :         }
    1074              : 
    1075       134498 :         if ((Atop + Abot) == 0) {
    1076              :             //    nperr = 16
    1077              :             //    return
    1078       134498 :             Atop = 0.000001;
    1079       134498 :             Abot = 0.000001;
    1080              :         }
    1081       134498 :         if ((Ah + Al + Ar) == 0.0) {
    1082            0 :             Ah = 0.000001;
    1083              :         }
    1084              : 
    1085       134498 :         converged = false;
    1086       134498 :         iter = 0;
    1087       134498 :         Real64 const s_2 = pow_2(s);
    1088       134498 :         Real64 const abs_cos_tilt = std::abs(std::cos(tilt));
    1089              : 
    1090       344726 :         while (!converged) {
    1091       210228 :             ++iter;
    1092       210228 :             GASSES90(state,
    1093              :                      Tgap,
    1094              :                      iprop2,
    1095              :                      frct2,
    1096              :                      press2,
    1097              :                      nmix2,
    1098              :                      xwght,
    1099              :                      xgcon,
    1100              :                      xgvis,
    1101              :                      xgcp,
    1102              :                      con2,
    1103              :                      visc2,
    1104              :                      dens2,
    1105              :                      cp2,
    1106              :                      pr2,
    1107              :                      TARCOGGassesParams::Stdrd::ISO15099,
    1108              :                      nperr,
    1109              :                      ErrorMessage);
    1110              : 
    1111       210228 :             if ((nperr > 0) && (nperr < 1000)) {
    1112            0 :                 return;
    1113              :             }
    1114              : 
    1115              :             //  A = dens0 * T0 * gravity * ABS(cos(tilt)) * ABS(Tgap - Tenv) / (Tgap * Tenv)
    1116              : 
    1117              :             // bi...Bug fix #00005:
    1118       210228 :             A = dens0 * T0 * Constant::Gravity * H * abs_cos_tilt * std::abs(Tgap - Tenv) / (Tgap * Tenv);
    1119              :             //  A = dens0 * T0 * GravityConstant * H * ABS(cos(tilt)) * (Tgap - Tenv) / (Tgap * Tenv)
    1120              : 
    1121       210228 :             B1 = dens2 / 2;
    1122       210228 :             C1 = 12.0 * visc2 * H / s_2;
    1123              : 
    1124       210228 :             if (Tgap > Tenv) {
    1125       113475 :                 A1eqin = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
    1126       113475 :                 A1eqout = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
    1127        96753 :             } else if (Tgap <= Tenv) {
    1128        96753 :                 A1eqout = Abot + 0.5 * Atop * (Al + Ar + Ah) / (Abot + Atop);
    1129        96753 :                 A1eqin = Atop + 0.5 * Abot * (Al + Ar + Ah) / (Abot + Atop);
    1130              :             }
    1131              : 
    1132       210228 :             Zin1 = pow_2((s * L / (0.6 * A1eqin)) - 1);
    1133       210228 :             Zout1 = pow_2((s * L / (0.6 * A1eqout)) - 1);
    1134              : 
    1135       210228 :             D1 = (dens2 / 2.0) * (Zin1 + Zout1);
    1136              : 
    1137       210228 :             A1 = B1 + D1;
    1138       210228 :             A2 = C1;
    1139              : 
    1140              :             // dr...recalculate speed if forced speed exist
    1141              :             // bi...skip forced vent for now
    1142              :             //  if (forcedspeed.ne.0) then
    1143       210228 :             if ((forcedspeed != 0.0) && (static_cast<int>(CalcForcedVentilation::Allow))) {
    1144            0 :                 speed = forcedspeed;
    1145              :             } else {
    1146       210228 :                 speed = (std::sqrt(pow_2(A2) + std::abs(4.0 * A * A1)) - A2) / (2.0 * A1);
    1147              :                 //  speed = ABS((SQRT((A2 ** 2) + (4 * A * A1)) - A2) / (2 * A1))
    1148              :             }
    1149              : 
    1150       210228 :             TGapOld = Tgap;
    1151              : 
    1152              :             // Speed is zero when environment temperature is equal to average layer temperatures
    1153              :             // For example, this can happen when inside and outside temperatures are equal
    1154       210228 :             if (speed != 0.0) {
    1155       210180 :                 H0 = (dens2 * cp2 * s * speed) / (4.0 * hc + 8.0 * speed);
    1156              : 
    1157       210180 :                 P = -H / H0;
    1158       210180 :                 if (P < -700.0) {
    1159         9214 :                     beta = 0.0;
    1160              :                 } else {
    1161       200966 :                     beta = std::pow(e, P);
    1162              :                 }
    1163       210180 :                 Tgapout = Tav - (Tav - Tenv) * beta;
    1164       210180 :                 Tgap = Tav - (H0 / H) * (Tgapout - Tenv);
    1165              :             } else {
    1166           48 :                 Tgapout = Tav;
    1167           48 :                 Tgap = Tav;
    1168              :             }
    1169              : 
    1170       210228 :             converged = false;
    1171       210228 :             if ((std::abs(Tgap - TGapOld) < AirflowConvergenceTolerance) || (iter >= NumOfIterations)) {
    1172       134498 :                 converged = true;
    1173              :             }
    1174              : 
    1175              :             // if (iter > NumOfIterations) then
    1176              :             //  converged = .TRUE.
    1177              :             // end if
    1178              :         }
    1179              : 
    1180              :         // bi...Test output:
    1181              :         //  write(*,101) tenv, tgap, tgapout
    1182              :         // 101  format(f15.9, f15.9, f15.9)
    1183              : 
    1184       134498 :         hcv = 2.0 * hc + 4.0 * speed;
    1185              : 
    1186       134498 :         qv = dens2 * cp2 * speed * s * L * (Tenv - Tgapout) / (H * L);
    1187              :     }
    1188              : 
    1189        37990 :     void updateEffectiveMultipliers(int const nlayer,                          // Number of layers
    1190              :                                     Real64 const width,                        // IGU width [m]
    1191              :                                     Real64 const height,                       // IGU height [m]
    1192              :                                     const Array1D<Real64> &Atop,               // Top opening area [m2]
    1193              :                                     const Array1D<Real64> &Abot,               // Bottom opening area [m2]
    1194              :                                     const Array1D<Real64> &Al,                 // Left side opening area [m2]
    1195              :                                     const Array1D<Real64> &Ar,                 // Right side opening area [m2]
    1196              :                                     const Array1D<Real64> &Ah,                 // Front side opening area [m2]
    1197              :                                     Array1D<Real64> &Atop_eff,                 // Output - Effective top opening area [m2]
    1198              :                                     Array1D<Real64> &Abot_eff,                 // Output - Effective bottom opening area [m2]
    1199              :                                     Array1D<Real64> &Al_eff,                   // Output - Effective left side opening area [m2]
    1200              :                                     Array1D<Real64> &Ar_eff,                   // Output - Effective right side opening area [m2]
    1201              :                                     Array1D<Real64> &Ah_eff,                   // Output - Effective front side opening area [m2]
    1202              :                                     const Array1D<TARCOGLayerType> &LayerType, // Layer type
    1203              :                                     const Array1D<Real64> &SlatAngle           // Venetian layer slat angle [deg]
    1204              :     )
    1205              :     {
    1206       144562 :         for (int i = 1; i <= nlayer; ++i) {
    1207       106572 :             if (LayerType(i) == TARCOGLayerType::VENETBLIND_HORIZ || LayerType(i) == TARCOGLayerType::VENETBLIND_VERT) {
    1208         5718 :                 const Real64 slatAngRad = SlatAngle(i) * 2 * Constant::Pi / 360;
    1209         5718 :                 Real64 C1_VENET(0);
    1210         5718 :                 Real64 C2_VENET(0);
    1211         5718 :                 Real64 C3_VENET(0);
    1212              : 
    1213         5718 :                 if (LayerType(i) == TARCOGLayerType::VENETBLIND_HORIZ) {
    1214         3028 :                     C1_VENET = C1_VENET_HORIZONTAL;
    1215         3028 :                     C2_VENET = C2_VENET_HORIZONTAL;
    1216         3028 :                     C3_VENET = C3_VENET_HORIZONTAL;
    1217              :                 }
    1218         5718 :                 if (LayerType(i) == TARCOGLayerType::VENETBLIND_VERT) {
    1219         2690 :                     C1_VENET = C1_VENET_VERTICAL;
    1220         2690 :                     C2_VENET = C2_VENET_VERTICAL;
    1221         2690 :                     C3_VENET = C3_VENET_VERTICAL;
    1222              :                 }
    1223         5718 :                 Ah_eff(i) = width * height * C1_VENET * pow((Ah(i) / (width * height)) * pow(cos(slatAngRad), C2_VENET), C3_VENET);
    1224         5718 :                 Al_eff(i) = 0.0;
    1225         5718 :                 Ar_eff(i) = 0.0;
    1226         5718 :                 Atop_eff(i) = Atop(i);
    1227         5718 :                 Abot_eff(i) = Abot(i);
    1228       189608 :             } else if ((LayerType(i) == TARCOGLayerType::PERFORATED) || (LayerType(i) == TARCOGLayerType::DIFFSHADE) ||
    1229       189608 :                        (LayerType(i) == TARCOGLayerType::BSDF) || (LayerType(i) == TARCOGLayerType::WOVSHADE)) {
    1230        24200 :                 Ah_eff(i) = width * height * C1_SHADE * pow((Ah(i) / (width * height)), C2_SHADE);
    1231        24200 :                 Al_eff(i) = Al(i) * C3_SHADE;
    1232        24200 :                 Ar_eff(i) = Ar(i) * C3_SHADE;
    1233        24200 :                 Atop_eff(i) = Atop(i) * C4_SHADE;
    1234        24200 :                 Abot_eff(i) = Abot(i) * C4_SHADE;
    1235              :             } else {
    1236        76654 :                 Ah_eff(i) = Ah(i);
    1237        76654 :                 Al_eff(i) = Al(i);
    1238        76654 :                 Ar_eff(i) = Ar(i);
    1239        76654 :                 Atop_eff(i) = Atop(i);
    1240        76654 :                 Abot_eff(i) = Abot(i);
    1241              :             }
    1242              :         }
    1243        37990 :     }
    1244              : 
    1245              : } // namespace TarcogShading
    1246              : 
    1247              : } // namespace EnergyPlus
        

Generated by: LCOV version 2.0-1