You are on page 1of 5

int ierr,iexist; }

int irepeat; if(ierr) exit(); [EJECUCION DE CIERRE POR ERROR]

set Sloads,BusBars,allBars,OldMons; !End of Check input data


======================================
object Load;

double stepval;

double stepvalold;
Ldf = GetCaseCommand('ComLdf');
object mon,busbar;

object monid,GrB,ViPg,Plot;
stepval=1;
object Ldf;
stepvalold=1;
object aLoad;
ierr=0;
int nLoads,iLoad;

int nBusBars;
!Get initial settings about tap changing and flat
int tap_step, tap_max, flat_opt, topo_opt;! initial
start. Change if necessary. [GUARDAR DATOS DEL
load flow settings
FLUJO DE POTENCIA]

tap_step = Ldf:itapopt; !stepped or direct


Sloads = SEL.AllLoads(); (ALMACENA LAS CARGAS
tap_max = Ldf:imaxtstep; !max number of steps
DEL SET SELECT)
flat_opt = Ldf:iopt_noinit; !flat start option
BusBars = SEL.AllBars(); (ALMACENA LAS BARRAS
DEL SET SELECT) topo_opt = Ldf:iopt_notopo; !topology option
allBars = AllRelevant('*.StaBar,*.ElmTerm'); [ASIGNAR LOS VALORES PARA PV]
(ALMACENA TODOS LOS BUSBAR DE SC) Ldf:itapopt = 1;
if(clear) {ClearOutput();} [input] Ldf:imaxtstep = 1;

Ldf:iopt_noinit = 1;
!Check input data Ldf:iopt_notopo = 1;
=========================================
==== [REVISAR LOS DATOS DE ENTRADA] !printf('%f %f %f %f',
Ldf:itapopt,Ldf:imaxtstep,Ldf:iopt_noinit,Ldf:iopt_
ierr=0; notopo);
nLoads=Sloads.Count(); [CONTAR LA CANTIDAD DE
CARGAS]
!Creating IntMon objects for all busbars in the
nBusBars= BusBars.Count(); [CONTAR LA CANTIDAD
result object
DE BUSBAR]
OldMons=Results.GetContents(); [GUARDAR LOS
if(nLoads<1){ INTMON ANTIGUOS]

Error('No load in the general selection.'); ! make sure that Xvar points to this
ierr=1; [ERROR POR NO HABER CARGAS] mon = OldMons.FirstFilt('Xvar.IntMon'); [SI EXISTE
} EL IntMont ‘Xvar’, guardarlo]

