Skip to content

Commit

Permalink
Streamline MakeMirrorSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
mjwitte committed May 9, 2024
1 parent 85662bb commit 28ec9eb
Showing 1 changed file with 40 additions and 110 deletions.
150 changes: 40 additions & 110 deletions src/EnergyPlus/SurfaceGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9732,129 +9732,59 @@ namespace SurfaceGeometry {
// SUBROUTINE INFORMATION:
// AUTHOR Linda Lawrie
// DATE WRITTEN June 2002
// MODIFIED na
// RE-ENGINEERED na

// PURPOSE OF THIS SUBROUTINE:
// This subroutine creates a "mirror" surface using the indicated surface.
// This is the simple approach for bi-directional shading devices. If, perchance,
// the user has already taken care of this (e.g. fins in middle of wall), there will
// be extra shading devices shown.

// METHODOLOGY EMPLOYED:
// Reverse the vertices in the original surface. Add "bi" to name.

using namespace Vectors;

int Vert;
int NVert;
Real64 SurfWorldAz;
Real64 SurfTilt;
int n;
// TYPE(Vector) :: temp1

NVert = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Vertex.allocate(NVert);
// doesn't work when Vertex are pointers SurfaceTmp(SurfNum+1)=SurfaceTmp(SurfNum)
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Name = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Name;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Construction = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Construction;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ConstructionStoredInputValue =
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ConstructionStoredInputValue;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Class = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Class;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).GrossArea = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).GrossArea;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Area = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Area;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Azimuth = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Azimuth;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Height = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Height;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Reveal = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Reveal;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Shape = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Shape;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Sides = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Tilt = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Tilt;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).convOrientation =
Convect::GetSurfConvOrientation(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Tilt);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Width = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Width;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).HeatTransSurf = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).HeatTransSurf;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).BaseSurfName = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).BaseSurfName;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).BaseSurf = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).BaseSurf;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ZoneName = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ZoneName;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Zone = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Zone;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ExtBoundCondName = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ExtBoundCondName;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ExtBoundCond = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ExtBoundCond;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ExtSolar = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ExtSolar;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ExtWind = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ExtWind;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ViewFactorGround = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorGround;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ViewFactorSky = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorSky;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ViewFactorGroundIR = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorGroundIR;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).ViewFactorSkyIR = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorSkyIR;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).SchedShadowSurfIndex = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).SchedShadowSurfIndex;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).SchedMinValue = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).SchedMinValue;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).IsTransparent = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).IsTransparent;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).activeWindowShadingControl =
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).activeWindowShadingControl;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).windowShadingControlList =
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).windowShadingControlList;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).HasShadeControl = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).HasShadeControl;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).activeShadedConstruction =
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).activeShadedConstruction;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).FrameDivider = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).FrameDivider;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Multiplier = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Multiplier;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).NetAreaShadowCalc = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NetAreaShadowCalc;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Perimeter = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Perimeter;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).IsConvex = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).IsConvex;

for (Vert = 1; Vert <= state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides; ++Vert) {
state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1).Vertex(Vert) = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Vertex(NVert);
--NVert;
}
++SurfNum;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Name = "Mir-" + state.dataSurfaceGeometry->SurfaceTmp(SurfNum - 1).Name;

// TH 3/26/2010
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).MirroredSurf = true;

if (state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides > 2) {
CreateNewellAreaVector(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Vertex,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NewellAreaVector);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).GrossArea = VecLength(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NewellAreaVector);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Area = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).GrossArea;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NetAreaShadowCalc = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Area;
CreateNewellSurfaceNormalVector(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Vertex,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NewellSurfaceNormalVector);
DetermineAzimuthAndTilt(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Vertex,
SurfWorldAz,
SurfTilt,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).lcsx,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).lcsy,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).lcsz,
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NewellSurfaceNormalVector);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Azimuth = SurfWorldAz;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Tilt = SurfTilt;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).convOrientation =
Convect::GetSurfConvOrientation(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Tilt);
auto &origSurface = state.dataSurfaceGeometry->SurfaceTmp(SurfNum);
auto &newSurface = state.dataSurfaceGeometry->SurfaceTmp(SurfNum + 1);
newSurface = origSurface;

int nVert = origSurface.Sides;
// Reverse the vertices in the original surface. Add "MIR-" to name.
for (int Vert = 1; Vert <= state.dataSurfaceGeometry->SurfaceTmp(SurfNum).Sides; ++Vert) {
newSurface.Vertex(Vert) = origSurface.Vertex(nVert);
--nVert;
}
newSurface.Name = "Mir-" + origSurface.Name;
newSurface.MirroredSurf = true;

