Skip to content

Commit

Permalink
Merge pull request #134 from LBNL-ETA/ParallelSpectralIntegration
Browse files Browse the repository at this point in the history
Parallel spectral integration
  • Loading branch information
vidanovic authored Aug 16, 2022
2 parents cfe0782 + df29932 commit 2bf22fb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(Windows-CalcEngine VERSION 1.0.32 LANGUAGES CXX)
project(Windows-CalcEngine VERSION 1.0.33 LANGUAGES CXX)

set(target_name ${PROJECT_NAME})

Expand Down
57 changes: 49 additions & 8 deletions src/Common/src/MatrixSeries.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include <cassert>
#include <stdexcept>

#include <thread>

#include "MatrixSeries.hpp"
#include "SquareMatrix.hpp"
#include "Series.hpp"
#include "IntegratorStrategy.hpp"
#include "Utility.hpp"


namespace FenestrationCommon
{
CMatrixSeries::CMatrixSeries(const size_t t_Size1, const size_t t_Size2, size_t seriesSize) :
m_Size1(t_Size1), m_Size2(t_Size2)
m_Size1(t_Size1),
m_Size2(t_Size2)
{
m_Matrix = std::vector<std::vector<CSeries>>(m_Size1);
for(size_t i = 0; i < m_Size1; ++i)
Expand Down Expand Up @@ -106,6 +110,7 @@ namespace FenestrationCommon

void CMatrixSeries::mMult(const CSeries & t_Series)
{
// Parallelization here did not show any improvements. Program was performing even slower.
for(size_t i = 0; i < m_Matrix.size(); ++i)
{
for(size_t j = 0; j < m_Matrix[i].size(); ++j)
Expand All @@ -118,11 +123,11 @@ namespace FenestrationCommon

void CMatrixSeries::mMult(const std::vector<CSeries> & t_Series)
{
// Parallelization here did not show any improvements. Program was performing even slower.
for(size_t i = 0; i < m_Matrix.size(); ++i)
{
for(size_t j = 0; j < m_Matrix[i].size(); ++j)
{
// assert( t_Series[ i ]->size() == ( *m_Matrix[ i ][ j ] ).size() );
m_Matrix[i][j] = m_Matrix[i][j] * t_Series[i];
}
}
Expand All @@ -139,21 +144,57 @@ namespace FenestrationCommon
{
for(size_t i = 0; i < m_Matrix.size(); ++i)
{
for(size_t j = 0; j < m_Matrix[i].size(); ++j)
auto numberOfThreads{1u};
#if MULTITHREADING
numberOfThreads = std::thread::hardware_concurrency();
#endif
const auto chunks{
FenestrationCommon::chunkIt(0u, m_Matrix[i].size() - 1u, numberOfThreads)};

std::vector<std::thread> workers;
for(const auto & chunk : chunks)
{
workers.emplace_back([&]() {
for(size_t j = chunk.start; j < chunk.end; ++j)
{
m_Matrix[i][j] = m_Matrix[i][j].integrate(
t_Integration, normalizationCoefficient, integrationPoints);
}
});
}

for(auto & worker : workers)
{
m_Matrix[i][j] = m_Matrix[i][j].integrate(
t_Integration, normalizationCoefficient, integrationPoints);
worker.join();
}
}
}

void CMatrixSeries::interpolate(const std::vector<double> & t_Wavelengths)
{
for(size_t i = 0; i < m_Matrix.size(); ++i)
for(size_t i = 0u; i < m_Matrix.size(); ++i)
{
for(size_t j = 0; j < m_Matrix[i].size(); ++j)
auto numberOfThreads{1u};
#if MULTITHREADING
numberOfThreads = std::thread::hardware_concurrency();
#endif
const auto chunks{
FenestrationCommon::chunkIt(0u, m_Matrix[i].size() - 1u, numberOfThreads)};

std::vector<std::thread> workers;
for(const auto & chunk : chunks)
{
workers.emplace_back([&]() {
for(size_t j = chunk.start; j < chunk.end; ++j)
{
m_Matrix[i][j] = m_Matrix[i][j].interpolate(t_Wavelengths);
}
});
}

for(auto & worker : workers)
{
m_Matrix[i][j] = m_Matrix[i][j].interpolate(t_Wavelengths);
worker.join();
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/MultiLayerOptics/src/EquivalentBSDFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ namespace MultiLayerOptics
return m_Layer.size();
}

void CEquivalentBSDFLayer::setMatrixLayerWavelengths(const std::vector<double> & wavelenghts)
{
m_CombinedLayerWavelengths = wavelenghts;
for(const auto & layer : m_Layer)
{
layer->setBandWavelengths(wavelenghts);
}
}

void CEquivalentBSDFLayer::calculate()
{
const size_t matrixSize = m_Lambda.size();
Expand All @@ -134,12 +125,6 @@ namespace MultiLayerOptics

void CEquivalentBSDFLayer::calculateWavelengthByWavelengthProperties()
{
std::vector<size_t> wavelengthIndexes;
for(size_t i = 0; i < m_CombinedLayerWavelengths.size(); ++i)
{
wavelengthIndexes.push_back(i);
}

std::mutex absorptanceMutex;
std::mutex jscMutex;
std::mutex totMutex;
Expand Down
31 changes: 6 additions & 25 deletions src/MultiLayerOptics/src/EquivalentBSDFLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,25 @@ namespace MultiLayerOptics
[[nodiscard]] double getMaxLambda() const;

// Absorptance wavelength by wavelength matrices
FenestrationCommon::CMatrixSeries getTotalA(const FenestrationCommon::Side t_Side);
FenestrationCommon::CMatrixSeries getTotalA(FenestrationCommon::Side t_Side);

// Photovoltaic current (scaled to income irradiance equal to one)
FenestrationCommon::CMatrixSeries getTotalJSC(FenestrationCommon::Side t_Side);

// Transmittance and reflectance wavelength by wavelength matrices
FenestrationCommon::CMatrixSeries
getTotal(const FenestrationCommon::Side t_Side,
const FenestrationCommon::PropertySimple t_Property);
FenestrationCommon::CMatrixSeries getTotal(FenestrationCommon::Side t_Side,
FenestrationCommon::PropertySimple t_Property);

void setSolarRadiation(FenestrationCommon::CSeries & t_SolarRadiation);

[[nodiscard]] std::vector<std::shared_ptr<SingleLayerOptics::CBSDFLayer>> & getLayers();
[[nodiscard]] size_t numberOfLayers() const;

void setMatrixLayerWavelengths(const std::vector<double> & wavelenghts);

private:
struct wavelenghtData
{
wavelenghtData(double wl, CEquivalentBSDFLayerSingleBand & layerWl) :
wavelength(wl),
layer(layerWl)
{}

double wavelength;
CEquivalentBSDFLayerSingleBand & layer;
std::map<std::pair<FenestrationCommon::Side, size_t>, std::vector<double>> totA;
std::map<std::pair<FenestrationCommon::Side, size_t>, std::vector<double>> totJSC;
std::map<std::pair<FenestrationCommon::Side, FenestrationCommon::PropertySimple>,
FenestrationCommon::SquareMatrix>
tot;
};

void calculate();

CEquivalentBSDFLayerSingleBand getEquivalentLayerAtWavelength(size_t wavelengthIndex) const;
private:
[[nodiscard]] CEquivalentBSDFLayerSingleBand
getEquivalentLayerAtWavelength(size_t wavelengthIndex) const;

static std::vector<double> unionOfLayerWavelengths(
const std::vector<std::shared_ptr<SingleLayerOptics::CBSDFLayer>> & t_Layer);
Expand Down Expand Up @@ -97,7 +79,6 @@ namespace MultiLayerOptics
bool m_Calculated;

void calculateWavelengthByWavelengthProperties();

};

} // namespace MultiLayerOptics
Expand Down
3 changes: 1 addition & 2 deletions src/MultiLayerOptics/src/MultiPaneBSDF.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include <cmath>
#include <numeric>
#include <algorithm>
#include <cassert>
#include <utility>

#include "MultiPaneBSDF.hpp"
#include "EquivalentBSDFLayer.hpp"
#include "EquivalentBSDFLayerSingleBand.hpp"
#include "WCESingleLayerOptics.hpp"
#include "WCECommon.hpp"
Expand Down Expand Up @@ -112,6 +110,7 @@ namespace MultiLayerOptics
m_IncomingSolar.push_back(iTotalSolar.sum(minLambda, maxLambda));
}


// Produce local results matrices for each side and property
std::map<std::pair<Side, PropertySimple>, SquareMatrix> aResults;

Expand Down

0 comments on commit 2bf22fb

Please sign in to comment.