Skip to content

Commit

Permalink
Merge pull request #1028 from NREL/ssc_1027
Browse files Browse the repository at this point in the history
Fixes #1027
  • Loading branch information
sjanzou authored May 25, 2023
2 parents f8d64af + 6ed193e commit 06c4c33
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 79 deletions.
2 changes: 1 addition & 1 deletion 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
sf_adjustment_factors sf_haf(this);
adjustment_factors sf_haf(this, "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 Down
2 changes: 1 addition & 1 deletion ssc/cmod_tcsmolten_salt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ class cm_tcsmolten_salt : public compute_module
heliostatfield.ms_params.mv_clearsky_data = clearsky_data;

//Load the solar field adjustment factors
sf_adjustment_factors sf_haf(this);
adjustment_factors sf_haf(this, "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
67 changes: 5 additions & 62 deletions ssc/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,81 +1125,24 @@ ssc_number_t adjustment_factors::operator()( size_t time )
else return 0.0;
}

sf_adjustment_factors::sf_adjustment_factors(compute_module *cm)
: m_cm(cm)
size_t adjustment_factors::size()
{
return m_factors.size();
}

bool sf_adjustment_factors::setup(int nsteps)
{
ssc_number_t f = m_cm->as_number("sf_adjust:constant");
f = 1.0 - f / 100.0; //convert from percentage to factor
m_factors.resize(nsteps, f);

if (m_cm->is_assigned("sf_adjust:hourly"))
{
size_t n;
ssc_number_t *p = m_cm->as_array("sf_adjust:hourly", &n);
if (p != 0 && n == (size_t)nsteps)
{
for (int i = 0; i < nsteps; i++)
m_factors[i] *= (1.0 - p[i] / 100.0); //convert from percentages to factors
}
if (n!=(size_t)nsteps)
m_error = util::format("array length (%d) must match number of yearly simulation time steps (%d).", n, nsteps);
}

if (m_cm->is_assigned("sf_adjust:periods"))
{
size_t nr, nc;
ssc_number_t *mat = m_cm->as_matrix("sf_adjust:periods", &nr, &nc);
if (mat != 0 && nc == 3)
{
for (size_t r = 0; r<nr; r++)
{
int start = (int)mat[nc*r];
int end = (int)mat[nc*r + 1];
float factor = (float)mat[nc*r + 2];

if (start < 0 || start >= nsteps || end < start)
{
m_error = util::format("period %d is invalid ( start: %d, end %d )", (int)r, start, end);
continue;
}

if (end >= nsteps) end = nsteps-1;

for (int i = start; i <= end; i++)
m_factors[i] *= (1 - factor / 100); //convert from percentages to factors
}
}
}

return m_error.length() == 0;
}

ssc_number_t sf_adjustment_factors::operator()(size_t time)
{
if (time < m_factors.size()) return m_factors[time];
else return 0.0;
}

int sf_adjustment_factors::size()
{
return (int)m_factors.size();
}

shading_factor_calculator::shading_factor_calculator()
{
m_steps_per_hour = 1;
m_string_option = -1;
m_enTimestep = false;
m_enAzAlt = false;
m_enMxH = false;
m_diffFactor = 1.0;
m_beam_shade_factor = 1.0;
m_dc_shade_factor = 1.0;
}



bool shading_factor_calculator::setup( compute_module *cm, const std::string &prefix )
{
bool ok = true;
Expand Down
16 changes: 1 addition & 15 deletions ssc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class adjustment_factors
adjustment_factors(compute_module *cm, const std::string &prefix);
bool setup(int nsteps=8760, int analysis_period=1);
ssc_number_t operator()(size_t time);
size_t size();
std::string error() { return m_error; }
};

Expand All @@ -100,21 +101,6 @@ class forecast_price_signal
std::string error() { return m_error; }
};


class sf_adjustment_factors
{
compute_module *m_cm;
std::vector<ssc_number_t> m_factors;
std::string m_error;
public:
sf_adjustment_factors(compute_module *cm);
bool setup(int nsteps=8760);
int size();
ssc_number_t operator()(size_t time);
std::string error() { return m_error; }
};


class shading_factor_calculator
{
std::vector<std::string> m_errors;
Expand Down

0 comments on commit 06c4c33

Please sign in to comment.