- Posts: 2
Turbine output control
- h.johnson
- Topic Author
Less
More
19 Sep 2018 06:38 #6440
by h.johnson
Turbine output control was created by h.johnson
Hi SAM team,
I'm working on a LK script to change some simulation inputs and I'm wondering if it's possible to change the turbine output fraction to an array. In my script, it sets the 'ui_disp_1_turbout' to hourly values over a year with no error, but after simulating, it shows that the turbine output fraction does not follow the assigned array, and just stays as a single value. Attached is an image of part of the code.
If this is not possible, is there a way to best mimic an off grid CSP system to follow the demand profile?
Lastly, is there a quicker way to do element-wise multiplication/ division between arrays or with a single value in LK other than using a loop?
Thanks!
Holly
I'm working on a LK script to change some simulation inputs and I'm wondering if it's possible to change the turbine output fraction to an array. In my script, it sets the 'ui_disp_1_turbout' to hourly values over a year with no error, but after simulating, it shows that the turbine output fraction does not follow the assigned array, and just stays as a single value. Attached is an image of part of the code.
If this is not possible, is there a way to best mimic an off grid CSP system to follow the demand profile?
Lastly, is there a quicker way to do element-wise multiplication/ division between arrays or with a single value in LK other than using a loop?
Thanks!
Holly
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5423
21 Sep 2018 15:24 #6441
by pgilman
Replied by pgilman on topic Turbine output control
Dear Holly,
The
input variable is a number with a single value, and is the turbine output fraction for Period 1. It is not possible to change the turbine output fraction on an hour by hour basis from LK. I'm not sure what happens when you set its value to an array -- it seems like you should get an error trying to set a number to an array.
A tedious way to do this might be to set the value of the turbine output fraction, run an entire simulation, extract the output data you need for the time step in question, then change the value of the turbine output fraction, run another simulation, etc.
LK does not have functions for array operations. If you plan to do that often in your script, you can write a functions for array multiplication/division.
Best regards,
Paul.
The
Code:
ui_disp_1_turbout
A tedious way to do this might be to set the value of the turbine output fraction, run an entire simulation, extract the output data you need for the time step in question, then change the value of the turbine output fraction, run another simulation, etc.
LK does not have functions for array operations. If you plan to do that often in your script, you can write a functions for array multiplication/division.
Best regards,
Paul.
Please Log in or Create an account to join the conversation.
- Mohammed Alfailakawi
Less
More
- Posts: 34
10 Jul 2022 07:04 #11238
by Mohammed Alfailakawi
Replied by Mohammed Alfailakawi on topic Turbine output control
Dear Mr. Gilman,
I am traying to multiply two arrays of a similar length and store the results in a third array in a LK script using the following loop but it does not work:
for (i = 0 ; i<26; i++)
{
OM_production_capacity_expenses = variable_costs * AEG ;
}
The error message says: access violation: expected numeric, but found array
The scripting reference does not mention much about array functions, and I saw your reply to Holly that a function of array multiplication/division must be written but I did not understand what exactly you mean.
Thanks in advance,
Mohammed
I am traying to multiply two arrays of a similar length and store the results in a third array in a LK script using the following loop but it does not work:
for (i = 0 ; i<26; i++)
{
OM_production_capacity_expenses = variable_costs * AEG ;
}
The error message says: access violation: expected numeric, but found array
The scripting reference does not mention much about array functions, and I saw your reply to Holly that a function of array multiplication/division must be written but I did not understand what exactly you mean.
Thanks in advance,
Mohammed
Please Log in or Create an account to join the conversation.
- pgilman
Less
More
- Posts: 5423
11 Jul 2022 17:28 - 11 Jul 2022 17:28 #11240
by pgilman
Replied by pgilman on topic Turbine output control
Hi Mohammed,
Section 4 of the LK Guide explains arrays. (A link to the document is available from SAM's Help system and from sam.nrel.gov/lk-script.html .)
Here is an example that might help:
Best regards,
Paul.
Best regards,
Paul.
Section 4 of the LK Guide explains arrays. (A link to the document is available from SAM's Help system and from sam.nrel.gov/lk-script.html .)
Here is an example that might help:
Code:
analysis_period = get('analysis_period'); // years
production = get('cf_energy_net'); // kWh/year
cost = 0.5; // $
for (i=0; i<analysis_period; i++)
{
expenses[i] = cost * production[i];
}
outln(expenses);
Best regards,
Paul.
Best regards,
Paul.
Last edit: 11 Jul 2022 17:28 by pgilman.
Please Log in or Create an account to join the conversation.
- Mohammed Alfailakawi
Less
More
- Posts: 34
12 Jul 2022 06:56 #11245
by Mohammed Alfailakawi
Replied by Mohammed Alfailakawi on topic Turbine output control
Dear Mr. Gilman,
Thanks a lot for the reply, your suggestion worked pretty well when multiplying arrays that are called from SAM.
My apologies, I forgot to mention that I am trying to call arrays from CSV files and multiply them as follow:
path = 'C:/Users/Mohammed/Desktop/LCOE Calculation' + '/';
AEG = csvread (path+'AEG.csv')
variable_costs = csvread (path + 'variable M&O costs.csv');
for (i = 0 ; i<26; i++)
{
OM_production_capacity_expenses = variable_costs * AEG;
}
simulate ();
I have some difficulty understanding the message when writing the csvread function in the LK script window:
csvread(string:file[,table:options]):array or table.
Note:
arrays in the CSV files are in columns and of the same length.
Thanks a lot for your time and efforts.
Regards,
Mohammed
Thanks a lot for the reply, your suggestion worked pretty well when multiplying arrays that are called from SAM.
My apologies, I forgot to mention that I am trying to call arrays from CSV files and multiply them as follow:
path = 'C:/Users/Mohammed/Desktop/LCOE Calculation' + '/';
AEG = csvread (path+'AEG.csv')
variable_costs = csvread (path + 'variable M&O costs.csv');
for (i = 0 ; i<26; i++)
{
OM_production_capacity_expenses = variable_costs * AEG;
}
simulate ();
I have some difficulty understanding the message when writing the csvread function in the LK script window:
csvread(string:file[,table:options]):array or table.
Note:
arrays in the CSV files are in columns and of the same length.
Thanks a lot for your time and efforts.
Regards,
Mohammed
Please Log in or Create an account to join the conversation.
- Mohammed Alfailakawi
Less
More
- Posts: 34
12 Jul 2022 10:32 #11247
by Mohammed Alfailakawi
Replied by Mohammed Alfailakawi on topic Turbine output control
I also forgot to mention that the problem seems in how the LK reads the data, as for instance if you see the following two examples of data called from SAM by a get finction:
electricity_purchase_price = [ 0, 53572.4, 55195.7, 56868.1, 58591.2, 60366.5, 62195.6, 64080.1, 66021.8, 68022.2, 70083.3, 72206.8, 74394.7, 76648.9, 78971.3, 81364.1, 83829.5, 86369.5, 88986.5, 91682.8, 94460.8, 97323, 100272, 103310, 106440, 109666 ]
while the data I call from a CSV file appears as follows:
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 ] ]
and that is despite the fact that the calling order I used is the following:
variable_costs = csvread (path + 'variable M&O costs.csv', {numeric = true});
Thanks again and apologies for any inconvenience.
Regards,
electricity_purchase_price = [ 0, 53572.4, 55195.7, 56868.1, 58591.2, 60366.5, 62195.6, 64080.1, 66021.8, 68022.2, 70083.3, 72206.8, 74394.7, 76648.9, 78971.3, 81364.1, 83829.5, 86369.5, 88986.5, 91682.8, 94460.8, 97323, 100272, 103310, 106440, 109666 ]
while the data I call from a CSV file appears as follows:
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 ] ]
and that is despite the fact that the calling order I used is the following:
variable_costs = csvread (path + 'variable M&O costs.csv', {numeric = true});
Thanks again and apologies for any inconvenience.
Regards,
Please Log in or Create an account to join the conversation.
Moderators: pgilman