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

Generated by: LCOV version 1.13