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 <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 : // DERIVED TYPE DEFINITIONS
115 : // na
116 :
117 : // INTERFACE BLOCK SPECIFICATIONS
118 : // na
119 :
120 : // MODULE VARIABLE DECLARATIONS:
121 :
122 : // Shading methods
123 :
124 : // Functions
125 :
126 148 : fs::path CheckForActualFilePath(EnergyPlusData &state,
127 : fs::path const &originalInputFilePath, // path (or filename only) as input for object
128 : const std::string &contextString //
129 : )
130 : {
131 :
132 : // SUBROUTINE INFORMATION:
133 : // AUTHOR Linda Lawrie
134 : // DATE WRITTEN October 2011
135 : // MODIFIED na
136 : // RE-ENGINEERED na
137 :
138 : // PURPOSE OF THIS SUBROUTINE:
139 : // With the Windows version, there are subfolders set and the input file names may not
140 : // be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see
141 : // if the file can be found. (It may have been input with full path so that is checked first.)
142 :
143 : // Locals
144 : // SUBROUTINE ARGUMENT DEFINITIONS:
145 :
146 : // SUBROUTINE PARAMETER DEFINITIONS:
147 :
148 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
149 148 : fs::path foundFilePath;
150 :
151 148 : if (state.dataSysVars->firstTime) {
152 21 : state.files.audit.ensure_open(state, "CheckForActualFilePath", state.files.outputControl.audit);
153 21 : std::string tmp;
154 :
155 : // epin is passed from Epl-run.bat as the path to the IDF file minus its extension, so take the parent directory
156 21 : get_environment_variable(cInputPath1, tmp);
157 21 : state.dataSysVars->envinputpath1 = FileSystem::getParentDirectoryPath(fs::path(tmp));
158 :
159 21 : get_environment_variable(cInputPath2, tmp);
160 21 : state.dataSysVars->envinputpath2 = fs::path(tmp);
161 :
162 21 : get_environment_variable(cProgramPath, tmp);
163 21 : state.dataStrGlobals->ProgramPath = fs::path(tmp);
164 21 : state.dataSysVars->firstTime = false;
165 21 : }
166 :
167 148 : fs::path InputFilePath = FileSystem::makeNativePath(originalInputFilePath); // save for changing out path characters
168 :
169 148 : std::vector<std::pair<fs::path, std::string>> pathsChecked;
170 :
171 : const std::array<std::pair<fs::path, std::string>, 7> pathsToCheck = {
172 : {{InputFilePath, "Current Working Directory"},
173 296 : {state.dataStrGlobals->inputDirPath / InputFilePath, "IDF Directory"},
174 296 : {state.dataStrGlobals->exeDirectoryPath / InputFilePath, "EnergyPlus Executable Directory"},
175 296 : {state.dataSysVars->envinputpath1 / InputFilePath, R"("epin" Environment Variable)"},
176 296 : {state.dataSysVars->envinputpath2 / InputFilePath, R"("input_path" Environment Variable)"},
177 : // These two only tested if `TestAllPaths` is true
178 296 : {state.dataStrGlobals->CurrentWorkingFolder / InputFilePath, "INI File Directory"},
179 1628 : {state.dataStrGlobals->ProgramPath / InputFilePath, R"("program", "dir" from INI File)"}}};
180 :
181 148 : std::size_t numPathsToTest = (state.dataSysVars->TestAllPaths) ? pathsToCheck.size() : pathsToCheck.size() - 2;
182 :
183 296 : for (std::size_t i = 0; i < numPathsToTest; ++i) {
184 296 : if (FileSystem::fileExists(pathsToCheck[i].first)) {
185 148 : foundFilePath = pathsToCheck[i].first;
186 148 : print(state.files.audit, "found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(foundFilePath));
187 :
188 148 : return foundFilePath;
189 : } else {
190 296 : std::pair<fs::path, std::string> currentPath(FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(pathsToCheck[i].first)),
191 296 : pathsToCheck[i].second);
192 148 : bool found = false;
193 148 : for (auto const &path : pathsChecked) {
194 0 : if (path.first == currentPath.first) {
195 0 : found = true;
196 : }
197 148 : }
198 148 : if (!found) {
199 148 : pathsChecked.push_back(currentPath);
200 : }
201 148 : print(state.files.audit, "not found ({})={}\n", pathsToCheck[i].second, FileSystem::getAbsolutePath(pathsToCheck[i].first));
202 148 : }
203 : }
204 :
205 : // If we get here, we didn't find the file
206 0 : ShowSevereError(state, format("{}\"{}\" not found.", contextString, originalInputFilePath));
207 0 : ShowContinueError(state, " Paths searched:");
208 0 : for (auto &path : pathsChecked) {
209 0 : ShowContinueError(state, format(" {}: \"{}\"", path.second, path.first));
210 0 : }
211 :
212 0 : return foundFilePath;
213 148 : }
214 :
215 796 : void processEnvironmentVariables(EnergyPlusData &state)
216 : {
217 :
218 796 : std::string cEnvValue;
219 :
220 796 : get_environment_variable(DDOnlyEnvVar, cEnvValue);
221 796 : state.dataSysVars->DDOnly = env_var_on(cEnvValue); // Yes or True
222 796 : if (state.dataGlobal->DDOnlySimulation) state.dataSysVars->DDOnly = true;
223 :
224 796 : get_environment_variable(ReverseDDEnvVar, cEnvValue);
225 796 : state.dataSysVars->ReverseDD = env_var_on(cEnvValue); // Yes or True
226 :
227 796 : get_environment_variable(DisableGLHECachingEnvVar, cEnvValue);
228 796 : state.dataSysVars->DisableGLHECaching = env_var_on(cEnvValue); // Yes or True
229 :
230 796 : get_environment_variable(FullAnnualSimulation, cEnvValue);
231 796 : state.dataSysVars->FullAnnualRun = env_var_on(cEnvValue); // Yes or True
232 796 : if (state.dataGlobal->AnnualSimulation) state.dataSysVars->FullAnnualRun = true;
233 :
234 796 : get_environment_variable(cDisplayAllWarnings, cEnvValue);
235 796 : state.dataGlobal->DisplayAllWarnings = env_var_on(cEnvValue); // Yes or True
236 796 : if (state.dataGlobal->DisplayAllWarnings) {
237 0 : state.dataGlobal->DisplayAllWarnings = true;
238 0 : state.dataGlobal->DisplayExtraWarnings = true;
239 0 : state.dataGlobal->DisplayUnusedSchedules = true;
240 0 : state.dataGlobal->DisplayUnusedObjects = true;
241 : }
242 :
243 796 : get_environment_variable(cDisplayExtraWarnings, cEnvValue);
244 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayExtraWarnings = env_var_on(cEnvValue); // Yes or True
245 :
246 796 : get_environment_variable(cDisplayUnusedObjects, cEnvValue);
247 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayUnusedObjects = env_var_on(cEnvValue); // Yes or True
248 :
249 796 : get_environment_variable(cDisplayUnusedSchedules, cEnvValue);
250 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayUnusedSchedules = env_var_on(cEnvValue); // Yes or True
251 :
252 796 : get_environment_variable(cDisplayZoneAirHeatBalanceOffBalance, cEnvValue);
253 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayZoneAirHeatBalanceOffBalance = env_var_on(cEnvValue); // Yes or True
254 :
255 796 : get_environment_variable(cDisplayAdvancedReportVariables, cEnvValue);
256 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayAdvancedReportVariables = env_var_on(cEnvValue); // Yes or True
257 :
258 796 : get_environment_variable(cReportDuringWarmup, cEnvValue);
259 796 : if (!cEnvValue.empty()) state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue); // Yes or True
260 796 : if (state.dataSysVars->ReverseDD) state.dataSysVars->ReportDuringWarmup = false; // force to false for ReverseDD runs
261 :
262 796 : get_environment_variable(cReportDuringWarmup, cEnvValue);
263 796 : if (!cEnvValue.empty()) state.dataSysVars->ReportDuringWarmup = env_var_on(cEnvValue); // Yes or True
264 796 : if (state.dataSysVars->DisableGLHECaching) state.dataSysVars->ReportDuringWarmup = true; // force to true for standard runs runs
265 :
266 796 : get_environment_variable(cReportDuringHVACSizingSimulation, cEnvValue);
267 796 : if (!cEnvValue.empty()) state.dataSysVars->ReportDuringHVACSizingSimulation = env_var_on(cEnvValue); // Yes or True
268 :
269 796 : get_environment_variable(cIgnoreSolarRadiation, cEnvValue);
270 796 : if (!cEnvValue.empty()) state.dataEnvrn->IgnoreSolarRadiation = env_var_on(cEnvValue); // Yes or True
271 :
272 796 : get_environment_variable(cMinimalSurfaceVariables, cEnvValue);
273 796 : if (!cEnvValue.empty()) state.dataGlobal->CreateMinimalSurfaceVariables = env_var_on(cEnvValue); // Yes or True
274 :
275 796 : get_environment_variable(cSortIDD, cEnvValue);
276 796 : if (!cEnvValue.empty()) state.dataSysVars->SortedIDD = env_var_on(cEnvValue); // Yes or True
277 :
278 796 : get_environment_variable(MinReportFrequencyEnvVar, cEnvValue);
279 796 : if (!cEnvValue.empty()) state.dataSysVars->MinReportFrequency = cEnvValue; // turned into value later
280 :
281 796 : get_environment_variable(cDeveloperFlag, cEnvValue);
282 796 : if (!cEnvValue.empty()) state.dataSysVars->DeveloperFlag = env_var_on(cEnvValue); // Yes or True
283 :
284 796 : get_environment_variable(cIgnoreBeamRadiation, cEnvValue);
285 796 : if (!cEnvValue.empty()) state.dataEnvrn->IgnoreBeamRadiation = env_var_on(cEnvValue); // Yes or True
286 :
287 796 : get_environment_variable(cIgnoreDiffuseRadiation, cEnvValue);
288 796 : if (!cEnvValue.empty()) state.dataEnvrn->IgnoreDiffuseRadiation = env_var_on(cEnvValue); // Yes or True
289 :
290 796 : get_environment_variable(cSutherlandHodgman, cEnvValue);
291 796 : if (!cEnvValue.empty()) state.dataSysVars->SutherlandHodgman = env_var_on(cEnvValue); // Yes or True
292 :
293 796 : get_environment_variable(cSlaterBarsky, cEnvValue);
294 796 : if (!cEnvValue.empty()) state.dataSysVars->SlaterBarsky = env_var_on(cEnvValue); // Yes or True
295 :
296 796 : get_environment_variable(cMinimalShadowing, cEnvValue);
297 796 : if (!cEnvValue.empty()) state.dataSysVars->lMinimalShadowing = env_var_on(cEnvValue); // Yes or True
298 :
299 796 : get_environment_variable(cTimingFlag, cEnvValue);
300 796 : if (!cEnvValue.empty()) state.dataSysVars->TimingFlag = env_var_on(cEnvValue); // Yes or True
301 :
302 : // Initialize env flags for air loop simulation debugging
303 796 : get_environment_variable(TrackAirLoopEnvVar, cEnvValue);
304 796 : if (!cEnvValue.empty()) state.dataSysVars->TrackAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
305 :
306 796 : get_environment_variable(TraceAirLoopEnvVar, cEnvValue);
307 796 : if (!cEnvValue.empty()) state.dataSysVars->TraceAirLoopEnvFlag = env_var_on(cEnvValue); // Yes or True
308 :
309 796 : get_environment_variable(TraceHVACControllerEnvVar, cEnvValue);
310 796 : if (!cEnvValue.empty()) state.dataSysVars->TraceHVACControllerEnvFlag = env_var_on(cEnvValue); // Yes or True
311 :
312 796 : get_environment_variable(cDisplayInputInAuditEnvVar, cEnvValue);
313 796 : if (!cEnvValue.empty()) state.dataGlobal->DisplayInputInAudit = env_var_on(cEnvValue); // Yes or True
314 796 : }
315 :
316 : } // namespace DataSystemVariables
317 :
318 : } // namespace EnergyPlus
|