Skip to content
ForCADDocumentation

forcad_nurbs_surface Module

Tensor-product B-spline and NURBS surfaces.

For degrees and , the rational tensor-product surface is

Control subscripts in this module's formulas are one-based to match Fortran storage. This is equivalent to conventional zero-based notation after subtracting one from each control index.

Let and . The rational tensor basis is nonnegative and forms a partition of unity on the active domain because the weights are positive. At parameter values where the requested mixed derivative exists, for every positive total derivative order . Polynomial tensor-basis derivatives vanish when an order exceeds the degree in its direction, but rational quotient derivatives generally need not. A common positive scaling of all weights is only a projective gauge and cannot change the surface. Rational values scale nonzero weighted basis contributions; derivative recurrences share a weight gauge. Homogeneous refinement selects a common representable gauge for weights and weighted controls and restores the original weights afterward. Geometric derivatives use nested division and do not explicitly form .

Control points are flattened with direction 1 varying fastest: linear(i,j)=i+(j-1)*nc(1). The physical coordinate is the second array dimension. Omitting weights selects the polynomial tensor-product B-spline form. Exactly equal weights cancel; every nonconstant positive weight list uses rational normalization.

Each direction accepts any valid finite, nondecreasing knot vector, including uniform or nonuniform, clamped, one-sided clamped, unclamped, and periodic-form vectors. A complete cyclic knot extension together with repeated control and weight layers is verified directionally by get_parameter_topology; malformed periodic-form data remain valid bounded splines. Its active interval is [knot(degree+1), knot(nc+1)]. Optional parameter wrapping performs modulo evaluation independently by direction and does not impose geometric closure. At an interior knot of multiplicity , the spline space has guaranteed directional continuity , although special control data can be smoother. Geometry and basis queries accept one trace selector per direction (−1 left, 0 default, +1 right). The default takes the right trace internally. At a closed endpoint both sides use the inward trace.

Directional refinement applies an exact one-dimensional operator to every homogeneous control line, preserving to working precision on the active domain. Insertion and degree elevation preserve a verified periodic direction. Other non-clamped directional representations are converted by degree elevation to an equivalent active-domain open-clamped form. Interior knot removal preserves periodic directions by applying the bounded removal test to a guarded cyclic extension. For an embedded surface with Jacobian , metric , and parameter area ,

The nurbs_surface API provides evaluation, mixed basis derivatives, IGA element data, geometry-preserving refinement, surface quadrature, fitting, discrete and local continuous nearest-point searches, transformations, and VTK/IGES export. Recoverable failures are recorded in err.

Primary reference: L. Piegl and W. Tiller, The NURBS Book, 2nd ed., Springer, 1997. doi:10.1007/978-3-642-59223-2. Finite-range reference: IEEE, IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2019, 2019. IEEE 754-2019.



Interfaces

public interface compute_Tgc

Evaluate dense tensor-product surface basis values. Scalar overloads return product(nc) values; vector overloads return one row per parameter pair. Rational overloads normalize with Wc. Scalar elem selections preserve ordering and repeated indices. When size(Wc)==size(elem) differs from product(nc), weights are local to that selection; otherwise normalization uses the complete active support. For , .

  • private pure function compute_Tgc_nurbs_2d_vector(Xt, knot1, knot2, degree, nc, ng, Wc, wrap_parameters) result(Tgc)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:,:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    integer, intent(in), optional :: ng(2)
    real(kind=rk), intent(in), contiguous :: Wc(:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)

    Return Value real(kind=rk), allocatable, (:,:)

  • private pure function compute_Tgc_bspline_2d_vector(Xt, knot1, knot2, degree, nc, ng, wrap_parameters) result(Tgc)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:,:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    integer, intent(in), optional :: ng(2)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)

    Return Value real(kind=rk), allocatable, (:,:)

  • private pure function compute_Tgc_nurbs_2d_scalar(Xt, knot1, knot2, degree, nc, Wc, elem, wrap_parameters) result(Tgc)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    real(kind=rk), intent(in), contiguous :: Wc(:)
    integer, intent(in), optional :: elem(:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)

    Return Value real(kind=rk), allocatable, (:)

  • private pure function compute_Tgc_bspline_2d_scalar(Xt, knot1, knot2, degree, nc, elem, wrap_parameters) result(Tgc)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    integer, intent(in), optional :: elem(:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)

    Return Value real(kind=rk), allocatable, (:)

public interface compute_dTgc

