LCOV - code coverage report
Current view: top level - EnergyPlus/GroundTemperatureModeling - KusudaAchenbachGroundTemperatureModel.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 94.6 % 74 70
Test Date: 2025-05-22 16:09:37 Functions: 100.0 % 5 5

            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              : // EnergyPlus Headers
      49              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      50              : #include <EnergyPlus/DataIPShortCuts.hh>
      51              : #include <EnergyPlus/GroundTemperatureModeling/KusudaAchenbachGroundTemperatureModel.hh>
      52              : #include <EnergyPlus/GroundTemperatureModeling/SiteShallowGroundTemperatures.hh>
      53              : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      54              : #include <EnergyPlus/UtilityRoutines.hh>
      55              : #include <EnergyPlus/WeatherManager.hh>
      56              : 
      57              : namespace EnergyPlus {
      58              : 
      59              : //******************************************************************************
      60              : namespace GroundTemp {
      61              : 
      62              :     // Kusuda model factory
      63           50 :     KusudaGroundTempsModel *KusudaGroundTempsModel::KusudaGTMFactory(EnergyPlusData &state, const std::string &objectName)
      64              :     {
      65              :         // SUBROUTINE INFORMATION:
      66              :         //       AUTHOR         Matt Mitchell
      67              :         //       DATE WRITTEN   Summer 2015
      68              : 
      69              :         // PURPOSE OF THIS SUBROUTINE:
      70              :         // Reads input and creates instance of Kusuda ground temps model
      71              : 
      72              :         // Locals
      73              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
      74           50 :         bool found = false;
      75              :         int NumNums;
      76              :         int NumAlphas;
      77              :         int IOStat;
      78              : 
      79              :         // New shared pointer for this model object
      80           50 :         auto *thisModel = new KusudaGroundTempsModel();
      81              : 
      82              :         // There was some **spooky** behavior here.  One of the calling sites for this factory was passing in a reference
      83              :         //  to a dataIPShortCuts item as the objectName argument.  Inside here, we make a second call to getObjectItem
      84              :         //  which then overwrites the value.  So objectName gets overwritten.  I made a copy of the string here to ensure
      85              :         //  it persists.
      86           50 :         const std::string lookingForName = objectName; // NOLINT(*-unnecessary-copy-initialization)
      87              : 
      88           50 :         ModelType modelType = ModelType::Kusuda;
      89              : 
      90           50 :         std::string_view const cCurrentModuleObject = GroundTemp::modelTypeNamesUC[(int)modelType];
      91           50 :         const int numCurrModels = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
      92              : 
      93           51 :         for (int modelNum = 1; modelNum <= numCurrModels; ++modelNum) {
      94              : 
      95          102 :             state.dataInputProcessing->inputProcessor->getObjectItem(state,
      96              :                                                                      cCurrentModuleObject,
      97              :                                                                      modelNum,
      98           51 :                                                                      state.dataIPShortCut->cAlphaArgs,
      99              :                                                                      NumAlphas,
     100           51 :                                                                      state.dataIPShortCut->rNumericArgs,
     101              :                                                                      NumNums,
     102              :                                                                      IOStat);
     103              : 
     104           51 :             if (lookingForName == state.dataIPShortCut->cAlphaArgs(1)) {
     105              : 
     106              :                 // Read input into object here
     107           50 :                 thisModel->Name = state.dataIPShortCut->cAlphaArgs(1);
     108           50 :                 thisModel->modelType = modelType;
     109           50 :                 thisModel->groundThermalDiffusivity =
     110           50 :                     state.dataIPShortCut->rNumericArgs(1) / (state.dataIPShortCut->rNumericArgs(2) * state.dataIPShortCut->rNumericArgs(3));
     111              : 
     112              :                 std::array<Real64, 3> flags = {
     113           50 :                     state.dataIPShortCut->rNumericArgs(4), state.dataIPShortCut->rNumericArgs(5), state.dataIPShortCut->rNumericArgs(6)};
     114              :                 const bool useGroundTempDataForKusuda =
     115          102 :                     std::any_of(flags.begin(), flags.end(), [](Real64 const flag) { return static_cast<bool>(flag); });
     116              : 
     117           50 :                 if (useGroundTempDataForKusuda) {
     118              :                     // Use Kusuda Parameters
     119           49 :                     thisModel->aveGroundTemp = state.dataIPShortCut->rNumericArgs(4);
     120           49 :                     thisModel->aveGroundTempAmplitude = state.dataIPShortCut->rNumericArgs(5);
     121           49 :                     thisModel->phaseShiftInSecs = state.dataIPShortCut->rNumericArgs(6) * Constant::rSecsInDay;
     122              :                 } else {
     123              :                     // Use data from Site:GroundTemperature:Shallow to generate parameters
     124              : 
     125            1 :                     constexpr int monthsInYear(12);
     126            1 :                     constexpr int avgDaysInMonth(30);
     127            1 :                     int monthOfMinSurfTemp(0);
     128            1 :                     Real64 averageGroundTemp(0);
     129            1 :                     Real64 amplitudeOfGroundTemp(0);
     130            1 :                     Real64 phaseShiftOfMinGroundTempDays(0);
     131            1 :                     Real64 minSurfTemp(100);  // Set high; month 1 temp will be lower than that and actually get updated
     132            1 :                     Real64 maxSurfTemp(-100); // Set low initially but will get updated
     133              : 
     134              :                     // get a non-owning pointer to the shallow ground temperature object, whether user-input or defaults
     135            1 :                     BaseGroundTempsModel *shallowObj = SiteShallowGroundTemps::ShallowGTMFactory(state, "");
     136              : 
     137           13 :                     for (int monthIndex = 1; monthIndex <= 12; ++monthIndex) {
     138           12 :                         const Real64 currMonthTemp = shallowObj->getGroundTempAtTimeInMonths(state, 0.0, monthIndex);
     139              : 
     140              :                         // Calculate Average Ground Temperature for all 12 months of the year:
     141           12 :                         averageGroundTemp += currMonthTemp;
     142              : 
     143              :                         // Need max temp, min temp, and month of min surf temp to set amplitude and month of min surf temp
     144           12 :                         if (currMonthTemp <= minSurfTemp) {
     145            2 :                             monthOfMinSurfTemp = monthIndex;
     146            2 :                             minSurfTemp = currMonthTemp;
     147              :                         }
     148              : 
     149           12 :                         if (currMonthTemp >= maxSurfTemp) {
     150            7 :                             maxSurfTemp = currMonthTemp;
     151              :                         }
     152              :                     }
     153              : 
     154            1 :                     averageGroundTemp /= monthsInYear;
     155              : 
     156            1 :                     amplitudeOfGroundTemp = (maxSurfTemp - minSurfTemp) / 2.0;
     157              : 
     158            1 :                     phaseShiftOfMinGroundTempDays = monthOfMinSurfTemp * avgDaysInMonth;
     159              : 
     160              :                     // Assign to KA Model
     161            1 :                     thisModel->aveGroundTemp = averageGroundTemp;
     162            1 :                     thisModel->aveGroundTempAmplitude = amplitudeOfGroundTemp;
     163            1 :                     thisModel->phaseShiftInSecs = phaseShiftOfMinGroundTempDays * Constant::rSecsInDay;
     164              :                 }
     165              : 
     166           50 :                 found = true;
     167           50 :                 break;
     168              :             }
     169              :         }
     170              : 
     171           50 :         if (found) {
     172           50 :             state.dataGrndTempModelMgr->groundTempModels.push_back(thisModel);
     173           50 :             return thisModel;
     174              :         }
     175              : 
     176            0 :         ShowFatalError(state, fmt::format("{}--Errors getting input for ground temperature model", GroundTemp::modelTypeNames[(int)modelType]));
     177            0 :         return nullptr;
     178           50 :     }
     179              : 
     180              :     //******************************************************************************
     181              : 
     182        76292 :     Real64 KusudaGroundTempsModel::getGroundTemp(EnergyPlusData &state)
     183              :     {
     184              :         // AUTHOR         Matt Mitchell
     185              :         // DATE WRITTEN   June 2015
     186              : 
     187              :         // PURPOSE OF THIS FUNCTION:
     188              :         // Returns a ground temperature
     189              : 
     190              :         // METHODOLOGY EMPLOYED:
     191              :         // Kusuda and Achenbach correlation is used
     192              : 
     193        76292 :         Real64 const secsInYear = Constant::rSecsInDay * state.dataWeather->NumDaysInYear;
     194              : 
     195        76292 :         const Real64 term1 = -depth * std::sqrt(Constant::Pi / (secsInYear * groundThermalDiffusivity));
     196        76292 :         const Real64 term2 = (2 * Constant::Pi / secsInYear) *
     197        76292 :                              (simTimeInSeconds - phaseShiftInSecs - (depth / 2) * std::sqrt(secsInYear / (Constant::Pi * groundThermalDiffusivity)));
     198              : 
     199        76292 :         return aveGroundTemp - aveGroundTempAmplitude * std::exp(term1) * std::cos(term2);
     200              :     }
     201              : 
     202              :     //******************************************************************************
     203              : 
     204        76290 :     Real64 KusudaGroundTempsModel::getGroundTempAtTimeInSeconds(EnergyPlusData &state, Real64 const _depth, Real64 const _seconds)
     205              :     {
     206              :         // SUBROUTINE INFORMATION:
     207              :         //       AUTHOR         Matt Mitchell
     208              :         //       DATE WRITTEN   Summer 2015
     209              : 
     210              :         // PURPOSE OF THIS SUBROUTINE:
     211              :         // Returns the ground temperature when input time is in seconds
     212              : 
     213              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     214        76290 :         Real64 const secondsInYear = state.dataWeather->NumDaysInYear * Constant::rSecsInDay;
     215              : 
     216        76290 :         depth = _depth;
     217              : 
     218        76290 :         simTimeInSeconds = _seconds;
     219              : 
     220        76290 :         if (simTimeInSeconds > secondsInYear) {
     221            0 :             simTimeInSeconds = remainder(simTimeInSeconds, secondsInYear);
     222              :         }
     223              : 
     224              :         // Get and return ground temperature
     225        76290 :         return getGroundTemp(state);
     226              :     }
     227              : 
     228              :     //******************************************************************************
     229              : 
     230            2 :     Real64 KusudaGroundTempsModel::getGroundTempAtTimeInMonths(EnergyPlusData &state, Real64 const _depth, int const _month)
     231              :     {
     232              :         // SUBROUTINE INFORMATION:
     233              :         //       AUTHOR         Matt Mitchell
     234              :         //       DATE WRITTEN   Summer 2015
     235              : 
     236              :         // PURPOSE OF THIS SUBROUTINE:
     237              :         // Returns the ground temperature when input time is in months
     238              : 
     239              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     240            2 :         Real64 const aveSecondsInMonth = (state.dataWeather->NumDaysInYear / 12) * Constant::rSecsInDay;
     241            2 :         Real64 const secondsPerYear = state.dataWeather->NumDaysInYear * Constant::rSecsInDay;
     242              : 
     243            2 :         depth = _depth;
     244              : 
     245            2 :         simTimeInSeconds = aveSecondsInMonth * (_month - 1 + 0.5);
     246              : 
     247            2 :         if (simTimeInSeconds > secondsPerYear) {
     248            0 :             simTimeInSeconds = remainder(simTimeInSeconds, secondsPerYear);
     249              :         }
     250              : 
     251              :         // Get and return ground temperature
     252            2 :         return getGroundTemp(state);
     253              :     }
     254              : 
     255              :     //******************************************************************************
     256              : 
     257              : } // namespace GroundTemp
     258              : } // namespace EnergyPlus
        

Generated by: LCOV version 2.0-1