Skip to content

10. Cut cells ​

A conservative cut-cell solver needs, for every cell the wall crosses, the fluid fraction of the cell, the fluid fraction of each face, and the separate fluid pieces when the wall splits a cell. Before its first step it also needs which piece talks to which, where a small piece sends its state, and integrals of higher order than the centroid. FOSSIL computes all of it exactly from the geometry. This chapter builds it up in five short runs: one grid line, the 2-D cut cells of the section of chapter 7, the 3-D cut cells of the dragon, then the solver support on top of them.

Crossings of a grid line ​

Every cut-cell quantity starts from where the wall crosses the grid lines. Take the 48 × 48 block of cells of side 0.025 around the section and find the grid line with the most crossings.

f90
use fossil,     only : curve_object, STATUS_OK
use penf,       only : I4P, R8P
use vecfor,     only : vector_R8P

implicit none
type(curve_object)        :: section
real(R8P)                 :: x(49), solid
real(R8P),    allocatable :: t(:)
integer(I4P), allocatable :: segments(:)
logical,      allocatable :: entering(:)
integer(I4P)              :: i, j, best, n, nbest, status

call section%load_from_file(file_name='dragon-section.dat', status=status)       ! chapter 7
if (status /= STATUS_OK) error stop 'cannot load dragon-section.dat'
x = [(-0.6_R8P + 0.025_R8P * i, i = 0, 48)]          ! the cell edges of a 48 x 48 block, h = 0.025
best = 1 ; nbest = 0
do j = 1, 49                                          ! the grid line x = x(j), along y, with the most crossings
   call section%line_crossings(axis=2_I4P, a=x(j), t0=x(1), t1=x(49), t=t, segments=segments, entering=entering, n=n)
   if (n > nbest) then
      best = j ; nbest = n
   endif
enddo
call section%line_crossings(axis=2_I4P, a=x(best), t0=x(1), t1=x(49), t=t, segments=segments, entering=entering, n=n)
print '(A,I0,A,F7.4,A,I0,A)', 'grid line ', best, ' (x = ', x(best), '): ', n, ' crossings'
do i = 1, n
   print '(A,F9.5,A,I4,A,A)', '  y = ', t(i), '  segment ', segments(i), '  ', merge('enters', 'leaves', entering(i))
enddo
solid = sum(t(2:n:2) - t(1:n-1:2))                    ! in +y: enter, leave, enter, leave, ...
print '(A,F9.6)', 'solid length of the line: ', solid
  • line_crossings(axis=, a=, t0=, t1=, t=, segments=, entering=, n=) returns the crossings of one axis-aligned line with the curve: axis=1 is the line along u at v = a, axis=2 the line along v at u = a (for this section, normal to z, u = x and v = y). The parameters t in [t0, t1] are sorted, each with its segment and whether the line, travelling in +axis, enters the solid there.
  • The side of a vertex against the line is decided by the exact orient2d, with a symbolic tie-break when a vertex lies on the line: each crossing is counted once, so the entering and leaving flags alternate on a closed curve. The positions are rounded, the topology is not.
$ tut10_a_crossings
grid line 24 (x = -0.0250): 8 crossings
  y =  -0.30294  segment  111  enters
  y =  -0.12994  segment  134  leaves
  y =  -0.04604  segment   18  enters
  y =   0.12736  segment   27  leaves
  y =   0.18151  segment   33  enters
  y =   0.32503  segment   44  leaves
  y =   0.35471  segment   51  enters
  y =   0.40365  segment   57  leaves
solid length of the line:  0.538856

The line x = −0.025 crosses the section 8 times, entering and leaving in turn. Between an entering crossing and the next leaving one the line is in the solid, 0.538856 of its length in all.

the dragon section on the 48 by 48 grid, seen from above with y across: the grid line x = -0.025 crosses it 8 times, its four solid intervals drawn in yellow between a teal dot where the line enters the solid and an ember dot where it leaves

Cut cells of a section ​

The crossings of all the grid lines, walked cell by cell, give the cut cells.

f90
use fossil, only : curve_object, cut_cells_2d_t, STATUS_OK
use penf,   only : I4P, R8P

implicit none
type(curve_object)   :: section
type(cut_cells_2d_t) :: cut
real(R8P)            :: x(49), h
integer(I4P)         :: i, j, k, c(2), p, status

