LCOV - code coverage report
Current view: top level - EnergyPlus - TARCOGGasses90.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 70 97 72.2 %
Date: 2023-01-17 19:17:23 Functions: 3 4 75.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             : // C++ Headers
      49             : #include <cassert>
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Array1D.hh>
      53             : #include <ObjexxFCL/Array2D.hh>
      54             : #include <ObjexxFCL/Fmath.hh>
      55             : 
      56             : // EnergyPlus Headers
      57             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      58             : #include <EnergyPlus/DataGlobals.hh>
      59             : #include <EnergyPlus/TARCOGGasses90.hh>
      60             : #include <EnergyPlus/TARCOGGassesParams.hh>
      61             : 
      62             : namespace EnergyPlus::TARCOGGasses90 {
      63             : 
      64             : // MODULE INFORMATION:
      65             : //       AUTHOR         D. Charlie Curcija
      66             : //       DATE WRITTEN   June/2000
      67             : //       MODIFIED       (see revision history bellow)
      68             : //       RE-ENGINEERED  na
      69             : //  Revision: 7.0.02  (November/8/2011), Simon Vidanovic
      70             : //   - feature: Error message (string) return from gasses
      71             : //  Revision: 7.0.00  (September/6/2011), Simon Vidanovic
      72             : //   - Introduction of vacuum coefficients and routine to calculate low gas pressure conductance
      73             : //  Revision: 6.3.09  (August/23/2011), Simon Vidanovic
      74             : //   - Removed GetGasIndex function which could cause a double usage of gas coefficients
      75             : //     and therefore introducing new bugs.
      76             : 
      77             : // PURPOSE OF THIS MODULE:
      78             : // A module containing functions for gas properties calculation
      79             : 
      80             : // Using/Aliasing
      81             : using namespace TARCOGGassesParams;
      82             : 
      83     1115947 : void GASSES90(EnergyPlusData &state,
      84             :               Real64 const tmean,
      85             :               const Array1D_int &iprop,
      86             :               const Array1D<Real64> &frct,
      87             :               Real64 const pres,
      88             :               int const nmix,
      89             :               const Array1D<Real64> &xwght,
      90             :               Array2<Real64> const &xgcon,
      91             :               Array2<Real64> const &xgvis,
      92             :               Array2<Real64> const &xgcp,
      93             :               Real64 &con,
      94             :               Real64 &visc,
      95             :               Real64 &dens,
      96             :               Real64 &cp,
      97             :               Real64 &pr,
      98             :               TARCOGGassesParams::Stdrd const standard,
      99             :               int &nperr,
     100             :               std::string &ErrorMessage)
     101             : {
     102             : 
     103             :     static Real64 const two_sqrt_2(2.0 * std::sqrt(2.0));
     104             :     Real64 molmix;
     105             :     Real64 cpmixm;
     106             :     Real64 phimup;
     107             :     Real64 downer;
     108             :     Real64 psiup;
     109             :     Real64 psiterm;
     110             :     Real64 phikup;
     111             : 
     112             :     // SUBROUTINE PARAMETER DEFINITIONS:
     113     1115947 :     Real64 constexpr ENpressure(1.0e5); // Gap gas pressure (Pa)
     114     1115947 :     Real64 constexpr gaslaw(8314.51);   // Molar gas constant (J/kMol-K)
     115             : 
     116             :     //!! Body of GASSES90
     117             : 
     118             :     // Autodesk:Uninit Initialize variables used uninitialized
     119             :     // xgrho = 0.0d0 //Autodesk:Uninit Force default initialization
     120             : 
     121     1115947 :     Real64 const tmean_2(pow_2(tmean));
     122     1115947 :     state.dataTARCOGGasses90->fcon(1) = xgcon(1, iprop(1)) + xgcon(2, iprop(1)) * tmean + xgcon(3, iprop(1)) * tmean_2;
     123     1115947 :     state.dataTARCOGGasses90->fvis(1) = xgvis(1, iprop(1)) + xgvis(2, iprop(1)) * tmean + xgvis(3, iprop(1)) * tmean_2;
     124     1115947 :     state.dataTARCOGGasses90->fcp(1) = xgcp(1, iprop(1)) + xgcp(2, iprop(1)) * tmean + xgcp(3, iprop(1)) * tmean_2;
     125             :     // Density using ideal gas law: rho=(presure*mol. weight)/(gas const*Tmean)
     126     1115947 :     state.dataTARCOGGasses90->fdens(1) = pres * xwght(iprop(1)) / (DataGlobalConstants::UniversalGasConst * tmean);
     127             :     // Mollecular weights in kg/kmol
     128     1115947 :     if ((standard == TARCOGGassesParams::Stdrd::EN673) || (standard == TARCOGGassesParams::Stdrd::EN673Design)) {
     129             :         // fdens( 1 ) = xgrho( iprop( 1 ), 1 ) + xgrho( iprop( 1 ), 2 ) * tmean + xgrho( iprop( 1 ), 3 ) * pow_2( tmean ); //Autodesk:Uninit xgrho
     130             :         // was uninitialized
     131           0 :         state.dataTARCOGGasses90->fdens(1) = ENpressure * xwght(iprop(1)) / (gaslaw * tmean);
     132             :     }
     133             : 
     134     1115947 :     if (frct(1) == 1.0) {                          // Single gas properties
     135      985768 :         visc = state.dataTARCOGGasses90->fvis(1);  // viscosity in kg/(m*s)
     136      985768 :         con = state.dataTARCOGGasses90->fcon(1);   // conductivity in W/(m*K)
     137      985768 :         cp = state.dataTARCOGGasses90->fcp(1);     // SpecIFic heat in J/(kg*K)
     138      985768 :         dens = state.dataTARCOGGasses90->fdens(1); // density in kg/m^3
     139             :     } else {                                       // Mixture properties
     140      130179 :         bool const stdISO15099(standard == TARCOGGassesParams::Stdrd::ISO15099);
     141      130179 :         bool const stdEN673((standard == TARCOGGassesParams::Stdrd::EN673) || (standard == TARCOGGassesParams::Stdrd::EN673Design));
     142      130179 :         if (stdISO15099) {
     143      130179 :             molmix = frct(1) * xwght(iprop(1));                 // initialize equation 56
     144      130179 :             cpmixm = molmix * state.dataTARCOGGasses90->fcp(1); // initialize equation 58
     145      130179 :             state.dataTARCOGGasses90->kprime(1) =
     146      130179 :                 3.75 * DataGlobalConstants::UniversalGasConst / xwght(iprop(1)) * state.dataTARCOGGasses90->fvis(1);        // equation 67
     147      130179 :             state.dataTARCOGGasses90->kdblprm(1) = state.dataTARCOGGasses90->fcon(1) - state.dataTARCOGGasses90->kprime(1); // equation 67
     148             :             // initialize sumations for eqns 60-66:
     149      130179 :             state.dataTARCOGGasses90->mukpdwn(1) = 1.0;
     150      130179 :             state.dataTARCOGGasses90->kpdown(1) = 1.0;
     151      130179 :             state.dataTARCOGGasses90->kdpdown(1) = 1.0;
     152             :         }
     153      260358 :         for (int i = 2; i <= nmix; ++i) {
     154      130179 :             if (frct(i) == 0.0) {
     155           0 :                 nperr = 2011; // error 2011: component fraction in a mixture is 0%
     156           0 :                 ErrorMessage = "Component fraction in mixture is 0%";
     157           0 :                 return;
     158             :             }
     159             :             // calculate properties of mixture constituents:
     160      130179 :             state.dataTARCOGGasses90->fcon(i) = xgcon(1, iprop(i)) + xgcon(2, iprop(i)) * tmean + xgcon(3, iprop(i)) * tmean_2;
     161      130179 :             state.dataTARCOGGasses90->fvis(i) = xgvis(1, iprop(i)) + xgvis(2, iprop(i)) * tmean + xgvis(3, iprop(i)) * tmean_2;
     162      130179 :             state.dataTARCOGGasses90->fcp(i) = xgcp(1, iprop(i)) + xgcp(2, iprop(i)) * tmean + xgcp(3, iprop(i)) * tmean_2;
     163      130179 :             if (stdEN673) {
     164             :                 // fdens( i ) = grho( iprop( i ), 1 ) + grho( iprop( i ), 2 ) * tmean + grho( iprop( i ), 3 ) * pow_2( tmean );
     165           0 :                 state.dataTARCOGGasses90->fdens(i) =
     166           0 :                     ENpressure * xwght(iprop(i)) / (gaslaw * tmean); // Density using ideal gas law: rho=(presure*mol. weight)/(gas const*Tmean)
     167             :             }
     168      130179 :             if (stdISO15099) {
     169      130179 :                 molmix += frct(i) * xwght(iprop(i));                                    // equation 56
     170      130179 :                 cpmixm += frct(i) * state.dataTARCOGGasses90->fcp(i) * xwght(iprop(i)); // equation 58-59
     171      130179 :                 state.dataTARCOGGasses90->kprime(i) =
     172      130179 :                     3.75 * DataGlobalConstants::UniversalGasConst / xwght(iprop(i)) * state.dataTARCOGGasses90->fvis(i);        // equation 67
     173      130179 :                 state.dataTARCOGGasses90->kdblprm(i) = state.dataTARCOGGasses90->fcon(i) - state.dataTARCOGGasses90->kprime(i); // equation 68
     174      130179 :                 state.dataTARCOGGasses90->mukpdwn(i) = 1.0; // initialize denominator of equation 60
     175      130179 :                 state.dataTARCOGGasses90->kpdown(i) = 1.0;  // initialize denominator of equation 63
     176      130179 :                 state.dataTARCOGGasses90->kdpdown(i) = 1.0; // initialize denominator of equation 65
     177             :             }
     178             :         }
     179             : 
     180      130179 :         if (stdISO15099) {
     181      130179 :             Real64 mumix(0.0);
     182      130179 :             Real64 kpmix(0.0);
     183      130179 :             Real64 kdpmix(0.0);
     184      390537 :             for (int i = 1; i <= nmix; ++i) {
     185      260358 :                 Real64 const kprime_i(state.dataTARCOGGasses90->kprime(i));
     186      260358 :                 Real64 const xwght_i(xwght(iprop(i)));
     187      781074 :                 for (int j = 1; j <= nmix; ++j) {
     188      520716 :                     Real64 const xwght_j(xwght(iprop(j)));
     189             : 
     190             :                     // numerator of equation 61
     191      520716 :                     Real64 const x_pow(root_4(xwght_j / xwght_i));
     192      520716 :                     phimup = pow_2(1.0 + std::sqrt(state.dataTARCOGGasses90->fvis(i) / state.dataTARCOGGasses90->fvis(j)) * x_pow);
     193             : 
     194             :                     // denominator of equation 61, 64 and 66
     195      520716 :                     downer = two_sqrt_2 * std::sqrt(1.0 + (xwght_i / xwght_j));
     196             : 
     197             :                     // calculate the denominator of equation 60
     198      520716 :                     if (i != j) state.dataTARCOGGasses90->mukpdwn(i) += phimup / downer * frct(j) / frct(i);
     199             : 
     200             :                     // numerator of equation 64, psiterm is the multiplied term in brackets
     201      520716 :                     psiup = pow_2(1.0 + std::sqrt(kprime_i / state.dataTARCOGGasses90->kprime(j)) / x_pow);
     202             : 
     203      520716 :                     psiterm = 1.0 + 2.41 * (xwght_i - xwght_j) * (xwght_i - 0.142 * xwght_j) / pow_2(xwght_i + xwght_j);
     204             : 
     205             :                     // using the common denominator downer calculate the denominator for equation 63
     206      520716 :                     if (i != j) state.dataTARCOGGasses90->kpdown(i) += psiup * psiterm / downer * frct(j) / frct(i);
     207             : 
     208             :                     // calculate the numerator of equation 66
     209      520716 :                     phikup = psiup; // Tuned Was pow_2( 1.0 + std::sqrt( kprime_i / kprime( j ) ) * std::pow( xwght_i / xwght_j, 0.25 ) );
     210             : 
     211             :                     // using the common denominator downer calculate the denominator for equation 65
     212      520716 :                     if (i != j) state.dataTARCOGGasses90->kdpdown(i) += phikup / downer * frct(j) / frct(i);
     213             :                 }
     214      260358 :                 mumix += state.dataTARCOGGasses90->fvis(i) / state.dataTARCOGGasses90->mukpdwn(i);     // equation 60
     215      260358 :                 kpmix += state.dataTARCOGGasses90->kprime(i) / state.dataTARCOGGasses90->kpdown(i);    // equation 63
     216      260358 :                 kdpmix += state.dataTARCOGGasses90->kdblprm(i) / state.dataTARCOGGasses90->kdpdown(i); // equation 65
     217             :             }
     218             : 
     219             :             // calculate the density of the mixture assuming an ideal gas:
     220      130179 :             Real64 const rhomix = pres * molmix / (DataGlobalConstants::UniversalGasConst * tmean); // equation 57
     221      130179 :             Real64 const kmix = kpmix + kdpmix;                                                     // equation 68-a
     222             : 
     223             :             // final mixture properties:
     224      130179 :             visc = mumix;
     225      130179 :             con = kmix;
     226      130179 :             dens = rhomix;
     227      130179 :             if (molmix > 0) {
     228      130179 :                 cp = cpmixm / molmix;
     229             :             } else {
     230           0 :                 cp = 0;
     231             :             }
     232           0 :         } else if (stdEN673) {
     233           0 :             con = 0.0;
     234           0 :             visc = 0.0;
     235           0 :             dens = 0.0;
     236           0 :             cp = 0.0;
     237           0 :             for (int i = 1; i <= nmix; ++i) {
     238           0 :                 Real64 const frct_i(frct(i));
     239           0 :                 con += state.dataTARCOGGasses90->fcon(i) * frct_i;
     240           0 :                 visc += state.dataTARCOGGasses90->fvis(i) * frct_i;
     241           0 :                 dens += state.dataTARCOGGasses90->fdens(i) * frct_i;
     242           0 :                 cp += state.dataTARCOGGasses90->fcp(i) * frct_i;
     243             :             }
     244             :         } else {
     245           0 :             assert(false); // should never come here - unsupported standard
     246             :         }
     247             :     }
     248             : 
     249     1115947 :     pr = cp * visc / con; // calculate the Prandtl number
     250             : }
     251             : 
     252           0 : void GassesLow(Real64 const tmean, Real64 const mwght, Real64 const pressure, Real64 const gama, Real64 &cond, int &nperr, std::string &ErrorMessage)
     253             : {
     254             : 
     255           0 :     Real64 const alpha = alpha1 * alpha2 / (alpha2 + alpha1 * (1 - alpha2));
     256             : 
     257           0 :     if ((gama) == 1) {
     258           0 :         nperr = 40; // supplied gamma coefficient is incorrect
     259           0 :         ErrorMessage = "Supplied gamma coefficient is incorrect.";
     260           0 :         return;
     261             :     }
     262             : 
     263             :     Real64 const B =
     264           0 :         alpha * (gama + 1) / (gama - 1) * std::sqrt(DataGlobalConstants::UniversalGasConst / (8 * DataGlobalConstants::Pi * mwght * tmean));
     265             : 
     266           0 :     cond = B * pressure;
     267             : }
     268             : 
     269        2313 : } // namespace EnergyPlus::TARCOGGasses90

Generated by: LCOV version 1.13