Turbine output control

  • pgilman
More
12 Jul 2022 17:02 #11248 by pgilman
Replied by pgilman on topic Turbine output control
Hi Mohammed,

The csvread() function reads data from the CSV file as a 2-D array. In your case, you can use a script like the following to read data from the array:
variable_costs  =  [ [ 0 ], [ 3.5 ], [ 3.61 ], [ 3.72 ], [ 3.83 ], [ 3.94 ], [ 4.06 ], [ 4.19 ], [ 4.31 ], [ 4.44 ], [ 4.58 ], [ 4.72 ], [ 4.86 ], [ 5.01 ], [ 5.16 ], [ 5.32 ], [ 5.48 ], [ 5.64 ], [ 5.81 ], [ 5.99 ], [ 6.17 ], [ 6.36 ], [ 6.55 ], [ 6.75 ], [ 6.95 ], [ 7.16 ] ];
 
 outln(#variable_costs);
 outln(#variable_costs[0]);
 
 production = get('cf_energy_net'); // kWh/year
 
 for (i=0; i<#variable_costs; i++ )
 {
    expenses[i] = variable_costs[i][0] * production[i];
 }
 
 outln(expenses);

If you want csvread() to read the data as a single array, you could modify your CSV file to store the data as a row of comma-separated values instead of a column of values. For example if the file test.csv contains the following:
0,3.5,3.61,3.72,3.83,3.94,4.06,4.19,4.31,4.44,4.58,4.72,4.86,5.01,5.16,5.32,5.48,5.64,5.81,5.99,6.17,6.36,6.55,6.75,6.95,7.16

Then you could use the following script to read the file:
test = csvread( cwd()+'/test.csv', {'numeric'=true, 'table'=false});

outln(test);
 
production = get('cf_energy_net'); // kWh/year
 
for (i=0; i<#test[0]; i++ )
{
    expenses[i] = test[0][i] * production[i];
}
 
outln(expenses);

The LK sample script csv-functions.lk has some other examples: github.com/NREL/SAM/tree/develop/samples/LK%20Scripts%20for%20SAM

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

  • Mohammed Alfailakawi
More
13 Jul 2022 13:48 #11255 by Mohammed Alfailakawi
Replied by Mohammed Alfailakawi on topic Turbine output control
Dear Mr. Gilman,

My true apologies for this being a never ending quest, but there is still something wrong..

When I try what you suggested lastly, i.e. all the array values separated by a comma and placed in the first cell of the CSV file forming a row of comma separated values, LK only reads the first value of 0 ..

Further, I tried to separate the values by a comma using (text to columns - delimited - comma) function from the Data tap in Excel, however, it gives the following (seems like an array placed at the first index of the main array):
AEG  =  [ [ 0, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000, 284000000 ] ]

and of course the same error message appears:  
access violation: expected numeric, but found array

Please have a super quick look on my CSV file and the very simple code:

path = 'C:/Users/Mohammed/Desktop/LCOE Calculation' + '/';


AEG = csvread (path + 'AEG.csv', {'numeric' = true, 'table' = false});
variable_costs = csvread (path + 'variable M&O costs.csv', {'numeric' = true, 'table' = false});  

for  (i = 0 ; i<26; i++)

{
OM_production_capacity_expenses = variable_costs * AEG;  

         simulate ();         }
   
   outln(OM_production_capacity_expenses);     
 


of course when  I set i= 26, this code gives error array index out of bound, while when I reset it to i=1, it goes back to error of access violation: expected numeric, but found array..

Thanks for your efforts and time.

Regards,
Mohammed 


         

Please Log in or Create an account to join the conversation.

  • pgilman
More
13 Jul 2022 18:14 #11256 by pgilman
Replied by pgilman on topic Turbine output control
Hi Mohammed,

In your code, the variables AEG and variable_costs are two-dimensional arrays, each with one row of data. To read the values in the array, you must provide two array indexes in brackets. Your loop should look like this:
for  (i = 0 ; i<26; i++)
{
    OM_production_capacity_expenses[i] = variable_costs[0][i] * AEG[0][i];  
}

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum