LCOV - code coverage report
Current view: top level - EnergyPlus - RuntimeLanguageProcessor.hh (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 7 47 14.9 %
Date: 2023-01-17 19:17:23 Functions: 10 13 76.9 %

          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 RuntimeLanguageProcessor_hh_INCLUDED
      49             : #define RuntimeLanguageProcessor_hh_INCLUDED
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Array1D.hh>
      53             : #include <ObjexxFCL/Optional.hh>
      54             : 
      55             : // EnergyPlus Headers
      56             : #include <EnergyPlus/Data/BaseData.hh>
      57             : #include <EnergyPlus/DataGlobals.hh>
      58             : #include <EnergyPlus/DataRuntimeLanguage.hh>
      59             : #include <EnergyPlus/EnergyPlus.hh>
      60             : 
      61             : namespace EnergyPlus {
      62             : 
      63             : // Forward declarations
      64             : struct EnergyPlusData;
      65             : 
      66             : namespace RuntimeLanguageProcessor {
      67             : 
      68             :     // Using/Aliasing
      69             :     using DataRuntimeLanguage::ErlFunc;
      70             :     using DataRuntimeLanguage::ErlValueType;
      71             : 
      72             :     int constexpr MaxErrors(20);
      73             : 
      74             :     enum class Token
      75             :     {
      76             :         Invalid = -1,
      77             :         Number = 1,            // matches the ValueNumber
      78             :         Variable = 4,          // matches the ValueVariable
      79             :         Expression = 5,        // matches the ValueExpression
      80             :         Operator = 7,          // includes basic operators and built-in functions.
      81             :         Parenthesis = 9,       // parenthesis token
      82             :         ParenthesisLeft = 10,  // indicates left side parenthesis found in parsing
      83             :         ParenthesisRight = 11, // indicates right side parenthesis found in parsing
      84             :         Num
      85             :     };
      86             : 
      87      235412 :     struct TokenType
      88             :     {
      89             :         // Members
      90             :         // structure for token information for parsing Erl code
      91             :         Token Type;         // token type, eg. TokenNumber
      92             :         Real64 Number;      // May want to store all literals as a variable?
      93             :         std::string String; // Serves double duty, also saves string version of token for easy debugging
      94             :         ErlFunc Operator;   // indentifies operator or function 1..64
      95             :         int Variable;       // points to a variable in ErlVariable structure
      96             :         Token Parenthesis;  // identifes if token is left or right parenthesis
      97             :         int Expression;     // points to an expression in ErlExpression structure
      98             :         std::string Error;  // holds token processing error message content
      99             : 
     100             :         // Default Constructor
     101       34996 :         TokenType() : Type(Token::Invalid), Number(0.0), Operator(ErlFunc::Invalid), Variable(0), Parenthesis(Token::Invalid), Expression(0)
     102             :         {
     103       34996 :         }
     104             :     };
     105             : 
     106         731 :     struct RuntimeReportVarType
     107             :     {
     108             :         // Members
     109             :         std::string Name; // name of custom Erl report variable
     110             :         int VariableNum;  // pointer to Erl variable associated with custom report variable
     111             :         Real64 Value;     // Value registered with output processor for report variable
     112             : 
     113             :         // Default Constructor
     114          37 :         RuntimeReportVarType() : VariableNum(0), Value(0.0)
     115             :         {
     116          37 :         }
     117             :     };
     118             : 
     119             :     void InitializeRuntimeLanguage(EnergyPlusData &state);
     120             : 
     121             :     void BeginEnvrnInitializeRuntimeLanguage(EnergyPlusData &state);
     122             : 
     123             :     void ParseStack(EnergyPlusData &state, int StackNum);
     124             : 
     125             :     int AddInstruction(EnergyPlusData &state,
     126             :                        int StackNum,
     127             :                        int LineNum,
     128             :                        DataRuntimeLanguage::ErlKeywordParam Keyword,
     129             :                        Optional_int_const Argument1 = _, // Erl variable index
     130             :                        Optional_int_const Argument2 = _);
     131             : 
     132             :     void AddError(EnergyPlusData &state,
     133             :                   int StackNum,            // index pointer to location in ErlStack structure
     134             :                   int LineNum,             // Erl program line number
     135             :                   std::string const &Error // error message to be added to ErlStack
     136             :     );
     137             : 
     138             :     ErlValueType EvaluateStack(EnergyPlusData &state, int StackNum);
     139             : 
     140             :     void WriteTrace(EnergyPlusData &state, int StackNum, int InstructionNum, ErlValueType const &ReturnValue, bool seriousErrorFound);
     141             : 
     142             :     void ParseExpression(EnergyPlusData &state,
     143             :                          std::string const &InString, // String of expression text written in the Runtime Language
     144             :                          int StackNum,                // Parent StackNum??
     145             :                          int &ExpressionNum,          // index of expression in structure
     146             :                          std::string const &Line      // Actual line from string
     147             :     );
     148             : 
     149             :     int ProcessTokens(EnergyPlusData &state, const Array1D<TokenType> &TokenIN, int NumTokensIN, int StackNum, std::string const &ParsingString);
     150             : 
     151             :     int NewExpression(EnergyPlusData &state);
     152             : 
     153             :     ErlValueType EvaluateExpression(EnergyPlusData &state, int ExpressionNum, bool &seriousErrorFound);
     154             : 
     155             :     void TodayTomorrowWeather(EnergyPlusData &state,
     156             :                               ErlFunc FunctionCode,
     157             :                               Real64 Operand1,
     158             :                               Real64 Operand2,
     159             :                               Array2D<Real64> &TodayTomorrowWeatherSource,
     160             :                               ErlValueType &ReturnVal);
     161             : 
     162             :     void TodayTomorrowWeather(EnergyPlusData &state,
     163             :                               ErlFunc FunctionCode,
     164             :                               Real64 Operand1,
     165             :                               Real64 Operand2,
     166             :                               Array2D_bool &TodayTomorrowWeatherSource,
     167             :                               ErlValueType &ReturnVal);
     168             : 
     169             :     int TodayTomorrowWeather(EnergyPlusData &state, int hour, int timestep, Array2D<Real64> &TodayTomorrowWeatherSource, Real64 &value);
     170             : 
     171             :     int TodayTomorrowWeather(EnergyPlusData &state, int hour, int timestep, Array2D<bool> &TodayTomorrowWeatherSource, int &value);
     172             : 
     173             :     void GetRuntimeLanguageUserInput(EnergyPlusData &state);
     174             : 
     175             :     void ReportRuntimeLanguage(EnergyPlusData &state);
     176             : 
     177             :     ErlValueType SetErlValueNumber(Real64 Number, Optional<ErlValueType const> OrigValue = _);
     178             : 
     179             :     ErlValueType StringValue(std::string const &String);
     180             : 
     181             :     std::string ValueToString(ErlValueType const &Value);
     182             : 
     183             :     int FindEMSVariable(EnergyPlusData &state,
     184             :                         std::string const &VariableName, // variable name in Erl
     185             :                         int StackNum);
     186             : 
     187             :     int NewEMSVariable(EnergyPlusData &state, std::string const &VariableName, int StackNum, Optional<ErlValueType const> Value = _);
     188             : 
     189             :     void SetupPossibleOperators(EnergyPlusData &state);
     190             : 
     191             :     void ExternalInterfaceSetErlVariable(EnergyPlusData &state,
     192             :                                          int varNum,  // The variable index to be written during run time
     193             :                                          Real64 value // The real time value of the vairable to be set
     194             :     );
     195             : 
     196             :     void ExternalInterfaceInitializeErlVariable(EnergyPlusData &state,
     197             :                                                 int varNum,                       // The variable index to be written during run time
     198             :                                                 ErlValueType const &initialValue, // The initial value
     199             :                                                 bool setToNull                    // Flag, if true, value will be initialized to Null
     200             :     );
     201             : 
     202             :     bool isExternalInterfaceErlVariable(EnergyPlusData &state, int varNum); // The variable index to be written during run time
     203             : 
     204             : } // namespace RuntimeLanguageProcessor
     205             : 
     206        1542 : struct RuntimeLanguageProcessorData : BaseGlobalStruct
     207             : {
     208             :     bool AlreadyDidOnce = false;
     209             :     bool GetInput = true;
     210             :     bool InitializeOnce = true;
     211             :     bool MyEnvrnFlag = true;
     212             :     int NullVariableNum = 0;
     213             :     int FalseVariableNum = 0;
     214             :     int TrueVariableNum = 0;
     215             :     int OffVariableNum = 0;
     216             :     int OnVariableNum = 0;
     217             :     int PiVariableNum = 0;
     218             :     Array1D_int CurveIndexVariableNums;
     219             :     Array1D_int ConstructionIndexVariableNums;
     220             :     int YearVariableNum = 0;
     221             :     int MonthVariableNum = 0;
     222             :     int DayOfMonthVariableNum = 0;
     223             :     int DayOfWeekVariableNum = 0;
     224             :     int DayOfYearVariableNum = 0;
     225             :     int HourVariableNum = 0;
     226             :     int TimeStepsPerHourVariableNum = 0;
     227             :     int TimeStepNumVariableNum = 0;
     228             :     int MinuteVariableNum = 0;
     229             :     int HolidayVariableNum = 0;
     230             :     int DSTVariableNum = 0;
     231             :     int CurrentTimeVariableNum = 0;
     232             :     int SunIsUpVariableNum = 0;
     233             :     int IsRainingVariableNum = 0;
     234             :     int SystemTimeStepVariableNum = 0;
     235             :     int ZoneTimeStepVariableNum = 0;
     236             :     int CurrentEnvironmentPeriodNum = 0;
     237             :     int ActualDateAndTimeNum = 0;
     238             :     int ActualTimeNum = 0;
     239             :     int WarmUpFlagNum = 0;
     240             :     Array1D<RuntimeLanguageProcessor::RuntimeReportVarType> RuntimeReportVar;
     241             :     std::unordered_map<std::string, std::string> ErlStackUniqueNames;
     242             :     std::unordered_map<std::string, std::string> RuntimeReportVarUniqueNames;
     243             :     bool WriteTraceMyOneTimeFlag = false;
     244             :     Array1D<RuntimeLanguageProcessor::TokenType> Token;
     245             :     Array1D<RuntimeLanguageProcessor::TokenType> PEToken;
     246             : 
     247           0 :     void clear_state() override
     248             :     {
     249           0 :         this->AlreadyDidOnce = false;
     250           0 :         this->GetInput = true;
     251           0 :         this->InitializeOnce = true;
     252           0 :         this->MyEnvrnFlag = true;
     253           0 :         this->NullVariableNum = 0;
     254           0 :         this->FalseVariableNum = 0;
     255           0 :         this->TrueVariableNum = 0;
     256           0 :         this->OffVariableNum = 0;
     257           0 :         this->OnVariableNum = 0;
     258           0 :         this->PiVariableNum = 0;
     259           0 :         this->CurveIndexVariableNums.clear();
     260           0 :         this->ConstructionIndexVariableNums.clear();
     261           0 :         this->YearVariableNum = 0;
     262           0 :         this->MonthVariableNum = 0;
     263           0 :         this->DayOfMonthVariableNum = 0;
     264           0 :         this->DayOfWeekVariableNum = 0;
     265           0 :         this->DayOfYearVariableNum = 0;
     266           0 :         this->HourVariableNum = 0;
     267           0 :         this->TimeStepsPerHourVariableNum = 0;
     268           0 :         this->TimeStepNumVariableNum = 0;
     269           0 :         this->MinuteVariableNum = 0;
     270           0 :         this->HolidayVariableNum = 0;
     271           0 :         this->DSTVariableNum = 0;
     272           0 :         this->CurrentTimeVariableNum = 0;
     273           0 :         this->SunIsUpVariableNum = 0;
     274           0 :         this->IsRainingVariableNum = 0;
     275           0 :         this->SystemTimeStepVariableNum = 0;
     276           0 :         this->ZoneTimeStepVariableNum = 0;
     277           0 :         this->CurrentEnvironmentPeriodNum = 0;
     278           0 :         this->ActualDateAndTimeNum = 0;
     279           0 :         this->ActualTimeNum = 0;
     280           0 :         this->WarmUpFlagNum = 0;
     281           0 :         this->RuntimeReportVar.clear();
     282           0 :         this->ErlStackUniqueNames.clear();
     283           0 :         this->RuntimeReportVarUniqueNames.clear();
     284           0 :         this->WriteTraceMyOneTimeFlag = false;
     285           0 :         this->PEToken.clear();
     286           0 :         this->Token.clear();
     287           0 :     }
     288             : };
     289             : 
     290             : } // namespace EnergyPlus
     291             : 
     292             : #endif

Generated by: LCOV version 1.13