Skip to content

Commit

Permalink
Added homogenious diffuse shade.
Browse files Browse the repository at this point in the history
  • Loading branch information
vidanovic committed Nov 5, 2024
1 parent fa5f628 commit 51ea67c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/SingleLayerOptics/src/BSDFLayerMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ namespace SingleLayerOptics
return std::make_shared<CUniformDiffuseBSDFLayer>(aCell, t_BSDF);
}

std::shared_ptr<CBSDFLayer>
CBSDFLayerMaker::getHomogeneousDiffuseLayer(const std::shared_ptr<CMaterial> & t_Material,
const BSDFHemisphere & t_BSDF)
{
auto aDescription = std::make_shared<CFlatCellDescription>();
auto aCell = std::make_shared<CDirectionalDiffuseCell>(t_Material, aDescription);
return std::make_shared<CHomogeneousDiffuseBSDFLayer>(aCell, t_BSDF);
}

std::shared_ptr<CBSDFLayer>
CBSDFLayerMaker::getDirectionalDiffuseLayer(const std::shared_ptr<CMaterial> & t_Material,
const BSDFHemisphere & t_BSDF)
Expand Down
4 changes: 4 additions & 0 deletions src/SingleLayerOptics/src/BSDFLayerMaker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace SingleLayerOptics
getPerfectlyDiffuseLayer(const std::shared_ptr<CMaterial> & t_Material,
const BSDFHemisphere & t_BSDF);

static std::shared_ptr<CBSDFLayer>
getHomogeneousDiffuseLayer(const std::shared_ptr<CMaterial> & t_Material,
const BSDFHemisphere & t_BSDF);

static std::shared_ptr<CBSDFLayer>
getDirectionalDiffuseLayer(const std::shared_ptr<CMaterial> & t_Material,
const BSDFHemisphere & t_BSDF);
Expand Down
32 changes: 24 additions & 8 deletions src/SingleLayerOptics/src/DirectionalDiffuseBSDFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace SingleLayerOptics
const double aRho = aCell->R_dir_dif(aSide, incomingDirection, jDirection);

tau(outgoingDirectionIndex, incomingDirectionIndex) +=
aTau * diffuseDistributionScalar(outgoingDirectionIndex);
aTau * diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
Rho(outgoingDirectionIndex, incomingDirectionIndex) +=
aRho * diffuseDistributionScalar(outgoingDirectionIndex);
aRho * diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
}
}

Expand Down Expand Up @@ -81,9 +81,11 @@ namespace SingleLayerOptics
auto & tau = results[j].getMatrix(aSide, PropertySimple::T);
auto & rho = results[j].getMatrix(aSide, PropertySimple::R);
tau(outgoingDirectionIndex, incomingDirectionIndex) +=
aTau[j] * diffuseDistributionScalar(outgoingDirectionIndex);
aTau[j]
* diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
rho(outgoingDirectionIndex, incomingDirectionIndex) +=
Ref[j] * diffuseDistributionScalar(outgoingDirectionIndex);
Ref[j]
* diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
}
}
}
Expand Down Expand Up @@ -114,9 +116,9 @@ namespace SingleLayerOptics
auto & tau = results.getMatrix(aSide, PropertySimple::T);
auto & rho = results.getMatrix(aSide, PropertySimple::R);
tau(outgoingDirectionIndex, incomingDirectionIndex) +=
aTau * diffuseDistributionScalar(outgoingDirectionIndex);
aTau * diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
rho(outgoingDirectionIndex, incomingDirectionIndex) +=
Ref * diffuseDistributionScalar(outgoingDirectionIndex);
Ref * diffuseDistributionScalar(incomingDirectionIndex, outgoingDirectionIndex);
}
}

Expand All @@ -126,17 +128,31 @@ namespace SingleLayerOptics
CDirectionalBSDFLayer(t_Cell, t_Hemisphere)
{}

double CDirectionalDiffuseBSDFLayer::diffuseDistributionScalar(size_t)
double CDirectionalDiffuseBSDFLayer::diffuseDistributionScalar(size_t, size_t)
{
return 1 / ConstantsData::WCE_PI;
}

CHomogeneousDiffuseBSDFLayer::CHomogeneousDiffuseBSDFLayer(
const std::shared_ptr<CDirectionalDiffuseCell> & t_Cell,
const BSDFHemisphere & t_Hemisphere) :
CDirectionalBSDFLayer(t_Cell, t_Hemisphere)
{}

double CHomogeneousDiffuseBSDFLayer::diffuseDistributionScalar(size_t incomingDirection,
size_t )
{
const auto lambdas{m_BSDFHemisphere.getDirections(BSDFDirection::Outgoing).lambdaVector()};
return 1 / (FenestrationCommon::WCE_PI - lambdas.at(incomingDirection));
}

CMatrixBSDFLayer::CMatrixBSDFLayer(const std::shared_ptr<CDirectionalDiffuseCell> & t_Cell,
const BSDFHemisphere & t_Hemisphere) :
CDirectionalBSDFLayer(t_Cell, t_Hemisphere)
{}

