Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9202 9222 reset delete state python #9304

Merged
merged 11 commits into from
Mar 4, 2022
Merged
27 changes: 26 additions & 1 deletion src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,22 @@ if(BUILD_TESTING)
add_executable(TestAPI_Runtime_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntime.c)
target_link_libraries(TestAPI_Runtime_C PRIVATE energyplusapi project_options project_fp_options)
# target_compile_options(TestAPI_Runtime_C PRIVATE -Wall -Wextra -Wno-unused)

add_test(NAME "API.TestRuntimeC" COMMAND TestAPI_Runtime_C -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}")

set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/runtimeresetpython")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added 4 tests:

  • stateDelete in both C and python
  • stateReset in both C and python

Without the fix the C ones pass, the python ones are exhibiting the segfault (tested ubuntu 20.04)

Copy link
Member

Choose a reason for hiding this comment

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

I always love TDD.

file(MAKE_DIRECTORY ${TEST_DIR})
add_executable(TestAPI_RuntimeResetState_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntimeResetState.c)
target_link_libraries(TestAPI_RuntimeResetState_C PRIVATE energyplusapi project_options project_fp_options)
# target_compile_options(TestAPI_RuntimeResetPython_C PRIVATE -Wall -Wextra -Wno-unused)
add_test(NAME "API.TestRuntimeResetStateC" COMMAND TestAPI_RuntimeResetState_C -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}")

set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/runtimedeletepython")
file(MAKE_DIRECTORY ${TEST_DIR})
add_executable(TestAPI_RuntimeDeleteState_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntimeDeleteState.c)
target_link_libraries(TestAPI_RuntimeDeleteState_C PRIVATE energyplusapi project_options project_fp_options)
# target_compile_options(TestAPI_RuntimeDeletePython_C PRIVATE -Wall -Wextra -Wno-unused)
add_test(NAME "API.TestRuntimeDeleteStateC" COMMAND TestAPI_RuntimeDeleteState_C -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}")

set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/exchange")
file(MAKE_DIRECTORY ${TEST_DIR})
add_executable(TestAPI_DataTransfer_C ${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestDataTransfer.c)
Expand Down Expand Up @@ -1011,6 +1024,18 @@ if(BUILD_TESTING)
endif()
set_tests_properties("API.TestRuntimePython" PROPERTIES ENVIRONMENT PYTHONPATH=${DIR_WITH_PY_ENERGYPLUS})

# Runtime tests need a folder to be created for output files
set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/runtime_resetstate_python")
file(MAKE_DIRECTORY ${TEST_DIR})
add_test(NAME "API.TestRuntimeResetStatePython" COMMAND "${Python_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntimeResetState.py" -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}")
set_tests_properties("API.TestRuntimeResetStatePython" PROPERTIES ENVIRONMENT PYTHONPATH=${DIR_WITH_PY_ENERGYPLUS})

# Runtime tests need a folder to be created for output files
set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/runtime_deletestate_python")
file(MAKE_DIRECTORY ${TEST_DIR})
add_test(NAME "API.TestRuntimeDeleteStatePython" COMMAND "${Python_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tst/EnergyPlus/api/TestRuntimeDeleteState.py" -d "${TEST_DIR}" -w "${EPW_FILE}" -D "${IDF_FILE}")
set_tests_properties("API.TestRuntimeDeleteStatePython" PROPERTIES ENVIRONMENT PYTHONPATH=${DIR_WITH_PY_ENERGYPLUS})

# Data exchange tests also need an output folder
set(TEST_DIR "${PROJECT_BINARY_DIR}/tst/api/exchange_python")
file(MAKE_DIRECTORY ${TEST_DIR})
Expand Down
6 changes: 4 additions & 2 deletions src/EnergyPlus/PluginManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void PluginManager::setupOutputVariables([[maybe_unused]] EnergyPlusData &state)
#endif
}

