Construct a periodic NURBS curve
Create a quadratic loop with four independent controls. At the seam, the end of the last span must meet the beginning of the first span with the same first derivative. Evaluate both sides before using the loop in a mesh or analysis.
program periodic_curve
use forcad, only: rk, nurbs_curve
implicit none
type(nurbs_curve) :: loop
real(rk) :: controls(6,2), weights(6), knots(9), position_gap, tangent_gap
integer, allocatable :: dof(:)
integer :: i
controls(1:4,1) = [1._rk, 0._rk, -1._rk, 0._rk]
controls(1:4,2) = [0._rk, 1._rk, 0._rk, -1._rk]
weights(1:4) = [1._rk, 1.5_rk, 1._rk, 1.5_rk]
controls(5:6,:) = controls(1:2,:)
weights(5:6) = weights(1:2)
knots = [(real(i,rk), i=-2,6)]
call loop%set(Xc=controls, Wc=weights, knot=knots, degree=2, wrap_parameters=.false.)
if (.not. loop%err%ok) error stop "Invalid curve"
if (loop%get_parameter_topology() /= "periodic") error stop "Expected a periodic loop"
position_gap = norm2(loop%cmp_Xg(0._rk, side=1) - loop%cmp_Xg(4._rk, side=-1))
tangent_gap = norm2(loop%cmp_Xg(0._rk, order=1, side=1) - loop%cmp_Xg(4._rk, order=1, side=-1))
if (max(position_gap,tangent_gap) > 100*epsilon(1._rk)) error stop "Seam mismatch"
dof = loop%cmp_dof_map()
print '(a,*(1x,i0))', 'Control IDs:', dof
print '(a,2(1x,es9.2))', 'Position and tangent gaps:', position_gap, tangent_gap
end program
The active interval is . The knots continue at the same spacing beyond both ends, and the last two controls repeat the first two positions and weights. With parameter wrapping disabled, the two endpoint evaluations use opposite ends of the stored curve. Both gaps should be zero to roundoff, giving a seam. Set wrap_parameters=.true. if evaluations outside the interval should repeat every four parameter units.
The control IDs are 1 2 3 4 1 2. When assembling on knot spans, use these IDs to give both stored copies of each seam control the same unknown.