diff --git a/CMakeLists.txt b/CMakeLists.txt index a88fbf8b..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}) @@ -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/include/WCECommon.hpp b/src/Common/include/WCECommon.hpp index bf1114a4..a27409b7 100644 --- a/src/Common/include/WCECommon.hpp +++ b/src/Common/include/WCECommon.hpp @@ -18,7 +18,7 @@ #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" +#include "../src/Utility.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/Utility.cpp b/src/Common/src/Utility.cpp new file mode 100644 index 00000000..24796c4f --- /dev/null +++ b/src/Common/src/Utility.cpp @@ -0,0 +1,29 @@ +#include "Utility.hpp" + +namespace FenestrationCommon +{ + IndexRange::IndexRange(unsigned startIndex, unsigned endIndex) : + start(startIndex), end(endIndex) + {} + + std::vector chunkIt(unsigned start, unsigned end, unsigned numberOfSplits) + { + unsigned stepSize{numberOfSplits < (end - start) + ? static_cast((end - start) / numberOfSplits) + : 0u}; + + std::vector result; + + unsigned currentStart{start}; + unsigned currentEnd{currentStart}; + + do + { + currentEnd = currentStart + stepSize < end ? currentStart + stepSize + 1u : end + 1u; + result.emplace_back(currentStart, currentEnd); + 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 new file mode 100644 index 00000000..bb7940d9 --- /dev/null +++ b/src/Common/src/Utility.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace FenestrationCommon +{ + struct IndexRange + { + 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(unsigned start, unsigned end, unsigned numberOfSplits); +} \ No newline at end of file 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/Common/tst/units/ChunkIt.unit.cpp b/src/Common/tst/units/ChunkIt.unit.cpp new file mode 100644 index 00000000..ab0e368e --- /dev/null +++ b/src/Common/tst/units/ChunkIt.unit.cpp @@ -0,0 +1,123 @@ +#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, 2u}, {2u, 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, 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, 1u}, {1u, 2u}, {2u, 3u}, {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, 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, 3u}, {3u, 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, 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, 4u}, {4u, 5u}, {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, 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, 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) + { + EXPECT_EQ(result[i].start, correct[i].start); + EXPECT_EQ(result[i].end, correct[i].end); + } +} \ No newline at end of file diff --git a/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp b/src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp index c67c2272..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); } @@ -147,44 +144,56 @@ 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(); #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 : FenestrationCommon::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 : FenestrationCommon::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 +201,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]}; @@ -212,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 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/src/Material.cpp b/src/SingleLayerOptics/src/Material.cpp index 016a804f..5423a09b 100644 --- a/src/SingleLayerOptics/src/Material.cpp +++ b/src/SingleLayerOptics/src/Material.cpp @@ -13,22 +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); - return std::make_shared(aVisibleRangeMaterial, aSolarRangeMaterial); - } - std::shared_ptr Material::dualBandMaterial(const double Tfsol, const double Tbsol, const double Rfsol, @@ -43,8 +27,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 +47,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 +69,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 +91,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/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, diff --git a/src/SingleLayerOptics/src/MaterialDescription.cpp b/src/SingleLayerOptics/src/MaterialDescription.cpp index 3f7e4461..aa1d5cc9 100644 --- a/src/SingleLayerOptics/src/MaterialDescription.cpp +++ b/src/SingleLayerOptics/src/MaterialDescription.cpp @@ -127,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) : @@ -316,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) @@ -361,11 +347,8 @@ namespace SingleLayerOptics const CBeamDirection & t_Incoming, const CBeamDirection & t_Outgoing) const { - if(m_MaterialScaledRange == nullptr) - { - m_RangeCreator(); - } std::vector aResults; + aResults.reserve(m_Wavelengths.size()); for(const auto wl : m_Wavelengths) { @@ -382,12 +365,8 @@ namespace SingleLayerOptics const CBeamDirection & t_IncomingDirection, const CBeamDirection & t_OutgoingDirection) const { - if(m_MaterialScaledRange == nullptr) - { - m_RangeCreator(); - } - return getMaterialFromWavelength(m_Wavelengths[wavelengthIndex])->getProperty( - t_Property, t_Side, t_IncomingDirection, t_OutgoingDirection); + return getMaterialFromWavelength(m_Wavelengths[wavelengthIndex]) + ->getProperty(t_Property, t_Side, t_IncomingDirection, t_OutgoingDirection); } std::vector IMaterialDualBand::calculateBandWavelengths() @@ -397,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, @@ -544,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 @@ -560,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) { @@ -767,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 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()); } 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/SpectralAveraging/src/SpectralSample.cpp b/src/SpectralAveraging/src/SpectralSample.cpp index 1b4279b1..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)); } @@ -318,7 +322,6 @@ namespace SpectralAveraging { CSample::calculateState(); - std::lock_guard lock(spectralSampleMutex); if(m_SourceData.size() == 0) { for(const auto & prop : EnumProperty()) 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 {