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