Evaluate dense first parametric derivatives of the surface basis. Derivative component 1 is with respect to the first parameter and component 2 to the second. Values and gradients share one local pass. Scalar elem selections support either full weights or local weights when size(Wc)==size(elem) differs from product(nc). For , rational derivatives use

  • private pure subroutine compute_dTgc_nurbs_2d_vector(Xt, knot1, knot2, degree, nc, ng, Wc, dTgc, Tgc, wrap_parameters)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:,:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    integer, intent(in), optional :: ng(2)
    real(kind=rk), intent(in), contiguous :: Wc(:)
    real(kind=rk), intent(out), allocatable :: dTgc(:,:,:)
    real(kind=rk), intent(out), allocatable :: Tgc(:,:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)
  • private pure subroutine compute_dTgc_bspline_2d_vector(Xt, knot1, knot2, degree, nc, ng, dTgc, Tgc, wrap_parameters)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:,:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    integer, intent(in), optional :: ng(2)
    real(kind=rk), intent(out), allocatable :: dTgc(:,:,:)
    real(kind=rk), intent(out), allocatable :: Tgc(:,:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)
  • private pure subroutine compute_dTgc_nurbs_2d_scalar(Xt, knot1, knot2, degree, nc, Wc, dTgc, Tgc, elem, wrap_parameters)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    real(kind=rk), intent(in), contiguous :: Wc(:)
    real(kind=rk), intent(out), allocatable :: dTgc(:,:)
    real(kind=rk), intent(out), allocatable :: Tgc(:)
    integer, intent(in), optional :: elem(:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)
  • private pure subroutine compute_dTgc_bspline_2d_scalar(Xt, knot1, knot2, degree, nc, dTgc, Tgc, elem, wrap_parameters)

    Compatibility adapter to the shared local surface calculation.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rk), intent(in), contiguous :: Xt(:)
    real(kind=rk), intent(in), contiguous :: knot1(:)
    real(kind=rk), intent(in), contiguous :: knot2(:)
    integer, intent(in) :: degree(2)
    integer, intent(in) :: nc(2)
    real(kind=rk), intent(out), allocatable :: dTgc(:,:)
    real(kind=rk), intent(out), allocatable :: Tgc(:)
    integer, intent(in), optional :: elem(:)
    logical, intent(in), optional, contiguous :: wrap_parameters(:)

Derived Types

type, public ::  nurbs_surface

Mutable tensor-product B-spline or NURBS surface.

Read more…

Components

Type Visibility Attributes Name Initial
type(debug), public :: err

Recoverable diagnostic state for the most recent failed operation.

Type-Bound Procedures

procedure, public :: ansatz

Evaluate element-local physical basis data and differential area.

Read more…
procedure, public :: ansatz_element

Evaluate all quadrature data for one analysis element.

Read more…
generic, public :: basis => basis_vector, basis_scalar

Evaluate the dense rational or polynomial basis.

Read more…
generic, public :: bezier => bezier_element, bezier_all

Extract one exact Bezier element or decompose the patch.

Read more…
generic, public :: cmp_Xg => cmp_Xg_scalar, cmp_Xg_vector, cmp_Xg_grid

Evaluate a point, paired batch, or tensor grid without changing samples.

Read more…
procedure, public :: cmp_Xth_in_Xg

Build embedded active isoparametric grid lines.

Read more…
procedure, public :: cmp_area

Integrate surface area with elementwise tensor Gauss quadrature.

Read more…
procedure, public :: cmp_degree

Infer both degrees from knots and control-net dimensions.

Read more…
procedure, public :: cmp_dof_map

Map stored periodic controls to independent cyclic degrees of freedom.

Read more…
procedure, public :: cmp_elem

Build nonzero-span tensor-product IGA connectivity.

Read more…
procedure, public :: cmp_elem_Xc_vis

Build quadrilateral connectivity for the control net.

Read more…
procedure, public :: cmp_elem_Xg_vis

Build quadrilateral connectivity for cached samples.

Read more…
procedure, public :: cmp_elem_Xth

Build quadrilateral connectivity for the parameter grid.

Read more…
procedure, public :: cmp_nc

Compute control-point counts implied by knots and degrees.

Read more…
procedure, public :: create

Sample a tensor grid and cache parameters, points, and connectivity.

Read more…
generic, public :: derivative => derivative_vector, derivative_scalar

Evaluate first parametric derivatives.

Read more…
generic, public :: derivative2 => derivative2_vector, derivative2_scalar

Evaluate complete parametric Hessians.

Read more…
generic, public :: derivative_order => derivative_order_vector, derivative_order_scalar

Evaluate dense mixed derivatives.

Read more…
generic, public :: derivative_order_active => derivative_order_active_vector, derivative_order_active_scalar

Evaluate active mixed derivatives.

procedure, public :: elevate_degree

Elevate degree while preserving active-domain geometry in one direction.

Read more…
procedure, public :: export_Xc

Export the control net in legacy VTK format.

Read more…
procedure, public :: export_Xg

Export cached surface samples in legacy VTK format.

Read more…
procedure, public :: export_Xth

Export the sampled parameter surface in legacy VTK format.

Read more…
procedure, public :: export_Xth_in_Xg

Export parameter-grid lines embedded in physical space.

Read more…
procedure, public :: export_iges

Export the surface as IGES entity 128.

Read more…
procedure, public :: finalize

Release all owned and derived surface data while preserving diagnostics.

Read more…
generic, public :: get_Wc => get_Wc_all, get_Wci

