LCOV - code coverage report
Current view: top level - EnergyPlus - General.hh (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 33 60 55.0 %
Date: 2023-01-17 19:17:23 Functions: 11 12 91.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             : #ifndef General_hh_INCLUDED
      49             : #define General_hh_INCLUDED
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Array1A.hh>
      53             : #include <ObjexxFCL/Array1D.hh>
      54             : #include <ObjexxFCL/Array1S.hh>
      55             : #include <ObjexxFCL/Array2A.hh>
      56             : #include <ObjexxFCL/Optional.hh>
      57             : 
      58             : // EnergyPlus Headers
      59             : #include <EnergyPlus/Data/BaseData.hh>
      60             : #include <EnergyPlus/EnergyPlus.hh>
      61             : 
      62             : namespace EnergyPlus {
      63             : 
      64             : // Forward declarations
      65             : struct EnergyPlusData;
      66             : 
      67             : // Forward declaration
      68             : namespace OutputProcessor {
      69             :     enum class TimeStepType;
      70             : }
      71             : 
      72             : namespace WeatherManager {
      73             :     enum class DateType;
      74             :     struct ReportPeriodData;
      75             : } // namespace WeatherManager
      76             : 
      77             : namespace General {
      78             : 
      79             :     // A second version that does not require a payload -- use lambdas
      80             :     void SolveRoot(EnergyPlusData &state,
      81             :                    Real64 Eps,   // required absolute accuracy
      82             :                    int MaxIte,   // maximum number of allowed iterations
      83             :                    int &Flag,    // integer storing exit status
      84             :                    Real64 &XRes, // value of x that solves f(x,Par) = 0
      85             :                    const std::function<Real64(Real64)> &f,
      86             :                    Real64 X_0,  // 1st bound of interval that contains the solution
      87             :                    Real64 X_1); // 2nd bound of interval that contains the solution
      88             : 
      89      106648 :     constexpr Real64 InterpGeneral(Real64 const Lower, Real64 const Upper, Real64 const InterpFac)
      90             :     {
      91      106648 :         return Lower + InterpFac * (Upper - Lower);
      92             :     }
      93             : 
      94        4004 :     constexpr Real64 InterpProfSlat(Real64 const SlatLower,
      95             :                                     Real64 const SlatUpper,
      96             :                                     Real64 const ProfLower,
      97             :                                     Real64 const ProfUpper,
      98             :                                     Real64 const SlatInterpFac,
      99             :                                     Real64 const ProfInterpFac)
     100             :     {
     101        4004 :         Real64 ValA = SlatLower + SlatInterpFac * (SlatUpper - SlatLower);
     102        4004 :         Real64 ValB = ProfLower + SlatInterpFac * (ProfUpper - ProfLower);
     103        4004 :         return ValA + ProfInterpFac * (ValB - ValA);
     104             :     }
     105             : 
     106     1133008 :     inline Real64 InterpSw(Real64 const SwitchFac, // Switching factor: 0.0 if glazing is unswitched, = 1.0 if fully switched
     107             :                            Real64 const A,         // Glazing property in unswitched state
     108             :                            Real64 const B          // Glazing property in fully switched state
     109             :     )
     110             :     {
     111             :         // FUNCTION INFORMATION:
     112             :         //       AUTHOR         Fred Winkelmann
     113             :         //       DATE WRITTEN   February 1999
     114             : 
     115             :         // PURPOSE OF THIS FUNCTION:
     116             :         // For switchable glazing, calculates a weighted average of properties
     117             :         // A and B
     118             : 
     119             :         // Return value
     120             :         Real64 InterpSw;
     121             : 
     122             :         // FUNCTION LOCAL VARIABLE DECLARATIONS:
     123             :         Real64 locSwitchFac;
     124             : 
     125     1133008 :         locSwitchFac = min(SwitchFac, 1.0);
     126     1133008 :         locSwitchFac = max(locSwitchFac, 0.0);
     127             : 
     128     1133008 :         InterpSw = (1.0 - locSwitchFac) * A + locSwitchFac * B;
     129     1133008 :         return InterpSw;
     130             :     }
     131             : 
     132             :     Real64 InterpProfAng(Real64 ProfAng,           // Profile angle (rad)
     133             :                          Array1S<Real64> PropArray // Array of blind properties
     134             :     );
     135             : 
     136             :     Real64 InterpSlatAng(Real64 SlatAng,           // Slat angle (rad)
     137             :                          bool VarSlats,            // True if slat angle is variable
     138             :                          Array1S<Real64> PropArray // Array of blind properties as function of slat angle
     139             :     );
     140             : 
     141             :     Real64 InterpProfSlatAng(Real64 ProfAng,           // Profile angle (rad)
     142             :                              Real64 SlatAng,           // Slat angle (rad)
     143             :                              bool VarSlats,            // True if variable-angle slats
     144             :                              Array2A<Real64> PropArray // Array of blind properties
     145             :     );
     146             : 
     147             :     Real64 BlindBeamBeamTrans(Real64 ProfAng,        // Solar profile angle (rad)
     148             :                               Real64 SlatAng,        // Slat angle (rad)
     149             :                               Real64 SlatWidth,      // Slat width (m)
     150             :                               Real64 SlatSeparation, // Slat separation (distance between surfaces of adjacent slats) (m)
     151             :                               Real64 SlatThickness   // Slat thickness (m)
     152             :     );
     153             : 
     154    64709789 :     constexpr Real64 POLYF(Real64 const X,          // Cosine of angle of incidence
     155             :                            Array1D<Real64> const &A // Polynomial coefficients
     156             :     )
     157             :     {
     158    64709789 :         if (X < 0.0 || X > 1.0) {
     159       85230 :             return 0.0;
     160             :         } else {
     161    64624559 :             return X * (A(1) + X * (A(2) + X * (A(3) + X * (A(4) + X * (A(5) + X * A(6))))));
     162             :         }
     163             :     }
     164             : 
     165             :     std::string &strip_trailing_zeros(std::string &InputString);
     166             : 
     167             :     void MovingAvg(Array1D<Real64> &DataIn, int NumItemsInAvg);
     168             : 
     169             :     void ProcessDateString(EnergyPlusData &state,
     170             :                            std::string const &String,
     171             :                            int &PMonth,
     172             :                            int &PDay,
     173             :                            int &PWeekDay,
     174             :                            WeatherManager::DateType &DateType, // DateType found (-1=invalid, 1=month/day, 2=nth day in month, 3=last day in month)
     175             :                            bool &ErrorsFound,
     176             :                            Optional_int PYear = _);
     177             : 
     178             :     void DetermineDateTokens(EnergyPlusData &state,
     179             :                              std::string const &String,
     180             :                              int &NumTokens,                     // Number of tokens found in string
     181             :                              int &TokenDay,                      // Value of numeric field found
     182             :                              int &TokenMonth,                    // Value of Month field found (1=Jan, 2=Feb, etc)
     183             :                              int &TokenWeekday,                  // Value of Weekday field found (1=Sunday, 2=Monday, etc), 0 if none
     184             :                              WeatherManager::DateType &DateType, // DateType found (-1=invalid, 1=month/day, 2=nth day in month, 3=last day in month)
     185             :                              bool &ErrorsFound,                  // Set to true if cannot process this string as a date
     186             :                              Optional_int TokenYear = _          // Value of Year if one appears to be present and this argument is present
     187             :     );
     188             : 
     189             :     void ValidateMonthDay(EnergyPlusData &state,
     190             :                           std::string const &String, // REAL(r64) string being processed
     191             :                           int Day,
     192             :                           int Month,
     193             :                           bool &ErrorsFound);
     194             : 
     195             :     int OrdinalDay(int Month,        // Month, 1..12
     196             :                    int Day,          // Day of Month, not validated by month
     197             :                    int LeapYearValue // 1 if leap year indicated, 0 if not
     198             :     );
     199             : 
     200             :     void InvOrdinalDay(int Number, int &PMonth, int &PDay, int LeapYr);
     201             : 
     202             :     bool BetweenDateHoursLeftInclusive(int TestDate, int TestHour, int StartDate, int StartHour, int EndDate, int EndHour);
     203             : 
     204             :     bool BetweenDates(int TestDate,  // Date to test
     205             :                       int StartDate, // Start date in sequence
     206             :                       int EndDate    // End date in sequence
     207             :     );
     208             : 
     209             :     std::string CreateSysTimeIntervalString(EnergyPlusData &state);
     210             : 
     211             :     int nthDayOfWeekOfMonth(EnergyPlusData &state,
     212             :                             int dayOfWeek,  // day of week (Sunday=1, Monday=2, ...)
     213             :                             int nthTime,    // nth time the day of the week occurs (first monday, third tuesday, ..)
     214             :                             int monthNumber // January = 1
     215             :     );
     216             : 
     217             :     Real64 SafeDivide(Real64 a, Real64 b);
     218             : 
     219             :     void Iterate(Real64 &ResultX, // ResultX is the final Iteration result passed back to the calling routine
     220             :                  Real64 Tol,      // Tolerance for Convergence
     221             :                  Real64 X0,       // Current value of X
     222             :                  Real64 Y0,       // Current value of the function Y(X)
     223             :                  Real64 &X1,      // First Previous values of X
     224             :                  Real64 &Y1,      // First Previous values of Y(X1)
     225             :                  int Iter,        // Number of iterations
     226             :                  int &Cnvg        // Convergence flag  Cnvg = 0:  Not converged
     227             :     );
     228             : 
     229             :     int FindNumberInList(int WhichNumber, Array1A_int ListOfItems, int NumItems);
     230             : 
     231             :     template <typename A> inline int FindNumberInList(int const WhichNumber, MArray1<A, int> const &ListOfItems, int const NumItems)
     232             :     {
     233             :         return FindNumberInList(WhichNumber, Array1D_int(ListOfItems), NumItems);
     234             :     }
     235             : 
     236             :     template <typename Container,
     237             :               class = typename std::enable_if<
     238             :                   !std::is_same<typename Container::value_type, std::string>::value>::type> // Container needs isize() and operator(i) and value_type
     239       34014 :     inline int FindNumberInList(int const WhichNumber, Container const &ListOfItems, int Container::value_type::*num_p)
     240             :     {
     241       34014 :         int FindNumberInList(0);
     242      235278 :         for (int Count = 1, NumItems = ListOfItems.isize(); Count <= NumItems; ++Count) {
     243      235278 :             if (WhichNumber == ListOfItems(Count).*num_p) {
     244       34014 :                 FindNumberInList = Count;
     245       34014 :                 break;
     246             :             }
     247             :         }
     248       34014 :         return FindNumberInList;
     249             :     }
     250             : 
     251             :     void DecodeMonDayHrMin(int Item,   // word containing encoded month, day, hour, minute
     252             :                            int &Month, // month in integer format (1-12)
     253             :                            int &Day,   // day in integer format (1-31)
     254             :                            int &Hour,  // hour in integer format (1-24)
     255             :                            int &Minute // minute in integer format (0:59)
     256             :     );
     257             : 
     258             :     // TODO: this probably shouldn't be here
     259             :     int DetermineMinuteForReporting(EnergyPlusData &state,
     260             :                                     OutputProcessor::TimeStepType t_timeStepType); // kind of reporting, Zone Timestep or System
     261             : 
     262             :     void EncodeMonDayHrMin(int &Item, // word containing encoded month, day, hour, minute
     263             :                            int Month, // month in integer format (1:12)
     264             :                            int Day,   // day in integer format (1:31)
     265             :                            int Hour,  // hour in integer format (1:24)
     266             :                            int Minute // minute in integer format (0:59)
     267             :     );
     268             : 
     269             :     int LogicalToInteger(bool Flag);
     270             : 
     271             :     Real64 GetCurrentHVACTime(EnergyPlusData &state);
     272             : 
     273             :     Real64 GetPreviousHVACTime(EnergyPlusData &state);
     274             : 
     275             :     std::string CreateHVACTimeIntervalString(EnergyPlusData &state);
     276             : 
     277             :     std::string CreateTimeString(Real64 Time); // Time in seconds
     278             : 
     279             :     std::string CreateTimeIntervalString(Real64 StartTime, // Start of current interval in seconds
     280             :                                          Real64 EndTime    // End of current interval in seconds
     281             :     );
     282             : 
     283             :     void ParseTime(Real64 Time,    // Time value in seconds
     284             :                    int &Hours,     // Number of hours
     285             :                    int &Minutes,   // Number of minutes < 60
     286             :                    Real64 &Seconds // Number of seconds < 60
     287             :     );
     288             : 
     289             :     void ScanForReports(EnergyPlusData &state,
     290             :                         std::string const &reportName,
     291             :                         bool &DoReport,
     292             :                         Optional_string_const ReportKey = _,
     293             :                         Optional_string Option1 = _,
     294             :                         Optional_string Option2 = _);
     295             : 
     296             :     inline void ReallocateRealArray(Array1D<Real64> &Array,
     297             :                                     int &ArrayMax,     // Current and resultant dimension for Array
     298             :                                     int const ArrayInc // increment for redimension
     299             :     )
     300             :     {
     301             :         Array.redimension(ArrayMax += ArrayInc, 0.0);
     302             :     }
     303             : 
     304             :     void CheckCreatedZoneItemName(EnergyPlusData &state,
     305             :                                   std::string_view calledFrom,              // routine called from
     306             :                                   std::string const &CurrentObject,         // object being parsed
     307             :                                   std::string const &ZoneName,              // Zone Name associated
     308             :                                   std::string::size_type MaxZoneNameLength, // maximum length of zonelist zone names
     309             :                                   std::string const &ItemName,              // Item name (People, Lights, etc object)
     310             :                                   Array1_string const &ItemNames,           // Item Names to check for duplication
     311             :                                   int NumItems,                             // Number of items in ItemNames array
     312             :                                   std::string &ResultName,                  // Resultant name
     313             :                                   bool &errFlag                             // Error flag set to true if error found here.
     314             :     );
     315             : 
     316             :     template <typename Container, class = typename std::enable_if<!std::is_same<typename Container::value_type, std::string>::value>::type>
     317          49 :     inline void CheckCreatedZoneItemName(EnergyPlusData &state,
     318             :                                          std::string_view const calledFrom,              // routine called from
     319             :                                          std::string const &CurrentObject,               // object being parsed
     320             :                                          std::string const &ZoneName,                    // Zone Name associated
     321             :                                          std::string::size_type const MaxZoneNameLength, // maximum length of zonelist zone names
     322             :                                          std::string const &ItemName,                    // Item name (People, Lights, etc object)
     323             :                                          Container const &Items,                         // Items to check for duplication Names
     324             :                                          int const NumItems,                             // Number of items in ItemNames array
     325             :                                          std::string &ResultName,                        // Resultant name
     326             :                                          bool &errFlag                                   // Error flag set to true if error found here.
     327             :     )
     328             :     {
     329          98 :         Array1D_string ItemNames(Items.size());
     330         339 :         for (std::size_t i = 0, e = Items.size(); i < e; ++i)
     331         290 :             ItemNames[i] = Items[i].Name;
     332          49 :         CheckCreatedZoneItemName(state, calledFrom, CurrentObject, ZoneName, MaxZoneNameLength, ItemName, ItemNames, NumItems, ResultName, errFlag);
     333          49 :     }
     334             : 
     335             :     std::vector<std::string> splitString(const std::string &string, char delimiter);
     336             : 
     337             :     bool isReportPeriodBeginning(EnergyPlusData &state, int periodIdx);
     338             : 
     339             :     void findReportPeriodIdx(EnergyPlusData &state,
     340             :                              const Array1D<WeatherManager::ReportPeriodData> &ReportPeriodInputData,
     341             :                              int nReportPeriods,
     342             :                              Array1D_bool &inReportPeriodFlags);
     343             : 
     344    19269012 :     inline Real64 epexp(const Real64 numerator, const Real64 denominator)
     345             :     {
     346    19269012 :         if (denominator == 0.0) {
     347        7281 :             return 0.0;
     348             :         } else {
     349    19261731 :             return std::exp(numerator / denominator);
     350             :         }
     351             :     }
     352             : 
     353             : } // namespace General
     354             : 
     355        1542 : struct GeneralData : BaseGlobalStruct
     356             : {
     357             :     bool GetReportInput = true;
     358             :     bool SurfVert = false;
     359             :     bool SurfDet = false;
     360             :     bool SurfDetWVert = false;
     361             :     bool DXFReport = false;
     362             :     bool DXFWFReport = false;
     363             :     bool VRMLReport = false;
     364             :     bool CostInfo = false;
     365             :     bool ViewFactorInfo = false;
     366             :     bool Constructions = false;
     367             :     bool Materials = false;
     368             :     bool LineRpt = false;
     369             :     bool VarDict = false;
     370             :     bool EMSoutput = false;
     371             :     Real64 XNext = 0.0; // used in root finder
     372             :     std::string DXFOption1;
     373             :     std::string DXFOption2;
     374             :     std::string DXFWFOption1;
     375             :     std::string DXFWFOption2;
     376             :     std::string VRMLOption1;
     377             :     std::string VRMLOption2;
     378             :     std::string ViewRptOption1;
     379             :     std::string LineRptOption1;
     380             :     std::string VarDictOption1;
     381             :     std::string VarDictOption2;
     382             : 
     383           0 :     void clear_state() override
     384             :     {
     385           0 :         this->GetReportInput = true;
     386           0 :         this->SurfVert = false;
     387           0 :         this->SurfDet = false;
     388           0 :         this->SurfDetWVert = false;
     389           0 :         this->DXFReport = false;
     390           0 :         this->DXFWFReport = false;
     391           0 :         this->VRMLReport = false;
     392           0 :         this->CostInfo = false;
     393           0 :         this->ViewFactorInfo = false;
     394           0 :         this->Constructions = false;
     395           0 :         this->Materials = false;
     396           0 :         this->LineRpt = false;
     397           0 :         this->VarDict = false;
     398           0 :         this->EMSoutput = false;
     399           0 :         this->XNext = 0.0;
     400           0 :         this->DXFOption1.clear();
     401           0 :         this->DXFOption2.clear();
     402           0 :         this->DXFWFOption1.clear();
     403           0 :         this->DXFWFOption2.clear();
     404           0 :         this->VRMLOption1.clear();
     405           0 :         this->VRMLOption2.clear();
     406           0 :         this->ViewRptOption1.clear();
     407           0 :         this->LineRptOption1.clear();
     408           0 :         this->VarDictOption1.clear();
     409           0 :         this->VarDictOption2.clear();
     410           0 :     }
     411             : };
     412             : 
     413             : } // namespace EnergyPlus
     414             : 
     415             : #endif

Generated by: LCOV version 1.13