Skip to content
ForCADDocumentation
Browse guide contents ↓

Public Fortran API

Import the names your program uses from the forcad module. Use real(rk) for model data and the _rk suffix for real literals.

use forcad, only: rk, nurbs_curve

Geometry and construction

Task Public interface
Define, evaluate, edit, or measure a patch nurbs_curve, nurbs_surface, nurbs_volume
Construct geometry from existing profiles extrude, revolve, sweep, loft
Group patches and register their interfaces nurbs_multipatch_curve, nurbs_multipatch_surface, nurbs_multipatch_volume, multipatch_connection
Integrate a physical quantity Curve length, surface area, volume

Call a generic such as extrude by its public name. Its reference page lists the argument types for each supported overload.

Built-in shapes

Choose a constructor on the type of geometry you want. The circle and ring constructors place their base in the XY plane at the specified three-coordinate center. All radii, lengths and translations use the same physical unit as your model.

Geometry Public constructors Example
Circular curve set_circle, set_half_circle, set_C Build a circle and extract one arc
Rectangular or annular surface set_tetragon, set_ring, set_half_ring, set_C Extrude a rectangular surface
Rectangular or annular volume set_hexahedron, set_ring, set_half_ring, set_C Build a tube and cut a section

For a custom control lattice, use set with the coordinates and weights described below. To position the result, apply a transform about a pivot.

Grids and numerical utilities

Name Result
ndgrid Tensor grid coordinates from two or three coordinate vectors
hexahedron_Xc Control coordinates for an axis-aligned rectangular volume
rotation A three-dimensional rotation matrix from three angles in degrees
solve Solution of a dense square system with one or more right-hand sides
rk Working real kind for coordinates, weights, and parameters

Patch data and evaluation

Let be the total number of control points and the number of physical coordinates per point. For a surface with controls along U and along V, . For a volume, .

Input to set Shape and convention
Control points, Xc A real(rk) array of shape (N, d). Each row is a point. U varies fastest, followed by V, then W.
Weights, Wc An optional real(rk) vector of length in the same order as Xc. Each weight must be finite and positive. Omit Wc for unit weights.
Explicit knots For control points and degree in one direction, supply nondecreasing knots. With one-based indexing, the active interval is .

For a volume control with one-based indices , the corresponding row of Xc and Wc is

For a surface, omit the last term. For example, the volume control is row 8 when each direction has two controls. Move this control in Fortran.

A polynomial patch can store its unit weights implicitly. For a valid patch with no stored weights, get_Wc() returns an empty array. Studio shows their effective value of one in the control editor.

Use cmp_Xg to evaluate positions at specified parameters. Use create to retain a sampled grid for export_Xg. After modify_Xc or modify_Wc, call create() to refresh the positions on a previously sampled grid.

See Evaluate a surface point and its tangents for physical derivatives and Evaluate the rational basis for the contribution of each control point.

Point queries, fitting, and analysis

Public call What it returns Worked example
nearest_point / nearest_point2 A cached sample index and position / a location on the continuous patch with its parameters Compare the two surface queries, locate a point in a volume
lsq_fit_bspline Updated controls fitted to physical observations at supplied parameters Fit a profile, fit panel heights on a grid
lsq_fit_nurbs Fitted control positions and weights on the chosen spline space Fit a quarter-ring volume and check an independent point
ansatz_element Local basis values, physical gradients and quadrature weights, with optional geometry derivatives Integrate a field, differentiate arc length
assemble_sensitivities Patch-local derivatives combined for independent multipatch controls and log weights Length gradient at a shared control, volume gradients at a shared face
cmp_elem(shared=.true.) / interface_quadrature Global element connectivity / paired interface parameters and integration weights Solve across two volumes and verify face flux

Diagnostics

Check patch%err%ok after a construction or edit. Recover from a rejected edit shows how to print the diagnostic and retry with corrected input.