dss-python-backend 0.13.1__cp37-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ '''dss_python_backend (or "DSS-Python: Backend") contains the native libraries for the DSS Engine from DSS-Extensions.org.
2
+ The CFFI module is used to bind the native libs, by processing the DSS C-API headers.
3
+
4
+ Previous to DSS-Python version 0.14.0, this backend was included in the same module.
5
+
6
+ For better maintenance and evolution of the Python-only code, the module was split in two.
7
+ '''
8
+
9
+ import os
10
+
11
+ if os.environ.get('DSS_EXTENSIONS_DEBUG', '') != '1':
12
+ from ._dss_capi import ffi, lib
13
+ else:
14
+ import warnings
15
+ warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
16
+ from ._dss_capid import ffi, lib
17
+
18
+ # Ensure this is called at least once. This was moved from
19
+ # CffiApiUtil so we call it as soon as the DLL/so is loaded.
20
+ lib.DSS_Start(0)
21
+
22
+ __version__ = '0.13.1'
23
+ __all__ = ['ffi', 'lib']
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,20 @@
1
+ /*!
2
+
3
+ dss.hpp: a C++ layer for DSS Extensions/C-API
4
+ Copyright (c) 2020-2022 Paulo Meira
5
+
6
+ Version: 0.5.0 (2022-07)
7
+
8
+ **POTENTIAL BREAKING CHANGES UNTIL VERSION 1.0**
9
+
10
+ */
11
+
12
+ #pragma once
13
+ #ifndef DSS_CPP_HPP
14
+ #define DSS_CPP_HPP
15
+
16
+ #include "dss_common.hpp"
17
+ #include "dss_classic.hpp"
18
+ #include "dss_obj.hpp"
19
+
20
+ #endif // #ifndef DSS_CPP_HPP
@@ -0,0 +1,12 @@
1
+ #include "dss_UserModels.h"
2
+
3
+ // These functions need to be implemented
4
+ DSS_MODEL_DLL(int32_t) New(struct TDSSCallBacks* CallBacks);
5
+ DSS_MODEL_DLL(void) Delete(int32_t *ID);
6
+ DSS_MODEL_DLL(int32_t) Select(int32_t *ID);
7
+ DSS_MODEL_DLL(void) UpdateModel(void);
8
+ DSS_MODEL_DLL(void) Sample(void);
9
+ DSS_MODEL_DLL(void) DoPending(int32_t *Code, int32_t *ProxyHdl);
10
+ DSS_MODEL_DLL(void) Edit(char *EditStr, uint32_t MaxLen);
11
+
12
+
@@ -0,0 +1,18 @@
1
+ #include "dss_UserModels.h"
2
+
3
+ // These functions need to be implemented
4
+ DSS_MODEL_DLL(int32_t) New(struct TGeneratorVars* GenData, struct TDynamicsRec* DynaData, struct TDSSCallBacks* CallBacks);
5
+ DSS_MODEL_DLL(void) Delete(int32_t *ID);
6
+ DSS_MODEL_DLL(int32_t) Select(int32_t *ID);
7
+ DSS_MODEL_DLL(void) Init(double *V, double *I);
8
+ DSS_MODEL_DLL(void) Calc(double *V, double *I);
9
+ DSS_MODEL_DLL(void) Integrate(void);
10
+ DSS_MODEL_DLL(void) Edit(char *EditStr, uint32_t MaxLen);
11
+ DSS_MODEL_DLL(void) UpdateModel(void);
12
+ DSS_MODEL_DLL(int32_t) NumVars(void);
13
+ DSS_MODEL_DLL(void) GetAllVars(double *vars);
14
+ DSS_MODEL_DLL(double) GetVariable(int32_t *i);
15
+ DSS_MODEL_DLL(void) SetVariable(int32_t *i, double *value);
16
+ DSS_MODEL_DLL(void) GetVarName(int32_t *i, char *VarName, uint32_t MaxLen);
17
+ DSS_MODEL_DLL(void) Save(void);
18
+ DSS_MODEL_DLL(void) Restore(void);
@@ -0,0 +1,18 @@
1
+ #include "dss_UserModels.h"
2
+
3
+ // These functions need to be implemented
4
+ DSS_MODEL_DLL(int32_t) New(struct TDynamicsRec* DynaData, struct TDSSCallBacks* CallBacks);
5
+ DSS_MODEL_DLL(void) Delete(int32_t *ID);
6
+ DSS_MODEL_DLL(int32_t) Select(int32_t *ID);
7
+ DSS_MODEL_DLL(void) Edit(char *EditStr, uint32_t MaxLen);
8
+ DSS_MODEL_DLL(void) Init(double *V, double *I);
9
+ DSS_MODEL_DLL(void) Calc(double *V, double *I);
10
+ DSS_MODEL_DLL(void) Integrate(void);
11
+ DSS_MODEL_DLL(void) UpdateModel(void);
12
+ DSS_MODEL_DLL(void) Save(void);
13
+ DSS_MODEL_DLL(void) Restore(void);
14
+ DSS_MODEL_DLL(int32_t) NumVars(void);
15
+ DSS_MODEL_DLL(void) GetAllVars(double *vars);
16
+ DSS_MODEL_DLL(double) GetVariable(int32_t *i);
17
+ DSS_MODEL_DLL(void) SetVariable(int32_t *i, double *value);
18
+ DSS_MODEL_DLL(void) GetVarName(int32_t *i, char *VarName, uint32_t MaxLen);
@@ -0,0 +1,16 @@
1
+ #include "dss_UserModels.h"
2
+
3
+ // These functions need to be implemented
4
+ DSS_MODEL_DLL(int32_t) New(struct TDynamicsRec* DynaData, struct TDSSCallBacks* CallBacks);
5
+ DSS_MODEL_DLL(void) Delete(int32_t *ID);
6
+ DSS_MODEL_DLL(int32_t) Select(int32_t *ID);
7
+ DSS_MODEL_DLL(void) Edit(char *EditStr, uint32_t MaxLen);
8
+ DSS_MODEL_DLL(void) Init(double *V, double *I);
9
+ DSS_MODEL_DLL(void) Calc(double *V, double *I);
10
+ DSS_MODEL_DLL(void) Integrate(void);
11
+ DSS_MODEL_DLL(void) UpdateModel(void);
12
+ DSS_MODEL_DLL(int32_t) NumVars(void);
13
+ DSS_MODEL_DLL(void) GetAllVars(double *vars);
14
+ DSS_MODEL_DLL(double) GetVariable(int32_t *i);
15
+ DSS_MODEL_DLL(void) SetVariable(int32_t *i, double *value);
16
+ DSS_MODEL_DLL(void) GetVarName(int32_t *i, char *VarName, uint32_t MaxLen);
@@ -0,0 +1,18 @@
1
+ #include "dss_UserModels.h"
2
+
3
+ // These functions need to be implemented
4
+ DSS_MODEL_DLL(int32_t) New(struct TDynamicsRec* DynaData, struct TDSSCallBacks* CallBacks);
5
+ DSS_MODEL_DLL(void) Delete(int32_t *ID);
6
+ DSS_MODEL_DLL(int32_t) Select(int32_t *ID);
7
+ DSS_MODEL_DLL(void) Edit(char *EditStr, uint32_t MaxLen);
8
+ DSS_MODEL_DLL(void) Init(double *V, double *I);
9
+ DSS_MODEL_DLL(void) Calc(double *V, double *I);
10
+ DSS_MODEL_DLL(void) Integrate(void);
11
+ DSS_MODEL_DLL(void) UpdateModel(void);
12
+ DSS_MODEL_DLL(void) Save(void);
13
+ DSS_MODEL_DLL(void) Restore(void);
14
+ DSS_MODEL_DLL(int32_t) NumVars(void);
15
+ DSS_MODEL_DLL(void) GetAllVars(double *vars);
16
+ DSS_MODEL_DLL(double) GetVariable(int32_t *i);
17
+ DSS_MODEL_DLL(void) SetVariable(int32_t *i, double *value);
18
+ DSS_MODEL_DLL(void) GetVarName(int32_t *i, char *VarName, uint32_t MaxLen);
@@ -0,0 +1,349 @@
1
+ #ifndef DSS_USER_MODELS_H
2
+ #define DSS_USER_MODELS_H
3
+
4
+ #ifdef __cplusplus
5
+ # ifdef _MSC_VER
6
+ # if _MSC_VER <= 1500
7
+ # include "stdint_compat.h"
8
+ # else
9
+ # include <cstdint>
10
+ # endif
11
+ # else
12
+ # include <cstdint>
13
+ # endif
14
+ #else
15
+ # ifdef _MSC_VER
16
+ # if _MSC_VER <= 1500
17
+ # include "stdint_compat.h"
18
+ typedef char bool;
19
+ # define false (0)
20
+ # define true (1)
21
+ # else
22
+ # include <stdint.h>
23
+ # include <stdbool.h>
24
+ # endif
25
+ # else
26
+ # include <stdint.h>
27
+ # include <stdbool.h>
28
+ # endif
29
+ #endif
30
+
31
+ #ifndef dss_long_bool
32
+ #ifdef DSS_CAPI_DLL
33
+ #define dss_long_bool int32_t
34
+ #else
35
+ #define dss_long_bool bool
36
+ #endif
37
+ #endif
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ enum SolutionMode
44
+ {
45
+ SOLUTION_SNAPSHOT = 0,
46
+ SOLUTION_DAILYMODE = 1,
47
+ SOLUTION_YEARLYMODE = 2,
48
+ SOLUTION_MONTECARLO1 = 3,
49
+ SOLUTION_LOADDURATION1 = 4,
50
+ SOLUTION_PEAKDAY = 5,
51
+ SOLUTION_DUTYCYCLE = 6,
52
+ SOLUTION_DIRECT = 7,
53
+ SOLUTION_MONTEFAULT = 8,
54
+ SOLUTION_FAULTSTUDY = 9,
55
+ SOLUTION_MONTECARLO2 = 10,
56
+ SOLUTION_MONTECARLO3 = 11,
57
+ SOLUTION_LOADDURATION2 = 12,
58
+ SOLUTION_AUTOADDFLAG = 13,
59
+ SOLUTION_DYNAMICMODE = 14,
60
+ SOLUTION_HARMONICMODE = 15,
61
+ SOLUTION_GENERALTIME = 16,
62
+ SOLUTION_HARMONICMODET = 17
63
+ };
64
+
65
+ enum ECapControlType
66
+ {
67
+ CAP_CURRENTCONTROL = 0,
68
+ CAP_VOLTAGECONTROL = 1,
69
+ CAP_KVARCONTROL = 2,
70
+ CAP_TIMECONTROL = 3,
71
+ CAP_PFCONTROL = 4,
72
+ CAP_USERCONTROL = 5
73
+ };
74
+
75
+ enum EControlAction
76
+ {
77
+ CTRL_NONE = 0,
78
+ CTRL_OPEN = 1,
79
+ CTRL_CLOSE = 2,
80
+ CTRL_RESET = 3,
81
+ CTRL_LOCK = 4,
82
+ CTRL_UNLOCK = 5,
83
+ CTRL_TAPUP = 6,
84
+ CTRL_TAPDOWN = 7
85
+ };
86
+
87
+ #pragma pack(push, 1)
88
+ struct TGeneratorVars
89
+ {
90
+ double
91
+ Theta, // Direct-Axis voltage magnitude & angle
92
+ Pshaft,
93
+ Speed,
94
+ w0, // present Shaft Power and relative Speed, rad/sec, difference from Synchronous speed, w0
95
+ // actual speed = Speed + w0
96
+ Hmass, // Per unit mass constant
97
+ Mmass, // Mass constant actual values (Joule-sec/rad
98
+ D, Dpu, // Actual and per unit damping factors
99
+ kVArating,
100
+ kVGeneratorBase,
101
+ Xd, Xdp, Xdpp, // machine Reactances, ohms
102
+ puXd, puXdp, puXdpp, // machine Reactances, per unit
103
+ dTheta,
104
+ dSpeed, // Derivatives of Theta and Speed
105
+ ThetaHistory,
106
+ SpeedHistory, // history variables for integration
107
+ PNominalPerPhase,
108
+ QNominalPerPhase; // Target P and Q for power flow solution, watts, vars
109
+
110
+ // 32-bit integers}
111
+ int32_t
112
+ NumPhases, //Number of phases
113
+ NumConductors, // Total Number of conductors (wye-connected will have 4)
114
+ Conn; // 0 = wye; 1 = Delta
115
+
116
+
117
+ // Revisions (additions) to structure ...
118
+ // Later additions are appended to end of the structure so that
119
+ // previously compiled DLLs do not break
120
+
121
+ double VThevMag; // Thevinen equivalent voltage for dynamic model
122
+ double VThevHarm; // Thevinen equivalent voltage mag reference for Harmonic model
123
+ double ThetaHarm; // Thevinen equivalent voltage angle reference for Harmonic model
124
+ double VTarget; // Target voltage for generator with voltage control
125
+ double RThev;
126
+ double XThev;
127
+ double XRdp; // Assumed X/R for Xd'
128
+ };
129
+
130
+
131
+ struct TCapControlVars
132
+ {
133
+ int32_t
134
+ FCTPhase,
135
+ FPTPhase; // "ALL" is -1
136
+
137
+ double
138
+ ON_Value,
139
+ OFF_Value,
140
+ PFON_Value,
141
+ PFOFF_Value,
142
+ CTRatio,
143
+ PTRatio,
144
+ ONDelay,
145
+ OFFDelay,
146
+ DeadTime,
147
+ LastOpenTime;
148
+
149
+ dss_long_bool
150
+ Voverride;
151
+
152
+ bool
153
+ VoverrideEvent,
154
+ VoverrideBusSpecified; // Added 8-11-11
155
+
156
+ int32_t VOverrideBusIndex;
157
+
158
+ double
159
+ Vmax,
160
+ Vmin;
161
+
162
+ uint8_t /*enum EControlAction*/ FPendingChange;
163
+ bool
164
+ ShouldSwitch, // True: action is pending
165
+ Armed; // Control is armed for switching unless reset
166
+ uint8_t /*enum EControlAction*/ PresentState;
167
+ uint8_t /*enum EControlAction*/ InitialState;
168
+
169
+ double
170
+ SampleP, // 64-bit number, kW
171
+ SampleQ, // 64-bit number, kvar
172
+ SampleV,
173
+ SampleCurr;
174
+
175
+ int32_t
176
+ NumCapSteps,
177
+ AvailableSteps, // available steps in controlled capacitor
178
+ LastStepInService; // Change this to force an update of cap states
179
+
180
+
181
+ // NOTE: VOverrideBusName and CapacitorName may be UnicodeStrings in Delphi.
182
+ // These pointers could be processed different according to the Pascal compiler.
183
+ char* VOverrideBusName; // Actual string data encoded in UTF-16
184
+ char* CapacitorName; // Actual string data encoded in UTF-16
185
+
186
+ int32_t ControlActionHandle;
187
+ int32_t CondOffset; // Offset for monitored terminal
188
+ };
189
+
190
+
191
+ struct TStorageVars
192
+ {
193
+ double
194
+ kWrating,
195
+ kWhRating,
196
+ kWhStored,
197
+ kWhReserve,
198
+ ChargeEff,
199
+ DisChargeEff,
200
+ kVStorageBase,
201
+ RThev,
202
+ XThev;
203
+
204
+ double
205
+ // Inverter Related Properties
206
+ kVArating,
207
+ kvarlimit,
208
+ kvarlimitneg;
209
+
210
+ dss_long_bool
211
+ P_Priority,
212
+ PF_Priority;
213
+
214
+ double
215
+ pctkWrated,
216
+ EffFactor;
217
+
218
+ double
219
+ // Interaction with InvControl
220
+ Vreg,
221
+ Vavg,
222
+ VVOperation,
223
+ VWOperation,
224
+ DRCOperation,
225
+ VVDRCOperation,
226
+ WPOperation,
227
+ WVOperation;
228
+
229
+ double
230
+ // Dynamics variables
231
+ Vthev_re, // Thevenin equivalent voltage (complex) for dynamic model
232
+ Vthev_im,
233
+ ZThev_re,
234
+ ZThev_im,
235
+ Vthevharm, // Thevenin equivalent voltage mag and angle reference for Harmonic model
236
+ Thetaharm, // Thevenin equivalent voltage mag and angle reference for Harmonic model
237
+ VthevMag, // Thevenin equivalent voltage for dynamic model
238
+ Theta, // Power angle between voltage and current
239
+ w_grid, // Grid frequency
240
+ TotalLosses,
241
+ IdlingLosses;
242
+
243
+ //32-bit integers
244
+ int32_t
245
+ NumPhases, // Number of phases
246
+ NumConductors, // Total Number of conductors (wye-connected will have 4)
247
+ Conn; // 0 = wye; 1 = Delta
248
+ };
249
+
250
+
251
+
252
+ struct TDynamicsRec
253
+ {
254
+ // time vars
255
+ double
256
+ h, // Time step size in sec for dynamics
257
+ t, // sec from top of hour
258
+ tstart,
259
+ tstop;
260
+ int32_t IterationFlag; // 0=New Time Step; 1= Same Time Step as last iteration
261
+ int32_t SolutionMode; // PEAKSNAP, DAILYMODE, YEARLYMODE, MONTECARLO, etc. (see DSSGlobals)
262
+ int32_t intHour; // time, in hours as an integer
263
+ double dblHour; // time, in hours as a floating point number including fractional part
264
+ };
265
+
266
+
267
+ // NOTE: Maxlen argument is to better accommodate Fortran strings. VB also
268
+ // Caller must allocate space for pchar values
269
+
270
+ #ifdef _WIN32
271
+ # define DSS_MODEL_CALLBACK(ret_type, fname) ret_type (__stdcall *fname)
272
+ #else
273
+ # define DSS_MODEL_CALLBACK(ret_type,fname ) ret_type (*fname)
274
+ #endif
275
+
276
+ struct TDSSCallBacks
277
+ {
278
+ DSS_MODEL_CALLBACK(void, MsgCallBack)(char *S, uint32_t Maxlen); // Make use of DSS Message handling
279
+
280
+ // Routines for using DSS Parser. This allows you to write models that accept
281
+ // syntax like other DSS scripts.
282
+ DSS_MODEL_CALLBACK(void, GetIntValue)(int32_t *i); // Get next param as an integer
283
+ DSS_MODEL_CALLBACK(void, GetDblValue)(double *x); // Get next param as a double
284
+ DSS_MODEL_CALLBACK(void, GetStrValue)(char *S, uint32_t MaxLen);
285
+
286
+ // Get next param as a string <= maxlen characters (Cardinal = 32-bit unsigned)}
287
+ // caller must allocate space for s (Maxlen chars)
288
+ DSS_MODEL_CALLBACK(void, LoadParser)(char *S, uint32_t MaxLen); // Copies a string into a special instance of the DSS parser
289
+ DSS_MODEL_CALLBACK(int32_t, NextParam)(char *S, uint32_t MaxLen);
290
+ // Advance to the next parameter and
291
+ // Get name of the param just retrieved, if one was given.
292
+ // Returns length of parameter found. If 0, then end of string.
293
+ // This is to handle the syntax "paramname=paramvalue" commonly used in DSS scripts
294
+ // Copies the string to the location specified by s up to maxlen characters.
295
+ // Caller must allocate space (MaxLen chars)
296
+
297
+ DSS_MODEL_CALLBACK(void, DoDSSCommand)(char *S, uint32_t Maxlen);
298
+ DSS_MODEL_CALLBACK(void, GetActiveElementBusNames)(char *Name1, uint32_t Len1, char *Name2, uint32_t Len2);
299
+ DSS_MODEL_CALLBACK(void, GetActiveElementVoltages)(int32_t *NumVoltages, double /* complex */ **V);
300
+ DSS_MODEL_CALLBACK(void, GetActiveElementCurrents)(int32_t *NumCurrents, double /* complex */ **Curr);
301
+ DSS_MODEL_CALLBACK(void, GetActiveElementLosses)(double /* complex */ *TotalLosses, double /* complex */ *LoadLosses, double /* complex */ *NoLoadLosses);
302
+ DSS_MODEL_CALLBACK(void, GetActiveElementPower)(int32_t Terminal, double /* complex */ *TotalPower);
303
+ DSS_MODEL_CALLBACK(void, GetActiveElementNumCust)(int32_t *NumCust, int32_t *TotalCust);
304
+ DSS_MODEL_CALLBACK(void, GetActiveElementNodeRef)(int32_t Maxsize, int32_t** NodeReferenceArray); // calling program must allocate
305
+ DSS_MODEL_CALLBACK(int32_t, GetActiveElementBusRef)(int32_t Terminal);
306
+ DSS_MODEL_CALLBACK(void, GetActiveElementTerminalInfo)(int32_t *NumTerminals, int32_t *NumConds, int32_t *NumPhases);
307
+ DSS_MODEL_CALLBACK(void, GetPtrToSystemVarray)(void *V, int32_t *iNumNodes); // Returns pointer to Solution.V and size
308
+ DSS_MODEL_CALLBACK(int32_t, GetActiveElementIndex)(void);
309
+
310
+ DSS_MODEL_CALLBACK(bool, IsActiveElementEnabled)(void);
311
+ DSS_MODEL_CALLBACK(bool, IsBusCoordinateDefined)(int32_t BusRef);
312
+ DSS_MODEL_CALLBACK(void, GetBusCoordinate)(int32_t BusRef, double *X, double* Y);
313
+ DSS_MODEL_CALLBACK(double, GetBuskVBase)(int32_t BusRef);
314
+ DSS_MODEL_CALLBACK(double, GetBusDistFromMeter)(int32_t BusRef);
315
+
316
+ DSS_MODEL_CALLBACK(void, GetDynamicsStruct)(void **DynamicsStruct); // Returns pointer to dynamics variables structure
317
+ DSS_MODEL_CALLBACK(double, GetStepSize)(void); // Return just 'h' from dynamics record
318
+ DSS_MODEL_CALLBACK(double, GetTimeSec)(void); // returns t in sec from top of hour
319
+ DSS_MODEL_CALLBACK(double, GetTimeHr)(void); // returns time as a double in hours
320
+
321
+ DSS_MODEL_CALLBACK(void, GetPublicDataPtr)(void **PublicData, int32_t *PublicDataBytes);
322
+ DSS_MODEL_CALLBACK(int32_t, GetActiveElementName)(char *FullName, uint32_t MaxNameLen);
323
+ DSS_MODEL_CALLBACK(void*, GetActiveElementPtr)(void); // Returns pointer to active circuit element
324
+
325
+ //TODO: check FPC vs Delphi compatibility for const parameters in ControlQueuePush
326
+ DSS_MODEL_CALLBACK(int32_t, ControlQueuePush)(const int32_t Hour, const double Sec, const int32_t Code, const int32_t ProxyHdl, void *Owner);
327
+ DSS_MODEL_CALLBACK(void, GetResultStr)(char *S, uint32_t Maxlen);
328
+ };
329
+
330
+ #ifdef __cplusplus
331
+ } // extern "C"
332
+ # ifdef _WIN32
333
+ # define DSS_MODEL_DLL(ret_type) extern "C" __declspec(dllexport) ret_type __stdcall
334
+ # else
335
+ # define DSS_MODEL_DLL(ret_type) extern "C" ret_type
336
+ # endif
337
+ #else
338
+ # ifdef _WIN32
339
+ # define DSS_MODEL_DLL(ret_type) __declspec(dllexport) ret_type __stdcall
340
+ # else
341
+ # define DSS_MODEL_DLL(ret_type) ret_type
342
+ # endif
343
+ #endif
344
+
345
+ #undef DSS_MODEL_CALLBACK
346
+ #pragma pack(pop)
347
+
348
+
349
+ #endif // DSS_USER_MODELS_H