Instructions



Economic Dispatch of Combined Cycle Generators

Programmer’s Guide

Client:

MidAmerican Energy Company

Alan Oneal

ISU Senior Design Team:

May06-07

Noraima Fernandez

Robert Walter

Jeremy Hamilton

Matthew Ellis

Table of Contents

I. Overview of Code Development 1

II. Calling Trees 2

i. ALL_TOTAL_RUN 2

ii. ALL_TOTAL_RUN_SECONDARY 3

III. Global Variables 5

i. Disp_Curve 5

ii. Disp_MU_Lambda 5

iii. Disp_NMU_Lambda 5

iv. Disp_Master_MU 5

v. Disp_Consol_NMU 5

vi. Disp_Num 5

vii. reload 6

viii. hrsg(400, 1000) 6

ix. relationcoe(100, 7) 6

x. strfilename 6

xi. proper_order(100) 6

xii. hour_in 6

xiii. load_to_solve 6

xiv. nmu_num(100) 7

xv. mu_num(100) 7

xvi. solution_array(30, 50000) 7

xvii. power_generators(150) 7

xviii. master_monotonic_table(100, 40000) 7

xix. master_nmu_table(100, 60000) 7

xx. error_list(2, 100) 7

xxi. is_error 8

xxii. is_warning 8

xxiii. array_row 8

xxiv. array_col 8

xxv. hourly_data 8

xxvi. commitment_unique(170) 8

xxvii. data_file(150) 8

xxviii. start_hour 9

xxix. end_hour 9

xxx. gen_data_change 9

xxxi. gen_constraints_change 9

xxxii. commitment_change 9

xxxiii. combined_cycle_change 9

xxxiv. load_data_change 10

IV. Custom Data Structures (Types) 11

i. Type hourly 11

ii. Type Generator 11

iii. Type input_data 14

V. Code Modules (Sub Routines) 15

i. ALL_TOTAL_RUN() 15

ii. Other_Data_Load() 15

iii. Sheet_Wash() 15

iv. Sheet_Hide() 15

v. Get_Filename() 15

vi. Input_Data_File() 15

vii. Data_File_To_Input_Page() 16

viii. Data_Check() 16

ix. Empty_All() 16

x. Gen_Data_Load() 16

xi. Input_To_Commitment() 16

xii. Commitment_Text_Load() 17

xiii. Input_To_Gen_Limits() 17

xiv. Gen_Limits_Load() 18

xv. Week_Load_Data_Input() 18

xvi. Error_generator() 18

xvii. Determine_Chars() 18

xviii. Check_For_NMU() 19

xix. Populate_NMU_Tables() 19

xx. Output_NMU_Tables() 19

xxi. Load_NMU_Data() 19

xxii. Populate_Lambda_Tables() 19

xxiii. Populate_Master_MU_Table(ByVal) 20

xxiv. NMU_Consolidator(ByVal) 20

xxv. Master_NMU(ByVal) 20

xxvi. Output_Check_Tables_Per_Unit() 20

xxvii. Output_Curve_Characteristics() 20

xxviii. Output_Master_MU_Table() 20

xxix. Output_Consolidator() 20

xxx. Populate_Solution_Array(ByVal) 21

xxxi. Retain_Power_Values_MU(ByVal, ByVal) 21

xxxii. Retain_Power_Values_MU_and_NMU(ByVal, ByVal, ByVal) 21

xxxiii. Output_Solution_values(ByVal) 21

xxxiv. Output_All_Solutions() 21

xxxv. Populate_Hourly_Cost_Tables() 21

xxxvi. Output_Hourly_Data() 22

xxxvii. Get_Proper_Order() 22

xxxviii. Fill_Total_Cost_Array() 22

xxxix. Fill_Min_Max_Capability() 22

xl. Fill_Hourly_Lambda_Values() 22

xli. Output_Hourly_Generator_Values() 22

xlii. Output_Hourly_Cost_Values() 22

xliii. Output_Generator_Fuel_Values() 23

xliv. Sheet_Wash_SECONDARY() 23

xlv. Unit_Commitment_Checker() 23

xlvi. Get_Secondary_Name_Order() 23

xlvii. Output_Solution_values_SECONDARY(ByVal) 23

