LCOV - code coverage report
Current view: top level - EnergyPlus - PVWatts.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 142 204 69.6 %
Date: 2023-01-17 19:17:23 Functions: 11 22 50.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, The Board of Trustees of the University of Illinois,
       2             : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3             : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4             : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5             : // contributors. All rights reserved.
       6             : //
       7             : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8             : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9             : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10             : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11             : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12             : //
      13             : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14             : // provided that the following conditions are met:
      15             : //
      16             : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17             : //     conditions and the following disclaimer.
      18             : //
      19             : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20             : //     conditions and the following disclaimer in the documentation and/or other materials
      21             : //     provided with the distribution.
      22             : //
      23             : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24             : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25             : //     used to endorse or promote products derived from this software without specific prior
      26             : //     written permission.
      27             : //
      28             : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29             : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30             : //     reference solely to the software portion of its product, Licensee must refer to the
      31             : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32             : //     obtained under this License and may not use a different name for the software. Except as
      33             : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34             : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35             : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36             : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37             : //
      38             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39             : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40             : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41             : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42             : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43             : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45             : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46             : // POSSIBILITY OF SUCH DAMAGE.
      47             : 
      48             : // C++ Headers
      49             : #include <math.h>
      50             : #include <stdexcept>
      51             : 
      52             : // ObjexxFCL Headers
      53             : 
      54             : // EnergyPlus Headers
      55             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      56             : #include <EnergyPlus/DataEnvironment.hh>
      57             : #include <EnergyPlus/DataHVACGlobals.hh>
      58             : #include <EnergyPlus/DataHeatBalance.hh>
      59             : #include <EnergyPlus/DataIPShortCuts.hh>
      60             : #include <EnergyPlus/ElectricPowerServiceManager.hh>
      61             : #include <EnergyPlus/General.hh>
      62             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      63             : #include <EnergyPlus/OutputProcessor.hh>
      64             : #include <EnergyPlus/PVWatts.hh>
      65             : #include <EnergyPlus/UtilityRoutines.hh>
      66             : #include <EnergyPlus/WeatherManager.hh>
      67             : 
      68             : // SAM Headers
      69             : //#include <../third_party/ssc/shared/lib_irradproc.h>
      70             : //#include <../third_party/ssc/shared/lib_pvwatts.h>
      71             : //#include <../third_party/ssc/shared/lib_pvshade.h>
      72             : //#include <../third_party/ssc/shared/lib_pv_incidence_modifier.h>
      73             : #include <../third_party/ssc/ssc/sscapi.h>
      74             : 
      75             : namespace EnergyPlus {
      76             : 
      77             : namespace PVWatts {
      78             : 
      79           3 :     PVWattsGenerator::PVWattsGenerator(EnergyPlusData &state,
      80             :                                        const std::string &name,
      81             :                                        const Real64 dcSystemCapacity,
      82             :                                        ModuleType moduleType,
      83             :                                        ArrayType arrayType,
      84             :                                        Real64 systemLosses,
      85             :                                        GeometryType geometryType,
      86             :                                        Real64 tilt,
      87             :                                        Real64 azimuth,
      88             :                                        size_t surfaceNum,
      89           3 :                                        Real64 groundCoverageRatio)
      90             :         : moduleType_(moduleType), arrayType_(arrayType), geometryType_(geometryType), DCtoACRatio_(1.1), inverterEfficiency_(0.96),
      91             :           outputDCPower_(1000.0), cellTemperature_(-9999), planeOfArrayIrradiance_(-9999), shadedPercent_(0.0),
      92           3 :           pvwattsModule_(ssc_module_create("pvwattsv5_1ts")), pvwattsData_(ssc_data_create()), NumTimeStepsToday_(0.0)
      93             : 
      94             :     {
      95             : 
      96           3 :         assert(pvwattsModule_ != nullptr);
      97             : 
      98           3 :         bool errorsFound(false);
      99             : 
     100           3 :         if (name.empty()) {
     101           0 :             ShowSevereError(state, "PVWatts: name cannot be blank.");
     102           0 :             errorsFound = true;
     103             :         }
     104           3 :         name_ = name;
     105             : 
     106           3 :         if (dcSystemCapacity <= 0) {
     107           0 :             ShowSevereError(state, "PVWatts: DC system capacity must be greater than zero.");
     108           0 :             errorsFound = true;
     109             :         }
     110           3 :         dcSystemCapacity_ = dcSystemCapacity;
     111             : 
     112           3 :         if (systemLosses > 1.0 || systemLosses < 0.0) {
     113           0 :             ShowSevereError(state, format("PVWatts: Invalid system loss value {:.2R}", systemLosses));
     114           0 :             errorsFound = true;
     115             :         }
     116           3 :         systemLosses_ = systemLosses;
     117             : 
     118           3 :         if (geometryType_ == GeometryType::TILT_AZIMUTH) {
     119           1 :             if (tilt < 0 || tilt > 90) {
     120           0 :                 ShowSevereError(state, format("PVWatts: Invalid tilt: {:.2R}", tilt));
     121           0 :                 errorsFound = true;
     122             :             }
     123           1 :             tilt_ = tilt;
     124           1 :             if (azimuth < 0 || azimuth >= 360) {
     125           0 :                 ShowSevereError(state, format("PVWatts: Invalid azimuth: {:.2R}", azimuth));
     126             :             }
     127           1 :             azimuth_ = azimuth;
     128           2 :         } else if (geometryType_ == GeometryType::SURFACE) {
     129           2 :             if (surfaceNum == 0 || surfaceNum > state.dataSurface->Surface.size()) {
     130           0 :                 ShowSevereError(state, format("PVWatts: SurfaceNum not in Surfaces: {}", surfaceNum));
     131           0 :                 errorsFound = true;
     132             :             } else {
     133           2 :                 surfaceNum_ = surfaceNum;
     134           2 :                 tilt_ = getSurface(state).Tilt;
     135           2 :                 azimuth_ = getSurface(state).Azimuth;
     136             :                 // TODO: Do some bounds checking on Tilt and Azimuth.
     137             :             }
     138             :         } else {
     139           0 :             assert(false);
     140             :         }
     141             : 
     142           3 :         if (groundCoverageRatio > 1.0 || groundCoverageRatio < 0.0) {
     143           0 :             ShowSevereError(state, format("PVWatts: Invalid ground coverage ratio: {:.2R}", groundCoverageRatio));
     144           0 :             errorsFound = true;
     145             :         }
     146           3 :         groundCoverageRatio_ = groundCoverageRatio;
     147             : 
     148           3 :         if (errorsFound) {
     149           0 :             ShowFatalError(state, "Errors found in getting PVWatts input");
     150             :         }
     151             : 
     152             :         // Initialize m_pvwattsData
     153             :         // Location
     154           3 :         ssc_data_set_number(pvwattsData_, "lat", state.dataWeatherManager->WeatherFileLatitude);
     155           3 :         ssc_data_set_number(pvwattsData_, "lon", state.dataWeatherManager->WeatherFileLongitude);
     156           3 :         ssc_data_set_number(pvwattsData_, "tz", state.dataWeatherManager->WeatherFileTimeZone);
     157             :         // System Properties
     158           3 :         ssc_data_set_number(pvwattsData_, "time_step", state.dataGlobal->TimeStepZone);
     159           3 :         ssc_data_set_number(pvwattsData_, "system_capacity", dcSystemCapacity_ * 0.001);
     160           3 :         ssc_data_set_number(pvwattsData_, "module_type", static_cast<int>(moduleType_));
     161           3 :         ssc_data_set_number(pvwattsData_, "dc_ac_ratio", DCtoACRatio_);
     162           3 :         ssc_data_set_number(pvwattsData_, "inv_eff", inverterEfficiency_ * 100.0);
     163           3 :         ssc_data_set_number(pvwattsData_, "losses", systemLosses_ * 100.0);
     164           3 :         ssc_data_set_number(pvwattsData_, "array_type", static_cast<int>(arrayType_));
     165           3 :         ssc_data_set_number(pvwattsData_, "tilt", tilt_);
     166           3 :         ssc_data_set_number(pvwattsData_, "azimuth", azimuth_);
     167           3 :         ssc_data_set_number(pvwattsData_, "gcr", groundCoverageRatio_);
     168             :         // Initialize shaded percent
     169           3 :         ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_);
     170           3 :     }
     171             : 
     172           3 :     void PVWattsGenerator::setupOutputVariables(EnergyPlusData &state)
     173             :     {
     174             :         // Set up output variables
     175           6 :         SetupOutputVariable(state,
     176             :                             "Generator Produced DC Electricity Rate",
     177             :                             OutputProcessor::Unit::W,
     178             :                             outputDCPower_,
     179             :                             OutputProcessor::SOVTimeStepType::System,
     180             :                             OutputProcessor::SOVStoreType::Average,
     181           3 :                             name_);
     182           6 :         SetupOutputVariable(state,
     183             :                             "Generator Produced DC Electricity Energy",
     184             :                             OutputProcessor::Unit::J,
     185             :                             outputDCEnergy_,
     186             :                             OutputProcessor::SOVTimeStepType::System,
     187             :                             OutputProcessor::SOVStoreType::Summed,
     188             :                             name_,
     189             :                             _,
     190             :                             "ElectricityProduced",
     191             :                             "Photovoltaics",
     192             :                             _,
     193           3 :                             "Plant");
     194           6 :         SetupOutputVariable(state,
     195             :                             "Generator PV Cell Temperature",
     196             :                             OutputProcessor::Unit::C,
     197             :                             cellTemperature_,
     198             :                             OutputProcessor::SOVTimeStepType::System,
     199             :                             OutputProcessor::SOVStoreType::Average,
     200           3 :                             name_);
     201           6 :         SetupOutputVariable(state,
     202             :                             "Plane of Array Irradiance",
     203             :                             OutputProcessor::Unit::W_m2,
     204             :                             planeOfArrayIrradiance_,
     205             :                             OutputProcessor::SOVTimeStepType::System,
     206             :                             OutputProcessor::SOVStoreType::Average,
     207           3 :                             name_);
     208           6 :         SetupOutputVariable(state,
     209             :                             "Shaded Percent",
     210             :                             OutputProcessor::Unit::Perc,
     211             :                             shadedPercent_,
     212             :                             OutputProcessor::SOVTimeStepType::System,
     213             :                             OutputProcessor::SOVStoreType::Average,
     214           3 :                             name_);
     215           3 :     }
     216             : 
     217           3 :     std::unique_ptr<PVWattsGenerator> PVWattsGenerator::createFromIdfObj(EnergyPlusData &state, int objNum)
     218             :     {
     219           6 :         Array1D_string cAlphaFieldNames;
     220           6 :         Array1D_string cNumericFieldNames;
     221           6 :         Array1D_bool lNumericFieldBlanks;
     222           6 :         Array1D_bool lAlphaFieldBlanks;
     223           6 :         Array1D_string cAlphaArgs;
     224           6 :         Array1D<Real64> rNumericArgs;
     225           3 :         constexpr int maxAlphas = 6;  // from idd
     226           3 :         constexpr int maxNumeric = 5; // from idd
     227           3 :         cAlphaFieldNames.allocate(maxAlphas);
     228           3 :         cNumericFieldNames.allocate(maxNumeric);
     229           3 :         lNumericFieldBlanks.allocate(maxNumeric);
     230           3 :         lAlphaFieldBlanks.allocate(maxAlphas);
     231           3 :         cAlphaArgs.allocate(maxAlphas);
     232           3 :         rNumericArgs.allocate(maxNumeric);
     233             :         int NumAlphas;
     234             :         int NumNums;
     235             :         int IOStat;
     236           3 :         bool errorsFound = false;
     237             : 
     238           6 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
     239             :                                                                  "Generator:PVWatts",
     240             :                                                                  objNum,
     241             :                                                                  cAlphaArgs,
     242             :                                                                  NumAlphas,
     243             :                                                                  rNumericArgs,
     244             :                                                                  NumNums,
     245             :                                                                  IOStat,
     246             :                                                                  lNumericFieldBlanks,
     247             :                                                                  lAlphaFieldBlanks,
     248             :                                                                  cAlphaFieldNames,
     249           3 :                                                                  cNumericFieldNames);
     250             : 
     251           6 :         const std::string name(cAlphaArgs(AlphaFields::NAME));
     252           3 :         const Real64 dcSystemCapacity(rNumericArgs(NumFields::DC_SYSTEM_CAPACITY));
     253             :         const std::map<std::string, ModuleType> moduleTypeMap = {
     254           6 :             {"STANDARD", ModuleType::STANDARD}, {"PREMIUM", ModuleType::PREMIUM}, {"THINFILM", ModuleType::THIN_FILM}};
     255             :         ModuleType moduleType;
     256           6 :         auto moduleTypeIt = moduleTypeMap.find(cAlphaArgs(AlphaFields::MODULE_TYPE));
     257           3 :         if (moduleTypeIt == moduleTypeMap.end()) {
     258           0 :             ShowSevereError(state, "PVWatts: Invalid Module Type: " + cAlphaArgs(AlphaFields::MODULE_TYPE));
     259           0 :             errorsFound = true;
     260             :         } else {
     261           3 :             moduleType = moduleTypeIt->second;
     262             :         }
     263             : 
     264             :         const std::map<std::string, ArrayType> arrayTypeMap = {{"FIXEDOPENRACK", ArrayType::FIXED_OPEN_RACK},
     265             :                                                                {"FIXEDROOFMOUNTED", ArrayType::FIXED_ROOF_MOUNTED},
     266             :                                                                {"ONEAXIS", ArrayType::ONE_AXIS},
     267             :                                                                {"ONEAXISBACKTRACKING", ArrayType::ONE_AXIS_BACKTRACKING},
     268           6 :                                                                {"TWOAXIS", ArrayType::TWO_AXIS}};
     269             :         ArrayType arrayType;
     270           6 :         auto arrayTypeIt = arrayTypeMap.find(cAlphaArgs(AlphaFields::ARRAY_TYPE));
     271           3 :         if (arrayTypeIt == arrayTypeMap.end()) {
     272           0 :             ShowSevereError(state, "PVWatts: Invalid Array Type: " + cAlphaArgs(AlphaFields::ARRAY_TYPE));
     273           0 :             errorsFound = true;
     274             :         } else {
     275           3 :             arrayType = arrayTypeIt->second;
     276             :         }
     277             : 
     278           3 :         const Real64 systemLosses(rNumericArgs(NumFields::SYSTEM_LOSSES));
     279           6 :         const std::map<std::string, GeometryType> geometryTypeMap{{"TILTAZIMUTH", GeometryType::TILT_AZIMUTH}, {"SURFACE", GeometryType::SURFACE}};
     280             :         GeometryType geometryType;
     281           6 :         auto geometryTypeIt = geometryTypeMap.find(cAlphaArgs(AlphaFields::GEOMETRY_TYPE));
     282           3 :         if (geometryTypeIt == geometryTypeMap.end()) {
     283           0 :             ShowSevereError(state, "PVWatts: Invalid Geometry Type: " + cAlphaArgs(AlphaFields::GEOMETRY_TYPE));
     284           0 :             errorsFound = true;
     285             :         } else {
     286           3 :             geometryType = geometryTypeIt->second;
     287             :         }
     288             : 
     289           3 :         const Real64 tilt(rNumericArgs(NumFields::TILT_ANGLE));
     290           3 :         const Real64 azimuth(rNumericArgs(NumFields::AZIMUTH_ANGLE));
     291             :         int surfaceNum;
     292           3 :         if (lAlphaFieldBlanks(AlphaFields::SURFACE_NAME)) {
     293           1 :             surfaceNum = 0;
     294             :         } else {
     295           2 :             surfaceNum = UtilityRoutines::FindItemInList(cAlphaArgs(AlphaFields::SURFACE_NAME), state.dataSurface->Surface);
     296             :         }
     297             : 
     298           3 :         if (errorsFound) {
     299           0 :             ShowFatalError(state, "Errors found in getting PVWatts input");
     300             :         }
     301             : 
     302           3 :         if (NumNums < NumFields::GROUND_COVERAGE_RATIO) {
     303             :             return std::make_unique<PVWattsGenerator>(
     304           3 :                 state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, 0.4);
     305             :         }
     306           0 :         const Real64 groundCoverageRatio(rNumericArgs(NumFields::GROUND_COVERAGE_RATIO));
     307             : 
     308             :         return std::make_unique<PVWattsGenerator>(
     309           0 :             state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, groundCoverageRatio);
     310             :     }
     311             : 
     312           3 :     Real64 PVWattsGenerator::getDCSystemCapacity()
     313             :     {
     314           3 :         return dcSystemCapacity_;
     315             :     }
     316             : 
     317           0 :     ModuleType PVWattsGenerator::getModuleType()
     318             :     {
     319           0 :         return moduleType_;
     320             :     }
     321             : 
     322           0 :     ArrayType PVWattsGenerator::getArrayType()
     323             :     {
     324           0 :         return arrayType_;
     325             :     }
     326             : 
     327           0 :     Real64 PVWattsGenerator::getSystemLosses()
     328             :     {
     329           0 :         return systemLosses_;
     330             :     }
     331             : 
     332           0 :     GeometryType PVWattsGenerator::getGeometryType()
     333             :     {
     334           0 :         return geometryType_;
     335             :     }
     336             : 
     337           0 :     Real64 PVWattsGenerator::getTilt()
     338             :     {
     339           0 :         return tilt_;
     340             :     }
     341             : 
     342           0 :     Real64 PVWattsGenerator::getAzimuth()
     343             :     {
     344           0 :         return azimuth_;
     345             :     }
     346             : 
     347           4 :     DataSurfaces::SurfaceData &PVWattsGenerator::getSurface(EnergyPlusData &state)
     348             :     {
     349           4 :         return state.dataSurface->Surface(surfaceNum_);
     350             :     }
     351             : 
     352           0 :     Real64 PVWattsGenerator::getGroundCoverageRatio()
     353             :     {
     354           0 :         return groundCoverageRatio_;
     355             :     }
     356             : 
     357           0 :     Real64 PVWattsGenerator::getCellTemperature()
     358             :     {
     359           0 :         return cellTemperature_;
     360             :     }
     361             : 
     362           0 :     void PVWattsGenerator::setCellTemperature(Real64 cellTemp)
     363             :     {
     364           0 :         cellTemperature_ = cellTemp;
     365           0 :     }
     366             : 
     367           0 :     Real64 PVWattsGenerator::getPlaneOfArrayIrradiance()
     368             :     {
     369           0 :         return planeOfArrayIrradiance_;
     370             :     }
     371             : 
     372           0 :     void PVWattsGenerator::setPlaneOfArrayIrradiance(Real64 poa)
     373             :     {
     374           0 :         planeOfArrayIrradiance_ = poa;
     375           0 :     }
     376             : 
     377           3 :     void PVWattsGenerator::setDCtoACRatio(Real64 const dc2ac)
     378             :     {
     379           3 :         DCtoACRatio_ = dc2ac;
     380           3 :     }
     381             : 
     382           3 :     void PVWattsGenerator::setInverterEfficiency(Real64 const inverterEfficiency)
     383             :     {
     384           3 :         inverterEfficiency_ = inverterEfficiency;
     385           3 :     }
     386             : 
     387        6624 :     void PVWattsGenerator::calc(EnergyPlusData &state)
     388             :     {
     389        6624 :         auto &TimeStepSys = state.dataHVACGlobal->TimeStepSys;
     390             : 
     391             :         // We only run this once for each zone time step.
     392        6624 :         const int NumTimeStepsToday_loc = state.dataGlobal->HourOfDay * state.dataGlobal->NumOfTimeStepInHour + state.dataGlobal->TimeStep;
     393        6624 :         if (NumTimeStepsToday_ != NumTimeStepsToday_loc) {
     394        1530 :             NumTimeStepsToday_ = NumTimeStepsToday_loc;
     395             :         } else {
     396        5094 :             outputDCEnergy_ = outputDCPower_ * TimeStepSys * DataGlobalConstants::SecInHour;
     397        5094 :             outputACEnergy_ = outputACPower_ * TimeStepSys * DataGlobalConstants::SecInHour;
     398        5094 :             return;
     399             :         }
     400             :         // SSC Inputs
     401             :         // Time
     402        1530 :         ssc_data_set_number(pvwattsData_, "year", state.dataEnvrn->Year);
     403        1530 :         ssc_data_set_number(pvwattsData_, "month", state.dataEnvrn->Month);
     404        1530 :         ssc_data_set_number(pvwattsData_, "day", state.dataEnvrn->DayOfMonth);
     405        1530 :         ssc_data_set_number(pvwattsData_, "hour", state.dataGlobal->HourOfDay - 1);
     406        1530 :         ssc_data_set_number(pvwattsData_, "minute", (state.dataGlobal->TimeStep - 0.5) * state.dataGlobal->MinutesPerTimeStep);
     407             : 
     408             :         // Weather Conditions
     409        1530 :         ssc_data_set_number(pvwattsData_, "beam", state.dataEnvrn->BeamSolarRad);
     410        1530 :         ssc_data_set_number(pvwattsData_, "diffuse", state.dataEnvrn->DifSolarRad);
     411        1530 :         ssc_data_set_number(pvwattsData_, "tamb", state.dataEnvrn->OutDryBulbTemp);
     412        1530 :         ssc_data_set_number(pvwattsData_, "wspd", state.dataEnvrn->WindSpeed);
     413        1530 :         Real64 albedo = state.dataWeatherManager->TodayAlbedo(state.dataGlobal->TimeStep, state.dataGlobal->HourOfDay);
     414        1530 :         if (!(std::isfinite(albedo) && albedo > 0.0 && albedo < 1)) {
     415        1530 :             albedo = 0.2;
     416             :         }
     417        1530 :         ssc_data_set_number(pvwattsData_, "alb", albedo);
     418             : 
     419             :         // In/Out Properties
     420        1530 :         ssc_data_set_number(pvwattsData_, "tcell", cellTemperature_);
     421        1530 :         ssc_data_set_number(pvwattsData_, "poa", planeOfArrayIrradiance_);
     422             : 
     423             :         // Get the shading from the geometry, if applicable
     424        1530 :         if (geometryType_ == GeometryType::SURFACE) {
     425        1020 :             shadedPercent_ = (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, surfaceNum_)) * 100.0;
     426        1020 :             ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_);
     427             :         }
     428             : 
     429        1530 :         if (ssc_module_exec(pvwattsModule_, pvwattsData_) == 0) {
     430             :             // Error
     431             :             const char *errtext;
     432             :             int sscErrType;
     433             :             float time;
     434           0 :             int i = 0;
     435           0 :             while ((errtext = ssc_module_log(pvwattsModule_, i++, &sscErrType, &time))) {
     436           0 :                 std::string err("PVWatts: ");
     437           0 :                 switch (sscErrType) {
     438           0 :                 case SSC_WARNING:
     439           0 :                     err.append(errtext);
     440           0 :                     ShowWarningMessage(state, err);
     441           0 :                     break;
     442           0 :                 case SSC_ERROR:
     443           0 :                     err.append(errtext);
     444           0 :                     ShowErrorMessage(state, err);
     445           0 :                     break;
     446           0 :                 default:
     447           0 :                     break;
     448             :                 }
     449             :             }
     450             :         } else {
     451             :             // Report Out
     452        1530 :             ssc_data_get_number(pvwattsData_, "dc", &outputDCPower_);
     453        1530 :             outputDCEnergy_ = outputDCPower_ * TimeStepSys * DataGlobalConstants::SecInHour;
     454        1530 :             ssc_data_get_number(pvwattsData_, "ac", &outputACPower_);
     455        1530 :             outputACEnergy_ = outputACPower_ * TimeStepSys * DataGlobalConstants::SecInHour;
     456        1530 :             ssc_data_get_number(pvwattsData_, "tcell", &cellTemperature_);
     457        1530 :             ssc_data_get_number(pvwattsData_, "poa", &planeOfArrayIrradiance_);
     458             :         }
     459             :     }
     460             : 
     461        6624 :     void PVWattsGenerator::getResults(Real64 &GeneratorPower, Real64 &GeneratorEnergy, Real64 &ThermalPower, Real64 &ThermalEnergy)
     462             :     {
     463        6624 :         GeneratorPower = outputDCPower_;
     464        6624 :         GeneratorEnergy = outputDCEnergy_;
     465        6624 :         ThermalPower = 0.0;
     466        6624 :         ThermalEnergy = 0.0;
     467        6624 :     }
     468             : 
     469             : } // namespace PVWatts
     470             : 
     471        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13