-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new algorithm for polygon clipping in solar calculations for rectangular surfaces #7574
Conversation
@XuanLuoLBL @lgentile it has been 28 days since this pull request was last updated. |
1 similar comment
@XuanLuoLBL @lgentile it has been 28 days since this pull request was last updated. |
@XuanLuoLBL This needs a unit test, please. Once that's in, please request a reviewer here in the PR. |
@XuanLuoLBL Needs doc updates, also. |
@mjwitte This branch is also ready for review, as I added those unit tests and documentation. |
@Myoldmopar Edwin, this branch is ready for review. Would you please suggest reviewers? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuanluo113 I've reviewed the idd and documentation changes. Comments below.
@Myoldmopar I've done a cursory review of the new code. Would like your eyes on this also.
doc/engineering-reference/src/climate-sky-and-solar-shading-calculations/shading-module.tex
Outdated
Show resolved
Hide resolved
doc/engineering-reference/src/climate-sky-and-solar-shading-calculations/shading-module.tex
Show resolved
Hide resolved
doc/engineering-reference/src/climate-sky-and-solar-shading-calculations/shading-module.tex
Outdated
Show resolved
Hide resolved
doc/engineering-reference/src/climate-sky-and-solar-shading-calculations/shading-module.tex
Outdated
Show resolved
Hide resolved
doc/engineering-reference/src/climate-sky-and-solar-shading-calculations/shading-module.tex
Outdated
Show resolved
Hide resolved
src/EnergyPlus/SolarShading.cc
Outdated
|
||
inline void CLIPLINE(Real64 &x1, Real64 &x2, Real64 &y1, Real64 &y2, | ||
Real64 maxX, Real64 minX, Real64 maxY, Real64 minY, bool &visible, bool &rev) { | ||
// SLATER & BARSKY 1994 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more complete citation would be good here. And the new functions should have at least a couple of comment lines stating what they do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this looks fine, but the citation is important. The CLIPLINE and CLIPRECT function names look suspiciously like they were taken from some FORTRAN source. Can you verify where this exact code came from? Also I'm not sure you're going to gain anything by trying to inline
this massive function filled with logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar @mjwitte I added the references and am trying to add line comments. I don't think it's borrowed code. It should be based on the algorithm introduced in the paper mimicking the Fortran naming style of other functions.
HCX[l1 + 2] == HCX[l1 + 3]) || | ||
((((HCY[l1] == HCY[l1 + 1] && HCX[l1] != HCX[l1 + 1]) && | ||
(HCX[l1 + 2] == HCX[l1 + 1] && HCX[l1 + 3] == HCX[l1])) && | ||
(HCY[l1 + 2] == HCY[l1 + 3])))))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard to read. Apply formatting? Also, seems it would be more efficient to move (NV2==4)
to an if block wrapping this so there's no need to check the other conditions if NV2
<>4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an FYI, native C++ operators will short circuit, so if NV2 is not 4, it will not evaluate the rest of this. But that said, yeah, this is a big messy expression. I would create three individual terms:
bool const numVertsIs4 = NV2 == 4;
bool const term1 = blah;
bool const term2 = blah;
rectFlat = numVertsIs4 || term1 || term2;
Of course better naming but that would at least make the logic here tractable.
doc/input-output-reference/src/overview/group-simulation-parameters.tex
Outdated
Show resolved
Hide resolved
@xuanluo113 Be sure to pull this branch before making additional changes. I merged in develop yesterday and fixed the unit tests for the new eio file stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few comments that should at least be discussed, and maybe requires some code changes.
HCX[l1 + 2] == HCX[l1 + 3]) || | ||
((((HCY[l1] == HCY[l1 + 1] && HCX[l1] != HCX[l1 + 1]) && | ||
(HCX[l1 + 2] == HCX[l1 + 1] && HCX[l1 + 3] == HCX[l1])) && | ||
(HCY[l1 + 2] == HCY[l1 + 3])))))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an FYI, native C++ operators will short circuit, so if NV2 is not 4, it will not evaluate the rest of this. But that said, yeah, this is a big messy expression. I would create three individual terms:
bool const numVertsIs4 = NV2 == 4;
bool const term1 = blah;
bool const term2 = blah;
rectFlat = numVertsIs4 || term1 || term2;
Of course better naming but that would at least make the logic here tractable.
src/EnergyPlus/SolarShading.cc
Outdated
|
||
inline void CLIPLINE(Real64 &x1, Real64 &x2, Real64 &y1, Real64 &y2, | ||
Real64 maxX, Real64 minX, Real64 maxY, Real64 minY, bool &visible, bool &rev) { | ||
// SLATER & BARSKY 1994 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this looks fine, but the citation is important. The CLIPLINE and CLIPRECT function names look suspiciously like they were taken from some FORTRAN source. Can you verify where this exact code came from? Also I'm not sure you're going to gain anything by trying to inline
this massive function filled with logic.
@Myoldmopar @mjwitte I've addressed all comments except for the coding style and comment ones for the two newly added solar clipping functions. Still working on this. |
Regressions locally look all clean, just eio diffs. I'm merging this. |
thanks. |
Pull request overview
There exists an extensive amount of literature on polygon clipping when constrained to rectangular surfaces. The current polygon clipping method implemented in EnergyPlus, using the Sutherland-Hodgman algorithm, is a performance hotspot. The method is generalized for clipping area of all shapes, but in EnergyPlus simulations runs, are often called with only rectangular surfaces.
We propose a negligible amount of code to check if the clipping surface is rectangular. And if so,
we redirect to a new method using the
Slater & Barsky
algorithm.Pull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.