LCOV - code coverage report
Current view: top level - EnergyPlus/GroundTemperatureModeling - SiteDeepGroundTemperatures.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 85.4 % 41 35
Test Date: 2025-05-22 16:09:37 Functions: 100.0 % 4 4

            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 <memory>
      50              : 
      51              : // EnergyPlus Headers
      52              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      53              : #include <EnergyPlus/DataEnvironment.hh>
      54              : #include <EnergyPlus/DataGlobals.hh>
      55              : #include <EnergyPlus/DataIPShortCuts.hh>
      56              : #include <EnergyPlus/GroundTemperatureModeling/SiteDeepGroundTemperatures.hh>
      57              : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      58              : #include <EnergyPlus/UtilityRoutines.hh>
      59              : #include <EnergyPlus/WeatherManager.hh>
      60              : 
      61              : namespace EnergyPlus {
      62              : 
      63              : //******************************************************************************
      64              : namespace GroundTemp {
      65              :     // Site:GroundTemperature:Deep factory
      66          112 :     SiteDeepGroundTemps *SiteDeepGroundTemps::DeepGTMFactory(EnergyPlusData &state, const std::string &objectName)
      67              :     {
      68              :         // SUBROUTINE INFORMATION:
      69              :         //       AUTHOR         Matt Mitchell
      70              :         //       DATE WRITTEN   Summer 2015
      71              : 
      72              :         // PURPOSE OF THIS SUBROUTINE:
      73              :         // Reads input and creates instance of Site:GroundTemperature:Deep object
      74              : 
      75              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
      76          112 :         bool errorsFound = false;
      77              : 
      78              :         // New shared pointer for this model object
      79          112 :         auto *thisModel = new SiteDeepGroundTemps();
      80              : 
      81          112 :         ModelType modelType = ModelType::SiteDeep;
      82              : 
      83          112 :         std::string_view const cCurrentModuleObject = GroundTemp::modelTypeNamesUC[(int)modelType];
      84          112 :         const int numCurrObjects = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
      85              : 
      86          112 :         thisModel->modelType = modelType;
      87          112 :         thisModel->Name = objectName;
      88              : 
      89          112 :         if (numCurrObjects == 1) {
      90              : 
      91              :             int NumNums;
      92              :             int NumAlphas;
      93              :             int IOStat;
      94              : 
      95              :             // Get the object names for each construction from the input processor
      96            8 :             state.dataInputProcessing->inputProcessor->getObjectItem(
      97            4 :                 state, cCurrentModuleObject, 1, state.dataIPShortCut->cAlphaArgs, NumAlphas, state.dataIPShortCut->rNumericArgs, NumNums, IOStat);
      98              : 
      99            4 :             if (NumNums < 12) {
     100            0 :                 ShowSevereError(state, fmt::format("{}: Less than 12 values entered.", GroundTemp::modelTypeNames[(int)modelType]));
     101            0 :                 errorsFound = true;
     102              :             }
     103              : 
     104              :             // overwrite values read from weather file for the 0.5m set ground temperatures
     105           52 :             for (int i = 1; i <= 12; ++i) {
     106           48 :                 thisModel->deepGroundTemps[i - 1] = state.dataIPShortCut->rNumericArgs(i);
     107              :             }
     108              : 
     109            4 :             state.dataEnvrn->GroundTempInputs[static_cast<int>(DataEnvironment::GroundTempType::Deep)] = true;
     110              : 
     111          108 :         } else if (numCurrObjects > 1) {
     112            0 :             ShowSevereError(state, fmt::format("{}: Too many objects entered. Only one allowed.", GroundTemp::modelTypeNames[(int)modelType]));
     113            0 :             errorsFound = true;
     114              : 
     115              :         } else {
     116          108 :             std::fill(thisModel->deepGroundTemps.begin(), thisModel->deepGroundTemps.end(), 16.0);
     117              :         }
     118              : 
     119              :         // Write Final Ground Temp Information to the initialization output file
     120          336 :         write_ground_temps(state.files.eio, "Deep", thisModel->deepGroundTemps);
     121              : 
     122          112 :         if (!errorsFound) {
     123          112 :             state.dataGrndTempModelMgr->groundTempModels.push_back(thisModel);
     124          112 :             return thisModel;
     125              :         }
     126              : 
     127            0 :         ShowFatalError(state, fmt::format("{}--Errors getting input for ground temperature model", GroundTemp::modelTypeNames[(int)modelType]));
     128            0 :         return nullptr;
     129              :     }
     130              : 
     131              :     //******************************************************************************
     132              : 
     133       326126 :     Real64 SiteDeepGroundTemps::getGroundTemp([[maybe_unused]] EnergyPlusData &state)
     134              :     {
     135              :         // SUBROUTINE INFORMATION:
     136              :         //       AUTHOR         Matt Mitchell
     137              :         //       DATE WRITTEN   Summer 2015
     138              : 
     139              :         // PURPOSE OF THIS SUBROUTINE:
     140              :         // Returns the ground temperature for Site:GroundTemperature:Deep
     141              : 
     142       326126 :         return deepGroundTemps[timeOfSimInMonths - 1];
     143              :     }
     144              : 
     145              :     //******************************************************************************
     146              : 
     147            3 :     Real64 SiteDeepGroundTemps::getGroundTempAtTimeInSeconds(EnergyPlusData &state, [[maybe_unused]] Real64 const _depth, Real64 const _seconds)
     148              :     {
     149              :         // SUBROUTINE INFORMATION:
     150              :         //       AUTHOR         Matt Mitchell
     151              :         //       DATE WRITTEN   Summer 2015
     152              : 
     153              :         // PURPOSE OF THIS SUBROUTINE:
     154              :         // Returns the ground temperature when input time is in seconds
     155              : 
     156              :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     157              : 
     158            3 :         const Real64 secPerMonth = state.dataWeather->NumDaysInYear * Constant::rSecsInDay / 12;
     159              : 
     160              :         // Convert secs to months
     161            3 :         const int month = ceil(_seconds / secPerMonth);
     162              : 
     163            3 :         if (month >= 1 && month <= 12) {
     164            2 :             timeOfSimInMonths = month;
     165              :         } else {
     166            1 :             timeOfSimInMonths = month % 12;
     167              :         }
     168              : 
     169              :         // Get and return ground temp
     170            3 :         return getGroundTemp(state);
     171              :     }
     172              : 
     173              :     //******************************************************************************
     174              : 
     175       326123 :     Real64 SiteDeepGroundTemps::getGroundTempAtTimeInMonths(EnergyPlusData &state, [[maybe_unused]] Real64 const _depth, int const _month)
     176              :     {
     177              :         // SUBROUTINE INFORMATION:
     178              :         //       AUTHOR         Matt Mitchell
     179              :         //       DATE WRITTEN   Summer 2015
     180              : 
     181              :         // PURPOSE OF THIS SUBROUTINE:
     182              :         // Returns the ground temperature when input time is in months
     183              : 
     184              :         // Set month
     185       326123 :         if (_month >= 1 && _month <= 12) {
     186       326122 :             timeOfSimInMonths = _month;
     187              :         } else {
     188            1 :             timeOfSimInMonths = _month % 12;
     189              :         }
     190              : 
     191              :         // Get and return ground temp
     192       326123 :         return getGroundTemp(state);
     193              :     }
     194              : 
     195              :     //******************************************************************************
     196              : } // namespace GroundTemp
     197              : } // namespace EnergyPlus
        

Generated by: LCOV version 2.0-1