Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(vector), | intent(in) | :: | center | |||
type(vector), | intent(in) | :: | axis | |||
real(kind=psb_dpk_), | intent(in) | :: | radius | |||
type(vertex), | intent(in) | :: | vertices(:) |
FUNCTION try_cylinder_r2(center,axis,radius,vertices)
USE class_vector
IMPLICIT NONE
REAL(psb_dpk_) :: try_cylinder_r2
TYPE(vector),INTENT(IN) :: center
TYPE(vector),INTENT(IN) :: axis
REAL(psb_dpk_),INTENT(IN) :: radius
TYPE(vertex),INTENT(IN) :: vertices(:)
! Local variables
REAL(psb_dpk_) :: s_t ! total deviations
INTEGER :: nverts ! number of vertices
INTEGER :: i
REAL(psb_dpk_) :: err ! cumulative error
TYPE(vector) :: centroid, xrad
! Calculate R2 for the cylinder
nverts = SIZE(vertices)
err = calc_error(center,axis,radius,vertices)
centroid = vector_(0.0d0, 0.0d0, 0.0d0)
DO i = 1,nverts
centroid = centroid + vertices(i)%position_()
ENDDO
centroid = ( 1.0d0/float(nverts) )* centroid
s_t = 0.0
! calculate cumulative error
DO i = 1,nverts
! calculate position relative to the centroid
xrad = centroid - vertices(i)%position_()
s_t = s_t + xrad%mag()**2
ENDDO
s_t = s_t / float(nverts)
try_cylinder_r2 = ( s_t - err ) / s_t
END FUNCTION try_cylinder_r2