LCOV - code coverage report
Current view: top level - EnergyPlus - PVWatts.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 149 216 69.0 %
Date: 2024-08-24 18:31:18 Functions: 9 20 45.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2024, 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           3 :         : moduleType_(moduleType), arrayType_(arrayType), geometryType_(geometryType), DCtoACRatio_(1.1), inverterEfficiency_(0.96),
      91           3 :           outputDCPower_(1000.0), outputDCEnergy_(0.0), outputACPower_(0.0), outputACEnergy_(0.0), cellTemperature_(-9999),
      92           3 :           planeOfArrayIrradiance_(-9999), shadedPercent_(0.0), pvwattsModule_(ssc_module_create("pvwattsv5_1ts")), pvwattsData_(ssc_data_create()),
      93           3 :           NumTimeStepsToday_(0.0)
      94             : 
      95             :     {
      96             : 
      97           3 :         assert(pvwattsModule_ != nullptr);
      98             : 
      99           3 :         bool errorsFound(false);
     100             : 
     101           3 :         if (name.empty()) {
     102           0 :             ShowSevereError(state, "PVWatts: name cannot be blank.");
     103           0 :             errorsFound = true;
     104             :         }
     105           3 :         name_ = name;
     106             : 
     107           3 :         if (dcSystemCapacity <= 0) {
     108           0 :             ShowSevereError(state, "PVWatts: DC system capacity must be greater than zero.");
     109           0 :             errorsFound = true;
     110             :         }
     111           3 :         dcSystemCapacity_ = dcSystemCapacity;
     112             : 
     113           3 :         if (systemLosses > 1.0 || systemLosses < 0.0) {
     114           0 :             ShowSevereError(state, format("PVWatts: Invalid system loss value {:.2R}", systemLosses));
     115           0 :             errorsFound = true;
     116             :         }
     117           3 :         systemLosses_ = systemLosses;
     118             : 
     119           3 :         if (geometryType_ == GeometryType::TILT_AZIMUTH) {
     120           1 :             if (tilt < 0 || tilt > 90) {
     121           0 :                 ShowSevereError(state, format("PVWatts: Invalid tilt: {:.2R}", tilt));
     122           0 :                 errorsFound = true;
     123             :             }
     124           1 :             tilt_ = tilt;
     125           1 :             if (azimuth < 0 || azimuth >= 360) {
     126           0 :                 ShowSevereError(state, format("PVWatts: Invalid azimuth: {:.2R}", azimuth));
     127             :             }
     128           1 :             azimuth_ = azimuth;
     129           2 :         } else if (geometryType_ == GeometryType::SURFACE) {
     130           2 :             if (surfaceNum == 0 || surfaceNum > state.dataSurface->Surface.size()) {
     131           0 :                 ShowSevereError(state, format("PVWatts: SurfaceNum not in Surfaces: {}", surfaceNum));
     132           0 :                 errorsFound = true;
     133             :             } else {
     134           2 :                 surfaceNum_ = surfaceNum;
     135           2 :                 tilt_ = getSurface(state).Tilt;
     136           2 :                 azimuth_ = getSurface(state).Azimuth;
     137             :                 // TODO: Do some bounds checking on Tilt and Azimuth.
     138             :             }
     139             :         } else {
     140           0 :             assert(false);
     141             :         }
     142             : 
     143           3 :         if (groundCoverageRatio > 1.0 || groundCoverageRatio < 0.0) {
     144           0 :             ShowSevereError(state, format("PVWatts: Invalid ground coverage ratio: {:.2R}", groundCoverageRatio));
     145           0 :             errorsFound = true;
     146             :         }
     147           3 :         groundCoverageRatio_ = groundCoverageRatio;
     148             : 
     149           3 :         if (errorsFound) {
     150           0 :             ShowFatalError(state, "Errors found in getting PVWatts input");
     151             :         }
     152             : 
     153             :         // Initialize m_pvwattsData
     154             :         // Location
     155           3 :         ssc_data_set_number(pvwattsData_, "lat", state.dataWeather->WeatherFileLatitude);
     156           3 :         ssc_data_set_number(pvwattsData_, "lon", state.dataWeather->WeatherFileLongitude);
     157           3 :         ssc_data_set_number(pvwattsData_, "tz", state.dataWeather->WeatherFileTimeZone);
     158             :         // System Properties
     159           3 :         ssc_data_set_number(pvwattsData_, "time_step", state.dataGlobal->TimeStepZone);
     160           3 :         ssc_data_set_number(pvwattsData_, "system_capacity", dcSystemCapacity_ * 0.001);
     161           3 :         ssc_data_set_number(pvwattsData_, "module_type", static_cast<int>(moduleType_));
     162           3 :         ssc_data_set_number(pvwattsData_, "dc_ac_ratio", DCtoACRatio_);
     163           3 :         ssc_data_set_number(pvwattsData_, "inv_eff", inverterEfficiency_ * 100.0);
     164           3 :         ssc_data_set_number(pvwattsData_, "losses", systemLosses_ * 100.0);
     165           3 :         ssc_data_set_number(pvwattsData_, "array_type", static_cast<int>(arrayType_));
     166           3 :         ssc_data_set_number(pvwattsData_, "tilt", tilt_);
     167           3 :         ssc_data_set_number(pvwattsData_, "azimuth", azimuth_);
     168           3 :         ssc_data_set_number(pvwattsData_, "gcr", groundCoverageRatio_);
     169             :         // Initialize shaded percent
     170           3 :         ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_);
     171           3 :     }
     172             : 
     173           3 :     void PVWattsGenerator::setupOutputVariables(EnergyPlusData &state)
     174             :     {
     175             :         // Set up output variables
     176           6 :         SetupOutputVariable(state,
     177             :                             "Generator Produced DC Electricity Rate",
     178             :                             Constant::Units::W,
     179           3 :                             outputDCPower_,
     180             :                             OutputProcessor::TimeStepType::System,
     181             :                             OutputProcessor::StoreType::Average,
     182           3 :                             name_);
     183           6 :         SetupOutputVariable(state,
     184             :                             "Generator Produced DC Electricity Energy",
     185             :                             Constant::Units::J,
     186           3 :                             outputDCEnergy_,
     187             :                             OutputProcessor::TimeStepType::System,
     188             :                             OutputProcessor::StoreType::Sum,
     189           3 :                             name_,
     190             :                             Constant::eResource::ElectricityProduced,
     191             :                             OutputProcessor::Group::Plant,
     192             :                             OutputProcessor::EndUseCat::Photovoltaic);
     193           6 :         SetupOutputVariable(state,
     194             :                             "Generator PV Cell Temperature",
     195             :                             Constant::Units::C,
     196           3 :                             cellTemperature_,
     197             :                             OutputProcessor::TimeStepType::System,
     198             :                             OutputProcessor::StoreType::Average,
     199           3 :                             name_);
     200           6 :         SetupOutputVariable(state,
     201             :                             "Plane of Array Irradiance",
     202             :                             Constant::Units::W_m2,
     203           3 :                             planeOfArrayIrradiance_,
     204             :                             OutputProcessor::TimeStepType::System,
     205             :                             OutputProcessor::StoreType::Average,
     206           3 :                             name_);
     207           6 :         SetupOutputVariable(state,
     208             :                             "Shaded Percent",
     209             :                             Constant::Units::Perc,
     210           3 :                             shadedPercent_,
     211             :                             OutputProcessor::TimeStepType::System,
     212             :                             OutputProcessor::StoreType::Average,
     213           3 :                             name_);
     214           3 :     }
     215             : 
     216           3 :     std::unique_ptr<PVWattsGenerator> PVWattsGenerator::createFromIdfObj(EnergyPlusData &state, int objNum)
     217             :     {
     218           3 :         Array1D_string cAlphaFieldNames;
     219           3 :         Array1D_string cNumericFieldNames;
     220           3 :         Array1D_bool lNumericFieldBlanks;
     221           3 :         Array1D_bool lAlphaFieldBlanks;
     222           3 :         Array1D_string cAlphaArgs;
     223           3 :         Array1D<Real64> rNumericArgs;
     224           3 :         constexpr int maxAlphas = 6;  // from idd
     225           3 :         constexpr int maxNumeric = 5; // from idd
     226           3 :         cAlphaFieldNames.allocate(maxAlphas);
     227           3 :         cNumericFieldNames.allocate(maxNumeric);
     228           3 :         lNumericFieldBlanks.allocate(maxNumeric);
     229           3 :         lAlphaFieldBlanks.allocate(maxAlphas);
     230           3 :         cAlphaArgs.allocate(maxAlphas);
     231           3 :         rNumericArgs.allocate(maxNumeric);
     232             :         int NumAlphas;
     233             :         int NumNums;
     234             :         int IOStat;
     235           3 :         bool errorsFound = false;
     236             : 
     237           3 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
     238             :                                                                  "Generator:PVWatts",
     239             :                                                                  objNum,
     240             :                                                                  cAlphaArgs,
     241             :                                                                  NumAlphas,
     242             :                                                                  rNumericArgs,
     243             :                                                                  NumNums,
     244             :                                                                  IOStat,
     245             :                                                                  lNumericFieldBlanks,
     246             :                                                                  lAlphaFieldBlanks,
     247             :                                                                  cAlphaFieldNames,
     248             :                                                                  cNumericFieldNames);
     249             : 
     250           3 :         const std::string name(cAlphaArgs(AlphaFields::NAME));
     251           3 :         const Real64 dcSystemCapacity(rNumericArgs(NumFields::DC_SYSTEM_CAPACITY));
     252             :         const std::map<std::string, ModuleType> moduleTypeMap = {
     253          15 :             {"STANDARD", ModuleType::STANDARD}, {"PREMIUM", ModuleType::PREMIUM}, {"THINFILM", ModuleType::THIN_FILM}};
     254             :         ModuleType moduleType;
     255           3 :         auto moduleTypeIt = moduleTypeMap.find(cAlphaArgs(AlphaFields::MODULE_TYPE));
     256           3 :         if (moduleTypeIt == moduleTypeMap.end()) {
     257           0 :             ShowSevereError(state, format("PVWatts: Invalid Module Type: {}", cAlphaArgs(AlphaFields::MODULE_TYPE)));
     258           0 :             errorsFound = true;
     259             :         } else {
     260           3 :             moduleType = moduleTypeIt->second;
     261             :         }
     262             : 
     263           0 :         const std::map<std::string, ArrayType> arrayTypeMap = {{"FIXEDOPENRACK", ArrayType::FIXED_OPEN_RACK},
     264           0 :                                                                {"FIXEDROOFMOUNTED", ArrayType::FIXED_ROOF_MOUNTED},
     265           0 :                                                                {"ONEAXIS", ArrayType::ONE_AXIS},
     266           0 :                                                                {"ONEAXISBACKTRACKING", ArrayType::ONE_AXIS_BACKTRACKING},
     267          21 :                                                                {"TWOAXIS", ArrayType::TWO_AXIS}};
     268             :         ArrayType arrayType;
     269           3 :         auto arrayTypeIt = arrayTypeMap.find(cAlphaArgs(AlphaFields::ARRAY_TYPE));
     270           3 :         if (arrayTypeIt == arrayTypeMap.end()) {
     271           0 :             ShowSevereError(state, format("PVWatts: Invalid Array Type: {}", cAlphaArgs(AlphaFields::ARRAY_TYPE)));
     272           0 :             errorsFound = true;
     273             :         } else {
     274           3 :             arrayType = arrayTypeIt->second;
     275             :         }
     276             : 
     277           3 :         const Real64 systemLosses(rNumericArgs(NumFields::SYSTEM_LOSSES));
     278          12 :         const std::map<std::string, GeometryType> geometryTypeMap{{"TILTAZIMUTH", GeometryType::TILT_AZIMUTH}, {"SURFACE", GeometryType::SURFACE}};
     279             :         GeometryType geometryType;
     280           3 :         auto geometryTypeIt = geometryTypeMap.find(cAlphaArgs(AlphaFields::GEOMETRY_TYPE));
     281           3 :         if (geometryTypeIt == geometryTypeMap.end()) {
     282           0 :             ShowSevereError(state, format("PVWatts: Invalid Geometry Type: {}", cAlphaArgs(AlphaFields::GEOMETRY_TYPE)));
     283           0 :             errorsFound = true;
     284             :         } else {
     285           3 :             geometryType = geometryTypeIt->second;
     286             :         }
     287             : 
     288           3 :         const Real64 tilt(rNumericArgs(NumFields::TILT_ANGLE));
     289           3 :         const Real64 azimuth(rNumericArgs(NumFields::AZIMUTH_ANGLE));
     290             :         int surfaceNum;
     291           3 :         if (lAlphaFieldBlanks(AlphaFields::SURFACE_NAME)) {
     292           1 :             surfaceNum = 0;
     293             :         } else {
     294           2 :             surfaceNum = Util::FindItemInList(cAlphaArgs(AlphaFields::SURFACE_NAME), state.dataSurface->Surface);
     295             :         }
     296             : 
     297           3 :         if (errorsFound) {
     298           0 :             ShowFatalError(state, "Errors found in getting PVWatts input");
     299             :         }
     300             : 
     301           3 :         if (NumNums < NumFields::GROUND_COVERAGE_RATIO) {
     302             :             return std::make_unique<PVWattsGenerator>(
     303           6 :                 state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, 0.4);
     304             :         }
     305           0 :         const Real64 groundCoverageRatio(rNumericArgs(NumFields::GROUND_COVERAGE_RATIO));
     306             : 
     307             :         return std::make_unique<PVWattsGenerator>(
     308           0 :             state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, groundCoverageRatio);
     309           3 :     }
     310             : 
     311           3 :     Real64 PVWattsGenerator::getDCSystemCapacity()
     312             :     {
     313           3 :         return dcSystemCapacity_;
     314             :     }
     315             : 
     316           0 :     ModuleType PVWattsGenerator::getModuleType()
     317             :     {
     318           0 :         return moduleType_;
     319             :     }
     320             : 
     321           0 :     ArrayType PVWattsGenerator::getArrayType()
     322             :     {
     323           0 :         return arrayType_;
     324             :     }
     325             : 
     326           0 :     Real64 PVWattsGenerator::getSystemLosses()
     327             :     {
     328           0 :         return systemLosses_;
     329             :     }
     330             : 
     331           0 :     GeometryType PVWattsGenerator::getGeometryType()
     332             :     {
     333           0 :         return geometryType_;
     334             :     }
     335             : 
     336           0 :     Real64 PVWattsGenerator::getTilt()
     337             :     {
     338           0 :         return tilt_;
     339             :     }
     340             : 
     341           0 :     Real64 PVWattsGenerator::getAzimuth()
     342             :     {
     343           0 :         return azimuth_;
     344             :     }
     345             : 
     346           4 :     DataSurfaces::SurfaceData &PVWattsGenerator::getSurface(EnergyPlusData &state)
     347             :     {
     348           4 :         return state.dataSurface->Surface(surfaceNum_);
     349             :     }
     350             : 
     351           0 :     Real64 PVWattsGenerator::getGroundCoverageRatio()
     352             :     {
     353           0 :         return groundCoverageRatio_;
     354             :     }
     355             : 
     356           0 :     Real64 PVWattsGenerator::getCellTemperature()
     357             :     {
     358           0 :         return cellTemperature_;
     359             :     }
     360             : 
     361           0 :     void PVWattsGenerator::setCellTemperature(Real64 cellTemp)
     362             :     {
     363           0 :         cellTemperature_ = cellTemp;
     364           0 :     }
     365             : 
     366           0 :     Real64 PVWattsGenerator::getPlaneOfArrayIrradiance()
     367             :     {
     368           0 :         return planeOfArrayIrradiance_;
     369             :     }
     370             : 
     371           0 :     void PVWattsGenerator::setPlaneOfArrayIrradiance(Real64 poa)
     372             :     {
     373           0 :         planeOfArrayIrradiance_ = poa;
     374           0 :     }
     375             : 
     376           3 :     void PVWattsGenerator::setDCtoACRatio(Real64 const dc2ac)
     377             :     {
     378           3 :         DCtoACRatio_ = dc2ac;
     379           3 :     }
     380             : 
     381           3 :     void PVWattsGenerator::setInverterEfficiency(Real64 const inverterEfficiency)
     382             :     {
     383           3 :         inverterEfficiency_ = inverterEfficiency;
     384           3 :     }
     385             : 
     386        6588 :     void PVWattsGenerator::calc(EnergyPlusData &state)
     387             :     {
     388        6588 :         Real64 TimeStepSysSec = state.dataHVACGlobal->TimeStepSysSec;
     389             : 
     390             :         // We only run this once for each zone time step.
     391        6588 :         const int NumTimeStepsToday_loc = state.dataGlobal->HourOfDay * state.dataGlobal->NumOfTimeStepInHour + state.dataGlobal->TimeStep;
     392        6588 :         if (NumTimeStepsToday_ != NumTimeStepsToday_loc) {
     393        1530 :             NumTimeStepsToday_ = NumTimeStepsToday_loc;
     394             :         } else {
     395        5058 :             outputDCEnergy_ = outputDCPower_ * TimeStepSysSec;
     396        5058 :             outputACEnergy_ = outputACPower_ * TimeStepSysSec;
     397        5058 :             return;
     398             :         }
     399             :         // SSC Inputs
     400             :         // Time
     401        1530 :         ssc_data_set_number(pvwattsData_, "year", state.dataEnvrn->Year);
     402        1530 :         ssc_data_set_number(pvwattsData_, "month", state.dataEnvrn->Month);
     403        1530 :         ssc_data_set_number(pvwattsData_, "day", state.dataEnvrn->DayOfMonth);
     404        1530 :         ssc_data_set_number(pvwattsData_, "hour", state.dataGlobal->HourOfDay - 1);
     405        1530 :         ssc_data_set_number(pvwattsData_, "minute", (state.dataGlobal->TimeStep - 0.5) * state.dataGlobal->MinutesPerTimeStep);
     406             : 
     407             :         // Weather Conditions
     408        1530 :         ssc_data_set_number(pvwattsData_, "beam", state.dataEnvrn->BeamSolarRad);
     409        1530 :         ssc_data_set_number(pvwattsData_, "diffuse", state.dataEnvrn->DifSolarRad);
     410        1530 :         ssc_data_set_number(pvwattsData_, "tamb", state.dataEnvrn->OutDryBulbTemp);
     411        1530 :         ssc_data_set_number(pvwattsData_, "wspd", state.dataEnvrn->WindSpeed);
     412        1530 :         Real64 albedo = state.dataWeather->wvarsHrTsToday(state.dataGlobal->TimeStep, state.dataGlobal->HourOfDay).Albedo;
     413        1530 :         if (!(std::isfinite(albedo) && albedo > 0.0 && albedo < 1)) {
     414        1530 :             albedo = 0.2;
     415             :         }
     416        1530 :         ssc_data_set_number(pvwattsData_, "alb", albedo);
     417             : 
     418             :         // In/Out Properties
     419        1530 :         ssc_data_set_number(pvwattsData_, "tcell", cellTemperature_);
     420        1530 :         ssc_data_set_number(pvwattsData_, "poa", planeOfArrayIrradiance_);
     421             : 
     422             :         // Get the shading from the geometry, if applicable
     423        1530 :         if (geometryType_ == GeometryType::SURFACE) {
     424        1020 :             shadedPercent_ = (1.0 - state.dataHeatBal->SurfSunlitFrac(state.dataGlobal->HourOfDay, state.dataGlobal->TimeStep, surfaceNum_)) * 100.0;
     425        1020 :             ssc_data_set_number(pvwattsData_, "shaded_percent", shadedPercent_);
     426             :         }
     427             : 
     428        1530 :         if (ssc_module_exec(pvwattsModule_, pvwattsData_) == 0) {
     429             :             // Error
     430             :             const char *errtext;
     431             :             int sscErrType;
     432             :             float time;
     433           0 :             int i = 0;
     434           0 :             while ((errtext = ssc_module_log(pvwattsModule_, i++, &sscErrType, &time))) {
     435           0 :                 std::string err("PVWatts: ");
     436           0 :                 switch (sscErrType) {
     437           0 :                 case SSC_WARNING:
     438           0 :                     err.append(errtext);
     439           0 :                     ShowWarningMessage(state, err);
     440           0 :                     break;
     441           0 :                 case SSC_ERROR:
     442           0 :                     err.append(errtext);
     443           0 :                     ShowErrorMessage(state, err);
     444           0 :                     break;
     445           0 :                 default:
     446           0 :                     break;
     447             :                 }
     448           0 :             }
     449             :         } else {
     450             :             // Report Out
     451        1530 :             ssc_data_get_number(pvwattsData_, "dc", &outputDCPower_);
     452        1530 :             outputDCEnergy_ = outputDCPower_ * TimeStepSysSec;
     453        1530 :             ssc_data_get_number(pvwattsData_, "ac", &outputACPower_);
     454        1530 :             outputACEnergy_ = outputACPower_ * TimeStepSysSec;
     455        1530 :             ssc_data_get_number(pvwattsData_, "tcell", &cellTemperature_);
     456        1530 :             ssc_data_get_number(pvwattsData_, "poa", &planeOfArrayIrradiance_);
     457             :         }
     458             :     }
     459             : 
     460        6588 :     void PVWattsGenerator::getResults(Real64 &GeneratorPower, Real64 &GeneratorEnergy, Real64 &ThermalPower, Real64 &ThermalEnergy)
     461             :     {
     462        6588 :         GeneratorPower = outputDCPower_;
     463        6588 :         GeneratorEnergy = outputDCEnergy_;
     464        6588 :         ThermalPower = 0.0;
     465        6588 :         ThermalEnergy = 0.0;
     466        6588 :     }
     467             : 
     468             : } // namespace PVWatts
     469             : 
     470             : } // namespace EnergyPlus

Generated by: LCOV version 1.14