Skip to content

Commit

Permalink
Forming irradiance equations finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
vidanovic committed Nov 4, 2024
1 parent f554fc5 commit 5101dda
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 39 deletions.
81 changes: 55 additions & 26 deletions src/SingleLayerOptics/src/VenetianSegments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace SingleLayerOptics
CVenetianCellEnergy::CVenetianCellEnergy(
const std::shared_ptr<CVenetianCellDescription> & t_Cell,
const LayerProperties & properties) :
m_Cell(t_Cell), m_LayerProperties(properties), m_SlatSegmentsMesh(*m_Cell),
m_Cell(t_Cell),
m_LayerProperties(properties),
m_SlatSegmentsMesh(*m_Cell),
slatsRadiancesMatrix(formIrradianceMatrix(m_Cell->viewFactors(), m_LayerProperties))
{}

Expand All @@ -39,7 +41,8 @@ namespace SingleLayerOptics
{
if(!m_SlatIrradiances.count(t_Direction))
{
const auto irradiance = slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_Direction);
const auto irradiance =
slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_Direction);
std::lock_guard<std::mutex> lock(irradianceMutex);
m_SlatIrradiances[t_Direction] = irradiance;
}
Expand All @@ -54,7 +57,8 @@ namespace SingleLayerOptics
{
if(!m_SlatIrradiances.count(t_Direction))
{
const auto irradiance = slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_Direction);
const auto irradiance =
slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_Direction);
std::lock_guard<std::mutex> lock(irradianceMutex);
m_SlatIrradiances[t_Direction] = irradiance;
}
Expand All @@ -65,9 +69,31 @@ namespace SingleLayerOptics
double CVenetianCellEnergy::T_dir_dir(const CBeamDirection & t_IncomingDirection,
const CBeamDirection & t_OutgoingDirection)
{
const auto insideSegLength = m_Cell->segmentLength(m_SlatSegmentsMesh.numberOfSegments);
assert(insideSegLength != 0);

if(!m_SlatIrradiances.count(t_IncomingDirection))
{
const auto irradiance{slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_IncomingDirection)};
auto irradiance{slatIrradiances(
m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_IncomingDirection)};

std::vector<BeamSegmentView> BVFin =
beamVector(Side::Back,
m_SlatSegmentsMesh.numberOfSegments,
m_Cell->beamViewFactors(Side::Front, t_IncomingDirection),
m_Cell->T_dir_dir(Side::Front, t_IncomingDirection));

for(size_t i = 1u; i < m_SlatSegmentsMesh.numberOfSegments; ++i)
{
irradiance[i].E_f *=
insideSegLength
* std::cos(FenestrationCommon::radians(t_IncomingDirection.profileAngle()))
/ m_Cell->segmentLength(i);
irradiance[i].E_b *=
insideSegLength
* std::cos(FenestrationCommon::radians(t_IncomingDirection.profileAngle()))
/ m_Cell->segmentLength(i);
}

std::lock_guard<std::mutex> lock(irradianceMutex);
m_SlatIrradiances[t_IncomingDirection] = irradiance;
Expand All @@ -82,7 +108,7 @@ namespace SingleLayerOptics

const auto & radiance = m_SlatRadiances.at(t_IncomingDirection);

std::vector<BeamSegmentView> BVF =
std::vector<BeamSegmentView> BVFout =
beamVector(Side::Back,
m_SlatSegmentsMesh.numberOfSegments,
m_Cell->beamViewFactors(Side::Back, t_OutgoingDirection),
Expand All @@ -93,24 +119,24 @@ namespace SingleLayerOptics
// Counting starts from one because this should exclude beam to beam energy.
for(size_t i = 1; i < radiance.size(); ++i)
{
aResult +=
radiance[i] * BVF[i].percentViewed * BVF[i].viewFactor / m_Cell->segmentLength(i);
aResult += radiance[i]
* std::cos(FenestrationCommon::radians(t_IncomingDirection.profileAngle()))
* BVFout[i].percentViewed * BVFout[i].viewFactor
* std::abs(BVFout[i].dotProduct) * m_Cell->segmentLength(i);
}

// Area weighting. Needs to be multiplied with number of segments
double insideSegLength = m_Cell->segmentLength(m_SlatSegmentsMesh.numberOfSegments);

assert(insideSegLength != 0);

return insideSegLength * aResult;
return aResult
/ (insideSegLength
* std::cos(FenestrationCommon::radians(t_OutgoingDirection.profileAngle())));
}

double CVenetianCellEnergy::R_dir_dir(const CBeamDirection & t_IncomingDirection,
const CBeamDirection & t_OutgoingDirection)
{
if(!m_SlatIrradiances.count(t_IncomingDirection))
{
const auto irradiance{slatIrradiances(m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_IncomingDirection)};
const auto irradiance{slatIrradiances(
m_Cell, slatsRadiancesMatrix, m_SlatSegmentsMesh, t_IncomingDirection)};

std::lock_guard<std::mutex> lock(irradianceMutex);
m_SlatIrradiances[t_IncomingDirection] = irradiance;
Expand Down Expand Up @@ -295,6 +321,7 @@ namespace SingleLayerOptics
}
B[index].viewFactor = aVF.value;
B[index].percentViewed = aVF.percentHit;
B[index].dotProduct = aVF.dotProduct;
}

const std::map<Side, size_t> sideIndex{{Side::Front, numberOfSegments}, {Side::Back, 0}};
Expand Down Expand Up @@ -341,12 +368,13 @@ namespace SingleLayerOptics
auto fillUpperLeft = [&](size_t i, size_t j) -> double {
if(i != numSeg - 1)
{
double value = viewFactors(m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[i + 1],
m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[j])
* properties.Tf
+ viewFactors(m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[i],
m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[j])
* properties.Rf;
double value =
viewFactors(m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[i + 1],
m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[j])
* properties.Tf
+ viewFactors(m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[i],
m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[j])
* properties.Rf;
if(i == j)
{
value -= 1;
Expand Down Expand Up @@ -385,12 +413,13 @@ namespace SingleLayerOptics
auto fillLowerRight = [&](size_t i, size_t j) -> double {
if(i != 0)
{
double value = viewFactors(m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[i - 1],
m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[j])
* properties.Tb
+ viewFactors(m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[i],
m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[j])
* properties.Rb;
double value =
viewFactors(m_SlatSegmentsMesh.surfaceIndexes.frontSideMeshIndex[i - 1],
m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[j])
* properties.Tb
+ viewFactors(m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[i],
m_SlatSegmentsMesh.surfaceIndexes.backSideMeshIndex[j])
* properties.Rb;
if(i == j)
{
value -= 1;
Expand Down
3 changes: 2 additions & 1 deletion src/SingleLayerOptics/src/VenetianSegments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ namespace SingleLayerOptics
//! of the slat that actually is being hit by the beam.
struct BeamSegmentView
{
BeamSegmentView() : viewFactor(0), percentViewed(0)
BeamSegmentView() : viewFactor(0), percentViewed(0), dotProduct(0)
{}
double viewFactor;
double percentViewed;
double dotProduct;
};

struct SegmentIndexes
Expand Down
2 changes: 1 addition & 1 deletion src/Viewer/src/Geometry2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Viewer
FenestrationCommon::SquareMatrix viewFactors();

// Shifts all segments for given coordinates
CGeometry2D Translate(double const t_x, double const t_y) const;
[[nodiscard]] CGeometry2D Translate(double t_x, double t_y) const;

// First and last point function are necessary to make connection between different
// enclosures
Expand Down
22 changes: 14 additions & 8 deletions src/Viewer/src/Geometry2DBeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ namespace Viewer
BeamViewFactor::BeamViewFactor(size_t const t_Geometry2DIndex,
size_t const t_SegmentIndex,
double const t_Value,
double const t_PercentHit) :
double const t_PercentHit,
double const t_dotProduct) :
enclosureIndex(t_Geometry2DIndex),
segmentIndex(t_SegmentIndex),
value(t_Value),
percentHit(t_PercentHit)
percentHit(t_PercentHit),
dotProduct(t_dotProduct)
{}

bool BeamViewFactor::operator==(BeamViewFactor const & t_BVF) const
Expand Down Expand Up @@ -104,13 +106,11 @@ namespace Viewer
////////////////////////////////////////////////////////////////////////////////////////

CDirect2DRay::CDirect2DRay(const CDirect2DBeam & t_Beam1, const CDirect2DBeam & t_Beam2) :
m_Beam1(t_Beam1),
m_Beam2(t_Beam2)
m_Beam1(t_Beam1), m_Beam2(t_Beam2)
{}

CDirect2DRay::CDirect2DRay(const CViewSegment2D & t_Ray1, const CViewSegment2D & t_Ray2) :
m_Beam1(t_Ray1),
m_Beam2(t_Ray2)
m_Beam1(t_Ray1), m_Beam2(t_Ray2)
{}

double CDirect2DRay::rayNormalHeight() const
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace Viewer
/ std::abs(beamRay.cosAngle(currentSegment.getNormal()));
percentHit = segmentHitLength / currentSegment.length();
auto aTest = find(
aViewFactors.begin(), aViewFactors.end(), BeamViewFactor(e, s, 0, 0));
aViewFactors.begin(), aViewFactors.end(), BeamViewFactor(e, s, 0, 0, 0));
if(aTest != aViewFactors.end())
{
auto & aVF = *aTest;
Expand All @@ -339,7 +339,13 @@ namespace Viewer
}
else
{
auto aVF = BeamViewFactor(e, s, viewFactor, percentHit);
const auto xs = std::cos(-FenestrationCommon::radians(t_ProfileAngle));
const auto ys = std::sin(-FenestrationCommon::radians(t_ProfileAngle));
const auto & seg{m_Geometries2D[e].segments()[s].getNormal()};
const auto dotProduct =
xs * (seg.endPoint().x() - seg.startPoint().x())
+ ys * (seg.endPoint().y() - seg.startPoint().y());
auto aVF = BeamViewFactor(e, s, viewFactor, percentHit, dotProduct);
aViewFactors.push_back(aVF);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Viewer/src/Geometry2DBeam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ namespace Viewer
BeamViewFactor(size_t t_Geometry2DIndex,
size_t t_SegmentIndex,
double t_Value,
double t_PercentHit);
double t_PercentHit,
double t_DotProduct);
bool operator==(BeamViewFactor const & t_BVF1) const;
// static bool isEqual( const BeamViewFactor& t_VF1, const BeamViewFactor& t_VF2 );
size_t enclosureIndex;
size_t segmentIndex;
double value;
double percentHit;
double dotProduct; // Dot product of the beam and segment normal
};

////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/Viewer/src/ViewSegment2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Viewer
CSegment2D(t_StartPoint, t_EndPoint)
{}

CViewSegment2D CViewSegment2D::getNormal()
CViewSegment2D CViewSegment2D::getNormal() const
{
assert(length() > 0);
double xn = (m_EndPoint.y() - m_StartPoint.y()) / length();
Expand Down
2 changes: 1 addition & 1 deletion src/Viewer/src/ViewSegment2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Viewer
CViewSegment2D() = default;
CViewSegment2D(const CPoint2D & t_StartPoint, const CPoint2D & t_EndPoint);

CViewSegment2D getNormal();
CViewSegment2D getNormal() const;

bool operator==(CViewSegment2D const & rhs) const;
bool operator!=(CViewSegment2D const & rhs) const;
Expand Down

0 comments on commit 5101dda

Please sign in to comment.