Skip to content

Commit

Permalink
Merge pull request #10202 from NREL/update-penumbra
Browse files Browse the repository at this point in the history
Update penumbra
  • Loading branch information
Myoldmopar authored Sep 19, 2023
2 parents 681939e + be25d22 commit 92e92d6
Show file tree
Hide file tree
Showing 186 changed files with 9,934 additions and 27,956 deletions.
79 changes: 50 additions & 29 deletions src/EnergyPlus/SolarShading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,10 @@ void GetShadowingInput(EnergyPlusData &state)
state.dataSysVars->shadingMethod = ShadingMethod::PolygonClipping;
state.dataIPShortCut->cAlphaArgs(aNum) = "PolygonClipping";
#else
auto error_callback = [](const int messageType, const std::string &message, void *contextPtr) {
auto *state = reinterpret_cast<EnergyPlusData *>(contextPtr);
if (messageType == Pumbra::MSG_ERR) {
ShowSevereError(*state, message);
} else if (messageType == Pumbra::MSG_WARN) {
ShowWarningError(*state, message);
} else { // if (messageType == MSG_INFO)
ShowMessage(*state, message);
}
};
if (Pumbra::Penumbra::isValidContext()) {
state.dataSolarShading->penumbra = std::make_unique<Pumbra::Penumbra>(error_callback, &state, pixelRes);
if (Penumbra::Penumbra::is_valid_context()) {
std::shared_ptr<EnergyPlusLogger> penumbra_logger = std::make_shared<EnergyPlus::EnergyPlusLogger>();
penumbra_logger->set_message_context(&state);
state.dataSolarShading->penumbra = std::make_unique<Penumbra::Penumbra>(pixelRes, penumbra_logger);
} else {
ShowWarningError(state, "No GPU found (required for PixelCounting)");
ShowContinueError(state, "PolygonClipping will be used instead");
Expand Down Expand Up @@ -5271,7 +5263,7 @@ void DetermineShadowingCombinations(EnergyPlusData &state)

if (!skipSurface) {
// Add surfaces to penumbra...
Pumbra::Polygon poly;
Penumbra::Polygon poly;

if (state.dataSurface->Surface(GRSNR).Reveal > 0.0) {
Real64 R = state.dataSurface->Surface(GRSNR).Reveal;
Expand All @@ -5289,7 +5281,7 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
vPrev = v[i - 1];
}

Pumbra::Polygon rPoly; // Reveal surface
Penumbra::Polygon rPoly; // Reveal surface
rPoly.push_back(v[i].x);
rPoly.push_back(v[i].y);
rPoly.push_back(v[i].z);
Expand All @@ -5306,8 +5298,8 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
rPoly.push_back(vPrev.y);
rPoly.push_back(vPrev.z);

Pumbra::Surface rSurf(rPoly);
state.dataSolarShading->penumbra->addSurface(rSurf);
Penumbra::Surface rSurf(rPoly, fmt::format("{} reveal {}", state.dataSurface->Surface(GRSNR).Name, i));
state.dataSolarShading->penumbra->add_surface(rSurf);
}
} else {
for (auto const &v : state.dataSurface->Surface(GRSNR).Vertex) {
Expand All @@ -5316,7 +5308,7 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
poly.push_back(v.z);
}
}
Pumbra::Surface pSurf(poly);
Penumbra::Surface pSurf(poly, state.dataSurface->Surface(GRSNR).Name);

// Punch holes for subsurfaces
if (state.dataSurface->Surface(GRSNR).BaseSurf == GRSNR) { // Only look for subsurfaces on base surfaces
Expand All @@ -5325,7 +5317,7 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
if (!state.dataSurface->Surface(subSurface).HeatTransSurf) continue; // Skip non heat transfer subsurfaces
if (subSurface == GRSNR) continue; // Surface itself cannot be its own subsurface

Pumbra::Polygon subPoly;
Penumbra::Polygon subPoly;
if (state.dataSurface->Surface(subSurface).Reveal > 0.0) {
Real64 R = state.dataSurface->Surface(subSurface).Reveal;
auto &norm = state.dataSurface->Surface(subSurface).NewellSurfaceNormalVector;
Expand All @@ -5342,10 +5334,10 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
}
}

pSurf.addHole(subPoly);
pSurf.add_hole(subPoly);
}
}
state.dataSurface->SurfPenumbraID(GRSNR) = state.dataSolarShading->penumbra->addSurface(pSurf);
state.dataSurface->SurfPenumbraID(GRSNR) = state.dataSolarShading->penumbra->add_surface(pSurf);
state.dataSolarShading->penumbraIDs.push_back(state.dataSurface->SurfPenumbraID(GRSNR));
}
}
Expand Down Expand Up @@ -5618,8 +5610,8 @@ void DetermineShadowingCombinations(EnergyPlusData &state)
CastingSurface.deallocate();