xlviii. Output_Hourly_Data_SECONDARY() 23

xlix. Fill_Total_Cost_Array_SECONDARY() 23

l. Fill_Min_Max_Capability_SECONDARY() 24

li. Fill_Hourly_Lambda_Values_SECONDARY() 24

lii. Output_Hourly_Generator_Values_SECONDARY() 24

liii. Output_Hourly_Cost_Values_SECONDARY() 24

liv. Output_Generator_Fuel_Values_SECONDARY() 24

VI. Independent Code Modules (Sub-Routines) 25

i. Reset_Unit_Commitment() 25

ii. Unit_Commitment_to_Default() 25

iii. Reset_Default_to_Commitment() 25

iv. UC_Checker() 25

VII. General Description of Solution Algorithm 26

VIII. Hand Calculated Example 27

Overview of Code Development

The program was developed by creating and testing individual modules and then calling them in specific sequences in order to produce output. The Visual Basic code can be viewed by selecting the Tools/Macro/Visual Basic Editor (alt + F8) in the Excel workbook. The security setting must be set to medium or below in order to view or run macros. This setting can be changed by selecting Tools/Macro/Security, choosing the security level, and then closing and re-opening the workbook. Once in the Visual Basic editor, any module may be selected; however, it is recommended to start with the main module called ALL_TOTAL_RUN(). Click Sheet 1. ALL_TOTAL_RUN() in the menu so that it is highlighted. While highlighted, click the Edit button on the right. It is this module that calls the smaller modules in a specified order to produce the output. To skip directly to any of the other modules use the scroll down list in the upper-right corner of the editor.

The overall structure of the Visual Basic code is set up much like the actual user interface for the software. There are two main parts: primary and secondary. Both parts are completely separate macros. All modules that are entirely dedicated to the secondary menu are denoted by a _SECONDARY() in their module title. There are also two main modules for the program. As stated above, the primary main menu is called ALL_TOTAL_RUN() and the secondary main menu is called ALL_TOTAL_RUN_SECONDARY(). Besides the two main macros there are also numerous independent macros which will be covered in greater detail in Section VI of the programmer’s guide.

Throughout the programmer’s guide, there are brief descriptions of each section of the code. For a better understanding of each module, the project team recommends that the user read the comments embedded throughout the code.

Calling Trees

This section gives the order for which the modules are called for both the main and the secondary program.

1 ALL_TOTAL_RUN

Other_Data_Load

Sheet_Wash

Sheet_Hide

Get_Filename

Input_Data_File

Data_File_To_Input_Page

Data_Check

Empty_All

Gen_Data_Load

Input_To_Commitment

Commitment_Text_Load

Input_to_Gen_Limits

Gen_Limits_Load

Week_Load_Data_Input

Error_generator

Determine_Chars *

Check_For_NMU

Populate_NMU_Tables

Master_NMU

Output_NMU_Tables **

Load_NMU_Data ***

Output_NMU_Tables

Determine_Chars

Populate_Lambda_Tables

Populate_Master_MU_Table

NMU_Consolidator

Output_Check_Tables_Per_Unit **

Output_Curve_Characteristics **

Output_Master_MU_Table **

Output_Consolidator **

Populate_Solution_Array

Retain_Power_Values_MU_and_NMU Retain_Power_Values_MU

Output_Solution_Values

Output_All_Solutions **

Populate_Hourly_Cost_Tables

Output_Hourly_Data

Get_Proper_Order

Fill_Total_Cost_Array

Fill_Min_Max_Capability

Fill_Houly_Lambda_Values

Output_Hourly_Generator_Values

Output_Hourly_Cost_Values

Output_Generator_Fuel_Values

* Executed if no errors exist

** Executed upon user request on input page

*** Executed upon user request, but must be run the first time the program is used or whenever NMU generator limits change

2 ALL_TOTAL_RUN_SECONDARY

Sheet_Wash_SECONDARY

Sheet_Hide

Get_Filename ^

Input_Data_File ^

Data_File_To_Input_Page ^

Data_Check ^

Gen_Data_Load ^

Unit_Commitment_Checker ^^^

Commitment_Text_Load ^^^

Get_Secondary_Name_Order ^^^

Input_to_Gen_Limits ^^

Gen_Limits_Load ^^

Week_Load_Data_Input ^^^^^

Error_generator

Determine_Chars

Check_For_NMU

Populate_NMU_Tables ^^^^

Output_NMU_Tables ^^^^

Load_NMU_Data

Output_NMU_Tables

Determine_Chars

Populate_Lambda_Tables

Populate_Master_MU_Table

NMU_Consolidator

Output_Check_Tables_Per_Unit

Output_Curve_Characteristics

Output_Master_MU_Table

Output_Consolidator

Populate_Solution_Array

Retain_Power_Values_MU_and_NMU

Retain_Power_Values_MU

Output_Solution_Values_SECONDARY

Output_All_Solutions

Populate_Hourly_Cost_Tables

Output_Hourly_Data_SECONDARY

Get_Proper_Order

Fill_Total_Cost_Array_SECONDARY

Fill_Min_Max_Capability_SECONDARY

Fill_Houly_Lambda_Values_SECONDARY

Output_Hourly_Generator_Values_SECONDARY

Output_Hourly_Cost_Values_SECONDARY

Output_Generator_Fuel_Values_SECONDARY

^ Executed if user specifies that the Generator Data txt File has changed

^^ Executed if user specifies that the Generator Constraints worksheet has changed

^^^ Executed if user specifies that the Unit Commitment worksheet has changed

^^^^ Executed if user specifies that the Combined Cycle Data worksheet has changed

^^^^^ Executed if user specifies that the Generation Requirement worksheet has changed

Global Variables

1 Disp_Curve

1. Data Type: Boolean

2. Description: Disp_Curve is set by the user if they wish for the curve characteristics (“ABC Checker” worksheet) to be displayed when the program is run.

2 Disp_MU_Lambda

1. Data Type: Boolean

2. Description: Disp_MU_Lambda is set by the user if they wish for the MU Lambda table to be displayed when the program is run.

3 Disp_NMU_Lambda

1. Data Type: Boolean

2. Description: Disp_NMU_Lambda is set by the user if they wish for the NMU Lambda table to be displayed when the program is run.

4 Disp_Master_MU

1. Data Type: Boolean

2. Description: Disp_Master_MU is set by the user if they wish for the Master MU table to be displayed when the program is run.

5 Disp_Consol_NMU

1. Data Type: Boolean

2. Description: Disp_Consol_NMU is set by the user if they wish for the consolidated NMU table to be displayed. This consolidated NMU table is basically the master NMU table.

6 Disp_Num

1. Data type: Integer

2. Description: Disp_Num is used to retain the value of the hour that the user would like to see the if they chose “TRUE” for Displaying the MU or NMU Lambda Tables.

7 reload

1. Data type: Boolean

2. Description: reload is used by the secondary program as a flag whether the HRSG vs. CT relationship has been changed since last run. If reload=TRUE then the NMU lambda values are recalculated.

8 hrsg(400, 1000)

1. Data Type: Single two dimensional array

2. Description: Stores HRST vs. CT relationship data.

9 relationcoe(100, 7)

1. Data Type: Single two dimensional array

2. Description: Stores the 7th order polynomial coefficients for HRSG vs. CT relationship.

10 strfilename

1. Data Type: String

2. Description: Used to retain the filename of the input file as a string.

11 proper_order(100)

1. Data Type: String array

2. Description: Stores the generator names in the order they appear on the “Commitment” worksheet. Used so output is listed in the same order.

12 hour_in

1. Data Type: Integer

2. Description: Keeps track of the current hour (1-168) during the solution process.

13 load_to_solve

1. Data Type: Single

2. Description: Keeps track of the current load to solve for.

14 nmu_num(100)

1. Data Type: Integer array

2. Description: Can handle up to 100 NMUs used to retain values that correspond to the NMU's input into the program IE: power_generators(nmu_num(0)) is the first NMU

15 mu_num(100)

1. Data Type: Integer array

2. Description: Can handle up to 100 MUs to retain values that correspond to the MU’s input into the program IE: power_generators(mu_num(0)) is the first MU

16 solution_array(30, 50000)

1. Data Type: Single two dimensional array

2. Description: Used to store solution values such as total power, total cost, nmu 1, nmu 2…

