From 466dc5a6e35b674afdfbd43a425b003d999856c1 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Mon, 9 Aug 2021 13:27:41 -0600 Subject: [PATCH 1/9] initialize the panels only once --- third_party/ssc/ssc/cmod_pvwattsv5.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/third_party/ssc/ssc/cmod_pvwattsv5.cpp b/third_party/ssc/ssc/cmod_pvwattsv5.cpp index 28f3607ba66..b187a6fb75c 100644 --- a/third_party/ssc/ssc/cmod_pvwattsv5.cpp +++ b/third_party/ssc/ssc/cmod_pvwattsv5.cpp @@ -644,6 +644,8 @@ 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() @@ -651,11 +653,15 @@ class cm_pvwattsv5_1ts : public cm_pvwattsv5_base 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"); if (is_assigned("tcell") && is_assigned("poa")) initialize_cell_temp(ts, as_double("tcell"), as_double("poa")); From 92ccf20287b730116d2478a0b0bc6d7e3b0736a0 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Mon, 9 Aug 2021 17:12:15 -0600 Subject: [PATCH 2/9] skip verifying cmod inputs --- third_party/ssc/ssc/core.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/ssc/ssc/core.cpp b/third_party/ssc/ssc/core.cpp index 4dd1880fe11..081eda70f6f 100644 --- a/third_party/ssc/ssc/core.cpp +++ b/third_party/ssc/ssc/core.cpp @@ -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; } catch (general_error &e) { log(e.err_text, SSC_ERROR, e.time); From d7fb6a5af0aefda07f84c50c6df0d58d1463b574 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Tue, 10 Aug 2021 16:09:54 -0600 Subject: [PATCH 3/9] using pvwatts obj name as map lookup --- src/EnergyPlus/PVWatts.cc | 21 ++++++++++----------- src/EnergyPlus/PVWatts.hh | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index 6d0eadd88dd..9a9b61b8265 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -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; } else { diff --git a/src/EnergyPlus/PVWatts.hh b/src/EnergyPlus/PVWatts.hh index cd828037bc0..cf47c580e62 100644 --- a/src/EnergyPlus/PVWatts.hh +++ b/src/EnergyPlus/PVWatts.hh @@ -215,7 +215,7 @@ namespace PVWatts { struct PVWattsData : BaseGlobalStruct { - std::map PVWattsGenerators; + std::map PVWattsGenerators; void clear_state() override { From b14b368539b66e3d6f2256c7d29fdf7708771499 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Wed, 11 Aug 2021 08:54:40 -0600 Subject: [PATCH 4/9] clang format --- src/EnergyPlus/PVWatts.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index 9a9b61b8265..fa85c6fa847 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -471,8 +471,8 @@ namespace PVWatts { auto it = PVWattsGenerators.find(GeneratorName); if (it == PVWattsGenerators.end()) { // It's not in the map, add it. - int ObjNum = - state.dataInputProcessing->inputProcessor->getObjectItemNum(state, "Generator:PVWatts", UtilityRoutines::MakeUPPERCase(GeneratorName)); + 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); From b264d6d706d533e10cb13c231647784b618d4b51 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Wed, 11 Aug 2021 16:44:16 -0600 Subject: [PATCH 5/9] making pvwattsGenerator a member of GeneratorController --- src/EnergyPlus/Data/EnergyPlusData.cc | 2 -- src/EnergyPlus/Data/EnergyPlusData.hh | 2 -- src/EnergyPlus/ElectricPowerServiceManager.cc | 23 +++++++++----- src/EnergyPlus/ElectricPowerServiceManager.hh | 3 ++ src/EnergyPlus/PVWatts.cc | 31 +++---------------- src/EnergyPlus/PVWatts.hh | 15 +-------- tst/EnergyPlus/unit/PVWatts.unit.cc | 23 +++++++------- 7 files changed, 34 insertions(+), 65 deletions(-) diff --git a/src/EnergyPlus/Data/EnergyPlusData.cc b/src/EnergyPlus/Data/EnergyPlusData.cc index d3fd6fc7697..87919e1eedd 100644 --- a/src/EnergyPlus/Data/EnergyPlusData.cc +++ b/src/EnergyPlus/Data/EnergyPlusData.cc @@ -198,7 +198,6 @@ EnergyPlusData::EnergyPlusData() this->dataOutputReports = std::make_unique(); this->dataOutsideEnergySrcs = std::make_unique(); this->dataPTHP = std::make_unique(); - this->dataPVWatts = std::make_unique(); this->dataPackagedThermalStorageCoil = std::make_unique(); this->dataPhotovoltaic = std::make_unique(); this->dataPhotovoltaicState = std::make_unique(); @@ -456,7 +455,6 @@ void EnergyPlusData::clear_state() this->dataOutputReports->clear_state(); this->dataOutsideEnergySrcs->clear_state(); this->dataPTHP->clear_state(); - this->dataPVWatts->clear_state(); this->dataPackagedThermalStorageCoil->clear_state(); this->dataPhotovoltaic->clear_state(); this->dataPhotovoltaicState->clear_state(); diff --git a/src/EnergyPlus/Data/EnergyPlusData.hh b/src/EnergyPlus/Data/EnergyPlusData.hh index 63608dbd698..1fa83270e00 100644 --- a/src/EnergyPlus/Data/EnergyPlusData.hh +++ b/src/EnergyPlus/Data/EnergyPlusData.hh @@ -211,7 +211,6 @@ struct OutputReportTabularData; struct OutputReportsData; struct OutputsData; struct OutsideEnergySourcesData; -struct PVWattsData; struct PackagedTerminalHeatPumpData; struct PackagedThermalStorageCoilData; struct PhotovoltaicStateData; @@ -472,7 +471,6 @@ struct EnergyPlusData : BaseGlobalStruct std::unique_ptr dataOutputReports; std::unique_ptr dataOutput; std::unique_ptr dataOutsideEnergySrcs; - std::unique_ptr dataPVWatts; std::unique_ptr dataPTHP; std::unique_ptr dataPackagedThermalStorageCoil; std::unique_ptr dataPhotovoltaicState; diff --git a/src/EnergyPlus/ElectricPowerServiceManager.cc b/src/EnergyPlus/ElectricPowerServiceManager.cc index 6c603038c13..9bbcca41a23 100644 --- a/src/EnergyPlus/ElectricPowerServiceManager.cc +++ b/src/EnergyPlus/ElectricPowerServiceManager.cc @@ -1045,12 +1045,11 @@ ElectPowerLoadCenter::ElectPowerLoadCenter(EnergyPlusData &state, int const obje ShowContinueError(state, "ElectricLoadCenter:Inverter:PVWatts can only be used with Generator:PVWatts"); ShowContinueError(state, "\"" + generatorController->name + "\" is of type " + generatorController->typeOfName); } else { - PVWatts::PVWattsGenerator &pvwGen = PVWatts::GetOrCreatePVWattsGenerator(state, generatorController->name); - totalDCCapacity += pvwGen.getDCSystemCapacity(); + totalDCCapacity += generatorController->pvwattsGenerator->getDCSystemCapacity(); // Pass the inverter properties to the PVWatts generator class - pvwGen.setDCtoACRatio(inverterObj->pvWattsDCtoACSizeRatio()); - pvwGen.setInverterEfficiency(inverterObj->pvWattsInverterEfficiency()); + generatorController->pvwattsGenerator->setDCtoACRatio(inverterObj->pvWattsDCtoACSizeRatio()); + generatorController->pvwattsGenerator->setInverterEfficiency(inverterObj->pvWattsInverterEfficiency()); } } if (!errorsFound) { @@ -2146,7 +2145,7 @@ GeneratorController::GeneratorController(EnergyPlusData &state, : compGenTypeOf_Num(GeneratorType::Unassigned), compPlantTypeOf_Num(0), generatorType(GeneratorType::Unassigned), generatorIndex(0), maxPowerOut(0.0), availSchedPtr(0), powerRequestThisTimestep(0.0), onThisTimestep(false), eMSPowerRequest(0.0), eMSRequestOn(false), plantInfoFound(false), cogenLocation(PlantLocation(0, 0, 0, 0)), nominalThermElectRatio(0.0), dCElectricityProd(0.0), dCElectProdRate(0.0), - electricityProd(0.0), electProdRate(0.0), thermalProd(0.0), thermProdRate(0.0), errCountNegElectProd_(0) + electricityProd(0.0), electProdRate(0.0), thermalProd(0.0), thermProdRate(0.0), pvwattsGenerator(nullptr), errCountNegElectProd_(0) { static constexpr std::string_view routineName = "GeneratorController constructor "; @@ -2177,6 +2176,15 @@ GeneratorController::GeneratorController(EnergyPlusData &state, generatorType = GeneratorType::PVWatts; compGenTypeOf_Num = GeneratorType::PVWatts; compPlantTypeOf_Num = DataPlant::TypeOf_Other; + + int ObjNum = + state.dataInputProcessing->inputProcessor->getObjectItemNum(state, "Generator:PVWatts", UtilityRoutines::MakeUPPERCase(objectName)); + assert(ObjNum >= 0); + if (ObjNum == 0) { + ShowFatalError(state, "Cannot find Generator:PVWatts " + objectName); + } + pvwattsGenerator = PVWatts::PVWattsGenerator::createFromIdfObj(state, ObjNum); + } else if (UtilityRoutines::SameString(objectType, "Generator:FuelCell")) { generatorType = GeneratorType::FuelCell; compGenTypeOf_Num = GeneratorType::FuelCell; @@ -2324,9 +2332,8 @@ void GeneratorController::simGeneratorGetPowerOutput(EnergyPlusData &state, break; } case GeneratorType::PVWatts: { - PVWatts::PVWattsGenerator &pvwattsGenerator(PVWatts::GetOrCreatePVWattsGenerator(state, name)); - pvwattsGenerator.calc(state); - pvwattsGenerator.getResults(dCElectProdRate, dCElectricityProd, thermProdRate, thermalProd); + pvwattsGenerator->calc(state); + pvwattsGenerator->getResults(dCElectProdRate, dCElectricityProd, thermProdRate, thermalProd); electricPowerOutput = dCElectProdRate; thermalPowerOutput = thermProdRate; break; diff --git a/src/EnergyPlus/ElectricPowerServiceManager.hh b/src/EnergyPlus/ElectricPowerServiceManager.hh index 7508a18dc55..3486cb57dce 100644 --- a/src/EnergyPlus/ElectricPowerServiceManager.hh +++ b/src/EnergyPlus/ElectricPowerServiceManager.hh @@ -60,6 +60,7 @@ #include #include #include +#include #include // SSC Headers @@ -571,6 +572,8 @@ public: // data // might make this class a friend o Real64 thermalProd; // Current Thermal energy Produced from Equipment (J) Real64 thermProdRate; // Current Thermal energy Production Rate from Equipment (W) + std::unique_ptr pvwattsGenerator; // PVWattsGenerator object pointer + private: int errCountNegElectProd_; // error count for reccuring error when generators produce negative electric power diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index fa85c6fa847..e0659c712b7 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -214,7 +214,7 @@ namespace PVWatts { m_name); } - PVWattsGenerator PVWattsGenerator::createFromIdfObj(EnergyPlusData &state, int objNum) + std::unique_ptr PVWattsGenerator::createFromIdfObj(EnergyPlusData &state, int objNum) { Array1D_string cAlphaFieldNames; Array1D_string cNumericFieldNames; @@ -300,13 +300,13 @@ namespace PVWatts { } if (NumNums < NumFields::GROUND_COVERAGE_RATIO) { - return PVWattsGenerator(state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, 0.4); + return std::make_unique( + state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, 0.4); } const Real64 groundCoverageRatio(rNumericArgs(NumFields::GROUND_COVERAGE_RATIO)); - PVWattsGenerator pvwattsGenerator( + return std::make_unique( state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, groundCoverageRatio); - return pvwattsGenerator; } Real64 PVWattsGenerator::getDCSystemCapacity() @@ -464,29 +464,6 @@ namespace PVWatts { ThermalEnergy = 0.0; } - PVWattsGenerator &GetOrCreatePVWattsGenerator(EnergyPlusData &state, std::string const &GeneratorName) - { - auto &PVWattsGenerators(state.dataPVWatts->PVWattsGenerators); - - auto it = PVWattsGenerators.find(GeneratorName); - if (it == PVWattsGenerators.end()) { - // It's not in the map, add it. - 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; - } else { - return it->second; - } - } - } // namespace PVWatts } // namespace EnergyPlus diff --git a/src/EnergyPlus/PVWatts.hh b/src/EnergyPlus/PVWatts.hh index cf47c580e62..5cb8007a64d 100644 --- a/src/EnergyPlus/PVWatts.hh +++ b/src/EnergyPlus/PVWatts.hh @@ -169,7 +169,7 @@ namespace PVWatts { ssc_data_t m_pvwattsData; public: - static PVWattsGenerator createFromIdfObj(EnergyPlusData &state, int objNum); + static std::unique_ptr createFromIdfObj(EnergyPlusData &state, int objNum); PVWattsGenerator(EnergyPlusData &state, const std::string &name, @@ -208,21 +208,8 @@ namespace PVWatts { void getResults(Real64 &GeneratorPower, Real64 &GeneratorEnergy, Real64 &ThermalPower, Real64 &ThermalEnergy); }; - PVWattsGenerator &GetOrCreatePVWattsGenerator(EnergyPlusData &state, std::string const &GeneratorName); - } // namespace PVWatts -struct PVWattsData : BaseGlobalStruct -{ - - std::map PVWattsGenerators; - - void clear_state() override - { - this->PVWattsGenerators.clear(); - } -}; - } // namespace EnergyPlus #endif diff --git a/tst/EnergyPlus/unit/PVWatts.unit.cc b/tst/EnergyPlus/unit/PVWatts.unit.cc index 35052fb0439..f5a440877f8 100644 --- a/tst/EnergyPlus/unit/PVWatts.unit.cc +++ b/tst/EnergyPlus/unit/PVWatts.unit.cc @@ -133,17 +133,16 @@ TEST_F(EnergyPlusFixture, PVWattsGenerator_GetInputs) "Output:Variable,*,Generator Produced DC Electricity Rate,timestep;"}); process_idf(idfTxt); EXPECT_FALSE(has_err_output()); - PVWattsGenerator &pvw1 = GetOrCreatePVWattsGenerator(*state, "PVWattsArray1"); - EXPECT_EQ(pvw1.getModuleType(), ModuleType::PREMIUM); - EXPECT_EQ(pvw1.getArrayType(), ArrayType::ONE_AXIS); - EXPECT_DOUBLE_EQ(0.4, pvw1.getGroundCoverageRatio()); - PVWattsGenerator &pvw2 = GetOrCreatePVWattsGenerator(*state, "PVWattsArray2"); - EXPECT_DOUBLE_EQ(0.4, pvw2.getGroundCoverageRatio()); - PVWattsGenerator &pvw3 = GetOrCreatePVWattsGenerator(*state, "PVWattsArray3"); - EXPECT_DOUBLE_EQ(175.0, pvw3.getAzimuth()); - EXPECT_DOUBLE_EQ(21.0, pvw3.getTilt()); - EXPECT_DOUBLE_EQ(0.5, pvw3.getGroundCoverageRatio()); - EXPECT_EQ(static_cast(state->dataPVWatts->PVWattsGenerators.size()), 3); + auto pvw1 = PVWattsGenerator::createFromIdfObj(*state, 1); + EXPECT_EQ(pvw1->getModuleType(), ModuleType::PREMIUM); + EXPECT_EQ(pvw1->getArrayType(), ArrayType::ONE_AXIS); + EXPECT_DOUBLE_EQ(0.4, pvw1->getGroundCoverageRatio()); + auto pvw2 = PVWattsGenerator::createFromIdfObj(*state, 2); + EXPECT_DOUBLE_EQ(0.4, pvw2->getGroundCoverageRatio()); + auto pvw3 = PVWattsGenerator::createFromIdfObj(*state, 3); + EXPECT_DOUBLE_EQ(175.0, pvw3->getAzimuth()); + EXPECT_DOUBLE_EQ(21.0, pvw3->getTilt()); + EXPECT_DOUBLE_EQ(0.5, pvw3->getGroundCoverageRatio()); } TEST_F(EnergyPlusFixture, PVWattsGenerator_GetInputsFailure) @@ -161,7 +160,7 @@ TEST_F(EnergyPlusFixture, PVWattsGenerator_GetInputsFailure) ";", "Output:Variable,*,Generator Produced DC Electricity Rate,timestep;"}); EXPECT_FALSE(process_idf(idfTxt, false)); - ASSERT_THROW(GetOrCreatePVWattsGenerator(*state, "PVWattsArray1"), std::runtime_error); + ASSERT_THROW(PVWattsGenerator::createFromIdfObj(*state, 1), std::runtime_error); std::string const error_string = delimited_string( {" ** Severe ** [Generator:PVWatts][PVWattsArray1][array_geometry_type] - \"asdf\" - Failed to match against any enum values.", " ** Severe ** [Generator:PVWatts][PVWattsArray1][array_type] - \"FixedRoofMount\" - Failed to match against any enum values.", From 4a0e26d42cd3924a29246e6b440d88c0d34ad0a4 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Thu, 12 Aug 2021 12:20:03 -0600 Subject: [PATCH 6/9] forgot to setup the output variables for PVWatts, fixing that --- src/EnergyPlus/ElectricPowerServiceManager.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EnergyPlus/ElectricPowerServiceManager.cc b/src/EnergyPlus/ElectricPowerServiceManager.cc index 9bbcca41a23..1c971fddca0 100644 --- a/src/EnergyPlus/ElectricPowerServiceManager.cc +++ b/src/EnergyPlus/ElectricPowerServiceManager.cc @@ -2184,6 +2184,7 @@ GeneratorController::GeneratorController(EnergyPlusData &state, ShowFatalError(state, "Cannot find Generator:PVWatts " + objectName); } pvwattsGenerator = PVWatts::PVWattsGenerator::createFromIdfObj(state, ObjNum); + pvwattsGenerator->setupOutputVariables(state); } else if (UtilityRoutines::SameString(objectType, "Generator:FuelCell")) { generatorType = GeneratorType::FuelCell; From 3c9145190a18e66bb7a1af0ff1866415dfc2f160 Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Thu, 19 Aug 2021 13:43:40 -0600 Subject: [PATCH 7/9] only calling PVWatts once per zone timestep --- src/EnergyPlus/PVWatts.cc | 7 +++++-- src/EnergyPlus/PVWatts.hh | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index e0659c712b7..9205c74c055 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -89,7 +89,7 @@ namespace PVWatts { Real64 groundCoverageRatio) : m_moduleType(moduleType), m_arrayType(arrayType), m_geometryType(geometryType), m_DCtoACRatio(1.1), m_inverterEfficiency(0.96), m_outputDCPower(1000.0), m_cellTemperature(-9999), m_planeOfArrayIrradiance(-9999), m_shadedPercent(0.0), - m_pvwattsModule(ssc_module_create("pvwattsv5_1ts")), m_pvwattsData(ssc_data_create()) + m_pvwattsModule(ssc_module_create("pvwattsv5_1ts")), m_pvwattsData(ssc_data_create()), m_NumTimeStepsToday(0.0) { @@ -389,7 +389,10 @@ namespace PVWatts { auto &TimeStepSys = state.dataHVACGlobal->TimeStepSys; // We only run this once for each zone time step. - if (!state.dataGlobal->BeginTimeStepFlag) { + const int NumTimeStepsToday_loc = state.dataGlobal->HourOfDay * state.dataGlobal->NumOfTimeStepInHour + state.dataGlobal->TimeStep; + if (m_NumTimeStepsToday != NumTimeStepsToday_loc) { + m_NumTimeStepsToday = NumTimeStepsToday_loc; + } else { m_outputDCEnergy = m_outputDCPower * TimeStepSys * DataGlobalConstants::SecInHour; m_outputACEnergy = m_outputACPower * TimeStepSys * DataGlobalConstants::SecInHour; return; diff --git a/src/EnergyPlus/PVWatts.hh b/src/EnergyPlus/PVWatts.hh index 5cb8007a64d..5e8d29e1042 100644 --- a/src/EnergyPlus/PVWatts.hh +++ b/src/EnergyPlus/PVWatts.hh @@ -167,6 +167,7 @@ namespace PVWatts { ssc_module_t m_pvwattsModule; ssc_data_t m_pvwattsData; + Real64 m_NumTimeStepsToday; public: static std::unique_ptr createFromIdfObj(EnergyPlusData &state, int objNum); From 58bc0d9ed94132f39d73d95b4d5d1f13dc94955c Mon Sep 17 00:00:00 2001 From: Noel Merket Date: Thu, 19 Aug 2021 15:31:18 -0600 Subject: [PATCH 8/9] renaming PVWattsGenerator member variables --- src/EnergyPlus/PVWatts.cc | 168 +++++++++++++++++++------------------- src/EnergyPlus/PVWatts.hh | 46 +++++------ 2 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index 9205c74c055..635709a7390 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -87,13 +87,13 @@ namespace PVWatts { Real64 azimuth, size_t surfaceNum, Real64 groundCoverageRatio) - : m_moduleType(moduleType), m_arrayType(arrayType), m_geometryType(geometryType), m_DCtoACRatio(1.1), m_inverterEfficiency(0.96), - m_outputDCPower(1000.0), m_cellTemperature(-9999), m_planeOfArrayIrradiance(-9999), m_shadedPercent(0.0), - m_pvwattsModule(ssc_module_create("pvwattsv5_1ts")), m_pvwattsData(ssc_data_create()), m_NumTimeStepsToday(0.0) + : moduleType_(moduleType), arrayType_(arrayType), geometryType_(geometryType), DCtoACRatio_(1.1), inverterEfficiency_(0.96), + outputDCPower_(1000.0), cellTemperature_(-9999), planeOfArrayIrradiance_(-9999), shadedPercent_(0.0), + pvwattsModule_(ssc_module_create("pvwattsv5_1ts")), pvwattsData_(ssc_data_create()), NumTimeStepsToday_(0.0) { - assert(m_pvwattsModule != nullptr); + assert(pvwattsModule_ != nullptr); bool errorsFound(false); @@ -101,38 +101,38 @@ namespace PVWatts { ShowSevereError(state, "PVWatts: name cannot be blank."); errorsFound = true; } - m_name = name; + name_ = name; if (dcSystemCapacity <= 0) { ShowSevereError(state, "PVWatts: DC system capacity must be greater than zero."); errorsFound = true; } - m_dcSystemCapacity = dcSystemCapacity; + dcSystemCapacity_ = dcSystemCapacity; if (systemLosses > 1.0 || systemLosses < 0.0) { ShowSevereError(state, format("PVWatts: Invalid system loss value {:.2R}", systemLosses)); errorsFound = true; } - m_systemLosses = systemLosses; + systemLosses_ = systemLosses; - if (m_geometryType == GeometryType::TILT_AZIMUTH) { + if (geometryType_ == GeometryType::TILT_AZIMUTH) { if (tilt < 0 || tilt > 90) { ShowSevereError(state, format("PVWatts: Invalid tilt: {:.2R}", tilt)); errorsFound = true; } - m_tilt = tilt; + tilt_ = tilt; if (azimuth < 0 || azimuth >= 360) { ShowSevereError(state, format("PVWatts: Invalid azimuth: {:.2R}", azimuth)); } - m_azimuth = azimuth; - } else if (m_geometryType == GeometryType::SURFACE) { + azimuth_ = azimuth; + } else if (geometryType_ == GeometryType::SURFACE) { if (surfaceNum == 0 || surfaceNum > state.dataSurface->Surface.size()) { ShowSevereError(state, format("PVWatts: SurfaceNum not in Surfaces: {}", surfaceNum)); errorsFound = true; } else { - m_surfaceNum = surfaceNum; - m_tilt = getSurface(state).Tilt; - m_azimuth = getSurface(state).Azimuth; + surfaceNum_ = surfaceNum; + tilt_ = getSurface(state).Tilt; + azimuth_ = getSurface(state).Azimuth; // TODO: Do some bounds checking on Tilt and Azimuth. } } else { @@ -143,7 +143,7 @@ namespace PVWatts { ShowSevereError(state, format("PVWatts: Invalid ground coverage ratio: {:.2R}", groundCoverageRatio)); errorsFound = true; } - m_groundCoverageRatio = groundCoverageRatio; + groundCoverageRatio_ = groundCoverageRatio; if (errorsFound) { ShowFatalError(state, "Errors found in getting PVWatts input"); @@ -151,22 +151,22 @@ namespace PVWatts { // Initialize m_pvwattsData // Location - ssc_data_set_number(m_pvwattsData, "lat", state.dataWeatherManager->WeatherFileLatitude); - ssc_data_set_number(m_pvwattsData, "lon", state.dataWeatherManager->WeatherFileLongitude); - ssc_data_set_number(m_pvwattsData, "tz", state.dataWeatherManager->WeatherFileTimeZone); + ssc_data_set_number(pvwattsData_, "lat", state.dataWeatherManager->WeatherFileLatitude); + ssc_data_set_number(pvwattsData_, "lon", state.dataWeatherManager->WeatherFileLongitude); + ssc_data_set_number(pvwattsData_, "tz", state.dataWeatherManager->WeatherFileTimeZone); // System Properties - ssc_data_set_number(m_pvwattsData, "time_step", state.dataGlobal->TimeStepZone); - ssc_data_set_number(m_pvwattsData, "system_capacity", m_dcSystemCapacity * 0.001); - ssc_data_set_number(m_pvwattsData, "module_type", static_cast(m_moduleType)); - ssc_data_set_number(m_pvwattsData, "dc_ac_ratio", m_DCtoACRatio); - ssc_data_set_number(m_pvwattsData, "inv_eff", m_inverterEfficiency * 100.0); - ssc_data_set_number(m_pvwattsData, "losses", m_systemLosses * 100.0); - ssc_data_set_number(m_pvwattsData, "array_type", static_cast(m_arrayType)); - ssc_data_set_number(m_pvwattsData, "tilt", m_tilt); - ssc_data_set_number(m_pvwattsData, "azimuth", m_azimuth); - ssc_data_set_number(m_pvwattsData, "gcr", m_groundCoverageRatio); + ssc_data_set_number(pvwattsData_, "time_step", state.dataGlobal->TimeStepZone); + ssc_data_set_number(pvwattsData_, "system_capacity", dcSystemCapacity_ * 0.001); + ssc_data_set_number(pvwattsData_, "module_type", static_cast(moduleType_)); + ssc_data_set_number(pvwattsData_, "dc_ac_ratio", DCtoACRatio_); + ssc_data_set_number(pvwattsData_, "inv_eff", inverterEfficiency_ * 100.0); + ssc_data_set_number(pvwattsData_, "losses", systemLosses_ * 100.0); + ssc_data_set_number(pvwattsData_, "array_type", static_cast(arrayType_)); + ssc_data_set_number(pvwattsData_, "tilt", tilt_); + ssc_data_set_number(pvwattsData_, "azimuth", azimuth_); + ssc_data_set_number(pvwattsData_, "gcr", groundCoverageRatio_); // Initialize shaded percent - ssc_data_set_number(m_pvwattsData, "shaded_percent", m_shadedPercent); + ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_); } void PVWattsGenerator::setupOutputVariables(EnergyPlusData &state) @@ -175,17 +175,17 @@ namespace PVWatts { SetupOutputVariable(state, "Generator Produced DC Electricity Rate", OutputProcessor::Unit::W, - m_outputDCPower, + outputDCPower_, OutputProcessor::SOVTimeStepType::System, OutputProcessor::SOVStoreType::Average, - m_name); + name_); SetupOutputVariable(state, "Generator Produced DC Electricity Energy", OutputProcessor::Unit::J, - m_outputDCEnergy, + outputDCEnergy_, OutputProcessor::SOVTimeStepType::System, OutputProcessor::SOVStoreType::Summed, - m_name, + name_, _, "ElectricityProduced", "Photovoltaics", @@ -194,24 +194,24 @@ namespace PVWatts { SetupOutputVariable(state, "Generator PV Cell Temperature", OutputProcessor::Unit::C, - m_cellTemperature, + cellTemperature_, OutputProcessor::SOVTimeStepType::System, OutputProcessor::SOVStoreType::Average, - m_name); + name_); SetupOutputVariable(state, "Plane of Array Irradiance", OutputProcessor::Unit::W_m2, - m_planeOfArrayIrradiance, + planeOfArrayIrradiance_, OutputProcessor::SOVTimeStepType::System, OutputProcessor::SOVStoreType::Average, - m_name); + name_); SetupOutputVariable(state, "Shaded Percent", OutputProcessor::Unit::Perc, - m_shadedPercent, + shadedPercent_, OutputProcessor::SOVTimeStepType::System, OutputProcessor::SOVStoreType::Average, - m_name); + name_); } std::unique_ptr PVWattsGenerator::createFromIdfObj(EnergyPlusData &state, int objNum) @@ -311,77 +311,77 @@ namespace PVWatts { Real64 PVWattsGenerator::getDCSystemCapacity() { - return m_dcSystemCapacity; + return dcSystemCapacity_; } ModuleType PVWattsGenerator::getModuleType() { - return m_moduleType; + return moduleType_; } ArrayType PVWattsGenerator::getArrayType() { - return m_arrayType; + return arrayType_; } Real64 PVWattsGenerator::getSystemLosses() { - return m_systemLosses; + return systemLosses_; } GeometryType PVWattsGenerator::getGeometryType() { - return m_geometryType; + return geometryType_; } Real64 PVWattsGenerator::getTilt() { - return m_tilt; + return tilt_; } Real64 PVWattsGenerator::getAzimuth() { - return m_azimuth; + return azimuth_; } DataSurfaces::SurfaceData &PVWattsGenerator::getSurface(EnergyPlusData &state) { - return state.dataSurface->Surface(m_surfaceNum); + return state.dataSurface->Surface(surfaceNum_); } Real64 PVWattsGenerator::getGroundCoverageRatio() { - return m_groundCoverageRatio; + return groundCoverageRatio_; } Real64 PVWattsGenerator::getCellTemperature() { - return m_cellTemperature; + return cellTemperature_; } void PVWattsGenerator::setCellTemperature(Real64 cellTemp) { - m_cellTemperature = cellTemp; + cellTemperature_ = cellTemp; } Real64 PVWattsGenerator::getPlaneOfArrayIrradiance() { - return m_planeOfArrayIrradiance; + return planeOfArrayIrradiance_; } void PVWattsGenerator::setPlaneOfArrayIrradiance(Real64 poa) { - m_planeOfArrayIrradiance = poa; + planeOfArrayIrradiance_ = poa; } void PVWattsGenerator::setDCtoACRatio(Real64 const dc2ac) { - m_DCtoACRatio = dc2ac; + DCtoACRatio_ = dc2ac; } void PVWattsGenerator::setInverterEfficiency(Real64 const inverterEfficiency) { - m_inverterEfficiency = inverterEfficiency; + inverterEfficiency_ = inverterEfficiency; } void PVWattsGenerator::calc(EnergyPlusData &state) @@ -390,50 +390,50 @@ namespace PVWatts { // We only run this once for each zone time step. const int NumTimeStepsToday_loc = state.dataGlobal->HourOfDay * state.dataGlobal->NumOfTimeStepInHour + state.dataGlobal->TimeStep; - if (m_NumTimeStepsToday != NumTimeStepsToday_loc) { - m_NumTimeStepsToday = NumTimeStepsToday_loc; + if (NumTimeStepsToday_ != NumTimeStepsToday_loc) { + NumTimeStepsToday_ = NumTimeStepsToday_loc; } else { - m_outputDCEnergy = m_outputDCPower * TimeStepSys * DataGlobalConstants::SecInHour; - m_outputACEnergy = m_outputACPower * TimeStepSys * DataGlobalConstants::SecInHour; + outputDCEnergy_ = outputDCPower_ * TimeStepSys * DataGlobalConstants::SecInHour; + outputACEnergy_ = outputACPower_ * TimeStepSys * DataGlobalConstants::SecInHour; return; } // SSC Inputs // Time - ssc_data_set_number(m_pvwattsData, "year", state.dataEnvrn->Year); - ssc_data_set_number(m_pvwattsData, "month", state.dataEnvrn->Month); - ssc_data_set_number(m_pvwattsData, "day", state.dataEnvrn->DayOfMonth); - ssc_data_set_number(m_pvwattsData, "hour", state.dataGlobal->HourOfDay - 1); - ssc_data_set_number(m_pvwattsData, "minute", (state.dataGlobal->TimeStep - 0.5) * state.dataGlobal->MinutesPerTimeStep); + ssc_data_set_number(pvwattsData_, "year", state.dataEnvrn->Year); + ssc_data_set_number(pvwattsData_, "month", state.dataEnvrn->Month); + ssc_data_set_number(pvwattsData_, "day", state.dataEnvrn->DayOfMonth); + ssc_data_set_number(pvwattsData_, "hour", state.dataGlobal->HourOfDay - 1); + ssc_data_set_number(pvwattsData_, "minute", (state.dataGlobal->TimeStep - 0.5) * state.dataGlobal->MinutesPerTimeStep); // Weather Conditions - ssc_data_set_number(m_pvwattsData, "beam", state.dataEnvrn->BeamSolarRad); - ssc_data_set_number(m_pvwattsData, "diffuse", state.dataEnvrn->DifSolarRad); - ssc_data_set_number(m_pvwattsData, "tamb", state.dataEnvrn->OutDryBulbTemp); - ssc_data_set_number(m_pvwattsData, "wspd", state.dataEnvrn->WindSpeed); + ssc_data_set_number(pvwattsData_, "beam", state.dataEnvrn->BeamSolarRad); + ssc_data_set_number(pvwattsData_, "diffuse", state.dataEnvrn->DifSolarRad); + ssc_data_set_number(pvwattsData_, "tamb", state.dataEnvrn->OutDryBulbTemp); + ssc_data_set_number(pvwattsData_, "wspd", state.dataEnvrn->WindSpeed); Real64 albedo = state.dataWeatherManager->TodayAlbedo(state.dataGlobal->TimeStep, state.dataGlobal->HourOfDay); if (!(std::isfinite(albedo) && albedo > 0.0 && albedo < 1)) { albedo = 0.2; } - ssc_data_set_number(m_pvwattsData, "alb", albedo); + ssc_data_set_number(pvwattsData_, "alb", albedo); // In/Out Properties - ssc_data_set_number(m_pvwattsData, "tcell", m_cellTemperature); - ssc_data_set_number(m_pvwattsData, "poa", m_planeOfArrayIrradiance); + ssc_data_set_number(pvwattsData_, "tcell", cellTemperature_); + ssc_data_set_number(pvwattsData_, "poa", planeOfArrayIrradiance_); // Get the shading from the geometry, if applicable - if (m_geometryType == GeometryType::SURFACE) { - m_shadedPercent = - (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, m_surfaceNum)) * 100.0; - ssc_data_set_number(m_pvwattsData, "shaded_percent", m_shadedPercent); + if (geometryType_ == GeometryType::SURFACE) { + shadedPercent_ = + (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, surfaceNum_)) * 100.0; + ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_); } - if (ssc_module_exec(m_pvwattsModule, m_pvwattsData) == 0) { + if (ssc_module_exec(pvwattsModule_, pvwattsData_) == 0) { // Error const char *errtext; int sscErrType; float time; int i = 0; - while ((errtext = ssc_module_log(m_pvwattsModule, i++, &sscErrType, &time))) { + while ((errtext = ssc_module_log(pvwattsModule_, i++, &sscErrType, &time))) { std::string err("PVWatts: "); switch (sscErrType) { case SSC_WARNING: @@ -450,19 +450,19 @@ namespace PVWatts { } } else { // Report Out - ssc_data_get_number(m_pvwattsData, "dc", &m_outputDCPower); - m_outputDCEnergy = m_outputDCPower * TimeStepSys * DataGlobalConstants::SecInHour; - ssc_data_get_number(m_pvwattsData, "ac", &m_outputACPower); - m_outputACEnergy = m_outputACPower * TimeStepSys * DataGlobalConstants::SecInHour; - ssc_data_get_number(m_pvwattsData, "tcell", &m_cellTemperature); - ssc_data_get_number(m_pvwattsData, "poa", &m_planeOfArrayIrradiance); + ssc_data_get_number(pvwattsData_, "dc", &outputDCPower_); + outputDCEnergy_ = outputDCPower_ * TimeStepSys * DataGlobalConstants::SecInHour; + ssc_data_get_number(pvwattsData_, "ac", &outputACPower_); + outputACEnergy_ = outputACPower_ * TimeStepSys * DataGlobalConstants::SecInHour; + ssc_data_get_number(pvwattsData_, "tcell", &cellTemperature_); + ssc_data_get_number(pvwattsData_, "poa", &planeOfArrayIrradiance_); } } void PVWattsGenerator::getResults(Real64 &GeneratorPower, Real64 &GeneratorEnergy, Real64 &ThermalPower, Real64 &ThermalEnergy) { - GeneratorPower = m_outputDCPower; - GeneratorEnergy = m_outputDCEnergy; + GeneratorPower = outputDCPower_; + GeneratorEnergy = outputDCEnergy_; ThermalPower = 0.0; ThermalEnergy = 0.0; } diff --git a/src/EnergyPlus/PVWatts.hh b/src/EnergyPlus/PVWatts.hh index 5e8d29e1042..711466d604a 100644 --- a/src/EnergyPlus/PVWatts.hh +++ b/src/EnergyPlus/PVWatts.hh @@ -143,31 +143,31 @@ namespace PVWatts { }; // User inputs - std::string m_name; - Real64 m_dcSystemCapacity; - ModuleType m_moduleType; - ArrayType m_arrayType; - Real64 m_systemLosses; - GeometryType m_geometryType; - Real64 m_tilt; - Real64 m_azimuth; - int m_surfaceNum; - Real64 m_groundCoverageRatio; - Real64 m_DCtoACRatio; - Real64 m_inverterEfficiency; + std::string name_; + Real64 dcSystemCapacity_; + ModuleType moduleType_; + ArrayType arrayType_; + Real64 systemLosses_; + GeometryType geometryType_; + Real64 tilt_; + Real64 azimuth_; + int surfaceNum_; + Real64 groundCoverageRatio_; + Real64 DCtoACRatio_; + Real64 inverterEfficiency_; // Output variables - Real64 m_outputDCPower; - Real64 m_outputDCEnergy; - Real64 m_outputACPower; - Real64 m_outputACEnergy; - Real64 m_cellTemperature; - Real64 m_planeOfArrayIrradiance; - Real64 m_shadedPercent; - - ssc_module_t m_pvwattsModule; - ssc_data_t m_pvwattsData; - Real64 m_NumTimeStepsToday; + Real64 outputDCPower_; + Real64 outputDCEnergy_; + Real64 outputACPower_; + Real64 outputACEnergy_; + Real64 cellTemperature_; + Real64 planeOfArrayIrradiance_; + Real64 shadedPercent_; + + ssc_module_t pvwattsModule_; + ssc_data_t pvwattsData_; + Real64 NumTimeStepsToday_; public: static std::unique_ptr createFromIdfObj(EnergyPlusData &state, int objNum); From 6a357a23f8707327c6ca64e82f796428d7993aaf Mon Sep 17 00:00:00 2001 From: Edwin Lee Date: Sat, 21 Aug 2021 16:06:20 -0500 Subject: [PATCH 9/9] Clang formatting --- src/EnergyPlus/PVWatts.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/EnergyPlus/PVWatts.cc b/src/EnergyPlus/PVWatts.cc index 635709a7390..a378d0c9e16 100644 --- a/src/EnergyPlus/PVWatts.cc +++ b/src/EnergyPlus/PVWatts.cc @@ -422,8 +422,7 @@ namespace PVWatts { // Get the shading from the geometry, if applicable if (geometryType_ == GeometryType::SURFACE) { - shadedPercent_ = - (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, surfaceNum_)) * 100.0; + shadedPercent_ = (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, surfaceNum_)) * 100.0; ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_); }