Skip to content

Commit

Permalink
Merged develop; resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Aug 14, 2024
2 parents bbfe61b + 463af86 commit 5c09ebf
Show file tree
Hide file tree
Showing 3 changed files with 368 additions and 161 deletions.
245 changes: 84 additions & 161 deletions src/EnergyPlus/SolarShading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
// POSSIBILITY OF SUCH DAMAGE.

// C++ Headers
#include <algorithm>
#include <cassert>
#include <cmath>
#include <memory>
Expand Down Expand Up @@ -414,7 +415,6 @@ void GetShadowingInput(EnergyPlusData &state)
int NumNumbers;
int NumAlphas;
int IOStat;
int Found = 0;
auto &cCurrentModuleObject = state.dataIPShortCut->cCurrentModuleObject;
state.dataIPShortCut->rNumericArgs({1, 4}) = 0.0; // so if nothing gotten, defaults will be maintained.
state.dataIPShortCut->cAlphaArgs(1) = "";
Expand Down Expand Up @@ -2586,7 +2586,6 @@ void AnisoSkyViewFactors(EnergyPlusData &state)
Real64 Epsilon; // Sky clearness parameter
Real64 Delta; // Sky brightness parameter
Real64 CosIncAngBeamOnSurface; // Cosine of incidence angle of beam solar on surface
Real64 IncAng; // Incidence angle of beam solar on surface (radians)
int EpsilonBin; // Sky clearness (Epsilon) bin index
Real64 AirMass; // Relative air mass
Real64 AirMassH; // Intermediate variable for relative air mass calculation
Expand Down Expand Up @@ -2651,8 +2650,6 @@ void AnisoSkyViewFactors(EnergyPlusData &state)
CosIncAngBeamOnSurface = -1.0;
}

IncAng = std::acos(CosIncAngBeamOnSurface);

