Skip to content

Commit

Permalink
Fix #8484 - Flush all files when Running via API before finish
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Mar 1, 2021
1 parent 6572493 commit 71793c6
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/EnergyPlus/IOFiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,111 @@ IOFiles *&IOFiles::getSingletonInternal()
return singleton;
}

void IOFiles::flushAll() {

audit.flush();
eio.flush();
eso.flush();
zsz.flush();
ssz.flush();
map.flush();
mtr.flush();
bnd.flush();
rdd.flush();
mdd.flush();
debug.flush();
dfs.flush();
mtd.flush();
edd.flush();
shade.flush();
csv.flush();

if (err_stream) {
err_stream->flush();
}
if (json.json_stream) {
json.json_stream->flush();
}
if (json.json_TSstream_Zone) {
json.json_TSstream_Zone->flush();
}
if (json.json_TSstream_HVAC) {
json.json_TSstream_HVAC->flush();
}
if (json.json_TSstream) {
json.json_TSstream->flush();
}
if (json.json_HRstream) {
json.json_HRstream->flush();
}
if (json.json_MNstream) {
json.json_MNstream->flush();
}
if (json.json_DYstream) {
json.json_DYstream->flush();
}
if (json.json_SMstream) {
json.json_SMstream->flush();
}
if (json.json_YRstream) {
json.json_YRstream->flush();
}
if (json.cbor_stream) {
json.cbor_stream->flush();
}
if (json.cbor_TSstream_Zone) {
json.cbor_TSstream_Zone->flush();
}
if (json.cbor_TSstream_HVAC) {
json.cbor_TSstream_HVAC->flush();
}
if (json.cbor_TSstream) {
json.cbor_TSstream->flush();
}
if (json.cbor_HRstream) {
json.cbor_HRstream->flush();
}
if (json.cbor_MNstream) {
json.cbor_MNstream->flush();
}
if (json.cbor_DYstream) {
json.cbor_DYstream->flush();
}
if (json.cbor_SMstream) {
json.cbor_SMstream->flush();
}
if (json.cbor_YRstream) {
json.cbor_YRstream->flush();
}
if (json.msgpack_stream) {
json.msgpack_stream->flush();
}
if (json.msgpack_TSstream_Zone) {
json.msgpack_TSstream_Zone->flush();
}
if (json.msgpack_TSstream_HVAC) {
json.msgpack_TSstream_HVAC->flush();
}
if (json.msgpack_TSstream) {
json.msgpack_TSstream->flush();
}
if (json.msgpack_HRstream) {
json.msgpack_HRstream->flush();
}
if (json.msgpack_MNstream) {
json.msgpack_MNstream->flush();
}
if (json.msgpack_DYstream) {
json.msgpack_DYstream->flush();
}
if (json.msgpack_SMstream) {
json.msgpack_SMstream->flush();
}
if (json.msgpack_YRstream) {
json.msgpack_YRstream->flush();
}
}

using arg_formatter = fmt::arg_formatter<fmt::buffer_range<char>>;

class custom_arg_formatter : public arg_formatter
Expand Down
2 changes: 2 additions & 0 deletions src/EnergyPlus/IOFiles.hh
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public:

JsonOutputStreams json; // Internal streams used for json outputs

void flushAll(); // For RunningEnergyPlusViaAPI only

private:
static IOFiles *&getSingletonInternal();
};
Expand Down
10 changes: 10 additions & 0 deletions src/EnergyPlus/UtilityRoutines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ namespace UtilityRoutines {
// Close the socket used by ExternalInterface. This call also sends the flag "-1" to the ExternalInterface,
// indicating that E+ terminated with an error.
if (NumExternalInterfaces > 0) CloseSocket(-1);

if (state.dataGlobal->eplusRunningViaAPI) {
state.files.flushAll();
}

return EXIT_FAILURE;
}

Expand Down Expand Up @@ -890,6 +895,11 @@ namespace UtilityRoutines {
// Close the ExternalInterface socket. This call also sends the flag "1" to the ExternalInterface,
// indicating that E+ finished its simulation
if ((NumExternalInterfaces > 0) && haveExternalInterfaceBCVTB) CloseSocket(1);

if (state.dataGlobal->eplusRunningViaAPI) {
state.files.flushAll();
}

return EXIT_SUCCESS;
}

Expand Down

1 comment on commit 71793c6

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8484_Python_FlushOutputFiles (jmarrec) - x86_64-MacOS-10.15-clang-11.0.0: Tests Failed (0 of 0 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.