Skip to content

Commit

Permalink
Perforated effective openness geometry renamed to Type. Also, solver …
Browse files Browse the repository at this point in the history
…is simplified so it will use const matrix and vector on the input.
  • Loading branch information
vidanovic committed Jun 10, 2024
1 parent 07b86a8 commit a628db6
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 75 deletions.
55 changes: 31 additions & 24 deletions src/Common/src/LinearSolver.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
#include <stdexcept>
#include <cassert>
#include <numeric>
#include <algorithm>
#include <cmath>

#include "LinearSolver.hpp"
#include "SquareMatrix.hpp"

#include <cmath>


namespace FenestrationCommon
{
std::vector<double> solveSystem(SquareMatrix t_MatrixA, std::vector<double> & t_VectorB)
std::vector<double> solveSystem(const SquareMatrix & t_MatrixA,
const std::vector<double> & t_VectorB)
{
if(t_MatrixA.size() != t_VectorB.size())
{
throw std::runtime_error(
"Matrix and vector for system of linear equations are not same size.");
"Matrix and vector for system of linear equations are not the same size.");
}

std::vector<size_t> index = t_MatrixA.makeUpperTriangular();
// Make a copy of t_VectorB to work with
std::vector<double> resultVector = t_VectorB;

const int size = int(t_MatrixA.size());
// Make a copy of t_MatrixA to work with (if necessary, depending on makeUpperTriangular
// implementation)
SquareMatrix matrixA = t_MatrixA;

std::vector<size_t> index = matrixA.makeUpperTriangular();
const size_t size = matrixA.size();

int ii = -1;
for(int i = 0; i < size; ++i)
for(size_t i = 0; i < size; ++i)
{
size_t ll = index[i];
double sum = t_VectorB[ll];
t_VectorB[ll] = t_VectorB[i];
std::swap(resultVector[ll], resultVector[i]);
double sum = resultVector[i];
if(ii != -1)
{
for(int j = ii; j <= i - 1; ++j)
for(size_t j = ii; j < i; ++j)
{
sum -= t_MatrixA(i, j) * t_VectorB[j];
} // j
sum -= matrixA(i, j) * resultVector[j];
}
}
else if(sum != 0.0)
{
ii = int(i);
ii = static_cast<int>(i);
}
t_VectorB[i] = sum;
} // i
resultVector[i] = sum;
}

for(int i = (size - 1); i >= 0; --i)
for(int i = static_cast<int>(size) - 1; i >= 0; --i)
{
double sum = t_VectorB[i];
for(int j = i + 1; j < size; ++j)
double sum = resultVector[i];
for(size_t j = i + 1; j < size; ++j)
{
sum -= t_MatrixA(i, j) * t_VectorB[j];
} // j
t_VectorB[i] = sum / t_MatrixA(i, i);
} // i
sum -= matrixA(i, j) * resultVector[j];
}
resultVector[i] = sum / matrixA(i, i);
}

return t_VectorB;
return resultVector;
}

} // namespace FenestrationCommon
2 changes: 1 addition & 1 deletion src/Common/src/LinearSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace FenestrationCommon
{
class SquareMatrix;

std::vector<double> solveSystem(SquareMatrix t_MatrixA, std::vector<double> & t_VectorB);
std::vector<double> solveSystem(const SquareMatrix& t_MatrixA, const std::vector<double> & t_VectorB);
} // namespace FenestrationCommon
2 changes: 1 addition & 1 deletion src/Common/tst/units/LinearSolver1.unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ TEST_F(TestLinearSolver1, TestSolverException)
{
EXPECT_EQ(
err.what(),
std::string("Matrix and vector for system of linear equations are not same size."));
std::string("Matrix and vector for system of linear equations are not the same size."));
}
}
4 changes: 1 addition & 3 deletions src/SingleLayerOptics/src/VenetianSegments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ namespace SingleLayerOptics
m_SlatSegmentsMesh.surfaceIndexes,
m_Cell->viewFactors())};

std::vector<double> aSolution = solveSystem(slatsDiffuseRadiancesMatrix, B);

return aSolution[m_SlatSegmentsMesh.numberOfSegments - 1];
return solveSystem(slatsDiffuseRadiancesMatrix, B)[m_SlatSegmentsMesh.numberOfSegments - 1];
}