17 power_generators(150)

1. Data Type: Generator

2. Description: Array of all generators under study up to 150 generators.

18 master_monotonic_table(100, 40000)

1. Data Type: Single two dimensional array

2. Description: lambda, total power, total cost. Can handle 100 generators with 40,000 lambda values

19 master_nmu_table(100, 60000)

1. Data Type: Single two dimensional array

2. Description: Master nmu array used by the consolidator module

20 error_list(2, 100)

1. Data Type: String two dimensional array

2. Description: Array which holds location of error and a description of the error. Able to handle 100 errors. Indices are updated by the array_row, and array_col variables.

21 is_error

1. Data Type: Boolean

2. Description: Variable set to true if an error parameter is violated. This generates an entry into the error_list array, and the program terminates until the errors are corrected. The user is prompted to look at the “Errors” worksheet and correct the error.

22 is_warning

1. Data Type: Boolean

2. Description: Variable set to true if a warning parameter is violated. This generates an entry into the error_list array, however, the program does not terminate. After execution, the user is notified of the warning on the “Errors” worksheet.

23 array_row

1. Data Type: Integer

2. Description: Index used to increment the error location column of the error_list.

24 array_col

1. Data Type: Integer

2. Description: Index used to increment the error description column of the error_list.

25 hourly_data

1. Data Type: hourly

2. Description: Stores commitment code and load value for a single hour.

26 commitment_unique(170)

1. Data Type: String array

2. Description: Array used to store unique commitment patterns over the 168 hour duration.

27 data_file(150)

1. Data Type: input_data array

2. Description: Array of all generators contained in the input file up to 50 generators.

28 start_hour

1. Data Type: Integer

2. Description: Index used to hold the value defined by the user on the secondary menu in the “Starting Hour” field. This value is the beginning of the range of hours that the software will calculate dispatch solutions.

29 end_hour

1. Data Type: Integer

2. Description: Index used to hold the value defined by the user on the secondary menu in the “Ending Hour” field. This value is the end of the range of hours that the software will calculate dispatch solutions.

30 gen_data_change

1. Data Type: Boolean

2. Description: Index used to hold the user defined option for whether the Generator Data txt file has changed or not. Used in the secondary program to save time by not reloading the entire sheet if it hasn’t changed.

31 gen_constraints_change

1. Data Type: Boolean

2. Description: Index used to hold the user defined option for whether the “Generator Constraints” worksheet has changed or not. Used in the secondary program to save time by not reloading the entire sheet into arrays if it hasn’t changed.

32 commitment_change

1. Data Type: Boolean

2. Description: Index used to hold the user defined option for whether the “Unit Commitment” worksheet has changed or not. Used in the secondary program to save time by not reloading the entire sheet into arrays if it hasn’t changed.

33 combined_cycle_change

1. Data Type: Boolean

2. Description: Index used to hold the user defined option for whether the “Combined Cycle Data” worksheet has changed or not. Used in the secondary program to save time by not reloading the entire sheet into arrays if it hasn’t changed.

34 load_data_change

1. Data Type: Boolean

2. Description: Index used to hold the user defined option for whether the “Load” or generation requirement worksheet has changed or not. Used in the secondary program to save time by not reloading the entire sheet into arrays if it hasn’t changed.

Custom Data Structures (Types)

1 Type hourly

Description: Stores commitment codes and load values for each of the 168 hours.

1. commitment_text(170)

a. Data Type: String array

b. Description: Stores commitment code for each hour of the 168 total hours

2. load_to_solve(170)

a. Data Type: Integer array

b. Description: Stores the load value for each hour of the 168 total hours

3. lambda_values(170)

a. Data Type: Integer array

b. Description: Stores the lambda values for each of the generators for all of the 168 total hours

4. total_cost(170)

a. Data Type: Integer array

b. Description: Stores the calculated total cost of generation for all of the 168 total hours

5. min_capability(170)

a. Data Type: Integer array

b. Description: Stores the minimum generation capability (MW) for each of the generators for all of the 168 total hours

6. max_capability(170)

a. Data Type: Integer array

b. Description: Stores the maximum generation capability (MW) for each of the generators for all of the 168 total hours

2 Type Generator

Description: Stores generator data for a single unit

