-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d778423
commit 362f85d
Showing
7 changed files
with
105 additions
and
41 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
include("DifferentiableTriangulations.jl") | ||
include("SubFacetBoundaryTriangulations.jl") | ||
include("EmbeddedCollections.jl") |
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,28 @@ | ||
|
||
struct EmbeddedCollection | ||
generate :: Function | ||
objects :: Dict{Symbol,Any} | ||
bgmodel :: Union{<:DiscreteModel,<:DistributedDiscreteModel} | ||
|
||
function EmbeddedCollection( | ||
generate::Function,bgmodel,φ0 | ||
) | ||
geo = DiscreteGeometry(φ0,bgmodel) | ||
cutgeo = cut(bgmodel,geo) | ||
objects = Dict{Symbol,Any}(pairs(generate(cutgeo))) | ||
new(generate,objects,bgmodel) | ||
end | ||
end | ||
|
||
(c::EmbeddedCollection)(φh) = update_collection!(c,φh) | ||
|
||
function update_collection!(c::EmbeddedCollection,φh) | ||
geo = DiscreteGeometry(φh,c.bgmodel) | ||
cutgeo = cut(c.bgmodel,geo) | ||
merge!(c.objects,pairs(c.generate(cutgeo))) | ||
return c | ||
end | ||
|
||
function Base.getindex(c::EmbeddedCollection,key) | ||
return c.objects[key] | ||
end |
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,59 @@ | ||
module EmbeddedCollectionsTests | ||
using Test | ||
|
||
using GridapTopOpt | ||
using Gridap | ||
|
||
using GridapEmbedded | ||
using GridapEmbedded.LevelSetCutters | ||
using Gridap.Geometry, Gridap.FESpaces, Gridap.CellData, Gridap.Adaptivity | ||
|
||
function generate_model(D,n) | ||
domain = (D==2) ? (0,1,0,1) : (0,1,0,1,0,1) | ||
cell_partition = (D==2) ? (n,n) : (n,n,n) | ||
base_model = UnstructuredDiscreteModel((CartesianDiscreteModel(domain,cell_partition))) | ||
ref_model = refine(base_model, refinement_method = "barycentric") | ||
model = ref_model.model | ||
return model | ||
end | ||
|
||
function main() | ||
order = 1 | ||
model = generate_model(2,40) | ||
|
||
reffe = ReferenceFE(lagrangian,Float64,order) | ||
V_φ = TestFESpace(model,reffe) | ||
|
||
φ(r) = interpolate(x->sqrt((x[1]-0.5)^2+(x[2]-0.5)^2)-r,V_φ) # Circle | ||
|
||
φ0 = φ(0.2) | ||
Ωs = EmbeddedCollection(model,φ0) do cutgeo | ||
Ω = Triangulation(cutgeo,PHYSICAL_IN) | ||
Γ = EmbeddedBoundary(cutgeo) | ||
(; | ||
:Ω => Ω, | ||
:Γ => Γ, | ||
:dΩ => Measure(Ω,2*order), | ||
:dΓ => Measure(Γ,2*order) | ||
) | ||
end | ||
|
||
area(Ωs) = sum(∫(1.0)*Ωs[:dΩ]) | ||
contour(Ωs) = sum(∫(1.0)*Ωs[:dΓ]) | ||
|
||
for r in 0.2:0.1:0.5 | ||
update_collection!(Ωs,φ(r)) | ||
A = area(Ωs) | ||
C = contour(Ωs) | ||
println(" >> Radius: $r") | ||
println(" >> Area: $(A) (expected: $(π*r^2))") | ||
println(" >> Contour: $(C) (expected: $(2π*r))") | ||
@test abs(A - π*r^2) < 1e-3 | ||
@test abs(C - 2π*r) < 1e-3 | ||
println("---------------------------------") | ||
end | ||
end | ||
|
||
main() | ||
|
||
end |
2 changes: 1 addition & 1 deletion
2
test/seq/EmbeddedTests.jl → test/seq/EmbeddedDifferentiationTests.jl
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module EmbeddedTests | ||
module EmbeddedDifferentiationTests | ||
using Test | ||
|
||
using GridapTopOpt | ||
|
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