LCOV - code coverage report
Current view: top level - EnergyPlus - DataEnvironment.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 35 77 45.5 %
Date: 2023-01-17 19:17:23 Functions: 6 9 66.7 %

          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 <cmath>
      50             : 
      51             : // EnergyPlus Headers
      52             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      53             : #include <EnergyPlus/DataEnvironment.hh>
      54             : #include <EnergyPlus/DataGlobals.hh>
      55             : #include <EnergyPlus/UtilityRoutines.hh>
      56             : 
      57             : namespace EnergyPlus::DataEnvironment {
      58             : 
      59             : // MODULE INFORMATION:
      60             : //       AUTHOR         Rick Strand, Dan Fisher, Linda Lawrie
      61             : //       DATE WRITTEN   December 1997
      62             : //       MODIFIED       November 1998, Fred Winkelmann
      63             : //       MODIFIED       June 1999,June 2000, Linda Lawrie
      64             : //       RE-ENGINEERED  na
      65             : 
      66             : // PURPOSE OF THIS MODULE:
      67             : // This data-only module is a repository for the variables that relate specifically
      68             : // to the "environment" (i.e. current date data, tomorrow's date data, and
      69             : // current weather variables)
      70             : 
      71    28709158 : Real64 OutDryBulbTempAt(EnergyPlusData &state, Real64 const Z) // Height above ground (m)
      72             : {
      73             : 
      74             :     // FUNCTION INFORMATION:
      75             :     //       AUTHOR         Peter Graham Ellis
      76             :     //       DATE WRITTEN   January 2006
      77             :     //       MODIFIED       na
      78             :     //       RE-ENGINEERED  na
      79             : 
      80             :     // PURPOSE OF THIS FUNCTION:
      81             :     // Calculates outdoor dry bulb temperature at a given altitude.
      82             : 
      83             :     // METHODOLOGY EMPLOYED:
      84             :     // 1976 U.S. Standard Atmosphere.
      85             : 
      86             :     // REFERENCES:
      87             :     // 1976 U.S. Standard Atmosphere. 1976. U.S. Government Printing Office, Washington, D.C.
      88             : 
      89             :     // Using/Aliasing
      90             : 
      91             :     // Return value
      92             :     Real64 LocalOutDryBulbTemp; // Return result for function (C)
      93             : 
      94             :     // Locals
      95             :     // FUNCTION ARGUMENT DEFINITIONS:
      96             : 
      97             :     // FUNCTION LOCAL VARIABLE DECLARATIONS:
      98             :     Real64 BaseTemp; // Base temperature at Z = 0 (C)
      99             : 
     100    28709158 :     BaseTemp = state.dataEnvrn->OutDryBulbTemp + state.dataEnvrn->WeatherFileTempModCoeff;
     101             : 
     102    28709158 :     if (state.dataEnvrn->SiteTempGradient == 0.0) {
     103           0 :         LocalOutDryBulbTemp = state.dataEnvrn->OutDryBulbTemp;
     104    28709158 :     } else if (Z <= 0.0) {
     105    18935183 :         LocalOutDryBulbTemp = BaseTemp;
     106             :     } else {
     107     9773975 :         LocalOutDryBulbTemp = BaseTemp - state.dataEnvrn->SiteTempGradient * DataEnvironment::EarthRadius * Z / (DataEnvironment::EarthRadius + Z);
     108             :     }
     109             : 
     110    28709158 :     if (LocalOutDryBulbTemp < -100.0) {
     111           0 :         ShowSevereError(state, "OutDryBulbTempAt: outdoor drybulb temperature < -100 C");
     112           0 :         ShowContinueError(state, format("...check heights, this height=[{:.0R}].", Z));
     113           0 :         ShowFatalError(state, "Program terminates due to preceding condition(s).");
     114             :     }
     115             : 
     116    28709158 :     return LocalOutDryBulbTemp;
     117             : }
     118             : 
     119      777639 : Real64 OutWetBulbTempAt(EnergyPlusData &state, Real64 const Z) // Height above ground (m)
     120             : {
     121             : 
     122             :     // FUNCTION INFORMATION:
     123             :     //       AUTHOR         Peter Graham Ellis
     124             :     //       DATE WRITTEN   January 2006
     125             :     //       MODIFIED       na
     126             :     //       RE-ENGINEERED  na
     127             : 
     128             :     // PURPOSE OF THIS FUNCTION:
     129             :     // Calculates outdoor wet bulb temperature at a given altitude.
     130             : 
     131             :     // METHODOLOGY EMPLOYED:
     132             :     // 1976 U.S. Standard Atmosphere.
     133             : 
     134             :     // REFERENCES:
     135             :     // 1976 U.S. Standard Atmosphere. 1976. U.S. Government Printing Office, Washington, D.C.
     136             : 
     137             :     // Return value
     138             :     Real64 LocalOutWetBulbTemp; // Return result for function (C)
     139             : 
     140             :     // FUNCTION LOCAL VARIABLE DECLARATIONS:
     141             :     Real64 BaseTemp; // Base temperature at Z = 0 (C)
     142             : 
     143      777639 :     BaseTemp = state.dataEnvrn->OutWetBulbTemp + state.dataEnvrn->WeatherFileTempModCoeff;
     144             : 
     145      777639 :     if (state.dataEnvrn->SiteTempGradient == 0.0) {
     146           0 :         LocalOutWetBulbTemp = state.dataEnvrn->OutWetBulbTemp;
     147      777639 :     } else if (Z <= 0.0) {
     148      493198 :         LocalOutWetBulbTemp = BaseTemp;
     149             :     } else {
     150      284441 :         LocalOutWetBulbTemp = BaseTemp - state.dataEnvrn->SiteTempGradient * DataEnvironment::EarthRadius * Z / (DataEnvironment::EarthRadius + Z);
     151             :     }
     152             : 
     153      777639 :     if (LocalOutWetBulbTemp < -100.0) {
     154           0 :         ShowSevereError(state, "OutWetBulbTempAt: outdoor wetbulb temperature < -100 C");
     155           0 :         ShowContinueError(state, format("...check heights, this height=[{:.0R}].", Z));
     156           0 :         ShowFatalError(state, "Program terminates due to preceding condition(s).");
     157             :     }
     158             : 
     159      777639 :     return LocalOutWetBulbTemp;
     160             : }
     161             : 
     162           0 : Real64 OutDewPointTempAt(EnergyPlusData &state, Real64 const Z) // Height above ground (m)
     163             : {
     164             : 
     165             :     // FUNCTION INFORMATION:
     166             :     //       AUTHOR         Linda Lawrie
     167             :     //       DATE WRITTEN   March 2007
     168             :     //       MODIFIED       na
     169             :     //       RE-ENGINEERED  na
     170             : 
     171             :     // PURPOSE OF THIS FUNCTION:
     172             :     // Calculates outdoor dew point temperature at a given altitude.
     173             : 
     174             :     // METHODOLOGY EMPLOYED:
     175             :     // 1976 U.S. Standard Atmosphere.
     176             :     // copied from outwetbulbtempat
     177             : 
     178             :     // REFERENCES:
     179             :     // 1976 U.S. Standard Atmosphere. 1976. U.S. Government Printing Office, Washington, D.C.
     180             : 
     181             :     // Return value
     182             :     Real64 LocalOutDewPointTemp; // Return result for function (C)
     183             : 
     184             :     // FUNCTION LOCAL VARIABLE DECLARATIONS:
     185             :     Real64 BaseTemp; // Base temperature at Z = 0 (C)
     186             : 
     187           0 :     BaseTemp = state.dataEnvrn->OutDewPointTemp + state.dataEnvrn->WeatherFileTempModCoeff;
     188             : 
     189           0 :     if (state.dataEnvrn->SiteTempGradient == 0.0) {
     190           0 :         LocalOutDewPointTemp = state.dataEnvrn->OutDewPointTemp;
     191           0 :     } else if (Z <= 0.0) {
     192           0 :         LocalOutDewPointTemp = BaseTemp;
     193             :     } else {
     194           0 :         LocalOutDewPointTemp = BaseTemp - state.dataEnvrn->SiteTempGradient * DataEnvironment::EarthRadius * Z / (DataEnvironment::EarthRadius + Z);
     195             :     }
     196             : 
     197           0 :     if (LocalOutDewPointTemp < -100.0) {
     198           0 :         ShowSevereError(state, "OutDewPointTempAt: outdoor dewpoint temperature < -100 C");
     199           0 :         ShowContinueError(state, format("...check heights, this height=[{:.0R}].", Z));
     200           0 :         ShowFatalError(state, "Program terminates due to preceding condition(s).");
     201             :     }
     202             : 
     203           0 :     return LocalOutDewPointTemp;
     204             : }
     205             : 
     206     6097900 : Real64 WindSpeedAt(EnergyPlusData &state, Real64 const Z) // Height above ground (m)
     207             : {
     208             : 
     209             :     // FUNCTION INFORMATION:
     210             :     //       AUTHOR         Peter Graham Ellis
     211             :     //       DATE WRITTEN   January 2006
     212             :     //       MODIFIED       na
     213             :     //       RE-ENGINEERED  na
     214             : 
     215             :     // PURPOSE OF THIS FUNCTION:
     216             :     // Calculates local wind speed at a given altitude.
     217             : 
     218             :     // METHODOLOGY EMPLOYED:
     219             :     // 2005 ASHRAE Fundamentals, Chapter 16, Equation 4.  (Different depending on terrain).
     220             : 
     221             :     // REFERENCES:
     222             :     // 2005 ASHRAE Fundamentals, Chapter 16, Equation 4.  (Different depending on terrain).
     223             :     // Terrain variables are set in HeatBalanceManager or entered by the user.
     224             : 
     225             :     // Return value
     226             :     Real64 LocalWindSpeed; // Return result for function (m/s)
     227             : 
     228     6097900 :     if (Z <= 0.0) {
     229      493198 :         LocalWindSpeed = 0.0;
     230     5604702 :     } else if (state.dataEnvrn->SiteWindExp == 0.0) {
     231           0 :         LocalWindSpeed = state.dataEnvrn->WindSpeed;
     232             :     } else {
     233             :         //  [Met] - at meterological Station, Height of measurement is usually 10m above ground
     234             :         //  LocalWindSpeed = Windspeed [Met] * (Wind Boundary LayerThickness [Met]/Height [Met])**Wind Exponent[Met] &
     235             :         //                     * (Height above ground / Site Wind Boundary Layer Thickness) ** Site Wind Exponent
     236    11209404 :         LocalWindSpeed = state.dataEnvrn->WindSpeed * state.dataEnvrn->WeatherFileWindModCoeff *
     237     5604702 :                          std::pow(Z / state.dataEnvrn->SiteWindBLHeight, state.dataEnvrn->SiteWindExp);
     238             :     }
     239             : 
     240     6097900 :     return LocalWindSpeed;
     241             : }
     242             : 
     243       16344 : Real64 OutBaroPressAt(EnergyPlusData &state, Real64 const Z) // Height above ground (m)
     244             : {
     245             : 
     246             :     // FUNCTION INFORMATION:
     247             :     //       AUTHOR         Daeho Kang
     248             :     //       DATE WRITTEN   August 2009
     249             :     //       MODIFIED       na
     250             :     //       RE-ENGINEERED  na
     251             : 
     252             :     // PURPOSE OF THIS FUNCTION:
     253             :     // Calculates local air barometric pressure at a given altitude.
     254             : 
     255             :     // METHODOLOGY EMPLOYED:
     256             :     // U.S. Standard Atmosphere1976, Part 1, Chapter 1.3, Equation 33b.
     257             : 
     258             :     // REFERENCES:
     259             :     // U.S. Standard Atmosphere1976, Part 1, Chapter 1.3, Equation 33b.
     260             : 
     261             :     // Return value
     262             :     Real64 LocalAirPressure; // Return result for function (Pa)
     263             : 
     264             :     // FNCTION PARAMETER DEFINITIONS:
     265       16344 :     Real64 constexpr StdGravity(9.80665);    // The acceleration of gravity at the sea level (m/s2)
     266       16344 :     Real64 constexpr AirMolarMass(0.028964); // Molar mass of Earth's air (kg/mol)
     267       16344 :     Real64 constexpr GasConstant(8.31432);   // Molar gas constant (J/Mol-K)
     268       16344 :     Real64 constexpr TempGradient(-0.0065);  // Molecular-scale temperature gradient (K/m)
     269       16344 :     Real64 constexpr GeopotentialH(0.0);     // Geopotential height (zero within 11km from the sea level) (m)
     270             : 
     271             :     // FUNCTION LOCAL VARIABLE DECLARATIONS:
     272             :     Real64 BaseTemp; // Base temperature at Z
     273             : 
     274       16344 :     BaseTemp = OutDryBulbTempAt(state, Z) + DataGlobalConstants::KelvinConv;
     275             : 
     276       16344 :     if (Z <= 0.0) {
     277           0 :         LocalAirPressure = 0.0;
     278       16344 :     } else if (state.dataEnvrn->SiteTempGradient == 0.0) {
     279           0 :         LocalAirPressure = state.dataEnvrn->OutBaroPress;
     280             :     } else {
     281       16344 :         LocalAirPressure = state.dataEnvrn->StdBaroPress * std::pow(BaseTemp / (BaseTemp + TempGradient * (Z - GeopotentialH)),
     282             :                                                                     (StdGravity * AirMolarMass) / (GasConstant * TempGradient));
     283             :     }
     284             : 
     285       16344 :     return LocalAirPressure;
     286             : }
     287             : 
     288           0 : void SetOutBulbTempAt_error(EnergyPlusData &state, std::string const &Settings, Real64 const max_height, std::string const &SettingsName)
     289             : {
     290             :     // Using/Aliasing
     291             : 
     292           0 :     ShowSevereError(state, "SetOutBulbTempAt: " + Settings + " Outdoor Temperatures < -100 C");
     293           0 :     ShowContinueError(state, format("...check {} Heights - Maximum {} Height=[{:.0R}].", Settings, Settings, max_height));
     294           0 :     if (max_height >= 20000.0) {
     295           0 :         ShowContinueError(state, "...according to your maximum Z height, your building is somewhere in the Stratosphere.");
     296           0 :         ShowContinueError(state, "...look at " + Settings + " Name= " + SettingsName);
     297             :     }
     298           0 :     ShowFatalError(state, "Program terminates due to preceding condition(s).");
     299           0 : }
     300             : 
     301           0 : void SetWindSpeedAt(EnergyPlusData &state,
     302             :                     int const NumItems,
     303             :                     const Array1D<Real64> &Heights,
     304             :                     Array1D<Real64> &LocalWindSpeed,
     305             :                     [[maybe_unused]] std::string const &Settings)
     306             : {
     307             : 
     308             :     // SUBROUTINE INFORMATION:
     309             :     //       AUTHOR         Linda Lawrie
     310             :     //       DATE WRITTEN   June 2013
     311             :     //       MODIFIED       na
     312             :     //       RE-ENGINEERED  na
     313             : 
     314             :     // PURPOSE OF THIS SUBROUTINE:
     315             :     // Routine provides facility for doing bulk Set Windspeed at Height.
     316             : 
     317           0 :     if (state.dataEnvrn->SiteWindExp == 0.0) {
     318           0 :         LocalWindSpeed = state.dataEnvrn->WindSpeed;
     319             :     } else {
     320           0 :         Real64 const fac(state.dataEnvrn->WindSpeed * state.dataEnvrn->WeatherFileWindModCoeff *
     321           0 :                          std::pow(state.dataEnvrn->SiteWindBLHeight, -state.dataEnvrn->SiteWindExp));
     322             :         Real64 Z; // Centroid value
     323           0 :         for (int i = 1; i <= NumItems; ++i) {
     324           0 :             Z = Heights(i);
     325           0 :             if (Z <= 0.0) {
     326           0 :                 LocalWindSpeed(i) = 0.0;
     327             :             } else {
     328             :                 //  [Met] - at meterological Station, Height of measurement is usually 10m above ground
     329             :                 //  LocalWindSpeed = Windspeed [Met] * (Wind Boundary LayerThickness [Met]/Height [Met])**Wind Exponent[Met] &
     330             :                 //                     * (Height above ground / Site Wind Boundary Layer Thickness) ** Site Wind Exponent
     331           0 :                 LocalWindSpeed(i) = fac * std::pow(Z, state.dataEnvrn->SiteWindExp);
     332             :             }
     333             :         }
     334             :     }
     335           0 : }
     336             : 
     337        2313 : } // namespace EnergyPlus::DataEnvironment

Generated by: LCOV version 1.13