Query control weights.

Read more…
generic, public :: get_Xc => get_Xc_all, get_Xci, get_Xcid

Query control-point data.

Read more…
generic, public :: get_Xg => get_Xg_all, get_Xgi, get_Xgid

Query cached geometry points.

Read more…
procedure, public :: get_Xt

Return cached parameter samples in one direction.

Read more…
procedure, public :: get_continuity

Return metadata for each distinct stored knot.

Read more…
generic, public :: get_degree => get_degree_all, get_degree_dir

Query polynomial degrees.

Read more…
procedure, public :: get_elem

Return IGA element-to-control-point connectivity.

Read more…
procedure, public :: get_elem_Xc_vis

Return control-net visualization connectivity.

Read more…
procedure, public :: get_elem_Xg_vis

Return sampled-surface visualization connectivity.

Read more…
generic, public :: get_knot => get_knoti, get_knot_all

Query knot-vector data.

Read more…
procedure, public :: get_multiplicity

Return multiplicities of all distinct stored knots in one direction.

Read more…
generic, public :: get_nc => get_nc_all, get_nc_dir

Query directional control-point counts.

Read more…
procedure, public :: get_ng

Return cached sample counts by direction.

Read more…
procedure, public :: get_parameter_topology

Classify one stored parameter topology.

Read more…
procedure, public :: get_parameter_wrapping

Report modulo parameter mapping in one direction.

Read more…
procedure, public :: insert_knots

Insert knots while preserving active-domain geometry.

Read more…
procedure, public :: is_rational

Report whether nonuniform weights affect the current basis.

Read more…
procedure, public :: is_valid

Report whether complete, internally consistent surface geometry is stored.

Read more…
procedure, public :: lsq_fit_bspline

Fit polynomial control points by structured least squares.

Read more…
procedure, public :: lsq_fit_nurbs

Fit control points and positive weights by damped nonlinear least squares.

Read more…
generic, public :: modify_Wc => modify_Wc_scalar, modify_Wc_all

Replace one weight or all positive control weights.

Read more…
generic, public :: modify_Xc => modify_Xc_scalar, modify_Xc_all

Replace one coordinate or a fixed-shape control net.

Read more…
procedure, public :: nearest_point

Select the nearest cached geometry sample.

Read more…
procedure, public :: nearest_point2

Minimize squared distance with bounded Newton iterations and backtracking.

Read more…
procedure, public :: put_to_nurbs

Map structured points to the current parameter domain and cache them.

Read more…
procedure, public :: reduce_degree

Reduce degree under one physical geometry-error budget.

Read more…
procedure, public :: remove_knots

Remove directional knots that pass an internal geometry test.

Read more…
generic, public :: reparameterize => reparameterize_interval, reparameterize_axes

Rescale or reorder parameter axes.

Read more…
procedure, public :: restrict

Extract a bounded patch on a literal parameter subinterval.

Read more…
procedure, public :: reverse

Reverse one parameter direction and its control/weight ordering.

Read more…
procedure, public :: rotate_Xc

Rotate control points in three-dimensional embedding space.

Read more…
procedure, public :: rotate_Xg

Rotate cached geometry points in three-dimensional embedding space.

Read more…
generic, public :: set => set1, set2, set3, set4

Replace surface geometry or initialize a fitting space.

Read more…
procedure, public :: set_C

Construct the predefined planar C-shaped surface.

Read more…
procedure, public :: set_elem

Replace stored IGA connectivity.

Read more…
procedure, public :: set_elem_Xc_vis

Replace control-net visualization connectivity.

Read more…
procedure, public :: set_elem_Xg_vis

Replace sampled-surface visualization connectivity.

Read more…
procedure, public :: set_half_ring

Construct an exact rational half-annulus.

Read more…
procedure, public :: set_ring

Construct an exact rational annular surface.

Read more…
procedure, public :: set_tetragon

Construct a bilinear tetragonal surface.

Read more…
procedure, public :: slice

Extract an exact isoparametric curve by fixing one parameter.

Read more…
procedure, public :: split => split_surface

Split a patch at an interior parameter, preserving both one-sided traces.

Read more…
procedure, public :: transform

Apply one affine map to control points and cached geometry.

Read more…
procedure, public :: translate_Xc

Translate the control net by a physical-space vector.

Read more…
procedure, public :: translate_Xg

Translate cached geometry points by a physical-space vector.

Read more…

Subroutines

public pure subroutine surface_geometry_derivative(patch, Xt, order, Xg, side, row_power)

Evaluate patch geometry, optionally retaining a common binary exponent per derivative row.

Arguments

Type IntentOptional Attributes Name
class(nurbs_surface), intent(in) :: patch
real(kind=rk), intent(in) :: Xt(:,:)
integer, intent(in), optional :: order(:)
real(kind=rk), intent(out), allocatable :: Xg(:,:)
integer, intent(in), optional :: side(:)
integer, intent(out), optional, allocatable :: row_power(:)