double CVenetianCellEnergy::R_dif_dif()
Expand Down
14 changes: 7 additions & 7 deletions src/Tarcog/src/EffectiveOpenness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ namespace EffectiveLayers
width, height, thickness, openness, slatAngle, slatWidth, {0.041, 0.0, 0.27, 0.012})
{}

EffectiveLayerType1::EffectiveLayerType1(double width,
EffectiveLayerCommonType::EffectiveLayerCommonType(double width,
double height,
double thickness,
const ShadeOpenness & openness) :
EffectiveLayer(width, height, thickness, openness, {0.078, 1.2, 1.0, 1.0})
{}

EffectiveOpenness EffectiveLayerType1::getEffectiveOpenness()
EffectiveOpenness EffectiveLayerCommonType::getEffectiveOpenness()
{
const auto area{m_Width * m_Height};
const auto Ah_eff{area * coefficients.C1
Expand All @@ -125,7 +125,7 @@ namespace EffectiveLayers
return {Ah_eff, Al_eff, Ar_eff, Atop_eff, Abop_eff, m_ShadeOpenness.Ah};
}

double EffectiveLayerType1::effectiveThickness()
double EffectiveLayerCommonType::effectiveThickness()
{
return m_Thickness;
}
Expand All @@ -134,28 +134,28 @@ namespace EffectiveLayers
double height,
double thickness,
const ShadeOpenness & openness) :
EffectiveLayerType1(width, height, thickness, openness)
EffectiveLayerCommonType(width, height, thickness, openness)
{}

EffectiveLayerDiffuse::EffectiveLayerDiffuse(double width,
double height,
double thickness,
const ShadeOpenness & openness) :
EffectiveLayerType1(width, height, thickness, openness)
EffectiveLayerCommonType(width, height, thickness, openness)
{}

EffectiveLayerWoven::EffectiveLayerWoven(double width,
double height,
double thickness,
const ShadeOpenness & openness) :
EffectiveLayerType1(width, height, thickness, openness)
EffectiveLayerCommonType(width, height, thickness, openness)
{}

EffectiveLayerBSDF::EffectiveLayerBSDF(double width,
double height,
double thickness,
const ShadeOpenness & openness) :
EffectiveLayerType1(width, height, thickness, openness)
EffectiveLayerCommonType(width, height, thickness, openness)
{}

EffectiveLayerOther::EffectiveLayerOther(double width,
Expand Down
23 changes: 11 additions & 12 deletions src/Tarcog/src/EffectiveOpenness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace EffectiveLayers
double Ar;
double Atop;
double Abot;
double
FrontPorosity; // Geometrical openness used to calculate equivalent layer conductivity
// Geometrical openness used to calculate equivalent layer conductivity
double FrontPorosity;
};

struct Coefficients
Expand Down Expand Up @@ -111,19 +111,19 @@ namespace EffectiveLayers
};

//! \brief Used for effective calculations for Perforated, Woven, Diffuse shade and BSDF
class EffectiveLayerType1 : public EffectiveLayer
class EffectiveLayerCommonType : public EffectiveLayer
{
public:
EffectiveLayerType1(double width,
double height,
double thickness,
const ShadeOpenness & openness);
EffectiveLayerCommonType(double width,
double height,
double thickness,
const ShadeOpenness & openness);

EffectiveOpenness getEffectiveOpenness() override;
double effectiveThickness() override;
};

class EffectiveLayerPerforated : public EffectiveLayerType1
class EffectiveLayerPerforated : public EffectiveLayerCommonType
{
public:
EffectiveLayerPerforated(double width,
Expand All @@ -132,7 +132,7 @@ namespace EffectiveLayers
const ShadeOpenness & openness);
};

class EffectiveLayerDiffuse : public EffectiveLayerType1
class EffectiveLayerDiffuse : public EffectiveLayerCommonType
{
public:
EffectiveLayerDiffuse(double width,
Expand All @@ -141,7 +141,7 @@ namespace EffectiveLayers
const ShadeOpenness & openness);
};

class EffectiveLayerWoven : public EffectiveLayerType1
class EffectiveLayerWoven : public EffectiveLayerCommonType
{
public:
EffectiveLayerWoven(double width,
Expand All @@ -150,7 +150,7 @@ namespace EffectiveLayers
const ShadeOpenness & openness);
};