if(nBusBars<1){ if (mon=NULL) { [si no existe, crearlo]

Error('No busbar in the general selection.'); mon = Results.CreateObject('IntMon', 'Xvar');

ierr=1; [ERROR POR NO HABER BUSBARS] }


if (mon) {

mon:obj_id = this; [asignar el DPL como objeto GrB = GetGraphBoard(); [objeto gráficos]
en IntMon]
if (GrB=NULL) { output('No Graphics Board open');
mon.AddVar('b:Ptot'); [asignar la variable] exit(); }

} else {

Error('Failed to create Xvar variable monitor in ! creating plots for selected busbars
result-object');
Plot = NULL; [objeto Plot vacio inicialmente]
exit();
ViPg = GrB.GetPage(this:loc_name,1); [Crear una
} página]

if (ViPg) { [si existe la primera página]

for (busbar=allBars.First(); busbar; ViPg.SetResults(Results); [Asigna los resultados


busbar=allBars.Next()) { predeterminados]

iexist=0; Plot=ViPg.GetVI('u','VisPlot',1); [Crear VisPlot]

mon=OldMons.Firstmatch('IntMon'); [primer if (Plot) {


IntMon]
Plot:use_x=1; [Dar escala de página en X]
while(mon.and.iexist=0){
Plot.SetXVar(this,'b:Ptot'); [Establece la variable en el eje X,
sino asume el tiempo]
monid=mon:obj_id; [obtiene objeto del
IntMon] Plot.SetAdaptY(1); [Adaptar escala]

if (monid=busbar){ [compara el objeto si es la for (busbar=BusBars.First(); busbar;


barra del for] busbar=BusBars.Next()) {

iexist=1; Plot.AddVars(busbar,MonDefault:vars:0);
[Asignar variables al subplot]
}
}
mon=OldMons.Nextmatch();
} [CIERRA IF DEL PLOT]
} [FIN DEL WHILE AL ENCONTRAR LA BARRA]
} [CIERRA IF DE LA PAGINA]
if (iexist=0){ [al encontrar la barra]
if (ViPg=NULL.or.Plot=NULL) {

mon=Results.AddCopy(MonDefault,MonDefault:lo Warn('Failed to create plot, continue


c_name); calculation ...');

[copia el objeto MonDefault a Results] }

mon:obj_id=busbar; [le asigna la barra] Echo.Off(); [no mostrar cálculos]

} [FIN DEL FOR DE BARRAS] !Store Initial Scaling Factors for all Loads
[almacena los fact inic]
[objeto adaptador de paso]
nLoads=Sloads.Count(); [contar cargas]
Step:valstart=1;
if(nLoads<1) exit(); !no load selected in the
Step:valstop=9999; general selection

Step:stepmin=0.001; InitLoadsSc.Resize(nLoads); [redefinir parámetro


del vector]
Step:p_resvar=Results;
InitLoadsPf.Resize(nLoads); [redefinir parámetro
Step.Init();
del vector]
Sloads.SortToName(0); [ordenar según nombre] output('Total initial active Power =Ptot MW');

aLoad=Sloads.First(); [primera carga]

iLoad=1; stepval=1;

while(aLoad){ stepvalold=1;

InitLoadsSc.Set(iLoad,aLoad:scale0); [setea los


fact esc]
do{
InitLoadsPf.Set(iLoad,aLoad:coslini); [setea los
!Scaling Loads: [escalamiento de cargas]
cos fi]
Load=Sloads.First(); [primera carga]
aLoad=Sloads.Next(); [pasa a la siguiente carga]
Ptot=0;
iLoad +=1;

}
while(Load){ [dando y cambiando esc con do]

!Initial Loading [carga inicial] Load:scale0=Load:scale0*stepval/stepvalold;

Load=Sloads.First(); [primera carga] Ptot=Ptot+Load:plini*Load:scale0;

Ptot=0; Load=Sloads.Next();

while(Load){ }

Load:coslini = powerfactor; [input, cos fi] output('Total active Power =Ptot MW');

Load:pf_recap = indcap; [input, ind o cap] ierr=Ldf.Execute(); [ejecuta 0, error 1]

Ptot=Ptot+Load:plini*Load:scale0; [potencia
inicial] if (ierr<0.5){
Load=Sloads.Next(); [siguiente carga] stepvalold=stepval; [el indicador actual se
} guarda en el antiguo]

output('Total active Power =Ptot MW'); Load=Sloads.First(); [primera carga]

irepeat=Step.GetNextStep(); [Si se genera, da 0]

stepvalold=scaleini; [input, escalamiento inicial if (irepeat=0){


dado] output('Load Flow calculated with
stepval=scaleini; [input, escalamiento inicial dado] trigger=stepval');

Results.WriteDraw(); [escribe los resultados actuales


y actualiza gráficos]
output('Stepval: =stepval'); [mostrar el
}
escalamiento inicial]
stepval=Step.GetNextIndex(); [se guarda el paso
Load=Sloads.First(); [primera carga]
generado]
while(Load){

Load:scale0=stepval; [asignar escalamiento


}
inicial]
}while(ierr<0.5); [para seguir ejecutando]
Ptot=Ptot+Load:plini*Load:scale0; [carga inicial]

Load=Sloads.Next();
Echo.On();
}
if (ierr=2) Ldf.Execute(); ! Ensure error message }
printed

!Restore load flow settings [restaurando valores]


if (ierr=1){ [ya no converge el flujo]
printf('Restoring initial load flow settings.');
Load=Sloads.First(); [primera carga]
Ldf:itapopt = tap_step;
Ptot=0;
Ldf:imaxtstep = tap_max;
stepvalold=stepval;
Ldf:iopt_noinit = flat_opt;
stepval=Step.GetLastIndex(); [se guarda el último
paso generado] Ldf:iopt_notopo = topo_opt;

while(Load){

Load:scale0=Load:scale0*stepval/stepvalold;

Ptot=Ptot+Load:plini*Load:scale0;

Load=Sloads.Next();

Ldf:itapopt=0;

ierr=Ldf.Execute();

output('Last load flow calculation at Ptot=Ptot


MW');

Ldf:itapopt=tap_step;

if (Plot) { [ajustar ploteo]

Plot.SetScaleX();

Plot.SetScaleY();

!Restore Initial Scaling Factors for all Loads


[restaurando valores]

printf('Restoring initial scaling factors.');

Sloads.SortToName(0);

iLoad=1;

aLoad=Sloads.First();

while(aLoad){

aLoad:scale0=InitLoadsSc.Get(iLoad);

aLoad:coslini=InitLoadsPf.Get(iLoad);

iLoad +=1;

aLoad=Sloads.Next();

You might also like