picogk-reinforce

    Stress-guided FDM micro-fissure and slicer-modifier reinforcer built on PicoGK

    Download zip
    Author
    Version
    0.2.6
    License
    Apache-2.0
    Last updated
    14 hours ago
    Downloads
    13

    #picogk-reinforce — Stress-Guided FDM Micro-Fissure Reinforcer

    Turns a PicoGK voxel body plus a load case into an FDM-oriented, stress-guided reinforcement: a matrix-free 3D linear-elastic voxel-FEM solve, principal-stress streamline tracing, micro-fissure channels that steer slicer perimeters, and a slicer modifier mesh for OrcaSlicer/PrusaSlicer.

    Built on gmlewis/picogkffi and runs on the native target only.

    #Package Structure

    FileDescription
    loadcase.mbtRegion, AnchorZone, ForceLoad, LoadCase, ReinforceConfig
    fea.mbtMatrix-free voxel-FEM solver and 3x3 principal-stress eigensolver
    fissures.mbtPrincipal-stress streamlines and micro-fissure / modifier synthesis

    #API

    ItemDescription
    LoadCase::new(anchors~, loads~)Fixed supports and applied forces
    Region::{Box, Sphere, CylinderZ}Spatial selection for anchors and loads
    ReinforceConfig::default()FEA grid step, skin margin, fissure radius, channel spacing, stress threshold, solver limits, material modulus
    solve_voxel_fea(voxels, load_case, config)Solve the voxel-FEM and return a StressField
    trace_stress_streamlines(field, voxels, config)Trace principal-stress streamlines
    reinforce_voxels(voxels, load_case, config?)Full pipeline; returns a ReinforceResult
    ReinforceResultreinforced, fissures, modifier, stress, streamlines, report
    ReinforceReportFEA node counts, PCG iterations/residual, peak von Mises, streamline/channel counts, and volumes

    #Pipeline

    1. solve_voxel_fea — 26-neighbour isotropic continuum lattice solved with a Jacobi-preconditioned conjugate-gradient solver, producing von Mises stress and principal directions per active node.
    2. trace_stress_streamlines — traces principal-stress streamlines strictly inside the safe interior (skin_margin_mm), resampled every streamline_step_mm.
    3. reinforce_voxels — carves micro-fissure channels only where the stress exceeds stress_threshold_fraction of the peak, and emits:

      • reinforced: the body with the micro-fissure channels subtracted (slice normally);
      • fissures: the internal channel network by itself (inspect/debug);
      • modifier: a standalone body for slicer modifier meshes.

    #Usage

    Add both packages to moon.pkg:

    import { "gmlewis/picogkffi" @pk, "gmlewis/picogk-reinforce" @reinforce, } pkgtype(kind: "executable")

    Then build a load case and run the pipeline:

    ///|
    fn main {
    @pk.init_with_size(0.2).unwrap()
    defer @pk.shutdown()

    // `part` is any @pk.Voxels body built with the FFI SDK.
    let part = @pk.new_box(0.0, 0.0, 0.0, 60.0, 20.0, 16.0)

    let load_case = @reinforce.LoadCase::new(
    anchors=[
    @reinforce.AnchorZone::new(
    "root_mount",
    @reinforce.Region::Box(
    @pk.Vec3::new(-1.0, -1.0, -1.0),
    @pk.Vec3::new(11.0, 21.0, 17.0),
    ),
    ),
    ],
    loads=[
    @reinforce.ForceLoad::new(
    "tip_load",
    @reinforce.Region::CylinderZ(54.0, 10.0, -1.0, 17.0, 6.0),
    @pk.Vec3::new(0.0, 0.0, -250.0), // 250 N downward
    ),
    ],
    )

    let config : @reinforce.ReinforceConfig = {
    ..@reinforce.ReinforceConfig::default(),
    fea_grid_step_mm: 2.0,
    skin_margin_mm: 1.6,
    fissure_radius_mm: 0.22,
    channel_spacing_mm: 3.2,
    stress_threshold_fraction: 0.25,
    }

    let result = @reinforce.reinforce_voxels(part, load_case, config~)
    println("peak von Mises = \{result.report.peak_von_mises_mpa} MPa")
    println("channels = \{result.report.streamline_count}")

    // Export `result.reinforced`, `result.fissures`, and `result.modifier`
    // with .to_mesh().save_stl(...) as needed, then release everything.
    result.destroy()
    part.destroy()
    }

    #Notes

    • Prefer ReinforceConfig::default() and override only the fields you need.
    • The input voxel size must be small enough to resolve the requested fissure_radius_mm and channel_spacing_mm.
    • Destroy the returned ReinforceResult (and any input voxel bodies you own) with .destroy().
    • A complete runnable pipeline — including STL export for the original body, reinforced body, fissure network, and modifier mesh — is examples/micro-fissure-reinforce.

    #Dependencies

    • gmlewis/picogkffi — direct FFI bindings to the PicoGK native library.

    AnchorZone

    pub(all) struct AnchorZone {
    name : String
    region : Region
    }

    A fixed/clamped mounting boundary condition (u = 0 on all nodes in region).

    AnchorZone::new

    fn AnchorZone::new(name : String, region : Region) -> AnchorZone

    Creates a named anchor zone.

    ForceLoad

    pub(all) struct ForceLoad {
    name : String
    region : Region
    force_n :
    Vec3

    }

    A 3D force vector (in Newtons) distributed over all active nodes in region.

    ForceLoad::new

    fn ForceLoad::new(name : String, region : Region, force_n :
    Vec3
    ) -> ForceLoad

    Creates a named 3D force load.

    LoadCase

    pub(all) struct LoadCase {
    anchors : Array[AnchorZone]
    loads : Array[ForceLoad]
    }

    Complete mechanical load case: fixed supports + applied forces.

    LoadCase::new

    fn LoadCase::new(anchors~ : Array[AnchorZone], loads~ : Array[ForceLoad]) -> LoadCase

    Creates a load case from anchors and loads.

    Region

    pub(all) enum Region {
    Box(
    Vec3
    ,
    Vec3
    )
    Sphere(
    Vec3
    , Double)
    CylinderZ(Double, Double, Double, Double, Double)
    }

    A 3D spatial region used to specify fixed supports (anchors) or applied loads.

    Region::contains

    fn Region::contains(self : Region, p :
    Vec3
    ) -> Bool

    Tests whether 3D point p lies inside self.

    ReinforceConfig

    pub(all) struct ReinforceConfig {
    fea_grid_step_mm : Double
    skin_margin_mm : Double
    fissure_radius_mm : Double
    channel_spacing_mm : Double
    stress_threshold_fraction : Double
    streamline_step_mm : Double
    max_streamline_steps : Int
    max_pcg_iters : Int
    youngs_modulus_mpa : Double
    }

    Tuning parameters for FEA stress evaluation and FDM micro-fissure synthesis.

    ReinforceConfig::default

    Sensible FDM defaults for a 0.4 mm nozzle printing PETG / CF-Nylon.

    ReinforceReport

    pub(all) struct ReinforceReport {
    active_fea_nodes : Int
    anchored_nodes : Int
    loaded_nodes : Int
    pcg_iterations : Int
    pcg_residual : Double
    peak_von_mises_mpa : Double
    streamline_count : Int
    total_channel_segments : Int
    original_volume_mm3 : Double
    reinforced_volume_mm3 : Double
    fissure_volume_mm3 : Double
    modifier_volume_mm3 : Double
    }

    Summary statistics from a reinforcement run.

    ReinforceResult

    pub(all) struct ReinforceResult {
    reinforced :
    Voxels

    fissures :
    Voxels

    modifier :
    Voxels

    stress : StressField
    streamlines : Array[Array[
    Vec3
    ]]
    report : ReinforceReport
    }

    Result of running reinforce_voxels: caller owns the returned Voxels handles and should call .destroy() when done.

    ReinforceResult::destroy

    fn ReinforceResult::destroy(self : ReinforceResult) -> Unit

    Destroys all owned PicoGK voxel handles in ReinforceResult.

    StressField

    pub(all) struct StressField {
    origin :
    Vec3

    step_mm : Double
    nx : Int
    ny : Int
    nz : Int
    node_of_cell : Array[Int]
    coords : Array[
    Vec3
    ]
    disp : Array[
    Vec3
    ]
    von_mises : Array[Double]
    principal_dir : Array[
    Vec3
    ]
    peak_von_mises_mpa : Double
    anchored_count : Int
    loaded_count : Int
    pcg_iterations : Int
    pcg_residual : Double
    }

    Per-node stress result on the active FEA voxel grid.

    principal_direction_3x3

    fn principal_direction_3x3(sxx : Double, syy : Double, szz : Double, sxy : Double, sxz : Double, syz : Double) -> (Double,
    Vec3
    )

    Computes the unit eigenvector corresponding to the eigenvalue of largest magnitude of a symmetric 3x3 matrix [[sxx, sxy, sxz], [sxy, syy, syz], [sxz, syz, szz]] using cyclic Jacobi rotations.

    reinforce_voxels

    fn reinforce_voxels(part :
    Voxels
    , load_case : LoadCase, config? : ReinforceConfig) -> ReinforceResult

    Runs the complete standalone stress-guided FDM reinforcement pipeline on a PicoGK Voxels solid:
    1. 3D linear-elastic voxel-FEM solve (solve_voxel_fea).
    2. Safe interior skin offset (part.offset(-skin_margin_mm)).
    3. Principal-stress streamline tracing (trace_stress_streamlines).
    4. Micro-fissure lattice voxelization, clipping to safe_interior, and boolean subtraction from part.
    5. High-stress OrcaSlicer/PrusaSlicer modifier volume synthesis.

    solve_voxel_fea

    fn solve_voxel_fea(part :
    Voxels
    , load_case : LoadCase, config : ReinforceConfig) -> StressField

    Runs a 3D linear-elastic voxel-FEM solve on part under load_case.

    trace_stress_streamlines

    fn trace_stress_streamlines(field : StressField, safe_interior :
    Voxels
    , config : ReinforceConfig) -> Array[Array[
    Vec3
    ]]

    Traces non-overlapping principal-stress streamlines through high-stress regions strictly inside safe_interior.