-
Notifications
You must be signed in to change notification settings - Fork 7
Iterator api #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Iterator api #23
Changes from all commits
5776667
0482242
036598b
c16dd48
b6d57cd
6206623
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ version = "1.15.0" | |
| authors = ["Juergen Fuhrmann <[email protected]>", "Patrick Jaap <[email protected]>"] | ||
|
|
||
| [deps] | ||
| ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e" | ||
| ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" | ||
| Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" | ||
| DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" | ||
|
|
@@ -19,6 +20,8 @@ Observables = "510215fc-4207-5dde-b226-833fc4488ee2" | |
| OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | ||
| Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
| StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
|
||
|
|
||
| [weakdeps] | ||
| Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" | ||
|
|
@@ -37,6 +40,7 @@ GridVisualizePlotsExt = "Plots" | |
| GridVisualizePlutoVistaExt = "PlutoVista" | ||
|
|
||
| [compat] | ||
| ChunkSplitters = "2.1" | ||
| ColorSchemes = "3" | ||
| Colors = "0.12,0.13,1" | ||
| DocStringExtensions = "0.8,0.9" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -82,30 +82,16 @@ end | |||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| Deprecated | ||||||
| """ | ||||||
| function GridVisualizeTools.marching_triangles(grid::ExtendableGrid, func, levels; gridscale = 1.0) | ||||||
| coord::Matrix{Float64} = grid[Coordinates] * gridscale | ||||||
| cellnodes::Matrix{Int32} = grid[CellNodes] | ||||||
| points, _, _ = marching_triangles(coord, cellnodes, func, [], levels) | ||||||
| return points | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| Collect isoline snippets and/or intersection points with lines and values ready for linesegments! | ||||||
| """ | ||||||
| function GridVisualizeTools.marching_triangles(grid::ExtendableGrid, func, lines, levels; gridscale = 1.0) | ||||||
| coord::Matrix{Float64} = grid[Coordinates] * gridscale | ||||||
| cellnodes::Matrix{Int32} = grid[CellNodes] | ||||||
| return marching_triangles(coord, cellnodes, func, lines, levels) | ||||||
| ls = LinearSimplices(grid, func; gridscale) | ||||||
| return vcat(marching_triangles(ls, levels)...) | ||||||
| end | ||||||
|
|
||||||
| function GridVisualizeTools.marching_triangles(grids::Vector{ExtendableGrid{Tv, Ti}}, funcs, lines, levels; gridscale = 1.0) where {Tv, Ti} | ||||||
| coords = [grid[Coordinates] * gridscale for grid in grids] | ||||||
| cellnodes = [grid[CellNodes] for grid in grids] | ||||||
| return marching_triangles(coords, cellnodes, funcs, lines, levels) | ||||||
| all_ls = [LinearSimplices(grids[i], funcs[i]; gridscale) for i in 1:length(grids)] | ||||||
|
||||||
| all_ls = [LinearSimplices(grids[i], funcs[i]; gridscale) for i in 1:length(grids)] | |
| all_ls = [LinearSimplices(grids[i], funcs[i](grids[i][Coordinates]); gridscale) for i in 1:length(grids)] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| struct LinearSimplices{D, Tc, Ti, Tf} <: LinearSimplexIterator{D} | ||
| coord::Matrix{Tc} | ||
| cellnodes::Matrix{Ti} | ||
| values::Vector{Tf} | ||
| gridscale::Tc | ||
| range::StepRange{Int, Int} | ||
| end | ||
|
|
||
| function LinearSimplices(coord::Matrix{Tc}, cn::Matrix{Ti}, f::Vector{Tf}; gridscale = 1.0, nthreads = Threads.nthreads()) where {Tc, Ti, Tf} | ||
| ncells = size(cn, 2) | ||
| dim = size(coord, 1) | ||
| return map(enumerate(chunks(1:ncells; n = nthreads))) do c | ||
| LinearSimplices{dim, Tc, Ti, Tf}(coord, cn, f, gridscale, last(c)) | ||
| end | ||
| end | ||
|
|
||
| function LinearSimplices(g::ExtendableGrid, f::Vector; nthreads = Threads.nthreads(), gridscale = 1.0) | ||
| return LinearSimplices(g[Coordinates], g[CellNodes], f; nthreads, gridscale) | ||
pjaap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function Base.iterate(linear_simplices::LinearSimplices{D}, args...) where {D} | ||
| (; coord, cellnodes, values, gridscale, range) = linear_simplices | ||
| iter = iterate(range, args...) | ||
| isnothing(iter) && return nothing | ||
| (icell, state) = iter | ||
| @views s = LinearSimplex( | ||
| Val{D}, | ||
| coord[:, cellnodes[:, icell]], | ||
| values[cellnodes[:, icell]], | ||
| gridscale | ||
| ) | ||
| return (s, state) | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| using ExtendableGrids | ||||||
| using GridVisualizeTools | ||||||
| using GridVisualize | ||||||
| using Test | ||||||
|
|
||||||
|
|
||||||
| function testloops(dim) | ||||||
| X = 0:0.1:10 | ||||||
| if dim == 1 | ||||||
| g = simplexgrid(X) | ||||||
| elseif dim == 2 | ||||||
| g = simplexgrid(X, X) | ||||||
| else | ||||||
| g = simplexgrid(X, X, X) | ||||||
| end | ||||||
| f = ones(num_nodes(g)) | ||||||
| ls = LinearSimplices(g, f; nthreads = 3) | ||||||
| testloop(ls) # for compilation | ||||||
| nalloc = @allocated sum_f = testloop(ls) | ||||||
|
|
||||||
|
|
||||||
| @test nalloc < 256 # allow for some allocations | ||||||
|
||||||
| @test nalloc < 256 # allow for some allocations | |
| @test nalloc < MAX_ALLOC_BYTES # Threshold for memory allocation to ensure efficiency |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,9 @@ import CairoMakie, PyPlot, PlutoVista | |||||
|
|
||||||
| CairoMakie.activate!(; type = "svg", visible = false) | ||||||
|
|
||||||
|
|
||||||
| include("griditerators.jl") | ||||||
|
||||||
| include("griditerators.jl") | |
| include(joinpath(@__DIR__, "griditerators.jl")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here
func(a user-provided function) is passed directly as thevaluesvector toLinearSimplices. You likely need to evaluatefuncat each node coordinate to build a numeric vector before constructing the iterator.