The error is usually a misalignment of one of the floating point arrays or not handling the pointers correctly.
Since you are using Delphi 7, I assume you are attempting to access with a 32-bit version of OpenDSS.
Everything is supposed to be rms.
the V array should be L-N
Seconds from the top of the present hour (intHour). If your simulation goes for more than one hour in dynamics mode, you may want to write your algorithm to use the dblHour value.
You can pass V, which is a pointer to the complex (double) array of voltages to the system Y matrix zero-volt reference (we typically think of this as L-N voltages, although that depends on what your model is connected to) as an argument to some procedure/function in PVModel.pas. Receive it as a pointer (pComplexArray (pointer to complex array) in IndMach012 example) and then dereference to use it.
ComplexArray is 1-based. So to get the voltage in phase 1, you would use
V^[1]...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your reply. I did get to work some of the parts. As I understand the MainUnit.pas calls two public declarations from PVModel.pas; CalcPFlow() and CalcDynamic().
CalcPFlow() internally calls a private procedure, Get_ModelCurrent(). This part is working fine.
CalcDynamic() internally calls the private procedure Get_DynamicModelCurrent(). This is exactly where I am getting issues. When I try to use the Integrate() I am obtaining the error in OpenDSS. If I force feed a hard coded number for currents in CalcDynamic() and empty the TPVModel.Integrate() the OpenDSS runs fine.
I am not able to clearly imagine the order of call for dynamic calculation. As I understand Calc() and Integrate() from the MainUnit.pas play an important role in this process.
Additionally, what is the command to export the trace which we create in the procedure TPVModel.WriteTraceRecord() in OpenDSS.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
WriteTraceRecord simply writes a file from your DLL. There is no command to export it unless you write the command.
I wouldn't export it from OpenDSS. I only use this function during debugging then turn it off when everything gets working. After a trial execution, I simply open the text file and look at the contents. Sometimes when there is an error, the home directory gets changed and the file is hard to find, but that should be rare.
Note that the InitTraceFile function creates the trace file and closes it. Then WriteTraceFile appends to the file and closes after each operation. This is done so that if your algorithm barfs between write operations, you can expect to have evidence in the trace file. Otherwise, the write buffers may not get written to disk and you can lose the key evidence of the problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OpenDSS Dynamics Mode.pdf
and
OpenDSS Storage Dynamics DLL.pdf
Integrate is called just before Calc when in Dynamics mode. Currently, Dynamics mode solution is a simple Predictor-Corrector with one corrector step. So Integrate will get called twice per time step.
The idea is that Integrate will advance all your state variables subject to differential equations to the next guess and then your algorithm will compute the current given the voltage for the present value of the state variables.
I generally use a trapezoidal rule integration formula, which is simple to code and generally stays stable. The Predictor step works out to be a forward Euler step. You can actually use other integration formulae in separate models. Of course, some might be incompatible and some don't stay very stable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The DLL seems to be working fine. I have few questions on the sign convention of the currents. In the case of the DLL which is based on the generator, I provide a positive magnitude of the current,
For example, I intend to inject 50 rms at an angle of 0 deg. The monitor at the terminal of the PV generator in dynamic mode shows a current of 50 A rms at an angle of 180 deg.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The direction of current in OpenDSS is positive INTO the terminals of an element. So I suspect an angle of 180 is correct.
If there is ever any question, check the direction of power flow. The phase angle of the current may be meaningless without the phase angle of the voltage. So the sign of the active power is usually a better indicator of which direction the current is flowing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have moved this to the Experts Forum. Here is the original post:
https://sourceforge.net/p/electricdss/discussion/861977/thread/fb550699/#dc45
Last edit: Roger Dugan 2014-02-25
The error is usually a misalignment of one of the floating point arrays or not handling the pointers correctly.
Since you are using Delphi 7, I assume you are attempting to access with a 32-bit version of OpenDSS.
ComplexArray is 1-based. So to get the voltage in phase 1, you would use
Thank you for your reply. I did get to work some of the parts. As I understand the MainUnit.pas calls two public declarations from PVModel.pas; CalcPFlow() and CalcDynamic().
CalcPFlow() internally calls a private procedure, Get_ModelCurrent(). This part is working fine.
CalcDynamic() internally calls the private procedure Get_DynamicModelCurrent(). This is exactly where I am getting issues. When I try to use the Integrate() I am obtaining the error in OpenDSS. If I force feed a hard coded number for currents in CalcDynamic() and empty the TPVModel.Integrate() the OpenDSS runs fine.
I am not able to clearly imagine the order of call for dynamic calculation. As I understand Calc() and Integrate() from the MainUnit.pas play an important role in this process.
Additionally, what is the command to export the trace which we create in the procedure TPVModel.WriteTraceRecord() in OpenDSS.
WriteTraceRecord simply writes a file from your DLL. There is no command to export it unless you write the command.
I wouldn't export it from OpenDSS. I only use this function during debugging then turn it off when everything gets working. After a trial execution, I simply open the text file and look at the contents. Sometimes when there is an error, the home directory gets changed and the file is hard to find, but that should be rare.
Note that the InitTraceFile function creates the trace file and closes it. Then WriteTraceFile appends to the file and closes after each operation. This is done so that if your algorithm barfs between write operations, you can expect to have evidence in the trace file. Otherwise, the write buffers may not get written to disk and you can lose the key evidence of the problem.
In the ..\distrib\doc\ folder see:
Integrate is called just before Calc when in Dynamics mode. Currently, Dynamics mode solution is a simple Predictor-Corrector with one corrector step. So Integrate will get called twice per time step.
The idea is that Integrate will advance all your state variables subject to differential equations to the next guess and then your algorithm will compute the current given the voltage for the present value of the state variables.
I generally use a trapezoidal rule integration formula, which is simple to code and generally stays stable. The Predictor step works out to be a forward Euler step. You can actually use other integration formulae in separate models. Of course, some might be incompatible and some don't stay very stable.
The DLL seems to be working fine. I have few questions on the sign convention of the currents. In the case of the DLL which is based on the generator, I provide a positive magnitude of the current,
For example, I intend to inject 50 rms at an angle of 0 deg. The monitor at the terminal of the PV generator in dynamic mode shows a current of 50 A rms at an angle of 180 deg.
Great!
The direction of current in OpenDSS is positive INTO the terminals of an element. So I suspect an angle of 180 is correct.
If there is ever any question, check the direction of power flow. The phase angle of the current may be meaningless without the phase angle of the voltage. So the sign of the active power is usually a better indicator of which direction the current is flowing.