if (newSurface.Sides > 2) {
Vectors::CreateNewellAreaVector(newSurface.Vertex, newSurface.Sides, newSurface.NewellAreaVector);
newSurface.GrossArea = Vectors::VecLength(newSurface.NewellAreaVector);
newSurface.Area = newSurface.GrossArea;
newSurface.NetAreaShadowCalc = newSurface.Area;
Vectors::CreateNewellSurfaceNormalVector(newSurface.Vertex, newSurface.Sides, newSurface.NewellSurfaceNormalVector);
Real64 SurfWorldAz = 0.0;
Real64 SurfTilt = 0.0;
Vectors::DetermineAzimuthAndTilt(
newSurface.Vertex, SurfWorldAz, SurfTilt, newSurface.lcsx, newSurface.lcsy, newSurface.lcsz, newSurface.NewellSurfaceNormalVector);
newSurface.Azimuth = SurfWorldAz;
newSurface.Tilt = SurfTilt;
newSurface.convOrientation = Convect::GetSurfConvOrientation(newSurface.Tilt);

// Sine and cosine of azimuth and tilt
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).SinAzim = std::sin(SurfWorldAz * Constant::DegToRadians);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).CosAzim = std::cos(SurfWorldAz * Constant::DegToRadians);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).SinTilt = std::sin(SurfTilt * Constant::DegToRadians);
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).CosTilt = std::cos(SurfTilt * Constant::DegToRadians);
newSurface.SinAzim = std::sin(SurfWorldAz * Constant::DegToRadians);
newSurface.CosAzim = std::cos(SurfWorldAz * Constant::DegToRadians);
newSurface.SinTilt = std::sin(SurfTilt * Constant::DegToRadians);
newSurface.CosTilt = std::cos(SurfTilt * Constant::DegToRadians);
// Outward normal unit vector (pointing away from room)
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).NewellSurfaceNormalVector;
for (n = 1; n <= 3; ++n) {
if (std::abs(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n) - 1.0) < 1.e-06)
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n) = +1.0;
if (std::abs(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n) + 1.0) < 1.e-06)
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n) = -1.0;
if (std::abs(state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n)) < 1.e-06)
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).OutNormVec(n) = 0.0;
newSurface.OutNormVec = newSurface.NewellSurfaceNormalVector;
for (int n = 1; n <= 3; ++n) {
if (std::abs(newSurface.OutNormVec(n) - 1.0) < 1.e-06) newSurface.OutNormVec(n) = +1.0;
if (std::abs(newSurface.OutNormVec(n) + 1.0) < 1.e-06) newSurface.OutNormVec(n) = -1.0;
if (std::abs(newSurface.OutNormVec(n)) < 1.e-06) newSurface.OutNormVec(n) = 0.0;

This comment has been minimized.

Copy link
@rraustad

rraustad May 9, 2024

Contributor

These changes look correct. There are about 250 1.0e-6 or 1.e-06 or 1.e-6, etc. Real64 constexpr oneMillionth = 1.0e-6;

This comment has been minimized.

Copy link
@mjwitte

mjwitte May 9, 2024

Author Contributor

Hmm, so now that you've pointed this out, I'll work on replacing these - at least any that have to do with geometry.

}

// Can perform tests on this surface here
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorSky = 0.5 * (1.0 + state.dataSurfaceGeometry->SurfaceTmp(SurfNum).CosTilt);
// The following IR view factors are modified in subr. SkyDifSolarShading if there are shadowing
// surfaces
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorSkyIR = state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorSky;
state.dataSurfaceGeometry->SurfaceTmp(SurfNum).ViewFactorGroundIR = 0.5 * (1.0 - state.dataSurfaceGeometry->SurfaceTmp(SurfNum).CosTilt);
newSurface.ViewFactorSky = 0.5 * (1.0 + newSurface.CosTilt);
// The following IR view factors are modified in subr. SkyDifSolarShading if there are shadowing surfaces
newSurface.ViewFactorSkyIR = newSurface.ViewFactorSky;
newSurface.ViewFactorGroundIR = 0.5 * (1.0 - newSurface.CosTilt);
++SurfNum; // Calling function expects incremented argument on return
}
}

Expand Down

4 comments on commit 28ec9eb

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

InterzonewindowsAndSurfs20PlusVertices (mjwitte) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3604 of 3604 tests passed, 0 test warnings)

Build Badge Test 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.

InterzonewindowsAndSurfs20PlusVertices (mjwitte) - Win64-Windows-10-VisualStudio-16: OK (2775 of 2775 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.

InterzonewindowsAndSurfs20PlusVertices (mjwitte) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (791 of 791 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.

InterzonewindowsAndSurfs20PlusVertices (mjwitte) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (1987 of 1987 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.