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 : #include <EnergyPlus/Data/EnergyPlusData.hh>
49 : #include <EnergyPlus/DataStringGlobals.hh>
50 : #include <EnergyPlus/PluginManager.hh>
51 : #include <EnergyPlus/UtilityRoutines.hh>
52 : #include <EnergyPlus/api/EnergyPlusPgm.hh>
53 : #include <EnergyPlus/api/runtime.h>
54 :
55 : // disabling "maybe unused" warnings for all the API functions so the IDE isn't lit up with messages
56 : #pragma clang diagnostic push
57 : #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
58 :
59 0 : int energyplus(EnergyPlusState state, int argc, const char *argv[])
60 : {
61 : // argv[0] = "energyplus";
62 : // argv[1] = "-d";
63 : // argv[2] = workingPath.string().c_str();
64 : // argv[3] = "-w";
65 : // argv[4] = epcomp->weatherFilePath.c_str();
66 : // argv[5] = "-i";
67 : // argv[6] = epcomp->iddPath.c_str();
68 : // argv[7] = epcomp->idfInputPath.c_str();
69 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
70 0 : if (!thisState->ready) {
71 0 : std::cerr << "Attempted to re-run EnergyPlus using a state that was not yet cleared, call stateReset() on this instance and try again\n";
72 0 : return 1;
73 : }
74 0 : thisState->ready = false;
75 0 : return runEnergyPlusAsLibrary(*thisState, argc, argv);
76 : }
77 :
78 0 : void stopSimulation(EnergyPlusState state)
79 : {
80 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
81 0 : thisState->dataGlobal->stopSimulation = true;
82 0 : }
83 :
84 0 : void setConsoleOutputState(EnergyPlusState state, int outputStatus)
85 : {
86 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
87 0 : if (outputStatus == 0) {
88 0 : thisState->dataGlobal->printConsoleOutput = false;
89 : } else {
90 0 : thisState->dataGlobal->printConsoleOutput = true;
91 : }
92 0 : }
93 :
94 0 : void setEnergyPlusRootDirectory(EnergyPlusState state, const char *path)
95 : {
96 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
97 0 : thisState->dataGlobal->installRootOverride = true;
98 0 : thisState->dataStrGlobals->exeDirectoryPath = fs::path(path);
99 0 : }
100 :
101 0 : void issueWarning(EnergyPlusState state, const char *message)
102 : {
103 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
104 0 : EnergyPlus::ShowWarningError(*thisState, message);
105 0 : }
106 0 : void issueSevere(EnergyPlusState state, const char *message)
107 : {
108 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
109 0 : EnergyPlus::ShowSevereError(*thisState, message);
110 0 : }
111 0 : void issueText(EnergyPlusState state, const char *message)
112 : {
113 0 : auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
114 0 : EnergyPlus::ShowContinueError(*thisState, message);
115 0 : }
116 :
117 0 : void registerProgressCallback(EnergyPlusState state, void (*f)(int const))
118 : {
119 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
120 0 : thisState->dataGlobal->progressCallback = f;
121 0 : }
122 :
123 0 : void registerStdOutCallback([[maybe_unused]] EnergyPlusState state, std::function<void(const std::string &)> f)
124 : {
125 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
126 0 : thisState->dataGlobal->messageCallback = f; // NOLINT(performance-unnecessary-value-param)
127 0 : }
128 :
129 0 : void registerStdOutCallback(EnergyPlusState state, void (*f)(const char *))
130 : {
131 0 : const auto stdf = [f](const std::string &message) { f(message.c_str()); };
132 0 : registerStdOutCallback(state, std::function<void(const std::string &)>(stdf));
133 0 : }
134 :
135 0 : void registerExternalHVACManager(EnergyPlusState state, std::function<void(EnergyPlusState)> f)
136 : {
137 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
138 0 : thisState->dataGlobal->externalHVACManager = f; // NOLINT(performance-unnecessary-value-param)
139 0 : }
140 :
141 0 : void registerExternalHVACManager(EnergyPlusState state, void (*f)(EnergyPlusState))
142 : {
143 0 : registerExternalHVACManager(state, std::function<void(EnergyPlusState)>(f));
144 0 : }
145 :
146 0 : void callbackBeginNewEnvironment(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
147 : {
148 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
149 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginNewEnvironment, f);
150 0 : }
151 :
152 0 : void callbackBeginNewEnvironment(EnergyPlusState state, void (*f)(EnergyPlusState))
153 : {
154 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
155 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginNewEnvironment, f);
156 0 : }
157 :
158 0 : void callbackBeginZoneTimestepBeforeSetCurrentWeather(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
159 : {
160 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
161 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepBeforeSetCurrentWeather, f);
162 0 : }
163 :
164 0 : void callbackBeginZoneTimestepBeforeSetCurrentWeather(EnergyPlusState state, void (*f)(EnergyPlusState))
165 : {
166 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
167 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepBeforeSetCurrentWeather, f);
168 0 : }
169 :
170 0 : void callbackAfterNewEnvironmentWarmupComplete(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
171 : {
172 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
173 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginNewEnvironmentAfterWarmUp, f);
174 0 : }
175 :
176 0 : void callbackAfterNewEnvironmentWarmupComplete(EnergyPlusState state, void (*f)(EnergyPlusState))
177 : {
178 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
179 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginNewEnvironmentAfterWarmUp, f);
180 0 : }
181 :
182 0 : void callbackBeginZoneTimeStepBeforeInitHeatBalance(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
183 : {
184 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
185 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepBeforeInitHeatBalance, f);
186 0 : }
187 :
188 0 : void callbackBeginZoneTimeStepBeforeInitHeatBalance(EnergyPlusState state, void (*f)(EnergyPlusState))
189 : {
190 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
191 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepBeforeInitHeatBalance, f);
192 0 : }
193 :
194 0 : void callbackBeginZoneTimeStepAfterInitHeatBalance(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
195 : {
196 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
197 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepAfterInitHeatBalance, f);
198 0 : }
199 :
200 0 : void callbackBeginZoneTimeStepAfterInitHeatBalance(EnergyPlusState state, void (*f)(EnergyPlusState))
201 : {
202 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
203 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginZoneTimestepAfterInitHeatBalance, f);
204 0 : }
205 :
206 0 : void callbackBeginTimeStepBeforePredictor(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
207 : {
208 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
209 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginTimestepBeforePredictor, f);
210 0 : }
211 :
212 0 : void callbackBeginTimeStepBeforePredictor(EnergyPlusState state, void (*f)(EnergyPlusState))
213 : {
214 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
215 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeginTimestepBeforePredictor, f);
216 0 : }
217 :
218 0 : void callbackAfterPredictorBeforeHVACManagers(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
219 : {
220 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
221 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeforeHVACManagers, f);
222 0 : }
223 :
224 0 : void callbackAfterPredictorBeforeHVACManagers(EnergyPlusState state, void (*f)(EnergyPlusState))
225 : {
226 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
227 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::BeforeHVACManagers, f);
228 0 : }
229 :
230 0 : void callbackAfterPredictorAfterHVACManagers(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
231 : {
232 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
233 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::AfterHVACManagers, f);
234 0 : }
235 :
236 0 : void callbackAfterPredictorAfterHVACManagers(EnergyPlusState state, void (*f)(EnergyPlusState))
237 : {
238 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
239 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::AfterHVACManagers, f);
240 0 : }
241 :
242 0 : void callbackInsideSystemIterationLoop(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
243 : {
244 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
245 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::HVACIterationLoop, f);
246 0 : }
247 :
248 0 : void callbackInsideSystemIterationLoop(EnergyPlusState state, void (*f)(EnergyPlusState))
249 : {
250 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
251 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::HVACIterationLoop, f);
252 0 : }
253 :
254 0 : void callbackEndOfZoneTimeStepBeforeZoneReporting(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
255 : {
256 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
257 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndZoneTimestepBeforeZoneReporting, f);
258 0 : }
259 :
260 0 : void callbackEndOfZoneTimeStepBeforeZoneReporting(EnergyPlusState state, void (*f)(EnergyPlusState))
261 : {
262 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
263 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndZoneTimestepBeforeZoneReporting, f);
264 0 : }
265 :
266 0 : void callbackEndOfZoneTimeStepAfterZoneReporting(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
267 : {
268 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
269 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndZoneTimestepAfterZoneReporting, f);
270 0 : }
271 :
272 0 : void callbackEndOfZoneTimeStepAfterZoneReporting(EnergyPlusState state, void (*f)(EnergyPlusState))
273 : {
274 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
275 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndZoneTimestepAfterZoneReporting, f);
276 0 : }
277 :
278 0 : void callbackEndOfSystemTimeStepBeforeHVACReporting(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
279 : {
280 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
281 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndSystemTimestepBeforeHVACReporting, f);
282 0 : }
283 :
284 0 : void callbackEndOfSystemTimeStepBeforeHVACReporting(EnergyPlusState state, void (*f)(EnergyPlusState))
285 : {
286 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
287 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndSystemTimestepBeforeHVACReporting, f);
288 0 : }
289 :
290 0 : void callbackEndOfSystemTimeStepAfterHVACReporting(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
291 : {
292 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
293 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndSystemTimestepAfterHVACReporting, f);
294 0 : }
295 :
296 0 : void callbackEndOfSystemTimeStepAfterHVACReporting(EnergyPlusState state, void (*f)(EnergyPlusState))
297 : {
298 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
299 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::EndSystemTimestepAfterHVACReporting, f);
300 0 : }
301 :
302 0 : void callbackEndOfZoneSizing(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
303 : {
304 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
305 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::ZoneSizing, f);
306 0 : }
307 :
308 0 : void callbackEndOfZoneSizing(EnergyPlusState state, void (*f)(EnergyPlusState))
309 : {
310 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
311 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::ZoneSizing, f);
312 0 : }
313 :
314 0 : void callbackEndOfSystemSizing(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
315 : {
316 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
317 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::SystemSizing, f);
318 0 : }
319 :
320 0 : void callbackEndOfSystemSizing(EnergyPlusState state, void (*f)(EnergyPlusState))
321 : {
322 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
323 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::SystemSizing, f);
324 0 : }
325 :
326 0 : void callbackEndOfAfterComponentGetInput(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
327 : {
328 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
329 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::ComponentGetInput, f);
330 0 : }
331 :
332 0 : void callbackEndOfAfterComponentGetInput(EnergyPlusState state, void (*f)(EnergyPlusState))
333 : {
334 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
335 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::ComponentGetInput, f);
336 0 : }
337 :
338 : // void callbackUserDefinedComponentModel(EnergyPlusState state, std::function<void ()> f) {
339 : // EnergyPlus::PluginManagement::registerNewCallback(EnergyPlus::DataGlobals::emsCallFromUserDefinedComponentModel, f);
340 : //}
341 : //
342 : // void callbackUserDefinedComponentModel(EnergyPlusState state, void (*f)()) {
343 : // callbackUserDefinedComponentModel(std::function<void ()>(f));
344 : //}
345 :
346 0 : void callbackUnitarySystemSizing(EnergyPlusState state, std::function<void(EnergyPlusState)> const &f)
347 : {
348 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
349 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::UnitarySystemSizing, f);
350 0 : }
351 :
352 0 : void callbackUnitarySystemSizing(EnergyPlusState state, void (*f)(EnergyPlusState))
353 : {
354 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
355 0 : EnergyPlus::PluginManagement::registerNewCallback(*thisState, EnergyPlus::EMSManager::EMSCallFrom::UnitarySystemSizing, f);
356 2313 : }
357 :
358 : #pragma clang diagnostic pop
|