call section%load_from_file(file_name='dragon-section.dat', status=status)
if (status /= STATUS_OK) error stop 'cannot load dragon-section.dat'
h = 0.025_R8P
x = [(-0.6_R8P + h * i, i = 0, 48)]                  ! the same 48 x 48 block as step 1
call section%cut_cells(x=x, y=x, cut=cut)
print '(A,I0,A,I0,A,I0)', 'cells: fluid ', count(cut%alpha == 1._R8P), ', solid ', count(cut%alpha == 0._R8P), &
                          ', cut ', count(cut%alpha > 0._R8P .and. cut%alpha < 1._R8P)
print '(A,F10.7,A,F10.7)', 'solid area from alpha ', sum(1._R8P - cut%alpha) * h**2, ', area of the curve ', &
                           section%get_area()
  • cut_cells(x=, y=, cut=) takes the cell edges of a block, strictly increasing in each direction, and fills a cut_cells_2d_t. The fluid is outside the solid. Per cell (nx × ny arrays): alpha, the fluid area fraction, 1 in the fluid and 0 in the solid; aperture(4, :, :), the fluid fraction of the four edges in the order −x, +x, −y, +y; centroid, wet_length, wet_centroid and wet_normal, the fluid centroid and the wetted wall.
  • A cell whose boundary does not close (an open loop) is flagged in closed, with alpha = -1.
f90
i = 24                                                ! the -x edges of column 24 lie on the line of step 1
print '(A,F9.6)', 'solid length of the line x = -0.025 from the apertures: ', sum(1._R8P - cut%aperture(1, i, :)) * h
c = maxloc(cut%wet_length)                            ! the cell with the longest wall
print '(A,I0,A,I0,A,F7.4,A,4F7.4)', 'cell (', c(1), ',', c(2), '): alpha ', cut%alpha(c(1), c(2)), &
                                    ', apertures -x +x -y +y', cut%aperture(:, c(1), c(2))
print '(A,F7.4,A,2F8.4)', '  wall length / h ', cut%wet_length(c(1), c(2)) / h, ', normal integral / h ', &
                          cut%wet_normal(:, c(1), c(2)) / h
print '(A,2F8.4)', '  aperture differences (+x - -x, +y - -y)    ', &
                   cut%aperture(2, c(1), c(2)) - cut%aperture(1, c(1), c(2)), &
                   cut%aperture(4, c(1), c(2)) - cut%aperture(3, c(1), c(2))
$ tut10_b_cells2d
cells: fluid 2141, solid 72, cut 91
solid area from alpha  0.0726092, area of the curve  0.0726092
solid length of the line x = -0.025 from the apertures:  0.538856
cell (23,41): alpha  0.3303, apertures -x +x -y +y 0.6170 0.8541 0.0000 0.4930
  wall length / h  2.0921, normal integral / h   0.2371  0.4930
  aperture differences (+x - -x, +y - -y)      0.2371  0.4930
pieces in the block 2234, cells with two or more 2
  cell (22,20) alpha  0.2061
    piece 914: area / h^2  0.1891, apertures 0.0000 0.5595 0.0000 0.6813
    piece 915: area / h^2  0.0171, apertures 0.4351 0.0000 0.0000 0.0785
  cell (23,41) alpha  0.3303
    piece 1872: area / h^2  0.2108, apertures 0.0000 0.8541 0.0000 0.1734
    piece 1873: area / h^2  0.1196, apertures 0.6170 0.0000 0.0000 0.3196
  • 91 of the 2304 cells are cut. The solid area summed from the fractions equals the area of the curve to the printed digits, 0.0726092.
  • The −x edges of column 24 lie on the grid line of the first run: their solid parts add up to 0.538856, the solid length that line_crossings gave. The apertures are the crossings of the grid lines, read edge by edge.
  • In the cell with the longest wall, (23, 41), the normal integral of the wall, pointing into the fluid, is (0.2371, 0.4930) h: the differences of the opposite apertures, +x minus −x and +y minus −y. The fluid region of the cell is closed, so its boundary normals cancel. A finite-volume update that uses the apertures and wet_normal keeps a uniform flow uniform.

the 2-D cut cells around the dragon section, each cell shaded by its fluid fraction alpha from cream (solid, 0) to sepia (fluid, 1), the section drawn on top, and the two cells holding two fluid pieces outlined in yellow

Fluid pieces ​

