Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor adjust losses to use vartable instead of cmod #1234

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ssc/cmod_biomass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ class cm_biomass : public compute_module
rated_eff += press_adj;


adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("biopower", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_etes_electric_resistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ class cm_etes_electric_resistance : public compute_module
ssc_number_t* p_time_final_hr = as_array("time_hr", &count);

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(n_steps_fixed))
throw exec_error("etes_electric_resistance", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_etes_ptes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ class cm_etes_ptes : public compute_module
ssc_number_t* p_time_final_hr = as_array("time_hr", &count);

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(count))
throw exec_error("etes_electric_resistance", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_fresnel_physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ class cm_fresnel_physical : public compute_module
throw exec_error("fresnel_physical", "The number of fixed steps does not match the length of output data arrays");

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(n_steps_fixed))
throw exec_error("fresnel_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_fresnel_physical_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ class cm_fresnel_physical_iph : public compute_module
throw exec_error("fresnel_physical", "The number of fixed steps does not match the length of output data arrays");

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(n_steps_fixed))
throw exec_error("fresnel_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_generic_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class cm_generic_system : public compute_module
sys_degradation.reserve(nyears);
double derate = (1 - (double)as_number("derate") / 100);

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec_load, nyears))
throw exec_error("generic system", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_geothermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class cm_geothermal : public compute_module
ssc_number_t * p_gen = allocate("gen", n_rec);

// TODO - implement performance factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(8760, geo_inputs.mi_ProjectLifeYears))
throw exec_error("geothermal", "failed to setup adjustment factors: " + haf.error());
std::vector<double> haf_input;
Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_hcpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class cm_hcpv : public compute_module
double ac_loss_tracker = 0;


adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("hcpv", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_linear_fresnel_dsg_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ class cm_linear_fresnel_dsg_iph : public compute_module
throw exec_error("linear_fresnel_dsg_iph", "The number of fixed steps does not match the length of output data arrays");

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if( !haf.setup(n_steps_fixed) )
throw exec_error("linear_fresnel_dsg_iph", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_mhk_tidal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class cm_mhk_tidal : public compute_module
ssc_number_t* p_gen = allocate("gen", number_records);
int power_bin = 0;

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(number_records, 1))
throw exec_error("mhk_tidal", "Failed to set up adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_mhk_wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class cm_mhk_wave : public compute_module
sys_degradation.push_back(1); // single year mode - degradation handled in financial models.
}

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(number_records, nyears))
throw exec_error("mhk_wave", "Failed to set up adjustment factors: " + haf.error());

Expand Down
4 changes: 2 additions & 2 deletions ssc/cmod_mspt_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ class cm_mspt_iph : public compute_module
heliostatfield.ms_params.mv_clearsky_data = clearsky_data;

//Load the solar field adjustment factors
adjustment_factors sf_haf(this, "sf_adjust");
adjustment_factors sf_haf(this->get_var_table(), "sf_adjust");
if (!sf_haf.setup((int)n_steps_full))
throw exec_error("mspt_iph", "failed to setup sf adjustment factors: " + sf_haf.error());
//allocate array to pass to tcs
Expand Down Expand Up @@ -2290,7 +2290,7 @@ class cm_mspt_iph : public compute_module
ssc_number_t* p_q_dot_heat_sink = as_array("q_dot_to_heat_sink", &count);

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(count))
throw exec_error("mspt_iph", "failed to setup adjustment factors: " + haf.error());

Expand Down
4 changes: 2 additions & 2 deletions ssc/cmod_pvsamv1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,12 @@ void cm_pvsamv1::exec()
//dc hourly adjustment factors
int nyears_haf = nyears;
if (!system_use_lifetime_output) nyears_haf = 1;
adjustment_factors dc_haf(this, "dc_adjust");
adjustment_factors dc_haf(this->get_var_table(), "dc_adjust");
if (!dc_haf.setup((int)nrec, nyears_haf))
throw exec_error("pvsamv1", "failed to setup DC adjustment factors: " + dc_haf.error());

