From 57d1f0801c5841749f85c9e8f04c503f560dcc3d Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Thu, 18 Feb 2021 16:07:34 +0100 Subject: [PATCH] Fix #8484 - Flush all files when Running via API before finish --- src/EnergyPlus/IOFiles.cc | 105 ++++++++++++++++++++++++++++++ src/EnergyPlus/IOFiles.hh | 2 + src/EnergyPlus/UtilityRoutines.cc | 10 +++ 3 files changed, 117 insertions(+) diff --git a/src/EnergyPlus/IOFiles.cc b/src/EnergyPlus/IOFiles.cc index 4e3fbd068bf..fd3d313dea9 100644 --- a/src/EnergyPlus/IOFiles.cc +++ b/src/EnergyPlus/IOFiles.cc @@ -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>; class custom_arg_formatter : public arg_formatter diff --git a/src/EnergyPlus/IOFiles.hh b/src/EnergyPlus/IOFiles.hh index 0c6ec83fd3d..3c26eedcc56 100644 --- a/src/EnergyPlus/IOFiles.hh +++ b/src/EnergyPlus/IOFiles.hh @@ -356,6 +356,8 @@ public: JsonOutputStreams json; // Internal streams used for json outputs + void flushAll(); // For RunningEnergyPlusViaAPI only + private: static IOFiles *&getSingletonInternal(); }; diff --git a/src/EnergyPlus/UtilityRoutines.cc b/src/EnergyPlus/UtilityRoutines.cc index b2f760fdee1..bb18a6e99be 100644 --- a/src/EnergyPlus/UtilityRoutines.cc +++ b/src/EnergyPlus/UtilityRoutines.cc @@ -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; } @@ -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; }