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/DataGlobalConstants.hh>
54 : #include <EnergyPlus/DataIPShortCuts.hh>
55 : #include <EnergyPlus/GroundTemperatureModeling/XingGroundTemperatureModel.hh>
56 : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
57 : #include <EnergyPlus/UtilityRoutines.hh>
58 : #include <EnergyPlus/WeatherManager.hh>
59 :
60 : namespace EnergyPlus {
61 :
62 : //******************************************************************************
63 : namespace GroundTemp {
64 : // Xing model factory
65 1 : XingGroundTempsModel *XingGroundTempsModel::XingGTMFactory(EnergyPlusData &state, const std::string &objectName)
66 : {
67 : // SUBROUTINE INFORMATION:
68 : // AUTHOR Matt Mitchell
69 : // DATE WRITTEN Summer 2015
70 :
71 : // PURPOSE OF THIS SUBROUTINE:
72 : // Reads input and creates instance of Xing ground temps model
73 :
74 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
75 1 : bool found = false;
76 : int NumNums;
77 : int NumAlphas;
78 : int IOStat;
79 :
80 : // New shared pointer for this model object
81 1 : auto *thisModel = new XingGroundTempsModel();
82 :
83 1 : ModelType modelType = ModelType::Xing;
84 :
85 1 : std::string_view const cCurrentModuleObject = GroundTemp::modelTypeNamesUC[(int)modelType];
86 1 : const int numCurrModels = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
87 :
88 1 : for (int modelNum = 1; modelNum <= numCurrModels; ++modelNum) {
89 :
90 2 : state.dataInputProcessing->inputProcessor->getObjectItem(state,
91 : cCurrentModuleObject,
92 : modelNum,
93 1 : state.dataIPShortCut->cAlphaArgs,
94 : NumAlphas,
95 1 : state.dataIPShortCut->rNumericArgs,
96 : NumNums,
97 : IOStat);
98 :
99 1 : if (objectName == state.dataIPShortCut->cAlphaArgs(1)) {
100 : // Read input into object here
101 :
102 1 : thisModel->Name = state.dataIPShortCut->cAlphaArgs(1);
103 1 : thisModel->modelType = modelType;
104 1 : thisModel->groundThermalDiffusivity = state.dataIPShortCut->rNumericArgs(1) /
105 1 : (state.dataIPShortCut->rNumericArgs(2) * state.dataIPShortCut->rNumericArgs(3)) *
106 : Constant::rSecsInDay;
107 1 : thisModel->aveGroundTemp = state.dataIPShortCut->rNumericArgs(4);
108 1 : thisModel->surfTempAmplitude_1 = state.dataIPShortCut->rNumericArgs(5);
109 1 : thisModel->surfTempAmplitude_2 = state.dataIPShortCut->rNumericArgs(6);
110 1 : thisModel->phaseShift_1 = state.dataIPShortCut->rNumericArgs(7);
111 1 : thisModel->phaseShift_2 = state.dataIPShortCut->rNumericArgs(8);
112 :
113 1 : found = true;
114 1 : break;
115 : }
116 : }
117 :
118 1 : if (found) {
119 1 : state.dataGrndTempModelMgr->groundTempModels.push_back(thisModel);
120 1 : return thisModel;
121 : }
122 :
123 0 : ShowFatalError(state, fmt::format("{}--Errors getting input for ground temperature model", GroundTemp::modelTypeNames[(int)modelType]));
124 0 : return nullptr;
125 : }
126 :
127 : //******************************************************************************
128 :
129 9 : Real64 XingGroundTempsModel::getGroundTemp(EnergyPlusData &state)
130 : {
131 : // SUBROUTINE INFORMATION:
132 : // AUTHOR Matt Mitchell
133 : // DATE WRITTEN Summer 2015
134 :
135 : // PURPOSE OF THIS SUBROUTINE:
136 : // Returns the ground temperature for the Site:GroundTemperature:Undisturbed:Xing
137 :
138 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
139 9 : const Real64 tp = state.dataWeather->NumDaysInYear; // Period of soil temperature cycle
140 :
141 : // Inits
142 9 : const Real64 Ts_1 = surfTempAmplitude_1; // Amplitude of surface temperature
143 9 : const Real64 PL_1 = phaseShift_1; // Phase shift of surface temperature
144 9 : const Real64 Ts_2 = surfTempAmplitude_2; // Amplitude of surface temperature
145 9 : const Real64 PL_2 = phaseShift_2; // Phase shift of surface temperature
146 :
147 9 : constexpr int n1 = 1;
148 9 : const Real64 gamma1 = std::sqrt((n1 * Constant::Pi) / (groundThermalDiffusivity * tp));
149 9 : const Real64 exp1 = -depth * gamma1;
150 9 : const Real64 cos1 = 2 * Constant::Pi * n1 / tp * (simTimeInDays - PL_1) - depth * gamma1;
151 :
152 9 : constexpr int n2 = 2;
153 9 : const Real64 gamma2 = std::sqrt((n2 * Constant::Pi) / (groundThermalDiffusivity * tp));
154 9 : const Real64 exp2 = -depth * gamma2;
155 9 : const Real64 cos2 = 2 * Constant::Pi * n2 / tp * (simTimeInDays - PL_2) - depth * gamma2;
156 :
157 9 : const Real64 summation = std::exp(exp1) * Ts_1 * std::cos(cos1) + std::exp(exp2) * Ts_2 * std::cos(cos2);
158 :
159 9 : return aveGroundTemp - summation;
160 : }
161 :
162 : //******************************************************************************
163 :
164 5 : Real64 XingGroundTempsModel::getGroundTempAtTimeInMonths(EnergyPlusData &state, const Real64 _depth, const int _month)
165 : {
166 : // SUBROUTINE INFORMATION:
167 : // AUTHOR Matt Mitchell
168 : // DATE WRITTEN Summer 2015
169 :
170 : // PURPOSE OF THIS SUBROUTINE:
171 : // Returns ground temperature when input time is in months
172 :
173 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
174 : // TODO: Fixing this to be floating point 12.0 causes diffs and failed tests
175 5 : Real64 const aveDaysInMonth = state.dataWeather->NumDaysInYear / 12;
176 :
177 5 : depth = _depth;
178 :
179 : // Set month
180 5 : if (_month >= 1 && _month <= 12) {
181 4 : simTimeInDays = aveDaysInMonth * (_month - 1 + 0.5);
182 : } else {
183 1 : const int monthIndex = _month % 12;
184 1 : simTimeInDays = aveDaysInMonth * (monthIndex - 1 + 0.5);
185 : }
186 :
187 : // Get and return ground temp
188 5 : return getGroundTemp(state);
189 : }
190 :
191 : //******************************************************************************
192 :
193 4 : Real64 XingGroundTempsModel::getGroundTempAtTimeInSeconds(EnergyPlusData &state, const Real64 _depth, const Real64 seconds)
194 : {
195 : // SUBROUTINE INFORMATION:
196 : // AUTHOR Matt Mitchell
197 : // DATE WRITTEN Summer 2015
198 :
199 : // PURPOSE OF THIS SUBROUTINE:
200 : // Returns ground temperature when time is in seconds
201 :
202 4 : depth = _depth;
203 :
204 4 : simTimeInDays = seconds / Constant::rSecsInDay;
205 :
206 4 : if (simTimeInDays > state.dataWeather->NumDaysInYear) {
207 1 : simTimeInDays = remainder(simTimeInDays, state.dataWeather->NumDaysInYear);
208 : }
209 :
210 4 : return getGroundTemp(state);
211 : }
212 :
213 : //******************************************************************************
214 : } // namespace GroundTemp
215 : } // namespace EnergyPlus
|