Knowledge Base

Contingency Analysis and Changing Data with Filters

Auxiliary File: CTG_Filters.aux

PowerWorld Case: B7OPF.pwb

PowerWorld Oneline: B7OPF.pwd

Output Files: CTG_Filters_BeforeReport.txtCTG_Filters_AfterReport.txt

(Right-click on the above files and select Save Target As to save them to your computer.)

A script can be used to perform contingency analysis. In this example we will perform contingency analysis on a 7-bus system and produce a report. Next, we will change some data using a filter to select the data to be changed. Finally, we will perform contingency analysis after the changes and produce a second report.

The auxiliary file contains two data sections; the first defines filters for selecting branches and generators, while the second (addCTG) defines a list of contingencies to use in contingency analysis. There are three scripts, ContingencyBefore, ChangeData, and ContingencyAfter. ContingencyBefore and ContingencyAfter perform contingency analysis and create an automatic report. ChangeData changes the MVA branch limits and generator max MW output limits for generators and branches meeting criteria defined in the filters.

The first data section defines two filters. We will use a filter to select the branches with MVA limits above 99, and a second filter to select the generators with a maximum MW output above 450.

These are the contingencies used in the contingency analysis, defined in the addCTG data section:

Open Generator 1 Open Branch 6-7
Open Branch 1-3 Open Generator 4
Open Branch 2-5 Open Generator 2
This ChangeData script demonstrates different ways of selecting data. First it selects all branches meeting the criteria in the branch filter using the SelectAll command. For the generators, we simply apply the generator filter to select the data.

The ContingencyBefore and ContingencyAfter scripts solve the power flow and then do contingency analysis using the six contingencies defined in the addCTG data section. They then produce an automatic report using the CTGProduceReport command. Some of the other example scripts demonstrate how to output custom data to a file.

CTG_Filters.aux:
//This script does contingency analysis, then applies filters
//to change some data, and then does contingency analysis again.

DATA (FILTER, [ObjectType, FilterName, FilterLogic, FilterPre])
{
//Create two filters - one for lines and one for generators
//Since these filters are not already defined in the case,
//PowerWorld may ask if you want to define them.
//Press "Yes".
//The first filter:

//Element     Filter name    Criteria    Always?
//------------------------------------------------
BRANCH       "BranchFilter"  "AND"        "no"

<SUBDATA CONDITION>
//The condition for BranchFilter
LineLimMVA > 99
</SUBDATA>
//Now, the second filter:

//Element    Filter name    Criteria    Always?
//------------------------------------------------
GEN         "GenFilter"    "AND"         "no"

<SUBDATA CONDITION>
//The condition for GenFilter: Generator Max.
//Output > 450 MW
GenMWMax > 450
</SUBDATA>
}

DATA addCTG(Contingency, [CTGlabel, CTGskip])
{
//Add a set of contingencies, named "Contingencies"
//Since this set of contingencies doesn’t exist in the case
//yet, PowerWorld will ask you if you want to define them.
//Say  "Yes"

//CTG name          skip?
//--------------------------
Contingencies       NO

<SUBDATA CTGElement>
//Here is the list of contingencies.
//"" for Model Criteria is required
//in order to enter a status.
//Action Model Criteria Status

//Action          Model Criteria      Status
//-----------------------------------------
"GEN 1 1 OPEN"           ""          ALWAYS
"BRANCH 1 3 1 OPEN"      ""          ALWAYS
"BRANCH 2 5 1 OPEN"      ""          ALWAYS
"BRANCH 6 7 1 OPEN"      ""          ALWAYS
"GEN 4 1 OPEN"           ""          ALWAYS
"GEN 2 1 OPEN"           ""          ALWAYS

</SUBDATA>
}

SCRIPT ContingencyBefore
{
//Do the 1st contingency analysis, produce the 'before'
//report. First, solve the power flow. We must enter
//PowerFlow mode.
EnterMode(PowerFlow);
//Solve the power flow.
SolvePowerFlow;
//Do contingency analysis.
//We must enter the Contingency mode.
EnterMode(Contingency);
//Solve all the contingencies entered earlier.
CTGSolveAll;
//Make an automatic contingency report. Store the report
//in the file "CTG_Filters_BeforeReport"
//in the current directory.
CTGProduceReport("CTG_Filters_BeforeReport");
}

SCRIPT ChangeData
{
//Change some data.
//To change data we must be in the edit mode.
Entermode(Edit);
//Select all branches meeting the criteria in the BranchFilter
SelectAll(BRANCH, "BranchFilter");
//Set all of the selected branch MVA limits to 99 MVA.
SetData(BRANCH, [LineLimMVA], [99], SELECTED);
//Unselect the branches.
UnSelectAll(BRANCH, BranchFilter);
//Here is a different way to change data:
//Use the SetData command with these arguments:
//SetData(Object, [Field], [New Value], "Filter name to use");
SetData(GEN, [GenMWMax], [399], "GenFilter");
}

Script ContingencyAfter
{
//Do the 2nd contingency analysis and produce the 'after' report
//Make sure the power flow still converges.
//Change to powerflow mode.
Entermode(PowerFlow);
//Solve the power flow.
SolvePowerFlow;
//Now enter contingency mode to do contingency analysis.
EnterMode(Contingency);
//Solve all the contingencies
CTGSolveAll;
//Produce the automatic contingency report, store it in the
//file "CTG_Filters_AfterReport" in the current directory.
CTGProduceReport("CTG_Filters_AfterReport");
}

Tags: ,,,

June 28, 2012