Where two walls cross the same cell, its fluid can come in parts that do not touch. A solver must keep their states apart: one fraction per cell would let mass leak across the solid between them.

f90
print '(A,I0,A,I0)', 'pieces in the block ', cut%np, ', cells with two or more ', count(cut%pieces > 1)
do j = 1, 48 ; do i = 1, 48
   if (cut%pieces(i, j) < 2) cycle
   p = cut%first_piece(i, j)                          ! its pieces are p, p + 1, ...
   print '(A,I0,A,I0,A,F7.4)', '  cell (', i, ',', j, ') alpha ', cut%alpha(i, j)
   do k = p, p + cut%pieces(i, j) - 1
      print '(A,I0,A,F7.4,A,4F7.4)', '    piece ', k, ': area / h^2 ', cut%piece_area(k) / h**2, &
                                     ', apertures', cut%piece_aperture(:, k)
   enddo
enddo ; enddo
  • pieces(i, j) is the number of fluid pieces of a cell, numbered from first_piece(i, j) in the block-wide piece arrays: piece_cell, piece_area, piece_centroid, piece_wet_length, piece_wet_normal and piece_aperture(4, :). A cell with one piece is that piece; the block has np pieces in all.
  • piece_iv_start, piece_iv_edge, piece_iv_lo and piece_iv_hi list the fluid intervals each piece owns on the cell edges. Two pieces of one cell share no interval, so their apertures add up to the cell's.

The last lines of the run above: of the 2234 pieces, two cells hold two. In cell (22, 20), between the first two lobes of the section, the pieces are 0.1891 and 0.0171 of the cell, and they own disjoint edges: the large one +x and +y, the small one −x and a 0.0785 sliver of +y. Their fractions add up to the cell's 0.2061.

cell (22, 20) of the section, seen from above: two walls cross it, the solid between them cream; the first piece, 0.189 of the cell, owns the fluid intervals drawn as teal bands on two edges, with its centroid in teal; the second, 0.017, a narrow wedge, owns the ember bands, with its centroid in ember

Cut cells in 3-D ​

The same quantities in 3-D: volume fractions, the six face fractions, the wetted area and the pieces.

f90
use fossil, only : surface_stl_object, curve_object, cut_cells_2d_t, cut_cells_3d_t, cut_cells_3d, STATUS_OK
use penf,   only : I4P, R8P

implicit none
type(surface_stl_object) :: surface
type(curve_object)       :: section
type(cut_cells_3d_t)     :: cut
type(cut_cells_2d_t)     :: cut2
real(R8P)                :: x(25), h
integer(I4P)             :: i, c(3), p, status

call surface%load_from_file(file_name='dragon-placed.stl', guess_format=.true.)    ! chapter 3
h = 0.05_R8P
x = [(-0.6_R8P + h * i, i = 0, 24)]                  ! 24^3 cells, h = 0.05; z = 0 is the plane x(13)
call cut_cells_3d(surface=surface, x=x, y=x, z=x, cut=cut)
print '(A,I0,A,I0,A,I0,A,I0)', 'cells: fluid ', count(cut%alpha == 1._R8P), ', solid ', count(cut%alpha == 0._R8P), &
                                ', cut ', count(cut%alpha > 0._R8P .and. cut%alpha < 1._R8P), &
                                ', flagged ', count(cut%pieces < 0)
f90
print '(A,I0,A,I0)', 'pieces ', cut%np, ', cells with two or more ', count(cut%pieces > 1)
c = findloc(cut%pieces, 2)                                                         ! the first cell with two pieces
p = cut%first_piece(c(1), c(2), c(3))
print '(A,I0,A,I0,A,I0,A,F8.5,A,2F8.5)', 'cell (', c(1), ',', c(2), ',', c(3), ') alpha ', &
   cut%alpha(c(1), c(2), c(3)), ' = ', cut%piece_volume(p:p + 1) / h**3
