OpenDSS Custom Scripting
OpenDSS Custom Scripting
Description
Snapshot
DIrect
Daily
Yearly
DUtycycle
Time
This mode is new with this version. It differs from the plain
Snapshot mode in following Loadshapes and automatically
sampling Monitor objects. (Also see Set LoadShapeClass
option)'
DYnamic
Harmonic
M1
M2
M3
Faultstudy
MF
Peakday
LD1
LD2
AutoAdd
The specific algorithms for these solution modes may be found in SolutionAlgs.pas. Each
of these was developed in response to a specific need.
You can theoretically interact with any of these modes by setting Number=1 after setting
the mode. Then after each solution (solve command) you sample the results and take
some action.
code in either approach if the script is long. So its six-in-one and a half-dozen in the
other as far as the OpenDSS is concerned.
If the algorithm you are working on is of general use to others, we can add it to the
SolutionAlgs.Pas module and add a solution mode to access it.
C:\Myfolder\Master.DSS
Solve
Set time=(0,0)
Set Controlmode=OFF
Sample
!
!
!
!
Sample
etc
This script starts by defining the circuit using the Compile command. The remainder of
the script is related to making modifications to selected elements in the circuit and
controlling the solution.
The next step is to perform a base case solution. This will cause all control devices to find
a satisfactory setting. Since the rest of the simulation takes place in a short time frame
too short for another regulator tap change or capacitor switch to take place the controls
are subsequently disabled by setting Controlmode=OFF.
A sample command is issued to record the base case solution.
In this problem we know beforehand that the 2500-kW solar PV generator ramps down at
10% per second. It is assumed the generator monitor/control samples the output once per
second and, as the generation starts to fall off, the control sends messages to the
distributed storage units in an attempt to compensate.
At each step, the script:
1. sets the time using the Set Sec= option
2. modifies the generator output, if appropriate. This is done in this example using
the inline math facility (RPN format) in OpenDSS so it is obvious what is being
done, but the script could simply set the value directly.
3. executes a Solve command, which solves the new power flow,
4. records the result in the Monitors defined in the circuit definition using the
Sample command.
During this simulation the Load object setting remain unchanged. (The solution might
change slightly due to different voltages in the network.) Loads do not follow any
Loadshape values in this solution mode. (See Time Mode Scripting below).
An external application was used to compute the latency in the communications system.
This is converted to the appropriate time in the simulation script. Thus, the first message
arrives at sec = 3.020834372. The messages arrive at irregular intervals. This is of no
consequence in this simulation because time is only used for reporting the results in the
Monitor records.
As each message arrives, its effect is simulated by setting the Storage elements to
discharging at a specified discharge rate. In this case, it is assumed the storage
controller/generator monitor determines that the discharge rate should be 11.9%. Note
that the Storage elements remain ON in dispatching mode for subsequent solutions so it is
not necessary to redispatch them until a different dispatch level is desired. So when the
message arrives at Unit 2 a few ms later, only the new Storage unit need be redispatched.
There are many similar problems that can be scripted in this simple manner. The key
thing to remember is that in the default Snapshot mode, everything must be explicitly
scripted.
C:\Myfolder\Master.DSS
storage.jo0235000265.state=discharging %discharge=11.9
Solve
Set sec = 3.024604602 ! Message arrives at Unit 4
storage.jo0235000268_1.state=discharging %discharge=11.9
Solve
etc
! go to 4.0s solution; next generator monitor sample
Set sec=4
Solve
! now simulate arrival of new messages at Storage elements
Set sec = 4.020834372 ! Message arrives at Unit 1
! dispatch twice as high because generator output has dropped
! another 10%
storage.jo0235001304.state=discharging %discharge=(11.9 2 *)
Solve
! solution at t=3.020834372; time incremented to 4.020834372
etc
In the initial base solution, the solar PV generator is at full output and the loads are
constant as well. Next, we define a Loadshape object that embodies the solar ramping
characteristic we will to simulate and assign it to the Duty property of the PV generator.
Note that the units on the Loadshape Interval property is hours, so we do a little in-line
math to specify that the points in the solarramp.csv file are in 1s intervals.
Then we switch the solution mode to the general Time mode and set the
LoadShapeClass=Duty. This means that for the duration of this simulation, Load and
Generator objects will follow the Loadshape object that has been associated with their
respective Duty property.
We set the stepsize to 1s, although one might argue that it doesnt really matter much in
this example because later, we will be setting time explicitly to a different value.
However, we let the time increment automatically for the first 3 solutions.
The first Solve is at time 0 since it is the first after the mode change. The
SolveGeneralTime procedure in SolutionAlgs.Pas auto-increments the time after the
solution so that time is 1s at the end of this statement. The generator ramp starts down
after t=1s and we assume the device monitoring the output once per second will notice
the decline after the t=2 solution and send out dispatch messages at t=3.
After the t=3s solution, the time is auto-incremented to 4s. However, we override that to
simulate the arrival of the first message at a storage unit a few milliseconds later. Time
incremented after each solution, but the incrementing is overridden for the remainder of
the simulation.
At the conclusion of the simulations, the Monitor objects will each contain a number of
records at irregular time intervals. These can be seen in the usual way with either the
Show, Export , or Plot commands.
The OpenDSS Solve command will typically invoke at some point the SolveSnap
function in the program. For the basic power flow solution the SolveSnap function
executes the following steps:
1. Initialize Snapshot (_InitSnap)
2. Repeat until converged:
a. Solve Circuit (_SolveNoControl)
b. Sample control devices (_SampleControls)
c. Do control actions, if any (_DoControlActions)
In _SolveNoControl you may get either an iterative power flow solution or a direct
solution. You will usually get an iterative one unless the mode is Harmonic or Dynamic,
in which cases the default is direct solution. You can specifically require a particular
solution by _SolveDirect or _SolvePFlow.
Using these commands, you can basically design your own solution process. Of course,
you would be required to do your own management of time and of sampling.
These functions are also available as direct calls through the COM interface. In addition,
there is access to other quantities such as the convergence flag, total iterations, etc. It
generally makes more sense to roll your own solution algorithm using a program that
accesses the COM interface, but if you want to do it in a script, you can.