Skip to content

Commit

Permalink
Change signature to allow setting the mute state on or off
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed May 8, 2021
1 parent d70fe7e commit b4206d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/EnergyPlus/api/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ void stopSimulation(EnergyPlusState state)
thisState->dataGlobal->stopSimulation = true;
}

void muteConsoleOutput(EnergyPlusState state)
void setConsoleOutputMuteState(EnergyPlusState state, int muteOutput)
{
auto thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
thisState->dataGlobal->muteConsoleOutput = true;
if (muteOutput == 0) {
thisState->dataGlobal->muteConsoleOutput = false;
} else {
thisState->dataGlobal->muteConsoleOutput = true;
}
}

void issueWarning(EnergyPlusState state, const char *message)
Expand Down
3 changes: 2 additions & 1 deletion src/EnergyPlus/api/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ ENERGYPLUSLIB_API void stopSimulation(EnergyPlusState state);
/// when calling EnergyPlus as a library. This function mutes the standard output messages. Note that these
/// can still be retrieved using callback functionality.
/// \param[in] state An active EnergyPlusState instance created with `stateNew`.
ENERGYPLUSLIB_API void muteConsoleOutput(EnergyPlusState state);
/// \param[in] muteOutput An integer describing whether the console output should be muted or not: nonzero integer for yes, 0 for no.
ENERGYPLUSLIB_API void setConsoleOutputMuteState(EnergyPlusState state, int muteOutput);

/// \brief Asks EnergyPlus to issue a warning message to the error file.
/// \details During an EnergyPlus simulation, if certain conditions arise, it may be useful to alert the user using
Expand Down
12 changes: 8 additions & 4 deletions src/EnergyPlus/api/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def __init__(self, api: cdll):
self.api.issueText.restype = c_void_p
self.api.stopSimulation.argtypes = [c_void_p]
self.api.stopSimulation.restype = c_void_p
self.api.muteConsoleOutput.argtypes = [c_void_p]
self.api.muteConsoleOutput.restype = c_void_p
self.api.setConsoleOutputMuteState.argtypes = [c_void_p, c_int]
self.api.setConsoleOutputMuteState.restype = c_void_p
self.py_progress_callback_type = CFUNCTYPE(c_void_p, c_int)
self.api.registerProgressCallback.argtypes = [c_void_p, self.py_progress_callback_type]
self.api.registerProgressCallback.restype = c_void_p
Expand Down Expand Up @@ -191,13 +191,17 @@ def run_energyplus(self, state: c_void_p, command_line_args: List[Union[str, byt
# def stop_simulation(self, state: c_void_p) -> None:
# pass

def mute_console_output(self, state) -> None:
def set_console_output_mute_state(self, state, mute_output: bool) -> None:
"""
Mutes all console output (stdout and stderr) when calling EnergyPlus as a library.
:param state: An active EnergyPlus "state" that is returned from a call to `api.state_manager.new_state()`.
:param mute_output: A boolean flag for whether we should mute console output
:return: Nothing
"""
self.api.muteConsoleOutput(state)
if mute_output:
self.api.setConsoleOutputMuteState(state, 1)
else:
self.api.setConsoleOutputMuteState(state, 0)

def issue_warning(self, state: c_void_p, message: Union[str, bytes]) -> None:
"""
Expand Down
8 changes: 8 additions & 0 deletions tst/EnergyPlus/api/TestRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ int main(int argc, const char *argv[])
numWarnings = 0;
}
oneTimeHalfway = 0;
// reset and run again
stateReset(state); // note previous callbacks are cleared here
callbackAfterNewEnvironmentWarmupComplete(state, newEnvrnHandler);
registerStdOutCallback(state, stdOutHandler);
Expand All @@ -190,8 +191,15 @@ int main(int argc, const char *argv[])
printf("There were %d warnings!\n", numWarnings);
numWarnings = 0;
}
// reset and run a test with an external hvac manager
stateReset(state);
registerExternalHVACManager(state, externalHVAC);
energyplus(state, argc, argv);
// create a new state and run it with console output muted
printf("Running EnergyPlus with Console Output Muted...\n");
EnergyPlusState state2 = stateNew();
setConsoleOutputMuteState(state2, 1);
energyplus(state2, argc, argv);
printf("...and it is done.");
return 0;
}
2 changes: 1 addition & 1 deletion tst/EnergyPlus/api/TestRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def error_handler(severity: int, message: bytes) -> None:
state2 = api.state_manager.new_state()
api.runtime.clear_callbacks()
api.functional.clear_callbacks()
api.runtime.mute_console_output(state2)
api.runtime.set_console_output_mute_state(state2, True)
print("RUNNING MUTED ENERGYPLUS...")
api.runtime.run_energyplus(state2, sys.argv[1:])
print("MUTED E+ RUN DONE")

5 comments on commit b4206d6

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

AddAPISupportToQuietStdOut (Myoldmopar) - Win64-Windows-10-VisualStudio-16: Build Failed

Failures:\n

API Test Summary

  • Failed: 1
  • notrun: 3

integration Test Summary

  • Passed: 2
  • Failed: 722

Build Badge Test Badge

@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.

AddAPISupportToQuietStdOut (Myoldmopar) - x86_64-MacOS-10.15-clang-11.0.0: OK (3082 of 3082 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

AddAPISupportToQuietStdOut (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1636 of 1636 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

AddAPISupportToQuietStdOut (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3122 of 3122 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

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

AddAPISupportToQuietStdOut (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (726 of 726 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.