1. name

a. Data Type: String

b. Description: Stores the name of the generator.

2. gen_min(170)

a. Data Type: Integer array

b. Description: Stores the generator’s minimum generation value for each hour over a 168 hour period.

3. gen_max(170)

a. Data Type: Integer array

b. Description: Stores the generator’s maximum generation value for each hour over a 168 hour period.

4. nmu

a. Data Type: Boolean

b. Description: True if generator exhibits non-monotonic characteristics

5. range_min(12)

a. Data Type: Integer array

b. Description: Stores the low end of each range of operation.

6. range_max(12)

a. Data Type: Integer array

b. Description: Stores the high end of each range of operation.

7. lambda_min

a. Data Type: Single array

b. Description: Stores the low end lambda.

8. lambda_max

a. Data Type: Single array

b. Description: Stores the high end lambda.

9. a_value(12)

a. Data Type: Single array

b. Description: Stores the “a” value for each range of operation.

10. b_value(12)

a. Data Type: Single array

b. Description: Stores the “b” value for each range of operation.

11. c_value(12)

a. Data Type: Single array

b. Description: Stores the “c” value for each range of operation.

12. ihr_value(12)

a. Data Type: Single array

b. Description: IHR value corresponding to the MW value in .range_value array.

13. range_value(12)

a. Data Type: Single array

b. Description: MW value corresponding to the IHR value in .ihr_value array.

14. io_value(12)

a. Data Type: Single array

b. Description: I/O value corresponding to the MW value in range_value array.

15. fuel_cost

a. Data Type: Single

b. Description: Fuel price for each unit ($/MBtu)

16. power_lambda_table(3, 4000)

a. Data Type: Single two-dimensional array

b. Description: Lambda table which includes lambda value, power, and total cost.

17. commitment(170)

a. Data Type: Integer array

b. Description: Stores the generator’s commitment value for each hour over a 168 hour period.

18. output(170)

a. Data Type: Integer array

b. Description: Stores the each generator’s MW output level for each hour over a 168 hour period

19. hourly_cost(170)

a. Data Type: Single array

b. Description: Stores the each generator’s cost ($) for each hour over a 168 hour period

20. up_time

a. Data Type: Integer array

b. Description: Stores the user defined minimum time required for each generator before the unit can be dispatched

21. down_time

a. Data Type: Integer array

b. Description: Stores the user defined minimum time required for each generator before the unit can be shut down

22. generator_sum

a. Data Type: Integer array

b. Description: Stores number of hours each unit is committed; is used to delete or add units to the output pages

3 Type input_data

Description: Stores generator data from the input file which is then loaded into a generator type structure for each unit.

1. name

a. Data Type: String

b. Description: Stores the name of the generator.

2. fuel_price

a. Data Type: Single

b. Description: Fuel price for each unit ($/MBtu).

3. io_value

a. Data Type: Integer

b. Description: Stores the initial I/O value needed to compute the a,b,c coefficients.

4. mw_points(20)

a. Data Type: Integer String

b. Description: Stores the MW values corresponding to the IHR values in ihr_points.

5. ihr_points(20)

a. Data Type: Single array

b. Description: Stores the IHR values corresponding to the MW values in mw_points.

Code Modules (Sub Routines)

1 ALL_TOTAL_RUN()

Description: ALL_TOTAL_RUN() is the main module which calls all the other smaller modules. It is the very last module contained in the visual basic editor.

2 Other_Data_Load()

Description: Other_Data_Load() accesses the “Display Sheets” portion of the “Input” worksheet. It gathers user input and sets the following global variables based on if the user wants to view the tables: Disp_Curve, Disp_MU_Lambda, Disp_NMU_Lambda, Disp_Master_MU, Disp_Consol_NMU, and reload. If the user chooses to “TRUE” for either Disp_Master_MU or Disp_Consol_NMU, the user is prompted to enter which hour they would like the tables displayed for (1-168).

3 Sheet_Wash()

Description: Sheet_Wash() is called in order to erase old data from the last run from certain sheets in the workbook.

4 Sheet_Hide()

Description: Sheet_Hide() temporarily hides a number of sheets which are then chosen by the user if they wish to view them or not after the program runs. The sheets can be viewed by choosing “TRUE” in the display sheets cells on the “Input” worksheet.