class EffectiveLayerBSDF : public EffectiveLayerType1
class EffectiveLayerBSDF : public EffectiveLayerCommonType
{
public:
EffectiveLayerBSDF(double width,
Expand All @@ -170,5 +170,4 @@ namespace EffectiveLayers
EffectiveOpenness getEffectiveOpenness() override;
double effectiveThickness() override;
};

} // namespace EffectiveLayers
2 changes: 1 addition & 1 deletion src/Tarcog/src/Layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace Tarcog::ISO15099
std::shared_ptr<CIGUSolidLayer>
Layers::shading(double thickness,
double conductivity,
EffectiveLayers::EffectiveOpenness effectiveOpenness,
const EffectiveLayers::EffectiveOpenness & effectiveOpenness,
double frontEmissivity,
double frontIRTransmittance,
double backEmissivity,
Expand Down
2 changes: 1 addition & 1 deletion src/Tarcog/src/Layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Tarcog::ISO15099
static std::shared_ptr<CIGUSolidLayer>
shading(double thickness,
double conductivity,
EffectiveLayers::EffectiveOpenness effectiveOpenness =
const EffectiveLayers::EffectiveOpenness & effectiveOpenness =
EffectiveLayers::EffectiveOpenness(0, 0, 0, 0, 0, 0),
double frontEmissivity = 0.84,
double frontIRTransmittance = 0.0,
Expand Down
13 changes: 6 additions & 7 deletions src/Tarcog/src/PermeabilityFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,21 @@ namespace ThermalPermeability
XYDimension::XYDimension(const double x, const double y) : x(x), y(y)
{}

double openness(const Geometry t_Geometry,
double openness(const Type t_Type,
const double t_SpacingX,
const double t_SpacingY,
const double t_DimensionX,
const double t_DimensionY)
{
const auto cellArea{t_SpacingX * t_SpacingY};
std::map<Geometry, std::function<double(const double, const double)>> opennessFraction{
{Geometry::Circular, {[&](const double x, const double y) {
std::map<Type, std::function<double(const double, const double)>> opennessFraction{
{Type::Circular, {[&](const double x, const double y) {
return (x / 2) * (y / 2) * ConstantsData::WCE_PI / cellArea;
}}},
{Geometry::Square,
{[&](const double x, const double y) { return x * y / cellArea; }}},
{Geometry::Rectangular,
{Type::Square, {[&](const double x, const double y) { return x * y / cellArea; }}},
{Type::Rectangular,
{[&](const double x, const double y) { return x * y / cellArea; }}}};
return opennessFraction.at(t_Geometry)(t_DimensionX, t_DimensionY);
return opennessFraction.at(t_Type)(t_DimensionX, t_DimensionY);
}

XYDimension diameterToXYDimension(const double diameter)
Expand Down
4 changes: 2 additions & 2 deletions src/Tarcog/src/PermeabilityFactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ThermalPermeability

namespace Perforated
{
enum class Geometry
enum class Type
{
Circular,
Square,
Expand All @@ -35,7 +35,7 @@ namespace ThermalPermeability

XYDimension diameterToXYDimension(double diameter);

double openness(Geometry t_Geometry,
double openness(Type t_Type,
double t_SpacingX,
double t_SpacingY,
double t_DimensionX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestDoubleOutsidePerforatedShadeExterior_UValue : public testing::Test
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};

const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TestDoubleOutsidePerforatedShade_SHGC : public testing::Test
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};

const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestDoubleOutsidePerforatedShade_UValue : public testing::Test
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};

const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestGapBetweenIrradiatedExteriorShadingAndGlassForcedVentilationInsideAir
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestGapBetweenIrradiatedExteriorShadingAndGlassForcedVentilationOutsideAir
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestGapBetweenIrradiatedGlassAndInteriorShadingFastForcedVentilationInside
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestGapBetweenIrradiatedGlassAndInteriorShadingForcedVentilationInsideAir
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestGapBetweenIrradiatedGlassAndInteriorShadingForcedVentilationInsideAirT
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TestGapBetweenIrradiatedGlassAndInteriorShadingNaturalConvection : public
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestGapBetweenIrradiatedGlassAndInteriorShadingNaturalConvection1mmGap : p
const auto CellDimension{
ThermalPermeability::Perforated::diameterToXYDimension(2 * radius)};
const auto frontOpenness{ThermalPermeability::Perforated::openness(
ThermalPermeability::Perforated::Geometry::Circular,
ThermalPermeability::Perforated::Type::Circular,
x,
y,
CellDimension.x,
Expand Down
Loading

0 comments on commit a628db6

Please sign in to comment.