Skip to content
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

added basic restrict/mask functions and tests #118

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CombinatorialSpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include("DiscreteExteriorCalculus.jl")
include("MeshInterop.jl")
include("FastDEC.jl")
include("Meshes.jl")
include("restrictions.jl")

@reexport using .SimplicialSets
@reexport using .DiscreteExteriorCalculus
Expand Down
30 changes: 30 additions & 0 deletions src/restrictions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CombinatorialSpaces, CombinatorialSpaces.SimplicialSets

export restrict, mask!

""" restrict(sd::HasDeltaSet,
quffaro marked this conversation as resolved.
Show resolved Hide resolved

restrict a form to a subset of the points.

# Arguments:
`sd`: the mesh,
`func`: a function that chooses the submesh indices corresponding to the boundary
`form`: the vector you want to restrict
"""
restrict(sd::HasDeltaSet, func::Function, form) = form[func(sd)]

restrict(indices, form) = form[indices]

""" mask(sd::HasDeltaSet, func::Function, form, values)

Masks a form to values on a subset of the points.

# Arguments:
`sd`: the mesh
`func`: function that chooses the submesh indices corresponding to the boundary
`form`: the vector you want to restrict and
`values:` is the vector you want to replace with
"""
mask!(sd::HasDeltaSet, func::Function, form, values) = setindex!(form, values, func(sd))

mask!(indices, form, values) = setindex!(form, values, indices)
26 changes: 26 additions & 0 deletions test/restrictions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CombinatorialSpaces
using GeometryBasics: Point3
Point3D = Point3{Float64}

rect′ = loadmesh(Rectangle_30x10());
rect = EmbeddedDeltaDualComplex2D{Bool,Float64,Point3D}(rect′);
subdivide_duals!(rect, Barycenter());

left_wall_idxs(sd) = begin
min_y = minimum(p -> p[2], sd[:point])
findall(p -> abs(p[2] - min_y) ≤ sd[1,:length]+1e-4, sd[:point])
end

# 0-form
zero_form = 2*ones(nv(rect));
idxlen = length(left_wall_idxs(rect))
max = Float64(length(zero_form) + 1)

@test restrict(left_wall_idxs(rect), zero_form) == fill(2.0, idxlen)
@test restrict(rect, left_wall_idxs, zero_form) == fill(2.0, idxlen)

copy_zero_form = copy(zero_form);
mask!(rect, left_wall_idxs, copy_zero_form, fill(max, idxlen));

@test copy_zero_form[copy_zero_form .== max] == fill(max, idxlen)

4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ end
include("Backends.jl")
end

@testset "Restrictions" begin
include("restrictions.jl")
end

end
Loading