LCOV - code coverage report
Current view: top level - EnergyPlus - ScheduleManager.hh (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 12 30 40.0 %
Date: 2024-08-24 18:31:18 Functions: 5 6 83.3 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2024, 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 ScheduleManager_hh_INCLUDED
      49             : #define ScheduleManager_hh_INCLUDED
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Array1D.hh>
      53             : #include <ObjexxFCL/Array1S.hh>
      54             : #include <ObjexxFCL/Array2A.hh>
      55             : #include <ObjexxFCL/Array2D.hh>
      56             : #include <ObjexxFCL/Array2S.hh>
      57             : #include <ObjexxFCL/Optional.hh>
      58             : 
      59             : // EnergyPlus Headers
      60             : #include <EnergyPlus/Data/BaseData.hh>
      61             : #include <EnergyPlus/DataGlobals.hh>
      62             : #include <EnergyPlus/EnergyPlus.hh>
      63             : 
      64             : namespace EnergyPlus {
      65             : 
      66             : // Forward declarations
      67             : struct EnergyPlusData;
      68             : 
      69             : namespace ScheduleManager {
      70             : 
      71             :     constexpr int ScheduleAlwaysOn = -1;
      72             :     constexpr int ScheduleAlwaysOff = 0;
      73             : 
      74             :     enum class DayType
      75             :     {
      76             :         Invalid = -1,
      77             :         Dummy = 0,
      78             :         Sunday = 1,
      79             :         Monday,
      80             :         Tuesday,
      81             :         Wednesday,
      82             :         Thursday,
      83             :         Friday,
      84             :         Saturday,
      85             :         Holiday,
      86             :         SummerDesignDay,
      87             :         WinterDesignDay,
      88             :         CustomDay1,
      89             :         CustomDay2,
      90             :         Num
      91             :     };
      92             : 
      93             :     int constexpr maxDayTypes = static_cast<int>(DayType::Num) - 1;
      94             :     extern const std::array<std::string_view, static_cast<int>(DayType::Num)> dayTypeNames;
      95             :     extern const std::array<std::string_view, static_cast<int>(DayType::Num)> dayTypeNamesUC;
      96             : 
      97             :     enum class DayTypeGroup
      98             :     {
      99             :         Invalid = -1,
     100             :         Weekday = 1,
     101             :         WeekEndHoliday,
     102             :         SummerDesignDay,
     103             :         WinterDesignDay,
     104             :         Num
     105             :     };
     106             : 
     107             :     enum class SchedType : int
     108             :     {
     109             :         Invalid = -1,
     110             :         ScheduleInput_year = 1,
     111             :         ScheduleInput_compact = 2,
     112             :         ScheduleInput_file = 3,
     113             :         ScheduleInput_constant = 4,
     114             :         ScheduleInput_external = 5,
     115             :         Num
     116             :     };
     117             : 
     118             :     enum class OutputReportLevel
     119             :     {
     120             :         Invalid = -1,
     121             :         Hourly,
     122             :         TimeStep,
     123             :         Num
     124             :     };
     125             : 
     126             :     enum class ScheduleInterpolation
     127             :     {
     128             :         Invalid = -1,
     129             :         No,      // no interpolation
     130             :         Average, // interpolation only to resolve time intervals not matching timestep lengths (this was previously interpolate:yes)
     131             :         Linear,  // linear interpolation from the previous time to the current time for the entire schedule
     132             :         Num
     133             :     };
     134             : 
     135             :     enum class Clusivity
     136             :     {
     137             :         Invalid = -1,
     138             :         Inclusive,
     139             :         Exclusive,
     140             :         Num
     141             :     };
     142             : 
     143             :     struct ScheduleTypeData
     144             :     {
     145             :         // Members
     146             :         std::string Name; // Schedule Type Name
     147             :         bool Limited;     // True if this Schedule Type has limits
     148             :         Real64 Minimum;   // Minimum for limited schedule
     149             :         Real64 Maximum;   // Maximum for limited schedule
     150             :         bool IsReal;      // True if this is a "real" schedule, false if integer
     151             :         int UnitType;     // reference ScheduleTypeLimit table
     152             : 
     153             :         // Default Constructor
     154         796 :         ScheduleTypeData() : Limited(false), Minimum(0.0), Maximum(0.0), IsReal(true), UnitType(0)
     155             :         {
     156         796 :         }
     157             :     };
     158             : 
     159             :     struct DayScheduleData
     160             :     {
     161             :         // Members
     162             :         std::string Name;                           // Day Schedule Name
     163             :         int ScheduleTypePtr;                        // Index of Schedule Type
     164             :         ScheduleInterpolation IntervalInterpolated; // Indicator for interval interpolation. If not "interpolated", False.  Else True
     165             :         bool Used;                                  // Indicator for this schedule being "used".
     166             :         Array2D<Real64> TSValue;                    // Value array by simulation timestep
     167             :         Real64 TSValMax;                            // maximum of all TSValue's
     168             :         Real64 TSValMin;                            // minimum of all TSValue's
     169             : 
     170             :         // Default Constructor
     171         796 :         DayScheduleData() : ScheduleTypePtr(0), IntervalInterpolated(ScheduleInterpolation::No), Used(false), TSValMax(0.0), TSValMin(0.0)
     172             :         {
     173         796 :         }
     174             :     };
     175             : 
     176             :     struct WeekScheduleData
     177             :     {
     178             :         // Members
     179             :         std::string Name;               // Week Schedule Name
     180             :         bool Used;                      // Indicator for this schedule being "used".
     181             :         Array1D_int DaySchedulePointer; // Index of Day Schedule
     182             : 
     183             :         // Default Constructor
     184         796 :         WeekScheduleData() : Used(false), DaySchedulePointer(maxDayTypes, 0)
     185             :         {
     186         796 :         }
     187             :     };
     188             : 
     189             :     struct ScheduleData
     190             :     {
     191             :         // Members
     192             :         std::string Name;                       // Schedule Name
     193             :         int ScheduleTypePtr;                    // Index of Schedule Type
     194             :         Array1D_int WeekSchedulePointer;        // one created for each day of possible simulation
     195             :         SchedType SchType = SchedType::Invalid; // what kind of object has been input.
     196             :         bool Used;                              // Indicator for this schedule being "used".
     197             :         bool MaxMinSet;                         // Max/min values have been stored for this schedule
     198             :         Real64 MaxValue;                        // Maximum value for this schedule
     199             :         Real64 MinValue;                        // Minimum value for this schedule
     200             :         std::array<bool, static_cast<int>(DayType::Num)> MaxMinByDayTypeSet{
     201             :             false}; // minimum and maximum values by daytype have been stored for this schedule
     202             :         std::array<Real64, static_cast<int>(DayType::Num)> MinByDayType{0.0}; // minimum values by daytype for this schedule
     203             :         std::array<Real64, static_cast<int>(DayType::Num)> MaxByDayType{0.0}; // maximum values by daytype for this schedule
     204             :         Real64 CurrentValue;                                                  // For Reporting
     205             :         bool EMSActuatedOn;                                                   // indicates if EMS computed
     206             :         Real64 EMSValue;                                                      // EMS value
     207             :         bool UseDaylightSaving; // Toggles between daylight saving option to be inclused as "No" or "Yes" (default)
     208             : 
     209             :         // Default Constructor
     210         796 :         ScheduleData()
     211         796 :             : ScheduleTypePtr(0), WeekSchedulePointer(366, 0), Used(false), MaxMinSet(false), MaxValue(0.0), MinValue(0.0), CurrentValue(0.0),
     212         796 :               EMSActuatedOn(false), EMSValue(0.0), UseDaylightSaving(true)
     213             :         {
     214         796 :         }
     215             :     };
     216             : 
     217             :     // Functions
     218             : 
     219             :     void ProcessScheduleInput(EnergyPlusData &state);
     220             : 
     221             :     void ReportScheduleDetails(EnergyPlusData &state, OutputReportLevel const LevelOfDetail);
     222             : 
     223             :     // Returns the CurrentScheduleValue
     224             :     Real64 GetCurrentScheduleValue(EnergyPlusData &state, int const ScheduleIndex);
     225             : 
     226             :     // Updates each schedule value to the current timestep
     227             :     // Uses EMS value if actuated, otherwise calls LookUpScheduleValue with ThisHour=DataGlobals::HourOfDay, ThisTimeStep=DataGlobals::TimeStep
     228             :     void UpdateScheduleValues(EnergyPlusData &state);
     229             : 
     230             :     // Looks up a given Schedule value for an hour & timestep, minding whether DST is enabled or not
     231             :     Real64 LookUpScheduleValue(EnergyPlusData &state,
     232             :                                int const ScheduleIndex,
     233             :                                int const ThisHour,
     234             :                                int const ThisTimeStep = -1 // Negative => unspecified, will use NumOfTimeStepInHour
     235             :     );
     236             : 
     237             :     int GetScheduleIndex(EnergyPlusData &state, std::string const &ScheduleName);
     238             : 
     239             :     std::string GetScheduleType(EnergyPlusData &state, int const ScheduleIndex);
     240             : 
     241             :     int GetDayScheduleIndex(EnergyPlusData &state, std::string &ScheduleName);
     242             : 
     243             :     void GetScheduleValuesForDay(EnergyPlusData &state,
     244             :                                  int const ScheduleIndex,
     245             :                                  Array2S<Real64> DayValues,
     246             :                                  ObjexxFCL::Optional_int_const JDay = _,
     247             :                                  ObjexxFCL::Optional_int_const CurDayofWeek = _);
     248             : 
     249             :     void GetSingleDayScheduleValues(EnergyPlusData &state,
     250             :                                     int const DayScheduleIndex, // Index of the DaySchedule for values
     251             :                                     Array2S<Real64> DayValues   // Returned set of values
     252             :     );
     253             : 
     254             :     void ExternalInterfaceSetSchedule(EnergyPlusData &state,
     255             :                                       int &ScheduleIndex,
     256             :                                       Real64 &Value // The new value for the schedule
     257             :     );
     258             : 
     259             :     void ProcessIntervalFields(EnergyPlusData &state,
     260             :                                Array1S_string const Untils,
     261             :                                Array1S<Real64> const Numbers,
     262             :                                int const NumUntils,
     263             :                                int const NumNumbers,
     264             :                                Array2A<Real64> MinuteValue,
     265             :                                Array2A_bool SetMinuteValue,
     266             :                                bool &ErrorsFound,
     267             :                                std::string const &DayScheduleName,     // Name (used for errors)
     268             :                                std::string const &ErrContext,          // Context (used for errors)
     269             :                                ScheduleInterpolation interpolationKind // enumeration on how to interpolate values in schedule
     270             :     );
     271             : 
     272             :     void DecodeHHMMField(EnergyPlusData &state,
     273             :                          std::string const &FieldValue,          // Input field value
     274             :                          int &RetHH,                             // Returned "hour"
     275             :                          int &RetMM,                             // Returned "minute"
     276             :                          bool &ErrorsFound,                      // True if errors found in this field
     277             :                          std::string const &DayScheduleName,     // originating day schedule name
     278             :                          std::string const &FullFieldValue,      // Full Input field value
     279             :                          ScheduleInterpolation interpolationKind // enumeration on how to interpolate values in schedule
     280             :     );
     281             : 
     282             :     bool isMinuteMultipleOfTimestep(int minute, int numMinutesPerTimestep);
     283             : 
     284             :     void ProcessForDayTypes(EnergyPlusData &state,
     285             :                             std::string const &ForDayField, // Field containing the "FOR:..."
     286             :                             Array1D_bool &TheseDays,        // Array to contain returned "true" days
     287             :                             Array1D_bool &AlReady,          // Array of days already done
     288             :                             bool &ErrorsFound               // Will be true if error found.
     289             :     );
     290             : 
     291             :     bool CheckScheduleValueMinMax(EnergyPlusData &state,
     292             :                                   int const ScheduleIndex, // Which Schedule being tested
     293             :                                   bool includeOrEquals,    // Minimum indicator ('>', '>=')
     294             :                                   Real64 const Minimum     // Minimum desired value
     295             :     );
     296             : 
     297             :     bool CheckScheduleValueMinMax(EnergyPlusData &state,
     298             :                                   int const ScheduleIndex,    // Which Schedule being tested
     299             :                                   std::string_view MinString, // Minimum indicator ('>', '>=')
     300             :                                   Real64 const Minimum,       // Minimum desired value
     301             :                                   std::string_view MaxString, // Maximum indicator ('<', ',=')
     302             :                                   Real64 const Maximum        // Maximum desired value
     303             :     );
     304             : 
     305             :     bool CheckScheduleValueMinMax(EnergyPlusData &state,
     306             :                                   int const ScheduleIndex, // Which Schedule being tested
     307             :                                   Clusivity clusiveMin,    // true ? '>' : '>='
     308             :                                   Real64 const Minimum,    // Minimum desired value
     309             :                                   Clusivity clusiveMax,    // true ? '<' : '<='
     310             :                                   Real64 const Maximum     // Maximum desired value
     311             :     );
     312             : 
     313             :     bool CheckScheduleValueMinMax(EnergyPlusData &state,
     314             :                                   int const ScheduleIndex,      // Which Schedule being tested
     315             :                                   std::string const &MinString, // Minimum indicator ('>', '>=')
     316             :                                   Real32 const Minimum          // Minimum desired value
     317             :     );
     318             : 
     319             :     bool CheckScheduleValueMinMax(EnergyPlusData &state,
     320             :                                   int const ScheduleIndex,      // Which Schedule being tested
     321             :                                   std::string const &MinString, // Minimum indicator ('>', '>=')
     322             :                                   Real32 const Minimum,         // Minimum desired value
     323             :                                   std::string const &MaxString, // Maximum indicator ('<', ',=')
     324             :                                   Real32 const Maximum          // Maximum desired value
     325             :     );
     326             : 
     327             :     bool CheckScheduleValue(EnergyPlusData &state,
     328             :                             int const ScheduleIndex, // Which Schedule being tested
     329             :                             Real64 const Value       // Actual desired value
     330             :     );
     331             : 
     332             :     bool CheckScheduleValue(EnergyPlusData &state,
     333             :                             int const ScheduleIndex, // Which Schedule being tested
     334             :                             int const Value          // Actual desired value
     335             :     );
     336             : 
     337             :     bool CheckDayScheduleValueMinMax(EnergyPlusData &state,
     338             :                                      int const ScheduleIndex, // Which Day Schedule being tested
     339             :                                      Real64 const Minimum,    // Minimum desired value
     340             :                                      bool const exclusiveMin, // Minimum indicator ('>', '>=')
     341             :                                      Real64 const Maximum,    // Maximum desired value
     342             :                                      bool const exclusiveMax  // Maximum indicator ('<', ',=')
     343             :     );
     344             : 
     345             :     bool CheckDayScheduleValueMinMax(EnergyPlusData &state,
     346             :                                      int const ScheduleIndex, // Which Day Schedule being tested
     347             :                                      Real64 const Minimum,    // Minimum desired value
     348             :                                      bool const exclusiveMin  // Minimum indicator ('>', '>=')
     349             :     );
     350             : 
     351             :     bool HasFractionalScheduleValue(EnergyPlusData &state, int const ScheduleIndex); // Which Schedule being tested
     352             : 
     353             :     Real64 GetScheduleMinValue(EnergyPlusData &state, int const ScheduleIndex); // Which Schedule being tested
     354             : 
     355             :     Real64 GetScheduleMaxValue(EnergyPlusData &state, int const ScheduleIndex); // Which Schedule being tested
     356             : 
     357             :     std::pair<Real64, Real64> getScheduleMinMaxByDayType(EnergyPlusData &state, int const ScheduleIndex, DayTypeGroup const days);
     358             : 
     359             :     std::string GetScheduleName(EnergyPlusData &state, int const ScheduleIndex);
     360             : 
     361             :     void ReportScheduleValues(EnergyPlusData &state);
     362             : 
     363             :     void ReportOrphanSchedules(EnergyPlusData &state);
     364             : 
     365             :     Real64 ScheduleAnnualFullLoadHours(EnergyPlusData &state,
     366             :                                        int const ScheduleIndex,  // Which Schedule being tested
     367             :                                        int const StartDayOfWeek, // Day of week for start of year
     368             :                                        bool const isItLeapYear   // true if it is a leap year containing February 29
     369             :     );
     370             : 
     371             :     Real64 ScheduleAverageHoursPerWeek(EnergyPlusData &state,
     372             :                                        int const ScheduleIndex,  // Which Schedule being tested
     373             :                                        int const StartDayOfWeek, // Day of week for start of year
     374             :                                        bool const isItLeapYear   // true if it is a leap year containing February 29
     375             :     );
     376             : 
     377             :     Real64 ScheduleHoursGT1perc(EnergyPlusData &state,
     378             :                                 int const ScheduleIndex,  // Which Schedule being tested
     379             :                                 int const StartDayOfWeek, // Day of week for start of year
     380             :                                 bool const isItLeapYear   // true if it is a leap year containing February 29
     381             :     );
     382             : 
     383             :     int GetNumberOfSchedules(EnergyPlusData &state);
     384             : 
     385             : } // namespace ScheduleManager
     386             : 
     387             : struct ScheduleManagerData : BaseGlobalStruct
     388             : {
     389             :     bool CheckScheduleValueMinMaxRunOnceOnly = true;
     390             :     bool DoScheduleReportingSetup = true;
     391             :     std::unordered_map<std::string, std::string> UniqueDayScheduleNames;
     392             :     std::unordered_map<std::string, std::string> UniqueWeekScheduleNames;
     393             :     std::unordered_map<std::string, std::string> UniqueScheduleNames;
     394             :     std::map<fs::path, nlohmann::json> UniqueProcessedExternalFiles;
     395             : 
     396             :     // Integer Variables for the Module
     397             :     int NumScheduleTypes = 0;
     398             :     int NumDaySchedules = 0;
     399             :     int NumWeekSchedules = 0;
     400             :     int NumSchedules = 0;
     401             : 
     402             :     // Logical Variables for Module
     403             :     bool ScheduleInputProcessed = false;       // This is false until the Schedule Input has been processed.
     404             :     bool ScheduleFileShadingProcessed = false; // This is false unless there is a Schedule:File:Shading object.
     405             : 
     406             :     // Object Data
     407             :     Array1D<ScheduleManager::ScheduleTypeData> ScheduleType; // Allowed Schedule Types
     408             :     Array1D<ScheduleManager::DayScheduleData> DaySchedule;   // Day Schedule Storage
     409             :     Array1D<ScheduleManager::WeekScheduleData> WeekSchedule; // Week Schedule Storage
     410             :     Array1D<ScheduleManager::ScheduleData> Schedule;         // Schedule Storage
     411             : 
     412         796 :     void init_state([[maybe_unused]] EnergyPlusData &state) override
     413             :     {
     414         796 :     }
     415             : 
     416           0 :     void clear_state() override
     417             :     {
     418           0 :         CheckScheduleValueMinMaxRunOnceOnly = true;
     419           0 :         UniqueDayScheduleNames.clear();
     420           0 :         UniqueWeekScheduleNames.clear();
     421           0 :         UniqueScheduleNames.clear();
     422           0 :         UniqueProcessedExternalFiles.clear();
     423           0 :         DoScheduleReportingSetup = true;
     424             : 
     425           0 :         NumScheduleTypes = 0;
     426           0 :         NumDaySchedules = 0;
     427           0 :         NumWeekSchedules = 0;
     428           0 :         NumSchedules = 0;
     429             : 
     430           0 :         ScheduleInputProcessed = false;
     431           0 :         ScheduleFileShadingProcessed = false;
     432             : 
     433           0 :         ScheduleType.clear(); // Allowed Schedule Types
     434           0 :         DaySchedule.clear();  // Day Schedule Storage
     435           0 :         WeekSchedule.clear(); // Week Schedule Storage
     436           0 :         Schedule.clear();     // Schedule Storage
     437           0 :     }
     438             : };
     439             : 
     440             : } // namespace EnergyPlus
     441             : 
     442             : #endif

Generated by: LCOV version 1.14