Skip to content
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

CLIP odd code #4315

Open
DeadParrot opened this issue Jun 23, 2014 · 2 comments
Open

CLIP odd code #4315

DeadParrot opened this issue Jun 23, 2014 · 2 comments
Labels
PriorityLow This defect or feature has been declared low priority SeverityMedium This defect is medium severity, indicating moderate impact and generally no workaround available

Comments

@DeadParrot
Copy link
Contributor

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
Copy link
Contributor

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
#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
Copy link
Contributor

jmarrec commented Jul 19, 2022

state.dataSolarShading->NVS = NABOVE + 2;
state.dataSolarShading->NumVertInShadowOrClippedSurface = NABOVE + 2;
Real64 ZVT_N, ZVT_P(ZVT(1));
XVT(NVT + 1) = XVT(1);
YVT(NVT + 1) = YVT(1);
ZVT(NVT + 1) = ZVT_P;
for (int N = 1, P = 2; N <= NVT; ++N, ++P) {
ZVT_N = ZVT_P;
ZVT_P = ZVT(P);
if (ZVT_N >= 0.0 && ZVT_P < 0.0) { // Line enters plane of receiving surface
Real64 const ZVT_fac(1.0 / (ZVT_P - ZVT_N));
XIN = (ZVT_P * XVT(N) - ZVT_N * XVT(P)) * ZVT_fac;
YIN = (ZVT_P * YVT(N) - ZVT_N * YVT(P)) * ZVT_fac;
} else if (ZVT_N <= 0.0 && ZVT_P > 0.0) { // Line exits plane of receiving surface
NEXT = N + 1;
Real64 const ZVT_fac(1.0 / (ZVT_P - ZVT_N));
XOUT = (ZVT_P * XVT(N) - ZVT_N * XVT(P)) * ZVT_fac;
YOUT = (ZVT_P * YVT(N) - ZVT_N * YVT(P)) * ZVT_fac;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PriorityLow This defect or feature has been declared low priority SeverityMedium This defect is medium severity, indicating moderate impact and generally no workaround available
Projects
None yet
Development

No branches or pull requests

5 participants