-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic restrict/mask functions and tests (#118)
* added basic restrict/mask functions and tests * applied feedback * fixed spaces * Update restrictions.jl * update docstring
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using CombinatorialSpaces, CombinatorialSpaces.SimplicialSets | ||
|
||
export restrict, mask! | ||
|
||
""" restrict(sd::HasDeltaSet, func::Function, form) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,8 @@ end | |
include("Backends.jl") | ||
end | ||
|
||
@testset "Restrictions" begin | ||
include("restrictions.jl") | ||
end | ||
|
||
end |