Named patches
What it does
A CFD body carries several boundary conditions: walls, inlets, outlets, porous or heated regions. Exporters write them as named solid <name> … endsolid blocks of one ASCII STL, or as one STL file per patch. FOSSIL keeps them (issue #66): every facet carries a patch id (facet%patch), an index into the surface's table of patch names.
Reading and writing
load_from_filereads one patch persolidblock of an ASCII file, named after the block, in file order; blocks with the same name merge. A file with one block, or a binary file, is one patch named after the header; a binary header is cut at its first NUL character (the 80 bytes are NUL-padded) and trimmed (issue #83).load_from_files(file_names)reads several files as one surface, one patch per file (or per block), named after thesolidname or, when that is empty, the file name.save_into_file(is_ascii=.true.)writes one block per patch; a single-patch surface writes exactly the file it wrote before. Binary STL has no names: all patches go into one.get_patches_number(),patch_name(i),facet_patch(f)read the table;set_patch(facets, name)moves facets to a named patch, created if new.
Before issue #66 the ASCII reader stopped with "malformed STL" at the first endsolid of a multi-solid file.
The dragon split by x into thirds (set_patch three times), saved as ASCII and loaded back: three solid blocks, read as the patches head (2238 facets), middle (2296) and tail (2054), 6588 facets in all. The names come from the file:
Through the pipeline
The patch id travels with the facet, so every operation that keeps or copies facets keeps it:
sanitize: degenerate and duplicate facets are removed with their ids; of two duplicates in different patches the first one in the file wins.rotate,translate,mirror,resizemove vertices only.clipkeeps the patch of every facet, and the remainder keeps the name table.merge_solids(other)mapsother's patches into the surface's table by name: equal names merge, new names are appended.fill_holesgives the new facets the patch of the hole's boundary when every boundary facet is in one patch, and a patch namedfilledotherwise (a hole across a wall/inlet edge has no single right answer; the caller canset_patchit).
A box remeshed to edge 0.15 with an inlet (z = 0), an outlet and walls, two inlet facets removed, one inside the inlet and one on its edge with a wall: fill_holes closes both, the first with an inlet facet, the second with a facet of the new patch filled:
Through booleans
boolean and resolve_self_intersections keep the patch of every facet: a sub-triangle of the arrangement takes its parent facet's patch, so the area of a patch in the result is the area of its parent patch outside (or inside) the other body, as the operation selects. The other surface's patches join the table by name before the arrangement: A ∪ B of a body with patches low, high and one with b_low, b_high has all four, and equal names merge (the Example measures it, through a remesh too).
A unit block (patch block, its top face lid) minus a sphere of radius 0.4 about the centre of the lid (patch sphere): the result's 2292 facets keep their parents' patches, 40 block, 102 lid (the lid retriangulated around the cut) and 2150 sphere, the dimple:
Through remeshing
Patch boundaries stay on the input's boundaries, like the sharp edges of feature edges, and every facet keeps a patch:
isotropic_remesh: the vertices of the edges between two patches are locked (whateverpreserve_featuressays), so those edges are never flipped or collapsed; a split facet's halves keep its patch, and a midpoint on a boundary edge becomes a boundary vertex.decimate: an interior vertex merges onto a boundary one at its place; two boundary vertices merge only along their own boundary edge, onto one of its two endpoints, so a boundary coarsens as a curve whose vertices are a subset of the input's, bit for bit (issue #81). A corner, where three or more patches meet, never moves, and no patch is emptied.decimate(rim_collapses=.false.)locks the boundaries instead: two boundary vertices never merge, the boundary vertices are the input ones exactly. See decimation.smooth: the boundary vertices do not move.alpha_wrap: each facet of the wrap takes the patch of the input facet closest to its centroid.
A marching-cubes sphere (2312 facets) in two patches, north and south, split along a zigzag of facet edges near the equator; remeshed (L = 0.08, 4832 facets) and decimated (384 facets), the zigzag stays on the input's: the remesh keeps all its vertices, the decimation 37 of its 68, joined by fewer, longer edges:
In the queries
query_many(patches=), query_many_device(patches=), probe_many(patches=) and image_points(patches=) return the patch of the facet that holds each query's closest point: the boundary condition to apply at an image point or a forcing point. The device path looks it up on the host from the facet ids the device returns, so it is bit-identical to the CPU path (the GPU bench line patch device vs serial mismatches is 0).
2-D curves
A curve carries a patch per segment (segment i runs from vertex i to the next). In the loop format, a line # patch <name> puts the segments starting at the vertices that follow in that patch; it does not end the loop. A curve without directives has one unnamed patch and is written back without them. repair keeps every segment's patch through joins, merges and reversals; slice_surface gives each segment the patch of the facet it is cut from, and the curve takes the surface's names. query_many(_device)(patches=), probe_many(patches=) and image_points(patches=) return the patch of the closest segment (device: host lookup, bit-identical). API: get_patches_number, patch_name, segment_patch, set_patch.
The union of the Example (two split boxes) cut at z = 0.25 and z = 0.75: at z = 0.25 the section meets only low, at z = 0.75 it meets high and b_low, each segment in the colour of the facet it is cut from:
# patch wall
0 0
1 0
1 1
# patch inlet
0 1Command line
fossilizer -i body.stl --patches prefix_ prints the patches (facets and area each) and writes each one to prefix_<name>.stl.
Example
The cookbook recipe wall, inlet and outlet from one STL tags the faces of a box, writes them as three blocks, reads them back and queries the patch at three points. Here the patches go through a boolean, a remesh and a section. Two unit boxes, each split at its mid-height into a lower and an upper patch (the helper split_box of the program, which calls set_patch twice), the second moved by (0.5, 0.5, 0.5), united:
call split_box(a, 'low', 'high', vector_R8P(0._R8P, 0._R8P, 0._R8P)) ! z < 0.5 and z > 0.5 of a unit box
call split_box(b, 'b_low', 'b_high', vector_R8P(0.5_R8P, 0.5_R8P, 0.5_R8P)) ! the same, moved by (0.5, 0.5, 0.5)
call a%boolean(other=b, op=BOOL_UNION, status=status) ! each sub-triangle keeps its patch
if (status /= BOOL_STATUS_OK) error stop 'boolean failed'
call areas('union', a)Then remeshed, and cut by the plane z = 0.75 (areas and lengths sum the facet areas and the segment lengths of every patch):
call a%isotropic_remesh(target_length=0.15_R8P, iterations=3_I4P, preserve_features=.true., status=status)
if (status /= REM_STATUS_OK) error stop 'remesh failed'
call areas('remeshed', a) ! patch boundaries stay where they arecall slice_surface(surface=a, normal_axis=3_I4P, level=0.75_R8P, curve=section) ! the section z = 0.75
call lengths(section) ! each segment has its facet's patch$ ref_patches
union: 84 facets
patch low: facets 24, area 3.00000000
patch high: facets 18, area 2.25000000
patch b_low: facets 18, area 2.25000000
patch b_high: facets 24, area 3.00000000
remeshed: 1278 facets
patch low: facets 352, area 3.00000000
patch high: facets 272, area 2.25000000
patch b_low: facets 286, area 2.25000000
patch b_high: facets 368, area 3.00000000
section z = 0.75: 95 segments
patch high: length 3.00000000
patch b_low: length 3.00000000- Boolean. The union's patches are the four input ones, merged into one table by name. Each keeps the area of its parent patch outside the other body:
lowandb_highlie wholly outside (area 3 each), whilehighandb_lowlose the three quarter-faces inside the other box (3 − 0.75 = 2.25). The four sum to the union's area, 10.5. - Remesh. 84 facets become 1278, but each patch keeps its area to the printed digits: the patch boundaries, the mid-height lines and the intersection curve, are locked, so no facet crosses them. Equilateral facets of edge 0.15 would take about 1080 for the area 10.5; the three iterations reach that density since each splits every long edge in rounds (roadmap #92 WP5: 610 facets before, the long faces under-refined).
- Section. The curve's segments take the patch of the facet they are cut from, and the curve takes the surface's names. At z = 0.75 the section meets
high(A's upper half) andb_low(B's lower half), 3 each: the perimeter of each square outside the other.
API
See Patches in the API reference.