LCOV - code coverage report
Current view: top level - EnergyPlus - SurfaceGroundHeatExchanger.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 0.0 % 528 0
Test Date: 2025-05-22 16:09:37 Functions: 0.0 % 17 0

            Line data    Source code
       1              : // EnergyPlus, Copyright (c) 1996-2025, 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 <cmath>
      50              : 
      51              : // ObjexxFCL Headers
      52              : #include <ObjexxFCL/Array.functions.hh>
      53              : 
      54              : // EnergyPlus Headers
      55              : #include <EnergyPlus/BranchNodeConnections.hh>
      56              : #include <EnergyPlus/Construction.hh>
      57              : #include <EnergyPlus/ConvectionCoefficients.hh>
      58              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      59              : #include <EnergyPlus/DataEnvironment.hh>
      60              : #include <EnergyPlus/DataHVACGlobals.hh>
      61              : #include <EnergyPlus/DataHeatBalance.hh>
      62              : #include <EnergyPlus/DataIPShortCuts.hh>
      63              : #include <EnergyPlus/DataLoopNode.hh>
      64              : #include <EnergyPlus/DataPrecisionGlobals.hh>
      65              : #include <EnergyPlus/FluidProperties.hh>
      66              : #include <EnergyPlus/General.hh>
      67              : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      68              : #include <EnergyPlus/Material.hh>
      69              : #include <EnergyPlus/NodeInputManager.hh>
      70              : #include <EnergyPlus/OutputProcessor.hh>
      71              : #include <EnergyPlus/Plant/DataPlant.hh>
      72              : #include <EnergyPlus/PlantUtilities.hh>
      73              : #include <EnergyPlus/SurfaceGroundHeatExchanger.hh>
      74              : #include <EnergyPlus/UtilityRoutines.hh>
      75              : 
      76              : namespace EnergyPlus {
      77              : 
      78              : namespace SurfaceGroundHeatExchanger {
      79              : 
      80              :     // Module containing the routines dealing with surface/panel ground heat exchangers
      81              : 
      82              :     // MODULE INFORMATION:
      83              :     //       AUTHOR         Simon Rees
      84              :     //       DATE WRITTEN   August 2002
      85              :     //       MODIFIED       Brent Griffith, Sept 2010, plant upgrades
      86              :     //       RE-ENGINEERED  na
      87              : 
      88              :     // PURPOSE OF THIS MODULE:
      89              :     // The purpose of this module is to simulate hydronic Surface Ground Heat
      90              :     // Exchangers. This includes pavement surfaces with embedded pipes for snow-
      91              :     // melting or heat rejection from hybrid ground source heat pump systems.
      92              :     // The heat exchanger may be gound coupled or not. In the latter case the
      93              :     // bottom surface is exposed to the wind but not solar gains.
      94              : 
      95              :     // METHODOLOGY EMPLOYED:
      96              :     // This model is based on the QTF formulation of heat transfer through
      97              :     // building elements with embedded heat sources/sinks. The model uses
      98              :     // a heat exchanger analogy to relate the inlet fluid temperature to the
      99              :     // net heat transfer rate and consequently outlet temperature. The model
     100              :     // is entirely passive i.e. it does not set any flow rates or incorporate
     101              :     // any controls. In order to deal with the non-linear boundary conditions
     102              :     // at the top surface due to the presence of ice/snow fluxes have to be
     103              :     // calculated by the QTF model and temperature calculated from the surface
     104              :     // heat balance. This requires some iteration.
     105              :     // Note: top surface variables correspond to 'outside' variables in standard
     106              :     // CTF/QTF definition. Bottom surface variables correspond to 'inside' variables.
     107              : 
     108              :     // REFERENCES:
     109              :     // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     110              :     //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     111              :     //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     112              :     //   Engineering.
     113              :     // Seem, J.E. 1986. "Heat Transfer in Buildings", Ph.D. dissertation, University
     114              :     //   of Wisconsin-Madison.
     115              : 
     116              :     // OTHER NOTES: none
     117              : 
     118              :     // USE STATEMENTS:
     119              :     // Use statements for data only modules
     120              :     // Using/Aliasing
     121              :     using namespace DataLoopNode;
     122              : 
     123              :     // Use statements for access to subroutines in other modules
     124              : 
     125              :     // Data
     126              :     // MODULE PARAMETER DEFINITIONS
     127              :     Real64 constexpr SmallNum(1.0e-30);         // Very small number to avoid div0 errors
     128              :     Real64 constexpr StefBoltzmann(5.6697e-08); // Stefan-Boltzmann constant
     129              :     Real64 constexpr SurfaceHXHeight(0.0);      // Surface Height above ground -- used in height dependent calcs.
     130              : 
     131              :     int constexpr SurfCond_Ground(1);
     132              :     int constexpr SurfCond_Exposed(2);
     133              : 
     134            0 :     PlantComponent *SurfaceGroundHeatExchangerData::factory(EnergyPlusData &state,
     135              :                                                             [[maybe_unused]] DataPlant::PlantEquipmentType objectType,
     136              :                                                             std::string const objectName)
     137              :     {
     138            0 :         if (state.dataSurfaceGroundHeatExchangers->GetInputFlag) {
     139            0 :             GetSurfaceGroundHeatExchanger(state);
     140            0 :             state.dataSurfaceGroundHeatExchangers->GetInputFlag = false;
     141              :         }
     142              :         // Now look for this particular pipe in the list
     143            0 :         for (auto &ghx : state.dataSurfaceGroundHeatExchangers->SurfaceGHE) {
     144            0 :             if (ghx.Name == objectName) {
     145            0 :                 return &ghx;
     146              :             }
     147              :         }
     148              :         // If we didn't find it, fatal
     149            0 :         ShowFatalError(state, format("Surface Ground Heat Exchanger: Error getting inputs for pipe named: {}", objectName));
     150              :         // Shut up the compiler
     151            0 :         return nullptr;
     152              :     }
     153              : 
     154            0 :     void SurfaceGroundHeatExchangerData::simulate(EnergyPlusData &state,
     155              :                                                   [[maybe_unused]] const PlantLocation &calledFromLocation,
     156              :                                                   bool const FirstHVACIteration,
     157              :                                                   [[maybe_unused]] Real64 &CurLoad,
     158              :                                                   [[maybe_unused]] bool const RunFlag)
     159              :     {
     160            0 :         this->InitSurfaceGroundHeatExchanger(state);
     161            0 :         this->CalcSurfaceGroundHeatExchanger(state, FirstHVACIteration);
     162            0 :         this->UpdateSurfaceGroundHeatExchngr(state);
     163            0 :         this->ReportSurfaceGroundHeatExchngr(state);
     164            0 :     }
     165              : 
     166            0 :     void GetSurfaceGroundHeatExchanger(EnergyPlusData &state)
     167              :     {
     168              : 
     169              :         // SUBROUTINE INFORMATION:
     170              :         //       AUTHOR         Simon Rees
     171              :         //       DATE WRITTEN   August 2002
     172              :         //       MODIFIED       na
     173              :         //       RE-ENGINEERED  na
     174              : 
     175              :         // PURPOSE OF THIS SUBROUTINE:
     176              :         // This subroutine reads the input for hydronic Surface Ground Heat Exchangers
     177              :         // from the user input file.  This will contain all of the information
     178              :         // needed to define and simulate the surface.
     179              : 
     180              :         // METHODOLOGY EMPLOYED:
     181              :         // Standard EnergyPlus methodology.
     182              : 
     183              :         // Using/Aliasing
     184              :         using BranchNodeConnections::TestCompSet;
     185              :         using NodeInputManager::GetOnlySingleNode;
     186              :         using namespace DataLoopNode;
     187              : 
     188              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     189              : 
     190            0 :         bool ErrorsFound(false); // Set to true if errors in input,
     191              :         // fatal at end of routine
     192              :         int IOStatus;   // Used in GetObjectItem
     193              :         int Item;       // Item to be "gotten"
     194              :         int NumAlphas;  // Number of Alphas for each GetObjectItem call
     195              :         int NumNumbers; // Number of Numbers for each GetObjectItem call
     196            0 :         auto &cCurrentModuleObject = state.dataIPShortCut->cCurrentModuleObject;
     197              :         // Initializations and allocations
     198            0 :         cCurrentModuleObject = "GroundHeatExchanger:Surface";
     199            0 :         int NumOfSurfaceGHEs = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
     200              :         // allocate data structures
     201            0 :         if (allocated(state.dataSurfaceGroundHeatExchangers->SurfaceGHE)) state.dataSurfaceGroundHeatExchangers->SurfaceGHE.deallocate();
     202              : 
     203            0 :         state.dataSurfaceGroundHeatExchangers->SurfaceGHE.allocate(NumOfSurfaceGHEs);
     204            0 :         state.dataSurfaceGroundHeatExchangers->CheckEquipName.dimension(NumOfSurfaceGHEs, true);
     205              : 
     206              :         // initialize data structures
     207              :         // surface data
     208              :         // Obtain all of the user data related to the surfaces...
     209            0 :         for (Item = 1; Item <= NumOfSurfaceGHEs; ++Item) {
     210              : 
     211              :             // get the input data
     212            0 :             state.dataInputProcessing->inputProcessor->getObjectItem(state,
     213              :                                                                      cCurrentModuleObject,
     214              :                                                                      Item,
     215            0 :                                                                      state.dataIPShortCut->cAlphaArgs,
     216              :                                                                      NumAlphas,
     217            0 :                                                                      state.dataIPShortCut->rNumericArgs,
     218              :                                                                      NumNumbers,
     219              :                                                                      IOStatus,
     220              :                                                                      _,
     221              :                                                                      _,
     222            0 :                                                                      state.dataIPShortCut->cAlphaFieldNames,
     223            0 :                                                                      state.dataIPShortCut->cNumericFieldNames);
     224              : 
     225              :             // General user input data
     226            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name = state.dataIPShortCut->cAlphaArgs(1);
     227            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).ConstructionName = state.dataIPShortCut->cAlphaArgs(2);
     228            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).ConstructionNum =
     229            0 :                 Util::FindItemInList(state.dataIPShortCut->cAlphaArgs(2), state.dataConstruction->Construct);
     230              : 
     231            0 :             if (state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).ConstructionNum == 0) {
     232            0 :                 ShowSevereError(state, format("Invalid {}={}", state.dataIPShortCut->cAlphaFieldNames(2), state.dataIPShortCut->cAlphaArgs(2)));
     233            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     234            0 :                 ErrorsFound = true;
     235              :             }
     236              : 
     237              :             // Error checking for surfaces, zones, and construction information
     238            0 :             if (!state.dataConstruction->Construct(state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).ConstructionNum).SourceSinkPresent) {
     239            0 :                 ShowSevereError(state, format("Invalid {}={}", state.dataIPShortCut->cAlphaFieldNames(2), state.dataIPShortCut->cAlphaArgs(2)));
     240            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     241            0 :                 ShowContinueError(
     242              :                     state, "Construction must have internal source/sink and be referenced by a ConstructionProperty:InternalHeatSource object");
     243            0 :                 ErrorsFound = true;
     244              :             }
     245              : 
     246              :             // get inlet node data
     247            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).InletNode = state.dataIPShortCut->cAlphaArgs(3);
     248            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).InletNodeNum =
     249            0 :                 GetOnlySingleNode(state,
     250            0 :                                   state.dataIPShortCut->cAlphaArgs(3),
     251              :                                   ErrorsFound,
     252              :                                   DataLoopNode::ConnectionObjectType::GroundHeatExchangerSurface,
     253            0 :                                   state.dataIPShortCut->cAlphaArgs(1),
     254              :                                   DataLoopNode::NodeFluidType::Water,
     255              :                                   DataLoopNode::ConnectionType::Inlet,
     256              :                                   NodeInputManager::CompFluidStream::Primary,
     257              :                                   ObjectIsNotParent);
     258            0 :             if (state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).InletNodeNum == 0) {
     259            0 :                 ShowSevereError(state, format("Invalid {}={}", state.dataIPShortCut->cAlphaFieldNames(3), state.dataIPShortCut->cAlphaArgs(3)));
     260            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     261            0 :                 ErrorsFound = true;
     262              :             }
     263              : 
     264              :             // get outlet node data
     265            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).OutletNode = state.dataIPShortCut->cAlphaArgs(4);
     266            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).OutletNodeNum =
     267            0 :                 GetOnlySingleNode(state,
     268            0 :                                   state.dataIPShortCut->cAlphaArgs(4),
     269              :                                   ErrorsFound,
     270              :                                   DataLoopNode::ConnectionObjectType::GroundHeatExchangerSurface,
     271            0 :                                   state.dataIPShortCut->cAlphaArgs(1),
     272              :                                   DataLoopNode::NodeFluidType::Water,
     273              :                                   DataLoopNode::ConnectionType::Outlet,
     274              :                                   NodeInputManager::CompFluidStream::Primary,
     275              :                                   ObjectIsNotParent);
     276            0 :             if (state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).OutletNodeNum == 0) {
     277            0 :                 ShowSevereError(state, format("Invalid {}={}", state.dataIPShortCut->cAlphaFieldNames(4), state.dataIPShortCut->cAlphaArgs(4)));
     278            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     279            0 :                 ErrorsFound = true;
     280              :             }
     281              : 
     282            0 :             TestCompSet(state,
     283              :                         cCurrentModuleObject,
     284            0 :                         state.dataIPShortCut->cAlphaArgs(1),
     285            0 :                         state.dataIPShortCut->cAlphaArgs(3),
     286            0 :                         state.dataIPShortCut->cAlphaArgs(4),
     287              :                         "Condenser Water Nodes");
     288              : 
     289              :             // tube data
     290            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).TubeDiameter = state.dataIPShortCut->rNumericArgs(1);
     291            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).TubeCircuits = state.dataIPShortCut->rNumericArgs(2);
     292            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).TubeSpacing = state.dataIPShortCut->rNumericArgs(3);
     293              : 
     294            0 :             if (state.dataIPShortCut->rNumericArgs(2) == 0) {
     295            0 :                 ShowSevereError(state,
     296            0 :                                 format("Invalid {}={:.2R}", state.dataIPShortCut->cNumericFieldNames(2), state.dataIPShortCut->rNumericArgs(2)));
     297            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     298            0 :                 ShowContinueError(state, "Value must be greater than 0.0");
     299            0 :                 ErrorsFound = true;
     300              :             }
     301            0 :             if (state.dataIPShortCut->rNumericArgs(3) == 0.0) {
     302            0 :                 ShowSevereError(state,
     303            0 :                                 format("Invalid {}={:.2R}", state.dataIPShortCut->cNumericFieldNames(3), state.dataIPShortCut->rNumericArgs(3)));
     304            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     305            0 :                 ShowContinueError(state, "Value must be greater than 0.0");
     306            0 :                 ErrorsFound = true;
     307              :             }
     308              : 
     309              :             // surface geometry data
     310            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).SurfaceLength = state.dataIPShortCut->rNumericArgs(4);
     311            0 :             state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).SurfaceWidth = state.dataIPShortCut->rNumericArgs(5);
     312            0 :             if (state.dataIPShortCut->rNumericArgs(4) <= 0.0) {
     313            0 :                 ShowSevereError(state,
     314            0 :                                 format("Invalid {}={:.2R}", state.dataIPShortCut->cNumericFieldNames(4), state.dataIPShortCut->rNumericArgs(4)));
     315            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     316            0 :                 ShowContinueError(state, "Value must be greater than 0.0");
     317            0 :                 ErrorsFound = true;
     318              :             }
     319            0 :             if (state.dataIPShortCut->rNumericArgs(5) <= 0.0) {
     320            0 :                 ShowSevereError(state,
     321            0 :                                 format("Invalid {}={:.2R}", state.dataIPShortCut->cNumericFieldNames(5), state.dataIPShortCut->rNumericArgs(5)));
     322            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     323            0 :                 ShowContinueError(state, "Value must be greater than 0.0");
     324            0 :                 ErrorsFound = true;
     325              :             }
     326              : 
     327              :             // get lower b.c. type
     328            0 :             if (Util::SameString(state.dataIPShortCut->cAlphaArgs(5), "GROUND")) {
     329            0 :                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).LowerSurfCond = SurfCond_Ground;
     330            0 :             } else if (Util::SameString(state.dataIPShortCut->cAlphaArgs(5), "EXPOSED")) {
     331            0 :                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).LowerSurfCond = SurfCond_Exposed;
     332              :             } else {
     333            0 :                 ShowSevereError(state, format("Invalid {}={}", state.dataIPShortCut->cAlphaFieldNames(5), state.dataIPShortCut->cAlphaArgs(5)));
     334            0 :                 ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
     335            0 :                 ShowContinueError(state, "Only \"Ground\" or \"Exposed\" is allowed.");
     336            0 :                 ErrorsFound = true;
     337              :             }
     338              : 
     339              :         } // end of input loop
     340              : 
     341              :         // final error check
     342            0 :         if (ErrorsFound) {
     343            0 :             ShowFatalError(state, format("Errors found in processing input for {}", cCurrentModuleObject));
     344              :         }
     345              : 
     346              :         // Set up the output variables
     347            0 :         for (Item = 1; Item <= NumOfSurfaceGHEs; ++Item) {
     348            0 :             SetupOutputVariable(state,
     349              :                                 "Ground Heat Exchanger Heat Transfer Rate",
     350              :                                 Constant::Units::W,
     351            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).HeatTransferRate,
     352              :                                 OutputProcessor::TimeStepType::System,
     353              :                                 OutputProcessor::StoreType::Average,
     354            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     355            0 :             SetupOutputVariable(state,
     356              :                                 "Ground Heat Exchanger Surface Heat Transfer Rate",
     357              :                                 Constant::Units::W,
     358            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).SurfHeatTransferRate,
     359              :                                 OutputProcessor::TimeStepType::System,
     360              :                                 OutputProcessor::StoreType::Average,
     361            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     362            0 :             SetupOutputVariable(state,
     363              :                                 "Ground Heat Exchanger Heat Transfer Energy",
     364              :                                 Constant::Units::J,
     365            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Energy,
     366              :                                 OutputProcessor::TimeStepType::System,
     367              :                                 OutputProcessor::StoreType::Sum,
     368            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     369            0 :             SetupOutputVariable(state,
     370              :                                 "Ground Heat Exchanger Mass Flow Rate",
     371              :                                 Constant::Units::kg_s,
     372            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).MassFlowRate,
     373              :                                 OutputProcessor::TimeStepType::System,
     374              :                                 OutputProcessor::StoreType::Average,
     375            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     376            0 :             SetupOutputVariable(state,
     377              :                                 "Ground Heat Exchanger Inlet Temperature",
     378              :                                 Constant::Units::C,
     379            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).InletTemp,
     380              :                                 OutputProcessor::TimeStepType::System,
     381              :                                 OutputProcessor::StoreType::Average,
     382            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     383            0 :             SetupOutputVariable(state,
     384              :                                 "Ground Heat Exchanger Outlet Temperature",
     385              :                                 Constant::Units::C,
     386            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).OutletTemp,
     387              :                                 OutputProcessor::TimeStepType::System,
     388              :                                 OutputProcessor::StoreType::Average,
     389            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     390            0 :             SetupOutputVariable(state,
     391              :                                 "Ground Heat Exchanger Top Surface Temperature",
     392              :                                 Constant::Units::C,
     393            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).TopSurfaceTemp,
     394              :                                 OutputProcessor::TimeStepType::System,
     395              :                                 OutputProcessor::StoreType::Average,
     396            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     397            0 :             SetupOutputVariable(state,
     398              :                                 "Ground Heat Exchanger Bottom Surface Temperature",
     399              :                                 Constant::Units::C,
     400            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).BtmSurfaceTemp,
     401              :                                 OutputProcessor::TimeStepType::System,
     402              :                                 OutputProcessor::StoreType::Average,
     403            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     404            0 :             SetupOutputVariable(state,
     405              :                                 "Ground Heat Exchanger Top Surface Heat Transfer Energy per Area",
     406              :                                 Constant::Units::J_m2,
     407            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).TopSurfaceFlux,
     408              :                                 OutputProcessor::TimeStepType::System,
     409              :                                 OutputProcessor::StoreType::Average,
     410            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     411            0 :             SetupOutputVariable(state,
     412              :                                 "Ground Heat Exchanger Bottom Surface Heat Transfer Energy per Area",
     413              :                                 Constant::Units::J_m2,
     414            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).BtmSurfaceFlux,
     415              :                                 OutputProcessor::TimeStepType::System,
     416              :                                 OutputProcessor::StoreType::Average,
     417            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     418            0 :             SetupOutputVariable(state,
     419              :                                 "Ground Heat Exchanger Surface Heat Transfer Energy",
     420              :                                 Constant::Units::J,
     421            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).SurfEnergy,
     422              :                                 OutputProcessor::TimeStepType::System,
     423              :                                 OutputProcessor::StoreType::Sum,
     424            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     425            0 :             SetupOutputVariable(state,
     426              :                                 "Ground Heat Exchanger Source Temperature",
     427              :                                 Constant::Units::C,
     428            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).SourceTemp,
     429              :                                 OutputProcessor::TimeStepType::System,
     430              :                                 OutputProcessor::StoreType::Average,
     431            0 :                                 state.dataSurfaceGroundHeatExchangers->SurfaceGHE(Item).Name);
     432              :         }
     433              : 
     434            0 :         if (state.dataSurfaceGroundHeatExchangers->NoSurfaceGroundTempObjWarning) {
     435            0 :             if (!state.dataEnvrn->GroundTempInputs[(int)DataEnvironment::GroundTempType::Shallow]) {
     436            0 :                 ShowWarningError(state, "GetSurfaceGroundHeatExchanger: No \"Site:GroundTemperature:Shallow\" were input.");
     437            0 :                 ShowContinueError(state,
     438            0 :                                   format("Defaults, constant throughout the year of ({:.1R}) will be used.",
     439            0 :                                          state.dataEnvrn->GroundTemp[(int)DataEnvironment::GroundTempType::Shallow]));
     440              :             }
     441            0 :             state.dataSurfaceGroundHeatExchangers->NoSurfaceGroundTempObjWarning = false;
     442              :         }
     443            0 :     }
     444              : 
     445            0 :     void SurfaceGroundHeatExchangerData::InitSurfaceGroundHeatExchanger(EnergyPlusData &state)
     446              :     {
     447              : 
     448              :         // SUBROUTINE INFORMATION:
     449              :         //       AUTHOR         Simon Rees
     450              :         //       DATE WRITTEN   August 2002
     451              :         //       MODIFIED       na
     452              :         //       RE-ENGINEERED  na
     453              : 
     454              :         // PURPOSE OF THIS SUBROUTINE:
     455              :         // This subroutine Resets the elements of the data structure as necessary
     456              :         // at the first HVAC iteration of each time step. The weather and QTF data
     457              :         // is initialized once only.
     458              : 
     459              :         // METHODOLOGY EMPLOYED:
     460              :         // Check flags and update data structure
     461              : 
     462              :         // Using/Aliasing
     463              :         using namespace DataEnvironment;
     464              :         using PlantUtilities::RegulateCondenserCompFlowReqOp;
     465              :         using PlantUtilities::SetComponentFlowRate;
     466              : 
     467              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     468              : 
     469              :         Real64 DesignFlow; // Hypothetical design flow rate
     470              :         int Cons;          // construction counter
     471              :         int LayerNum;      // material layer number for bottom
     472              :         Real64 OutDryBulb; // Height Dependent dry bulb.
     473              : 
     474            0 :         auto &s_mat = state.dataMaterial;
     475              : 
     476              :         // get QTF data - only once
     477            0 :         if (this->InitQTF) {
     478            0 :             for (Cons = 1; Cons <= state.dataHeatBal->TotConstructs; ++Cons) {
     479            0 :                 if (Util::SameString(state.dataConstruction->Construct(Cons).Name, this->ConstructionName)) {
     480              :                     // some error checking ??
     481              :                     // CTF stuff
     482            0 :                     LayerNum = state.dataConstruction->Construct(Cons).TotLayers;
     483            0 :                     this->NumCTFTerms = state.dataConstruction->Construct(Cons).NumCTFTerms;
     484            0 :                     this->CTFin = state.dataConstruction->Construct(Cons).CTFInside;   // Z coefficents
     485            0 :                     this->CTFout = state.dataConstruction->Construct(Cons).CTFOutside; // X coefficents
     486            0 :                     this->CTFcross = state.dataConstruction->Construct(Cons).CTFCross; // Y coefficents
     487            0 :                     for (size_t i = 1; i < state.dataConstruction->Construct(Cons).CTFFlux.size(); i++) {
     488            0 :                         this->CTFflux[i] = state.dataConstruction->Construct(Cons).CTFFlux[i]; // F & f coefficents
     489              :                     }
     490              :                     // QTF stuff
     491            0 :                     this->CTFSourceIn = state.dataConstruction->Construct(Cons).CTFSourceIn;     // Wi coefficents
     492            0 :                     this->CTFSourceOut = state.dataConstruction->Construct(Cons).CTFSourceOut;   // Wo coefficents
     493            0 :                     this->CTFTSourceOut = state.dataConstruction->Construct(Cons).CTFTSourceOut; // y coefficents
     494            0 :                     this->CTFTSourceIn = state.dataConstruction->Construct(Cons).CTFTSourceIn;   // x coefficents
     495            0 :                     this->CTFTSourceQ = state.dataConstruction->Construct(Cons).CTFTSourceQ;     // w coefficents
     496            0 :                     this->ConstructionNum = Cons;
     497              :                     // surface properties
     498            0 :                     auto const *thisMaterialLayer = s_mat->materials(state.dataConstruction->Construct(Cons).LayerPoint(LayerNum));
     499            0 :                     assert(thisMaterialLayer != nullptr);
     500            0 :                     this->BtmRoughness = thisMaterialLayer->Roughness;
     501            0 :                     this->TopThermAbs = thisMaterialLayer->AbsorpThermal;
     502            0 :                     auto const *thisMaterial1 = s_mat->materials(state.dataConstruction->Construct(Cons).LayerPoint(1));
     503            0 :                     assert(thisMaterial1 != nullptr);
     504            0 :                     this->TopRoughness = thisMaterial1->Roughness;
     505            0 :                     this->TopThermAbs = thisMaterial1->AbsorpThermal;
     506            0 :                     this->TopSolarAbs = thisMaterial1->AbsorpSolar;
     507              :                 }
     508              :             }
     509              :             // set one-time flag
     510            0 :             this->InitQTF = false;
     511              :         }
     512              : 
     513            0 :         if (this->MyEnvrnFlag && state.dataGlobal->BeginEnvrnFlag) {
     514            0 :             OutDryBulb = OutDryBulbTempAt(state, SurfaceHXHeight);
     515            0 :             this->CTFflux[0] = 0.0;
     516            0 :             this->TsrcHistory.fill(OutDryBulb);
     517            0 :             this->TbtmHistory.fill(OutDryBulb);
     518            0 :             this->TtopHistory.fill(OutDryBulb);
     519            0 :             this->TsrcHistory.fill(OutDryBulb);
     520            0 :             this->QbtmHistory.fill(0.0);
     521            0 :             this->QtopHistory.fill(0.0);
     522            0 :             this->QsrcHistory.fill(0.0);
     523            0 :             this->TsrcConstCoef = 0.0;
     524            0 :             this->TsrcVarCoef = 0.0;
     525            0 :             this->QbtmConstCoef = 0.0;
     526            0 :             this->QbtmVarCoef = 0.0;
     527            0 :             this->QtopConstCoef = 0.0;
     528            0 :             this->QtopVarCoef = 0.0;
     529            0 :             this->QSrc = 0.0;
     530            0 :             this->QSrcAvg = 0.0;
     531            0 :             this->LastQSrc = 0.0;
     532            0 :             this->LastSysTimeElapsed = 0.0;
     533            0 :             this->LastTimeStepSys = 0.0;
     534              :             // initialize past weather variables
     535            0 :             state.dataSurfaceGroundHeatExchangers->PastBeamSolarRad = state.dataEnvrn->BeamSolarRad;
     536            0 :             state.dataSurfaceGroundHeatExchangers->PastSolarDirCosVert = state.dataEnvrn->SOLCOS(3);
     537            0 :             state.dataSurfaceGroundHeatExchangers->PastDifSolarRad = state.dataEnvrn->DifSolarRad;
     538            0 :             state.dataSurfaceGroundHeatExchangers->PastGroundTemp = state.dataEnvrn->GroundTemp[(int)DataEnvironment::GroundTempType::Shallow];
     539            0 :             state.dataSurfaceGroundHeatExchangers->PastIsRain = state.dataEnvrn->IsRain;
     540            0 :             state.dataSurfaceGroundHeatExchangers->PastIsSnow = state.dataEnvrn->IsSnow;
     541            0 :             state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp = OutDryBulbTempAt(state, SurfaceHXHeight);
     542            0 :             state.dataSurfaceGroundHeatExchangers->PastOutWetBulbTemp = OutWetBulbTempAt(state, SurfaceHXHeight);
     543            0 :             state.dataSurfaceGroundHeatExchangers->PastSkyTemp = state.dataEnvrn->SkyTemp;
     544            0 :             state.dataSurfaceGroundHeatExchangers->PastWindSpeed = DataEnvironment::WindSpeedAt(state, SurfaceHXHeight);
     545            0 :             this->MyEnvrnFlag = false;
     546              :         }
     547              : 
     548            0 :         if (!state.dataGlobal->BeginEnvrnFlag) this->MyEnvrnFlag = true;
     549              : 
     550              :         // always initialize - module variables
     551            0 :         this->SurfaceArea = this->SurfaceLength * this->SurfaceWidth;
     552              : 
     553              :         // If loop operation is controlled by an environmental variable (DBtemp, WBtemp, etc)
     554              :         // then shut branch down when equipment is not scheduled to run.
     555            0 :         DesignFlow = RegulateCondenserCompFlowReqOp(state, this->plantLoc, this->DesignMassFlowRate);
     556              : 
     557            0 :         SetComponentFlowRate(state, DesignFlow, this->InletNodeNum, this->OutletNodeNum, this->plantLoc);
     558              : 
     559              :         // get the current flow rate - module variable
     560            0 :         state.dataSurfaceGroundHeatExchangers->FlowRate = state.dataLoopNodes->Node(this->InletNodeNum).MassFlowRate;
     561            0 :     }
     562              : 
     563            0 :     void SurfaceGroundHeatExchangerData::CalcSurfaceGroundHeatExchanger(
     564              :         EnergyPlusData &state, bool const FirstHVACIteration // TRUE if 1st HVAC simulation of system timestep
     565              :     )
     566              :     {
     567              : 
     568              :         //       AUTHOR         Simon Rees
     569              :         //       DATE WRITTEN   August 2002
     570              :         //       MODIFIED       na
     571              :         //       RE-ENGINEERED  na
     572              : 
     573              :         // PURPOSE OF THIS SUBROUTINE:
     574              :         // This subroutine does all of the stuff that is necessary to simulate
     575              :         // a surface ground heat exchanger.  Calls are made to appropriate subroutines
     576              :         // either in this module or outside of it.
     577              : 
     578              :         // METHODOLOGY EMPLOYED:
     579              :         // To update temperature and flux histories it is necessary to make a surface
     580              :         // flux/temperature calculation at the begining of each zone time step using the
     581              :         // weather data from the previous step, and using the average source flux.
     582              :         // Once this has been done a new source flux, and current surface temperatures,
     583              :         // are calculated using the current weather data. These surface temperatures and
     584              :         // fluxes are used for the rest of the system time steps. During subsequent system
     585              :         // time steps only the source flux is updated.
     586              : 
     587              :         // Surface fluxes are calculated from the QTF equations using assumed surface
     588              :         // temperatures. Surface fluxes are then dependant only on source flux. Constant
     589              :         // and terms and terms that multiply the source flux from the QTF equations, are
     590              :         // grouped together for convenience. These are calculated in "CalcBottomFluxCoefficents"
     591              :         // etc. It is necessary to iterate on these equations, updating the current surface
     592              :         // temperatures at each step.
     593              : 
     594              :         // REFERENCES:
     595              :         // See 'LowTempRadiantSystem' module
     596              :         // IBLAST-QTF research program, completed in January 1995 (unreleased)
     597              :         // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     598              :         //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     599              :         //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     600              :         //   Engineering.
     601              :         // Seem, J.E. 1986. "Heat Transfer in Buildings", Ph.D. dissertation, University
     602              :         //   of Wisconsin-Madison.
     603              : 
     604              :         // Using/Aliasing
     605              :         using namespace DataEnvironment;
     606              : 
     607            0 :         Real64 constexpr SurfFluxTol(0.001); // tolerance on the surface fluxes
     608            0 :         Real64 constexpr SrcFluxTol(0.001);  // tolerance on the source flux
     609            0 :         Real64 constexpr RelaxT(0.1);        // temperature relaxation factor
     610            0 :         int constexpr Maxiter(100);
     611            0 :         int constexpr Maxiter1(100);
     612              : 
     613              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     614              :         Real64 PastFluxTop;    // top surface flux - past value
     615              :         Real64 PastFluxBtm;    // bottom surface flux - past value
     616              :         Real64 PastTempBtm;    // bottom surface temp - past value
     617              :         Real64 PastTempTop;    // top surface temp - past value
     618              :         Real64 OldPastFluxTop; // top surface flux - past value used during iteration
     619              :         Real64 OldPastFluxBtm; // bottom surface flux - past value used during iteration
     620              :         // variables used with current environmental conditions
     621            0 :         auto &FluxTop = state.dataSurfaceGroundHeatExchangers->FluxTop; // top surface flux
     622            0 :         auto &FluxBtm = state.dataSurfaceGroundHeatExchangers->FluxBtm; // bottom surface flux
     623            0 :         auto &TempBtm = state.dataSurfaceGroundHeatExchangers->TempBtm; // bottom surface temp
     624            0 :         auto &TempTop = state.dataSurfaceGroundHeatExchangers->TempTop; // top surface temp
     625              :         Real64 TempT;                                                   // top surface temp - used in underrelaxation
     626              :         Real64 TempB;                                                   // bottom surface temp - used in underrelaxation
     627              :         Real64 OldFluxTop;                                              // top surface flux - value used during iteration
     628              :         Real64 OldFluxBtm;                                              // bottom surface flux - value used during iteration
     629              :         Real64 OldSourceFlux;                                           // previous value of source flux - used during iteration
     630              :         int iter;
     631              :         int iter1;
     632              : 
     633              :         // check if we are in very first call for this zone time step
     634            0 :         if (FirstHVACIteration && !state.dataHVACGlobal->ShortenTimeStepSys && this->firstTimeThrough) {
     635            0 :             this->firstTimeThrough = false;
     636              :             // calc temps and fluxes with past env. conditions and average source flux
     637            0 :             state.dataSurfaceGroundHeatExchangers->SourceFlux = this->QSrcAvg;
     638              :             // starting values for the surface temps
     639            0 :             PastTempBtm = this->TbtmHistory[1];
     640            0 :             PastTempTop = this->TtopHistory[1];
     641            0 :             OldPastFluxTop = 1.0e+30;
     642            0 :             OldPastFluxBtm = 1.0e+30;
     643            0 :             TempB = 0.0;
     644            0 :             TempT = 0.0;
     645            0 :             iter = 0;
     646              :             while (true) { // iterate to find surface heat balances
     647              :                 // update coefficients
     648              : 
     649            0 :                 ++iter;
     650            0 :                 CalcTopFluxCoefficents(PastTempBtm, PastTempTop);
     651              :                 // calc top surface flux
     652            0 :                 PastFluxTop = this->QtopConstCoef + this->QtopVarCoef * state.dataSurfaceGroundHeatExchangers->SourceFlux;
     653              : 
     654              :                 // calc new top surface temp
     655            0 :                 CalcTopSurfTemp(-PastFluxTop,
     656              :                                 TempT,
     657            0 :                                 state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp,
     658            0 :                                 state.dataSurfaceGroundHeatExchangers->PastOutWetBulbTemp,
     659            0 :                                 state.dataSurfaceGroundHeatExchangers->PastSkyTemp,
     660            0 :                                 state.dataSurfaceGroundHeatExchangers->PastBeamSolarRad,
     661            0 :                                 state.dataSurfaceGroundHeatExchangers->PastDifSolarRad,
     662            0 :                                 state.dataSurfaceGroundHeatExchangers->PastSolarDirCosVert,
     663            0 :                                 state.dataSurfaceGroundHeatExchangers->PastWindSpeed,
     664            0 :                                 state.dataSurfaceGroundHeatExchangers->PastIsRain,
     665            0 :                                 state.dataSurfaceGroundHeatExchangers->PastIsSnow);
     666              :                 // under relax
     667            0 :                 PastTempTop = PastTempTop * (1.0 - RelaxT) + RelaxT * TempT;
     668              : 
     669              :                 // update coefficients
     670            0 :                 CalcBottomFluxCoefficents(PastTempBtm, PastTempTop);
     671            0 :                 PastFluxBtm = this->QbtmConstCoef + this->QbtmVarCoef * state.dataSurfaceGroundHeatExchangers->SourceFlux;
     672              : 
     673            0 :                 if (std::abs((OldPastFluxTop - PastFluxTop) / OldPastFluxTop) <= SurfFluxTol &&
     674            0 :                     std::abs((OldPastFluxBtm - PastFluxBtm) / OldPastFluxBtm) <= SurfFluxTol)
     675            0 :                     break;
     676              : 
     677              :                 // calc new surface temps
     678            0 :                 CalcBottomSurfTemp(PastFluxBtm,
     679              :                                    TempB,
     680            0 :                                    state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp,
     681            0 :                                    state.dataSurfaceGroundHeatExchangers->PastWindSpeed,
     682            0 :                                    state.dataSurfaceGroundHeatExchangers->PastGroundTemp);
     683              :                 // underrelax
     684            0 :                 PastTempBtm = PastTempBtm * (1.0 - RelaxT) + RelaxT * TempB;
     685              :                 // update flux record
     686            0 :                 OldPastFluxTop = PastFluxTop;
     687            0 :                 OldPastFluxBtm = PastFluxBtm;
     688              : 
     689              :                 // Check for non-convergence
     690            0 :                 if (iter > Maxiter) {
     691            0 :                     if (this->ConvErrIndex1 == 0) {
     692            0 :                         ShowWarningMessage(
     693            0 :                             state, format("CalcSurfaceGroundHeatExchanger=\"{}\", Did not converge (part 1), Iterations={}", this->Name, Maxiter));
     694            0 :                         ShowContinueErrorTimeStamp(state, "");
     695              :                     }
     696            0 :                     ShowRecurringWarningErrorAtEnd(
     697            0 :                         state, "CalcSurfaceGroundHeatExchanger=\"" + this->Name + "\", Did not converge (part 1)", this->ConvErrIndex1);
     698            0 :                     break;
     699              :                 }
     700              :             }
     701              : 
     702            0 :             if (!state.dataSurfaceGroundHeatExchangers->InitializeTempTop) {
     703            0 :                 TempTop = TempT;
     704            0 :                 TempBtm = TempB;
     705            0 :                 FluxTop = PastFluxTop;
     706            0 :                 FluxBtm = PastFluxBtm;
     707            0 :                 state.dataSurfaceGroundHeatExchangers->InitializeTempTop = true;
     708              :             }
     709              : 
     710              :             // update module variables
     711            0 :             state.dataSurfaceGroundHeatExchangers->TopSurfTemp = TempTop;
     712            0 :             state.dataSurfaceGroundHeatExchangers->BtmSurfTemp = TempBtm;
     713            0 :             state.dataSurfaceGroundHeatExchangers->TopSurfFlux = -FluxTop;
     714            0 :             state.dataSurfaceGroundHeatExchangers->BtmSurfFlux = FluxBtm;
     715              : 
     716              :             // get source temp for output
     717            0 :             CalcSourceTempCoefficents(PastTempBtm, PastTempTop);
     718            0 :             this->SourceTemp = this->TsrcConstCoef + this->TsrcVarCoef * state.dataSurfaceGroundHeatExchangers->SourceFlux;
     719              :             // update histories
     720            0 :             UpdateHistories(PastFluxTop, PastFluxBtm, state.dataSurfaceGroundHeatExchangers->SourceFlux, this->SourceTemp);
     721              : 
     722              :             // At the beginning of a time step, reset to zero so average calculation can start again
     723            0 :             this->QSrcAvg = 0.0;
     724            0 :             this->LastSysTimeElapsed = 0.0;
     725            0 :             this->LastTimeStepSys = 0.0;
     726              : 
     727              :             // get current env. conditions
     728            0 :             state.dataSurfaceGroundHeatExchangers->PastBeamSolarRad = state.dataEnvrn->BeamSolarRad;
     729            0 :             state.dataSurfaceGroundHeatExchangers->PastSolarDirCosVert = state.dataEnvrn->SOLCOS(3);
     730            0 :             state.dataSurfaceGroundHeatExchangers->PastDifSolarRad = state.dataEnvrn->DifSolarRad;
     731            0 :             state.dataSurfaceGroundHeatExchangers->PastGroundTemp = state.dataEnvrn->GroundTemp[(int)DataEnvironment::GroundTempType::Shallow];
     732            0 :             state.dataSurfaceGroundHeatExchangers->PastIsRain = state.dataEnvrn->IsRain;
     733            0 :             state.dataSurfaceGroundHeatExchangers->PastIsSnow = state.dataEnvrn->IsSnow;
     734            0 :             state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp = OutDryBulbTempAt(state, SurfaceHXHeight);
     735            0 :             state.dataSurfaceGroundHeatExchangers->PastOutWetBulbTemp = OutWetBulbTempAt(state, SurfaceHXHeight);
     736            0 :             state.dataSurfaceGroundHeatExchangers->PastSkyTemp = state.dataEnvrn->SkyTemp;
     737            0 :             state.dataSurfaceGroundHeatExchangers->PastWindSpeed = DataEnvironment::WindSpeedAt(state, SurfaceHXHeight);
     738              : 
     739            0 :             TempBtm = this->TbtmHistory[1];
     740            0 :             TempTop = this->TtopHistory[1];
     741            0 :             OldFluxTop = 1.0e+30;
     742            0 :             OldFluxBtm = 1.0e+30;
     743            0 :             OldSourceFlux = 1.0e+30;
     744            0 :             state.dataSurfaceGroundHeatExchangers->SourceFlux = CalcSourceFlux(state);
     745            0 :             iter = 0;
     746              :             while (true) { // iterate to find source flux
     747            0 :                 ++iter;
     748            0 :                 iter1 = 0;
     749              :                 while (true) { // iterate to find surface heat balances
     750            0 :                     ++iter1;
     751              :                     // update top coefficients
     752            0 :                     CalcTopFluxCoefficents(TempBtm, TempTop);
     753              :                     // calc top surface flux
     754            0 :                     FluxTop = this->QtopConstCoef + this->QtopVarCoef * state.dataSurfaceGroundHeatExchangers->SourceFlux;
     755              :                     // calc new surface temps
     756            0 :                     CalcTopSurfTemp(-FluxTop,
     757              :                                     TempT,
     758            0 :                                     state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp,
     759            0 :                                     state.dataSurfaceGroundHeatExchangers->PastOutWetBulbTemp,
     760            0 :                                     state.dataSurfaceGroundHeatExchangers->PastSkyTemp,
     761            0 :                                     state.dataSurfaceGroundHeatExchangers->PastBeamSolarRad,
     762            0 :                                     state.dataSurfaceGroundHeatExchangers->PastDifSolarRad,
     763            0 :                                     state.dataSurfaceGroundHeatExchangers->PastSolarDirCosVert,
     764            0 :                                     state.dataSurfaceGroundHeatExchangers->PastWindSpeed,
     765            0 :                                     state.dataSurfaceGroundHeatExchangers->PastIsRain,
     766            0 :                                     state.dataSurfaceGroundHeatExchangers->PastIsSnow);
     767              :                     // under-relax
     768            0 :                     TempTop = TempTop * (1.0 - RelaxT) + RelaxT * TempT;
     769              :                     // update bottom coefficients
     770            0 :                     CalcBottomFluxCoefficents(TempBtm, TempTop);
     771            0 :                     FluxBtm = this->QbtmConstCoef + this->QbtmVarCoef * state.dataSurfaceGroundHeatExchangers->SourceFlux;
     772              :                     // convergence test on surface fluxes
     773            0 :                     if (std::abs((OldFluxTop - FluxTop) / OldFluxTop) <= SurfFluxTol && std::abs((OldFluxBtm - FluxBtm) / OldFluxBtm) <= SurfFluxTol)
     774            0 :                         break;
     775              : 
     776              :                     // calc new surface temps
     777            0 :                     CalcBottomSurfTemp(FluxBtm,
     778              :                                        TempB,
     779            0 :                                        state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp,
     780            0 :                                        state.dataSurfaceGroundHeatExchangers->PastOutDryBulbTemp,
     781            0 :                                        state.dataEnvrn->GroundTemp[(int)DataEnvironment::GroundTempType::Shallow]);
     782              :                     // under-relax
     783            0 :                     TempBtm = TempBtm * (1.0 - RelaxT) + RelaxT * TempB;
     784              :                     // update flux record
     785            0 :                     OldFluxBtm = FluxBtm;
     786            0 :                     OldFluxTop = FluxTop;
     787              : 
     788              :                     // Check for non-convergence
     789            0 :                     if (iter1 > Maxiter1) {
     790            0 :                         if (this->ConvErrIndex2 == 0) {
     791            0 :                             ShowWarningMessage(
     792              :                                 state,
     793            0 :                                 format("CalcSurfaceGroundHeatExchanger=\"{}\", Did not converge (part 2), Iterations={}", this->Name, Maxiter));
     794            0 :                             ShowContinueErrorTimeStamp(state, "");
     795              :                         }
     796            0 :                         ShowRecurringWarningErrorAtEnd(
     797            0 :                             state, "CalcSurfaceGroundHeatExchanger=\"" + this->Name + "\", Did not converge (part 2)", this->ConvErrIndex2);
     798            0 :                         break;
     799              :                     }
     800              :                 }
     801              :                 // update the source temp coefficients and update the source flux
     802            0 :                 CalcSourceTempCoefficents(TempBtm, TempTop);
     803            0 :                 state.dataSurfaceGroundHeatExchangers->SourceFlux = CalcSourceFlux(state);
     804              :                 // check source flux convergence
     805            0 :                 if (std::abs((OldSourceFlux - state.dataSurfaceGroundHeatExchangers->SourceFlux) / (1.0e-20 + OldSourceFlux)) <= SrcFluxTol) break;
     806            0 :                 OldSourceFlux = state.dataSurfaceGroundHeatExchangers->SourceFlux;
     807              : 
     808              :                 // Check for non-convergence
     809            0 :                 if (iter > Maxiter) {
     810            0 :                     if (this->ConvErrIndex3 == 0) {
     811            0 :                         ShowWarningMessage(
     812            0 :                             state, format("CalcSurfaceGroundHeatExchanger=\"{}\", Did not converge (part 3), Iterations={}", this->Name, Maxiter));
     813            0 :                         ShowContinueErrorTimeStamp(state, "");
     814              :                     }
     815            0 :                     ShowRecurringWarningErrorAtEnd(
     816            0 :                         state, "CalcSurfaceGroundHeatExchanger=\"" + this->Name + "\", Did not converge (part 3)", this->ConvErrIndex3);
     817            0 :                     break;
     818              :                 }
     819              :             } // end surface heat balance iteration
     820              : 
     821            0 :         } else if (!FirstHVACIteration) { // end source flux iteration
     822              :             // For the rest of the system time steps ...
     823              :             // update source flux from Twi
     824            0 :             this->firstTimeThrough = true;
     825            0 :             state.dataSurfaceGroundHeatExchangers->SourceFlux = this->CalcSourceFlux(state);
     826              :         }
     827            0 :     }
     828              : 
     829            0 :     void SurfaceGroundHeatExchangerData::CalcBottomFluxCoefficents(Real64 const Tbottom, // current bottom (lower) surface temperature
     830              :                                                                    Real64 const Ttop     // current top (upper) surface temperature
     831              :     )
     832              :     {
     833              : 
     834              :         //       AUTHOR         Simon Rees
     835              :         //       DATE WRITTEN   August 2002
     836              :         //       MODIFIED       na
     837              :         //       RE-ENGINEERED  na
     838              : 
     839              :         // PURPOSE OF THIS SUBROUTINE:
     840              :         // Calculates current version of constant variable parts of QTF equations.
     841              : 
     842              :         // METHODOLOGY EMPLOYED:
     843              :         // For given current surface temperatures the terms of the QTF equations can be
     844              :         // grouped into constant terms, and those depending on the current source flux.
     845              :         // This routine calculates the current coefficient values for the bottom flux
     846              :         // equation.
     847              : 
     848              :         // REFERENCES:
     849              :         // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     850              :         //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     851              :         //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     852              :         //   Engineering.
     853              : 
     854              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     855              :         int Term;
     856              : 
     857              :         // add current surface temperatures to history data
     858            0 :         this->TbtmHistory[0] = Tbottom;
     859            0 :         this->TtopHistory[0] = Ttop;
     860              : 
     861              :         // Bottom Surface Coefficients
     862            0 :         this->QbtmConstCoef = 0.0;
     863            0 :         for (Term = 0; Term <= this->NumCTFTerms - 1; ++Term) {
     864              : 
     865            0 :             this->QbtmConstCoef += (-this->CTFin[Term] * this->TbtmHistory[Term]) + (this->CTFcross[Term] * this->TtopHistory[Term]) +
     866            0 :                                    (this->CTFflux[Term] * this->QbtmHistory[Term]) + (this->CTFSourceIn[Term] * this->QsrcHistory[Term]);
     867              :         }
     868              : 
     869              :         // correct for extra bottom surface flux term
     870            0 :         this->QbtmConstCoef -= this->CTFSourceIn[0] * this->QsrcHistory[0];
     871              :         // source flux current coefficient
     872            0 :         this->QbtmVarCoef = this->CTFSourceIn[0];
     873            0 :     }
     874              : 
     875            0 :     void SurfaceGroundHeatExchangerData::CalcTopFluxCoefficents(Real64 const Tbottom, // current bottom (lower) surface temperature
     876              :                                                                 Real64 const Ttop     // current top (upper) surface temperature
     877              :     )
     878              :     {
     879              : 
     880              :         //       AUTHOR         Simon Rees
     881              :         //       DATE WRITTEN   August 2002
     882              :         //       MODIFIED       na
     883              :         //       RE-ENGINEERED  na
     884              : 
     885              :         // PURPOSE OF THIS SUBROUTINE:
     886              :         // Calculates current version of constant variable parts of QTF equations.
     887              : 
     888              :         // METHODOLOGY EMPLOYED:
     889              :         // For given current surface temperatures the terms of the QTF equations can be
     890              :         // grouped into constant terms, and those depending on the current source flux.
     891              :         // This routine calculates the current coefficient values for the top flux
     892              :         // equation.
     893              : 
     894              :         // REFERENCES:
     895              :         // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     896              :         //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     897              :         //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     898              :         //   Engineering.
     899              : 
     900              :         // add current surface temperatures to history data
     901            0 :         this->TbtmHistory[0] = Tbottom;
     902            0 :         this->TtopHistory[0] = Ttop;
     903              : 
     904              :         // Top Surface Coefficients
     905            0 :         this->QtopConstCoef = 0.0;
     906            0 :         for (int Term = 0; Term <= this->NumCTFTerms - 1; ++Term) {
     907              : 
     908            0 :             this->QtopConstCoef += (this->CTFout[Term] * this->TtopHistory[Term]) - (this->CTFcross[Term] * this->TbtmHistory[Term]) +
     909            0 :                                    (this->CTFflux[Term] * this->QtopHistory[Term]) + (this->CTFSourceOut[Term] * this->QsrcHistory[Term]);
     910              :         }
     911              : 
     912              :         // correct for extra top surface flux term
     913            0 :         this->QtopConstCoef -= (this->CTFSourceOut[0] * this->QsrcHistory[0]);
     914              :         // surface flux current coefficient
     915            0 :         this->QtopVarCoef = this->CTFSourceOut[0];
     916            0 :     }
     917              : 
     918            0 :     void SurfaceGroundHeatExchangerData::CalcSourceTempCoefficents(Real64 const Tbottom, // current bottom (lower) surface temperature
     919              :                                                                    Real64 const Ttop     // current top (upper) surface temperature
     920              :     )
     921              :     {
     922              : 
     923              :         //       AUTHOR         Simon Rees
     924              :         //       DATE WRITTEN   August 2002
     925              :         //       MODIFIED       na
     926              :         //       RE-ENGINEERED  na
     927              : 
     928              :         // PURPOSE OF THIS SUBROUTINE:
     929              :         // Calculates current version of constant variable parts of QTF equations.
     930              : 
     931              :         // METHODOLOGY EMPLOYED:
     932              :         // For given current surface temperatures the terms of the QTF equations can be
     933              :         // grouped into constant terms, and those depending on the current source flux.
     934              :         // This routine calculates the current coefficient values for the source temperature
     935              :         // equation.
     936              : 
     937              :         // REFERENCES:
     938              :         // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     939              :         //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     940              :         //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     941              :         //   Engineering.
     942              : 
     943              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     944              :         int Term;
     945              : 
     946              :         // add current surface temperatures to history data
     947            0 :         this->TbtmHistory[0] = Tbottom;
     948            0 :         this->TtopHistory[0] = Ttop;
     949              : 
     950            0 :         this->TsrcConstCoef = 0.0;
     951            0 :         for (Term = 0; Term <= this->NumCTFTerms - 1; ++Term) {
     952              : 
     953            0 :             this->TsrcConstCoef += (this->CTFTSourceIn[Term] * this->TbtmHistory[Term]) + (this->CTFTSourceOut[Term] * this->TtopHistory[Term]) +
     954            0 :                                    (this->CTFflux[Term] * this->TsrcHistory[Term]) + (this->CTFTSourceQ[Term] * this->QsrcHistory[Term]);
     955              :         }
     956              : 
     957              :         // correct for extra source flux term
     958            0 :         this->TsrcConstCoef -= this->CTFTSourceQ[0] * this->QsrcHistory[0];
     959              :         // source flux current coefficient
     960            0 :         this->TsrcVarCoef = this->CTFTSourceQ[0];
     961            0 :     }
     962              : 
     963            0 :     Real64 SurfaceGroundHeatExchangerData::CalcSourceFlux(EnergyPlusData &state) // component number
     964              :     {
     965              : 
     966              :         //       AUTHOR         Simon Rees
     967              :         //       DATE WRITTEN   August 2002
     968              :         //       MODIFIED       na
     969              :         //       RE-ENGINEERED  na
     970              : 
     971              :         // PURPOSE OF THIS SUBROUTINE:
     972              :         // This calculates the source flux given the inlet fluid temperature. A
     973              :         // heat exchanger analogy is used, with the surface as a 'Fixed' fluid.
     974              : 
     975              :         // METHODOLOGY EMPLOYED:
     976              : 
     977              :         // REFERENCES:
     978              :         // Strand, R.K. 1995. "Heat Source Transfer Functions and Their Application to
     979              :         //   Low Temperature Radiant Heating Systems", Ph.D. dissertation, University
     980              :         //   of Illinois at Urbana-Champaign, Department of Mechanical and Industrial
     981              :         //   Engineering.
     982              : 
     983              :         // Return value
     984              :         Real64 CalcSourceFlux;
     985              : 
     986              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     987              :         Real64 EpsMdotCp; // Epsilon (heat exchanger terminology) times water mass flow rate times water specific heat
     988              : 
     989              :         // Effectiveness * Modot * specific heat
     990            0 :         if (state.dataSurfaceGroundHeatExchangers->FlowRate > 0.0) {
     991            0 :             EpsMdotCp = CalcHXEffectTerm(state, this->InletTemp, state.dataSurfaceGroundHeatExchangers->FlowRate);
     992              :             // calc flux
     993            0 :             CalcSourceFlux = (this->InletTemp - this->TsrcConstCoef) / (this->SurfaceArea / EpsMdotCp + this->TsrcVarCoef);
     994              :         } else {
     995            0 :             CalcSourceFlux = 0.0;
     996              :         }
     997              : 
     998            0 :         return CalcSourceFlux;
     999              :     }
    1000              : 
    1001            0 :     void SurfaceGroundHeatExchangerData::UpdateHistories(Real64 const TopFlux,    // current top (top) surface flux
    1002              :                                                          Real64 const BottomFlux, // current bottom (bottom) surface flux
    1003              :                                                          Real64 const sourceFlux, // current source surface flux
    1004              :                                                          Real64 const sourceTemp  // current source temperature
    1005              :     )
    1006              :     {
    1007              : 
    1008              :         //       AUTHOR         Simon Rees
    1009              :         //       DATE WRITTEN   August 2002
    1010              :         //       MODIFIED       na
    1011              :         //       RE-ENGINEERED  na
    1012              : 
    1013              :         // PURPOSE OF THIS SUBROUTINE:
    1014              :         // This is used to update the temperature and flux records for the QTF
    1015              :         // calculations. This is called at the start of each zone timestep.
    1016              : 
    1017              :         // METHODOLOGY EMPLOYED:
    1018              :         // Just shift along and replace zero index element with current value.
    1019              : 
    1020              :         // update top surface temps
    1021            0 :         this->TtopHistory = eoshiftArray(this->TtopHistory, -1, 0.0);
    1022              : 
    1023              :         // update bottom surface temps
    1024            0 :         this->TbtmHistory = eoshiftArray(this->TbtmHistory, -1, 0.0);
    1025              : 
    1026              :         // update bottom surface temps
    1027            0 :         this->TsrcHistory = eoshiftArray(this->TsrcHistory, -1, 0.0);
    1028            0 :         this->TsrcHistory[1] = sourceTemp;
    1029              : 
    1030              :         // update bottom surface fluxes
    1031            0 :         this->QbtmHistory = eoshiftArray(this->QbtmHistory, -1, 0.0);
    1032            0 :         this->QbtmHistory[1] = BottomFlux;
    1033              : 
    1034              :         // update bottom surface fluxes
    1035            0 :         this->QtopHistory = eoshiftArray(this->QtopHistory, -1, 0.0);
    1036            0 :         this->QtopHistory[1] = TopFlux;
    1037              : 
    1038              :         // update bottom surface fluxes
    1039            0 :         this->QsrcHistory = eoshiftArray(this->QsrcHistory, -1, 0.0);
    1040            0 :         this->QsrcHistory[1] = sourceFlux;
    1041            0 :     }
    1042              : 
    1043            0 :     Real64 SurfaceGroundHeatExchangerData::CalcHXEffectTerm(EnergyPlusData &state,
    1044              :                                                             Real64 const Temperature,  // Temperature of water entering the surface, in C
    1045              :                                                             Real64 const WaterMassFlow // Mass flow rate, in kg/s
    1046              :     )
    1047              :     {
    1048              : 
    1049              :         // SUBROUTINE INFORMATION:
    1050              :         //       AUTHOR         Rick Strand
    1051              :         //       DATE WRITTEN   December 2000
    1052              :         //       MODIFIED       Simon Rees, August 2002
    1053              :         //       RE-ENGINEERED  na
    1054              : 
    1055              :         // PURPOSE OF THIS SUBROUTINE:
    1056              :         // This subroutine calculates the "heat exchanger"
    1057              :         // effectiveness term.  This is equal to the mass flow rate of water
    1058              :         // times the specific heat of water times the effectiveness of
    1059              :         // the surface heat exchanger. This routine is adapted from that in
    1060              :         // the low temp radiant surface model.
    1061              : 
    1062              :         // METHODOLOGY EMPLOYED:
    1063              :         // Assumes that the only REAL(r64) heat transfer term that we have to
    1064              :         // deal with is the convection from the water to the tube.  The
    1065              :         // other assumptions are that the tube bottom surface temperature
    1066              :         // is equal to the "source location temperature" and that it is
    1067              :         // a CONSTANT throughout the surface.
    1068              : 
    1069              :         // REFERENCES:
    1070              :         // See RadiantSystemLowTemp module.
    1071              :         // Property data for water shown below as parameters taken from
    1072              :         //   Incropera and DeWitt, Introduction to Heat Transfer, Table A.6.
    1073              :         // Heat exchanger information also from Incropera and DeWitt.
    1074              :         // Code based loosely on code from IBLAST program (research version)
    1075              : 
    1076              :         // Return value
    1077              :         Real64 CalcHXEffectTerm;
    1078              : 
    1079            0 :         Real64 constexpr MaxLaminarRe(2300.0); // Maximum Reynolds number for laminar flow
    1080            0 :         int constexpr NumOfPropDivisions(13);  // intervals in property correlation
    1081              :         static constexpr std::array<Real64, NumOfPropDivisions> Temps = {
    1082              :             1.85, 6.85, 11.85, 16.85, 21.85, 26.85, 31.85, 36.85, 41.85, 46.85, 51.85, 56.85, 61.85}; // Temperature, in C
    1083              :         static constexpr std::array<Real64, NumOfPropDivisions> Mu = {0.001652,
    1084              :                                                                       0.001422,
    1085              :                                                                       0.001225,
    1086              :                                                                       0.00108,
    1087              :                                                                       0.000959,
    1088              :                                                                       0.000855,
    1089              :                                                                       0.000769,
    1090              :                                                                       0.000695,
    1091              :                                                                       0.000631,
    1092              :                                                                       0.000577,
    1093              :                                                                       0.000528,
    1094              :                                                                       0.000489,
    1095              :                                                                       0.000453}; // Viscosity, in Ns/m2
    1096              :         static constexpr std::array<Real64, NumOfPropDivisions> Conductivity = {
    1097              :             0.574, 0.582, 0.590, 0.598, 0.606, 0.613, 0.620, 0.628, 0.634, 0.640, 0.645, 0.650, 0.656}; // Conductivity, in W/mK
    1098              :         static constexpr std::array<Real64, NumOfPropDivisions> Pr = {
    1099              :             12.22, 10.26, 8.81, 7.56, 6.62, 5.83, 5.20, 4.62, 4.16, 3.77, 3.42, 3.15, 2.88}; // Prandtl number (dimensionless)
    1100            0 :         int constexpr WaterIndex(1);
    1101              :         static constexpr std::string_view RoutineName("SurfaceGroundHeatExchanger:CalcHXEffectTerm");
    1102              : 
    1103              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
    1104              :         int Index;
    1105              :         Real64 InterpFrac;
    1106              :         Real64 NuD;
    1107              :         Real64 ReD;
    1108              :         Real64 NTU;
    1109              :         Real64 CpWater;
    1110              :         Real64 Kactual;
    1111              :         Real64 MUactual;
    1112              :         Real64 PRactual;
    1113              :         Real64 PipeLength;
    1114              : 
    1115              :         // First find out where we are in the range of temperatures
    1116            0 :         Index = 0;
    1117            0 :         while (Index < NumOfPropDivisions) {
    1118            0 :             if (Temperature < Temps[Index]) break; // DO loop
    1119            0 :             ++Index;
    1120              :         }
    1121              : 
    1122              :         // Initialize thermal properties of water
    1123            0 :         if (Index == 0) {
    1124            0 :             MUactual = Mu[Index];
    1125            0 :             Kactual = Conductivity[Index];
    1126            0 :             PRactual = Pr[Index];
    1127            0 :         } else if (Index > NumOfPropDivisions - 1) {
    1128            0 :             Index = NumOfPropDivisions - 1;
    1129            0 :             MUactual = Mu[Index];
    1130            0 :             Kactual = Conductivity[Index];
    1131            0 :             PRactual = Pr[Index];
    1132              :         } else {
    1133            0 :             InterpFrac = (Temperature - Temps[Index - 1]) / (Temps[Index] - Temps[Index - 1]);
    1134            0 :             MUactual = Mu[Index - 1] + InterpFrac * (Mu[Index] - Mu[Index - 1]);
    1135            0 :             Kactual = Conductivity[Index - 1] + InterpFrac * (Conductivity[Index] - Conductivity[Index - 1]);
    1136            0 :             PRactual = Pr[Index - 1] + InterpFrac * (Pr[Index] - Pr[Index - 1]);
    1137              :         }
    1138              :         // arguments are glycol name, temperature, and concentration
    1139            0 :         if (Temperature < 0.0) { // check if fluid is water and would be freezing
    1140            0 :             if (state.dataPlnt->PlantLoop(this->plantLoc.loopNum).FluidIndex == WaterIndex) {
    1141            0 :                 if (this->FrozenErrIndex1 == 0) {
    1142            0 :                     ShowWarningMessage(
    1143              :                         state,
    1144            0 :                         format("GroundHeatExchanger:Surface=\"{}\", water is frozen; Model not valid. Calculated Water Temperature=[{:.2R}] C",
    1145            0 :                                this->Name,
    1146            0 :                                this->InletTemp));
    1147            0 :                     ShowContinueErrorTimeStamp(state, "");
    1148              :                 }
    1149            0 :                 ShowRecurringWarningErrorAtEnd(state,
    1150            0 :                                                "GroundHeatExchanger:Surface=\"" + this->Name + "\", water is frozen",
    1151            0 :                                                this->FrozenErrIndex1,
    1152            0 :                                                this->InletTemp,
    1153            0 :                                                this->InletTemp,
    1154              :                                                _,
    1155              :                                                "[C]",
    1156              :                                                "[C]");
    1157            0 :                 this->InletTemp = max(this->InletTemp, 0.0);
    1158              :             }
    1159              :         }
    1160            0 :         CpWater = state.dataPlnt->PlantLoop(this->plantLoc.loopNum).glycol->getSpecificHeat(state, Temperature, RoutineName);
    1161              : 
    1162              :         // Calculate the Reynold's number from RE=(4*Mdot)/(Pi*Mu*Diameter)
    1163            0 :         ReD = 4.0 * WaterMassFlow / (Constant::Pi * MUactual * this->TubeDiameter * this->TubeCircuits);
    1164              : 
    1165              :         // Calculate the Nusselt number based on what flow regime one is in
    1166            0 :         if (ReD >= MaxLaminarRe) { // Turbulent flow --> use Colburn equation
    1167            0 :             NuD = 0.023 * std::pow(ReD, 0.8) * std::pow(PRactual, 1.0 / 3.0);
    1168              :         } else { // Laminar flow --> use constant surface temperature relation
    1169            0 :             NuD = 3.66;
    1170              :         }
    1171              :         // Calculate the NTU parameter
    1172              :         // NTU = UA/[(Mdot*Cp)min]
    1173              :         // where: U = h (convection coefficient) and h = (k)(Nu)/D
    1174              :         //        A = Pi*D*TubeLength
    1175              :         //  NTU = PI * Kactual * NuD * SurfaceGHE(SurfaceGHENum)%TubeLength / (WaterMassFlow * CpWater)
    1176              : 
    1177            0 :         PipeLength = this->SurfaceLength * this->SurfaceWidth / this->TubeSpacing;
    1178              : 
    1179            0 :         NTU = Constant::Pi * Kactual * NuD * PipeLength / (WaterMassFlow * CpWater);
    1180              :         // Calculate Epsilon*MassFlowRate*Cp
    1181            0 :         if (-NTU >= DataPrecisionGlobals::EXP_LowerLimit) {
    1182            0 :             CalcHXEffectTerm = (1.0 - std::exp(-NTU)) * WaterMassFlow * CpWater;
    1183              :         } else {
    1184            0 :             CalcHXEffectTerm = 1.0 * WaterMassFlow * CpWater;
    1185              :         }
    1186              : 
    1187            0 :         return CalcHXEffectTerm;
    1188              :     }
    1189              : 
    1190            0 :     void SurfaceGroundHeatExchangerData::CalcTopSurfTemp(Real64 const FluxTop,             // top surface flux
    1191              :                                                          Real64 &TempTop,                  // top surface temperature
    1192              :                                                          Real64 const ThisDryBulb,         // dry bulb temperature
    1193              :                                                          Real64 const ThisWetBulb,         // wet bulb temperature
    1194              :                                                          Real64 const ThisSkyTemp,         // sky temperature
    1195              :                                                          Real64 const ThisBeamSolarRad,    // beam solar radiation
    1196              :                                                          Real64 const ThisDifSolarRad,     // diffuse solar radiation
    1197              :                                                          Real64 const ThisSolarDirCosVert, // vertical component of solar normal
    1198              :                                                          Real64 const ThisWindSpeed,       // wind speed
    1199              :                                                          bool const ThisIsRain,            // rain flag
    1200              :                                                          bool const ThisIsSnow             // snow flag
    1201              :     )
    1202              :     {
    1203              : 
    1204              :         //       AUTHOR         Simon Rees
    1205              :         //       DATE WRITTEN   August 2002
    1206              :         //       MODIFIED       na
    1207              :         //       RE-ENGINEERED  na
    1208              : 
    1209              :         // PURPOSE OF THIS SUBROUTINE:
    1210              :         // This subroutine is used to calculate the top surface
    1211              :         // temperature for the given surface flux.
    1212              : 
    1213              :         // METHODOLOGY EMPLOYED:
    1214              :         // calc surface heat balance
    1215              : 
    1216              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
    1217              :         Real64 ConvCoef;     // convection coefficient
    1218              :         Real64 RadCoef;      // radiation coefficient
    1219              :         Real64 ExternalTemp; // external environmental temp - drybulb or wetbulb
    1220              :         Real64 OldSurfTemp;  // previous surface temperature
    1221              :         Real64 QSolAbsorbed; // absorbed solar flux
    1222              :         Real64 SurfTempAbs;  // absolute value of surface temp
    1223              :         Real64 SkyTempAbs;   // absolute value of sky temp
    1224              : 
    1225              :         // make a surface heat balance and solve for temperature
    1226              : 
    1227              :         // set appropriate external temp
    1228            0 :         if (ThisIsSnow || ThisIsRain) {
    1229            0 :             ExternalTemp = ThisWetBulb;
    1230              :         } else { // normal dry conditions
    1231            0 :             ExternalTemp = ThisDryBulb;
    1232              :         }
    1233              : 
    1234              :         // set previous surface temp
    1235            0 :         OldSurfTemp = this->TtopHistory[1];
    1236              :         // absolute temperatures
    1237            0 :         SurfTempAbs = OldSurfTemp + Constant::Kelvin;
    1238            0 :         SkyTempAbs = ThisSkyTemp + Constant::Kelvin;
    1239              : 
    1240              :         // ASHRAE simple convection coefficient model for external surfaces.
    1241            0 :         ConvCoef = Convect::CalcASHRAESimpExtConvCoeff(this->TopRoughness, ThisWindSpeed);
    1242              :         // radiation coefficient using surf temp from past time step
    1243            0 :         if (std::abs(SurfTempAbs - SkyTempAbs) > SmallNum) {
    1244            0 :             RadCoef = StefBoltzmann * this->TopThermAbs * (pow_4(SurfTempAbs) - pow_4(SkyTempAbs)) / (SurfTempAbs - SkyTempAbs);
    1245              :         } else {
    1246            0 :             RadCoef = 0.0;
    1247              :         }
    1248              : 
    1249              :         // total absorbed solar - no ground solar
    1250            0 :         QSolAbsorbed = this->TopSolarAbs * (max(ThisSolarDirCosVert, 0.0) * ThisBeamSolarRad + ThisDifSolarRad);
    1251              : 
    1252              :         // solve for temperature
    1253            0 :         TempTop = (FluxTop + ConvCoef * ExternalTemp + RadCoef * ThisSkyTemp + QSolAbsorbed) / (ConvCoef + RadCoef);
    1254            0 :     }
    1255              : 
    1256            0 :     void SurfaceGroundHeatExchangerData::CalcBottomSurfTemp(Real64 const FluxBtm,       // bottom surface flux
    1257              :                                                             Real64 &TempBtm,            // bottom surface temperature
    1258              :                                                             Real64 const ThisDryBulb,   // dry bulb temperature
    1259              :                                                             Real64 const ThisWindSpeed, // wind speed
    1260              :                                                             Real64 const ThisGroundTemp // ground temperature
    1261              :     )
    1262              :     {
    1263              : 
    1264              :         //       AUTHOR         Simon Rees
    1265              :         //       DATE WRITTEN   August 2002
    1266              :         //       MODIFIED       na
    1267              :         //       RE-ENGINEERED  na
    1268              : 
    1269              :         // PURPOSE OF THIS SUBROUTINE:
    1270              :         // This subroutine is used to calculate the bottom surface
    1271              :         // temperature for the given surface flux.
    1272              : 
    1273              :         // METHODOLOGY EMPLOYED:
    1274              :         // calc surface heat balances
    1275              : 
    1276              :         // Using/Aliasing
    1277              : 
    1278              :         Real64 ConvCoef;    // convection coefficient
    1279              :         Real64 RadCoef;     // radiation coefficient
    1280              :         Real64 OldSurfTemp; // previous surface temperature
    1281              :         Real64 SurfTempAbs; // absolute value of surface temp
    1282              :         Real64 ExtTempAbs;  // absolute value of sky temp
    1283              : 
    1284            0 :         if (this->LowerSurfCond == SurfCond_Exposed) {
    1285              : 
    1286              :             // make a surface heat balance and solve for temperature
    1287            0 :             OldSurfTemp = this->TbtmHistory[1];
    1288              :             // absolute temperatures
    1289            0 :             SurfTempAbs = OldSurfTemp + Constant::Kelvin;
    1290            0 :             ExtTempAbs = ThisDryBulb + Constant::Kelvin;
    1291              : 
    1292              :             // ASHRAE simple convection coefficient model for external surfaces.
    1293            0 :             ConvCoef = Convect::CalcASHRAESimpExtConvCoeff(this->TopRoughness, ThisWindSpeed);
    1294              : 
    1295              :             // radiation coefficient using surf temp from past time step
    1296            0 :             if (std::abs(SurfTempAbs - ExtTempAbs) > SmallNum) {
    1297            0 :                 RadCoef = StefBoltzmann * this->TopThermAbs * (pow_4(SurfTempAbs) - pow_4(ExtTempAbs)) / (SurfTempAbs - ExtTempAbs);
    1298              :             } else {
    1299            0 :                 RadCoef = 0.0;
    1300              :             }
    1301              : 
    1302              :             // total absorbed solar - no ground solar
    1303            0 :             TempBtm = (FluxBtm + ConvCoef * ThisDryBulb + RadCoef * ThisDryBulb) / (ConvCoef + RadCoef);
    1304              : 
    1305              :         } else { // ground coupled
    1306              :             // just use the supplied ground temperature
    1307            0 :             TempBtm = ThisGroundTemp;
    1308              :         }
    1309            0 :     }
    1310              : 
    1311            0 :     void SurfaceGroundHeatExchangerData::UpdateSurfaceGroundHeatExchngr(EnergyPlusData &state) // Index for the surface
    1312              :     {
    1313              : 
    1314              :         // SUBROUTINE INFORMATION:
    1315              :         //       AUTHOR         Simon Rees
    1316              :         //       DATE WRITTEN   August 2002
    1317              :         //       MODIFIED       na
    1318              :         //       RE-ENGINEERED  na
    1319              : 
    1320              :         // PURPOSE OF THIS SUBROUTINE:
    1321              :         // This subroutine does any updating that needs to be done for surface
    1322              :         // ground heat exchangers.  One of the most important functions of
    1323              :         // this routine is to update the average heat source/sink for a
    1324              :         // particular system over the various system time steps that make up
    1325              :         // the zone time step. This routine must also set the outlet water conditions.
    1326              : 
    1327              :         // METHODOLOGY EMPLOYED:
    1328              :         // For the source/sink average update, if the system time step elapsed
    1329              :         // is still what it used to be, then either we are still iterating or
    1330              :         // we had to go back and shorten the time step.  As a result, we have
    1331              :         // to subtract out the previous value that we added.  If the system
    1332              :         // time step elapsed is different, then we just need to add the new
    1333              :         // values to the running average.
    1334              : 
    1335              :         // Using/Aliasing
    1336            0 :         Real64 SysTimeElapsed = state.dataHVACGlobal->SysTimeElapsed;
    1337            0 :         Real64 TimeStepSys = state.dataHVACGlobal->TimeStepSys;
    1338              :         using PlantUtilities::SafeCopyPlantNode;
    1339              : 
    1340              :         // SUBROUTINE PARAMETER DEFINITIONS:
    1341              :         static constexpr std::string_view RoutineName("SurfaceGroundHeatExchanger:Update");
    1342              : 
    1343              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
    1344              :         Real64 CpFluid; // Specific heat of working fluid
    1345              : 
    1346              :         // update flux
    1347            0 :         this->QSrc = state.dataSurfaceGroundHeatExchangers->SourceFlux;
    1348              : 
    1349            0 :         if (this->LastSysTimeElapsed == SysTimeElapsed) { // only update in normal mode
    1350              :             // Still iterating or reducing system time step, so subtract old values which were not valid
    1351            0 :             this->QSrcAvg -= this->LastQSrc * this->LastTimeStepSys / state.dataGlobal->TimeStepZone;
    1352              : 
    1353              :             // Update the running average and the "last" values with the current values of the appropriate variables
    1354            0 :             this->QSrcAvg += this->QSrc * TimeStepSys / state.dataGlobal->TimeStepZone;
    1355              : 
    1356            0 :             this->LastQSrc = state.dataSurfaceGroundHeatExchangers->SourceFlux;
    1357            0 :             this->LastSysTimeElapsed = SysTimeElapsed;
    1358            0 :             this->LastTimeStepSys = TimeStepSys;
    1359              :         }
    1360              : 
    1361              :         // Calculate the water side outlet conditions and set the
    1362              :         // appropriate conditions on the correct HVAC node.
    1363            0 :         if (state.dataPlnt->PlantLoop(this->plantLoc.loopNum).FluidName == "WATER") {
    1364            0 :             if (InletTemp < 0.0) {
    1365            0 :                 ShowRecurringWarningErrorAtEnd(state,
    1366            0 :                                                "UpdateSurfaceGroundHeatExchngr: Water is frozen in Surf HX=" + this->Name,
    1367            0 :                                                this->FrozenErrIndex2,
    1368            0 :                                                this->InletTemp,
    1369            0 :                                                this->InletTemp);
    1370              :             }
    1371            0 :             this->InletTemp = max(this->InletTemp, 0.0);
    1372              :         }
    1373              : 
    1374            0 :         CpFluid = state.dataPlnt->PlantLoop(this->plantLoc.loopNum).glycol->getSpecificHeat(state, this->InletTemp, RoutineName);
    1375              : 
    1376            0 :         SafeCopyPlantNode(state, this->InletNodeNum, this->OutletNodeNum);
    1377              :         // check for flow
    1378            0 :         if ((CpFluid > 0.0) && (state.dataSurfaceGroundHeatExchangers->FlowRate > 0.0)) {
    1379            0 :             state.dataLoopNodes->Node(this->OutletNodeNum).Temp = this->InletTemp - this->SurfaceArea *
    1380            0 :                                                                                         state.dataSurfaceGroundHeatExchangers->SourceFlux /
    1381            0 :                                                                                         (state.dataSurfaceGroundHeatExchangers->FlowRate * CpFluid);
    1382            0 :             state.dataLoopNodes->Node(this->OutletNodeNum).Enthalpy = state.dataLoopNodes->Node(this->OutletNodeNum).Temp * CpFluid;
    1383              :         }
    1384            0 :     }
    1385              : 
    1386            0 :     void SurfaceGroundHeatExchangerData::ReportSurfaceGroundHeatExchngr(EnergyPlusData &state) // Index for the surface under consideration
    1387              :     {
    1388              : 
    1389              :         // SUBROUTINE INFORMATION:
    1390              :         //       AUTHOR         Simon Rees
    1391              :         //       DATE WRITTEN   August 2002
    1392              :         //       MODIFIED       na
    1393              :         //       RE-ENGINEERED  na
    1394              : 
    1395              :         // PURPOSE OF THIS SUBROUTINE:
    1396              :         // This subroutine simply produces output for Surface ground heat exchangers
    1397              : 
    1398              :         // Using/Aliasing
    1399            0 :         Real64 TimeStepSysSec = state.dataHVACGlobal->TimeStepSysSec;
    1400              : 
    1401              :         // update flows and temps from node data
    1402            0 :         this->InletTemp = state.dataLoopNodes->Node(this->InletNodeNum).Temp;
    1403            0 :         this->OutletTemp = state.dataLoopNodes->Node(this->OutletNodeNum).Temp;
    1404            0 :         this->MassFlowRate = state.dataLoopNodes->Node(this->InletNodeNum).MassFlowRate;
    1405              : 
    1406              :         // update other variables from module variables
    1407            0 :         this->HeatTransferRate = state.dataSurfaceGroundHeatExchangers->SourceFlux * this->SurfaceArea;
    1408            0 :         this->SurfHeatTransferRate =
    1409            0 :             this->SurfaceArea * (state.dataSurfaceGroundHeatExchangers->TopSurfFlux + state.dataSurfaceGroundHeatExchangers->BtmSurfFlux);
    1410            0 :         this->Energy = state.dataSurfaceGroundHeatExchangers->SourceFlux * this->SurfaceArea * TimeStepSysSec;
    1411            0 :         this->TopSurfaceTemp = state.dataSurfaceGroundHeatExchangers->TopSurfTemp;
    1412            0 :         this->BtmSurfaceTemp = state.dataSurfaceGroundHeatExchangers->BtmSurfTemp;
    1413            0 :         this->TopSurfaceFlux = state.dataSurfaceGroundHeatExchangers->TopSurfFlux;
    1414            0 :         this->BtmSurfaceFlux = state.dataSurfaceGroundHeatExchangers->BtmSurfFlux;
    1415            0 :         this->SurfEnergy =
    1416            0 :             SurfaceArea * (state.dataSurfaceGroundHeatExchangers->TopSurfFlux + state.dataSurfaceGroundHeatExchangers->BtmSurfFlux) * TimeStepSysSec;
    1417            0 :     }
    1418            0 :     void SurfaceGroundHeatExchangerData::oneTimeInit_new(EnergyPlusData &state)
    1419              :     {
    1420              : 
    1421              :         using PlantUtilities::InitComponentNodes;
    1422              :         using PlantUtilities::RegisterPlantCompDesignFlow;
    1423              :         using PlantUtilities::ScanPlantLoopsForObject;
    1424              : 
    1425              :         // SUBROUTINE PARAMETER DEFINITIONS:
    1426            0 :         Real64 constexpr DesignVelocity(0.5); // Hypothetical design max pipe velocity [m/s]
    1427              :         Real64 rho;                           // local fluid density
    1428              :         bool errFlag;
    1429            0 :         static std::string const RoutineName("InitSurfaceGroundHeatExchanger");
    1430              : 
    1431              :         // Locate the hx on the plant loops for later usage
    1432            0 :         errFlag = false;
    1433            0 :         ScanPlantLoopsForObject(state, this->Name, DataPlant::PlantEquipmentType::GrndHtExchgSurface, this->plantLoc, errFlag, _, _, _, _, _);
    1434              : 
    1435            0 :         if (errFlag) {
    1436            0 :             ShowFatalError(state, "InitSurfaceGroundHeatExchanger: Program terminated due to previous condition(s).");
    1437              :         }
    1438            0 :         rho = state.dataPlnt->PlantLoop(this->plantLoc.loopNum).glycol->getDensity(state, 0.0, RoutineName);
    1439            0 :         this->DesignMassFlowRate = Constant::Pi / 4.0 * pow_2(this->TubeDiameter) * DesignVelocity * rho * this->TubeCircuits;
    1440            0 :         InitComponentNodes(state, 0.0, this->DesignMassFlowRate, this->InletNodeNum, this->OutletNodeNum);
    1441            0 :         RegisterPlantCompDesignFlow(state, this->InletNodeNum, this->DesignMassFlowRate / rho);
    1442            0 :     }
    1443            0 :     void SurfaceGroundHeatExchangerData::oneTimeInit([[maybe_unused]] EnergyPlusData &state)
    1444              :     {
    1445            0 :     }
    1446              : 
    1447              : } // namespace SurfaceGroundHeatExchanger
    1448              : 
    1449              : } // namespace EnergyPlus
        

Generated by: LCOV version 2.0-1