LCOV - code coverage report
Current view: top level - EnergyPlus/GroundTemperatureModeling - SiteBuildingSurfaceGroundTemperatures.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 70.2 % 47 33
Test Date: 2025-06-02 07:23:51 Functions: 75.0 % 4 3

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

Generated by: LCOV version 2.0-1