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 <utility>
50 :
51 : // ObjexxFCL Headers
52 : #include <ObjexxFCL/environment.hh>
53 : #include <ObjexxFCL/string.functions.hh>
54 :
55 : // EnergyPlus Headers
56 : #include <EnergyPlus/Data/EnergyPlusData.hh>
57 : #include <EnergyPlus/DataEnvironment.hh>
58 : #include <EnergyPlus/DataGlobals.hh>
59 : #include <EnergyPlus/DataStringGlobals.hh>
60 : #include <EnergyPlus/DataSystemVariables.hh>
61 : #include <EnergyPlus/FileSystem.hh>
62 : #include <EnergyPlus/UtilityRoutines.hh>
63 :
64 : namespace EnergyPlus {
65 :
66 : namespace DataSystemVariables {
67 :
68 : // MODULE INFORMATION:
69 : // AUTHOR Linda K. Lawrie
70 : // DATE WRITTEN May 2006
71 : // MODIFIED na
72 : // RE-ENGINEERED na
73 :
74 : // PURPOSE OF THIS MODULE:
75 : // This data-only module is a repository for system (such as environment) variables that are set
76 : // before a run or set of runs.
77 :
78 : constexpr const char *DDOnlyEnvVar("DDONLY"); // Only run design days
79 : constexpr const char *ReverseDDEnvVar("REVERSEDD"); // Reverse DD during run
80 : constexpr const char *DisableGLHECachingEnvVar("DISABLEGLHECACHING");
81 : constexpr const char *FullAnnualSimulation("FULLANNUALRUN"); // Generate annual run
82 : constexpr const char *cDeveloperFlag("DeveloperFlag");
83 : constexpr const char *cDisplayAllWarnings("DisplayAllWarnings");
84 : constexpr const char *cDisplayExtraWarnings("DisplayExtraWarnings");
85 : constexpr const char *cDisplayAdvancedReportVariables("DisplayAdvancedReportVariables");
86 : constexpr const char *cDisplayUnusedObjects("DisplayUnusedObjects");
87 : constexpr const char *cDisplayUnusedSchedules("DisplayUnusedSchedules");
88 : constexpr const char *cDisplayZoneAirHeatBalanceOffBalance("DisplayZoneAirHeatBalanceOffBalance");
89 : constexpr const char *cSortIDD("SortIDD");
90 : constexpr const char *cReportDuringWarmup("ReportDuringWarmup");
91 : constexpr const char *cReportDuringHVACSizingSimulation("REPORTDURINGHVACSIZINGSIMULATION");
92 : constexpr const char *cIgnoreSolarRadiation("IgnoreSolarRadiation");
93 : constexpr const char *cIgnoreBeamRadiation("IgnoreBeamRadiation");
94 : constexpr const char *cIgnoreDiffuseRadiation("IgnoreDiffuseRadiation");
95 : constexpr const char *cSutherlandHodgman("SutherlandHodgman");
96 : constexpr const char *cSlaterBarsky("SlaterBarsky");
97 : constexpr const char *cMinimalSurfaceVariables("CreateMinimalSurfaceVariables");
98 : constexpr const char *cMinimalShadowing("MinimalShadowing");
99 : constexpr const char *cInputPath1("epin"); // EP-Launch setting. Full path + project name
100 : constexpr const char *cInputPath2("input_path"); // RunEplus.bat setting. Full path
101 : constexpr const char *cProgramPath("program_path");
102 : constexpr const char *cTimingFlag("TimingFlag");
103 : constexpr const char *TrackAirLoopEnvVar("TRACK_AIRLOOP"); // To generate a file with runtime statistics
104 : // for each controller on each air loop
105 : constexpr const char *TraceAirLoopEnvVar("TRACE_AIRLOOP"); // To generate a trace file with the converged
106 : // solutions of all controllers on each air loop at each call to SimAirLoop()
107 : constexpr const char *TraceHVACControllerEnvVar("TRACE_HVACCONTROLLER"); // To generate a trace file for
108 : // each individual HVAC controller with all controller iterations
109 :
110 : constexpr const char *MinReportFrequencyEnvVar("MINREPORTFREQUENCY"); // environment var for reporting frequency.
111 : constexpr const char *
112 : cDisplayInputInAuditEnvVar("DISPLAYINPUTINAUDIT"); // environmental variable that enables the echoing of the input file into the audit file
113 :
114 : constexpr const char *ciForceTimeStepEnvVar("CI_FORCE_TIME_STEP"); // environment var forcing 30 minute time steps on CI for efficiency
115 :
116 10 : fs::path CheckForActualFilePath(EnergyPlusData &state,
117 : fs::path const &originalInputFilePath, // path (or filename only) as input for object
118 : const std::string &contextString //
119 : )
120 : {
121 :
122 : // SUBROUTINE INFORMATION:
123 : // AUTHOR Linda Lawrie
124 : // DATE WRITTEN October 2011
125 : // MODIFIED na
126 : // RE-ENGINEERED na
127 :
128 : // PURPOSE OF THIS SUBROUTINE:
129 : // With the Windows version, there are subfolders set and the input file names may not
130 : // be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see
131 : // if the file can be found. (It may have been input with full path so that is checked first.)
132 :
133 : // Locals
134 : // SUBROUTINE ARGUMENT DEFINITIONS:
135 :
136 : // SUBROUTINE PARAMETER DEFINITIONS:
137 :
138 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
139 10 : fs::path foundFilePath;
140 :
141 10 : if (state.dataSysVars->firstTime) {
142 14 : state.files.audit.ensure_open(state, "CheckForActualFilePath", state.files.outputControl.audit);
143 7 : std::string tmp;
144 :
145 : // epin is passed from Epl-run.bat as the path to the IDF file minus its extension, so take the parent directory
146 21 : get_environment_variable(cInputPath1, tmp);
147 7 : state.dataSysVars->envinputpath1 = FileSystem::getParentDirectoryPath(fs::path(tmp));
148 :
149 21 : get_environment_variable(cInputPath2, tmp);
150 7 : state.dataSysVars->envinputpath2 = fs::path(tmp);
151 :
152 21 : get_environment_variable(cProgramPath, tmp);
153 7 : state.dataStrGlobals->ProgramPath = fs::path(tmp);
154 7 : state.dataSysVars->firstTime = false;
155 7 : }
156 :
157 10 : fs::path InputFilePath = FileSystem::makeNativePath(originalInputFilePath); // save for changing out path characters
158 :
159 10 : std::vector<std::pair<fs::path, std::string>> pathsChecked;
160 :
161 : const std::array<std::pair<fs::path, std::string>, 7> pathsToCheck = {
162 : {{InputFilePath, "Current Working Directory"},
163 10 : {state.dataStrGlobals->inputDirPath / InputFilePath, "IDF Directory"},
164 20 : {state.dataStrGlobals->exeDirectoryPath / InputFilePath, "EnergyPlus Executable Directory"},
165 20 : {state.dataSysVars->envinputpath1 / InputFilePath, R"("epin" Environment Variable)"},
166 20 : {state.dataSysVars->envinputpath2 / InputFilePath, R"("input_path" Environment Variable)"},
167 : // These two only tested if `TestAllPaths` is true
168 20 : {state.dataStrGlobals->CurrentWorkingFolder / InputFilePath, "INI File Directory"},
169 60 : {state.dataStrGlobals->ProgramPath / InputFilePath, R"("program", "dir" from INI File)"}}};
170 :
171 20 : std::size_t numPathsToTest = (state.dataSysVars->TestAllPaths) ? pathsToCheck.size() : pathsToCheck.size() - 2;
172 :
173 15 : for (std::size_t i = 0; i < numPathsToTest; ++i) {
174 14 : if (FileSystem::fileExists(pathsToCheck[i].first)) {
175 9 : foundFilePath = pathsToCheck[i].first;
176 9 : print(state.files.audit, "found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(foundFilePath));
177 :
178 9 : return foundFilePath;
179 : } else {
180 10 : std::pair<fs::path, std::string> currentPath(FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(pathsToCheck[i].first)),
181 10 : pathsToCheck[i].second);
182 5 : bool found = false;
183 9 : for (auto const &path : pathsChecked) {
184 4 : if (path.first == currentPath.first) {
185 4 : found = true;
186 : }
187 5 : }
188 5 : if (!found) {
189 1 : pathsChecked.push_back(currentPath);
190 : }
191 5 : print(state.files.audit, "not found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(pathsToCheck[i].first));
192 5 : }
193 : }
194 :
195 : // If we get here, we didn't find the file
196 1 : ShowSevereError(state, format("{}\"{}\" not found.", contextString, originalInputFilePath));
197 2 : ShowContinueError(state, " Paths searched:");
198 2 : for (auto &path : pathsChecked) {
199 1 : ShowContinueError(state, format(" {}: \"{}\"", path.second, path.first));
200 1 : }
201 :
202 1 : return foundFilePath;
203 10 : }
204 :
205 26 : void processEnvironmentVariables(EnergyPlusData &state)
206 : {
207 :
208 26 : std::string cEnvValue;
209 :
210 78 : get_environment_variable(DDOnlyEnvVar, cEnvValue);
211 26 : state.dataSysVars->DDOnly = env_var_on(cEnvValue); // Yes or True
212 26 : if (state.dataGlobal->DDOnlySimulation) {
213 25 : state.dataSysVars->DDOnly = true;
214 : }
215 :
216 78 : get_environment_variable(ReverseDDEnvVar, cEnvValue);
217 26 : state.dataSysVars->ReverseDD = env_var_on(cEnvValue); // Yes or True
218 :
219 78 : get_environment_variable(DisableGLHECachingEnvVar, cEnvValue);
220 26 : state.dataSysVars->DisableGLHECaching = env_var_on(cEnvValue); // Yes or True
221 :
222 78 : get_environment_variable(FullAnnualSimulation, cEnvValue);
223 26 : state.dataSysVars->FullAnnualRun = env_var_on(cEnvValue); // Yes or True
224 26 : if (state.dataGlobal->AnnualSimulation) {
225 0 : state.dataSysVars->FullAnnualRun = true;
226 : }
227 :
228 78 : get_environment_variable(cDisplayAllWarnings, cEnvValue);
229 26 : state.dataGlobal->DisplayAllWarnings = env_var_on(cEnvValue); // Yes or True
230 26 : if (state.dataGlobal->DisplayAllWarnings) {
231 0 : state.dataGlobal->DisplayAllWarnings = true;
232 0 : state.dataGlobal->DisplayExtraWarnings = true;
233 0 : state.dataGlobal->DisplayUnusedSchedules = true;
234 0 : state.dataGlobal->DisplayUnusedObjects = true;
235 : }
236 :
237 78 : get_environment_variable(cDisplayExtraWarnings, cEnvValue);
238 26 : if (!cEnvValue.empty()) {
239 0 : state.dataGlobal->DisplayExtraWarnings = env_var_on(cEnvValue); // Yes or True
240 : }
241 :
242 78 : get_environment_variable(cDisplayUnusedObjects, cEnvValue);
243 26 : if (!cEnvValue.empty()) {
244 0 : state.dataGlobal->DisplayUnusedObjects = env_var_on(cEnvValue); // Yes or True
245 : }
246 :
247 78 : get_environment_variable(cDisplayUnusedSchedules, cEnvValue);
248 26 : if (!cEnvValue.empty()) {
249 0 : state.dataGlobal->DisplayUnusedSchedules = env_var_on(cEnvValue); // Yes or True
250 : }
251 :
252 78 : get_environment_variable(cDisplayZoneAirHeatBalanceOffBalance, cEnvValue);
253 26 : if (!cEnvValue.empty()) {
254 0 : state.dataGlobal->DisplayZoneAirHeatBalanceOffBalance = env_var_on(cEnvValue); // Yes or True
255 : }
256 :
257 78 : get_environment_variable(cDisplayAdvancedReportVariables, cEnvValue);
258 26 : if (!cEnvValue.empty()) {
259 0 : state.dataGlobal->DisplayAdvancedReportVariables = env_var_on(cEnvValue); // Yes or True
260 : }
261 :
262 78 : get_environment_variable(cReportDuringWarmup, cEnvValue);
263 26 : if (!cEnvValue.empty()) {
264 0 : state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue); // Yes or True
265 : }
266 26 : if (state.dataSysVars->ReverseDD) {
267 0 : state.dataSysVars->ReportDuringWarmup = false; // force to false for ReverseDD runs
268 : }
269 :
270 78 : get_environment_variable(cReportDuringWarmup, cEnvValue);
271 26 : if (!cEnvValue.empty()) {
272 0 : state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue); // Yes or True
273 : }
274 26 : if (state.dataSysVars->DisableGLHECaching) {
275 0 : state.dataSysVars->ReportDuringWarmup = true; // force to true for standard runs runs
276 : }
277 :
278 78 : get_environment_variable(cReportDuringHVACSizingSimulation, cEnvValue);
279 26 : if (!cEnvValue.empty()) {
280 0 : state.dataSysVars->ReportDuringHVACSizingSimulation = env_var_on(cEnvValue); // Yes or True
281 : }
282 :
283 78 : get_environment_variable(cIgnoreSolarRadiation, cEnvValue);
284 26 : if (!cEnvValue.empty()) {
285 0 : state.dataEnvrn->IgnoreSolarRadiation = env_var_on(cEnvValue); // Yes or True
286 : }
287 :
288 78 : get_environment_variable(cMinimalSurfaceVariables, cEnvValue);
289 26 : if (!cEnvValue.empty()) {
290 0 : state.dataGlobal->CreateMinimalSurfaceVariables = env_var_on(cEnvValue); // Yes or True
291 : }
292 :
293 78 : get_environment_variable(cSortIDD, cEnvValue);
294 26 : if (!cEnvValue.empty()) {
295 0 : state.dataSysVars->SortedIDD = env_var_on(cEnvValue); // Yes or True
296 : }
297 :
298 78 : get_environment_variable(MinReportFrequencyEnvVar, cEnvValue);
299 26 : if (!cEnvValue.empty()) {
300 0 : state.dataSysVars->MinReportFrequency = cEnvValue; // turned into value later
301 : }
302 :
303 78 : get_environment_variable(cDeveloperFlag, cEnvValue);
304 26 : if (!cEnvValue.empty()) {
305 0 : state.dataSysVars->DeveloperFlag = env_var_on(cEnvValue); // Yes or True
306 : }
307 :
308 78 : get_environment_variable(cIgnoreBeamRadiation, cEnvValue);
309 26 : if (!cEnvValue.empty()) {
310 0 : state.dataEnvrn->IgnoreBeamRadiation = env_var_on(cEnvValue); // Yes or True
311 : }
312 :
313 78 : get_environment_variable(cIgnoreDiffuseRadiation, cEnvValue);
314 26 : if (!cEnvValue.empty()) {
315 0 : state.dataEnvrn->IgnoreDiffuseRadiation = env_var_on(cEnvValue); // Yes or True
316 : }
317 :
318 78 : get_environment_variable(cSutherlandHodgman, cEnvValue);
319 26 : if (!cEnvValue.empty()) {
320 0 : state.dataSysVars->SutherlandHodgman = env_var_on(cEnvValue); // Yes or True
321 : }
322 :
323 78 : get_environment_variable(cSlaterBarsky, cEnvValue);
324 26 : if (!cEnvValue.empty()) {
325 0 : state.dataSysVars->SlaterBarsky = env_var_on(cEnvValue); // Yes or True
326 : }
327 :
328 78 : get_environment_variable(cMinimalShadowing, cEnvValue);
329 26 : if (!cEnvValue.empty()) {
330 0 : state.dataSysVars->lMinimalShadowing = env_var_on(cEnvValue); // Yes or True
331 : }
332 :
333 78 : get_environment_variable(cTimingFlag, cEnvValue);
334 26 : if (!cEnvValue.empty()) {
335 0 : state.dataSysVars->TimingFlag = env_var_on(cEnvValue); // Yes or True
336 : }
337 :
338 : // Initialize env flags for air loop simulation debugging
339 78 : get_environment_variable(TrackAirLoopEnvVar, cEnvValue);
340 26 : if (!cEnvValue.empty()) {
341 0 : state.dataSysVars->TrackAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
342 : }
343 :
344 78 : get_environment_variable(TraceAirLoopEnvVar, cEnvValue);
345 26 : if (!cEnvValue.empty()) {
346 0 : state.dataSysVars->TraceAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
347 : }
348 :
349 78 : get_environment_variable(TraceHVACControllerEnvVar, cEnvValue);
350 26 : if (!cEnvValue.empty()) {
351 0 : state.dataSysVars->TraceHVACControllerEnvFlag = env_var_on(cEnvValue); // Yes or True
352 : }
353 :
354 78 : get_environment_variable(cDisplayInputInAuditEnvVar, cEnvValue);
355 26 : if (!cEnvValue.empty()) {
356 0 : state.dataGlobal->DisplayInputInAudit = env_var_on(cEnvValue); // Yes or True
357 : }
358 :
359 78 : get_environment_variable(ciForceTimeStepEnvVar, cEnvValue);
360 26 : if (!cEnvValue.empty()) {
361 0 : state.dataSysVars->ciForceTimeStep = env_var_on(cEnvValue); // Yes or True
362 : }
363 26 : }
364 :
365 : } // namespace DataSystemVariables
366 :
367 : } // namespace EnergyPlus
|