#ifndef EP_NO_OPENGL
if (state.dataSolarShading->penumbra && state.dataSolarShading->penumbra->getNumSurfaces() > 0) {
state.dataSolarShading->penumbra->setModel();
if (state.dataSolarShading->penumbra && state.dataSolarShading->penumbra->get_number_of_surfaces() > 0) {
state.dataSolarShading->penumbra->set_model();
}
#endif
}
Expand Down Expand Up @@ -5681,8 +5673,8 @@ void SHADOW(EnergyPlusData &state,
if (state.dataSolarShading->penumbra) {
Real64 ElevSun = Constant::PiOvr2 - std::acos(state.dataSolarShading->SUNCOS(3));
Real64 AzimSun = std::atan2(state.dataSolarShading->SUNCOS(1), state.dataSolarShading->SUNCOS(2));
state.dataSolarShading->penumbra->setSunPosition(AzimSun, ElevSun);
state.dataSolarShading->penumbra->submitPSSA();
state.dataSolarShading->penumbra->set_sun_position(AzimSun, ElevSun);
state.dataSolarShading->penumbra->submit_pssa();
}
#endif

Expand Down Expand Up @@ -5718,15 +5710,15 @@ void SHADOW(EnergyPlusData &state,
if (state.dataSolarShading->penumbra && id >= 0) {
// SurfSunlitArea(HTS) = buildingPSSF.at(id) / SurfSunCosTheta(HTS);
state.dataSolarShading->SurfSunlitArea(HTS) =
state.dataSolarShading->penumbra->fetchPSSA(id) / state.dataSolarShading->SurfSunCosTheta(HTS);
state.dataSolarShading->penumbra->retrieve_pssa(id) / state.dataSolarShading->SurfSunCosTheta(HTS);
// SurfSunlitArea(HTS) = penumbra->fetchPSSA(Surface(HTS).PenumbraID)/SurfSunCosTheta(HTS);
for (int SS = 1; SS <= NSBS; ++SS) {
int HTSS = state.dataShadowComb->ShadowComb(HTS).SubSurf(SS);
id = state.dataSurface->SurfPenumbraID(HTSS);
if (id >= 0) {
// SurfSunlitArea(HTSS) = buildingPSSF.at(id) / SurfSunCosTheta(HTSS);
state.dataSolarShading->SurfSunlitArea(HTSS) =
state.dataSolarShading->penumbra->fetchPSSA(id) / state.dataSolarShading->SurfSunCosTheta(HTSS);
state.dataSolarShading->penumbra->retrieve_pssa(id) / state.dataSolarShading->SurfSunCosTheta(HTSS);
// SurfSunlitArea(HTSS) = penumbra->fetchPSSA(Surface(HTSS).PenumbraID)/SurfSunCosTheta(HTSS);
if (state.dataSolarShading->SurfSunlitArea(HTSS) > 0.0) {
if (iHour > 0 && TS > 0)
Expand Down Expand Up @@ -6269,7 +6261,7 @@ void CalcInteriorSolarOverlaps(EnergyPlusData &state,

if (!UseSimpleDistribution) { // Compute overlaps

std::map<unsigned, float> pssas;
std::unordered_map<unsigned, float> pssas;

#ifndef EP_NO_OPENGL
if (state.dataSolarShading->penumbra) {
Expand All @@ -6281,8 +6273,9 @@ void CalcInteriorSolarOverlaps(EnergyPlusData &state,
pbBackSurfaces.push_back(state.dataSurface->SurfPenumbraID(bkSurfNum));
}
}
pssas = state.dataSolarShading->penumbra->calculateInteriorPSSAs({(unsigned)state.dataSurface->SurfPenumbraID(HTSS)}, pbBackSurfaces);
// penumbra->renderInteriorScene({(unsigned)Surface(HTSS).PenumbraID}, pbBackSurfaces);
pssas =
state.dataSolarShading->penumbra->calculate_interior_pssas({(unsigned)state.dataSurface->SurfPenumbraID(HTSS)}, pbBackSurfaces);
// penumbra->render_interior_scene({(unsigned)Surface(HTSS).PenumbraID}, pbBackSurfaces);

JBKS = 0;
for (int bkSurfNum : state.dataShadowComb->ShadowComb(GRSNR).BackSurf) {
Expand Down Expand Up @@ -12925,3 +12918,31 @@ void TimestepInitComplexFenestration(EnergyPlusData &state)
}

} // namespace EnergyPlus::SolarShading

#ifndef EP_NO_OPENGL
namespace EnergyPlus {

void EnergyPlusLogger::error(const std::string_view message)
{
auto *state = reinterpret_cast<EnergyPlusData *>(message_context);
std::string message_string(message);
ShowSevereError(*state, message_string);
}
void EnergyPlusLogger::warning(const std::string_view message)
{
auto *state = reinterpret_cast<EnergyPlusData *>(message_context);
std::string message_string(message);
ShowWarningError(*state, message_string);
}
void EnergyPlusLogger::info(const std::string_view message)
{
auto *state = reinterpret_cast<EnergyPlusData *>(message_context);
std::string message_string(message);
ShowMessage(*state, message_string);
}
void EnergyPlusLogger::debug(const std::string_view message)
{
info(message);
}
} // namespace EnergyPlus
#endif
14 changes: 13 additions & 1 deletion src/EnergyPlus/SolarShading.hh
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ struct SolarShadingData : BaseGlobalStruct
#ifdef EP_NO_OPENGL
bool penumbra = false;
#else
std::unique_ptr<Pumbra::Penumbra> penumbra = nullptr;
std::unique_ptr<Penumbra::Penumbra> penumbra = nullptr;
#endif

bool GetInputFlag = true;
Expand Down Expand Up @@ -642,6 +642,18 @@ struct SolarShadingData : BaseGlobalStruct
{
}
};

#ifndef EP_NO_OPENGL
class EnergyPlusLogger : public Courierr::Courierr
{
public:
void error(const std::string_view message) override;
void warning(const std::string_view message) override;
void info(const std::string_view message) override;
void debug(const std::string_view message) override;
};
#endif

} // namespace EnergyPlus

#endif
20 changes: 20 additions & 0 deletions third_party/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,29 @@ libtk205/.gitmodules

# unused repo directories/files
btwxt/vendor/googletest
penumbra/.github
penumbra/examples
penumbra/test
penumbra/vendor/courierr/.codecov.yml
penumbra/vendor/courierr/.github
penumbra/vendor/courierr/.gitmodules
penumbra/vendor/courierr/README.md
penumbra/vendor/courierr/test
penumbra/vendor/courierr/vendor/fmt
penumbra/vendor/courierr/vendor/googletest
penumbra/vendor/glfw/.github
penumbra/vendor/glfw/.appveyor.yml
penumbra/vendor/glfw/docs
penumbra/vendor/glfw/examples
penumbra/vendor/glfw/tests
penumbra/vendor/googletest
libtk205/.github
libtk205/examples
libtk205/test
libtk205/vendor/btwxt
libtk205/vendor/json

FindGcov.cmake
FindLcov.cmake
Findcodecov.cmake
llvm-cov-wrapper
1 change: 0 additions & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ if(OPENGL_FOUND)
OFF
CACHE BOOL "" FORCE)
add_subdirectory(penumbra)
set_target_properties(awning PROPERTIES FOLDER ThirdParty/Penumbra)
set_target_properties(glfw PROPERTIES FOLDER ThirdParty/Penumbra/GLFW)
set_target_properties(glad PROPERTIES FOLDER ThirdParty/Penumbra)
set_target_properties(penumbra PROPERTIES FOLDER ThirdParty/Penumbra)
Expand Down
2 changes: 1 addition & 1 deletion third_party/penumbra/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ builds/
.DS_Store
cmake-build-*/
.vscode

.vs/
55 changes: 0 additions & 55 deletions third_party/penumbra/.travis.yml

This file was deleted.

36 changes: 26 additions & 10 deletions third_party/penumbra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.7)
project(penumbra)
cmake_policy(SET CMP0091 NEW)
project(penumbra LANGUAGES CXX C)

cmake_policy(SET CMP0079 NEW) # target_link_libraries() allows use with targets in other directories.

# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
Expand All @@ -11,21 +14,31 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

find_package(Git QUIET)

set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL)

set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )

set (CMAKE_MODULE_PATH "${penumbra_SOURCE_DIR}/cmake")
set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

include(compiler-flags)
include(CMakeDependentOption)

cmake_dependent_option( ${PROJECT_NAME}_BUILD_TESTING "Build ${PROJECT_NAME} testing targets" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF )
option( ${PROJECT_NAME}_COVERAGE "Add ${PROJECT_NAME} coverage reports" OFF )
cmake_dependent_option( ${PROJECT_NAME}_BUILD_EXAMPLES "Build ${PROJECT_NAME} examples" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF )
cmake_dependent_option( ${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat warnings in ${PROJECT_NAME} as errors" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF )

option( BUILD_PENUMBRA_TESTING "Build Penumbra testing targets" OFF )
option( PENUMBRA_COVERAGE "Add coverage reports" OFF)
if (NOT ${PROJECT_NAME}_STATIC_LIB)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()

include(compiler-flags)

# Set up testing/coverage
if (BUILD_PENUMBRA_TESTING)
if (${PROJECT_NAME}_BUILD_TESTING)
enable_testing()
if (PENUMBRA_COVERAGE)
if (${PROJECT_NAME}_COVERAGE)
set(ENABLE_COVERAGE ON CACHE BOOL "" FORCE)
find_package(codecov)
endif()
Expand All @@ -36,11 +49,14 @@ endif()
add_subdirectory(vendor)

add_subdirectory(src)
add_subdirectory(examples)

if (BUILD_PENUMBRA_TESTING)
if (${PROJECT_NAME}_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if (${PROJECT_NAME}_BUILD_TESTING)
add_subdirectory(test)
if (PENUMBRA_COVERAGE)
if (${PROJECT_NAME}_COVERAGE)
coverage_evaluate()
endif()
endif()
17 changes: 15 additions & 2 deletions third_party/penumbra/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[![Build Status](https://travis-ci.org/bigladder/penumbra.svg?branch=develop)](https://travis-ci.org/bigladder/penumbra)
[![Build and Test](https://github.com/bigladder/penumbra/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/bigladder/penumbra/actions/workflows/build-and-test.yml)
[![codecov](https://codecov.io/gh/bigladder/penumbra/branch/develop/graph/badge.svg)](https://codecov.io/gh/bigladder/penumbra)

# Penumbra

Penumbra is a free and open source library for GPU accelerated solar shading calculations using [pixel counting](http://www.ibpsa.org/proceedings/BS2011/P_1271.pdf).
Penumbra is a free and open source library for GPU accelerated solar shading calculations using [pixel counting](http://www.ibpsa.org/proceedings/BS2011/P_1271.pdf). It is configured as a cross-platform CMake project.

## Pre-requisites:

1. A C++ compiler (e.g., Clang, GCC, MSVC)
2. CMake

## Building penumbra from source

1. Clone the git repository.
2. Make a directory called `build` inside the top level of your source.
3. Open a console in the `build` directory.
4. Type `cmake ..`.
5. Type `cmake --build . --config Release`.
Loading

1 comment on commit 92e92d6

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2733 of 2737 tests passed, 0 test warnings)

Failures:\n

integration Test Summary

  • Passed: 784
  • Failed: 4

Build Badge Test Badge

Please sign in to comment.