LCOV - code coverage report
Current view: top level - EnergyPlus/Plant - Loop.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 63 82 76.8 %
Date: 2023-01-17 19:17:23 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, The Board of Trustees of the University of Illinois,
       2             : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3             : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4             : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5             : // contributors. All rights reserved.
       6             : //
       7             : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8             : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9             : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10             : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11             : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12             : //
      13             : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14             : // provided that the following conditions are met:
      15             : //
      16             : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17             : //     conditions and the following disclaimer.
      18             : //
      19             : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20             : //     conditions and the following disclaimer in the documentation and/or other materials
      21             : //     provided with the distribution.
      22             : //
      23             : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24             : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25             : //     used to endorse or promote products derived from this software without specific prior
      26             : //     written permission.
      27             : //
      28             : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29             : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30             : //     reference solely to the software portion of its product, Licensee must refer to the
      31             : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32             : //     obtained under this License and may not use a different name for the software. Except as
      33             : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34             : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35             : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36             : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37             : //
      38             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39             : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40             : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41             : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42             : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43             : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45             : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46             : // POSSIBILITY OF SUCH DAMAGE.
      47             : 
      48             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      49             : #include <EnergyPlus/DataBranchAirLoopPlant.hh>
      50             : #include <EnergyPlus/FluidProperties.hh>
      51             : #include <EnergyPlus/General.hh>
      52             : #include <EnergyPlus/Plant/DataPlant.hh>
      53             : #include <EnergyPlus/Plant/Loop.hh>
      54             : #include <EnergyPlus/UtilityRoutines.hh>
      55             : 
      56             : namespace EnergyPlus::DataPlant {
      57             : 
      58    17204433 : void PlantLoopData::UpdateLoopSideReportVars(EnergyPlusData &state,
      59             :                                              Real64 const OtherSideDemand,   // This is the 'other side' demand, based on other side flow
      60             :                                              Real64 const LocalRemLoopDemand // Unmet Demand after equipment has been simulated (report variable)
      61             : )
      62             : {
      63             : 
      64             :     // SUBROUTINE INFORMATION:
      65             :     //       AUTHOR         Dan Fisher
      66             :     //       DATE WRITTEN   July 1998
      67             :     //       MODIFIED       Aug 2010 Edwin Lee -- add per LoopSide variable support
      68             :     //       RE-ENGINEERED  na
      69             : 
      70    17204433 :     this->InletNodeFlowrate = state.dataLoopNodes->Node(this->LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumIn).MassFlowRate;
      71    17204433 :     this->InletNodeTemperature = state.dataLoopNodes->Node(this->LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumIn).Temp;
      72    17204433 :     this->OutletNodeFlowrate = state.dataLoopNodes->Node(this->LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumOut).MassFlowRate;
      73    17204433 :     this->OutletNodeTemperature = state.dataLoopNodes->Node(this->LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumOut).Temp;
      74             : 
      75             :     // In the baseline code, only reported supply side demand. so putting in "SupplySide" IF block for now but might expand later
      76    17204433 :     if (OtherSideDemand < 0.0) {
      77     4614102 :         this->CoolingDemand = std::abs(OtherSideDemand);
      78     4614102 :         this->HeatingDemand = 0.0;
      79     4614102 :         this->DemandNotDispatched = -LocalRemLoopDemand; //  Setting sign based on old logic for now
      80             :     } else {
      81    12590331 :         this->HeatingDemand = OtherSideDemand;
      82    12590331 :         this->CoolingDemand = 0.0;
      83    12590331 :         this->DemandNotDispatched = LocalRemLoopDemand; //  Setting sign based on old logic for now
      84             :     }
      85             : 
      86    17204433 :     this->CalcUnmetPlantDemand(state);
      87    17204433 : }
      88             : 
      89    17204433 : void PlantLoopData::CalcUnmetPlantDemand(EnergyPlusData &state)
      90             : {
      91             : 
      92             :     // SUBROUTINE INFORMATION:
      93             :     //       AUTHOR         Brent Griffith
      94             :     //       DATE WRITTEN   June 2011
      95             :     //       MODIFIED       na
      96             :     //       RE-ENGINEERED  na
      97             : 
      98             :     // PURPOSE OF THIS SUBROUTINE:
      99             :     // determine the magnitude of unmet plant loads after the half loop simulation is done
     100             : 
     101             :     // METHODOLOGY EMPLOYED:
     102             :     // using the loop setpoint node, look at target vs current and
     103             :     // calculate a demand based on mass flow times specific heat times delta T
     104             : 
     105             :     // Using/Aliasing
     106             :     using DataPlant::LoopDemandTol;
     107             :     using FluidProperties::GetSatEnthalpyRefrig;
     108             :     using FluidProperties::GetSpecificHeatGlycol;
     109             : 
     110             :     // SUBROUTINE PARAMETER DEFINITIONS:
     111             :     static constexpr std::string_view RoutineName("PlantLoopSolver::EvaluateLoopSetPointLoad");
     112             :     static constexpr std::string_view RoutineNameAlt("PlantSupplySide:EvaluateLoopSetPointLoad");
     113             : 
     114             :     //~ General variables
     115             :     Real64 MassFlowRate;
     116             :     Real64 TargetTemp;
     117             :     Real64 LoopSetPointTemperature;
     118             :     Real64 LoopSetPointTemperatureHi;
     119             :     Real64 LoopSetPointTemperatureLo;
     120             :     Real64 LoadToHeatingSetPoint;
     121             :     Real64 LoadToCoolingSetPoint;
     122             :     Real64 DeltaTemp;
     123             :     Real64 Cp;
     124             :     Real64 EnthalpySteamSatVapor;  // Enthalpy of saturated vapor
     125             :     Real64 EnthalpySteamSatLiquid; // Enthalpy of saturated liquid
     126             :     Real64 LatentHeatSteam;        // Latent heat of steam
     127             :     Real64 LoadToLoopSetPoint;
     128             : 
     129             :     // Initialize
     130    17204433 :     LoadToLoopSetPoint = 0.0;
     131             : 
     132             :     // Get temperature at loop setpoint node.
     133    17204433 :     TargetTemp = state.dataLoopNodes->Node(this->TempSetPointNodeNum).Temp;
     134    17204433 :     MassFlowRate = state.dataLoopNodes->Node(this->TempSetPointNodeNum).MassFlowRate;
     135             : 
     136    17204433 :     if (this->FluidType == DataLoopNode::NodeFluidType::Water) {
     137             : 
     138    17152045 :         Cp = GetSpecificHeatGlycol(state, this->FluidName, TargetTemp, this->FluidIndex, RoutineName);
     139             : 
     140    17152045 :         switch (this->LoopDemandCalcScheme) {
     141    16972667 :         case DataPlant::LoopDemandCalcScheme::SingleSetPoint: {
     142             : 
     143             :             // Pick up the loop setpoint temperature
     144    16972667 :             LoopSetPointTemperature = this->LoopSide(DataPlant::LoopSideLocation::Supply).TempSetPoint;
     145             :             // Calculate the delta temperature
     146    16972667 :             DeltaTemp = LoopSetPointTemperature - TargetTemp;
     147             : 
     148             :             // Calculate the demand on the loop
     149    16972667 :             LoadToLoopSetPoint = MassFlowRate * Cp * DeltaTemp;
     150    16972667 :         } break;
     151      179378 :         case DataPlant::LoopDemandCalcScheme::DualSetPointDeadBand: {
     152             :             // Get the range of setpoints
     153      179378 :             LoopSetPointTemperatureHi = state.dataLoopNodes->Node(this->TempSetPointNodeNum).TempSetPointHi;
     154      179378 :             LoopSetPointTemperatureLo = state.dataLoopNodes->Node(this->TempSetPointNodeNum).TempSetPointLo;
     155             : 
     156             :             // Calculate the demand on the loop
     157      179378 :             if (MassFlowRate > 0.0) {
     158      170899 :                 LoadToHeatingSetPoint = MassFlowRate * Cp * (LoopSetPointTemperatureLo - TargetTemp);
     159      170899 :                 LoadToCoolingSetPoint = MassFlowRate * Cp * (LoopSetPointTemperatureHi - TargetTemp);
     160             :                 // Possible combinations:
     161             :                 // 1  LoadToHeatingSetPoint > 0 & LoadToCoolingSetPoint > 0 -->  Heating required
     162             :                 // 2  LoadToHeatingSetPoint < 0 & LoadToCoolingSetPoint < 0 -->  Cooling Required
     163             :                 // 3  LoadToHeatingSetPoint <=0 & LoadToCoolingSetPoint >=0 -->  Dead Band Operation - includes zero load cases
     164             :                 // 4  LoadToHeatingSetPoint  >  LoadToCoolingSetPoint       -->  Not Feasible if LoopSetPointHi >= LoopSetPointLo
     165      170899 :                 if (LoadToHeatingSetPoint > 0.0 && LoadToCoolingSetPoint > 0.0) {
     166       28230 :                     LoadToLoopSetPoint = LoadToHeatingSetPoint;
     167      142669 :                 } else if (LoadToHeatingSetPoint < 0.0 && LoadToCoolingSetPoint < 0.0) {
     168       38406 :                     LoadToLoopSetPoint = LoadToCoolingSetPoint;
     169      104263 :                 } else if (LoadToHeatingSetPoint <= 0.0 && LoadToCoolingSetPoint >= 0.0) { // deadband includes zero loads
     170      104263 :                     LoadToLoopSetPoint = 0.0;
     171             :                 }
     172             :             } else {
     173        8479 :                 LoadToLoopSetPoint = 0.0;
     174             :             }
     175      179378 :         } break;
     176           0 :         default:
     177           0 :             break;
     178             :         }
     179             : 
     180       52388 :     } else if (this->FluidType == DataLoopNode::NodeFluidType::Steam) {
     181             : 
     182       52388 :         Cp = GetSpecificHeatGlycol(state, this->FluidName, TargetTemp, this->FluidIndex, RoutineName);
     183             : 
     184       52388 :         switch (this->LoopDemandCalcScheme) {
     185       52388 :         case DataPlant::LoopDemandCalcScheme::SingleSetPoint: {
     186             : 
     187             :             // Pick up the loop setpoint temperature
     188       52388 :             LoopSetPointTemperature = this->LoopSide(DataPlant::LoopSideLocation::Supply).TempSetPoint;
     189             : 
     190             :             // Calculate the delta temperature
     191       52388 :             DeltaTemp = LoopSetPointTemperature - TargetTemp;
     192             : 
     193       52388 :             EnthalpySteamSatVapor = GetSatEnthalpyRefrig(state, this->FluidName, LoopSetPointTemperature, 1.0, this->FluidIndex, RoutineNameAlt);
     194       52388 :             EnthalpySteamSatLiquid = GetSatEnthalpyRefrig(state, this->FluidName, LoopSetPointTemperature, 0.0, this->FluidIndex, RoutineNameAlt);
     195             : 
     196       52388 :             LatentHeatSteam = EnthalpySteamSatVapor - EnthalpySteamSatLiquid;
     197             : 
     198             :             // Calculate the demand on the loop
     199       52388 :             LoadToLoopSetPoint = MassFlowRate * (Cp * DeltaTemp + LatentHeatSteam);
     200       52388 :         } break;
     201           0 :         default:
     202           0 :             break;
     203             :         }
     204             : 
     205             :     } else { // only have two types, water serves for glycol.
     206             :     }
     207             : 
     208             :     // Trim the demand to zero if it is very small
     209    17204433 :     if (std::abs(LoadToLoopSetPoint) < LoopDemandTol) LoadToLoopSetPoint = 0.0;
     210             : 
     211    17204433 :     this->UnmetDemand = LoadToLoopSetPoint;
     212    17204433 : }
     213             : 
     214    17204433 : void PlantLoopData::CheckLoopExitNode(EnergyPlusData &state, bool const FirstHVACIteration)
     215             : {
     216             : 
     217             :     // SUBROUTINE INFORMATION:
     218             :     //       AUTHOR         Dan Fisher
     219             :     //       DATE WRITTEN   October 1998
     220             :     //       MODIFIED       na
     221             :     //       RE-ENGINEERED  na
     222             : 
     223             :     // PURPOSE OF THIS SUBROUTINE:
     224             :     // This subroutine sets the temperature
     225             :     // and mass flow rate of the plant loop supply side exit
     226             :     // node.  As written, the routine calculates the exit
     227             :     // temperature based on the fraction of loop demand met
     228             :     // by the plant equipment.  This assumes that each piece
     229             :     // of operating plant equipment produced chilled/hot water
     230             :     // at the loop setpoint temperature.
     231             : 
     232             :     // Using/Aliasing
     233             : 
     234             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     235             :     int LoopInlet;  // plant loop inlet node num.
     236             :     int LoopOutlet; // plant loop outlet node num.
     237             : 
     238             :     // set local variables: loop inlet and outlet nodes
     239    17204433 :     auto &Supply = this->LoopSide(DataPlant::LoopSideLocation::Supply);
     240    17204433 :     LoopInlet = Supply.NodeNumIn;
     241    17204433 :     LoopOutlet = Supply.NodeNumOut;
     242             :     // Check continuity invalid...loop pumps now turned on and off
     243    17204433 :     if (!FirstHVACIteration && !state.dataGlobal->WarmupFlag) {
     244     1617721 :         if (std::abs(state.dataLoopNodes->Node(LoopOutlet).MassFlowRate - state.dataLoopNodes->Node(LoopInlet).MassFlowRate) >
     245             :             DataBranchAirLoopPlant::MassFlowTolerance) {
     246           0 :             if (this->MFErrIndex == 0) {
     247           0 :                 ShowWarningError(state,
     248           0 :                                  "PlantSupplySide: PlantLoop=\"" + this->Name +
     249             :                                      "\", Error (CheckLoopExitNode) -- Mass Flow Rate Calculation. Outlet and Inlet differ by more than tolerance.");
     250           0 :                 ShowContinueErrorTimeStamp(state, "");
     251           0 :                 ShowContinueError(state,
     252           0 :                                   format("Loop inlet node={}, flowrate={:.4R} kg/s",
     253           0 :                                          state.dataLoopNodes->NodeID(LoopInlet),
     254           0 :                                          state.dataLoopNodes->Node(LoopInlet).MassFlowRate));
     255           0 :                 ShowContinueError(state,
     256           0 :                                   format("Loop outlet node={}, flowrate={:.4R} kg/s",
     257           0 :                                          state.dataLoopNodes->NodeID(LoopOutlet),
     258           0 :                                          state.dataLoopNodes->Node(LoopOutlet).MassFlowRate));
     259           0 :                 ShowContinueError(state, "This loop might be helped by a bypass.");
     260             :             }
     261           0 :             ShowRecurringWarningErrorAtEnd(
     262           0 :                 state, "PlantSupplySide: PlantLoop=\"" + this->Name + "\", Error -- Mass Flow Rate Calculation -- continues ** ", this->MFErrIndex);
     263             :         }
     264             :     }
     265             :     // Reset Max loop flow rate based on pump performance
     266    17204433 :     state.dataLoopNodes->Node(LoopOutlet).MassFlowRateMax = state.dataLoopNodes->Node(LoopInlet).MassFlowRateMax;
     267    17204433 : }
     268             : 
     269        2313 : } // namespace EnergyPlus::DataPlant

Generated by: LCOV version 1.13