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 DataRuntimeLanguage_hh_INCLUDED
49 : #define DataRuntimeLanguage_hh_INCLUDED
50 :
51 : // C++ Headers
52 : #include <functional>
53 : #include <unordered_set>
54 : #include <utility>
55 :
56 : // ObjexxFCL Headers
57 : #include <ObjexxFCL/Array1D.hh>
58 : #include <ObjexxFCL/Array2D.hh>
59 :
60 : // EnergyPlus Headers
61 : #include <EnergyPlus/Data/BaseData.hh>
62 : #include <EnergyPlus/DataGlobals.hh>
63 : #include <EnergyPlus/EMSManager.hh>
64 : #include <EnergyPlus/EnergyPlus.hh>
65 :
66 : namespace EnergyPlus {
67 :
68 : // Data only module for EMS runtime language
69 :
70 : namespace DataRuntimeLanguage {
71 :
72 : // Data module should be available to other modules and routines.
73 : // Thus, all variables in this module must be PUBLIC.
74 :
75 : enum class ErlKeywordParam // keyword parameters for types of Erl statements
76 : {
77 : Invalid = -1,
78 : None, // statement type not set
79 : Return, // Return statement, as in leave program
80 : Goto, // Goto statement, used in parsing to manage IF-ElseIf-Else-EndIf and nesting
81 : Set, // Set statement, as in assign RHS to LHS
82 : Run, // Run statement, used to call a subroutine from a main program
83 : If, // If statement, begins an IF-ElseIf-Else-EndIf logic block
84 : ElseIf, // ElseIf statement, begins an ElseIf block
85 : Else, // Else statement, begins an Else block
86 : EndIf, // EndIf statement, terminates an IF-ElseIf-Else-EndIf logic block
87 : While, // While statement, begins a While block
88 : EndWhile, // EndWhile statement, terminates a While block
89 : Num
90 : };
91 :
92 : enum class Value
93 : {
94 : Invalid = -1,
95 : Null, // Erl entity type, "Null" value
96 : Number, // Erl entity type, hard numeric value
97 : String, // Erl entity type, character data
98 : Array, // Erl entity type, not used yet, for future array type
99 : Variable, // Erl entity type, Erl variable
100 : Expression, // Erl entity type, Erl expression
101 : Trend, // Erl entity type, Erl trend variable
102 : Error, // Erl entity type, processing of an expression failed, returned error
103 : Num
104 : };
105 :
106 : enum class PtrDataType
107 : {
108 : Invalid = -1,
109 : Real, // data type for overloaded pointer management, double real
110 : Integer, // data type for overloaded pointer management, integer
111 : Logical, // data type for overloaded pointer management, logical
112 : Num
113 : };
114 :
115 : // Parameters for identifying operator types in Erl
116 : // The number of these parameters indicates the order of precedence
117 : enum class ErlFunc
118 : {
119 : Invalid = -1,
120 : Null,
121 : Literal, // Just stores a literal value
122 : Negative, // - (unary) No LHS?
123 : Divide, // /
124 : Multiply, // *
125 : Subtract, // - (binary)
126 : Add, // + (binary)
127 : Equal, // ==
128 : NotEqual, // <>
129 : LessOrEqual, // <=
130 : GreaterOrEqual, // >=
131 : LessThan, // <
132 : GreaterThan, // >
133 : RaiseToPower, // ^
134 : LogicalAND, // &&
135 : LogicalOR, // ||
136 : // note there is an important check "> 15" to distinguish operators from functions
137 : // so be careful if renumber these parameters. Binary operator additions should get inserted here rather than appended
138 :
139 : // parameters for built-in Erl functions, these are processed like operators and numbering
140 : // must be sequential with the operators.
141 : // math functions
142 : Round, // accessor for Fortran's DNINT()
143 : Mod, // accessor for Fortran's MOD()
144 : Sin, // accessor for Fortran's SIN()
145 : Cos, // accessor for Fortran's COS()
146 : ArcSin, // accessor for Fortran's ASIN()
147 : ArcCos, // accessor for Fortran's ACOS()
148 : DegToRad, // Multiplies degrees by DegToRad
149 : RadToDeg, // Divides radians by DegToRad
150 : Exp, // accessor for Fortran's EXP()
151 : Ln, // accessor for Fortran's LOG()
152 : Max, // accessor for Fortran's MAX()
153 : Min, // accessor for Fortran's MIN()
154 : ABS, // accessor for Fortran's ABS()
155 : RandU, // accessor for Fortran's Random_Number() intrinsic, uniform distribution
156 : RandG, // accessor for Gaussian/normal distribution random number
157 : RandSeed, // accessor for Fortran's Random_Seed() intrinsic
158 :
159 : // begin psychrometric routines
160 : RhoAirFnPbTdbW, // accessor for E+ psych routine
161 : CpAirFnW, // accessor for E+ psych routine
162 : HfgAirFnWTdb, // accessor for E+ psych routine
163 : HgAirFnWTdb, // accessor for E+ psych routine
164 : TdpFnTdbTwbPb, // accessor for E+ psych routine
165 : TdpFnWPb, // accessor for E+ psych routine
166 : HFnTdbW, // accessor for E+ psych routine
167 : HFnTdbRhPb, // accessor for E+ psych routine
168 : TdbFnHW, // accessor for E+ psych routine
169 : RhovFnTdbRh, // accessor for E+ psych routine
170 : RhovFnTdbRhLBnd0C, // accessor for E+ psych routine
171 : RhovFnTdbWPb, // accessor for E+ psych routine
172 : RhFnTdbRhov, // accessor for E+ psych routine
173 : RhFnTdbRhovLBnd0C, // accessor for E+ psych routine
174 : RhFnTdbWPb, // accessor for E+ psych routine
175 : TwbFnTdbWPb, // accessor for E+ psych routine
176 : VFnTdbWPb, // accessor for E+ psych routine
177 : WFnTdpPb, // accessor for E+ psych routine
178 : WFnTdbH, // accessor for E+ psych routine
179 : WFnTdbTwbPb, // accessor for E+ psych routine
180 : WFnTdbRhPb, // accessor for E+ psych routine
181 : PsatFnTemp, // accessor for E+ psych routine
182 : TsatFnHPb, // accessor for E+ psych routine
183 : TsatFnPb, // not public in PsychRoutines.cc so not really available in EMS.
184 : CpCW, // accessor for E+ psych routine
185 : CpHW, // accessor for E+ psych routine
186 : RhoH2O, // accessor for E+ psych routine
187 :
188 : // Simulation Management Functions
189 : FatalHaltEp, // accessor for E+ error management, "Fatal" level
190 : SevereWarnEp, // accessor for E+ error management, "Severe" level
191 : WarnEp, // accessor for E+ error management, "Warning" level
192 :
193 : // Trend variable handling Functions
194 : TrendValue, // accessor for Erl Trend variables, instance value
195 : TrendAverage, // accessor for Erl Trend variables, average value
196 : TrendMax, // accessor for Erl Trend variables, max value
197 : TrendMin, // accessor for Erl Trend variables, min value
198 : TrendDirection, // accessor for Erl Trend variables, slope value
199 : TrendSum, // accessor for Erl Trend variables, sum value
200 :
201 : // Curve and Table access function
202 : CurveValue,
203 :
204 : // Weather data query functions
205 : TodayIsRain, // Access TodayIsRain(hour, timestep)
206 : TodayIsSnow, // Access TodayIsSnow(hour, timestep)
207 : TodayOutDryBulbTemp, // Access TodayOutDryBulbTemp(hour, timestep)
208 : TodayOutDewPointTemp, // Access TodayOutDewPointTemp(hour, timestep)
209 : TodayOutBaroPress, // Access TodayOutBaroPress(hour, timestep)
210 : TodayOutRelHum, // Access TodayOutRelHum(hour, timestep)
211 : TodayWindSpeed, // Access TodayWindSpeed(hour, timestep)
212 : TodayWindDir, // Access TodayWindDir(hour, timestep)
213 : TodaySkyTemp, // Access TodaySkyTemp(hour, timestep)
214 : TodayHorizIRSky, // Access TodayHorizIRSky(hour, timestep)
215 : TodayBeamSolarRad, // Access TodayBeamSolarRad(hour, timestep)
216 : TodayDifSolarRad, // Access TodayDifSolarRad(hour, timestep)
217 : TodayAlbedo, // Access TodayAlbedo(hour, timestep)
218 : TodayLiquidPrecip, // Access TodayLiquidPrecip(hour, timestep)
219 : TomorrowIsRain, // Access TomorrowIsRain(hour, timestep)
220 : TomorrowIsSnow, // Access TomorrowIsSnow(hour, timestep)
221 : TomorrowOutDryBulbTemp, // Access TomorrowOutDryBulbTemp(hour, timestep)
222 : TomorrowOutDewPointTemp, // Access TomorrowOutDewPointTemp(hour, timestep)
223 : TomorrowOutBaroPress, // Access TomorrowOutBaroPress(hour, timestep)
224 : TomorrowOutRelHum, // Access TomorrowOutRelHum(hour, timestep)
225 : TomorrowWindSpeed, // Access TomorrowWindSpeed(hour, timestep)
226 : TomorrowWindDir, // Access TomorrowWindDir(hour, timestep)
227 : TomorrowSkyTemp, // Access TomorrowSkyTemp(hour, timestep)
228 : TomorrowHorizIRSky, // Access TomorrowHorizIRSky(hour, timestep)
229 : TomorrowBeamSolarRad, // Access TomorrowBeamSolarRad(hour, timestep)
230 : TomorrowDifSolarRad, // Access TomorrowDifSolarRad(hour, timestep)
231 : TomorrowAlbedo, // Access TomorrowAlbedo(hour, timestep)
232 : TomorrowLiquidPrecip, // Access TomorrowLiquidPrecip(hour, timestep)
233 : Num
234 : };
235 :
236 : int constexpr NumPossibleOperators(96); // total number of operators and built-in functions
237 :
238 : int constexpr MaxWhileLoopIterations(1000000); // protect from infinite loop in WHILE loops
239 :
240 : // Types
241 :
242 : struct OutputVarSensorType
243 : {
244 : // Members
245 : std::string Name; // name of associated Erl Variable
246 : std::string UniqueKeyName; // unique key name associated with output variable
247 : std::string OutputVarName; // name of output variable
248 : bool CheckedOkay; // set to true once checked out okay
249 : OutputProcessor::VariableType VariableType;
250 : int Index; // ref index in output processor, points to variable
251 : int VariableNum; // ref to global variable in runtime language
252 : int SchedNum; // ref index ptr to schedule service (filled if Schedule Value)
253 : // INTEGER :: VarType = 0
254 :
255 : // Default Constructor
256 51 : OutputVarSensorType() : CheckedOkay(false), VariableType(OutputProcessor::VariableType::Invalid), Index(0), VariableNum(0), SchedNum(0)
257 : {
258 51 : }
259 : };
260 :
261 : struct InternalVarsAvailableType
262 : {
263 : // Members
264 : // structure for internal data available for use in Erl that are not sourced by output variables
265 : std::string DataTypeName; // general internal variable name registered, All uppercase
266 : std::string UniqueIDName; // unique id for internal var, All uppercase
267 : std::string Units; // registered units, used for reporting and checks.
268 : PtrDataType PntrVarTypeUsed; // data type used: integer (PntrInteger) or real (PntrReal)
269 : Real64 *RealValue; // POINTER to the REAL value that is being accessed
270 : int *IntValue; // POINTER to the Integer value that is being accessed
271 :
272 : // Default Constructor
273 373 : InternalVarsAvailableType() : PntrVarTypeUsed(PtrDataType::Invalid), RealValue(nullptr), IntValue(nullptr)
274 : {
275 373 : }
276 : };
277 :
278 : struct InternalVarsUsedType
279 : {
280 : // Members
281 : // structure for internal data that user has selected to use in Erl.
282 : std::string Name; // Erl variable name
283 : std::string InternalDataTypeName; // general internal variable name, All uppercase
284 : std::string UniqueIDName; // unique id for internal var, All uppercase
285 : bool CheckedOkay; // set to true once matched to available internal var
286 : int ErlVariableNum; // points to global Erl variable, matches Name
287 : int InternVarNum; // points to index match in EMSInternalVarsAvailable structure
288 :
289 : // Default Constructor
290 28 : InternalVarsUsedType() : CheckedOkay(false), ErlVariableNum(0), InternVarNum(0)
291 : {
292 28 : }
293 : };
294 :
295 : struct EMSActuatorAvailableType
296 : {
297 : // Members
298 : // structure for all the actuators available for use in Erl
299 : std::string ComponentTypeName; // general actuator name registered, All uppercase
300 : std::string UniqueIDName; // unique id for actuator, All uppercase
301 : std::string ControlTypeName; // control type id for actuator, All uppercase
302 : std::string Units; // control value units, used for reporting and checks.
303 : int handleCount; // Number of times you tried to get a handle on this actuator,
304 : // whether from EMS:Actuator or getActuatorHandle (API)
305 : PtrDataType PntrVarTypeUsed; // data type used: integer (PntrInteger), real (PntrReal) or logical (PntrLogical)
306 : bool *Actuated; // POINTER to the logical value that signals EMS is actuating
307 : Real64 *RealValue; // POINTER to the REAL value that is being actuated
308 : int *IntValue; // POINTER to the Integer value that is being actuated
309 : bool *LogValue; // POINTER to the Logical value that is being actuated
310 :
311 : // Default Constructor
312 167 : EMSActuatorAvailableType()
313 167 : : handleCount(0), PntrVarTypeUsed(PtrDataType::Invalid), Actuated(nullptr), RealValue(nullptr), IntValue(nullptr), LogValue(nullptr)
314 : {
315 167 : }
316 : };
317 :
318 : struct ActuatorUsedType
319 : {
320 : // Members
321 : // structure for actuators user selected to use in Erl
322 : std::string Name; // Erl variable name
323 : std::string ComponentTypeName; // general actuator name, All uppercase
324 : std::string UniqueIDName; // unique id for actuator, All uppercase
325 : std::string ControlTypeName; // control type id for actuator, All uppercase
326 : bool CheckedOkay; // set to true once matched to available actuator
327 : int ErlVariableNum; // points to global Erl variable, matches Name
328 : int ActuatorVariableNum; // points to index match in EMSActuatorAvailable structure
329 :
330 : // Default Constructor
331 44 : ActuatorUsedType() : CheckedOkay(false), ErlVariableNum(0), ActuatorVariableNum(0)
332 : {
333 44 : }
334 : };
335 :
336 : struct EMSProgramCallManagementType
337 : {
338 : // Members
339 : // structure for Erl program calling managers
340 : std::string Name; // user defined name for calling manager
341 : EMSManager::EMSCallFrom CallingPoint; // EMS Calling point for this manager, see parameters emsCallFrom*
342 : int NumErlPrograms; // count of total number of Erl programs called by this manager
343 : Array1D_int ErlProgramARR; // list of integer pointers to Erl programs used by this manager
344 :
345 : // Default Constructor
346 53 : EMSProgramCallManagementType() : CallingPoint(EMSManager::EMSCallFrom::Invalid), NumErlPrograms(0)
347 : {
348 53 : }
349 : };
350 :
351 : struct ErlValueType
352 : {
353 : // Members
354 : // instance data structure for the values taken by Erl variables, nested structure in ErlVariable
355 : Value Type; // value type, eg. ValueNumber,
356 : Real64 Number; // numeric value instance for Erl variable
357 : std::string String; // string data types in Erl (not used yet)
358 : int Variable; // Pointer to another Erl variable
359 : // Might be good to change names to VariableNum and ExpressionNum just to be clear
360 : int Expression; // Pointer to another Erl expression (e.g. compound operators)
361 : bool TrendVariable; // true if Erl variable is really a trend variable
362 : int TrendVarPointer; // index to match in TrendVariable structure
363 : std::string Error; // holds error message string for reporting
364 : bool initialized; // true if number value has been SET (ie. has been on LHS in SET expression)
365 :
366 : // Default Constructor
367 288946278 : ErlValueType() : Type(Value::Null), Number(0.0), Variable(0), Expression(0), TrendVariable(false), TrendVarPointer(0), initialized(false)
368 : {
369 288946278 : }
370 :
371 : // Member Constructor
372 2388 : ErlValueType(Value const Type, // value type, eg. ValueNumber,
373 : Real64 const Number, // numeric value instance for Erl variable
374 : std::string const &String, // string data types in Erl (not used yet)
375 : int const Variable, // Pointer to another Erl variable
376 : int const Expression, // Pointer to another Erl expression (e.g. compound operators)
377 : bool const TrendVariable, // true if Erl variable is really a trend variable
378 : int const TrendVarPointer, // index to match in TrendVariable structure
379 : std::string const &Error, // holds error message string for reporting
380 : bool const initialized)
381 2388 : : Type(Type), Number(Number), String(String), Variable(Variable), Expression(Expression), TrendVariable(TrendVariable),
382 2388 : TrendVarPointer(TrendVarPointer), Error(Error), initialized(initialized)
383 : {
384 2388 : }
385 : };
386 :
387 : struct ErlVariableType
388 : {
389 : // Members
390 : // structure for Erl variables
391 : std::string Name; // Erl Variable Name
392 : int StackNum; // 0 for global Erl variables, index in ErlStack structure if local
393 : ErlValueType Value; // values taken by Erl variables
394 : bool ReadOnly; // true if Erl variable is read-only
395 : bool SetByExternalInterface; // set to true if value is set by ExternalInterface
396 :
397 : // Default Constructor
398 7308 : ErlVariableType() : StackNum(0), ReadOnly(false), SetByExternalInterface(false)
399 : {
400 7308 : }
401 : };
402 :
403 : struct InstructionType
404 : {
405 : // Members
406 : // nested structure inside ErlStack that holds program instructions
407 : int LineNum; // Erl program line number reference
408 : DataRuntimeLanguage::ErlKeywordParam Keyword; // type of instruction for this line, e.g. KeywordSet, KeywordIf, etc
409 : int Argument1; // Index to a variable, function, expression, or stack
410 : int Argument2; // Index to a variable, function, expression, or stack
411 :
412 : // Default Constructor
413 9792 : InstructionType() : LineNum(0), Keyword(DataRuntimeLanguage::ErlKeywordParam::None), Argument1(0), Argument2(0)
414 : {
415 9792 : }
416 : };
417 :
418 : struct ErlStackType // Stores Erl programs in a stack of statements/instructions
419 : {
420 : // Members
421 : std::string Name; // Erl program or subroutine name, user defined
422 : int NumLines; // count of lines in Erl program or subroutine
423 : Array1D_string Line; // string array holding lines of Erl code (for processing)
424 : int NumInstructions; // count of program instructions in stack
425 : Array1D<InstructionType> Instruction; // structure array of program instructions
426 : int NumErrors; // count of errors during stack parsing
427 : Array1D_string Error; // array of error messages from stack parsing
428 :
429 : // Default Constructor
430 9865 : ErlStackType() : NumLines(0), NumInstructions(0), NumErrors(0)
431 : {
432 9865 : }
433 : };
434 :
435 : struct ErlExpressionType
436 : {
437 : // Members
438 : ErlFunc Operator; // indicates the type of operator or function 1..64
439 : int NumOperands; // count of operands in expression
440 : Array1D<ErlValueType> Operand; // holds Erl values for operands in expression
441 :
442 : // Default Constructor
443 11508 : ErlExpressionType() : Operator(ErlFunc::Invalid), NumOperands(0)
444 : {
445 11508 : }
446 : };
447 :
448 : struct Operator
449 : {
450 : // Members
451 : // structure for operators and functions, used to look up information about each operator or function
452 : std::string_view symbol = ""; // string representation of operator or function (for reporting)
453 : int numOperands = 0; // count of operands or function arguments.
454 : };
455 :
456 : static constexpr std::array<std::string_view, (int)ErlFunc::Num> ErlFuncNamesUC = {
457 : "", // Null
458 : "", // Literal
459 : "-", // Negative
460 : "/", // Divide
461 : "*", // Multiply
462 : "-", // Subtract
463 : "+", // Add
464 : "==", // Equal
465 : "<>", // NotEqual
466 : "<=", // LessOrEqual
467 : ">=", // GreaterOrEqual
468 : "<", // LessThan
469 : ">", // GreaterThan
470 : "^", // RaiseToPower
471 : "&&", // LogicalAND
472 : "||", // LogicalOR
473 : // note there is an important check "> 15" to distinguish operators from functions
474 : // so be careful if renumber these parameters. Binary operator additions should get inserted here rather than appended
475 :
476 : // parameters for built-in Erl functions, these are processed like operators and numbering
477 : // must be sequential with the operators.
478 : // math functions
479 : "@ROUND", // Round
480 : "@MOD", // Mod
481 : "@SIN", // Sin
482 : "@COS", // Cos
483 : "@ARCSIN", // ArcSin
484 : "@ARCCOS", // ArcCos
485 : "@DEGTORAD", // DegToRad
486 : "@RADTODEG", // RadToDeg
487 : "@EXP", // Exp
488 : "@LN", // Ln
489 : "@MAX", // Max
490 : "@MIN", // Min
491 : "@ABS", // Abs
492 : "@RANDOMUNIFORMU", // RandU
493 : "@RANDOMGAUSSIAN", // RandG
494 : "@SEEDRANDOM", // RandSeed
495 :
496 : // begin psychrometric routines
497 : "@RHOAIRFNPBTDBW", // RhoAirFnPbTdbW
498 : "@CPAIRFNW", // CpAirFnW
499 : "@HFGAIRFNWTDB", // HfgAirFnWTdb
500 : "@HGAIRFNWTDB", // HgAirFnWTdb
501 : "@TDPFNTDBTWBPB", // TdpFnTdbTwbPb
502 : "@TDPFNWPB", // TdpFnWPb
503 : "@HFNTDBW", // HFnTdbW
504 : "@HFNTDBRHPB", // HFnTdbRhPb
505 : "@TDBFNHW", // TdbFnHW
506 : "@RHOVFNTDBRH", // RhovFnTdbRh
507 : "@RHOVFNTDBRHLBND0C", // RhovFnTdbRhLBnd0C
508 : "@RHOVFNTDBWPB", // RhovFnTdbWPb
509 : "@RHFNTDBRHOV", // RhFnTdbRhov
510 : "@RHFNTDBRHOVBND0C", // RhFnTdbRhovLBnd0C
511 : "@RHFNTDBWPB", // RhFnTdbWPb
512 : "@TWBFNTDBWPB", // TwbFnTdbWPb
513 : "@VFNTDBWPB", // VFnTdbWPb
514 : "@WFNTDPPB", // WFnTdpPb
515 : "@WFNTDBH", // WFnTdbH
516 : "@WFNTDBTWBPB", // WFnTdbTwbPb
517 : "@WFNTDBRHPB", // WFnTdbRhPb
518 : "@PSATFNTEMP", // PsatFnTemp
519 : "@TSATFNHPB", // TsatFnHPb
520 : "@TSATFNPB", // TsatFnPb
521 : "@CPCW", // CpCW
522 : "@CPHW", // CpHW
523 : "@RHOH2O", // RhoH2O
524 :
525 : // Simulation Management Functions
526 : "@FATALHALTEP", // FatalHaltEp
527 : "@SEVEREWARNEP", // SevereWarnEp
528 : "@WARNEP", // WarnEp
529 :
530 : // Trend variable handling Functions
531 : "@TRENDVALUE", // TrendValue
532 : "@TRENDAVERAGE", // TrendAverage
533 : "@TRENDMAX", // TrendMax
534 : "@TRENDMIN", // TrendMin
535 : "@TRENDDIRECTION", // TrendDirection
536 : "@TRENDSUM", // TrendSum
537 :
538 : // Curve and Table access function
539 : "@CURVEVALUE", // CurveValue
540 :
541 : // Weather data query functions
542 : "@TODAYISRAIN", // TodayIsRain
543 : "@TODAYISSNOW", // TodayIsSnow
544 : "@TODAYOUTDRYBULBTEMP", // TodayOutDryBulbTemp
545 : "@TODAYOUTDEWPOINTTEMP", // TodayOutDewPointTemp
546 : "@TODAYOUTBAROPRESS", // TodayOutBaroPress
547 : "@TODAYOUTRELHUM", // TodayOutRelHum
548 : "@TODAYWINDSPEED", // TodayWindSpeed
549 : "@TODAYWINDDIR", // TodayWindDir
550 : "@TODAYSKYTEMP", // TodaySkyTemp
551 : "@TODAYHORIZRSKY", // TodayHorizIRSky
552 : "@TODAYBEAMSOLARRAD", // TodayBeamSolarRad
553 : "@TODAYDIFSOLARRAD", // TodayDifSolarRad
554 : "@TODAYALBEDO", // TodayAlbedo
555 : "@TODAYLIQUIDPRECIP", // TodayLiquidPrecip
556 : "@TOMORROWISRAIN", // TomorrowIsRain
557 : "@TOMORROWISSNOW", // TomorrowIsSnow
558 : "@TOMORROWOUTDRYBULBTEMP", // TomorrowOutDryBulbTemp
559 : "@TOMORROWOUTDEWPOINTTEMP", // TomorrowOutDewPointTemp
560 : "@TOMORROWOUTBAROPRESS", // TomorrowOutBaroPress
561 : "@TOMORROWOUTRELHUM", // TomorrowOutRelHum
562 : "@TOMORROWWINDSPEED", // TomorrowWindSpeed
563 : "@TOMORROWWINDDIR", // TomorrowWindDir
564 : "@TOMORROWSKYTEMP", // TomorrowSkyTemp
565 : "@TOMORROWHORIZRSKY", // TomorrowHorizIRSky
566 : "@TOMORROWBEAMSOLARRAD", // TomorrowBeamSolarRad
567 : "@TOMORROWDIFSOLARRAD", // TomorrowDifSolarRad
568 : "@TOMORROWALBEDO", // TomorrowAlbedo
569 : "@TOMORROWLIQUIDPRECIP" // TomorrowLiquidPrecip
570 : };
571 :
572 : static constexpr std::array<int, (int)ErlFunc::Num> ErlFuncNumOperands = {
573 : 0, // Null
574 : 1, // Literal
575 : 0, // Negative
576 : 2, // Divide
577 : 2, // Multiply
578 : 2, // Subtract
579 : 2, // Add
580 : 2, // Equal
581 : 2, // NotEqual
582 : 2, // LessOrEqual
583 : 2, // GreaterOrEqual
584 : 2, // LessThan
585 : 2, // GreaterThan
586 : 2, // RaiseToPower
587 : 2, // LogicalAND
588 : 2, // LogicalOR
589 : 1, // Round
590 : 2, // Mod
591 : 1, // Sin
592 : 1, // Cos
593 : 1, // ArcSin
594 : 1, // ArcCos
595 : 1, // DegToRad
596 : 1, // RadToDeg
597 : 1, // Exp
598 : 1, // Ln
599 : 2, // Max
600 : 2, // Min
601 : 1, // ABS
602 : 2, // RandU
603 : 4, // RandG
604 : 1, // RandSeed
605 :
606 : // begin psychrometric routines
607 : 3, // RhoAirFnPbTdbW
608 : 1, // CpAirFnW
609 : 2, // HfgAirFnWTdb
610 : 2, // HgAirFnWTdb
611 : 3, // TdpFnTdbTwbPb
612 : 2, // TdpFnWPb
613 : 2, // HFnTdbW
614 : 3, // HFnTdbRhPb
615 : 2, // TdbFnHW
616 : 2, // RhovFnTdbRh
617 : 2, // RhovFnTdbRhLBnd0C
618 : 3, // RhovFnTdbWPb
619 : 2, // RhFnTdbRhov
620 : 2, // RhFnTdbRhovLBnd0C
621 : 3, // RhFnTdbWPb
622 : 3, // TwbFnTdbWPb
623 : 3, // VFnTdbWPb
624 : 2, // WFnTdpPb
625 : 2, // WFnTdbH
626 : 3, // WFnTdbTwbPb
627 : 4, // WFnTdbRhPb
628 : 1, // PsatFnTemp
629 : 2, // TsatFnHPb
630 : 1, // TsatFnPb
631 : 1, // CpCW
632 : 1, // CpHW
633 : 1, // RhoH2O
634 :
635 : // Simulation Management Functions
636 : 1, // FatalHaltEp
637 : 1, // SevereWarnEp
638 : 1, // WarnEp
639 :
640 : // Trend variable handling Functions
641 : 2, // TrendValue
642 : 2, // TrendAverage
643 : 2, // TrendMax
644 : 2, // TrendMin
645 : 2, // TrendDirection
646 : 2, // TrendSum
647 :
648 : // Curve and Table access function
649 : 6, // CurveValue
650 :
651 : // Weather data query functions
652 : 2, // TodayIsRain
653 : 2, // TodayIsSnow
654 : 2, // TodayOutDryBulbTemp
655 : 2, // TodayOutDewPointTemp
656 : 2, // TodayOutBaroPress
657 : 2, // TodayOutRelHum
658 : 2, // TodayWindSpeed
659 : 2, // TodayWindDir
660 : 2, // TodaySkyTemp
661 : 2, // TodayHorizIRSky
662 : 2, // TodayBeamSolarRad
663 : 2, // TodayDifSolarRad
664 : 2, // TodayAlbedo
665 : 2, // TodayLiquidPrecip
666 : 2, // TomorrowIsRain
667 : 2, // TomorrowIsSnow
668 : 2, // TomorrowOutDryBulbTemp
669 : 2, // TomorrowOutDewPointTemp
670 : 2, // TomorrowOutBaroPress
671 : 2, // TomorrowOutRelHum
672 : 2, // TomorrowWindSpeed
673 : 2, // TomorrowWindDir
674 : 2, // TomorrowSkyTemp
675 : 2, // TomorrowHorizIRSky
676 : 2, // TomorrowBeamSolarRad
677 : 2, // TomorrowDifSolarRad
678 : 2, // TomorrowAlbedo
679 : 2 // TomorrowLiquidPrecip
680 : };
681 :
682 : struct TrendVariableType
683 : {
684 : // Members
685 : std::string Name;
686 : int ErlVariablePointer; // the Erl variable being logged in trend
687 : int LogDepth; // number of timesteps back
688 : Array1D<Real64> TrendValARR; // the main storage of trend data
689 : Array1D<Real64> tempTrendARR; // temporary holder during push
690 : Array1D<Real64> TimeARR; // hours back in time for trend points
691 :
692 : // Default Constructor
693 3 : TrendVariableType() : ErlVariablePointer(0), LogDepth(0)
694 : {
695 3 : }
696 : };
697 :
698 : // EMS Actuator fast duplicate check lookup support
699 : typedef std::tuple<std::string, std::string, std::string> EMSActuatorKey;
700 : struct EMSActuatorKey_hash
701 : {
702 1321086 : inline static void hash_combine(std::size_t &seed, std::string const &s)
703 : {
704 : std::hash<std::string> hasher;
705 1321086 : seed ^= hasher(s) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
706 1321086 : }
707 :
708 440362 : inline std::size_t operator()(EMSActuatorKey const &key) const
709 : {
710 440362 : std::size_t seed(0);
711 440362 : hash_combine(seed, std::get<0>(key));
712 440362 : hash_combine(seed, std::get<1>(key));
713 440362 : hash_combine(seed, std::get<2>(key));
714 440362 : return seed;
715 : }
716 : };
717 :
718 : void ValidateEMSVariableName(EnergyPlusData &state,
719 : std::string const &cModuleObject, // the current object name
720 : std::string const &cFieldValue, // the field value
721 : std::string const &cFieldName, // the current field name
722 : bool &errFlag, // true if errors found in this routine, false otherwise.
723 : bool &ErrorsFound // true if errors found in this routine, untouched otherwise.
724 : );
725 :
726 : void ValidateEMSProgramName(EnergyPlusData &state,
727 : std::string const &cModuleObject, // the current object name
728 : std::string const &cFieldValue, // the field value
729 : std::string const &cFieldName, // the current field name
730 : std::string const &cSubType, // sub type = Program or Subroutine
731 : bool &errFlag, // true if errors found in this routine, false otherwise.
732 : bool &ErrorsFound // true if errors found in this routine, untouched otherwise.
733 : );
734 :
735 : } // namespace DataRuntimeLanguage
736 :
737 : struct RuntimeLanguageData : BaseGlobalStruct
738 : {
739 :
740 : // In the API, we allow the user to manipulate user-defined EMS globals, but we skip the built-in ones to avoid
741 : // problems. The built-in ones will not always start at zero, so we keep a start/end to ignore that specific range.
742 : int emsVarBuiltInStart = 0;
743 : int emsVarBuiltInEnd = 0;
744 :
745 : int NumProgramCallManagers = 0; // count of Erl program managers with calling points
746 : int NumSensors = 0; // count of EMS sensors used in model (data from output variables)
747 : int numActuatorsUsed = 0; // count of EMS actuators used in model
748 : int numEMSActuatorsAvailable = 0; // count of EMS actuators available for use in such a model
749 : int maxEMSActuatorsAvailable = 0; // count of EMS current maximum actuators available for use in such a model
750 : int NumInternalVariablesUsed = 0; // count of EMS internal variables used in model
751 : int numEMSInternalVarsAvailable = 0; // count of EMS internal variables available for use in such a model
752 : int maxEMSInternalVarsAvailable = 0; // count of EMS current maximum internal variables available for use in such a model
753 : int varsAvailableAllocInc = 1000; // allocation increment for variable arrays
754 : int NumErlPrograms = 0; // count of Erl programs in model
755 : int NumErlSubroutines = 0; // count of Erl subroutines in model
756 : int NumUserGlobalVariables = 0; // count of global EMS variables defined by user
757 : int NumErlVariables = 0; // count of Erl variables
758 : int NumErlStacks = 0; // count of Erl program stacks in model. sum of programs and subroutines
759 : int NumExpressions = 0; // count of Erl expressions
760 : int NumEMSOutputVariables = 0; // count of EMS output variables, custom output variables from Erl
761 : int NumEMSMeteredOutputVariables = 0; // count of EMS metered output variables, custom meters from Erl
762 : int NumErlTrendVariables = 0; // count of EMS trend variables in model
763 : int NumEMSCurveIndices = 0; // count of EMS curve index variables in model
764 : int NumEMSConstructionIndices = 0; // count of EMS construction index variables in model
765 :
766 : // ######################################################################################################################################
767 : // code for ExternalInterface
768 : int NumExternalInterfaceGlobalVariables = 0; // count of ExternalInterface runtime variable
769 : int NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables = 0; // count of ExternalInterface runtime variable for FMUImport
770 : // will be updated with values from ExternalInterface
771 : int NumExternalInterfaceFunctionalMockupUnitExportGlobalVariables = 0; // count of ExternalInterface runtime variable for FMUExport
772 : // will be updated with values from ExternalInterface
773 : int NumExternalInterfaceActuatorsUsed = 0; // count of ExternalInterface Actuators
774 : int NumExternalInterfaceFunctionalMockupUnitImportActuatorsUsed = 0; // count of ExternalInterface Actuators for FMUImport
775 : int NumExternalInterfaceFunctionalMockupUnitExportActuatorsUsed = 0; // count of ExternalInterface Actuators for FMUExport
776 :
777 : // ######################################################################################################################################
778 :
779 : bool OutputEDDFile = false; // set to true if user requests EDD output file be written
780 : bool OutputFullEMSTrace = false; // how much to write out to trace, if true do verbose for each line
781 : bool OutputEMSErrors = false; // how much to write out to trace, if true include Erl error messages
782 : bool OutputEMSActuatorAvailFull = false; // how much to write out to EDD file, if true dump full combinatorial actuator list
783 : bool OutputEMSActuatorAvailSmall = false; // how much to write out to EDD file, if true dump actuator list without key names
784 : bool OutputEMSInternalVarsFull = false; // how much to write out to EDD file, if true dump full combinatorial internal list
785 : bool OutputEMSInternalVarsSmall = false; // how much to write out to EDD file, if true dump internal list without key names
786 :
787 : Array2D_bool EMSConstructActuatorChecked;
788 : Array2D_bool EMSConstructActuatorIsOkay;
789 :
790 : // Object Data
791 : Array1D<DataRuntimeLanguage::ErlVariableType> ErlVariable; // holds Erl variables in a structure array
792 : Array1D<DataRuntimeLanguage::ErlStackType> ErlStack; // holds Erl programs in separate "stacks"
793 : Array1D<DataRuntimeLanguage::ErlExpressionType> ErlExpression; // holds Erl expressions in structure array
794 : Array1D<DataRuntimeLanguage::TrendVariableType> TrendVariable; // holds Erl trend variables in a structure array
795 : Array1D<DataRuntimeLanguage::OutputVarSensorType> Sensor; // EMS:SENSOR objects used (from output variables)
796 : Array1D<DataRuntimeLanguage::EMSActuatorAvailableType> EMSActuatorAvailable; // actuators that could be used
797 : Array1D<DataRuntimeLanguage::ActuatorUsedType> EMSActuatorUsed; // actuators that are used
798 : Array1D<DataRuntimeLanguage::InternalVarsAvailableType> EMSInternalVarsAvailable; // internal data that could be used
799 : Array1D<DataRuntimeLanguage::InternalVarsUsedType> EMSInternalVarsUsed; // internal data that are used
800 : Array1D<DataRuntimeLanguage::EMSProgramCallManagementType> EMSProgramCallManager; // program calling managers
801 : DataRuntimeLanguage::ErlValueType Null = DataRuntimeLanguage::ErlValueType(
802 : DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "null" Erl variable value instance
803 : DataRuntimeLanguage::ErlValueType False = DataRuntimeLanguage::ErlValueType(
804 : DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "false" Erl variable value instance
805 : DataRuntimeLanguage::ErlValueType True = DataRuntimeLanguage::ErlValueType(
806 : DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "True" Erl variable value instance, gets reset
807 :
808 : // EMS Actuator fast duplicate check lookup support
809 : std::unordered_set<std::tuple<std::string, std::string, std::string>, DataRuntimeLanguage::EMSActuatorKey_hash>
810 : EMSActuator_lookup; // Fast duplicate lookup structure
811 :
812 796 : void init_state([[maybe_unused]] EnergyPlusData &state) override
813 : {
814 796 : }
815 :
816 0 : void clear_state() override
817 : {
818 0 : this->NumProgramCallManagers = 0;
819 0 : this->NumSensors = 0;
820 0 : this->numActuatorsUsed = 0;
821 0 : this->numEMSActuatorsAvailable = 0;
822 0 : this->maxEMSActuatorsAvailable = 0;
823 0 : this->NumInternalVariablesUsed = 0;
824 0 : this->numEMSInternalVarsAvailable = 0;
825 0 : this->maxEMSInternalVarsAvailable = 0;
826 0 : this->varsAvailableAllocInc = 1000;
827 0 : this->NumErlPrograms = 0;
828 0 : this->NumErlSubroutines = 0;
829 0 : this->NumUserGlobalVariables = 0;
830 0 : this->NumErlVariables = 0;
831 0 : this->NumErlStacks = 0;
832 0 : this->NumExpressions = 0;
833 0 : this->NumEMSOutputVariables = 0;
834 0 : this->NumEMSMeteredOutputVariables = 0;
835 0 : this->NumErlTrendVariables = 0;
836 0 : this->NumEMSCurveIndices = 0;
837 0 : this->NumEMSConstructionIndices = 0;
838 0 : this->NumExternalInterfaceGlobalVariables = 0;
839 0 : this->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables = 0;
840 0 : this->NumExternalInterfaceFunctionalMockupUnitExportGlobalVariables = 0;
841 0 : this->NumExternalInterfaceActuatorsUsed = 0;
842 0 : this->NumExternalInterfaceFunctionalMockupUnitImportActuatorsUsed = 0;
843 0 : this->NumExternalInterfaceFunctionalMockupUnitExportActuatorsUsed = 0;
844 0 : this->OutputEDDFile = false;
845 0 : this->OutputFullEMSTrace = false;
846 0 : this->OutputEMSErrors = false;
847 0 : this->OutputEMSActuatorAvailFull = false;
848 0 : this->OutputEMSActuatorAvailSmall = false;
849 0 : this->OutputEMSInternalVarsFull = false;
850 0 : this->OutputEMSInternalVarsSmall = false;
851 0 : this->EMSConstructActuatorChecked.deallocate();
852 0 : this->EMSConstructActuatorIsOkay.deallocate();
853 0 : this->ErlVariable.deallocate();
854 0 : this->ErlStack.deallocate();
855 0 : this->ErlExpression.deallocate();
856 0 : this->TrendVariable.deallocate();
857 0 : this->Sensor.deallocate();
858 0 : this->EMSActuatorAvailable.deallocate();
859 0 : this->EMSActuatorUsed.deallocate();
860 0 : this->EMSInternalVarsAvailable.deallocate();
861 0 : this->EMSInternalVarsUsed.deallocate();
862 0 : this->EMSProgramCallManager.deallocate();
863 0 : this->EMSActuator_lookup.clear();
864 0 : this->Null = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
865 0 : this->False = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
866 0 : this->True = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
867 0 : }
868 : };
869 :
870 : } // namespace EnergyPlus
871 :
872 : #endif
|