print '(A,6F7.3)', '  faces of piece 1 (-x +x -y +y -z +z)', cut%piece_face(:, p)
print '(A,6F7.3)', '  faces of piece 2                    ', cut%piece_face(:, p + 1)
print '(A,6F7.3)', '  faces of the cell                   ', cut%face_x(c(1):c(1) + 1, c(2), c(3)), &
                   cut%face_y(c(1), c(2):c(2) + 1, c(3)), cut%face_z(c(1), c(2), c(3):c(3) + 1)
  • cut_cells_3d(surface=, x=, y=, z=, cut=) is a free routine (from use fossil) that fills a cut_cells_3d_t: alpha, face_x, face_y, face_z (the fluid fraction of every grid face), wet_area, wet_centroid, wet_normal, and the pieces: pieces(i, j, k) from first_piece(i, j, k), each with piece_volume, piece_centroid, its wall terms and piece_face(6, :), its fluid fraction of the six faces (−x, +x, −y, +y, −z, +z).
  • pieces = -1 flags a cell that cannot be trusted: a boundary edge of the mesh crosses it, or its faces do not close. Such a cell has no measures and alpha = -1.
$ tut10_c_cells3d
cells: fluid 12829, solid 96, cut 895, flagged 17
faces z = 0: cut 43, largest |face_z - 2-D alpha|  3.47E-15
pieces 13797, cells with two or more 75
cell (13,7,6) alpha  0.06856 =  0.06533 0.00323
  faces of piece 1 (-x +x -y +y -z +z)  0.046  0.147  0.142  0.009  0.866  0.000
  faces of piece 2                      0.008  0.000  0.000  0.035  0.102  0.000
  faces of the cell                     0.055  0.147  0.142  0.044  0.967  0.000
  • 895 of the 13824 cells are cut; 17 are flagged. The dragon is open (chapter 2), and the cells its open edges cross get no measures: a solid with holes has no inside to measure there.
  • 75 cells have two or more pieces. In cell (13, 7, 6) the fluid is 6.856 % of the cell, in two pieces of 6.533 % and 0.323 %. Their face fractions add up to the cell's: on −x, 0.046 and 0.008 make 0.055 within the rounding of the print, on −z 0.866 and 0.102 make 0.967.

the 3-D cells below z = 0 that are not all fluid, drawn as cubes shaded by their fluid fraction: the solid interior cream on the cut plane, the cut cells around it towards sepia, the flagged cells in ember; the dragon above z = 0 as a translucent ghost

The top of the cubes is the plane z = 0 of the 2-D section: the solid inside, the cut cells around it. The ember cells are flagged, where an open edge of the dragon crosses them.

A plane through the block ​

A face of a 3-D cell lies in a grid plane, and its fluid fraction is a 2-D cut cell of the section of the body by that plane. The plane z = 0 is the grid plane x(13), and chapter 7 saved its section.

f90
call section%load_from_file(file_name='dragon-section.dat', status=status)        ! chapter 7: the section z = 0
if (status /= STATUS_OK) error stop 'cannot load dragon-section.dat'
call section%cut_cells(x=x, y=x, cut=cut2)                                         ! its 2-D cut cells, same grid
print '(A,I0,A,ES9.2)', 'faces z = 0: cut ', count(cut%face_z(:, :, 13) > 0._R8P .and. cut%face_z(:, :, 13) < 1._R8P), &
                        ', largest |face_z - 2-D alpha| ', maxval(abs(cut%face_z(:, :, 13) - cut2%alpha))

The 43 cut faces of that plane equal the 2-D fractions of the section on the same grid to 3.47e-15 (second line of the run above): two different code paths, one from the triangles and one from the saved curve, agree to round-off. The animation sweeps the block layer by layer: each frame shows the cells between two grid planes, shaded by their volume fraction, with the section at the bottom plane of the layer in teal and at its top plane in red. The cut cells follow the two sections (a cell is also cut by a part of the body that ends between the two planes); the 17 flagged cells sit in five layers, where the open edges of the dragon lie.

the block of 24 by 24 by 24 cells swept from z = -0.40 to z = 0.40, one layer of cells per frame seen from above: the cells of the layer shaded by their fluid fraction, the flagged ones in ember, the dragon's section at the layer's bottom plane in teal and at its top plane in red; the caption counts the cut and flagged cells of each layer, 107 cut and 5 flagged in the layer z in [-0.35, -0.30]

Explicit schemes on cut cells are limited by the smallest piece: a piece of 4e-4 of its cell would force a time step about 2500 times shorter. The cures (state redistribution, flux redistribution, cell merging) all work on the graph of the pieces. FOSSIL builds the graph and the neighbourhoods; the solver keeps the arithmetic on its states.

