LCOV - code coverage report
Current view: top level - EnergyPlus/GroundTemperatureModeling - SiteBuildingSurfaceGroundTemperatures.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 35 54 64.8 %
Date: 2024-08-24 18:31:18 Functions: 3 4 75.0 %

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

Generated by: LCOV version 1.14