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

PVWatts Speed Up #8960

Merged
merged 13 commits into from
Aug 21, 2021
Merged
21 changes: 10 additions & 11 deletions src/EnergyPlus/PVWatts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,21 +466,20 @@ namespace PVWatts {

PVWattsGenerator &GetOrCreatePVWattsGenerator(EnergyPlusData &state, std::string const &GeneratorName)
{
// Find the generator, and create a new one if it hasn't been loaded yet.
int ObjNum =
state.dataInputProcessing->inputProcessor->getObjectItemNum(state, "Generator:PVWatts", UtilityRoutines::MakeUPPERCase(GeneratorName));
assert(ObjNum >= 0);
if (ObjNum == 0) {
ShowFatalError(state, "Cannot find Generator:PVWatts " + GeneratorName);
}

auto &PVWattsGenerators(state.dataPVWatts->PVWattsGenerators);

auto it = PVWattsGenerators.find(ObjNum);
auto it = PVWattsGenerators.find(GeneratorName);
if (it == PVWattsGenerators.end()) {
// It's not in the map, add it.
PVWattsGenerators.insert(std::make_pair(ObjNum, PVWattsGenerator::createFromIdfObj(state, ObjNum)));
PVWattsGenerator &pvw(PVWattsGenerators.find(ObjNum)->second);
int ObjNum =
state.dataInputProcessing->inputProcessor->getObjectItemNum(state, "Generator:PVWatts", UtilityRoutines::MakeUPPERCase(GeneratorName));
assert(ObjNum >= 0);
if (ObjNum == 0) {
ShowFatalError(state, "Cannot find Generator:PVWatts " + GeneratorName);
}

PVWattsGenerators.insert(std::make_pair(GeneratorName, PVWattsGenerator::createFromIdfObj(state, ObjNum)));
PVWattsGenerator &pvw(PVWattsGenerators.find(GeneratorName)->second);
pvw.setupOutputVariables(state);
return pvw;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lookup of the PVWatts object in the list was adding some time mostly because we called the input processor every time around to get the ObjNum from the object name. Changed the std::map that holds those to have the names as keys instead of ObjNum and it shaved some time off.

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/PVWatts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace PVWatts {
struct PVWattsData : BaseGlobalStruct
{

std::map<int, PVWatts::PVWattsGenerator> PVWattsGenerators;
std::map<std::string, PVWatts::PVWattsGenerator> PVWattsGenerators;

void clear_state() override
{
Expand Down
8 changes: 7 additions & 1 deletion third_party/ssc/ssc/cmod_pvwattsv5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,18 +644,24 @@ static var_info _cm_vtab_pvwattsv5_1ts_outputs[] = {

class cm_pvwattsv5_1ts : public cm_pvwattsv5_base
{
private:
bool system_inputs_are_setup;
public:

cm_pvwattsv5_1ts()
{
add_var_info(_cm_vtab_pvwattsv5_1ts_weather);
add_var_info(_cm_vtab_pvwattsv5_common);
add_var_info(_cm_vtab_pvwattsv5_1ts_outputs);
system_inputs_are_setup = false;
}

void exec()
{
setup_system_inputs();
if (!system_inputs_are_setup) {
setup_system_inputs();
system_inputs_are_setup = true;
}
double ts = as_number("time_step");
Comment on lines +647 to 665
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the biggest win. Using the 1-timestep model from SSC caused the panels to be initialized every timestep. This isn't a design flaw on their end because they take the unchanging properties of the PV system as inputs each timestep, so it could need to be reinitialized, but we know we're not changing those, so I hacked it to only initialize the first time.

if (is_assigned("tcell") && is_assigned("poa"))
initialize_cell_temp(ts, as_double("tcell"), as_double("poa"));
Expand Down
4 changes: 2 additions & 2 deletions third_party/ssc/ssc/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ bool compute_module::compute(handler_interface *handler, var_table *data) {
try { // catch any 'general_error' that can be thrown during precheck, exec, and postcheck

if (!evaluate()) return false; // This can be enabled when we want automatic updating of interdependent-inputs
if (!verify("precheck input", SSC_INPUT)) return false;
// if (!verify("precheck input", SSC_INPUT)) return false;
exec();
if (!verify("postcheck output", SSC_OUTPUT)) return false;
// if (!verify("postcheck output", SSC_OUTPUT)) return false;
Comment on lines -67 to +69
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "compute module" (cmod) in SSC verifies all inputs at each timestep are within valid ranges or enums. We're doing that validation with the idd, so no need to redo that here.


} catch (general_error &e) {
log(e.err_text, SSC_ERROR, e.time);
Expand Down