// hourly adjustment factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup((int)nrec, nyears_haf))
throw exec_error("pvsamv1", "failed to setup AC adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_pvwattsv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class cm_pvwattsv5 : public cm_pvwattsv5_base
size_t nrec = wdprov->nrecords();
size_t nlifetime = nrec * nyears;

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec, nyears))
throw exec_error("pvwattsv5", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_pvwattsv7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class cm_pvwattsv7 : public compute_module
size_t nrec = wdprov->nrecords();
size_t nlifetime = nrec * nyears;

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec, nyears))
throw exec_error("pvwattsv7", "Failed to set up adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_pvwattsv8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class cm_pvwattsv8 : public compute_module
size_t nrec = wdprov->nrecords();
size_t nlifetime = nrec * nyears;

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec, nyears))
throw exec_error("pvwattsv8", "Failed to set up adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_swh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class cm_swh : public compute_module
double ts_hour = 1.0/step_per_hour;
double ts_sec = 3600.0/step_per_hour;

adjustment_factors haf( this, "adjust" );
adjustment_factors haf( this->get_var_table(), "adjust" );
if ( !haf.setup(nrec) )
throw exec_error("swh", "failed to setup adjustment factors: " + haf.error() );

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcsdish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class cm_tcsdish : public tcKernel
ssc_number_t *po8 = allocate("hourly_Q_rec_losses", count);


adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(count))
throw exec_error("dish", "failed to setup adjustment factors: " + haf.error());

Expand Down
4 changes: 2 additions & 2 deletions ssc/cmod_tcsgeneric_solar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class cm_tcsgeneric_solar : public tcKernel
size_t hours = 8760;

//Load the solar field adjustment factors
adjustment_factors sf_haf(this, "sf_adjust");
adjustment_factors sf_haf(this->get_var_table(), "sf_adjust");
if (!sf_haf.setup(hours))
throw exec_error("tcsgeneric_solar", "failed to setup sf adjustment factors: " + sf_haf.error());
//allocate array to pass to tcs
Expand All @@ -400,7 +400,7 @@ class cm_tcsgeneric_solar : public tcKernel
if (!enet || count != 8760)
throw exec_error("tcsgeneric_solar", "Failed to retrieve hourly net energy");

adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(count))
throw exec_error("tcsgeneric_solar", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcslinear_fresnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class cm_tcslinear_fresnel : public tcKernel
throw exec_error( "tcslinear_fresnel", util::format("there was a problem returning the results from the simulation.") );

// performance adjustement factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("tcstrough_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
4 changes: 2 additions & 2 deletions ssc/cmod_tcsmolten_salt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ class cm_tcsmolten_salt : public compute_module
heliostatfield.ms_params.mv_clearsky_data = clearsky_data;

//Load the solar field adjustment factors
adjustment_factors sf_haf(this, "sf_adjust");
adjustment_factors sf_haf(this->get_var_table(), "sf_adjust");
if (!sf_haf.setup((int)n_steps_full))
throw exec_error("tcsmolten_salt", "failed to setup sf adjustment factors: " + sf_haf.error());
//allocate array to pass to tcs
Expand Down Expand Up @@ -2979,7 +2979,7 @@ class cm_tcsmolten_salt : public compute_module
ssc_number_t *p_time_final_hr = as_array("time_hr", &count);

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if( !haf.setup(n_steps_full) )
throw exec_error("tcsmolten_salt", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcsmslf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ class cm_tcsmslf : public tcKernel
std::copy(sgs_P_dsn, sgs_P_dsn + nv, sgs_P_dsn_cm);

// performance adjustement factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("tcsmslf", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcstrough_empirical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class cm_tcstrough_empirical : public tcKernel
assign("conversion_factor", convfactor);

// performance adjustement factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("tcstrough_empirical", "failed to setup adjustment factors: " + haf.error());
// hourly_energy output
Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcstrough_physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ class cm_tcstrough_physical : public tcKernel
std::copy(sgs_P_dsn, sgs_P_dsn + nv, sgs_P_dsn_cm);

// performance adjustment factors
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup(nrec))
throw exec_error("tcstrough_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_trough_physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ class cm_trough_physical : public compute_module
throw exec_error("trough_physical", "The number of fixed steps does not match the length of output data arrays");

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if( !haf.setup(n_steps_full) )
throw exec_error("trough_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_trough_physical_iph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ class cm_trough_physical_iph : public compute_module
throw exec_error("trough_physical", "The number of fixed steps does not match the length of output data arrays");

// 'adjustment_factors' class stores factors in hourly array, so need to index as such
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if( !haf.setup(n_steps_fixed) )
throw exec_error("trough_physical", "failed to setup adjustment factors: " + haf.error());

Expand Down
2 changes: 1 addition & 1 deletion ssc/cmod_windpower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void cm_windpower::exec()
throw exec_error("windpower", util::format("the wind model is only configured to handle up to %d turbines.", wpc.GetMaxTurbines()));

// create adjustment factors and losses - set them up initially here for the Weibull distribution method, rewrite them later with nrec for the time series method
adjustment_factors haf(this, "adjust");
adjustment_factors haf(this->get_var_table(), "adjust");
if (!haf.setup())
throw exec_error("windpower", "failed to setup adjustment factors: " + haf.error());

Expand Down
20 changes: 10 additions & 10 deletions ssc/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,22 +1063,22 @@ var_info vtab_utility_rate_common[] = {
var_info_invalid
};

adjustment_factors::adjustment_factors( compute_module *cm, const std::string &prefix )
: m_cm(cm), m_prefix(prefix)
adjustment_factors::adjustment_factors(var_table* vt, const std::string &prefix )
: m_vt(vt), m_prefix(prefix)
{
}

//adjustment factors changed from derates to percentages jmf 1/9/15
bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set to 8760 in this declaration function in common.h
{
ssc_number_t f = m_cm->as_number(m_prefix + "_constant");
ssc_number_t f = m_vt->as_number(m_prefix + "_constant");
f = 1.0 - f / 100.0; //convert from percentage to factor
m_factors.resize( nsteps * analysis_period, f);

if (m_cm->is_assigned(m_prefix + "_en_hourly")) {
if (m_cm->as_boolean(m_prefix + "_en_hourly")) {
if (m_vt->is_assigned(m_prefix + "_en_hourly")) {
if (m_vt->as_boolean(m_prefix + "_en_hourly")) {
size_t n;
ssc_number_t* p = m_cm->as_array(m_prefix + "_hourly", &n);
ssc_number_t* p = m_vt->as_array(m_prefix + "_hourly", &n);
if (p != 0 && n == 8760)
{
for (int i = 0; i < 8760; i++)
Expand All @@ -1089,14 +1089,14 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set
}
}
}
if (m_cm->as_boolean(m_prefix + "_en_timeindex"))
if (m_vt->as_boolean(m_prefix + "_en_timeindex"))
{
size_t n;
double steps_per_hour = nsteps / 8760.0;
int month = 0;
int day = 0;
int week = 0;
ssc_number_t* p = m_cm->as_array(m_prefix + "_timeindex", &n);
ssc_number_t* p = m_vt->as_array(m_prefix + "_timeindex", &n);
if (p != 0) {
if (n == 1) {
for (int a = 0; a < analysis_period; a++) {
Expand Down Expand Up @@ -1152,10 +1152,10 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set
}
}
}
if (m_cm->as_boolean(m_prefix + "_en_periods"))
if (m_vt->as_boolean(m_prefix + "_en_periods"))
{
size_t nr, nc;
ssc_number_t* mat = m_cm->as_matrix(m_prefix + "_periods", &nr, &nc);
ssc_number_t* mat = m_vt->as_matrix(m_prefix + "_periods", &nr, &nc);
double ts_mult = nsteps / 8760.0;
if ( mat != 0 && nc == 3 )
{
Expand Down
4 changes: 2 additions & 2 deletions ssc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ void prepend_to_output(compute_module* cm, std::string var_name, size_t count, s

class adjustment_factors
{
compute_module *m_cm;
var_table *m_vt;
std::vector<ssc_number_t> m_factors;
std::string m_error;
std::string m_prefix;
public:
adjustment_factors(compute_module *cm, const std::string &prefix);
adjustment_factors(var_table *vt, const std::string &prefix);
bool setup(int nsteps=8760, int analysis_period=1);
ssc_number_t operator()(size_t time);
size_t size();
Expand Down