LCOV - code coverage report
Current view: top level - EnergyPlus/GroundTemperatureModeling - XingGroundTemperatureModel.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 48 61 78.7 %
Date: 2023-01-17 19:17:23 Functions: 5 6 83.3 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, 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/DataGlobals.hh>
      54             : #include <EnergyPlus/DataIPShortCuts.hh>
      55             : #include <EnergyPlus/GroundTemperatureModeling/GroundTemperatureModelManager.hh>
      56             : #include <EnergyPlus/GroundTemperatureModeling/XingGroundTemperatureModel.hh>
      57             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      58             : #include <EnergyPlus/UtilityRoutines.hh>
      59             : #include <EnergyPlus/WeatherManager.hh>
      60             : 
      61             : namespace EnergyPlus {
      62             : 
      63             : //******************************************************************************
      64             : 
      65             : // Xing model factory
      66           1 : std::shared_ptr<XingGroundTempsModel> XingGroundTempsModel::XingGTMFactory(EnergyPlusData &state, std::string objectName)
      67             : {
      68             :     // SUBROUTINE INFORMATION:
      69             :     //       AUTHOR         Matt Mitchell
      70             :     //       DATE WRITTEN   Summer 2015
      71             :     //       MODIFIED       na
      72             :     //       RE-ENGINEERED  na
      73             : 
      74             :     // PURPOSE OF THIS SUBROUTINE:
      75             :     // Reads input and creates instance of Xing ground temps model
      76             : 
      77             :     // USE STATEMENTS:
      78             :     using namespace GroundTemperatureManager;
      79             : 
      80             :     // Locals
      81             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
      82           1 :     bool found = false;
      83             :     int NumNums;
      84             :     int NumAlphas;
      85             :     int IOStat;
      86           1 :     bool ErrorsFound = false;
      87             : 
      88             :     // New shared pointer for this model object
      89           2 :     std::shared_ptr<XingGroundTempsModel> thisModel(new XingGroundTempsModel());
      90             : 
      91           1 :     GroundTempObjType objType = GroundTempObjType::XingGroundTemp;
      92             : 
      93           1 :     std::string_view const cCurrentModuleObject = GroundTemperatureManager::groundTempModelNamesUC[static_cast<int>(objType)];
      94           1 :     int numCurrModels = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
      95             : 
      96           1 :     for (int modelNum = 1; modelNum <= numCurrModels; ++modelNum) {
      97             : 
      98           3 :         state.dataInputProcessing->inputProcessor->getObjectItem(
      99           2 :             state, cCurrentModuleObject, modelNum, state.dataIPShortCut->cAlphaArgs, NumAlphas, state.dataIPShortCut->rNumericArgs, NumNums, IOStat);
     100             : 
     101           1 :         if (objectName == state.dataIPShortCut->cAlphaArgs(1)) {
     102             :             // Read input into object here
     103             : 
     104           1 :             thisModel->objectName = state.dataIPShortCut->cAlphaArgs(1);
     105           1 :             thisModel->objectType = objType;
     106           1 :             thisModel->groundThermalDiffisivity =
     107           1 :                 state.dataIPShortCut->rNumericArgs(1) / (state.dataIPShortCut->rNumericArgs(2) * state.dataIPShortCut->rNumericArgs(3));
     108           1 :             thisModel->aveGroundTemp = state.dataIPShortCut->rNumericArgs(4);
     109           1 :             thisModel->surfTempAmplitude_1 = state.dataIPShortCut->rNumericArgs(5);
     110           1 :             thisModel->surfTempAmplitude_2 = state.dataIPShortCut->rNumericArgs(6);
     111           1 :             thisModel->phaseShift_1 = state.dataIPShortCut->rNumericArgs(7);
     112           1 :             thisModel->phaseShift_2 = state.dataIPShortCut->rNumericArgs(8);
     113             : 
     114           1 :             found = true;
     115           1 :             break;
     116             :         }
     117             :     }
     118             : 
     119           1 :     if (found && !ErrorsFound) {
     120           1 :         state.dataGrndTempModelMgr->groundTempModels.push_back(thisModel);
     121           1 :         return thisModel;
     122             :     } else {
     123           0 :         ShowFatalError(state,
     124           0 :                        fmt::format("{}--Errors getting input for ground temperature model",
     125           0 :                                    GroundTemperatureManager::groundTempModelNames[static_cast<int>(objType)]));
     126           0 :         return nullptr;
     127             :     }
     128             : }
     129             : 
     130             : //******************************************************************************
     131             : 
     132      826248 : Real64 XingGroundTempsModel::getGroundTemp(EnergyPlusData &state)
     133             : {
     134             :     // SUBROUTINE INFORMATION:
     135             :     //       AUTHOR         Matt Mitchell
     136             :     //       DATE WRITTEN   Summer 2015
     137             :     //       MODIFIED       na
     138             :     //       RE-ENGINEERED  na
     139             : 
     140             :     // PURPOSE OF THIS SUBROUTINE:
     141             :     // Returns the ground temperature for the Site:GroundTemperature:Undisturbed:Xing
     142             : 
     143             :     // USE STATEMENTS:
     144             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     145             :     int n;
     146      826248 :     Real64 tp = state.dataWeatherManager->NumDaysInYear; // Period of soil temperature cycle
     147             :     Real64 Ts_1;                                         // Amplitude of surface temperature
     148             :     Real64 Ts_2;                                         // Amplitude of surface temperature
     149             :     Real64 PL_1;                                         // Phase shift of surface temperature
     150             :     Real64 PL_2;                                         // Phase shift of surface temperature
     151             : 
     152             :     Real64 term1;
     153             :     Real64 term2;
     154             :     Real64 term3;
     155             :     Real64 term4;
     156             : 
     157             :     Real64 retVal;
     158             :     Real64 summation;
     159             : 
     160             :     // Inits
     161      826248 :     Ts_1 = surfTempAmplitude_1;
     162      826248 :     PL_1 = phaseShift_1;
     163      826248 :     Ts_2 = surfTempAmplitude_2;
     164      826248 :     PL_2 = phaseShift_2;
     165             : 
     166      826248 :     n = 1;
     167      826248 :     term1 = -depth * std::sqrt((n * DataGlobalConstants::Pi) / (groundThermalDiffisivity * tp));
     168     1652496 :     term2 = (2 * DataGlobalConstants::Pi * n) / tp * (simTimeInDays - PL_1) -
     169      826248 :             depth * std::sqrt((n * DataGlobalConstants::Pi) / (groundThermalDiffisivity * tp));
     170             : 
     171      826248 :     n = 2;
     172      826248 :     term3 = -depth * std::sqrt((n * DataGlobalConstants::Pi) / (groundThermalDiffisivity * tp));
     173     1652496 :     term4 = (2 * DataGlobalConstants::Pi * n) / tp * (simTimeInDays - PL_2) -
     174      826248 :             depth * std::sqrt((n * DataGlobalConstants::Pi) / (groundThermalDiffisivity * tp));
     175             : 
     176      826248 :     summation = std::exp(term1) * Ts_1 * std::cos(term2) + std::exp(term3) * Ts_2 * std::cos(term4);
     177             : 
     178      826248 :     retVal = aveGroundTemp - summation;
     179             : 
     180      826248 :     return retVal;
     181             : }
     182             : 
     183             : //******************************************************************************
     184             : 
     185           0 : Real64 XingGroundTempsModel::getGroundTempAtTimeInMonths(EnergyPlusData &state, Real64 _depth, int _month)
     186             : {
     187             :     // SUBROUTINE INFORMATION:
     188             :     //       AUTHOR         Matt Mitchell
     189             :     //       DATE WRITTEN   Summer 2015
     190             :     //       MODIFIED       na
     191             :     //       RE-ENGINEERED  na
     192             : 
     193             :     // PURPOSE OF THIS SUBROUTINE:
     194             :     // Returns ground temperature when input time is in months
     195             : 
     196             :     // USE STATEMENTS:
     197             : 
     198             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     199           0 :     Real64 const aveDaysInMonth = state.dataWeatherManager->NumDaysInYear / 12;
     200             : 
     201           0 :     depth = _depth;
     202             : 
     203             :     // Set month
     204           0 :     if (_month >= 1 && _month <= 12) {
     205           0 :         simTimeInDays = aveDaysInMonth * ((_month - 1) + 0.5);
     206             :     } else {
     207           0 :         int monthIndex = remainder(_month, 12);
     208           0 :         simTimeInDays = aveDaysInMonth * ((monthIndex - 1) + 0.5);
     209             :     }
     210             : 
     211             :     // Get and return ground temp
     212           0 :     return getGroundTemp(state);
     213             : }
     214             : 
     215             : //******************************************************************************
     216             : 
     217      826248 : Real64 XingGroundTempsModel::getGroundTempAtTimeInSeconds(EnergyPlusData &state, Real64 _depth, Real64 seconds)
     218             : {
     219             :     // SUBROUTINE INFORMATION:
     220             :     //       AUTHOR         Matt Mitchell
     221             :     //       DATE WRITTEN   Summer 2015
     222             :     //       MODIFIED       na
     223             :     //       RE-ENGINEERED  na
     224             : 
     225             :     // PURPOSE OF THIS SUBROUTINE:
     226             :     // Returns ground temperature when time is in seconds
     227             : 
     228             :     // USE STATEMENTS:
     229             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     230             : 
     231      826248 :     depth = _depth;
     232             : 
     233      826248 :     simTimeInDays = seconds / DataGlobalConstants::SecsInDay;
     234             : 
     235      826248 :     if (simTimeInDays > state.dataWeatherManager->NumDaysInYear) {
     236           0 :         simTimeInDays = remainder(simTimeInDays, state.dataWeatherManager->NumDaysInYear);
     237             :     }
     238             : 
     239      826248 :     return getGroundTemp(state);
     240             : }
     241             : 
     242             : //******************************************************************************
     243             : 
     244        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13