f90
use fossil, only : surface_stl_object, curve_object, cut_cells_2d_t, cut_cells_3d_t, cut_cells_3d, cut_links_t, &
                   cut_links_2d, srd_t, srd_neighbourhoods, SRD_REGULAR, SRD_COMPLETE, SRD_INCOMPLETE, merge_t, &
                   merge_targets, MERGE_NONE, MERGE_OK, MERGE_CHAIN, STATUS_OK
use penf,   only : I4P, R8P

implicit none
type(curve_object)       :: section
type(surface_stl_object) :: surface
type(cut_cells_2d_t)     :: cut
type(cut_cells_3d_t)     :: cut3
type(cut_links_t)        :: links, links3
type(srd_t)              :: srd
type(merge_t)            :: mt
real(R8P)                :: x(49), h
integer(I4P)             :: i, k, p, status

call section%load_from_file(file_name='dragon-section.dat', status=status)
if (status /= STATUS_OK) error stop 'cannot load dragon-section.dat'
h = 0.025_R8P
x = [(-0.6_R8P + h * i, i = 0, 48)]
call section%cut_cells(x=x, y=x, cut=cut)
call cut_links_2d(cut, links)                        ! piece p meets links%piece(k) over face links%face(k)
print '(A,I0,A,I0)', 'pieces ', cut%np, ', links (both directions) ', size(links%piece)
p = cut%first_piece(22, 20) + 1                      ! the small second piece of cell (22, 20), step 2
do k = links%start(p), links%start(p + 1) - 1
   print '(A,I0,A,I0,A,2I3,A,I0,A,F7.4)', '  piece ', p, ' -> ', links%piece(k), ' in cell', &
         cut%piece_cell(:, links%piece(k)), ' over face ', links%face(k), ', length / h ', links%area(k) / h
enddo
  • cut_links_2d(cut, links) gives a cut_links_t in CSR form: the links of piece p are start(p) to start(p + 1) - 1, each with the piece across, the face (1 to 4: −x, +x, −y, +y) and the shared fluid area (a length in 2-D). Both directions are stored, with the same area.
  • Two pieces are linked only where they share a fluid interval of a cell edge, never across the solid.
f90
call srd_neighbourhoods(links, cut%piece_cell, cut%piece_area, cut%piece_centroid, cut%piece_wet_normal, x, x, srd)
print '(A,I0,A,I0,A,I0)', 'SRD: regular ', count(srd%status == SRD_REGULAR), ', small ', &
                          count(srd%status == SRD_COMPLETE), ', incomplete ', count(srd%status == SRD_INCOMPLETE)
p = minloc(cut%piece_area, 1, mask=cut%piece_area > 0._R8P)          ! the smallest piece with area
print '(A,I0,A,2I3,A,ES9.2,A,I0,A)', '  smallest piece ', p, ' in cell', cut%piece_cell(:, p), ', area / h^2 ', &
                                     cut%piece_area(p) / h**2, ', neighbourhood of ', srd%start(p + 1) - srd%start(p), &
                                     ' pieces'
print '(A,F7.4,A,F7.4)', '  neighbourhood area / h^2 ', &
                         sum(cut%piece_area(srd%member(srd%start(p):srd%start(p + 1) - 1))) / h**2, ' >= tau = ', srd%tau
  • srd_neighbourhoods(links, piece_cell, piece_volume, piece_centroid, wet_normal, x, y, srd) marks a piece small if it holds less than τ = ½ of its cell and grows its neighbourhood through the links, the neighbours along the wall normal first, until it holds τ of a cell. srd%start/srd%member list it, the piece first; vhat, xhat, eta_nb and eta_self are the weighted volumes, centroids and factors of weighted state redistribution.
f90
call merge_targets(links, cut%piece_cell, cut%piece_area, cut%piece_wet_normal, x, x, mt)
print '(A,I0,A,I0,A,I0)', 'merge: served ', count(mt%status /= MERGE_NONE), ', direct ', count(mt%status == MERGE_OK), &
                          ', through a chain ', count(mt%status == MERGE_CHAIN)
print '(A,2I3,A,I0)', '  smallest piece -> cell', cut%piece_cell(:, mt%final_target(p)), &
                      ', normal-directed targets ', mt%mix_start(p + 1) - mt%mix_start(p)
  • merge_targets(links, piece_cell, piece_volume, wet_normal, x, y, mt) gives each small piece one target, the linked piece that is not small and lies best along the wall normal (target, final_target after a chain through small pieces), and the normal-directed targets of conservative mixing (mix_piece, mix_weight).