ViewFactorSkyGeom = state.dataSurface->Surface(SurfNum).ViewFactorSky;
state.dataSolarShading->SurfMultIsoSky(SurfNum) = ViewFactorSkyGeom * (1.0 - F1);
// 0.0871557 below corresponds to a zenith angle of 85 deg
Expand Down Expand Up @@ -3140,19 +3137,17 @@ bool polygon_contains_point(int const nsides, // number of sides (ver
// Using/Aliasing
using namespace DataVectorTypes;

// Return value
bool inside; // return value, true=inside, false = not inside
// return value, true=inside, false = not inside

EP_SIZE_CHECK(polygon_3d, nsides);

int i;
int ip1;

// Object Data
Array1D<Vector_2d> polygon(nsides);
Vector_2d point;

inside = false;
bool inside = false;
if (ignorex) {
for (int i = 1; i <= nsides; ++i) {
polygon(i).x = polygon_3d(i).y;
Expand All @@ -3179,7 +3174,7 @@ bool polygon_contains_point(int const nsides, // number of sides (ver
point.x = point.y = 0.0; // Elim possibly used uninitialized warnings
}

for (i = 1; i <= nsides; ++i) {
for (int i = 1; i <= nsides; ++i) {

if (i < nsides) {
ip1 = i + 1;
Expand Down Expand Up @@ -3868,162 +3863,99 @@ inline bool d_eq(Real64 a, Real64 b)
return std::abs(a - b) < 2.0;
}

void CLIPLINE(Real64 &x1, Real64 &x2, Real64 &y1, Real64 &y2, Real64 maxX, Real64 minX, Real64 maxY, Real64 minY, bool &visible, bool &rev)
void CLIPLINE(Real64 &x0, Real64 &x1, Real64 &y0, Real64 &y1, Real64 maxX, Real64 minX, Real64 maxY, Real64 minY, bool &visible)
{

// Line segment clipping
// Reference:
// Slater, M., Barsky, B.A.
// Liang, Y.D., Barsky, B.A., Slater, M.
// 2D line and polygon clipping based on space subdivision.
// The Visual Computer 10, 407–422 (1994).
Real64 dx, dy, e, xinc, yinc, tempVar;
bool needX = true, needY = true;
int c1, c2;

if (x1 > x2) { // reverse for efficiency
tempVar = x1;
x1 = x2;
x2 = tempVar;
tempVar = y1;
y1 = y2;
y2 = tempVar;

// Tweaked via microbenchmarking to improve efficiency

bool rev = false;
if (x0 > x1) { // reverse for efficiency
std::swap(x0, x1);
std::swap(y0, y1);
rev = true;
}
if (x1 > maxX || x2 < minX) return; // x is positive
if (x1 < minX) {
if (y1 < minY) {
if (y2 < minY) return;
c1 = 0;
dx = x2 - x1;
dy = y2 - y1;
e = dy * (minX - x1) + dx * (y1 - minY);
} else if (y1 > maxY) {
if (y2 > maxY) return;
c1 = 6;
dx = x2 - x1;
dy = y2 - y1;
e = dy * (minX - x1) + dx * (y1 - maxY);
} else {
c1 = 3;
dx = x2 - x1;
dy = y2 - y1;
if (dy > 0) {
e = dy * (minX - x1) + dx * (y1 - maxY);
} else {
e = dy * (minX - x1) + dx * (y1 - minY);
}

if (x0 > maxX || x1 < minX) {
// Both points are outside the clip window, so they can't cross it
return;
}

// defining variables
Real64 const dx = x1 - x0; // >= 0
Real64 const dy = y1 - y0;

Real64 const q1 = x0 - minX;
Real64 const q2 = maxX - x0;
Real64 const q3 = y0 - minY;
Real64 const q4 = maxY - y0;

Real64 u1 = 0;
Real64 u2 = 1;

if ((dx == 0 && (q1 < 0 || q2 < 0)) || (dy == 0 && (q3 < 0 || q4 < 0))) {
// Line is parallel to clipping window
return;
}
if (dx != 0) {
Real64 const r1 = q1 / -dx;
if (r1 > u1) {
u1 = r1;
}
} else {
if (y1 < minY) {
if (y2 < minY) return;
c1 = 1;
dx = x2 - x1;
dy = y2 - y1;
e = dy * (maxX - x1) + dx * (y1 - minY);
} else if (y1 > maxY) {
if (y2 > maxY) return;
c1 = 7;
dx = x2 - x1;
dy = y2 - y1;
e = dy * (maxX - x1) + dx * (y1 - maxY);
} else {
visible = true;
if (x2 <= maxX && (y2 >= minY && y2 <= maxY)) return;
c1 = 4;
dx = x2 - x1;
dy = y2 - y1;
if (dy > 0) {
e = dy * (maxX - x1) + dx * (y1 - maxY);
} else {
e = dy * (maxX - x1) + dx * (y1 - minY);
}
Real64 const r2 = q2 / dx;
if (r2 < u2) {
u2 = r2;
}
}
c2 = c1;
if (dy > 0) {
while (true) {
if (e < 0.0) {
if (c2 == 1)
return;
else if (c2 == 3) {
visible = true;
x1 = minX;
y1 = maxY + General::SafeDivide(e, dx);
if (x2 <= maxX && y2 <= maxY) return;
} else if (c2 == 4) {
x2 = maxX;
y2 = maxY + General::SafeDivide(e, dx);
return;
}
if (needX) {
xinc = dy * (maxX - minX);
needX = false;
}
e += xinc;
c2 += 1;
} else {
if (c2 == 3)
return;
else if (c2 == 1) {
visible = true;
x1 = maxX - General::SafeDivide(e, dy);
y1 = minY;
if (x2 <= maxX && y2 <= maxY) return;
} else if (c2 == 4) {
x2 = maxX - General::SafeDivide(e, dy);
y2 = maxY;
return;
}
if (needY) {
yinc = dx * (maxY - minY);
needY = false;
}
e -= yinc;
c2 += 3;
if (dy != 0) {
Real64 const r3 = q3 / -dy;
Real64 const r4 = q4 / dy;
if (dy > 0) {
if (r3 > u1) {
u1 = r3;
}
}
} else {
while (true) {
if (e >= 0.0) {
if (c2 == 7)
return;
else if (c2 == 3) {
visible = true;
x1 = minX;
y1 = minY + General::SafeDivide(e, dx);
if (x2 <= maxX && y2 >= minY) return;
} else if (c2 == 4) {
x2 = maxX;
y2 = minY + General::SafeDivide(e, dx);
return;
}
if (needX) {
xinc = dy * (maxX - minX);
needX = false;
}
e += xinc;
c2 += 1;
} else {
if (c2 == 3)
return;
else if (c2 == 7) {
visible = true;
x1 = maxX - General::SafeDivide(e, dy);
y1 = maxY;
if (x2 <= maxX && y2 >= minY) return;
} else if (c2 == 4) {
x2 = maxX - General::SafeDivide(e, dy);
y2 = minY;
return;
}
if (needY) {
yinc = dx * (maxY - minY);
needY = false;
}
e += yinc;
c2 -= 3;
if (r4 < u2) {
u2 = r4;
}
} else {
if (r4 > u1) {
u1 = r4;
}
if (r3 < u2) {
u2 = r3;
}
}
}

if (u1 > u2) { // reject
// Line is outside the clipping window
return;
}

visible = true;

Real64 const xn0 = x0 + dx * u1;
Real64 const yn0 = y0 + dy * u1;

Real64 const xn1 = x0 + dx * u2;
Real64 const yn1 = y0 + dy * u2;

if (rev) {
x0 = xn1;
y0 = yn1;
x1 = xn0;
y1 = yn0;
} else {
x0 = xn0;
y0 = yn0;
x1 = xn1;
y1 = yn1;
}
}

void CLIPRECT(EnergyPlusData &state, int const NS2, int const NV1, int &NV3)
Expand Down Expand Up @@ -4063,20 +3995,11 @@ void CLIPRECT(EnergyPlusData &state, int const NS2, int const NV1, int &NV3)
Real64 x1 = x_1, x2 = x_2, y1 = y_1, y2 = y_2;

bool visible = false;
bool rev = false;
CLIPLINE(x_1, x_2, y_1, y_2, maxX, minX, maxY, minY, visible, rev);
CLIPLINE(x_1, x_2, y_1, y_2, maxX, minX, maxY, minY, visible);
if (visible) {
if ((x_1 != x1 || y_1 != y1) || (x_2 != x2 || y_2 != y2)) {
INTFLAG = true;
}
if (rev) { // undo reverse
Real64 tempVar = x_1;
x_1 = x_2;
x_2 = tempVar;
tempVar = y_1;
y_1 = y_2;
y_2 = tempVar;
}
// if line on edge, or inside, add both points
if (arrc == 0 || ((neq(arrx[arrc - 1], x_1) || neq(arry[arrc - 1], y_1)) && (neq(arrx[0], x_1) || neq(arry[0], y_1)))) {
arrx[arrc] = x_1;
Expand Down
2 changes: 2 additions & 0 deletions src/EnergyPlus/SolarShading.hh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ namespace SolarShading {

void CLIP(EnergyPlusData &state, int const NVT, Array1D<Real64> &XVT, Array1D<Real64> &YVT, Array1D<Real64> &ZVT);

void CLIPLINE(Real64 &x0, Real64 &x1, Real64 &y0, Real64 &y1, Real64 maxX, Real64 minX, Real64 maxY, Real64 minY, bool &visible);

void CTRANS(EnergyPlusData &state,
int const NS, // Surface number whose vertex coordinates are being transformed
int const NGRS, // Base surface number for surface NS
Expand Down
Loading

5 comments on commit 5c09ebf

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_fe_default_debug (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (3659 of 3659 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_fe_default_debug (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3700 of 3700 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_fe_default_debug (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2073 of 2073 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_fe_default_debug (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (796 of 796 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_fe_default_debug (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2866 of 2866 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.