5 Get_Filename()

Description: Get_Filename() prompts the for the location of the input file to use. The location is then loaded into a string so that it is accessible by the program.

6 Input_Data_File()

Description: Input_Data_File() opens the input file from the specified path from the Get_Filename module. It loads the data into the data_file array and then closes the input file.

7 Data_File_To_Input_Page()

Description: Data_File_To_Input_Page() prints the data from the data_file array onto the left side of the “Input” page. This data includes all the necessary data which was contained in the input file.

8 Data_Check()

Description: Data_Check() provides some preliminary input data verification checks. The following conditions are verified:

• No two units have the same name

• Missing fuel price, I/O value, MW and IHR points

• MW points must be integer values

In the event of an error, the global variables, error_list, error_row, error_col, and is_error are updated, the program stops, and an error is displayed on the “Errors” worksheet.

9 Empty_All()

Description: Empty_all() resets a number of global variables to their default values (0’s for integer and single types, and empties the contents of strings.

10 Gen_Data_Load()

Description: Gen_Data_Load() loads the generator data from the left side of the “Input” page into the power_generators array.

11 Input_To_Commitment()

Description: Input_To_Commitment() synchronizes the generators from the current input file to the generators listed in the “Commitment” worksheet. If a generator is not currently on the input file but is listed in the commitment table, that listing is no longer needed and therefore erased. If a new generator is added to the input file that has not previously been added to the commitment table, it is added to the end of the commitment table. In the event of an error, the global variables, error_list, error_row, error_col, and is_error are updated, the program stops, and an error message is then generated urging the user to input 168 hours of status codes for the new generator. If missing or invalid status codes (anything other than 1 or 0) are entered into the table, an error message is generated urging the user to change the codes.

12 Commitment_Text_Load()

Description: Commitment_Text_Load() loops through every hour of the 168 hour commitment table and loads the commitment code for that hour into the hourly_mitment_text array. This code specifies which units are on during a specified hour. It then loops through the hourly_mitment_text array to find the unique patterns. The unique patterns are then loaded into the commitment_unique array. The idea is to solve for all the hours that have the same commitment pattern at the same time thus reducing program run-time. Commitment_Text_Load() then loads commitment data for the (i)th unit and (j)th hour into power_generators(i).commitment(j).

13 Input_To_Gen_Limits()

Description: Input_To_Gen_Limits() is similar to Input_To_Commitment() in that it synchronizes the generators in the input file with the generators displayed in the min/max table. If a new generator is added to the input file but is not currently on the “Gen Limits” page, then it is added to the bottom of the min/max table. If a generator has been removed from the input page but still exists in the min/max table, the generator will be removed from the table. Input_To_Gen_Limits() also includes the following error checks:

• Missing min/max values throughout the 168 hour period

• Invalid (non integer) min/max values throughout the 168 hour period

• Gen min must be less than gen max

In the event of an error, the global variables, error_list, error_row, error_col, and is_error are updated, the program stops, and an error message is displayed on the “Errors” worksheet.

14 Gen_Limits_Load()

Description: Gen_Limits_Load() loops through the 168 hours of min/max values and loads unit (i)’s min and max generation value into power_generators(i).gen_min(j) and power_generators(i).gen_max(j). A final error check is made to ensure that each min and max value is indeed feasible given each unit’s MW operating range on the input file. Both power_generators arrays are looped through for the 168 hour period and checked against power_generators(i).range_value initial and final values. If gen min > initial range value and gen max < final range value. The min and max values are valid and no errors will be displayed. However in the event of an error, the global variables, error_list, error_row, error_col, and is_error are updated, the program stops, and an error message is displayed on the “Errors” worksheet telling the user that the current min or max values are invalid.

15 Week_Load_Data_Input()

Description: Week_Load_Data_Input() selects the “Load Data” worksheet and imports the 168 load values into hourly.load_to_solve array. For each hour (j), the minimum and maximum generation is summed based on the commitment pattern for (i) units in the (j)th hour given in the power_generators(i).commitment(j) array. An error message is displayed on the “Errors” worksheet urging the user to modify the load value if either the load value for a specific hour is invalid ( ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download