From 6fd2353c367ac4b8ace6cc4d5ad1d0ad61ae4f1c Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Mon, 15 Aug 2022 09:59:00 -0700 Subject: [PATCH 1/9] Using make_unique from standard template library now --- src/Common/include/WCECommon.hpp | 1 - src/Common/src/IntegratorStrategy.cpp | 3 +-- src/Common/src/Series.cpp | 1 - src/Common/src/wceunique.hpp | 18 ------------------ .../MultilayerInterreflectances_3.unit.cpp | 2 +- .../MultilayerInterreflectances_4.unit.cpp | 2 +- .../units/BSDFThetaLimitsFullBasis.unit.cpp | 2 +- .../units/BSDFThetaLimitsHalfBasis.unit.cpp | 2 +- .../units/BSDFThetaLimitsQuarterBasis.unit.cpp | 2 +- .../tst/units/NFRC_5439_SB70XL_Colors.unit.cpp | 2 +- src/Tarcog/src/NusseltNumber.cpp | 10 +++++----- 11 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 src/Common/src/wceunique.hpp diff --git a/src/Common/include/WCECommon.hpp b/src/Common/include/WCECommon.hpp index bf1114a4..0ec19bd0 100644 --- a/src/Common/include/WCECommon.hpp +++ b/src/Common/include/WCECommon.hpp @@ -18,7 +18,6 @@ #include "../src/PolynomialFit.hpp" #include "../src/Polynom.hpp" #include "../src/mmap.hpp" -#include "../src/wceunique.hpp" #include "../src/WavelengthSpectrum.hpp" #include "../src/Table2D.hpp" #include "../src/Table2DInterpolators.hpp" diff --git a/src/Common/src/IntegratorStrategy.cpp b/src/Common/src/IntegratorStrategy.cpp index fdb1cfa1..fae5f89b 100644 --- a/src/Common/src/IntegratorStrategy.cpp +++ b/src/Common/src/IntegratorStrategy.cpp @@ -1,6 +1,5 @@ #include "IntegratorStrategy.hpp" #include "Series.hpp" -#include "wceunique.hpp" #include namespace FenestrationCommon @@ -156,7 +155,7 @@ namespace FenestrationCommon aStrategy = std::make_unique(); break; case IntegrationType::PreWeighted: - aStrategy = wce::make_unique(); + aStrategy = std::make_unique(); break; default: assert("Irregular call of integration strategy."); diff --git a/src/Common/src/Series.cpp b/src/Common/src/Series.cpp index 5375d597..2dd25fa3 100644 --- a/src/Common/src/Series.cpp +++ b/src/Common/src/Series.cpp @@ -2,7 +2,6 @@ #include #include -#include "wceunique.hpp" #include "Series.hpp" #include "IntegratorStrategy.hpp" diff --git a/src/Common/src/wceunique.hpp b/src/Common/src/wceunique.hpp deleted file mode 100644 index 9207602b..00000000 --- a/src/Common/src/wceunique.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef WINDOWS_CALCENGINE_WCEUNIQUE_H -#define WINDOWS_CALCENGINE_WCEUNIQUE_H - -#include - -// C++ 11 does not support make_unique. Use this header file to have make_unique functionality. -// When using later C++ standards, remove this header file - -namespace wce -{ - template - std::unique_ptr make_unique(Args &&... args) - { - return std::unique_ptr(new T(std::forward(args)...)); - } -} // namespace wce - -#endif // WINDOWS_CALCENGINE_WCEUNIQUE_H \ No newline at end of file diff --git a/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_3.unit.cpp b/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_3.unit.cpp index c0942dfa..1ae54ad2 100644 --- a/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_3.unit.cpp +++ b/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_3.unit.cpp @@ -33,7 +33,7 @@ class TestMultilayerInterreflectances_3 : public testing::Test aBack = CScatteringSurface(0.13, 0.25, 0.38, 0.19, 0.64, 0.22); CScatteringLayer aLayer3(aFront, aBack); - m_Interref = wce::make_unique(aLayer1); + m_Interref = std::make_unique(aLayer1); m_Interref->addLayer(aLayer2, Side::Back); m_Interref->addLayer(aLayer3, Side::Back); } diff --git a/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_4.unit.cpp b/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_4.unit.cpp index 9cb6ca0f..9e02edb9 100644 --- a/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_4.unit.cpp +++ b/src/MultiLayerOptics/tst/units/MultilayerInterreflectances_4.unit.cpp @@ -33,7 +33,7 @@ class TestMultilayerInterreflectances_4 : public testing::Test aBack = CScatteringSurface(0.13, 0.25, 0.38, 0.19, 0.64, 0.22); CScatteringLayer aLayer3(aFront, aBack); - m_Interref = wce::make_unique(aLayer3); + m_Interref = std::make_unique(aLayer3); m_Interref->addLayer(aLayer2, Side::Front); m_Interref->addLayer(aLayer1, Side::Front); } diff --git a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsFullBasis.unit.cpp b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsFullBasis.unit.cpp index a0ee0272..5e96d4af 100644 --- a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsFullBasis.unit.cpp +++ b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsFullBasis.unit.cpp @@ -17,7 +17,7 @@ class TestBSDFThetaLimtisFullBasis : public testing::Test virtual void SetUp() { std::vector thetaAngles = {0, 10, 20, 30, 40, 50, 60, 70, 82.5}; - m_Thetas = wce::make_unique(thetaAngles); + m_Thetas = std::make_unique(thetaAngles); } public: diff --git a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsHalfBasis.unit.cpp b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsHalfBasis.unit.cpp index eeac69b6..839032b3 100644 --- a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsHalfBasis.unit.cpp +++ b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsHalfBasis.unit.cpp @@ -17,7 +17,7 @@ class TestBSDFThetaLimtisHalfBasis : public testing::Test virtual void SetUp() { std::vector thetaAngles{0, 13, 26, 39, 52, 65, 80.75}; - m_Thetas = wce::make_unique(thetaAngles); + m_Thetas = std::make_unique(thetaAngles); } public: diff --git a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsQuarterBasis.unit.cpp b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsQuarterBasis.unit.cpp index ccceb894..362dbd19 100644 --- a/src/SingleLayerOptics/tst/units/BSDFThetaLimitsQuarterBasis.unit.cpp +++ b/src/SingleLayerOptics/tst/units/BSDFThetaLimitsQuarterBasis.unit.cpp @@ -17,7 +17,7 @@ class TestBSDFThetaLimtisQuarterBasis : public testing::Test virtual void SetUp() { std::vector thetaAngles{0, 18, 36, 54, 76.5}; - m_Thetas = wce::make_unique(thetaAngles); + m_Thetas = std::make_unique(thetaAngles); } public: diff --git a/src/SingleLayerOptics/tst/units/NFRC_5439_SB70XL_Colors.unit.cpp b/src/SingleLayerOptics/tst/units/NFRC_5439_SB70XL_Colors.unit.cpp index 5dc150f2..da326cdb 100644 --- a/src/SingleLayerOptics/tst/units/NFRC_5439_SB70XL_Colors.unit.cpp +++ b/src/SingleLayerOptics/tst/units/NFRC_5439_SB70XL_Colors.unit.cpp @@ -322,7 +322,7 @@ class TestNFRC_5439_SB70XL_Colors_Scattering : public testing::Test thickness, FenestrationCommon::MaterialType::Monolithic); - auto layer = wce::make_unique( + auto layer = std::make_unique( SingleLayerOptics::CScatteringLayer::createSpecularLayer(aMaterial)); CSeries solarRadiation{loadSolarRadiationFile()}; layer->setSourceData(solarRadiation); diff --git a/src/Tarcog/src/NusseltNumber.cpp b/src/Tarcog/src/NusseltNumber.cpp index 307c1f26..175184a5 100644 --- a/src/Tarcog/src/NusseltNumber.cpp +++ b/src/Tarcog/src/NusseltNumber.cpp @@ -114,23 +114,23 @@ namespace Tarcog if(t_Tilt >= 0 && t_Tilt < 60) { - nusseltNumber = wce::make_unique(); + nusseltNumber = std::make_unique(); } else if(t_Tilt == 60) { - nusseltNumber = wce::make_unique(); + nusseltNumber = std::make_unique(); } else if(t_Tilt > 60 && t_Tilt < 90) { - nusseltNumber = wce::make_unique(); + nusseltNumber = std::make_unique(); } else if(t_Tilt == 90) { - nusseltNumber = wce::make_unique(); + nusseltNumber = std::make_unique(); } else if(t_Tilt > 90 && t_Tilt <= 180) { - nusseltNumber = wce::make_unique(); + nusseltNumber = std::make_unique(); } else { From 63719f0c4f7f5e0a6d81afcf98a4a22e10fdd734 Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Mon, 15 Aug 2022 12:19:32 -0700 Subject: [PATCH 2/9] Chunk routine for splitting numbers into different threads. --- src/Common/include/WCECommon.hpp | 1 + src/Common/src/Utility.cpp | 27 ++++++++ src/Common/src/Utility.hpp | 16 +++++ src/Common/tst/units/ChunkIt.unit.cpp | 95 +++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/Common/src/Utility.cpp create mode 100644 src/Common/src/Utility.hpp create mode 100644 src/Common/tst/units/ChunkIt.unit.cpp diff --git a/src/Common/include/WCECommon.hpp b/src/Common/include/WCECommon.hpp index 0ec19bd0..a27409b7 100644 --- a/src/Common/include/WCECommon.hpp +++ b/src/Common/include/WCECommon.hpp @@ -21,3 +21,4 @@ #include "../src/WavelengthSpectrum.hpp" #include "../src/Table2D.hpp" #include "../src/Table2DInterpolators.hpp" +#include "../src/Utility.hpp" diff --git a/src/Common/src/Utility.cpp b/src/Common/src/Utility.cpp new file mode 100644 index 00000000..ed350e20 --- /dev/null +++ b/src/Common/src/Utility.cpp @@ -0,0 +1,27 @@ +#include "Utility.hpp" + +namespace FenestrationCommon +{ + IndexRange::IndexRange(size_t start, size_t end) : start(start), end(end) + {} + + std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits) + { + size_t numOfLoops{numberOfSplits < (end - start) + ? static_cast((end - start) / numberOfSplits) + 1u + : end - start + 1u}; + size_t stepSize{numberOfSplits < (end - start) ? numOfLoops - 1u : 0u}; + + std::vector result; + result.reserve(numOfLoops); + + size_t currentStart{start}; + for(size_t i = 0u; i < numOfLoops; ++i) + { + size_t currentEnd{currentStart + stepSize}; + result.emplace_back(currentStart, currentEnd); + currentStart = currentEnd + 1u; + } + return result; + } +} // namespace FenestrationCommon \ No newline at end of file diff --git a/src/Common/src/Utility.hpp b/src/Common/src/Utility.hpp new file mode 100644 index 00000000..0c56e61b --- /dev/null +++ b/src/Common/src/Utility.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace FenestrationCommon +{ + struct IndexRange + { + IndexRange(size_t start, size_t end); + size_t start{0u}; + size_t end{0u}; + }; + + //! Makes division for indexes that are defined from start to end for the purpose of multithreading. + std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits); +} \ No newline at end of file diff --git a/src/Common/tst/units/ChunkIt.unit.cpp b/src/Common/tst/units/ChunkIt.unit.cpp new file mode 100644 index 00000000..2afd829e --- /dev/null +++ b/src/Common/tst/units/ChunkIt.unit.cpp @@ -0,0 +1,95 @@ +#include +#include + +#include "WCECommon.hpp" + +using namespace FenestrationCommon; + +class TestChunkIt : public testing::Test +{}; + +TEST_F(TestChunkIt, Chunk1) +{ + constexpr size_t start{0u}; + constexpr size_t end{3u}; + constexpr size_t numberOfSplits{2u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{{0u, 1u}, {2u, 3u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} + +TEST_F(TestChunkIt, Chunk2) +{ + constexpr size_t start{0u}; + constexpr size_t end{3u}; + constexpr size_t numberOfSplits{12u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{ + {0u, 0u}, {1u, 1u}, {2u, 2u}, {3u, 3u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} + +TEST_F(TestChunkIt, Chunk3) +{ + constexpr size_t start{1u}; + constexpr size_t end{4u}; + constexpr size_t numberOfSplits{2u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{{1u, 2u}, {3u, 4u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} + +TEST_F(TestChunkIt, Chunk4) +{ + constexpr size_t start{3u}; + constexpr size_t end{5u}; + constexpr size_t numberOfSplits{12u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{{3u, 3u}, {4u, 4u}, {5u, 5u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} + +TEST_F(TestChunkIt, Chunk5) +{ + constexpr size_t start{5u}; + constexpr size_t end{5u}; + constexpr size_t numberOfSplits{12u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{{5u, 5u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} \ No newline at end of file From 6f97dcdbe5e5091235d4d92216ed5f871fd38f2e Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Mon, 15 Aug 2022 13:47:41 -0700 Subject: [PATCH 3/9] std::thread used instead of parallel algorithms. --- CMakeLists.txt | 2 + cmake/WCECompilerFlags.cmake | 1 - src/Common/src/Utility.cpp | 20 ++-- src/Common/src/Utility.hpp | 2 +- src/Common/tst/units/ChunkIt.unit.cpp | 38 +++++++- .../src/EquivalentBSDFLayer.cpp | 91 +++++++++++-------- src/SpectralAveraging/src/SpectralSample.cpp | 19 ++-- 7 files changed, 108 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a88fbf8b..284175a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ set(target_name ${PROJECT_NAME}) set (CMAKE_CXX_STANDARD 17) +add_definitions(-DMULTITHREADING) + include( cmake/WCEProjectMacros.cmake ) include( cmake/WCEInternalUtils.cmake ) include( cmake/WCECompilerFlags.cmake ) diff --git a/cmake/WCECompilerFlags.cmake b/cmake/WCECompilerFlags.cmake index 1bbe4145..dbc55f1e 100644 --- a/cmake/WCECompilerFlags.cmake +++ b/cmake/WCECompilerFlags.cmake @@ -39,7 +39,6 @@ ENDIF () if (MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11)) # VS 2017 : Disable warnings from from gtest code, using deprecated code related to TR1 add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) - add_definitions(-DSTL_MULTITHREADING) endif() macro( warning_level_update_wce ) diff --git a/src/Common/src/Utility.cpp b/src/Common/src/Utility.cpp index ed350e20..8f4b6673 100644 --- a/src/Common/src/Utility.cpp +++ b/src/Common/src/Utility.cpp @@ -2,26 +2,24 @@ namespace FenestrationCommon { - IndexRange::IndexRange(size_t start, size_t end) : start(start), end(end) + IndexRange::IndexRange(size_t startIndex, size_t endIndex) : start(startIndex), end(endIndex) {} std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits) { - size_t numOfLoops{numberOfSplits < (end - start) - ? static_cast((end - start) / numberOfSplits) + 1u - : end - start + 1u}; - size_t stepSize{numberOfSplits < (end - start) ? numOfLoops - 1u : 0u}; + size_t stepSize{numberOfSplits < (end - start) ? static_cast((end - start) / numberOfSplits): 0u}; std::vector result; - result.reserve(numOfLoops); size_t currentStart{start}; - for(size_t i = 0u; i < numOfLoops; ++i) - { - size_t currentEnd{currentStart + stepSize}; + size_t currentEnd{currentStart}; + + do { + currentEnd = currentStart + stepSize < end ? currentStart + stepSize + 1u : end + 1u; result.emplace_back(currentStart, currentEnd); - currentStart = currentEnd + 1u; - } + currentStart = currentEnd; + } while(currentEnd < end + 1u); + return result; } } // namespace FenestrationCommon \ No newline at end of file diff --git a/src/Common/src/Utility.hpp b/src/Common/src/Utility.hpp index 0c56e61b..20fd7cea 100644 --- a/src/Common/src/Utility.hpp +++ b/src/Common/src/Utility.hpp @@ -6,7 +6,7 @@ namespace FenestrationCommon { struct IndexRange { - IndexRange(size_t start, size_t end); + IndexRange(size_t startIndex, size_t endIndex); size_t start{0u}; size_t end{0u}; }; diff --git a/src/Common/tst/units/ChunkIt.unit.cpp b/src/Common/tst/units/ChunkIt.unit.cpp index 2afd829e..ab0e368e 100644 --- a/src/Common/tst/units/ChunkIt.unit.cpp +++ b/src/Common/tst/units/ChunkIt.unit.cpp @@ -15,7 +15,7 @@ TEST_F(TestChunkIt, Chunk1) constexpr size_t numberOfSplits{2u}; const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; - const std::vector correct{{0u, 1u}, {2u, 3u}}; + const std::vector correct{{0u, 2u}, {2u, 4u}}; EXPECT_EQ(result.size(), correct.size()); for(size_t i = 0u; i < correct.size(); ++i) @@ -33,7 +33,7 @@ TEST_F(TestChunkIt, Chunk2) const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; const std::vector correct{ - {0u, 0u}, {1u, 1u}, {2u, 2u}, {3u, 3u}}; + {0u, 1u}, {1u, 2u}, {2u, 3u}, {3u, 4u}}; EXPECT_EQ(result.size(), correct.size()); for(size_t i = 0u; i < correct.size(); ++i) @@ -50,7 +50,7 @@ TEST_F(TestChunkIt, Chunk3) constexpr size_t numberOfSplits{2u}; const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; - const std::vector correct{{1u, 2u}, {3u, 4u}}; + const std::vector correct{{1u, 3u}, {3u, 5u}}; EXPECT_EQ(result.size(), correct.size()); for(size_t i = 0u; i < correct.size(); ++i) @@ -67,7 +67,7 @@ TEST_F(TestChunkIt, Chunk4) constexpr size_t numberOfSplits{12u}; const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; - const std::vector correct{{3u, 3u}, {4u, 4u}, {5u, 5u}}; + const std::vector correct{{3u, 4u}, {4u, 5u}, {5u, 6u}}; EXPECT_EQ(result.size(), correct.size()); for(size_t i = 0u; i < correct.size(); ++i) @@ -84,7 +84,35 @@ TEST_F(TestChunkIt, Chunk5) constexpr size_t numberOfSplits{12u}; const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; - const std::vector correct{{5u, 5u}}; + const std::vector correct{{5u, 6u}}; + + EXPECT_EQ(result.size(), correct.size()); + for(size_t i = 0u; i < correct.size(); ++i) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} + +TEST_F(TestChunkIt, Chunk6) +{ + constexpr size_t start{0u}; + constexpr size_t end{110u}; + constexpr size_t numberOfSplits{12u}; + + const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; + const std::vector correct{{0u, 10u}, + {10u, 20u}, + {20u, 30u}, + {30u, 40u}, + {40u, 50u}, + {50u, 60u}, + {60u, 70u}, + {70u, 80u}, + {80u, 90u}, + {90u, 100u}, + {100u, 110u}, + {110u, 111u}}; EXPECT_EQ(result.size(), correct.size()); for(size_t i = 0u; i < correct.size(); ++i) diff --git a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp index c67c2272..61e4fb01 100644 --- a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp +++ b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp @@ -5,7 +5,7 @@ #ifdef STL_MULTITHREADING # include #else -# include +# include #endif #include "EquivalentBSDFLayer.hpp" @@ -147,44 +147,57 @@ namespace MultiLayerOptics std::mutex jscMutex; std::mutex totMutex; -#ifdef STL_MULTITHREADING - std::for_each(std::execution::par, -#else - std::for_each( + auto numberOfThreads{1u}; +#if MULTITHREADING + numberOfThreads = std::thread::hardware_concurrency(); + //numberOfThreads = 1u; #endif - wavelengthIndexes.begin(), - wavelengthIndexes.end(), - [&](const size_t & index) { - // for(size_t i = 0u; i < m_CombinedLayerWavelengths.size(); ++i) - auto layer{getEquivalentLayerAtWavelength(index)}; - for(auto aSide : EnumSide()) - { - const auto numberOfLayers{m_Layer.size()}; - for(size_t layerNumber = 0; layerNumber < numberOfLayers; - ++layerNumber) - { - auto totA{layer.getLayerAbsorptances(layerNumber + 1, aSide)}; - - std::lock_guard lock_abs(absorptanceMutex); - m_TotA.at(aSide).setPropertiesAtIndex(index, - layerNumber, m_CombinedLayerWavelengths[index], totA); - - auto totJSC{layer.getLayerJSC(layerNumber + 1, aSide)}; - std::lock_guard lock_jsc(jscMutex); - m_TotJSC.at(aSide).setPropertiesAtIndex(index, - layerNumber, m_CombinedLayerWavelengths[index], totJSC); - } - for(auto aProperty : EnumPropertySimple()) - { - auto tot{layer.getProperty(aSide, aProperty)}; - - std::lock_guard lock_tot(totMutex); - m_Tot.at({aSide, aProperty}) - .setPropertiesAtIndex(index, m_CombinedLayerWavelengths[index], tot); - } - } - }); - }; + + const auto chunks{FenestrationCommon::chunkIt( + 0u, m_CombinedLayerWavelengths.size() - 1u, numberOfThreads)}; + + std::vector workers; + + for(const auto & chunk : chunks) + { + workers.emplace_back([&]() { + for(size_t index = chunk.start; index < chunk.end; ++index) + { + auto layer{getEquivalentLayerAtWavelength(index)}; + for(auto aSide : EnumSide()) + { + const auto numberOfLayers{m_Layer.size()}; + for(size_t layerNumber = 0; layerNumber < numberOfLayers; ++layerNumber) + { + auto totA{layer.getLayerAbsorptances(layerNumber + 1, aSide)}; + + std::lock_guard lock_abs(absorptanceMutex); + m_TotA.at(aSide).setPropertiesAtIndex( + index, layerNumber, m_CombinedLayerWavelengths[index], totA); + + auto totJSC{layer.getLayerJSC(layerNumber + 1, aSide)}; + std::lock_guard lock_jsc(jscMutex); + m_TotJSC.at(aSide).setPropertiesAtIndex( + index, layerNumber, m_CombinedLayerWavelengths[index], totJSC); + } + for(auto aProperty : EnumPropertySimple()) + { + auto tot{layer.getProperty(aSide, aProperty)}; + + std::lock_guard lock_tot(totMutex); + m_Tot.at({aSide, aProperty}) + .setPropertiesAtIndex(index, m_CombinedLayerWavelengths[index], tot); + } + } + } + }); + } + + for(auto & worker : workers) + { + worker.join(); + } + } CEquivalentBSDFLayerSingleBand CEquivalentBSDFLayer::getEquivalentLayerAtWavelength(size_t wavelengthIndex) const @@ -192,7 +205,7 @@ namespace MultiLayerOptics auto jscPrimeFront{m_Layer[0]->jscPrime(Side::Front, m_CombinedLayerWavelengths)}; auto jscPrimeBack{m_Layer[0]->jscPrime(Side::Back, m_CombinedLayerWavelengths)}; auto layerWLResults{m_Layer[0]->getResultsAtWavelength(wavelengthIndex)}; - + CEquivalentBSDFLayerSingleBand result{ layerWLResults, jscPrimeFront[wavelengthIndex], jscPrimeBack[wavelengthIndex]}; diff --git a/src/SpectralAveraging/src/SpectralSample.cpp b/src/SpectralAveraging/src/SpectralSample.cpp index 1b4279b1..f9898a49 100644 --- a/src/SpectralAveraging/src/SpectralSample.cpp +++ b/src/SpectralAveraging/src/SpectralSample.cpp @@ -316,20 +316,23 @@ namespace SpectralAveraging void CSpectralSample::calculateState() { - CSample::calculateState(); - std::lock_guard lock(spectralSampleMutex); - if(m_SourceData.size() == 0) + if(!m_StateCalculated) { - for(const auto & prop : EnumProperty()) + CSample::calculateState(); + + if(m_SourceData.size() == 0) { - for(const auto & side : EnumSide()) + for(const auto & prop : EnumProperty()) { - m_Property[{prop, side}] = m_SampleData->properties(prop, side); + for(const auto & side : EnumSide()) + { + m_Property[{prop, side}] = m_SampleData->properties(prop, side); + } } - } - m_StateCalculated = true; + m_StateCalculated = true; + } } } From 8e9089ae5216b9c8ac24a87bcac691a6baaeaa43 Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Mon, 15 Aug 2022 14:28:01 -0700 Subject: [PATCH 4/9] mutex lock is now used in IDualBandMaterial. Need to fix unix and mac compilations. --- .../src/EquivalentBSDFLayer.cpp | 1 - .../src/MaterialDescription.cpp | 4 +++ src/SpectralAveraging/src/SpectralSample.cpp | 26 +++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp index 61e4fb01..702f576f 100644 --- a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp +++ b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp @@ -150,7 +150,6 @@ namespace MultiLayerOptics auto numberOfThreads{1u}; #if MULTITHREADING numberOfThreads = std::thread::hardware_concurrency(); - //numberOfThreads = 1u; #endif const auto chunks{FenestrationCommon::chunkIt( diff --git a/src/SingleLayerOptics/src/MaterialDescription.cpp b/src/SingleLayerOptics/src/MaterialDescription.cpp index 3f7e4461..d7eeec38 100644 --- a/src/SingleLayerOptics/src/MaterialDescription.cpp +++ b/src/SingleLayerOptics/src/MaterialDescription.cpp @@ -12,6 +12,8 @@ std::mutex materialWL; std::mutex baseMaterialMutex; std::mutex materialSampleWL; +std::mutex dualBandMaterialMutexProperty; +std::mutex dualBandMaterialMutexProperties; std::mutex dualBandMaterialMutexRatio; std::mutex dualBandMaterialMutexRadiation; @@ -361,6 +363,7 @@ namespace SingleLayerOptics const CBeamDirection & t_Incoming, const CBeamDirection & t_Outgoing) const { + std::lock_guard lock(dualBandMaterialMutexProperties); if(m_MaterialScaledRange == nullptr) { m_RangeCreator(); @@ -382,6 +385,7 @@ namespace SingleLayerOptics const CBeamDirection & t_IncomingDirection, const CBeamDirection & t_OutgoingDirection) const { + std::lock_guard lock(dualBandMaterialMutexProperty); if(m_MaterialScaledRange == nullptr) { m_RangeCreator(); diff --git a/src/SpectralAveraging/src/SpectralSample.cpp b/src/SpectralAveraging/src/SpectralSample.cpp index f9898a49..56124ea7 100644 --- a/src/SpectralAveraging/src/SpectralSample.cpp +++ b/src/SpectralAveraging/src/SpectralSample.cpp @@ -277,7 +277,11 @@ namespace SpectralAveraging CSeries CSpectralSample::getWavelengthsProperty(const Property t_Property, const Side t_Side) { - calculateState(); + std::lock_guard lock(spectralSampleMutex); + if(!m_StateCalculated) + { + calculateState(); + } return m_Property.at(std::make_pair(t_Property, t_Side)); } @@ -316,23 +320,19 @@ namespace SpectralAveraging void CSpectralSample::calculateState() { - std::lock_guard lock(spectralSampleMutex); - if(!m_StateCalculated) - { - CSample::calculateState(); + CSample::calculateState(); - if(m_SourceData.size() == 0) + if(m_SourceData.size() == 0) + { + for(const auto & prop : EnumProperty()) { - for(const auto & prop : EnumProperty()) + for(const auto & side : EnumSide()) { - for(const auto & side : EnumSide()) - { - m_Property[{prop, side}] = m_SampleData->properties(prop, side); - } + m_Property[{prop, side}] = m_SampleData->properties(prop, side); } - - m_StateCalculated = true; } + + m_StateCalculated = true; } } From e398c1f8b5cf9ac3060874d8dc9114c0d1f9e468 Mon Sep 17 00:00:00 2001 From: vidanovic Date: Mon, 15 Aug 2022 14:45:12 -0700 Subject: [PATCH 5/9] Fixes for gcc 11.2 errors. --- src/Common/src/Utility.cpp | 16 +++++---- src/Common/src/Utility.hpp | 8 ++--- .../src/EquivalentBSDFLayer.cpp | 35 +++++++++---------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/Common/src/Utility.cpp b/src/Common/src/Utility.cpp index 8f4b6673..24796c4f 100644 --- a/src/Common/src/Utility.cpp +++ b/src/Common/src/Utility.cpp @@ -2,19 +2,23 @@ namespace FenestrationCommon { - IndexRange::IndexRange(size_t startIndex, size_t endIndex) : start(startIndex), end(endIndex) + IndexRange::IndexRange(unsigned startIndex, unsigned endIndex) : + start(startIndex), end(endIndex) {} - std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits) + std::vector chunkIt(unsigned start, unsigned end, unsigned numberOfSplits) { - size_t stepSize{numberOfSplits < (end - start) ? static_cast((end - start) / numberOfSplits): 0u}; + unsigned stepSize{numberOfSplits < (end - start) + ? static_cast((end - start) / numberOfSplits) + : 0u}; std::vector result; - size_t currentStart{start}; - size_t currentEnd{currentStart}; + unsigned currentStart{start}; + unsigned currentEnd{currentStart}; - do { + do + { currentEnd = currentStart + stepSize < end ? currentStart + stepSize + 1u : end + 1u; result.emplace_back(currentStart, currentEnd); currentStart = currentEnd; diff --git a/src/Common/src/Utility.hpp b/src/Common/src/Utility.hpp index 20fd7cea..bb7940d9 100644 --- a/src/Common/src/Utility.hpp +++ b/src/Common/src/Utility.hpp @@ -6,11 +6,11 @@ namespace FenestrationCommon { struct IndexRange { - IndexRange(size_t startIndex, size_t endIndex); - size_t start{0u}; - size_t end{0u}; + IndexRange(unsigned startIndex, unsigned endIndex); + unsigned start{0u}; + unsigned end{0u}; }; //! Makes division for indexes that are defined from start to end for the purpose of multithreading. - std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits); + std::vector chunkIt(unsigned start, unsigned end, unsigned numberOfSplits); } \ No newline at end of file diff --git a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp index 702f576f..8e272de9 100644 --- a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp +++ b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp @@ -1,24 +1,21 @@ #include -#include -#include -#ifdef STL_MULTITHREADING -# include -#else -# include -#endif + +#include +#include #include "EquivalentBSDFLayer.hpp" #include "EquivalentBSDFLayerSingleBand.hpp" -#include "WCECommon.hpp" -using namespace FenestrationCommon; +using FenestrationCommon::CMatrixSeries; +using FenestrationCommon::Side; +using FenestrationCommon::PropertySimple; +using FenestrationCommon::CSeries; namespace MultiLayerOptics { CEquivalentBSDFLayer::CEquivalentBSDFLayer(const std::vector & t_CommonWavelengths) : - m_CombinedLayerWavelengths(t_CommonWavelengths), - m_Calculated(false) + m_CombinedLayerWavelengths(t_CommonWavelengths), m_Calculated(false) {} CEquivalentBSDFLayer::CEquivalentBSDFLayer( @@ -120,11 +117,11 @@ namespace MultiLayerOptics const size_t numberOfLayers = m_Layer.size(); const size_t seriesSize = m_CombinedLayerWavelengths.size(); - for(Side aSide : EnumSide()) + for(Side aSide : FenestrationCommon::EnumSide()) { m_TotA[aSide] = CMatrixSeries(numberOfLayers, matrixSize, seriesSize); m_TotJSC[aSide] = CMatrixSeries(numberOfLayers, matrixSize, seriesSize); - for(PropertySimple aProperty : EnumPropertySimple()) + for(PropertySimple aProperty : FenestrationCommon::EnumPropertySimple()) { m_Tot[{aSide, aProperty}] = CMatrixSeries(matrixSize, matrixSize, seriesSize); } @@ -152,8 +149,8 @@ namespace MultiLayerOptics numberOfThreads = std::thread::hardware_concurrency(); #endif - const auto chunks{FenestrationCommon::chunkIt( - 0u, m_CombinedLayerWavelengths.size() - 1u, numberOfThreads)}; + const auto chunks{ + FenestrationCommon::chunkIt(0u, m_CombinedLayerWavelengths.size() - 1u, numberOfThreads)}; std::vector workers; @@ -163,7 +160,7 @@ namespace MultiLayerOptics for(size_t index = chunk.start; index < chunk.end; ++index) { auto layer{getEquivalentLayerAtWavelength(index)}; - for(auto aSide : EnumSide()) + for(auto aSide : FenestrationCommon::EnumSide()) { const auto numberOfLayers{m_Layer.size()}; for(size_t layerNumber = 0; layerNumber < numberOfLayers; ++layerNumber) @@ -179,7 +176,7 @@ namespace MultiLayerOptics m_TotJSC.at(aSide).setPropertiesAtIndex( index, layerNumber, m_CombinedLayerWavelengths[index], totJSC); } - for(auto aProperty : EnumPropertySimple()) + for(auto aProperty : FenestrationCommon::EnumPropertySimple()) { auto tot{layer.getProperty(aSide, aProperty)}; @@ -224,12 +221,12 @@ namespace MultiLayerOptics std::vector CEquivalentBSDFLayer::unionOfLayerWavelengths( const std::vector> & t_Layer) { - CCommonWavelengths wl; + FenestrationCommon::CCommonWavelengths wl; for(const auto & layer : t_Layer) { wl.addWavelength(layer->getBandWavelengths()); } - return wl.getCombinedWavelengths(Combine::Interpolate); + return wl.getCombinedWavelengths(FenestrationCommon::Combine::Interpolate); } } // namespace MultiLayerOptics From d25e19f0b3923edbb0c769f412599ba862f53e1c Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Mon, 15 Aug 2022 17:01:51 -0700 Subject: [PATCH 6/9] DualBand materials do not cause crash in multithreading case. Some optimization is still possible if NIR range material can be created in a more convenient place. --- src/SingleLayerOptics/src/MaterialDescription.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/SingleLayerOptics/src/MaterialDescription.cpp b/src/SingleLayerOptics/src/MaterialDescription.cpp index d7eeec38..f0875de1 100644 --- a/src/SingleLayerOptics/src/MaterialDescription.cpp +++ b/src/SingleLayerOptics/src/MaterialDescription.cpp @@ -363,11 +363,13 @@ namespace SingleLayerOptics const CBeamDirection & t_Incoming, const CBeamDirection & t_Outgoing) const { - std::lock_guard lock(dualBandMaterialMutexProperties); + dualBandMaterialMutexProperties.lock(); if(m_MaterialScaledRange == nullptr) { m_RangeCreator(); } + dualBandMaterialMutexProperties.unlock(); + std::vector aResults; for(const auto wl : m_Wavelengths) @@ -385,13 +387,14 @@ namespace SingleLayerOptics const CBeamDirection & t_IncomingDirection, const CBeamDirection & t_OutgoingDirection) const { - std::lock_guard lock(dualBandMaterialMutexProperty); + dualBandMaterialMutexProperty.lock(); if(m_MaterialScaledRange == nullptr) { m_RangeCreator(); } - return getMaterialFromWavelength(m_Wavelengths[wavelengthIndex])->getProperty( - t_Property, t_Side, t_IncomingDirection, t_OutgoingDirection); + dualBandMaterialMutexProperty.unlock(); + return getMaterialFromWavelength(m_Wavelengths[wavelengthIndex]) + ->getProperty(t_Property, t_Side, t_IncomingDirection, t_OutgoingDirection); } std::vector IMaterialDualBand::calculateBandWavelengths() From 3b0c0422bd1ee5092dfb4a66dfc2ca724c2766b7 Mon Sep 17 00:00:00 2001 From: vidanovic Date: Mon, 15 Aug 2022 18:04:48 -0700 Subject: [PATCH 7/9] Creation of NIR range in dual band material is now optimized in creator functions from Material class. NIR range is no longer doing lazy calculations in calling getProperty of material because that function is called thousands of times in BSDF calculations. --- src/SingleLayerOptics/src/Material.cpp | 30 ++++++--- .../src/MaterialDescription.cpp | 65 +++---------------- .../src/MaterialDescription.hpp | 46 ++++--------- 3 files changed, 42 insertions(+), 99 deletions(-) diff --git a/src/SingleLayerOptics/src/Material.cpp b/src/SingleLayerOptics/src/Material.cpp index 016a804f..5c8e93cf 100644 --- a/src/SingleLayerOptics/src/Material.cpp +++ b/src/SingleLayerOptics/src/Material.cpp @@ -26,7 +26,10 @@ namespace SingleLayerOptics std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol); auto aVisibleRangeMaterial = std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis); - return std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + auto material = + std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + material->createRangesFromRatio(ConstantsData::NIRRatio); + return material; } std::shared_ptr Material::dualBandMaterial(const double Tfsol, @@ -43,8 +46,10 @@ namespace SingleLayerOptics std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol); auto aVisibleRangeMaterial = std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis); - return std::make_shared( - aVisibleRangeMaterial, aSolarRangeMaterial, ratio); + auto material = + std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + material->createRangesFromRatio(ratio); + return material; } std::shared_ptr Material::dualBandMaterial(const double Tfsol, @@ -61,8 +66,10 @@ namespace SingleLayerOptics std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol); auto aVisibleRangeMaterial = std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis); - return std::make_shared( - aVisibleRangeMaterial, aSolarRangeMaterial, solarRadiation); + auto material = + std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + material->createRangesFromSolarRadiation(solarRadiation); + return material; } std::shared_ptr @@ -81,8 +88,10 @@ namespace SingleLayerOptics std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol, hemisphere); auto aVisibleRangeMaterial = std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis, hemisphere); - return std::make_shared( - aVisibleRangeMaterial, aSolarRangeMaterial, ratio); + auto material = + std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + material->createRangesFromRatio(ratio); + return material; } std::shared_ptr @@ -101,8 +110,11 @@ namespace SingleLayerOptics std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol, hemisphere); auto aVisibleRangeMaterial = std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis, hemisphere); - return std::make_shared( - aVisibleRangeMaterial, aSolarRangeMaterial, solarRadiation); + auto material = + std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); + material->createRangesFromSolarRadiation(solarRadiation); + + return material; } std::shared_ptr Material::singleBandMaterial(const double Tf, diff --git a/src/SingleLayerOptics/src/MaterialDescription.cpp b/src/SingleLayerOptics/src/MaterialDescription.cpp index f0875de1..aa1d5cc9 100644 --- a/src/SingleLayerOptics/src/MaterialDescription.cpp +++ b/src/SingleLayerOptics/src/MaterialDescription.cpp @@ -12,8 +12,6 @@ std::mutex materialWL; std::mutex baseMaterialMutex; std::mutex materialSampleWL; -std::mutex dualBandMaterialMutexProperty; -std::mutex dualBandMaterialMutexProperties; std::mutex dualBandMaterialMutexRatio; std::mutex dualBandMaterialMutexRadiation; @@ -129,9 +127,7 @@ namespace SingleLayerOptics //////////////////////////////////////////////////////////////////////////////////// CMaterial::CMaterial(const double minLambda, const double maxLambda) : - m_MinLambda(minLambda), - m_MaxLambda(maxLambda), - m_WavelengthsCalculated(false) + m_MinLambda(minLambda), m_MaxLambda(maxLambda), m_WavelengthsCalculated(false) {} CMaterial::CMaterial(FenestrationCommon::Limits wavelengthRange) : @@ -318,22 +314,10 @@ namespace SingleLayerOptics //////////////////////////////////////////////////////////////////////////////////// IMaterialDualBand::IMaterialDualBand(const std::shared_ptr & visibleRange, - const std::shared_ptr & solarRange, - double t_Ratio) : + const std::shared_ptr & solarRange) : CMaterial(solarRange->getMinLambda(), solarRange->getMaxLambda()), m_MaterialSolarRange(solarRange), - m_MaterialVisibleRange(visibleRange), - m_RangeCreator(std::bind(&IMaterialDualBand::createRangesFromRatio, this, t_Ratio)) - {} - - IMaterialDualBand::IMaterialDualBand(const std::shared_ptr & visibleRange, - const std::shared_ptr & solarRange, - const FenestrationCommon::CSeries & t_SolarRadiation) : - CMaterial(solarRange->getMinLambda(), solarRange->getMaxLambda()), - m_MaterialSolarRange(solarRange), - m_MaterialVisibleRange(visibleRange), - m_RangeCreator( - std::bind(&IMaterialDualBand::createRangesFromSolarRadiation, this, t_SolarRadiation)) + m_MaterialVisibleRange(visibleRange) {} void IMaterialDualBand::setSourceData(CSeries & t_SourceData) @@ -363,14 +347,8 @@ namespace SingleLayerOptics const CBeamDirection & t_Incoming, const CBeamDirection & t_Outgoing) const { - dualBandMaterialMutexProperties.lock(); - if(m_MaterialScaledRange == nullptr) - { - m_RangeCreator(); - } - dualBandMaterialMutexProperties.unlock(); - std::vector aResults; + aResults.reserve(m_Wavelengths.size()); for(const auto wl : m_Wavelengths) { @@ -387,12 +365,6 @@ namespace SingleLayerOptics const CBeamDirection & t_IncomingDirection, const CBeamDirection & t_OutgoingDirection) const { - dualBandMaterialMutexProperty.lock(); - if(m_MaterialScaledRange == nullptr) - { - m_RangeCreator(); - } - dualBandMaterialMutexProperty.unlock(); return getMaterialFromWavelength(m_Wavelengths[wavelengthIndex]) ->getProperty(t_Property, t_Side, t_IncomingDirection, t_OutgoingDirection); } @@ -404,15 +376,8 @@ namespace SingleLayerOptics } CMaterialDualBand::CMaterialDualBand(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - double t_Ratio) : - IMaterialDualBand(t_PartialRange, t_FullRange, t_Ratio) - {} - - CMaterialDualBand::CMaterialDualBand(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - const FenestrationCommon::CSeries & t_SolarRadiation) : - IMaterialDualBand(t_PartialRange, t_FullRange, t_SolarRadiation) + const std::shared_ptr & t_FullRange) : + IMaterialDualBand(t_PartialRange, t_FullRange) {} void CMaterialDualBand::createNIRRange(const std::shared_ptr & t_PartialRange, @@ -551,8 +516,7 @@ namespace SingleLayerOptics const std::shared_ptr & t_SpectralSample, double t_Thickness, FenestrationCommon::MaterialType t_Type) : - CMaterialSample(t_SpectralSample, t_Thickness, t_Type), - m_PVSample(t_SpectralSample) + CMaterialSample(t_SpectralSample, t_Thickness, t_Type), m_PVSample(t_SpectralSample) {} FenestrationCommon::CSeries @@ -567,8 +531,7 @@ namespace SingleLayerOptics CMaterialMeasured::CMaterialMeasured( const std::shared_ptr & t_Measurements) : - CMaterial(t_Measurements->getWavelengthLimits()), - m_AngularMeasurements(t_Measurements) + CMaterial(t_Measurements->getWavelengthLimits()), m_AngularMeasurements(t_Measurements) { if(t_Measurements == nullptr) { @@ -774,16 +737,8 @@ namespace SingleLayerOptics CMaterialDualBandBSDF::CMaterialDualBandBSDF( const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - double t_Ratio) : - IMaterialDualBand(t_PartialRange, t_FullRange, t_Ratio) - {} - - CMaterialDualBandBSDF::CMaterialDualBandBSDF( - const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - const FenestrationCommon::CSeries & t_SolarRadiation) : - IMaterialDualBand(t_PartialRange, t_FullRange, t_SolarRadiation) + const std::shared_ptr & t_FullRange) : + IMaterialDualBand(t_PartialRange, t_FullRange) {} void CMaterialDualBandBSDF::createNIRRange(const std::shared_ptr & t_PartialRange, diff --git a/src/SingleLayerOptics/src/MaterialDescription.hpp b/src/SingleLayerOptics/src/MaterialDescription.hpp index a55b3720..9159b328 100644 --- a/src/SingleLayerOptics/src/MaterialDescription.hpp +++ b/src/SingleLayerOptics/src/MaterialDescription.hpp @@ -220,13 +220,8 @@ namespace SingleLayerOptics { public: IMaterialDualBand(const std::shared_ptr & visibleRange, - const std::shared_ptr & solarRange, - double t_Ratio = ConstantsData::NIRRatio); + const std::shared_ptr & solarRange); - // ratio is calculated based on provided solar radiation values - IMaterialDualBand(const std::shared_ptr & visibleRange, - const std::shared_ptr & solarRange, - const FenestrationCommon::CSeries & t_SolarRadiation); void setSourceData(FenestrationCommon::CSeries & t_SourceData) override; void setDetectorData(FenestrationCommon::CSeries & t_DetectorData) override; @@ -250,6 +245,12 @@ namespace SingleLayerOptics const CBeamDirection & t_IncomingDirection = CBeamDirection(), const CBeamDirection & t_OutgoingDirection = CBeamDirection()) const override; + // Creates all the required ranges in m_Materials from a ratio + void createRangesFromRatio(double t_Ratio); + + // Creates all the required ranges in m_Materials from solar radiation + void createRangesFromSolarRadiation(const FenestrationCommon::CSeries & t_SolarRadiation); + protected: std::vector calculateBandWavelengths() override; @@ -258,12 +259,6 @@ namespace SingleLayerOptics const std::shared_ptr & t_SolarRange, double t_Fraction) = 0; - // Creates all of the required ranges in m_Materials from a ratio - void createRangesFromRatio(double t_Ratio); - - // Creates all of the required ranges in m_Materials from solar radiation - void createRangesFromSolarRadiation(const FenestrationCommon::CSeries & t_SolarRadiation); - [[nodiscard]] std::vector getWavelengthsFromMaterials() const; // Properties over the rest of range will depend on partial range as well. @@ -272,31 +267,21 @@ namespace SingleLayerOptics // double getModifiedProperty(double t_Range, double t_Solar, double t_Fraction) const; [[nodiscard]] std::shared_ptr getMaterialFromWavelength(double wavelength) const; - [[nodiscard]] std::shared_ptr getMaterialFromWavelength(size_t wavelengthIndex) const; + [[nodiscard]] std::shared_ptr + getMaterialFromWavelength(size_t wavelengthIndex) const; std::shared_ptr m_MaterialSolarRange; std::shared_ptr m_MaterialVisibleRange; std::shared_ptr m_MaterialScaledRange; - - std::function m_RangeCreator; }; class CMaterialDualBand : public IMaterialDualBand { public: - // ratio is calculated outside of the class and can be provided here. - // TODO: Need to confirm with the team if we actually need this approach - // (ratio should be calculated and not quessed) CMaterialDualBand(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - double t_Ratio = ConstantsData::NIRRatio); - - // ratio is calculated based on provided solar radiation values - CMaterialDualBand(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - const FenestrationCommon::CSeries & t_SolarRadiation); + const std::shared_ptr & t_FullRange); private: // Creates after UV range and stores data into m_Materials @@ -316,17 +301,8 @@ namespace SingleLayerOptics class CMaterialDualBandBSDF : public IMaterialDualBand { public: - // ratio is calculated outside of the class and can be provided here. - // TODO: Need to confirm with the team if we actually need this approach - // (ratio should be calculated and not quessed) - CMaterialDualBandBSDF(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - double t_Ratio = ConstantsData::NIRRatio); - - // ratio is calculated based on provided solar radiation values CMaterialDualBandBSDF(const std::shared_ptr & t_PartialRange, - const std::shared_ptr & t_FullRange, - const FenestrationCommon::CSeries & t_SolarRadiation); + const std::shared_ptr & t_FullRange); protected: // Creates after UV range and stores data into m_Materials From a7c0fb20a7b938dedd7340822cc6045e2e010a41 Mon Sep 17 00:00:00 2001 From: vidanovic Date: Mon, 15 Aug 2022 19:17:15 -0700 Subject: [PATCH 8/9] Fix for single layer optics tests. Build of the material was incorrect. --- src/SingleLayerOptics/tst/units/BSDFMaterialDualBand.unit.cpp | 1 + .../tst/units/BSDFMaterialDualBandCondensedRange.unit.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/SingleLayerOptics/tst/units/BSDFMaterialDualBand.unit.cpp b/src/SingleLayerOptics/tst/units/BSDFMaterialDualBand.unit.cpp index 61925d7d..8a3aa97f 100644 --- a/src/SingleLayerOptics/tst/units/BSDFMaterialDualBand.unit.cpp +++ b/src/SingleLayerOptics/tst/units/BSDFMaterialDualBand.unit.cpp @@ -109,6 +109,7 @@ class TestBSDFMaterialDualBand : public testing::Test m_RbSol, m_Hemisphere); m_Material = std::make_shared(m_MaterialVis, m_MaterialSol); + m_Material->createRangesFromRatio(ConstantsData::NIRRatio); } }; diff --git a/src/SingleLayerOptics/tst/units/BSDFMaterialDualBandCondensedRange.unit.cpp b/src/SingleLayerOptics/tst/units/BSDFMaterialDualBandCondensedRange.unit.cpp index ace6b5c3..f729a902 100644 --- a/src/SingleLayerOptics/tst/units/BSDFMaterialDualBandCondensedRange.unit.cpp +++ b/src/SingleLayerOptics/tst/units/BSDFMaterialDualBandCondensedRange.unit.cpp @@ -132,6 +132,7 @@ class TestBSDFMaterialDualBandCondensedRange : public testing::Test m_RbSol, m_Hemisphere); m_Material = std::make_shared(m_MaterialVis, m_MaterialSol); + m_Material->createRangesFromRatio(ConstantsData::NIRRatio); m_Material->setBandWavelengths(condensedSpectrum()); } From 5c05e6b20cee539531d224bcdbd3d750762f6886 Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Tue, 16 Aug 2022 08:33:55 -0700 Subject: [PATCH 9/9] Dual-band materials have ratio as default parameter instead of two overloaded functions. --- CMakeLists.txt | 2 +- src/SingleLayerOptics/src/Material.cpp | 19 ------------------- src/SingleLayerOptics/src/Material.hpp | 12 ++---------- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 284175a6..48765a9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -project(Windows-CalcEngine VERSION 1.0.11 LANGUAGES CXX) +project(Windows-CalcEngine VERSION 1.0.32 LANGUAGES CXX) set(target_name ${PROJECT_NAME}) diff --git a/src/SingleLayerOptics/src/Material.cpp b/src/SingleLayerOptics/src/Material.cpp index 5c8e93cf..5423a09b 100644 --- a/src/SingleLayerOptics/src/Material.cpp +++ b/src/SingleLayerOptics/src/Material.cpp @@ -13,25 +13,6 @@ using SpectralAveraging::CPhotovoltaicSample; namespace SingleLayerOptics { - std::shared_ptr Material::dualBandMaterial(const double Tfsol, - const double Tbsol, - const double Rfsol, - const double Rbsol, - const double Tfvis, - const double Tbvis, - const double Rfvis, - const double Rbvis) - { - auto aSolarRangeMaterial = - std::make_shared(Tfsol, Tbsol, Rfsol, Rbsol); - auto aVisibleRangeMaterial = - std::make_shared(Tfvis, Tbvis, Rfvis, Rbvis); - auto material = - std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); - material->createRangesFromRatio(ConstantsData::NIRRatio); - return material; - } - std::shared_ptr Material::dualBandMaterial(const double Tfsol, const double Tbsol, const double Rfsol, diff --git a/src/SingleLayerOptics/src/Material.hpp b/src/SingleLayerOptics/src/Material.hpp index 0f69e3ed..dbe884bb 100644 --- a/src/SingleLayerOptics/src/Material.hpp +++ b/src/SingleLayerOptics/src/Material.hpp @@ -18,14 +18,6 @@ namespace SingleLayerOptics class Material { public: - static std::shared_ptr dualBandMaterial(double Tfsol, - double Tbsol, - double Rfsol, - double Rbsol, - double Tfvis, - double Tbvis, - double Rfvis, - double Rbvis); static std::shared_ptr dualBandMaterial(double Tfsol, double Tbsol, @@ -35,7 +27,7 @@ namespace SingleLayerOptics double Tbvis, double Rfvis, double Rbvis, - double ratio); + double ratio = ConstantsData::NIRRatio); static std::shared_ptr dualBandMaterial(double Tfsol, @@ -58,7 +50,7 @@ namespace SingleLayerOptics std::vector> const & Rfvis, std::vector> const & Rbvis, BSDFHemisphere const & hemisphere, - double ratio); + double ratio = ConstantsData::NIRRatio); static std::shared_ptr dualBandBSDFMaterial(std::vector> const & Tfsol,