f90
call surface%load_from_file(file_name='dragon-placed.stl', guess_format=.true.)
call cut_cells_3d(surface=surface, x=x(1:49:2), y=x(1:49:2), z=x(1:49:2), cut=cut3, links=links3)
print '(A,I0,A,I0,A,I0)', '3-D: pieces ', cut3%np, ', links ', size(links3%piece), ', unmatched regions ', &
                          links3%unmatched
  • In 3-D the links come with the cut cells, cut_cells_3d(..., links=): the pieces across a face are matched through the fluid regions of the face. links%unmatched counts the regions it could not assign.
$ tut10_d_solver
pieces 2234, links (both directions) 8658
  piece 915 -> 913 in cell 21 20 over face 1, length / h  0.4351
  piece 915 -> 963 in cell 22 21 over face 4, length / h  0.0785
SRD: regular 2187, small 47, incomplete 0
  smallest piece 1277 in cell 24 28, area / h^2  4.07E-04, neighbourhood of 2 pieces
  neighbourhood area / h^2  0.8991 >= tau =  0.5000
merge: served 47, direct 47, through a chain 0
  smallest piece -> cell 25 28, normal-directed targets 2
3-D: pieces 13797, links 78614, unmatched regions 0
  • The small piece of cell (22, 20) links to two pieces: across −x over 0.4351 h and across +y over 0.0785 h, its two apertures of the previous run. It does not link to the other piece of its own cell.
  • 47 pieces are small; every neighbourhood reaches τ (none is incomplete). The smallest, 4.07e-4 of cell (24, 28), needs one neighbour: with the piece of cell (25, 28) across its wall normal the neighbourhood holds 0.8991 of a cell.
  • All 47 have a suitable target directly; the smallest one's is that same cell (25, 28), and it has 2 normal-directed targets.
  • The 3-D graph of the dragon: 78614 links over 13797 pieces, no unmatched region.

a zoom on the section around the smallest piece, 4.07e-4 of its cell, seen from above: cells shaded by fluid fraction, the wall in red, gold lines joining each cut piece's centroid to the pieces it links to, teal dots on the small pieces with a teal segment to their merge target, and the two cells of the smallest piece's SRD neighbourhood outlined in ember

Moments, quadrature and a coarse level ​

A second-order scheme needs the centroid of each piece; a higher-order one needs integrals of polynomials over it, and an AMR solver needs the same geometry on the coarse level.

f90
use fossil, only : curve_object, cut_cells_2d_t, cut_links_t, cut_links_2d, cut_coarsen_2d, STATUS_OK
use penf,   only : I4P, R8P

implicit none
type(curve_object)        :: section
type(cut_cells_2d_t)      :: cut, coarse, direct
type(cut_links_t)         :: links, coarse_links
real(R8P)                 :: x(49), h, xc(2), qx
integer(I4P), allocatable :: fine_to_coarse(:)
integer(I4P)              :: i, k, p, status

call section%load_from_file(file_name='dragon-section.dat', status=status)
if (status /= STATUS_OK) error stop 'cannot load dragon-section.dat'
h = 0.025_R8P
x = [(-0.6_R8P + h * i, i = 0, 48)]
call section%cut_cells(x=x, y=x, cut=cut, moments_order=2_I4P, boundaries=.true., quadrature=.true.)
p = cut%first_piece(23, 41)                          ! the first piece of the tail cell (23, 41), step 2
xc = 0.5_R8P * [x(23) + x(24), x(41) + x(42)]        ! the cell centre: moments in X = (x - xc) / h, Y = (y - yc) / h
print '(A,6F9.5)', 'moments / h^2 (1, X, Y, X^2, XY, Y^2):', cut%piece_moments(:, p) / h**2
print '(A,2F9.5,A,2F9.5)', '  centroid from the moments ', xc + h * cut%piece_moments(2:3, p) / cut%piece_moments(1, p), &
                           ', piece_centroid ', cut%piece_centroid(:, p)
  • cut_cells(..., moments_order=p) (p ≤ 4; cut_cells_3d(..., moments_order=) in 3-D) gives piece_moments(:, np), the integrals of X^a Y^b over each piece with a + b ≤ p, in X = (x − x_c)/h, Y = (y − y_c)/h about the cell centre, in the order of mono_exponents: 1, X, Y, X², XY, Y². piece_wall_moments are the same over its wall.
