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 : // Portions of the EnergyPlus(tm) software package have been developed and copyrighted by other
49 : // individuals, companies and institutions. These portions have been incorporated into the EnergyPlus
50 : // software package under license.
51 :
52 : // In addition to the primary authorship of the LBNL Simulation Research Group (
53 : // http://simulationresearch.lbl.gov/) and the UIUC Building Systems Laboratory (
54 : // http://www.bso.uiuc.edu/), the following have contributed to EnergyPlus V1.0:
55 :
56 : // Portions of the EnergyPlus weather processor were developed by US Department of Energy, Building
57 : // Technologies Program, www.energyplus.gov
58 :
59 : // Portions of the input processing, output processing, weather processor, BLAST Translator were
60 : // developed by US Army Corps of Engineers, Construction Engineering Research Laboratories, 2902 Newmark
61 : // Drive, Champaign IL 61821. www.cecer.army.mil
62 :
63 : // Portions of this software package were developed by Linda Lawrie of DHL Consulting LLC.
64 :
65 : // Portions of this software package were developed by C.O. Pedersen Associates.
66 :
67 : // Portions of the EnergyPlus utility software (EP-Launch, IDFEditor, DOE2Translator, HVAC-Diagram,
68 : // ExpandObjects, CSVProc, System Templates, and convertESOMTR) were developed by GARD Analytics, Inc.
69 : // 1028 Busse Highway, Park Ridge, Illinois 60068-1802, USA (847) 698-5690, www.gard.com. GARD Analytics
70 : // performed independent verification and validation testing of the software after developing the testing
71 : // strategy and plan. GARD Analytics was also responsible for gas absorption chiller, desiccant
72 : // dehumidifier, ice storage (simple), table reports and economics.
73 :
74 : // Portions of flow resolver, chiller models (absorption, electric, const cop, engine-driven, gas-
75 : // turbine), generator models (diesel electric, gas turbine), furnace models, heat recovery loop, plant
76 : // loop, plant condenser loop, air-change dependent inside film coefficients were developed by Oklahoma
77 : // State University, 110 Engineering North, Stillwater, OK 74078.
78 :
79 : // Portions of EnergyPlus related to the models for EMPD moisture calculations, DX coils, furnace/unitary
80 : // systems, cooling towers, air-to-air heat pumps, air distribution systems, refrigerated cases, electric
81 : // EIR chillers, packaged terminal heat pumps, desuperheater air and water heating coils, and heat pump
82 : // water heaters were developed by University of Central Florida, Florida Solar Energy Center (FSEC),
83 : // 1679 Clearlake Road, Cocoa, FL 32922, www.fsec.ucf.edu/.
84 :
85 : // Portions of EnergyPlus were developed by the National Renewable Energy Laboratory (NREL), 1617 Cole
86 : // Blvd, Golden, CO 80401.
87 :
88 : // EnergyPlus v1.0.1, v1.0.2, v1.0.3, v1.1, v1.1.1 (Wintel platform) includes a link to TRNSYS (The Transient
89 : // Energy System Simulation Tool) for photovoltaic calculations developed by Thermal Energy System Specialists,
90 : // 2916 Marketplace Drive, Suite 104, Madison, WI 53719; Tel: (608) 274-2577. EnergyPlus v1.2 and later
91 : // includes Photovoltaic calculations implemented in EnergyPlus by Thermal Energy System Specialists.
92 : // This model was originally developed by Oystein Ulleberg, Institute for Energy Technology, Norway -- based on
93 : // the Duffie and Beckman equivalent one-diode model.
94 :
95 : // Portions of this software package that convert certain stand-alone heat transfer models for slab-on-
96 : // grade and basement foundations were developed by William Bahnfleth, Cynthia Cogil, and Edward
97 : // Clements, Department of Architectural Engineering, Pennsylvania State University, 224 Engineering Unit
98 : // A, University Park, Pennsylvania 16802-1416, (814) 863-2076.
99 :
100 : // The concept and initial implementation for the EnergyPlus COM/DLL version (Wintel platform) was made
101 : // possible through cooperation with DesignBuilder Software, Ltd, Andy Tindale - an EnergyPlus
102 : // collaborative developer.
103 :
104 : // The thickness, conductivity, density and specific heat values of the material layers for the
105 : // constructions in the Composite Wall Construction reference data set have been taken from the ASHRAE
106 : // report "Modeling Two- and Three-Dimensional Heat Transfer through Composite Wall and Roof Assemblies
107 : // in Hourly Energy Simulation Programs (1145-TRP)," by Enermodal Engineering Limited, Oak Ridge
108 : // National Laboratory, and the Polish Academy of Sciences, January 2001.
109 :
110 : // EnergyPlus v1.2 contains DELight2 (wintel platform), a simulation engine for daylighting and electric
111 : // lighting system analysis developed at Ernest Orlando Lawrence Berkeley National Laboratory.
112 :
113 : // Portions of the EnergyPlus v1.2 air distribution system calculations were written by George Walton of
114 : // the National Institute for Standards and Technology (NIST), 100 Bureau Drive, Gaithersburg, MD 20899,
115 : // (301) 975-6478. The EnergyPlus AirflowNetwork model also includes portions of an early version of COMIS
116 : // (Conjunction Of Multizone Infiltration Specialists) developed by a multinational, multi-institutional
117 : // effort under the auspices of the International Energy Agency's Buildings and Community Systems Agreement
118 : // working group focusing on multizone air flow modeling (Annex 23) and now administered by the Swiss Federal
119 : // Laboratories for Materials Testing and Research (EMPA), Division 175, Uberlandstrasse 129, CH-8600 Dubendorf,
120 : // Switzerland.
121 :
122 : // The EnergyPlus v1.2 model for displacement ventilation and cross-ventilation was developed
123 : // by Guilherme Carrilho da Graca and Paul Linden of the Department of Mechanical and Aerospace
124 : // Engineering, University of California, San Diego.
125 :
126 : // The EnergyPlus models for UFAD served zones were developed by Anna Liu and Paul Linden at the Department
127 : // of Mechanical and Aerospace Engineering, University of California, San Diego.
128 :
129 : // ASHRAE research project 1254-RP supported the development of the following features first added in
130 : // EnergyPlus v1.2.2:
131 : // DXSystem:AirLoop enhancements (valid as OA system equipment, new humidity control options);
132 : // New set point managers: SET POINT MANAGER:SINGLE ZONE HEATING, SET POINT MANAGER:SINGLE ZONE COOLING,
133 : // and SET POINT MANAGER:OUTSIDE AIR PRETREAT;
134 : // New 2-stage DX coil with enhanced dehumidification option (COIL:DX:MultiMode:CoolingEmpirical);
135 : // Additional DESICCANT DEHUMIDIFIER:SOLID setpoint control option;
136 : // American Society of Heating Refrigerating and Air-Conditioning Engineers, Inc,,
137 : // 1791 Tullie Circle, N.E., Atlanta, GA 30329. www.ashrae.org
138 : // Work performed by GARD Analytics, Inc., 1028 Busse Highway, Park Ridge, Illinois 60068-1802, USA.
139 : // www.gard.com, November 2004.
140 :
141 : // EnergyPlus v1.2.2 and later versions (wintel platform) contains links to SPARK, a simulation engine for
142 : // detailed system modeling developed at Ernest Orlando Lawrence Berkeley National Laboratory in
143 : // conjunction with Ayres Sowell Associates, Inc. SPARK was removed in V3.1 - April 2009 release.
144 :
145 : // The Ecoroof (Green Roof) model, first introduced in EnergyPlus v2.0, was developed at Portland State University,
146 : // by David Sailor and his students. It is based on the FASST vegetation models developed by Frankenstein and
147 : // Koenig for the US Army Corps of Engineers.
148 :
149 : // The HAMT (Heat And Moisture Transfer) model, first introduced in EnergyPlus v3.0.0 was developed by Phillip Biddulph,
150 : // Complex Built Environment Systems, The Bartlett School of Graduate Studies, University College London, Gower Street,
151 : // London WC1E 6BT, United Kingdom. http://www.cbes.ucl.ac.uk/.
152 :
153 : // The SQLite output module, first introduced in EnergyPlus v3.0.0, was developed by Gregory B. Stark, P.E.,
154 : // Building Synergies, LLC, 1860 Washington Street, Suite 208, Denver, Colorado 80203, United States.
155 : // http://www.buildingsynergies.com/
156 :
157 : // Refrigeration compressor performance data and refrigeration practices were provided by CDH Energy, Cazenovia, NY 12035.
158 :
159 : // Other Acknowledgments
160 :
161 : // This work was supported by the Assistant Secretary for Energy Efficiency and Renewable Energy, Office
162 : // of Building Technologies Program of the US Department of Energy.
163 :
164 : // Additional support was provided by the Gas Technology Institute and the California Energy Commission.
165 :
166 : // The ice thermal storage module development was supported by the U.S. Department of Energy Office of
167 : // Electricity Delivery and Energy Reliability.
168 :
169 : // The HAMT (Heat And Moisture Transfer) model was supported by the Engineering and Physical Sciences Research Council (EPSRC),
170 : // the UK government agency for funding research and training in engineering and the physical sciences.
171 :
172 : // The SQLite output module was funded by Building Synergies, LLC and was made possible by inclusion of software code
173 : // from the SQLite project (http://www.sqlite.org/).
174 :
175 : #ifdef _WIN32
176 : # include <Windows.h>
177 : #endif
178 :
179 : // C++ Headers
180 : #include <exception>
181 : #include <iostream>
182 : #include <string>
183 : #include <vector>
184 :
185 : #ifdef DEBUG_ARITHM_GCC_OR_CLANG
186 : # include <EnergyPlus/fenv_missing.h>
187 : #endif
188 :
189 : #ifdef DEBUG_ARITHM_MSVC
190 : # include <cfloat>
191 : #endif
192 :
193 : // ObjexxFCL Headers
194 : #include <ObjexxFCL/Array1D.hh>
195 : #include <ObjexxFCL/time.hh>
196 :
197 : // EnergyPlus Headers
198 : #include <EnergyPlus/CommandLineInterface.hh>
199 : #include <EnergyPlus/Data/EnergyPlusData.hh>
200 : #include <EnergyPlus/DataGlobals.hh>
201 : #include <EnergyPlus/DataStringGlobals.hh>
202 : #include <EnergyPlus/DataSystemVariables.hh>
203 : #include <EnergyPlus/DataTimings.hh>
204 : #include <EnergyPlus/DisplayRoutines.hh>
205 : #include <EnergyPlus/FileSystem.hh>
206 : #include <EnergyPlus/FluidProperties.hh>
207 : #include <EnergyPlus/IOFiles.hh>
208 : #include <EnergyPlus/InputProcessing/IdfParser.hh>
209 : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
210 : #include <EnergyPlus/InputProcessing/InputValidation.hh>
211 : #include <EnergyPlus/OutputProcessor.hh>
212 : #include <EnergyPlus/Psychrometrics.hh>
213 : #include <EnergyPlus/ResultsFramework.hh>
214 : #include <EnergyPlus/SQLiteProcedures.hh>
215 : #include <EnergyPlus/ScheduleManager.hh>
216 : #include <EnergyPlus/SimulationManager.hh>
217 : #include <EnergyPlus/UtilityRoutines.hh>
218 : #include <EnergyPlus/api/EnergyPlusPgm.hh>
219 :
220 : #ifdef _WIN32
221 : # include <direct.h>
222 : # include <stdlib.h>
223 : #else // Mac or Linux
224 : # include <unistd.h>
225 : #endif
226 :
227 4 : int EnergyPlusPgm(const std::vector<std::string> &args, std::string const &filepath)
228 : {
229 4 : EnergyPlus::EnergyPlusData state;
230 : //// these need to be set early to be used in help and version output messaging
231 4 : Array1D_int value(8);
232 4 : std::string datestring; // supposedly returns blank when no date available.
233 4 : date_and_time(datestring, _, _, value);
234 4 : if (!datestring.empty()) {
235 8 : state.dataStrGlobals->CurrentDateTime = fmt::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
236 : } else {
237 0 : state.dataStrGlobals->CurrentDateTime = " unknown date/time";
238 : }
239 4 : state.dataStrGlobals->VerStringVar = EnergyPlus::DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
240 :
241 4 : EnergyPlus::CommandLineInterface::ProcessArgs(state, args);
242 8 : return RunEnergyPlus(state, filepath);
243 4 : }
244 :
245 26 : void commonInitialize(EnergyPlus::EnergyPlusData &state)
246 : {
247 : using namespace EnergyPlus;
248 : // Disable C++ i/o synching with C methods for speed
249 : // std::ios_base::sync_with_stdio(false);
250 : // std::cin.tie(nullptr); // Untie cin and cout: Could cause odd behavior for interactive prompts
251 :
252 : // Enable floating point exceptions
253 : #ifdef DEBUG_ARITHM_GCC_OR_CLANG
254 : feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); // These exceptions are enabled (FE_INEXACT and FE_UNDERFLOW will not throw)
255 : #endif
256 :
257 : #ifdef DEBUG_ARITHM_MSVC
258 : // the following enables NaN detection in Visual Studio debug builds. See
259 : // https://github.com/NREL/EnergyPlus/wiki/Debugging-Tips
260 :
261 : // Note: what you need to pass to the _controlfp_s is actually the opposite
262 : // By default all bits are 1, and the exceptions are turned off, so you need to turn off the bits for the exceptions you want to enable
263 : // > For the _MCW_EM mask, clearing it sets the exception, which allows the hardware exception; setting it hides the exception.
264 : unsigned int fpcntrl = 0;
265 : _controlfp_s(&fpcntrl, 0, 0);
266 : unsigned int new_exceptions = _EM_ZERODIVIDE | _EM_INVALID | _EM_OVERFLOW;
267 : unsigned int new_control = fpcntrl & ~new_exceptions;
268 : _controlfp_s(&fpcntrl, new_control, _MCW_EM);
269 : #endif
270 :
271 : #ifdef _MSC_VER
272 : # ifndef _DEBUG
273 : // If _MSC_VER and not debug then prevent dialogs on error
274 : SetErrorMode(SEM_NOGPFAULTERRORBOX);
275 : _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
276 : _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
277 : # endif
278 : #endif
279 :
280 26 : state.dataSysVars->runtimeTimer.tick();
281 :
282 26 : state.dataStrGlobals->CurrentDateTime = CreateCurrentDateTimeString();
283 :
284 26 : state.dataResultsFramework->resultsFramework->SimulationInformation.setProgramVersion(state.dataStrGlobals->VerStringVar);
285 26 : state.dataResultsFramework->resultsFramework->SimulationInformation.setStartDateTimeStamp(state.dataStrGlobals->CurrentDateTime.substr(5));
286 :
287 26 : state.dataStrGlobals->VerStringVar = DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
288 :
289 26 : DataSystemVariables::processEnvironmentVariables(state);
290 26 : }
291 :
292 26 : int commonRun(EnergyPlus::EnergyPlusData &state)
293 : {
294 : using namespace EnergyPlus;
295 :
296 26 : int errStatus = initErrorFile(state);
297 26 : if (errStatus) {
298 0 : return errStatus;
299 : }
300 :
301 26 : state.dataSysVars->TestAllPaths = true;
302 :
303 26 : DisplayString(state, "EnergyPlus Starting");
304 26 : DisplayString(state, state.dataStrGlobals->VerStringVar);
305 :
306 : try {
307 26 : if (!state.dataInputProcessing->inputProcessor) {
308 0 : state.dataInputProcessing->inputProcessor = InputProcessor::factory();
309 : }
310 26 : state.dataInputProcessing->inputProcessor->processInput(state);
311 26 : if (state.dataGlobal->outputEpJSONConversionOnly) {
312 0 : DisplayString(state, "Converted input file format. Exiting.");
313 0 : return EndEnergyPlus(state);
314 : }
315 0 : } catch (const FatalError &e) {
316 0 : return AbortEnergyPlus(state);
317 0 : } catch (const std::exception &e) {
318 0 : ShowSevereError(state, e.what());
319 0 : return AbortEnergyPlus(state);
320 0 : }
321 26 : return 0;
322 : }
323 :
324 5 : int initializeEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
325 : {
326 : using namespace EnergyPlus;
327 5 : commonInitialize(state);
328 :
329 5 : if (!filepath.empty()) {
330 : // if filepath is not empty, then we are using E+ as a library API call
331 : // change the directory to the specified folder, and pass in dummy args to command line parser
332 : // this will initialize the paths throughout E+ to the defaults
333 1 : DisplayString(state, "EnergyPlus Library: Changing directory to: " + filepath);
334 : #ifdef _WIN32
335 : int status = _chdir(filepath.c_str());
336 : #else
337 1 : int status = chdir(filepath.c_str());
338 : #endif
339 1 : if (status == 0) {
340 1 : DisplayString(state, "Directory change successful.");
341 : } else {
342 0 : DisplayString(state, "Couldn't change directory; aborting EnergyPlus");
343 0 : return EXIT_FAILURE;
344 : }
345 1 : state.dataStrGlobals->ProgramPath = filepath + DataStringGlobals::pathChar;
346 3 : CommandLineInterface::ProcessArgs(state, {"energyplus"});
347 : }
348 :
349 5 : return commonRun(state);
350 : }
351 :
352 21 : int initializeAsLibrary(EnergyPlus::EnergyPlusData &state)
353 : {
354 21 : commonInitialize(state);
355 21 : return commonRun(state);
356 : }
357 :
358 24 : int wrapUpEnergyPlus(EnergyPlus::EnergyPlusData &state)
359 : {
360 : using namespace EnergyPlus;
361 :
362 : try {
363 48 : ShowMessage(state, "Simulation Error Summary *************");
364 :
365 24 : GenOutputVariablesAuditReport(state);
366 :
367 24 : Psychrometrics::ShowPsychrometricSummary(state, state.files.audit);
368 :
369 24 : state.dataInputProcessing->inputProcessor->reportOrphanRecordObjects(state);
370 :
371 24 : Fluid::ReportOrphanFluids(state);
372 24 : Sched::ReportOrphanSchedules(state);
373 :
374 24 : if (state.dataSQLiteProcedures->sqlite) {
375 1 : state.dataSQLiteProcedures->sqlite.reset();
376 : }
377 24 : if (state.dataInputProcessing->inputProcessor) {
378 24 : state.dataInputProcessing->inputProcessor.reset();
379 : }
380 :
381 24 : if (state.dataGlobal->runReadVars) {
382 3 : if (state.files.outputControl.csv) {
383 0 : ShowWarningMessage(state, "Native CSV output requested in input file, but running ReadVarsESO due to command line argument.");
384 0 : ShowWarningMessage(state, "This will overwrite the native CSV output.");
385 : }
386 3 : int status = CommandLineInterface::runReadVarsESO(state);
387 3 : if (status) {
388 0 : return status;
389 : }
390 : }
391 0 : } catch (const FatalError &e) {
392 0 : return AbortEnergyPlus(state);
393 0 : } catch (const std::exception &e) {
394 0 : ShowSevereError(state, e.what());
395 0 : return AbortEnergyPlus(state);
396 0 : }
397 :
398 24 : return EndEnergyPlus(state);
399 : }
400 :
401 5 : int RunEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
402 : {
403 :
404 : // PROGRAM INFORMATION:
405 : // AUTHOR Linda K. Lawrie, et al
406 : // DATE WRITTEN January 1997.....
407 : // MODIFIED na
408 : // RE-ENGINEERED na
409 :
410 : // PURPOSE OF THIS PROGRAM:
411 : // This program implements the calls for EnergyPlus (originally configured
412 : // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
413 :
414 : // METHODOLOGY EMPLOYED:
415 : // The method used in EnergyPlus is to simplify the main program as much
416 : // as possible and contain all "simulation" code in other modules and files.
417 : using namespace EnergyPlus;
418 5 : int status = initializeEnergyPlus(state, filepath);
419 5 : if (status || state.dataGlobal->outputEpJSONConversionOnly) return status;
420 : try {
421 5 : EnergyPlus::SimulationManager::ManageSimulation(state);
422 0 : } catch (const EnergyPlus::FatalError &e) {
423 0 : return EnergyPlus::AbortEnergyPlus(state);
424 : #ifdef NDEBUG
425 : } catch (const std::exception &e) {
426 : ShowSevereError(state, e.what());
427 : return EnergyPlus::AbortEnergyPlus(state);
428 : #endif
429 0 : }
430 :
431 5 : return wrapUpEnergyPlus(state);
432 : }
433 :
434 23 : int runEnergyPlusAsLibrary(EnergyPlus::EnergyPlusData &state, const std::vector<std::string> &args)
435 : {
436 : // PROGRAM INFORMATION:
437 : // AUTHOR Linda K. Lawrie, et al
438 : // DATE WRITTEN January 1997.....
439 : // MODIFIED na
440 : // RE-ENGINEERED na
441 :
442 : // PURPOSE OF THIS PROGRAM:
443 : // This program implements the calls for EnergyPlus (originally configured
444 : // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
445 :
446 : // METHODOLOGY EMPLOYED:
447 : // The method used in EnergyPlus is to simplify the main program as much
448 : // as possible and contain all "simulation" code in other modules and files.
449 : using namespace EnergyPlus;
450 23 : state.dataGlobal->eplusRunningViaAPI = true;
451 :
452 : // clean out any stdin, stderr, stdout flags from a prior call
453 23 : if (!std::cin.good()) std::cin.clear();
454 23 : if (!std::cerr.good()) std::cerr.clear();
455 23 : if (!std::cout.good()) std::cout.clear();
456 :
457 23 : int return_code = EnergyPlus::CommandLineInterface::ProcessArgs(state, args);
458 23 : if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Failure)) {
459 1 : return return_code;
460 22 : } else if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::SuccessButHelper)) {
461 : // If it was "--version" or "--help", you do not want to continue trying to run the simulation, but do not want to indicate failure either
462 1 : return static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Success);
463 : }
464 :
465 21 : int status = initializeAsLibrary(state);
466 21 : if (status || state.dataGlobal->outputEpJSONConversionOnly) {
467 0 : return status;
468 : }
469 : try {
470 21 : EnergyPlus::SimulationManager::ManageSimulation(state);
471 2 : } catch (const EnergyPlus::FatalError &e) {
472 2 : return EnergyPlus::AbortEnergyPlus(state);
473 2 : } catch (const std::exception &e) {
474 0 : ShowSevereError(state, e.what());
475 0 : return EnergyPlus::AbortEnergyPlus(state);
476 0 : }
477 19 : return wrapUpEnergyPlus(state);
478 : }
479 :
480 1 : void StoreProgressCallback(EnergyPlus::EnergyPlusData &state, void (*f)(int const))
481 : {
482 1 : state.dataGlobal->fProgressPtr = f;
483 1 : }
484 1 : void StoreMessageCallback(EnergyPlus::EnergyPlusData &state, void (*f)(std::string const &))
485 : {
486 1 : state.dataGlobal->fMessagePtr = f;
487 1 : }
488 :
489 26 : std::string CreateCurrentDateTimeString()
490 : {
491 :
492 : // SUBROUTINE INFORMATION:
493 : // AUTHOR Linda Lawrie
494 : // DATE WRITTEN October 2010
495 : // MODIFIED na
496 : // RE-ENGINEERED na
497 :
498 : // PURPOSE OF THIS SUBROUTINE:
499 : // Be able to supply a current date/time string from intrinsic calls so
500 : // that one is always available.
501 :
502 : // SUBROUTINE PARAMETER DEFINITIONS:
503 :
504 : // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
505 26 : Array1D_int value(8);
506 : // value(1) Current year
507 : // value(2) Current month
508 : // value(3) Current day
509 : // value(4) Time difference with respect to UTC in minutes (0-59)
510 : // value(5) Hour of the day (0-23)
511 : // value(6) Minutes (0-59)
512 : // value(7) Seconds (0-59)
513 : // value(8) Milliseconds (0-999)
514 26 : std::string datestring; // supposedly returns blank when no date available.
515 :
516 26 : date_and_time(datestring, _, _, value);
517 26 : if (!datestring.empty()) {
518 26 : return EnergyPlus::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
519 : } else {
520 0 : return " unknown date/time";
521 : }
522 26 : }
|