LCOV - code coverage report
Current view: top level - EnergyPlus - ElectricPowerServiceManager.hh (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 12 15 80.0 %
Date: 2024-08-24 18:31:18 Functions: 2 3 66.7 %

          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             : #ifndef ElectricPowerServiceManager_hh_INCLUDED
      49             : #define ElectricPowerServiceManager_hh_INCLUDED
      50             : 
      51             : // C++ Headers
      52             : #include <memory>
      53             : #include <string>
      54             : #include <vector>
      55             : 
      56             : // EnergyPlus Headers
      57             : #include <EnergyPlus/Data/BaseData.hh>
      58             : #include <EnergyPlus/DataGlobalConstants.hh>
      59             : #include <EnergyPlus/DataHeatBalance.hh>
      60             : #include <EnergyPlus/EMSManager.hh>
      61             : #include <EnergyPlus/EnergyPlus.hh>
      62             : #include <EnergyPlus/OutputProcessor.hh>
      63             : #include <EnergyPlus/PVWatts.hh>
      64             : #include <EnergyPlus/Plant/Enums.hh>
      65             : #include <EnergyPlus/Plant/PlantLocation.hh>
      66             : 
      67             : // SSC Headers
      68             : #include <../third_party/ssc/shared/lib_battery.h>
      69             : 
      70             : namespace EnergyPlus {
      71             : 
      72             : enum class GeneratorType
      73             : {
      74             :     Invalid = -1,
      75             :     ICEngine,
      76             :     CombTurbine,
      77             :     PV,
      78             :     FuelCell,
      79             :     MicroCHP,
      80             :     Microturbine,
      81             :     WindTurbine,
      82             :     PVWatts,
      83             :     Num
      84             : };
      85             : 
      86             : static constexpr std::array<std::string_view, static_cast<int>(GeneratorType::Num)> GeneratorTypeNames{"Generator:InternalCombustionEngine",
      87             :                                                                                                        "Generator:CombustionTurbine",
      88             :                                                                                                        "Generator:Photovoltaic",
      89             :                                                                                                        "Generator:FuelCell",
      90             :                                                                                                        "Generator:MicroCHP",
      91             :                                                                                                        "Generator:MicroTurbine",
      92             :                                                                                                        "Generator:WindTurbine",
      93             :                                                                                                        "Generator:PVWatts"};
      94             : 
      95             : static constexpr std::array<std::string_view, static_cast<int>(GeneratorType::Num)> GeneratorTypeNamesUC{"GENERATOR:INTERNALCOMBUSTIONENGINE",
      96             :                                                                                                          "GENERATOR:COMBUSTIONTURBINE",
      97             :                                                                                                          "GENERATOR:PHOTOVOLTAIC",
      98             :                                                                                                          "GENERATOR:FUELCELL",
      99             :                                                                                                          "GENERATOR:MICROCHP",
     100             :                                                                                                          "GENERATOR:MICROTURBINE",
     101             :                                                                                                          "GENERATOR:WINDTURBINE",
     102             :                                                                                                          "GENERATOR:PVWATTS"};
     103             : 
     104             : enum class ThermalLossDestination
     105             : {
     106             :     Invalid = -1,
     107             :     ZoneGains,     // device thermal losses are added to a zone as internal gains
     108             :     LostToOutside, // device thermal losses have no destination
     109             :     Num
     110             : };
     111             : 
     112             : void initializeElectricPowerServiceZoneGains(const EnergyPlusData &state);
     113             : 
     114             : class DCtoACInverter
     115             : // This class is for modelling a power conversion device that takes DC power in and produces AC power out.
     116             : // This class combines three separate input objects that have different methods of determining efficiency.
     117             : {
     118             : 
     119             : public: // Methods
     120             :     enum class InverterModelType
     121             :     {
     122             :         Invalid = -1,
     123             :         CECLookUpTableModel,
     124             :         CurveFuncOfPower,
     125             :         SimpleConstantEff,
     126             :         PVWatts,
     127             :         Num
     128             :     };
     129             : 
     130             :     // Constructor
     131             :     DCtoACInverter(EnergyPlusData &state, std::string const &objectName);
     132             : 
     133             :     void simulate(EnergyPlusData &state, Real64 const powerIntoInverter);
     134             : 
     135             :     void reinitAtBeginEnvironment();
     136             : 
     137             :     void reinitZoneGainsAtBeginEnvironment();
     138             : 
     139             :     void setPVWattsDCCapacity(EnergyPlusData &state, Real64 const dcCapacity);
     140             : 
     141             :     Real64 pvWattsDCCapacity();
     142             : 
     143             :     Real64 pvWattsInverterEfficiency();
     144             : 
     145             :     Real64 pvWattsDCtoACSizeRatio();
     146             : 
     147             :     Real64 getLossRateForOutputPower(EnergyPlusData &state, Real64 const powerOutOfInverter);
     148             : 
     149             :     Real64 aCPowerOut() const;
     150             : 
     151             :     InverterModelType modelType() const;
     152             : 
     153             :     std::string const &name() const;
     154             : 
     155             : private: // Methods
     156             :     void calcEfficiency(EnergyPlusData &state);
     157             : 
     158             : private:               // data
     159             :     std::string name_; // user identifier
     160             :     Real64 aCPowerOut_;
     161             :     Real64 aCEnergyOut_;
     162             :     Real64 efficiency_;
     163             :     Real64 dCPowerIn_;
     164             :     Real64 dCEnergyIn_;
     165             :     Real64 conversionLossPower_;
     166             :     Real64 conversionLossEnergy_;
     167             :     Real64 conversionLossEnergyDecrement_;
     168             :     Real64 thermLossRate_;
     169             :     Real64 thermLossEnergy_;
     170             :     Real64 qdotConvZone_;
     171             :     Real64 qdotRadZone_;
     172             :     Real64 ancillACuseRate_;
     173             :     Real64 ancillACuseEnergy_;
     174             :     InverterModelType modelType_; // type of inverter model used
     175             :     int availSchedPtr_;           // number for availability schedule.
     176             :     ThermalLossDestination heatLossesDestination_;
     177             :     int zoneNum_;                              // destination zone for heat losses from inverter.
     178             :     Real64 zoneRadFract_;                      // radiative fraction for thermal losses to zone
     179             :     Real64 nominalVoltage_;                    // CEC lookup table model
     180             :     std::vector<Real64> nomVoltEfficiencyARR_; // eff at 10, 20, 30, 50, 75, & 100% CEC lookup table model
     181             :     int curveNum_;                             // curve index for eff as func of power
     182             :     Real64 ratedPower_;                        // rated, max continuous power output level for inverter
     183             :     Real64 minPower_;
     184             :     Real64 maxPower_;
     185             :     Real64 minEfficiency_;
     186             :     Real64 maxEfficiency_;
     187             :     Real64 standbyPower_;
     188             :     Real64 pvWattsDCtoACSizeRatio_;
     189             :     Real64 pvWattsInverterEfficiency_;
     190             : 
     191             : }; // DCtoACInverter
     192             : 
     193             : class ACtoDCConverter
     194             : // This class is for modelling a power conversion device that takes AC power in and produces DC power out.
     195             : 
     196             : {
     197             : 
     198             : public: // Methods
     199             :     // Constructor
     200             :     ACtoDCConverter(EnergyPlusData &state, std::string const &objectName);
     201             : 
     202             :     void simulate(EnergyPlusData &state, Real64 const powerOutFromConverter);
     203             : 
     204             :     void reinitAtBeginEnvironment();
     205             : 
     206             :     void reinitZoneGainsAtBeginEnvironment();
     207             : 
     208             :     Real64 aCPowerIn() const;
     209             : 
     210             :     Real64 getLossRateForInputPower(EnergyPlusData &state, Real64 const powerIntoConverter); // AC power going into inverter
     211             : 
     212             :     std::string const &name() const;
     213             : 
     214             : private: // methods
     215             :     void calcEfficiency(EnergyPlusData &state);
     216             : 
     217             : private: // data
     218             :     enum class ConverterModelType
     219             :     {
     220             :         Invalid = -1,
     221             :         CurveFuncOfPower,
     222             :         SimpleConstantEff,
     223             :         Num
     224             :     };
     225             : 
     226             :     std::string name_; // user identifier
     227             :     Real64 efficiency_;
     228             :     Real64 aCPowerIn_;
     229             :     Real64 aCEnergyIn_;
     230             :     Real64 dCPowerOut_;
     231             :     Real64 dCEnergyOut_;
     232             :     Real64 conversionLossPower_;
     233             :     Real64 conversionLossEnergy_;
     234             :     Real64 conversionLossEnergyDecrement_;
     235             :     Real64 thermLossRate_;
     236             :     Real64 thermLossEnergy_;
     237             :     Real64 qdotConvZone_;
     238             :     Real64 qdotRadZone_;
     239             :     Real64 ancillACuseRate_;
     240             :     Real64 ancillACuseEnergy_;
     241             :     int availSchedPtr_;            // number for availability schedule.
     242             :     ConverterModelType modelType_; // type of inverter model used
     243             :     int curveNum_;                 // performance curve or table index
     244             :     ThermalLossDestination heatLossesDestination_;
     245             :     int zoneNum_;         // destination zone for heat losses from inverter.
     246             :     Real64 zoneRadFract_; // radiative fraction for thermal losses to zone
     247             :     Real64 standbyPower_;
     248             :     Real64 maxPower_;
     249             : };
     250             : 
     251             : class ElectricStorage
     252             : // This class is for modeling a device for storing electric power over time.
     253             : // This class combines two separate input objects that have different models.
     254             : {
     255             : 
     256             : public: // methods
     257             :     // Constructor
     258             :     ElectricStorage(EnergyPlusData &state, std::string const &objectName);
     259             : 
     260             :     void timeCheckAndUpdate(EnergyPlusData &state);
     261             : 
     262             :     void simulate(EnergyPlusData &state,
     263             :                   Real64 &powerCharge,
     264             :                   Real64 &powerDischarge,
     265             :                   bool &charging,
     266             :                   bool &discharging,
     267             :                   Real64 const controlSOCMaxFracLimit,
     268             :                   Real64 const controlSOCMinFracLimit);
     269             : 
     270             :     // void calcAndReportSimpleBucketModel();
     271             : 
     272             :     // void calcAndReportKineticBatteryModel();
     273             : 
     274             :     void reinitAtBeginEnvironment();
     275             : 
     276             :     void reinitZoneGainsAtBeginEnvironment();
     277             : 
     278             :     void reinitAtEndWarmup();
     279             : 
     280             :     Real64 drawnPower() const;
     281             : 
     282             :     Real64 storedPower() const;
     283             : 
     284             :     Real64 drawnEnergy() const;
     285             : 
     286             :     Real64 storedEnergy() const;
     287             : 
     288             :     Real64 stateOfChargeFraction() const;
     289             : 
     290             :     Real64 batteryTemperature() const;
     291             : 
     292             :     bool determineCurrentForBatteryDischarge(EnergyPlusData &state,
     293             :                                              Real64 &curI0,
     294             :                                              Real64 &curT0,
     295             :                                              Real64 &curVolt,
     296             :                                              Real64 const Pw,
     297             :                                              Real64 const q0,
     298             :                                              int const CurveNum,
     299             :                                              Real64 const k,
     300             :                                              Real64 const c,
     301             :                                              Real64 const qmax,
     302             :                                              Real64 const E0c,
     303             :                                              Real64 const InternalR);
     304             : 
     305             :     std::string const &name() const;
     306             : 
     307             : private:                            // methods
     308             :     void simulateSimpleBucketModel( // request charge discharge and
     309             :         EnergyPlusData &state,
     310             :         Real64 &powerCharge,
     311             :         Real64 &powerDischarge,
     312             :         bool &charging,
     313             :         bool &discharging,
     314             :         Real64 const controlSOCMaxFracLimit,
     315             :         Real64 const controlSOCMinFracLimit);
     316             : 
     317             :     void simulateKineticBatteryModel(EnergyPlusData &state,
     318             :                                      Real64 &powerCharge,
     319             :                                      Real64 &powerDischarge,
     320             :                                      bool &charging,
     321             :                                      bool &discharging,
     322             :                                      Real64 const controlSOCMaxFracLimit,
     323             :                                      Real64 const controlSOCMinFracLimit);
     324             : 
     325             :     void simulateLiIonNmcBatteryModel(EnergyPlusData &state,
     326             :                                       Real64 &powerCharge,
     327             :                                       Real64 &powerDischarge,
     328             :                                       bool &charging,
     329             :                                       bool &discharging,
     330             :                                       Real64 const controlSOCMaxFracLimit,
     331             :                                       Real64 const controlSOCMinFracLimit);
     332             : 
     333             :     void rainflow(int const numbin,           // numbin = constant value
     334             :                   Real64 const input,         // input = input value from other object (battery model)
     335             :                   std::vector<Real64> &B1,    // stores values of points, calculated here - stored for next timestep
     336             :                   std::vector<Real64> &X,     // stores values of two data point difference, calculated here - stored for next timestep
     337             :                   int &count,                 // calculated here - stored for next timestep in main loop
     338             :                   std::vector<Real64> &Nmb,   // calculated here - stored for next timestep in main loop
     339             :                   std::vector<Real64> &OneNmb // calculated here - stored for next timestep in main loop
     340             :                                               //    int const dim // end dimension of array
     341             :     );
     342             : 
     343             :     void shift(std::vector<Real64> &A, int const m, int const n, std::vector<Real64> &B
     344             :                //    int const dim // end dimension of arrays
     345             :     );
     346             : 
     347             : private: // data
     348             :     enum class StorageModelType
     349             :     {
     350             :         Invalid = -1,
     351             :         SimpleBucketStorage,
     352             :         KIBaMBattery,
     353             :         LiIonNmcBattery,
     354             :         Num
     355             :     };
     356             : 
     357             :     enum class BatteryDegradationModelType
     358             :     {
     359             :         Invalid = -1,
     360             :         LifeCalculationYes,
     361             :         LifeCalculationNo,
     362             :         Num
     363             :     };
     364             : 
     365             :     std::string name_;               // name of this electrical storage module
     366             :     Real64 storedPower_;             // [W]
     367             :     Real64 storedEnergy_;            // [J]
     368             :     Real64 drawnPower_;              // [W]
     369             :     Real64 drawnEnergy_;             // [J]
     370             :     Real64 decrementedEnergyStored_; // [J] this is the negative of StoredEnergy
     371             :     int maxRainflowArrayBounds_;
     372             :     bool myWarmUpFlag_;
     373             :     StorageModelType storageModelMode_;            // type of model parameter, SimpleBucketStorage
     374             :     int availSchedPtr_;                            // availability schedule index.
     375             :     ThermalLossDestination heatLossesDestination_; // mode for where thermal losses go
     376             :     int zoneNum_;                                  // destination zone for heat losses from inverter.
     377             :     Real64 zoneRadFract_;                          // radiative fraction for thermal losses to zone
     378             :     Real64 startingEnergyStored_;                  // [J] joules inside at beginning of environment period
     379             :     Real64 energeticEfficCharge_;                  // [ ] efficiency of charging
     380             :     Real64 energeticEfficDischarge_;               // [ ] efficiency of discharging
     381             :     Real64 maxPowerDraw_;                          // [W] max rate of discharge
     382             :     Real64 maxPowerStore_;                         // [W] max rate of charge
     383             :     Real64 maxEnergyCapacity_;                     // [J] max storage capacity
     384             :     int parallelNum_;                              // [ ] number of battery modules in parallel
     385             :     int seriesNum_;                                // [ ] number of battery modules in series
     386             :     int numBattery_;                               // total number of batteries all together
     387             :     int chargeCurveNum_;                           // [ ] voltage change curve index number for charging
     388             :     int dischargeCurveNum_;                        // [ ] voltage change curve index number for discharging
     389             :     int cycleBinNum_;                              // [ ] number of cycle bins
     390             :     Real64 startingSOC_;                           // [ ] initial fractional state of charge
     391             :     Real64 maxAhCapacity_;                         // [Ah]maximum capacity
     392             :     Real64 availableFrac_;                         // [ ] maximum fraction of available charge capacity
     393             :     Real64 chargeConversionRate_;                  // [1/h]change rate from bound charge energy to available charge
     394             :     Real64 chargedOCV_;                            // [V] fully charged open circuit voltage
     395             :     Real64 dischargedOCV_;                         // [V] fully discharged open circuit voltage
     396             :     Real64 internalR_;                             // [ohm]internal electric resistance
     397             :     Real64 maxDischargeI_;                         // [A] maximum discharging current
     398             :     Real64 cutoffV_;                               // [V] cut-off voltage
     399             :     Real64 maxChargeRate_;                         // [1/h] charge rate limit
     400             :     BatteryDegradationModelType lifeCalculation_;  // [ ] battery life calculation: Yes or No
     401             :     int lifeCurveNum_;                             // [ ] battery life curve name index number
     402             :     Real64 liIon_dcToDcChargingEff_;               // [ ] DC to DC Charging Efficiency (Li-ion NMC model)
     403             :     Real64 liIon_mass_;                            // [kg] mass of battery (Li-ion NMC model)
     404             :     Real64 liIon_surfaceArea_;                     // [m2] battery surface area (Li-ion NMC model)
     405             :     Real64 liIon_Cp_;                              // [J/kg-K] battery specific heat capacity (Li-ion NMC model)
     406             :     Real64 liIon_heatTransferCoef_;                // [W/m2-K] Heat Transfer Coefficient Between Battery and Ambient (Li-ion NMC model)
     407             :     Real64 liIon_Vfull_;                           // [V] Fully charged cell voltage (Li-ion NMC model)
     408             :     Real64 liIon_Vexp_;                            // [V] Cell Voltage at End of Exponential Zone (Li-ion NMC model)
     409             :     Real64 liIon_Vnom_;                            // [V] Cell voltage at end of nominal zone (Li-ion NMC model)
     410             :     Real64 liIon_Vnom_default_;                    // [V] Default nominal cell voltage (Li-ion NMC model)
     411             :     Real64 liIon_Qfull_;                           // [A-h] Fully charged cell capacity (Li-ion NMC model)
     412             :     Real64 liIon_Qexp_;                            // [A-h] Cell capacity at end of exponential zone (Li-ion NMC model)
     413             :     Real64 liIon_Qnom_;                            // [A-h] Cell capacity at end of nominal zone (Li-ion NMC model)
     414             :     Real64 liIon_C_rate_;                          // [ ] Rate at which voltage vs capacity curve input (Li-ion NMC model)
     415             :     // calculated and from elsewhere vars
     416             :     Real64 thisTimeStepStateOfCharge_; // [J]
     417             :     Real64 lastTimeStepStateOfCharge_; // [J]
     418             :     Real64 pelNeedFromStorage_;        // [W]
     419             :     Real64 pelFromStorage_;            // [W]
     420             :     Real64 pelIntoStorage_;            // [W]
     421             :     Real64 qdotConvZone_;              // [W]
     422             :     Real64 qdotRadZone_;               // [W]
     423             :     Real64 timeElapsed_;               // [h]
     424             :     Real64 thisTimeStepAvailable_;     // [Ah] available charge at the current timestep
     425             :     Real64 thisTimeStepBound_;         // [Ah] bound charge at the current timestep
     426             :     Real64 lastTimeStepAvailable_;     // [Ah] available charge at the previous timestep
     427             :     Real64 lastTimeStepBound_;         // [Ah] bound charge at the previous timestep
     428             :     Real64 lastTwoTimeStepAvailable_;  // [Ah] available charge at the previous two timesteps
     429             :     Real64 lastTwoTimeStepBound_;      // [Ah] bound charge at the previous two timesteps
     430             :     // Li-ion NMC battery objects from SAM Simulation Core lib_battery
     431             :     std::unique_ptr<battery_t> ssc_battery_;
     432             :     std::unique_ptr<battery_state> ssc_lastBatteryState_;
     433             :     Real64 ssc_lastBatteryTimeStep_ = 0.0;
     434             :     std::unique_ptr<battery_state> ssc_initBatteryState_;
     435             :     Real64 ssc_initBatteryTimeStep_ = 0.0;
     436             :     // battery life calculation variables
     437             :     int count0_;
     438             :     std::vector<Real64> b10_;
     439             :     std::vector<Real64> x0_;
     440             :     std::vector<Real64> nmb0_;
     441             :     std::vector<Real64> oneNmb0_;
     442             :     // report
     443             :     Real64 electEnergyinStorage_; // [J] state of charge
     444             :     Real64 thermLossRate_;        // [W]
     445             :     Real64 thermLossEnergy_;      // [J]
     446             :     int storageMode_;             // [ ] mode of operation 0 for idle, 1 for discharging, 2 for charging
     447             :     Real64 absoluteSOC_;          // [Ah] total state of charge
     448             :     Real64 fractionSOC_;          // [ ] fractional state of charge
     449             :     Real64 batteryCurrent_;       // [A] total current
     450             :     Real64 batteryVoltage_;       // [V] total voltage
     451             :     Real64 batteryDamage_;        // [ ] fractional battery damage
     452             :     Real64 batteryTemperature_;   // [C] battery temperature (only used in Li-ion batteries)
     453             : 
     454             : }; // ElectricStorage
     455             : 
     456             : class ElectricTransformer
     457             : // This class is for modeling a power conversion device that changes from one voltage to another, or serves as an isolation transformer
     458             : {
     459             : 
     460             : public: // methods
     461             :     // Constructor
     462             :     ElectricTransformer(EnergyPlusData &state, std::string const &objectName);
     463             : 
     464             :     Real64 getLossRateForOutputPower(EnergyPlusData &state, Real64 const powerOutOfTransformer);
     465             : 
     466             :     Real64 getLossRateForInputPower(EnergyPlusData &state, Real64 const powerIntoTransformer);
     467             : 
     468             :     void manageTransformers(EnergyPlusData &state, Real64 const surplusPowerOutFromLoadCenters);
     469             : 
     470             :     void setupMeterIndices(EnergyPlusData &state);
     471             : 
     472             :     void reinitAtBeginEnvironment();
     473             : 
     474             :     void reinitZoneGainsAtBeginEnvironment();
     475             : 
     476             :     std::string const &name() const;
     477             : 
     478             : private: // data
     479             :     enum class TransformerUse
     480             :     {
     481             :         Invalid = -1,
     482             :         PowerInFromGrid,               // condition power from grid going into building buss
     483             :         PowerOutFromBldgToGrid,        // condition power from building buss going out to grid
     484             :         PowerBetweenLoadCenterAndBldg, // condition power from a load center going into building buss, or from building buss into load center for
     485             :                                        // draws
     486             :         Num
     487             :     };
     488             :     enum class TransformerPerformanceInput
     489             :     {
     490             :         Invalid = -1,
     491             :         LossesMethod,
     492             :         EfficiencyMethod,
     493             :         Num
     494             :     };
     495             : 
     496             :     std::string name_; // user identifier
     497             :     bool myOneTimeFlag_;
     498             :     int availSchedPtr_;                                // availability schedule index.
     499             :     TransformerUse usageMode_;                         // mode for transformer usage
     500             :     ThermalLossDestination heatLossesDestination_;     // mode for where thermal losses go
     501             :     int zoneNum_;                                      // destination zone for heat losses from inverter.
     502             :     Real64 zoneRadFrac_;                               // radiative fraction for thermal losses to zone
     503             :     Real64 ratedCapacity_;                             // rated capacity [VA]
     504             :                                                        //    int phase_;                                        // phase
     505             :     Real64 factorTempCoeff_;                           // thermal coefficient of resistance for winding material
     506             :     Real64 tempRise_;                                  // full load temperature rise [C]
     507             :     Real64 eddyFrac_;                                  // fraction of eddy current losses []
     508             :     TransformerPerformanceInput performanceInputMode_; // performance input method
     509             :     Real64 ratedEfficiency_;                           // nameplate efficiency []
     510             :     Real64 ratedPUL_;                                  // per unit load for nameplate efficiency []
     511             :     Real64 ratedTemp_;                                 // reference temperature for nameplate efficiency [C]
     512             :     Real64 maxPUL_;                                    // per unit load for maximum efficiency []
     513             :     bool considerLosses_;                              // if true, consider transformer lossses in metering
     514             :     std::vector<std::string> wiredMeterNames_;         // names of the meters wired to transformer
     515             :     std::vector<int> wiredMeterPtrs_;                  // array of "pointers" to meters wired to transformer
     516             :     std::vector<bool> specialMeter_;                   // indicates whether a meter needs special consideration
     517             :     // Electricity:Facility and Electricity:HVAC are two special
     518             :     // meters because tranformer loss is part of them
     519             :     // calculated and from elsewhere vars
     520             :     Real64 ratedNL_;         // rated no load losses, user input or calculated [W]
     521             :     Real64 ratedLL_;         // rated load losses, user input or calculated [W]
     522             :     int overloadErrorIndex_; // used for warning message when transformer is overloaded
     523             :     // results and reporting
     524             :     Real64 efficiency_;                  // transformer efficiency
     525             :     Real64 powerIn_;                     // [W]
     526             :     Real64 energyIn_;                    // [J]
     527             :     Real64 powerOut_;                    // [W]
     528             :     Real64 energyOut_;                   // [J]
     529             :     Real64 noLoadLossRate_;              // [W]
     530             :     Real64 noLoadLossEnergy_;            // [J]
     531             :     Real64 loadLossRate_;                // [W]
     532             :     Real64 loadLossEnergy_;              // [J]
     533             :     Real64 totalLossRate_;               // [W]
     534             :                                          //    Real64 totalLossEnergy_;             // [J]
     535             :     Real64 thermalLossRate_;             // [W]
     536             :     Real64 thermalLossEnergy_;           // [J]
     537             :     Real64 elecUseMeteredUtilityLosses_; // [J] Energy consumption for a utility transformer (power in)
     538             :     // Positive values
     539             :     Real64 powerConversionMeteredLosses_; // [J] Energy consumption for a (cogeneration )transformer (power out from building to grid)
     540             :     // Negative values
     541             :     Real64 qdotConvZone_; // [W]
     542             :     Real64 qdotRadZone_;  // [W]
     543             : };                        // ElectricTransformer
     544             : 
     545             : class GeneratorController
     546             : // this class is used as part of the supervisory control and calling of electric power generators.  Each instances is for one generator
     547             : {
     548             : 
     549             : public: // Method
     550             :     // Constructor
     551             :     GeneratorController(EnergyPlusData &state,
     552             :                         std::string const &objectName,
     553             :                         std::string const &objectType,
     554             :                         Real64 ratedElecPowerOutput,
     555             :                         std::string const &availSchedName,
     556             :                         Real64 thermalToElectRatio);
     557             : 
     558             :     void simGeneratorGetPowerOutput(EnergyPlusData &state,
     559             :                                     bool const runFlag,             // true if generator is on
     560             :                                     Real64 const myElecLoadRequest, // target electric power production request
     561             :                                     bool const FirstHVACIteration,  //
     562             :                                     Real64 &electricPowerOutput,    // Actual generator electric power output
     563             :                                     Real64 &thermalPowerOutput      // Actual generator thermal power output
     564             :     );
     565             : 
     566             :     void reinitAtBeginEnvironment();
     567             : 
     568             : public:                          // data // might make this class a friend of ElectPowerLoadCenter?
     569             :     std::string name;            // user identifier
     570             :     GeneratorType generatorType; // Numeric designator for generator CompType (TypeOf), in DataGlobalConstants
     571             :     DataPlant::PlantEquipmentType compPlantType{DataPlant::PlantEquipmentType::Invalid}; // numeric designator for plant component, in DataPlant
     572             :     std::string compPlantName;                                                           // name of plant component if heat recovery
     573             :     int generatorIndex;                                                                  // index in generator model data struct
     574             :     Real64 maxPowerOut;                                                                  // Maximum Power Output (W)
     575             :     std::string availSched;                                                              // Operation Schedule.
     576             :     int availSchedPtr;                                                                   // pointer to operation schedule
     577             :     Real64 powerRequestThisTimestep;                                                     // Current Demand on Equipment (W)
     578             :     bool onThisTimestep;                                                                 // Indicator whether Generator on
     579             :     Real64 eMSPowerRequest;                                                              // EMS actuator for current demand on equipment (W)
     580             :     bool eMSRequestOn;                                                                   // EMS actuating On if true.
     581             :     bool plantInfoFound;
     582             :     PlantLocation cogenLocation;
     583             :     Real64 nominalThermElectRatio; // Cogen: nominal ratio of thermal to elect production
     584             :     // results of component models for load center reporting
     585             :     Real64 dCElectricityProd; // Current DC Electric Produced from Equipment (J)
     586             :     Real64 dCElectProdRate;   // Current DC Electric Production Rate from Equipment (W)
     587             :     Real64 electricityProd;   // Current AC Electric Produced from Equipment (J)
     588             :     Real64 electProdRate;     // Current AC Electric Production Rate from Equipment (W)
     589             :     Real64 thermalProd;       // Current Thermal energy Produced from Equipment (J)
     590             :     Real64 thermProdRate;     // Current Thermal energy Production Rate from Equipment (W)
     591             : 
     592             :     std::unique_ptr<PVWatts::PVWattsGenerator> pvwattsGenerator; // PVWattsGenerator object pointer
     593             : 
     594             : private:
     595             :     int errCountNegElectProd_; // error count for reccuring error when generators produce negative electric power
     596             : 
     597             : }; // class GeneratorController
     598             : 
     599             : class ElectPowerLoadCenter
     600             : // This class if for modeling a load center which can be thought of as a kind of subpanel that connects power equipment to a main panel
     601             : // multiple subpanels can be connected to the main panel and each ElectPowerLoadCenter object is a subpanel
     602             : // Each load center will contain other power conversion devices and/or generator(s).
     603             : {
     604             : 
     605             : public: // Methods
     606             :     // Constructor
     607             :     ElectPowerLoadCenter(EnergyPlusData &state, int const objectNum);
     608             : 
     609             :     void manageElecLoadCenter(EnergyPlusData &state, bool const firstHVACIteration, Real64 &remainingPowerDemand);
     610             : 
     611             :     void setupLoadCenterMeterIndices(EnergyPlusData &state);
     612             : 
     613             :     void reinitAtBeginEnvironment();
     614             : 
     615             :     void reinitZoneGainsAtBeginEnvironment();
     616             : 
     617             :     std::string const &generatorListName() const;
     618             : 
     619             :     void updateLoadCenterGeneratorRecords(EnergyPlusData &state);
     620             : 
     621             : private: // Methods
     622             :     void dispatchGenerators(EnergyPlusData &state, bool const firstHVACIteration, Real64 &remainingPowerDemand);
     623             : 
     624             :     void dispatchStorage(EnergyPlusData &state, Real64 const remainingPowerDemand);
     625             : 
     626             :     Real64 calcLoadCenterThermalLoad(EnergyPlusData &state); // returns heat rate called for from cogenerator(watts)
     627             : 
     628             : public: // data public for unit test
     629             :     enum class ElectricBussType
     630             :     {
     631             :         Invalid = -1,
     632             :         ACBuss,
     633             :         DCBussInverter,
     634             :         ACBussStorage,
     635             :         DCBussInverterDCStorage,
     636             :         DCBussInverterACStorage,
     637             :         Num
     638             :     };
     639             : 
     640             :     std::unique_ptr<ElectricStorage> storageObj;
     641             :     std::unique_ptr<ACtoDCConverter> converterObj;
     642             :     std::unique_ptr<ElectricTransformer> transformerObj;
     643             :     int numGenerators;                                                 // Number of Generators
     644             :     std::vector<std::unique_ptr<GeneratorController>> elecGenCntrlObj; // generator controller objects
     645             :     ElectricBussType bussType;                                         // is this load center powered by AC or DC generators
     646             :     Real64 thermalProd;                                                // Current thermal energy Produced from generators in load center (J)
     647             :     Real64 thermalProdRate;                                            // Current thermal energy production rate from generators in load center (W)
     648             :     bool inverterPresent;
     649             :     std::string inverterName; // hold name for verificaton and error messages
     650             :     std::unique_ptr<DCtoACInverter> inverterObj;
     651             :     Real64 subpanelFeedInRequest;
     652             :     // subpanel terms, interact with main panel
     653             :     Real64 subpanelFeedInRate; // Current AC electric power fed into main panel by load center, adjusted by inverter if any (W)
     654             :     Real64 subpanelDrawRate;   // Current AC electric power draw from main panel into load center (W)
     655             :     // storage operation terms,
     656             :     Real64 genElectricProd;       // Current electric produced by generators in the load center, DC or AC (J)
     657             :     Real64 genElectProdRate;      // Current electric power produced by generators in the load center, DC or AC (W)
     658             :     Real64 storOpCVGenRate;       // power from generators (and maybe inverter) going into storage operation control volume, DC or AC ( W )
     659             :     Real64 storOpCVDrawRate;      // power drawn from main panel into storage operation control volume after any converter, DC or AC ( W )
     660             :     Real64 storOpCVFeedInRate;    // power fed toward main panel from storage operation control volume before any inverter, DC or AC ( W )
     661             :     Real64 storOpCVChargeRate;    // power fed into storage device from storage operation control volume, before any storage losses, DC or AC ( W )
     662             :     Real64 storOpCVDischargeRate; // power drawn from storage device into storage operation control volume, after any storage losses, DC or AC ( W )
     663             :     bool storOpIsCharging;        // true if storage operation scheme is trying to charge
     664             :     bool storOpIsDischarging;     // true if storage operation scheme is trying to discharge
     665             : 
     666             : private: // data
     667             :     enum class GeneratorOpScheme : int
     668             :     {
     669             :         Invalid = -1,
     670             :         BaseLoad,
     671             :         DemandLimit,
     672             :         TrackElectrical,
     673             :         TrackSchedule,
     674             :         TrackMeter,
     675             :         ThermalFollow,
     676             :         ThermalFollowLimitElectrical,
     677             :         Num
     678             :     };
     679             : 
     680             :     enum class StorageOpScheme : int
     681             :     {
     682             :         Invalid = -1,
     683             :         FacilityDemandStoreExcessOnSite, // legacy control behavior
     684             :         MeterDemandStoreExcessOnSite,
     685             :         ChargeDischargeSchedules,
     686             :         FacilityDemandLeveling,
     687             :         Num
     688             :     };
     689             : 
     690             :     std::string name_;                     // user identifier
     691             :     std::string generatorListName_;        // List name of available generators
     692             :     GeneratorOpScheme genOperationScheme_; // Name of Operation Scheme
     693             :     std::string demandMeterName_;          // Name of Demand Energy Meter for "on demand" operation
     694             :     int demandMeterPtr_;                   // "pointer" to Meter for electrical Demand to meet
     695             :     std::string generationMeterName_;      // Name of Generated Energy Meter for "on demand" operation
     696             :     bool generatorsPresent_;               // true if any generators
     697             :     bool myCoGenSetupFlag_;
     698             :     Real64 demandLimit_; // Demand Limit in Watts(W) which the generator will operate above
     699             :     int trackSchedPtr_;  // "pointer" to schedule for electrical demand to meet.
     700             :     bool storagePresent_;
     701             :     std::string storageName_;            // hold name for verificaton and error messages
     702             :     bool transformerPresent_;            // should only be transformers for on-site load center, not facility service
     703             :     std::string transformerName_;        // hold name for verificaton and error messages
     704             :     Real64 totalPowerRequest_;           // Total electric power request from the load center (W)
     705             :     Real64 totalThermalPowerRequest_;    // Total thermal power request from the load center (W)
     706             :     StorageOpScheme storageScheme_;      // what options are available for charging storage.
     707             :     std::string trackSorageOpMeterName_; // user name for a specific meter
     708             :     int trackStorageOpMeterIndex_;       // points to meter being
     709             :     bool converterPresent_;
     710             :     std::string converterName_;
     711             :     Real64 maxStorageSOCFraction_; // Fraction of storage capacity used as upper limit for controlling charging (don't overcharge the batteries)
     712             :     Real64 minStorageSOCFraction_; // Fraction of storage capacity used as lower limit for controlling discharging (dont drain the batteries too far)
     713             :     Real64 designStorageChargePower_;        // rate of electric power drawn from grid to go into storage
     714             :     bool designStorageChargePowerWasSet_;    // true if a value was input
     715             :     Real64 designStorageDischargePower_;     // rate of electric power exported to grid by being drawn from storage
     716             :     bool designStorageDischargePowerWasSet_; // true if value was input
     717             :     int storageChargeModSchedIndex_;         // index of fraction schedule for controlling charge rate over time
     718             :     int storageDischargeModSchedIndex_;      // index of fraction schedule for controlling discharge rate over time.
     719             :     Real64 facilityDemandTarget_;            // target utility demand level in Watts
     720             :     int facilityDemandTargetModSchedIndex_;  // index of fracton schedule for controlling target demand over time.
     721             :     bool eMSOverridePelFromStorage_;         // if true, EMS calling for override
     722             :     Real64 eMSValuePelFromStorage_;          // value EMS is directing to use, power from storage [W]
     723             :     bool eMSOverridePelIntoStorage_;         // if true, EMS calling for override
     724             :     Real64 eMSValuePelIntoStorage_;          // value EMS is directing to use, power into storage [W]
     725             : 
     726             : }; // class ElectPowerLoadCenter
     727             : 
     728             : class ElectricPowerServiceManager //
     729             :                                   // This class if the top level object for modeling complex electric power service.  It contains transformers and/or
     730             :                                   // load center(s).
     731             : {
     732             : 
     733             : public: // Creation
     734             :     // Default Constructor
     735         796 :     ElectricPowerServiceManager()
     736        1592 :         : newEnvironmentInternalGainsFlag(true), numElecStorageDevices(0), getInputFlag_(true), newEnvironmentFlag_(true), numLoadCenters_(0),
     737         796 :           numTransformers_(0), setupMeterIndexFlag_(true), elecFacilityMeterIndex_(-1), elecProducedCoGenMeterIndex_(-1),
     738         796 :           elecProducedPVMeterIndex_(-1), elecProducedWTMeterIndex_(-1), elecProducedStorageMeterIndex_(-1),
     739         796 :           elecProducedPowerConversionMeterIndex_(-1), name_("Whole Building"), facilityPowerInTransformerPresent_(false), numPowerOutTransformers_(0),
     740         796 :           wholeBldgRemainingLoad_(0.0), electricityProd_(0.0), electProdRate_(0.0), electricityPurch_(0.0), electPurchRate_(0.0),
     741         796 :           electSurplusRate_(0.0), electricitySurplus_(0.0), electricityNetRate_(0.0), electricityNet_(0.0), totalBldgElecDemand_(0.0),
     742         796 :           totalHVACElecDemand_(0.0), totalElectricDemand_(0.0), elecProducedPVRate_(0.0), elecProducedWTRate_(0.0), elecProducedStorageRate_(0.0),
     743        1592 :           elecProducedPowerConversionRate_(0.0), elecProducedCoGenRate_(0.0), pvTotalCapacity_(0.0), windTotalCapacity_(0.0)
     744             :     {
     745         796 :     }
     746             : 
     747             : public: // Methods
     748             :     void manageElectricPowerService(EnergyPlusData &state,
     749             :                                     bool const FirstHVACIteration,
     750             :                                     bool &SimElecCircuits,      // simulation convergence flag
     751             :                                     bool const UpdateMetersOnly // if true then don't resimulate generators, just update meters.
     752             :     );
     753             : 
     754             :     void reinitZoneGainsAtBeginEnvironment();
     755             : 
     756             :     void verifyCustomMetersElecPowerMgr(EnergyPlusData &state);
     757             : 
     758             : private: // Methods
     759             :     void getPowerManagerInput(EnergyPlusData &state);
     760             : 
     761             :     void setupMeterIndices(EnergyPlusData &state);
     762             : 
     763             :     void reinitAtBeginEnvironment();
     764             : 
     765             :     void updateWholeBuildingRecords(EnergyPlusData &state);
     766             : 
     767             :     void reportPVandWindCapacity(EnergyPlusData &state);
     768             : 
     769             :     void sumUpNumberOfStorageDevices();
     770             : 
     771             :     void checkLoadCenters(EnergyPlusData &state);
     772             : 
     773             : public: // data
     774             :     bool newEnvironmentInternalGainsFlag;
     775             :     int numElecStorageDevices;
     776             :     std::vector<std::unique_ptr<ElectPowerLoadCenter>> elecLoadCenterObjs;
     777             : 
     778             : private:                      // data
     779             :     bool getInputFlag_;       // control if object needs to get input and call factory methods
     780             :     bool newEnvironmentFlag_; // control if object needs to reinit at beginning of a new environment period
     781             :     int numLoadCenters_;
     782             :     int numTransformers_;
     783             :     bool setupMeterIndexFlag_; // control if object needs to make calls to GetMeterIndex
     784             :     int elecFacilityMeterIndex_;
     785             :     int elecProducedCoGenMeterIndex_;
     786             :     int elecProducedPVMeterIndex_;
     787             :     int elecProducedWTMeterIndex_;
     788             :     int elecProducedStorageMeterIndex_;
     789             :     int elecProducedPowerConversionMeterIndex_;
     790             :     std::string name_;
     791             :     bool facilityPowerInTransformerPresent_;
     792             :     std::string facilityPowerInTransformerName_; // hold name for verificaton and error messages
     793             :     std::unique_ptr<ElectricTransformer> facilityPowerInTransformerObj_;
     794             :     int numPowerOutTransformers_;
     795             :     std::string powerOutTransformerName_;
     796             :     std::unique_ptr<ElectricTransformer> powerOutTransformerObj_;
     797             :     Real64 wholeBldgRemainingLoad_;
     798             :     Real64 electricityProd_;                 // Current Electric Produced from Equipment (J)
     799             :     Real64 electProdRate_;                   // Current Electric Production Rate from Equipment (W)
     800             :     Real64 electricityPurch_;                // Current Purchased Electric (J)
     801             :     Real64 electPurchRate_;                  // Current Electric Purhcased Rate (W)
     802             :     Real64 electSurplusRate_;                // Current excess power (W)
     803             :     Real64 electricitySurplus_;              // Current excess energy (J)
     804             :     Real64 electricityNetRate_;              // Net elect rate, + is Purchased, - is Surplus (W)
     805             :     Real64 electricityNet_;                  // Net energy, + is Purchased, - is Surplus (J)
     806             :     Real64 totalBldgElecDemand_;             // Current Total Building Electric Demand (W)
     807             :     Real64 totalHVACElecDemand_;             // Current Total HVAC Electric Demand (W)
     808             :     Real64 totalElectricDemand_;             // Current Total Electric Demand (W)
     809             :     Real64 elecProducedPVRate_;              // Current Rate of PV Produced from the Arrays (W)
     810             :     Real64 elecProducedWTRate_;              // Current Rate of Wind Turbine Produced (W)
     811             :     Real64 elecProducedStorageRate_;         // Current Rate of power to(-)/from(+) storage
     812             :     Real64 elecProducedPowerConversionRate_; // Current rate of power loss from power conversion, negative (W)
     813             :     Real64 elecProducedCoGenRate_;           // Current Rate of Cogeneration generators produced ( W )
     814             :     Real64 pvTotalCapacity_;                 // for LEED report, total installed PV capacity
     815             :     Real64 windTotalCapacity_;               // for LEED report, total installed wind capacity
     816             : 
     817             : }; // class ElectricPowerServiceManager
     818             : 
     819             : void createFacilityElectricPowerServiceObject(const EnergyPlusData &state);
     820             : 
     821             : Real64 checkUserEfficiencyInput(EnergyPlusData &state, Real64 userInputValue, std::string whichType, std::string deviceName, bool &errorsFound);
     822             : 
     823             : void checkChargeDischargeVoltageCurves(
     824             :     EnergyPlusData &state, std::string_view nameBatt, Real64 const E0c, Real64 const E0d, int const chargeIndex, int const dischargeIndex);
     825             : 
     826             : struct ElectPwrSvcMgrData : BaseGlobalStruct
     827             : {
     828             : 
     829             :     std::unique_ptr<ElectricPowerServiceManager> facilityElectricServiceObj;
     830             : 
     831         796 :     void init_state([[maybe_unused]] EnergyPlusData &state) override
     832             :     {
     833         796 :     }
     834             : 
     835           0 :     void clear_state() override
     836             :     {
     837           0 :         this->facilityElectricServiceObj.release();
     838           0 :     }
     839             : };
     840             : 
     841             : } // namespace EnergyPlus
     842             : #endif // ElectricPowerServiceManager_hh_INCLUDED

Generated by: LCOV version 1.14