double CMatrixBSDFLayer::diffuseDistributionScalar(size_t outgoingDirection)
double CMatrixBSDFLayer::diffuseDistributionScalar(size_t ,
size_t outgoingDirection)
{
const auto lambdas{m_BSDFHemisphere.getDirections(BSDFDirection::Outgoing).lambdaVector()};
return 1 / lambdas.at(outgoingDirection);
Expand Down
16 changes: 13 additions & 3 deletions src/SingleLayerOptics/src/DirectionalDiffuseBSDFLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace SingleLayerOptics
size_t wavelengthIndex,
BSDFIntegrator & results) override;

virtual double diffuseDistributionScalar(size_t outgoingDirection) = 0;
virtual double diffuseDistributionScalar(size_t incomingDirection, size_t outgoingDirection) = 0;
};

class CDirectionalDiffuseBSDFLayer : public CDirectionalBSDFLayer
Expand All @@ -41,7 +41,17 @@ namespace SingleLayerOptics
const BSDFHemisphere & t_Hemisphere);

protected:
double diffuseDistributionScalar(size_t outgoingDirection) override;
double diffuseDistributionScalar(size_t incomingDirection, size_t outgoingDirection) override;
};

class CHomogeneousDiffuseBSDFLayer : public CDirectionalBSDFLayer
{
public:
CHomogeneousDiffuseBSDFLayer(const std::shared_ptr<CDirectionalDiffuseCell> & t_Cell,
const BSDFHemisphere & t_Hemisphere);

protected:
double diffuseDistributionScalar(size_t incomingDirection, size_t outgoingDirection) override;
};

class CMatrixBSDFLayer : public CDirectionalBSDFLayer
Expand All @@ -51,7 +61,7 @@ namespace SingleLayerOptics
const BSDFHemisphere & t_Hemisphere);

protected:
double diffuseDistributionScalar(size_t outgoingDirection) override;
double diffuseDistributionScalar(size_t incomingDirection, size_t outgoingDirection) override;
};

} // namespace SingleLayerOptics
Expand Down
107 changes: 107 additions & 0 deletions src/SingleLayerOptics/tst/units/HomogeneousDiffuseShade1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <memory>
#include <gtest/gtest.h>

#include "WCESingleLayerOptics.hpp"

#include "csvHandlers.hpp"


using namespace SingleLayerOptics;
using namespace FenestrationCommon;

class TestHomogenousDiffuseShade1 : public testing::Test
{
private:
std::shared_ptr<CBSDFLayer> m_Shade;

protected:
virtual void SetUp()
{
// create material
double Tmat = 0.1;
double Rfmat = 0.7;
double Rbmat = 0.7;
auto aMaterial = Material::singleBandMaterial(Tmat, Tmat, Rfmat, Rbmat);

auto aBSDF = BSDFHemisphere::create(BSDFBasis::Quarter);

m_Shade = CBSDFLayerMaker::getHomogeneousDiffuseLayer(aMaterial, aBSDF);
}

public:
std::shared_ptr<CBSDFLayer> GetShade()
{
return m_Shade;
};
};

TEST_F(TestHomogenousDiffuseShade1, TestSolarProperties)
{
SCOPED_TRACE("Begin Test: Perfect diffuse shade - Solar properties.");

std::shared_ptr<CBSDFLayer> aShade = GetShade();

BSDFIntegrator aResults = aShade->getResults();

double tauDiff = aResults.DiffDiff(Side::Front, PropertySimple::T);
EXPECT_NEAR(0.000000000, tauDiff, 1e-6);

double RfDiff = aResults.DiffDiff(Side::Front, PropertySimple::R);
EXPECT_NEAR(0.550000000, RfDiff, 1e-6);

auto aT = aResults.getMatrix(Side::Front, PropertySimple::T);

Helper::writeVectorToCSV(aT.getMatrix(), TEST_DATA_DIR "/data/T.csv");

// Test only diagonal of transmittance matrix
const size_t size = aT.size();

std::vector<double> correctResults(41, 0);

std::vector<double> calculatedResults;
for(size_t i = 0; i < size; ++i)
{
calculatedResults.push_back(aT(i, i));
}

EXPECT_EQ(correctResults.size(), calculatedResults.size());
for(size_t i = 0; i < size; ++i)
{
EXPECT_NEAR(correctResults[i], calculatedResults[i], 1e-5);
}

auto aRf = aResults.getMatrix(Side::Front, PropertySimple::R);

correctResults = {0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070,
0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070,
0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070,
0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070,
0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070,
0.175070, 0.175070, 0.175070, 0.175070, 0.175070, 0.175070};

calculatedResults.clear();
for(size_t i = 0; i < size; ++i)
{
calculatedResults.push_back(aRf(i, i));
}

EXPECT_EQ(correctResults.size(), calculatedResults.size());
for(size_t i = 0; i < size; ++i)
{
EXPECT_NEAR(correctResults[i], calculatedResults[i], 1e-5);
}
}

TEST_F(TestHomogenousDiffuseShade1, AtWavelength)
{

std::shared_ptr<CBSDFLayer> aShade = GetShade();

constexpr size_t wavelengthIndex{0u};
auto aResults{aShade->getResultsAtWavelength(wavelengthIndex)};

const auto correct{0.55};
const auto result{aResults.DiffDiff(Side::Front, PropertySimple::R)};

EXPECT_NEAR(correct, result, 1e-6);
}

0 comments on commit 51ea67c

Please sign in to comment.