Map an existing hex mesh into a volume
Use put_to_nurbs when you already have node coordinates and cell connectivity and want to carry their layout into a NURBS volume. For each of the first three input columns, ForCAD maps the column minimum and maximum to the ends of the corresponding knot interval. It then evaluates the volume at each resulting parameter triple. Each column needs a nonzero range.
This example maps two adjacent hexahedra into an 8 × 4 × 2 block. The middle layer lies one quarter of the way along the input X range, so it should land at X = 2. The two cells should still share the same four nodes.
program map_mesh
use forcad, only: nurbs_volume, rk
implicit none
type(nurbs_volume) :: block
real(rk), parameter :: x(3) = [10.0_rk, 11.0_rk, 14.0_rk]
real(rk) :: nodes(12, 3)
real(rk), allocatable :: mapped(:, :)
integer :: cells(2, 8), i, j, k, row
do k = 0, 1
do j = 0, 1
do i = 1, 3
row = i + 3*j + 6*k
nodes(row, :) = [x(i), real(j, rk), real(k, rk)]
end do
end do
end do
cells(1, :) = [1, 2, 4, 5, 7, 8, 10, 11]
cells(2, :) = [2, 3, 5, 6, 8, 9, 11, 12]
call block%set_hexahedron(L=[8.0_rk, 4.0_rk, 2.0_rk], nc=[2, 2, 2])
call block%put_to_nurbs(nodes, cells)
if (.not. block%err%ok) error stop "Could not map the mesh"
mapped = block%get_Xg()
print '(3(f5.1,1x))', mapped(11, :)
if (any(block%get_elem_Xg_vis() /= cells)) error stop "Connectivity changed"
call block%export_Xg("mapped.vtk", encoding="ASCII")
if (.not. block%err%ok) error stop "Could not export the mesh"
end program map_mesh
The program prints 2.0 4.0 2.0. The VTK file contains 12 points and two hexahedra. ForCAD takes one-based connectivity in tensor-product order, with U varying fastest. Its VTK writer handles the file's node ordering.
Use structured sampling when you want ForCAD to choose a regular grid. Use a volume point query when the input is already in physical space and you need the parameter coordinates of a particular point.