03
03
03
int i,k,m,iLdfError,ctr_k,Tap,z;
int iNoofSCases,iMultipleSCases,iNoofSVCs,iNoofWTGs,iNoofTF2Ws,iNoofTF3Ws;
int iNoofVoltageScenarios,iMultipleVScenarios,iTotalRuns,iSaveScenarios;
int iNoofTapableTransformers;
int iNoofTriggers,iNoofActiveTriggers,iNoofPowerPoints,iNoofPoints,
iIsItDRPCTrigger;
double dVoltageSetPoint,dPSetPoint,dQSetPoint;
string strDate,strFilePath,strFileName,strTriggerName;
string strResultsFolderName,strResultsFolderPath,strResultsFilePathandName;
set
sXgrids,sSVCs,sWTGs,sTFWTGs,sTFGTs,sTF3Ws,sLines,sExportCables,sIACableType1,sIACab
leType2,sIACableType3,sIACableType4;
set
sStudyCases,sTriggers,sDRPCTriggers,sWTGTriggers,sDeleteElmRes,sDeleteViPages;
set
sResults,sGridResults,sSVCResults,sWTGResults,sTFWTGResults,sTFGTResults,sTF3WResul
ts,sExportCablesResults,sIACableType1Results,sIACableType2Results,sIACableType3Resu
lts,sIACableType4Results;
object
ldf,oProject,oActiveStudyCase,oActiveScenario,oBackupScenario,oBackupScenario1;
object oTrigger,oWTGTrigger,oDRPCTrigger;
object oXgrid,oSVC,oWTG,oTF2W,oTF3W,oLine,oExportCable;
object oGraphBoard,oViPage,oPlot,oDeleteViPage;
object
oResults,oGridResults,oSVCResults,oWTGResults,oTFWTGResults,oTFGTResults,oTF3WResul
ts,oExportCablesResults,oIACableType1Results,oIACableType2Results,oIACableType3Resu
lts,oIACableType4Results;
!Temporary Variables
object oTemp;
string strDateTemp,strTemp;
int iTempFlag,iOnce;
k=1;
!Future works
!All Future works are placed where they are relevent place and some are listed
below
!Future:Create a own grid summary box similar to grid summary box
Delete(sDeleteElmRes);
!Inputs
!Constants
iMultipleSCases = 0; !1 = Yes or 0 = No, Used to run multiple study cases !
Future: Use General select to give option to user to select required study cases
iMultipleVScenarios = 1; !1 = Yes or 0 = No, used to run multiple Voltage scenarios
iSaveScenarios = 0; !1 = Yes or 0 = No, used to create the changes to the
equiment as new scenarios
printf('===========================================================================
=======');
!Print Date of Execution
strDateTemp = strftime('Date of execution : %A, %d. %B %Y,
%H:%M:%S');
printf(strDateTemp);
iNoofSCases = sStudyCases.Count();
iTempFlag = 0;
!start of For loop for Study Cases
for (i=1;i<=iNoofSCases;i=i+1){
iSCaseNo = i;
printf('===========================================================================
=======');
if (iNoofSCases = 1) {
!Get Active Study Case
oActiveStudyCase = GetActiveStudyCase();
if (NULL = oActiveStudyCase) {
Warn('Warning:No Study Case has been Activated, hence the First Study
Case will be assigned Automatically');
!Assign the first Study Case from all the stuy cases
oActiveStudyCase = sStudyCases.First();
}
}
else {
if (iTempFlag = 0){
oActiveStudyCase=sStudyCases.First();
iTempFlag = 1; !This to ensure that the above command is executed only
once
}
else {
oActiveStudyCase=sStudyCases.Next();
}
}
oActiveStudyCase.Activate();
printf('Running Study Case : %d of %d',i,iNoofSCases);
printf('Active Study case : %o', oActiveStudyCase);
Delete(sDeleteElmRes);
oActiveScenario = GetActiveScenario();
printf('Active Scenario : %o', oActiveScenario);
if (NULL = oActiveScenario) {
Warn('Warning: No Active Scenario Present in the study case');
}
else {
oBackupScenario = SaveAsScenario('BackUpScenario', 0); ! Create a backup
scenario - 0 - do not activate it
}
sGridResults.Clear();
oResults = oActiveStudyCase.CreateObject('ElmRes','ALLResults',k);
oGridResults = oActiveStudyCase.CreateObject('ElmRes','ALLGridResults',k);
oSVCResults = oActiveStudyCase.CreateObject('ElmRes','ALLSVCResults',k);
oWTGResults = oActiveStudyCase.CreateObject('ElmRes','ALLWTGResults',k);
oTFWTGResults = oActiveStudyCase.CreateObject('ElmRes','ALLTFWTGResults',k);
oTFGTResults = oActiveStudyCase.CreateObject('ElmRes','ALLTFGTResults',k);
oTF3WResults = oActiveStudyCase.CreateObject('ElmRes','ALLTF3WResults',k);
oExportCablesResults =
oActiveStudyCase.CreateObject('ElmRes','ALLExportCableResults',k);
oIACableType1Results =
oActiveStudyCase.CreateObject('ElmRes','ALLIACableType1Results',k);
oIACableType2Results =
oActiveStudyCase.CreateObject('ElmRes','ALLIACableType2Results',k);
oIACableType3Results =
oActiveStudyCase.CreateObject('ElmRes','ALLIACableType3Results',k);
oIACableType4Results =
oActiveStudyCase.CreateObject('ElmRes','ALLIACableType4Results',k);
sResults.Add(oResults);
sGridResults.Add(oGridResults);
sSVCResults.Add(oSVCResults);
sWTGResults.Add(oWTGResults);
sTFGTResults.Add(oTFGTResults);
sTFWTGResults.Add(oTFWTGResults);
sTF3WResults.Add(oTF3WResults);
sExportCablesResults.Add(oExportCablesResults);
sIACableType1Results.Add(oIACableType1Results);
sIACableType2Results.Add(oIACableType2Results);
sIACableType3Results.Add(oIACableType3Results);
sIACableType4Results.Add(oIACableType4Results);
oResults.AddVars(this,'b:iSCaseNo');
oResults.AddVars(this,'b:dVsetpoint');
oResults.AddVars(this,'b:dPsetpoint');
oResults.AddVars(this,'b:dQsetpoint');
oResults.AddVars(oTF2W,'m:u1:bushv','m:I:bushv','m:P:bushv','m:Q:bushv','m:S:bushv'
);
oResults.AddVars(oTF2W,'m:u1:buslv','m:I:buslv','m:P:buslv','m:Q:buslv','m:S:buslv'
,'c:nntap','c:loading');
}
oResults.AddVars(oTF2W,'m:u1:bushv','m:I:bushv','m:P:bushv','m:Q:bushv','m:S:bushv'
);
oResults.AddVars(oTF2W,'m:u1:buslv','m:I:buslv','m:P:buslv','m:Q:buslv','m:S:buslv'
,'c:nntap','c:loading');
}
oResults.AddVars(oTF3W,'m:u1:bushv','m:I:bushv','m:phii:bushv','m:P:bushv','m:Q:bus
hv','m:S:bushv');
oResults.AddVars(oTF3W,'m:u1:busmv','m:I:busmv','m:phii:busmv','m:P:busmv','m:Q:bus
mv','m:S:busmv');
oResults.AddVars(oTF3W,'m:u1:buslv','m:I:buslv','m:phii:buslv','m:P:buslv','m:Q:bus
lv','m:S:buslv');
oResults.AddVars(oTF3W,'c:n3tap_m','c:loading');
}
oResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S:bus1');
oResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S:bus2','c:cu
rnom','c:Imax','c:loading');
}
if (sIACableType1 .not. NULL){
for (oLine=sIACableType1.First(); oLine; oLine = sIACableType1.Next()) {
oResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S:bus1');
oResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S:bus2','c:cu
rnom','c:Imax','c:loading');
}
}
oResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S:bus1');
oResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S:bus2','c:cu
rnom','c:Imax','c:loading');
}
}
oResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S:bus1');
oResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S:bus2','c:cu
rnom','c:Imax','c:loading');
}
}
oResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S:bus1');
oResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S:bus2','c:cu
rnom','c:Imax','c:loading');
}
}
oResults.AddVars(oXgrid,'m:P:bus1','m:Q:bus1','m:I:bus1','n:u1:bus1');
oGridResults.AddVars(this,'b:iSCaseNo');
oGridResults.AddVars(this,'b:dVsetpoint');
oGridResults.AddVars(this,'b:dPsetpoint');
oGridResults.AddVars(this,'b:dQsetpoint');
oTFWTGResults.AddVars(oTF2W,'m:u1:buslv','m:I:buslv','m:P:buslv','m:Q:buslv','m:S:b
uslv','c:nntap','c:loading');
}
oTFGTResults.AddVars(oTF2W,'m:u1:bushv','m:I:bushv','m:P:bushv','m:Q:bushv','m:S:bu
shv');
oTFGTResults.AddVars(oTF2W,'m:u1:buslv','m:I:buslv','m:P:buslv','m:Q:buslv','m:S:bu
slv','c:nntap','c:loading');
}
oTF3WResults.AddVars(oTF3W,'m:u1:bushv','m:I:bushv','m:phii:bushv','m:P:bushv','m:Q
:bushv','m:S:bushv');
oTF3WResults.AddVars(oTF3W,'m:u1:busmv','m:I:busmv','m:phii:busmv','m:P:busmv','m:Q
:busmv','m:S:busmv');
oTF3WResults.AddVars(oTF3W,'m:u1:buslv','m:I:buslv','m:phii:buslv','m:P:buslv','m:Q
:buslv','m:S:buslv');
oTF3WResults.AddVars(oTF3W,'c:n3tap_m','c:loading');
}
oExportCablesResults.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S
:bus1');
oExportCablesResults.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S
:bus2','c:curnom','c:Imax','c:loading');
}
oIACableType1Results.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S
:bus1');
oIACableType1Results.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S
:bus2','c:curnom','c:Imax','c:loading');
}
}
oIACableType2Results.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S
:bus1');
oIACableType2Results.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S
:bus2','c:curnom','c:Imax','c:loading');
}
}
if (sIACableType3 .not. NULL){
for (oLine=sIACableType3.First(); oLine; oLine = sIACableType3.Next()) {
oIACableType3Results.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S
:bus1');
oIACableType3Results.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S
:bus2','c:curnom','c:Imax','c:loading');
}
}
oIACableType4Results.AddVars(oLine,'n:u:bus1','m:I:bus1','m:P:bus1','m:Q:bus1','m:S
:bus1');
oIACableType4Results.AddVars(oLine,'n:u:bus2','m:I:bus2','m:P:bus2','m:Q:bus2','m:S
:bus2','c:curnom','c:Imax','c:loading');
}
}
oGridResults.AddVars(oXgrid,'m:P:bus1','m:Q:bus1','m:I:bus1','n:u1:bus1');
!Future: use a map oblect to save Xgrid and all sets for backup in case if
required to change it to its original values
!Create Plot pages and initialise their settings
iOnce = 0;
!For loop for Voltage Scenarios
printf('---------------------------------------------------------------------------
-------');
!Plot
oResults = sResults.Obj(k-1);
oGridResults = sGridResults.Obj(k-1);
oSVCResults = sSVCResults.Obj(k-1);
oWTGResults = sWTGResults.Obj(k-1);
oTFWTGResults = sTFWTGResults.Obj(k-1);
oTFGTResults = sTFGTResults.Obj(k-1);
oTF3WResults = sTF3WResults.Obj(k-1);
oExportCablesResults = sExportCablesResults.Obj(k-1);
oIACableType1Results = sIACableType1Results.Obj(k-1);
oIACableType2Results = sIACableType2Results.Obj(k-1);
oIACableType3Results = sIACableType3Results.Obj(k-1);
oIACableType4Results = sIACableType4Results.Obj(k-1);
!printf('%o',oResults);
if (PlotResultsChoice = 1){
InitialisePlots.Execute(iNoofPoints,GetRequiredEquipment);
PlotResults.Execute(1,1,oXgrid,GetRequiredEquipment,oGridResults);
}
oResults.InitialiseWriting();
oGridResults.InitialiseWriting();
oSVCResults.InitialiseWriting();
oWTGResults.InitialiseWriting();
oTFWTGResults.InitialiseWriting();
oTFGTResults.InitialiseWriting();
oTF3WResults.InitialiseWriting();
oExportCablesResults.InitialiseWriting();
oIACableType1Results.InitialiseWriting();
oIACableType2Results.InitialiseWriting();
oIACableType3Results.InitialiseWriting();
oIACableType4Results.InitialiseWriting();
ctr_k = 0;
iNoofTapableTransformers = 0;
!For loop for Power Set Points
for (m=1;m<=iNoofPoints;m=m+1){
dVoltageSetPoint = PQVSetPoints.Get(m,3);
dPSetPoint = PQVSetPoints.Get(m,1);
dQSetPoint = PQVSetPoints.Get(m,2);
printf('Running Step : %d of %d (Vset = (%4.3f pu), Pset =
(%4.3f pu), Qset = (%4.3f pu))',m,iNoofPoints, dVoltageSetPoint, dPSetPoint,
dQSetPoint);
if (iNoofPoints > 1){ !Change the Power set points only if any active
triggers are present otherwise run with the existing values
!Change the current value of WTG Triggers to change the power set point
oWTGTrigger = sWTGTriggers.First();
while(oWTGTrigger){
oWTGTrigger:ftrigger = PQVSetPoints.Get(m,1);
oWTGTrigger = sWTGTriggers.Next();
}
!Change the current value of DRPC Triggers to change the Reactive power
set point
oDRPCTrigger = sDRPCTriggers.First();
while(oDRPCTrigger){
oDRPCTrigger:ftrigger = PQVSetPoints.Get(m,2);
oDRPCTrigger = sDRPCTriggers.Next();
}
oXgrid:usetp = PQVSetPoints.Get(m,3);
!Assigning to the results variable
dPsetpoint = PQVSetPoints.Get(m,1);
dQsetpoint = PQVSetPoints.Get(m,2);
}
if(iLdfError){
Error('Initial load flow calculation does not converge! Please set up
basic scenario correctly.');
exit();
}
printf('Running Power Set Point : %d of
%d',m,iNoofPoints);
if (ctr_k = 1){
z=1;
for (oTF2W=sTFGTs.First(); oTF2W; oTF2W = sTFGTs.Next()) {
Tap=oTF2W:c:nntap;
TempTapSetting.Set(z,1,Tap);
z=z+1;
}
for (oTF3W=sTF3Ws.First(); oTF3W; oTF3W = sTF3Ws.Next()) {
Tap=oTF3W:c:n3tap_m;
TempTapSetting.Set(z,1,Tap);
z=z+1;
}
oResults.WriteDraw();
oGridResults.WriteDraw();
oSVCResults.WriteDraw();
oWTGResults.WriteDraw();
oTFWTGResults.WriteDraw();
oTFGTResults.WriteDraw();
oTF3WResults.WriteDraw();
oExportCablesResults.WriteDraw();
oIACableType1Results.WriteDraw();
oIACableType2Results.WriteDraw();
oIACableType3Results.WriteDraw();
oIACableType4Results.WriteDraw();
!oResults.FinishWriting();
if(iSaveScenarios){
!Future: add code to save scenarios with "code created appropriate names" and
discard changes to the existing scenario
}
else {
if (NULL <> oActiveScenario) {!if the scenario is not existing then no need
to back up and save
oBackupScenario.Apply(0); !0 - just apply the data without further
confirmation requests
Delete(oBackupScenario);
oActiveScenario.Save();
}
}
}!End of For loop of Study Cases
printf('===========================================================================
=======');
if (PlotResultsChoice = 1){
!Export all plots to folder
ExportPlots.Execute(strResultsFolderPath);
printf('All Pictures are closed and exported to the folder
%s',strResultsFolderPath);
}