LCOV - code coverage report
Current view: top level - EnergyPlus - General.hh (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 72.9 % 48 35
Test Date: 2025-06-02 07:23:51 Functions: 90.9 % 11 10

            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              : #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/EPVector.hh>
      61              : #include <EnergyPlus/EnergyPlus.hh>
      62              : 
      63              : namespace EnergyPlus {
      64              : 
      65              : // Forward declarations
      66              : struct EnergyPlusData;
      67              : 
      68              : namespace Weather {
      69              :     enum class DateType;
      70              :     struct ReportPeriodData;
      71              : } // namespace Weather
      72              : 
      73              : namespace General {
      74              : 
      75              :     // A second version that does not require a payload -- use lambdas
      76              :     void SolveRoot(const EnergyPlusData &state,
      77              :                    Real64 Eps,   // required absolute accuracy
      78              :                    int MaxIte,   // maximum number of allowed iterations
      79              :                    int &Flag,    // integer storing exit status
      80              :                    Real64 &XRes, // value of x that solves f(x,Par) = 0
      81              :                    const std::function<Real64(Real64)> &f,
      82              :                    Real64 X_0,  // 1st bound of interval that contains the solution
      83              :                    Real64 X_1); // 2nd bound of interval that contains the solution
      84              : 
      85              :     void MovingAvg(Array1D<Real64> &DataIn, int NumItemsInAvg);
      86              : 
      87              :     void ProcessDateString(EnergyPlusData &state,
      88              :                            std::string const &String,
      89              :                            int &PMonth,
      90              :                            int &PDay,
      91              :                            int &PWeekDay,
      92              :                            Weather::DateType &DateType, // DateType found (-1=invalid, 1=month/day, 2=nth day in month, 3=last day in month)
      93              :                            bool &ErrorsFound,
      94              :                            ObjexxFCL::Optional_int PYear = _);
      95              : 
      96              :     void DetermineDateTokens(EnergyPlusData &state,
      97              :                              std::string const &String,
      98              :                              int &NumTokens,              // Number of tokens found in string
      99              :                              int &TokenDay,               // Value of numeric field found
     100              :                              int &TokenMonth,             // Value of Month field found (1=Jan, 2=Feb, etc)
     101              :                              int &TokenWeekday,           // Value of Weekday field found (1=Sunday, 2=Monday, etc), 0 if none
     102              :                              Weather::DateType &DateType, // DateType found (-1=invalid, 1=month/day, 2=nth day in month, 3=last day in month)
     103              :                              bool &ErrorsFound,           // Set to true if cannot process this string as a date
     104              :                              ObjexxFCL::Optional_int TokenYear = _ // Value of Year if one appears to be present and this argument is present
     105              :     );
     106              : 
     107              :     void ValidateMonthDay(EnergyPlusData &state,
     108              :                           std::string const &String, // REAL(r64) string being processed
     109              :                           int Day,
     110              :                           int Month,
     111              :                           bool &ErrorsFound);
     112              : 
     113              :     int OrdinalDay(int Month,        // Month, 1..12
     114              :                    int Day,          // Day of Month, not validated by month
     115              :                    int LeapYearValue // 1 if leap year indicated, 0 if not
     116              :     );
     117              : 
     118              :     void InvOrdinalDay(int Number, int &PMonth, int &PDay, int LeapYr);
     119              : 
     120              :     bool BetweenDateHoursLeftInclusive(int TestDate, int TestHour, int StartDate, int StartHour, int EndDate, int EndHour);
     121              : 
     122              :     bool BetweenDates(int TestDate,  // Date to test
     123              :                       int StartDate, // Start date in sequence
     124              :                       int EndDate    // End date in sequence
     125              :     );
     126              : 
     127              :     std::string CreateSysTimeIntervalString(EnergyPlusData &state);
     128              : 
     129              :     int nthDayOfWeekOfMonth(const EnergyPlusData &state,
     130              :                             int dayOfWeek,  // day of week (Sunday=1, Monday=2, ...)
     131              :                             int nthTime,    // nth time the day of the week occurs (first monday, third tuesday, ..)
     132              :                             int monthNumber // January = 1
     133              :     );
     134              : 
     135              :     Real64 SafeDivide(Real64 a, Real64 b);
     136              : 
     137              :     void Iterate(Real64 &ResultX, // ResultX is the final Iteration result passed back to the calling routine
     138              :                  Real64 Tol,      // Tolerance for Convergence
     139              :                  Real64 X0,       // Current value of X
     140              :                  Real64 Y0,       // Current value of the function Y(X)
     141              :                  Real64 &X1,      // First Previous values of X
     142              :                  Real64 &Y1,      // First Previous values of Y(X1)
     143              :                  int Iter,        // Number of iterations
     144              :                  int &Cnvg        // Convergence flag  Cnvg = 0:  Not converged
     145              :     );
     146              : 
     147              :     int FindNumberInList(int WhichNumber, Array1A_int ListOfItems, int NumItems);
     148              : 
     149              :     template <typename A> inline int FindNumberInList(int const WhichNumber, MArray1<A, int> const &ListOfItems, int const NumItems)
     150              :     {
     151              :         return FindNumberInList(WhichNumber, Array1D_int(ListOfItems), NumItems);
     152              :     }
     153              : 
     154              :     template <typename Container,
     155              :               class = typename std::enable_if<
     156              :                   !std::is_same<typename Container::value_type, std::string>::value>::type> // Container needs isize() and operator(i) and value_type
     157        34550 :     inline int FindNumberInList(int const WhichNumber, Container const &ListOfItems, int Container::value_type::*num_p)
     158              :     {
     159        34550 :         int FindNumberInList(0);
     160       239441 :         for (int Count = 1, NumItems = ListOfItems.isize(); Count <= NumItems; ++Count) {
     161       239441 :             if (WhichNumber == ListOfItems(Count).*num_p) {
     162        34550 :                 FindNumberInList = Count;
     163        34550 :                 break;
     164              :             }
     165              :         }
     166        34550 :         return FindNumberInList;
     167              :     }
     168              : 
     169              :     void DecodeMonDayHrMin(int Item,   // word containing encoded month, day, hour, minute
     170              :                            int &Month, // month in integer format (1-12)
     171              :                            int &Day,   // day in integer format (1-31)
     172              :                            int &Hour,  // hour in integer format (1-24)
     173              :                            int &Minute // minute in integer format (0:59)
     174              :     );
     175              : 
     176              :     void EncodeMonDayHrMin(int &Item, // word containing encoded month, day, hour, minute
     177              :                            int Month, // month in integer format (1:12)
     178              :                            int Day,   // day in integer format (1:31)
     179              :                            int Hour,  // hour in integer format (1:24)
     180              :                            int Minute // minute in integer format (0:59)
     181              :     );
     182              : 
     183              :     std::string CreateTimeString(Real64 Time); // Time in seconds
     184              : 
     185              :     void ParseTime(Real64 Time,    // Time value in seconds
     186              :                    int &Hours,     // Number of hours
     187              :                    int &Minutes,   // Number of minutes < 60
     188              :                    Real64 &Seconds // Number of seconds < 60
     189              :     );
     190              : 
     191              :     void ScanForReports(EnergyPlusData &state,
     192              :                         std::string const &reportName,
     193              :                         bool &DoReport,
     194              :                         ObjexxFCL::Optional_string_const ReportKey = _,
     195              :                         ObjexxFCL::Optional_string Option1 = _,
     196              :                         ObjexxFCL::Optional_string Option2 = _);
     197              : 
     198              :     void CheckCreatedZoneItemName(EnergyPlusData &state,
     199              :                                   std::string_view calledFrom,              // routine called from
     200              :                                   std::string const &CurrentObject,         // object being parsed
     201              :                                   std::string const &ZoneName,              // Zone Name associated
     202              :                                   std::string::size_type MaxZoneNameLength, // maximum length of zonelist zone names
     203              :                                   std::string const &ItemName,              // Item name (People, Lights, etc object)
     204              :                                   Array1_string const &ItemNames,           // Item Names to check for duplication
     205              :                                   int NumItems,                             // Number of items in ItemNames array
     206              :                                   std::string &ResultName,                  // Resultant name
     207              :                                   bool &errFlag                             // Error flag set to true if error found here.
     208              :     );
     209              : 
     210              :     template <typename Container, class = typename std::enable_if<!std::is_same<typename Container::value_type, std::string>::value>::type>
     211           54 :     inline void CheckCreatedZoneItemName(EnergyPlusData &state,
     212              :                                          std::string_view const calledFrom,              // routine called from
     213              :                                          std::string const &CurrentObject,               // object being parsed
     214              :                                          std::string const &ZoneName,                    // Zone Name associated
     215              :                                          std::string::size_type const MaxZoneNameLength, // maximum length of zonelist zone names
     216              :                                          std::string const &ItemName,                    // Item name (People, Lights, etc object)
     217              :                                          Container const &Items,                         // Items to check for duplication Names
     218              :                                          int const NumItems,                             // Number of items in ItemNames array
     219              :                                          std::string &ResultName,                        // Resultant name
     220              :                                          bool &errFlag                                   // Error flag set to true if error found here.
     221              :     )
     222              :     {
     223           54 :         Array1D_string ItemNames(Items.size());
     224          749 :         for (std::size_t i = 0, e = Items.size(); i < e; ++i) {
     225          695 :             ItemNames[i] = Items[i].Name;
     226              :         }
     227           54 :         CheckCreatedZoneItemName(state, calledFrom, CurrentObject, ZoneName, MaxZoneNameLength, ItemName, ItemNames, NumItems, ResultName, errFlag);
     228           54 :     }
     229              : 
     230              :     bool isReportPeriodBeginning(EnergyPlusData &state, int periodIdx);
     231              : 
     232              :     void findReportPeriodIdx(EnergyPlusData &state,
     233              :                              const Array1D<Weather::ReportPeriodData> &ReportPeriodInputData,
     234              :                              int nReportPeriods,
     235              :                              Array1D_bool &inReportPeriodFlags);
     236              : 
     237              :     Real64 rotAzmDiffDeg(Real64 AzmA, Real64 AzmB);
     238              : 
     239     12938383 :     inline Real64 epexp(const Real64 numerator, const Real64 denominator)
     240              :     {
     241     12938383 :         if (denominator == 0.0) {
     242         6756 :             return 0.0;
     243              :         } else {
     244     12931627 :             return std::exp(numerator / denominator);
     245              :         }
     246              :     }
     247              : } // namespace General
     248              : 
     249     62991244 : constexpr Real64 Interp(Real64 const Lower, Real64 const Upper, Real64 const InterpFac)
     250              : {
     251     62991244 :     return Lower + InterpFac * (Upper - Lower);
     252              : }
     253              : 
     254              : struct InterpCoeffs
     255              : {
     256              :     Real64 x1;
     257              :     Real64 x2;
     258              : };
     259              : 
     260              : inline void GetInterpCoeffs(Real64 X, Real64 X1, Real64 X2, InterpCoeffs &c)
     261              : {
     262              :     c.x1 = (X - X1) / (X2 - X1);
     263              :     c.x2 = (X2 - X) / (X2 - X1);
     264              : }
     265              : 
     266              : inline Real64 Interp2(Real64 Fx1, Real64 Fx2, InterpCoeffs const &c)
     267              : {
     268              :     return c.x1 * Fx1 + c.x2 * Fx2;
     269              : }
     270              : 
     271              : // Disaggregated implementation of bilinear interpolation so that coefficients can be used with multiple variables
     272              : struct BilinearInterpCoeffs
     273              : {
     274              :     Real64 denom;
     275              :     Real64 x1y1;
     276              :     Real64 x1y2;
     277              :     Real64 x2y1;
     278              :     Real64 x2y2;
     279              : };
     280              : 
     281         4692 : inline void GetBilinearInterpCoeffs(
     282              :     Real64 const X, Real64 const Y, Real64 const X1, Real64 const X2, Real64 const Y1, Real64 const Y2, BilinearInterpCoeffs &coeffs)
     283              : {
     284         4692 :     if (X1 == X2 && Y1 == Y2) {
     285            0 :         coeffs.denom = coeffs.x1y1 = 1.0;
     286            0 :         coeffs.x1y2 = coeffs.x2y1 = coeffs.x2y2 = 0.0;
     287         4692 :     } else if (X1 == X2) {
     288            0 :         coeffs.denom = (Y2 - Y1);
     289            0 :         coeffs.x1y1 = (Y2 - Y);
     290            0 :         coeffs.x1y2 = (Y - Y1);
     291            0 :         coeffs.x2y1 = coeffs.x2y2 = 0.0;
     292         4692 :     } else if (Y1 == Y2) {
     293            0 :         coeffs.denom = (X2 - X1);
     294            0 :         coeffs.x1y1 = (X2 - X);
     295            0 :         coeffs.x2y1 = (X - X1);
     296            0 :         coeffs.x1y2 = coeffs.x2y2 = 0.0;
     297              :     } else {
     298         4692 :         coeffs.denom = (X2 - X1) * (Y2 - Y1);
     299         4692 :         coeffs.x1y1 = (X2 - X) * (Y2 - Y);
     300         4692 :         coeffs.x2y1 = (X - X1) * (Y2 - Y);
     301         4692 :         coeffs.x1y2 = (X2 - X) * (Y - Y1);
     302         4692 :         coeffs.x2y2 = (X - X1) * (Y - Y1);
     303              :     }
     304         4692 : }
     305              : 
     306        12812 : inline Real64 BilinearInterp(Real64 const Fx1y1, Real64 const Fx1y2, Real64 const Fx2y1, Real64 const Fx2y2, BilinearInterpCoeffs const &coeffs)
     307              : {
     308        12812 :     return (coeffs.x1y1 * Fx1y1 + coeffs.x2y1 * Fx2y1 + coeffs.x1y2 * Fx1y2 + coeffs.x2y2 * Fx2y2) / coeffs.denom;
     309              : }
     310              : 
     311              : struct GeneralData : BaseGlobalStruct
     312              : {
     313              :     bool GetReportInput = true;
     314              :     bool SurfVert = false;
     315              :     bool SurfDet = false;
     316              :     bool SurfDetWVert = false;
     317              :     bool DXFReport = false;
     318              :     bool DXFWFReport = false;
     319              :     bool VRMLReport = false;
     320              :     bool CostInfo = false;
     321              :     bool ViewFactorInfo = false;
     322              :     bool Constructions = false;
     323              :     bool Materials = false;
     324              :     bool LineRpt = false;
     325              :     bool VarDict = false;
     326              :     bool EMSoutput = false;
     327              :     Real64 XNext = 0.0; // used in root finder
     328              :     std::string DXFOption1;
     329              :     std::string DXFOption2;
     330              :     std::string DXFWFOption1;
     331              :     std::string DXFWFOption2;
     332              :     std::string VRMLOption1;
     333              :     std::string VRMLOption2;
     334              :     std::string ViewRptOption1;
     335              :     std::string LineRptOption1;
     336              :     std::string VarDictOption1;
     337              :     std::string VarDictOption2;
     338              : 
     339          801 :     void init_constant_state([[maybe_unused]] EnergyPlusData &state) override
     340              :     {
     341          801 :     }
     342              : 
     343          801 :     void init_state([[maybe_unused]] EnergyPlusData &state) override
     344              :     {
     345          801 :     }
     346              : 
     347            0 :     void clear_state() override
     348              :     {
     349            0 :         new (this) GeneralData();
     350            0 :     }
     351              : };
     352              : 
     353              : } // namespace EnergyPlus
     354              : 
     355              : #endif
        

Generated by: LCOV version 2.0-1