PluginManager::PluginManager(EnergyPlusData &state)
PluginManager::PluginManager(EnergyPlusData &state) : eplusRunningViaPythonAPI(state.dataPluginManager->eplusRunningViaPythonAPI)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ctor initializes the boolean from the PluginManagerData, so we can access it in the Dtor

Copy link
Member

Choose a reason for hiding this comment

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

It's all making sense now. Nice.

{
#if LINK_WITH_PYTHON
// this frozen flag tells Python that the package and library have been frozen for embedding, so it shouldn't warn about missing prefixes
Expand Down Expand Up @@ -648,7 +648,9 @@ PluginManager::PluginManager(EnergyPlusData &state)
PluginManager::~PluginManager()
{
#if LINK_WITH_PYTHON
Py_FinalizeEx();
if (!this->eplusRunningViaPythonAPI) {
Py_FinalizeEx();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is really only so we do call Py_FinalizeEx in the PluginManager destructors when not running from a python api: it's to be safe (when running from C API or not from api at all), but I think we would get away with not doing it at all...

Copy link
Member

Choose a reason for hiding this comment

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

I personally think we could go without it entirely as well......but yeah, this is the safer option.

#endif // LINK_WITH_PYTHON
}

Expand Down
5 changes: 5 additions & 0 deletions src/EnergyPlus/PluginManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ namespace PluginManagement {
static int getLocationOfUserDefinedPlugin(EnergyPlusData &state, std::string const &_programName);
static void runSingleUserDefinedPlugin(EnergyPlusData &state, int index);
static bool anyUnexpectedPluginObjects(EnergyPlusData &state);

bool eplusRunningViaPythonAPI = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is on the PluginManager class

Copy link
Member

Choose a reason for hiding this comment

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

Again, it seems this is so that the dtor has access to a copy of the flag.

};

struct PluginTrendVariable
Expand Down Expand Up @@ -243,6 +245,9 @@ struct PluginManagerData : BaseGlobalStruct
bool apiErrorFlag = false;
std::vector<std::string> const objectsToFind = {
"PythonPlugin:OutputVariable", "PythonPlugin:SearchPaths", "PythonPlugin:Instance", "PythonPlugin:Variables", "PythonPlugin:TrendVariable"};

bool eplusRunningViaPythonAPI = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is on PluginManagerData, only so I can forward it to to PluginManager when it is finally instantiated.

When stateNewPython is called, the std::unique_ptr<PluginManagement::PluginManager> pluginManager isn't initialized yet, that's done later by the SimulationManager.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. This isn't code that is commonly touched, so I'm not going to rigor over an extra variable, but I am a bit unsure why you can't just always use the one from state, and not have one on the plugin manager at all. I guess it's because the plugin manager dtor doesn't take a state argument...so there is no state to access, only local members.


void clear_state() override
{
callbacks.clear();
Expand Down
7 changes: 7 additions & 0 deletions src/EnergyPlus/api/state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ EnergyPlusState stateNew()
return reinterpret_cast<EnergyPlusState>(state);
}

EnergyPlusState stateNewPython()
{
auto *state = new EnergyPlus::EnergyPlusData;
state->dataPluginManager->eplusRunningViaPythonAPI = true;
return reinterpret_cast<EnergyPlusState>(state);
}

Comment on lines +62 to +68
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When running from Python, set the boolean to true.

Copy link
Member

Choose a reason for hiding this comment

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

Nice.

void stateReset(EnergyPlusState state)
{
auto *this_state = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
Expand Down
3 changes: 3 additions & 0 deletions src/EnergyPlus/api/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ typedef void *EnergyPlusState;
/// \see stateReset
/// \see stateDelete
ENERGYPLUSLIB_API EnergyPlusState stateNew();

ENERGYPLUSLIB_API EnergyPlusState stateNewPython();

/// \brief Resets the simulation state of EnergyPlus
/// \details A simulation state is created by calling the `stateNew` function. After a simulation is complete, if a
/// second is to be run using the same memory space, the simulation state must be cleared with this function,
Expand Down
6 changes: 3 additions & 3 deletions src/EnergyPlus/api/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class StateManager:

def __init__(self, api: cdll):
self.api = api
self.api.stateNew.argtypes = []
self.api.stateNew.restype = c_void_p
self.api.stateNewPython.argtypes = []
self.api.stateNewPython.restype = c_void_p
self.api.stateReset.argtypes = [c_void_p]
self.api.stateReset.restype = c_void_p
self.api.stateDelete.argtypes = [c_void_p]
Expand All @@ -85,7 +85,7 @@ def new_state(self) -> c_void_p:

:return: A pointer to a new state object in memory
"""
return self.api.stateNew()
return self.api.stateNewPython()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

state_new in python calls stateNewPython... That's unfortunate to add another extern C method, but given the lack of support in C for default argument values...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's not a big deal to me at all. This is hidden within the API anyway, so all good.


def reset_state(self, state: c_void_p) -> None:
"""
Expand Down
87 changes: 87 additions & 0 deletions tst/EnergyPlus/api/TestRuntimeDeleteState.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// EnergyPlus, Copyright (c) 1996-2020, The Board of Trustees of the University of Illinois,
// The Regents of the University of California, through Lawrence Berkeley National Laboratory
// (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
// National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
// contributors. All rights reserved.
//
// NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
// U.S. Government consequently retains certain rights. As such, the U.S. Government has been
// granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
// worldwide license in the Software to reproduce, distribute copies to the public, prepare
// derivative works, and perform publicly and display publicly, and to permit others to do so.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// (1) Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// (2) Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
// the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific prior
// written permission.
//
// (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
// without changes from the version obtained under this License, or (ii) Licensee makes a
// reference solely to the software portion of its product, Licensee must refer to the
// software as "EnergyPlus version X" software, where "X" is the version number Licensee
// obtained under this License and may not use a different name for the software. Except as
// specifically required in this Section (4), Licensee shall not use in a company name, a
// product name, in advertising, publicity, or other promotional activities any name, trade
// name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
// similar designation, without the U.S. Department of Energy's prior written consent.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include <EnergyPlus/api/runtime.h>
#include <EnergyPlus/api/state.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

int numWarnings = 0;
int oneTimeHalfway = 0;

void BeginNewEnvironmentHandler1(EnergyPlusState state)
{
printf("CALLBACK: %s\n", __PRETTY_FUNCTION__);
}

void BeginNewEnvironmentHandler2(EnergyPlusState state)
{
printf("CALLBACK: %s\n", __PRETTY_FUNCTION__);
}

int main(int argc, const char *argv[])
{

EnergyPlusState state = stateNew();
callbackBeginNewEnvironment(state, BeginNewEnvironmentHandler1);
energyplus(state, argc, argv);

// Delete, recreate and run again
stateDelete(state);
state = stateNew();
callbackBeginNewEnvironment(state, BeginNewEnvironmentHandler2);
printf("Running EnergyPlus with Console Output Muted...\n");
setConsoleOutputState(state, 0);
energyplus(state, argc, argv);
printf("...and it is done.\n");

return 0;
}
85 changes: 85 additions & 0 deletions tst/EnergyPlus/api/TestRuntimeDeleteState.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# EnergyPlus, Copyright (c) 1996-2022, The Board of Trustees of the University
# of Illinois, The Regents of the University of California, through Lawrence
# Berkeley National Laboratory (subject to receipt of any required approvals
# from the U.S. Dept. of Energy), Oak Ridge National Laboratory, managed by UT-
# Battelle, Alliance for Sustainable Energy, LLC, and other contributors. All
# rights reserved.
#
# NOTICE: This Software was developed under funding from the U.S. Department of
# Energy and the U.S. Government consequently retains certain rights. As such,
# the U.S. Government has been granted for itself and others acting on its
# behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
# Software to reproduce, distribute copies to the public, prepare derivative
# works, and perform publicly and display publicly, and to permit others to do
# so.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the University of California, Lawrence Berkeley
# National Laboratory, the University of Illinois, U.S. Dept. of Energy nor
# the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in
# stand-alone form without changes from the version obtained under this
# License, or (ii) Licensee makes a reference solely to the software
# portion of its product, Licensee must refer to the software as
# "EnergyPlus version X" software, where "X" is the version number Licensee
# obtained under this License and may not use a different name for the
# software. Except as specifically required in this Section (4), Licensee
# shall not use in a company name, a product name, in advertising,
# publicity, or other promotional activities any name, trade name,
# trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or
# confusingly similar designation, without the U.S. Department of Energy's
# prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import sys
from pyenergyplus.api import EnergyPlusAPI

def progress_handler(progress: int) -> None:
if 49 < progress < 51:
print("HALFWAY THERE!!")
sys.stdout.flush()

api = EnergyPlusAPI()
state = api.state_manager.new_state()
api.runtime.callback_progress(state, progress_handler)
v = api.runtime.run_energyplus(state, sys.argv[1:])
if v != 0:
print("EnergyPlus Failed!")
sys.exit(1)

print("MUTED E+ RUN 1 DONE")

print("DELETE STATE")
api.state_manager.delete_state(state)

print("REBOOT STATE")
state = api.state_manager.new_state()
api.runtime.callback_progress(state, progress_handler)
v = api.runtime.run_energyplus(state, sys.argv[1:])
if v != 0:
print("EnergyPlus Failed!")
sys.exit(1)

print("MUTED E+ RUN 2 DONE")
86 changes: 86 additions & 0 deletions tst/EnergyPlus/api/TestRuntimeResetState.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// EnergyPlus, Copyright (c) 1996-2020, The Board of Trustees of the University of Illinois,
// The Regents of the University of California, through Lawrence Berkeley National Laboratory
// (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
// National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
// contributors. All rights reserved.
//
// NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
// U.S. Government consequently retains certain rights. As such, the U.S. Government has been
// granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
// worldwide license in the Software to reproduce, distribute copies to the public, prepare
// derivative works, and perform publicly and display publicly, and to permit others to do so.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// (1) Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// (2) Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
// the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific prior
// written permission.
//
// (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
// without changes from the version obtained under this License, or (ii) Licensee makes a
// reference solely to the software portion of its product, Licensee must refer to the
// software as "EnergyPlus version X" software, where "X" is the version number Licensee
// obtained under this License and may not use a different name for the software. Except as
// specifically required in this Section (4), Licensee shall not use in a company name, a
// product name, in advertising, publicity, or other promotional activities any name, trade
// name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
// similar designation, without the U.S. Department of Energy's prior written consent.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include <EnergyPlus/api/runtime.h>
#include <EnergyPlus/api/state.h>
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

int numWarnings = 0;
int oneTimeHalfway = 0;

void BeginNewEnvironmentHandler1(EnergyPlusState state)
{
printf("CALLBACK: %s\n", __PRETTY_FUNCTION__);
}

void BeginNewEnvironmentHandler2(EnergyPlusState state)
{
printf("CALLBACK: %s\n", __PRETTY_FUNCTION__);
}

int main(int argc, const char *argv[])
{

EnergyPlusState state = stateNew();
callbackBeginNewEnvironment(state, BeginNewEnvironmentHandler1);
energyplus(state, argc, argv);

// reset and run again
stateReset(state); // note previous callbacks are cleared here
callbackBeginNewEnvironment(state, BeginNewEnvironmentHandler2);
printf("Running EnergyPlus with Console Output Muted...\n");
setConsoleOutputState(state, 0);
energyplus(state, argc, argv);
printf("...and it is done.\n");

return 0;
}
Loading