NREL / EnergyPlus

EnergyPlus™ is a whole building energy simulation program that engineers, architects, and researchers use to model both energy consumption and water use in buildings.
https://energyplus.net
Other
1.09k stars 383 forks source link

CLIP odd code #4315

Open DeadParrot opened 10 years ago

DeadParrot commented 10 years ago

Another odd looking bit of code from CLIP:

NVS = NABOVE + 2;
NumVertInShadowOrClippedSurface = NABOVE + 2;
XVT( NVT + 1 ) = XVT( 1 );
YVT( NVT + 1 ) = YVT( 1 );
ZVT( NVT + 1 ) = ZVT( 1 );
for ( N = 1; N <= NVT; ++N ) {
   if ( ZVT( N ) >= 0.0 && ZVT( N + 1 ) < 0.0 ) { // Line enters plane of receiving surface
      XIN = ( ZVT( N + 1 ) * XVT( N ) - ZVT( N ) * XVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) );
      YIN = ( ZVT( N + 1 ) * YVT( N ) - ZVT( N ) * YVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) );
   } else if ( ZVT( N ) <= 0.0 && ZVT( N + 1 ) > 0.0 ) { // Line exits plane of receiving surface
      NEXT = N + 1;
      XOUT = ( ZVT( N + 1 ) * XVT( N ) - ZVT( N ) * XVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) );
      YOUT = ( ZVT( N + 1 ) * YVT( N ) - ZVT( N ) * YVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) );
   }
}

It just keeps going on to next N after setting the IN or OUT coords, only keeping the last ones. It also uses the IN and OUT values even if they are never set. If the usage assures that the IN and OUT cases are satisfied exactly once over all N then I guess it is OK but that should really be documented and assert-checked.

Comments?

rraustad commented 10 years ago

Again needing help from the author....

IF (NABOVE+NON == NVT) THEN ! Rename the unclipped shadow casting surface.

 NVS=NVT
 NumVertInShadowOrClippedSurface = NVT
 DO N = 1, NVT
   XVC(N) = XVT(N)
   YVC(N) = YVT(N)
   ZVC(N) = ZVT(N)
 END DO

ELSEIF (NABOVE == 0) THEN ! Totally submerged shadow casting surface.

 NVS=0
 NumVertInShadowOrClippedSurface = 0

ELSE ! Remove (clip) that portion of the shadow casting surface. which is below the receiving surface

 NVS        = NABOVE + 2
 NumVertInShadowOrClippedSurface = NABOVE + 2
 XVT(NVT+1) = XVT(1)
 YVT(NVT+1) = YVT(1)
 ZVT(NVT+1) = ZVT(1)
 DO N = 1, NVT
   IF (ZVT(N) >= 0.0d0 .AND. ZVT(N+1) < 0.0d0) THEN ! Line enters 

plane of receiving surface

     XIN=(ZVT(N+1)*XVT(N)-ZVT(N)*XVT(N+1))/(ZVT(N+1)-ZVT(N))
     YIN=(ZVT(N+1)*YVT(N)-ZVT(N)*YVT(N+1))/(ZVT(N+1)-ZVT(N))

   ELSEIF (ZVT(N) <= 0.0d0 .AND. ZVT(N+1) > 0.0d0) THEN ! Line exits 

plane of receiving surface

     NEXT=N+1
     XOUT=(ZVT(N+1)*XVT(N)-ZVT(N)*XVT(N+1))/(ZVT(N+1)-ZVT(N))
     YOUT=(ZVT(N+1)*YVT(N)-ZVT(N)*YVT(N+1))/(ZVT(N+1)-ZVT(N))

   END IF
 END DO

       ! Renumber the vertices of the clipped shadow casting 

surface. so they are still counter-clockwise sequential.

 XVC(1)   = XOUT
 YVC(1)   = YOUT
 ZVC(1)   = 0.0d0
 XVC(NVS) = XIN
 YVC(NVS) = YIN
 ZVC(NVS) = 0.0d0
 DO N = 1, NABOVE
   IF (NEXT > NVT) NEXT = 1
   XVC(N+1) = XVT(NEXT)
   YVC(N+1) = YVT(NEXT)
   ZVC(N+1) = ZVT(NEXT)
   NEXT     = NEXT+1
 END DO

END IF

On 6/23/2014 6:18 PM, Stuart Mentzer wrote:

Another odd looking bit of code from CLIP:

NVS = NABOVE + 2; NumVertInShadowOrClippedSurface = NABOVE + 2; XVT( NVT + 1 ) = XVT( 1 ); YVT( NVT + 1 ) = YVT( 1 ); ZVT( NVT + 1 ) = ZVT( 1 ); for ( N = 1; N <= NVT; ++N ) { if ( ZVT( N ) >= 0.0 && ZVT( N + 1 ) < 0.0 ) { // Line enters plane of receiving surface XIN = ( ZVT( N + 1 ) * XVT( N ) - ZVT( N ) * XVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) ); YIN = ( ZVT( N + 1 ) * YVT( N ) - ZVT( N ) * YVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) ); } else if ( ZVT( N ) <= 0.0 && ZVT( N + 1 ) > 0.0 ) { // Line exits plane of receiving surface NEXT = N + 1; XOUT = ( ZVT( N + 1 ) * XVT( N ) - ZVT( N ) * XVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) ); YOUT = ( ZVT( N + 1 ) * YVT( N ) - ZVT( N ) * YVT( N + 1 ) ) / ( ZVT( N + 1 ) - ZVT( N ) ); } }

It just keeps going on to next N after setting the IN or OUT coords, only keeping the last ones. It also uses the IN and OUT values even if they are never set. If the usage assures that the IN and OUT cases are satisfied exactly once over all N then I guess it is OK but that should really be documented and assert-checked.

Comments?

— Reply to this email directly or view it on GitHub https://github.com/NREL/EnergyPlusTeam/issues/4315.

Richard Raustad Senior Research Engineer Florida Solar Energy Center 1679 Clearlake Road Cocoa, FL 32922 Ph: (321)638-1454 http://www.fsec.ucf.edu/en/

Electric Vehicle Transportation Center http://evtc.fsec.ucf.edu/

jmarrec commented 2 years ago

https://github.com/NREL/EnergyPlus/blob/0c9b8c4944b5f06edb000bf0d766f067830af0ae/src/EnergyPlus/SolarShading.cc#L3306-L3325