Skip to content

Commit

Permalink
Add conversion efficiency to thermal buy rates.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorbrown75 committed Oct 30, 2024
1 parent 1733bd1 commit 8fa9f29
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions ssc/cmod_thermalrate_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static var_info vtab_thermal_rate_iph[] = {
{ SSC_INPUT, SSC_ARRAY, "thermal_load_escalation", "Annual load escalation", "%/year", "", "Thermal Rate", "?=0", "", "" },
{ SSC_INPUT, SSC_ARRAY, "thermal_rate_escalation", "Annual thermal rate escalation", "%/year", "", "Thermal Rate", "?=0", "", "" },

{ SSC_INPUT, SSC_NUMBER, "thermal_conversion_efficiency", "Heat conversion efficiency (buy)", "%", "", "Thermal Rate", "?=100", "", "" },


{ SSC_INPUT, SSC_NUMBER, "thermal_buy_rate_option", "Thermal buy rate option", "0-2", "0=flat,1=timestep,2=monthly", "Thermal Rate", "?=0", "INTEGER,MIN=0,MAX=2", "" },
{ SSC_INPUT, SSC_NUMBER, "thermal_buy_rate_flat_heat_btu", "Thermal buy rate flat", "$/(MMBtu/hr)", "", "Thermal Rate", "?=0", "", "" },
{ SSC_INPUT, SSC_ARRAY, "thermal_timestep_buy_rate_heat_btu", "Thermal buy rate", "$/(MMBtu/hr)", "", "Thermal Rate", "?=0", "", "" },
Expand Down Expand Up @@ -210,7 +213,7 @@ class cm_thermalrate_iph : public compute_module
nrec_gen_per_year = nrec_gen / nyears;
step_per_hour_gen = nrec_gen_per_year / 8760;
if (step_per_hour_gen < 1 || step_per_hour_gen > 60 || step_per_hour_gen * 8760 != nrec_gen_per_year)
throw exec_error("thermalrate", util::format("invalid number of thermal records (%d): must be an integer multiple of 8760", (int)nrec_gen_per_year));
throw exec_error("thermalrate_iph", util::format("invalid number of thermal records (%d): must be an integer multiple of 8760", (int)nrec_gen_per_year));
ssc_number_t ts_hour_gen = 1.0f / step_per_hour_gen;
m_num_rec_yearly = nrec_gen_per_year;

Expand All @@ -226,9 +229,9 @@ class cm_thermalrate_iph : public compute_module

step_per_hour_load = nrec_load / 8760;
if (step_per_hour_load < 1 || step_per_hour_load > 60 || step_per_hour_load * 8760 != nrec_load)
throw exec_error("thermalrate", util::format("invalid number of load records (%d): must be an integer multiple of 8760", (int)nrec_load));
throw exec_error("thermalrate_iph", util::format("invalid number of load records (%d): must be an integer multiple of 8760", (int)nrec_load));
if ((nrec_load != m_num_rec_yearly) && (nrec_load != 8760))
throw exec_error("thermalrate", util::format("number of load records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nrec_load, (int)m_num_rec_yearly));
throw exec_error("thermalrate_iph", util::format("number of load records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nrec_load, (int)m_num_rec_yearly));
}
// ssc_number_t ts_hour_load = 1.0f / step_per_hour_load;

Expand All @@ -248,6 +251,13 @@ class cm_thermalrate_iph : public compute_module

size_t idx = 0;

// Get conversion efficiency
double eff_buy_frac = as_double("thermal_conversion_efficiency") / 100.0; // Bought heat conversion efficiency (converted to fraction)
if (eff_buy_frac <= 0)
{
throw exec_error("thermalrate_iph", "Conversion efficiency must be greater than 0");
}

// Timestep Buy Rate
if (as_integer("thermal_buy_rate_option") == 1)
{
Expand All @@ -256,16 +266,16 @@ class cm_thermalrate_iph : public compute_module
pbuyrate = as_array("thermal_timestep_buy_rate_heat_btu", &nbuyrate);
step_per_hour_br = nbuyrate / 8760;
if (step_per_hour_br < 1 || step_per_hour_br > 60 || step_per_hour_br * 8760 != nbuyrate)
throw exec_error("thermalrate", util::format("invalid number of buy rate records (%d): must be an integer multiple of 8760", (int)nbuyrate));
throw exec_error("thermalrate_iph", util::format("invalid number of buy rate records (%d): must be an integer multiple of 8760", (int)nbuyrate));
if ((nbuyrate != m_num_rec_yearly) && (nbuyrate != 8760))
throw exec_error("thermalrate", util::format("number of buy rate records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nbuyrate, (int)m_num_rec_yearly));
throw exec_error("thermalrate_iph", util::format("number of buy rate records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nbuyrate, (int)m_num_rec_yearly));
for (i = 0; i < 8760; i++)
{
for (size_t ii = 0; ii < step_per_hour_gen; ii++)
{
size_t ndx = i * step_per_hour_gen + ii;
br = ((idx < nbuyrate) ? pbuyrate[idx] : 0);
p_buyrate[ndx] = br;
p_buyrate[ndx] = br / eff_buy_frac; // account for heat conversion efficiency
if (step_per_hour_gen == step_per_hour_br)
idx++;
else if (ii == (step_per_hour_gen - 1))
Expand All @@ -279,7 +289,7 @@ class cm_thermalrate_iph : public compute_module
std::vector<double> br_monthly = as_vector_double("thermal_monthly_buy_rate_heat_btu");
if (br_monthly.size() != 12)
{
throw exec_error("thermalrate", util::format("invalid number of monthly buy rate records (%d): must be equal to 12", (int)br_monthly.size()));
throw exec_error("thermalrate_iph", util::format("invalid number of monthly buy rate records (%d): must be equal to 12", (int)br_monthly.size()));
}
// Assign buy rate for every hour in each month
int hr_count = 0;
Expand All @@ -288,7 +298,7 @@ class cm_thermalrate_iph : public compute_module
int hr_in_current_month = util::hours_in_month(month);
for (int hr_in_mnth = 0; hr_in_mnth < hr_in_current_month; hr_in_mnth++)
{
p_buyrate[hr_count] = br_monthly[month - 1];
p_buyrate[hr_count] = br_monthly[month - 1] / eff_buy_frac; // account for heat conversion efficiency
hr_count++;
}
}
Expand All @@ -297,7 +307,7 @@ class cm_thermalrate_iph : public compute_module
{
ssc_number_t br = as_number("thermal_buy_rate_flat_heat_btu");
for (i = 0; i < m_num_rec_yearly; i++)
p_buyrate[i] = br;
p_buyrate[i] = br / eff_buy_frac; // account for heat conversion efficiency
}

// Time step input
Expand All @@ -308,9 +318,9 @@ class cm_thermalrate_iph : public compute_module
psellrate = as_array("thermal_timestep_sell_rate_heat_btu", &nsellrate);
step_per_hour_br = nsellrate / 8760;
if (step_per_hour_br < 1 || step_per_hour_br > 60 || step_per_hour_br * 8760 != nsellrate)
throw exec_error("thermalrate", util::format("invalid number of sell rate records (%d): must be an integer multiple of 8760", (int)nsellrate));
throw exec_error("thermalrate_iph", util::format("invalid number of sell rate records (%d): must be an integer multiple of 8760", (int)nsellrate));
if ((nsellrate != m_num_rec_yearly) && (nsellrate != 8760))
throw exec_error("thermalrate", util::format("number of sell rate records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nsellrate, (int)m_num_rec_yearly));
throw exec_error("thermalrate_iph", util::format("number of sell rate records (%d) must be equal to number of gen records (%d) or 8760 for each year", (int)nsellrate, (int)m_num_rec_yearly));
for (i = 0; i < 8760; i++)
{
for (size_t ii = 0; ii < step_per_hour_gen; ii++)
Expand All @@ -331,7 +341,7 @@ class cm_thermalrate_iph : public compute_module
std::vector<double> sr_monthly = as_vector_double("thermal_monthly_sell_rate_heat_btu");
if (sr_monthly.size() != 12)
{
throw exec_error("thermalrate", util::format("invalid number of monthly sell rate records (%d): must be equal to 12", (int)sr_monthly.size()));
throw exec_error("thermalrate_iph", util::format("invalid number of monthly sell rate records (%d): must be equal to 12", (int)sr_monthly.size()));
}
// Assign sell rate for every hour in each month
int hr_count = 0;
Expand Down

0 comments on commit 8fa9f29

Please sign in to comment.