f90
k = cut%quad_start(p + 1) - cut%quad_start(p)
print '(A,I0,A,I0,A,I0,A)', 'area rule: ', k, ' points (', &
      count(cut%quad_weight(cut%quad_start(p):cut%quad_start(p + 1) - 1) < 0._R8P), ' negative), wall rule: ', &
      cut%wall_quad_start(p + 1) - cut%wall_quad_start(p), ' points'
qx = 0._R8P
do k = cut%quad_start(p), cut%quad_start(p + 1) - 1  ! integrate X^2 with the rule
   qx = qx + cut%quad_weight(k) * ((cut%quad_point(1, k) - xc(1)) / h)**2
enddo
print '(A,ES9.2,A,ES9.2)', '  sum of weights - area ', &
      sum(cut%quad_weight(cut%quad_start(p):cut%quad_start(p + 1) - 1)) - cut%piece_area(p), &
      ', rule on X^2 - moment ', qx - cut%piece_moments(4, p)
  • quadrature=.true. adds a rule per piece: quad_start, quad_point, quad_weight for the area and wall_quad_start, wall_quad_point, wall_quad_weight for the wall. The area rule is a fan of signed triangles from the cell centre over the piece's oriented boundary (boundaries=.true. exports it: piece_seg_start, piece_seg), 7 points each, exact to degree 5. Where the piece is not star-shaped about the centre, triangles over the solid side carry negative weights that cancel the points outside the piece.
f90
call cut_links_2d(cut, links)
call cut_coarsen_2d(cut, links, x, x, 2_I4P, coarse, coarse_links, fine_to_coarse, status)
call section%cut_cells(x=x(1:49:2), y=x(1:49:2), cut=direct)                      ! the coarse grid directly
print '(A,I0,A,I0,A,I0,A,I0,A,I0)', 'coarse (ratio 2): status ', status, ', pieces ', coarse%np, ', direct ', direct%np, &
                               ', fine piece ', p, ' -> coarse piece ', fine_to_coarse(p)
print '(A,ES9.2)', '  largest |alpha coarsened - alpha direct| ', maxval(abs(coarse%alpha - direct%alpha))
  • cut_coarsen_2d(fine, links, x, y, ratio, coarse, coarse_links, fine_to_coarse, status) (cut_coarsen_3d in 3-D) builds the coarse level from the fine one: coarse pieces are the fine pieces of a coarse cell joined by fine links, and their measures, moments and links are sums of the fine ones.
$ tut10_e_moments
moments / h^2 (1, X, Y, X^2, XY, Y^2):  0.21077  0.07225  0.02296  0.02704  0.00883  0.01018
  centroid from the moments  -0.02893  0.41522, piece_centroid  -0.02893  0.41522
area rule: 42 points (21 negative), wall rule: 12 points
  sum of weights - area  3.25E-19, rule on X^2 - moment  4.74E-20
coarse (ratio 2): status 0, pieces 570, direct 570, fine piece 1872 -> coarse piece 486
  largest |alpha coarsened - alpha direct|  1.78E-15
  • The first piece of the tail cell (23, 41) holds 0.21077 of the cell. Its first moments divided by its area give its centroid, (−0.02893, 0.41522), the same as piece_centroid.
  • Its rule has 42 area points, 21 of them with negative weights, and 12 wall points. The weights add up to the area to 3.25e-19 and the rule integrates X² to the moment to 4.74e-20.
  • At ratio 2 the 2234 fine pieces become 570 coarse ones, as many as the cut cells computed directly on the coarse grid, and the coarse fractions equal the direct ones to 1.78e-15.

the first piece of the tail cell (23, 41), seen from above: its oriented boundary in red, the fan of triangles from the cell centre over it in grey, its 42 area points in teal where the weight is positive and in ember where it is negative (21 of them, outside the piece), and its 12 wall points in gold on the wall

What you learned

line_crossings gives the exact crossings of a grid line; curve%cut_cells and cut_cells_3d give exact fluid fractions, apertures, face fractions and fluid pieces, and flag the cells an open surface makes untrustworthy. cut_links_2d (or links=), srd_neighbourhoods and merge_targets give the piece graph a small-cell cure works on, moments_order= and quadrature= the higher-order geometry, cut_coarsen_2d/cut_coarsen_3d the coarse level. Reference: Cut-cell geometry, Cut cells: solver support.

Next: 11. Moving bodies.