Skip to content

fix adaptivesampling! to only split leaf cells#45

Open
cserteGT3 wants to merge 2 commits intoJuliaGeometry:masterfrom
cserteGT3:cst-fix-adaptivesampling
Open

fix adaptivesampling! to only split leaf cells#45
cserteGT3 wants to merge 2 commits intoJuliaGeometry:masterfrom
cserteGT3:cst-fix-adaptivesampling

Conversation

@cserteGT3
Copy link

Subsequent calls of adaptivesampling! fail because it just collects the cells and splits them if required. MWE from example:

using RegionTrees
using StaticArrays: SVector
import RegionTrees: AbstractRefinery, needs_refinement, refine_data

struct MyRefinery <: AbstractRefinery
    tolerance::Float64
end

function needs_refinement(r::MyRefinery, cell)
    maximum(cell.boundary.widths) > r.tolerance
end

function refine_data(r::MyRefinery, cell::Cell, indices)
    boundary = child_boundary(cell, indices)
    "child with widths: $(boundary.widths)"
end

r = MyRefinery(0.05)
root = Cell(SVector(0., 0), SVector(1., 1), "root")

Then calling adaptivesampling! twice:

julia> root = Cell(SVector(0., 0), SVector(1., 1), "root")
Cell: HyperRectangle{2, Float64}([0.0, 0.0], [1.0, 1.0])

julia> adaptivesampling!(root, r)
Cell: HyperRectangle{2, Float64}([0.0, 0.0], [1.0, 1.0])

julia> adaptivesampling!(root, r)
ERROR: AssertionError: isleaf(cell)
Stacktrace:
 [1] macro expansion
   @ C:\Users\user\.julia\packages\RegionTrees\rosFd\src\cell.jl:76 [inlined]
 [2] split!(cell::Cell{String, 2, Float64, 4}, child_data::RegionTrees.TwosArray{2, String, 4})
   @ RegionTrees C:\Users\user\.julia\packages\RegionTrees\rosFd\src\cell.jl:65
 [3] split!
   @ C:\Users\user\.julia\packages\RegionTrees\rosFd\src\cell.jl:69 [inlined]
 [4] adaptivesampling!(root::Cell{String, 2, Float64, 4}, refinery::MyRefinery)
   @ RegionTrees C:\Users\user\.julia\packages\RegionTrees\rosFd\src\adaptivesampling.jl:13
 [5] top-level scope
   @ REPL[11]:1

This PR fixes this by only splitting leaf cells and adding the children of others instead so subsequent calls work as intended.

@codecov
Copy link

codecov bot commented Nov 3, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@cserteGT3
Copy link
Author

@rdeits If you have time, could you please take a look at my PRs? I hope them to be easy to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant