Skip to content

Commit

Permalink
[distributed] add distributed poisson tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmartorell committed Apr 30, 2024
1 parent 55a387c commit d06626b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/DistributedTests/CutterTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ function main(distribute;
writevtk(Γ,"Γ")
end

@test vol_in + vol_out - vol_box < 1e-10
@test vol_in + vol_out - vol_box < 1e-9
ref_vol,ref_surf = reference_volume_and_surface(geoname)
if ref_vol > 0
@test abs(vol_in - ref_vol) < 1e-10
@test abs(surf - ref_surf) < 1e-10
@test abs(vol_in - ref_vol) < 1e-9
@test abs(surf - ref_surf) < 1e-9
end
end

function reference_volume_and_surface(geoname)
volumes = Dict("cube"=>1.0,)
surfaces = Dict("cube"=>6.0,)
volumes = Dict("cube"=>1.0,"Bunny-LowPoly"=>273280.03374196636)
surfaces = Dict("cube"=>6.0,"Bunny-LowPoly"=>29490.7154966073)
if haskey(volumes,geoname)
volumes[geoname],surfaces[geoname]
else
Expand Down
98 changes: 98 additions & 0 deletions test/DistributedTests/Poisson.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
module DistributedPoissonTests

using Gridap
using STLCutters
using GridapDistributed
using PartitionedArrays
using GridapEmbedded
using Test

function main(distribute;
np = (1,1,1),
nc = (2,2,2),
geoname = "cube",
δ = 0.2,
tolfactor=10^4,
simplex=false,
vtk = false,
verbose = false)

# Manufactured solution
u(x) = x[1] + x[2] - x[3]
f(x) = - Δ(u)(x)
ud(x) = u(x)

filename = joinpath(@__DIR__,"..","data","$geoname.stl")
if !isfile(filename)
filename = download_thingi10k(id;path="")
end

ranks = distribute(LinearIndices((prod(np),)))
geo = STLGeometry(filename)

pmin,pmax = get_bounding_box(geo)
diagonal = pmax-pmin
pmin = pmin - diagonal*δ
pmax = pmax + diagonal*δ
bgmodel = CartesianDiscreteModel(ranks,np,pmin,pmax,nc)
if simplex
bgmodel = simplexify(bgmodel,positive=true)
end

cutter = STLCutter(;tolfactor)
cutgeo = cut(cutter,bgmodel,geo)

Ω = Triangulation(cutgeo,PHYSICAL_IN)
Γ = EmbeddedBoundary(cutgeo)
n_Γ = get_normal_vector(Γ)
degree = 2
= Measure(Ω,degree)
= Measure(Γ,degree)

# Setup FESpace
order = 1
Ω_act = Triangulation(cutgeo,ACTIVE)
V = TestFESpace(Ω_act,ReferenceFE(lagrangian,Float64,order),conformity=:H1)
U = TrialFESpace(V)

# Weak form
γ = 10.0
h = (pmax - pmin)[1] / nc[1]

a(u,v) =
( (v)(u) ) *+
( (γ/h)*v*u - v*(n_Γ(u)) - (n_Γ(v))*u ) *

l(v) =
( v*f ) *+
( (γ/h)*v*ud - (n_Γ(v))*ud ) *

# FE problem
@time op = AffineFEOperator(a,l,U,V)
@time uh = solve(op)

e = u - uh

# Postprocess
l2(u) = sqrt(sum( ( u*u )*dΩ ))
h1(u) = sqrt(sum( ( u*u + (u)(u) )*dΩ ))

el2 = l2(e)
eh1 = h1(e)
ul2 = l2(uh)
uh1 = h1(uh)

if vtk
writevtk(Ω,"results",cellfields=["uh"=>uh])
end

if verbose
println("L2 error: ", el2/ul2)
println("H1 error: ", eh1/uh1)
end

@test el2/ul2 < 1.e-8
@test eh1/uh1 < 1.e-7
end

end # module
6 changes: 6 additions & 0 deletions test/DistributedTests/mpi/runtests_body.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const PArrays = PartitionedArrays
using MPI

include("../CutterTests.jl")
include("../Poisson.jl")

if ! MPI.Initialized()
MPI.Init()
Expand All @@ -22,6 +23,11 @@ function all_tests(distribute,parts)
DistributedCutterTests.main(distribute,np=parts,nc=(8,8,8),simplex=true)
PArrays.toc!(t,"MPIDistributedCutter")

DistributedPoissonTests.main(distribute,np=parts,nc=(4,4,4))
DistributedPoissonTests.main(distribute,np=parts,nc=(8,8,8))
DistributedPoissonTests.main(distribute,np=(2,2,2),nc=(8,8,8),geoname="Bunny-LowPoly")
PArrays.toc!(t,"MPIDistributedPoisson")

display(t)
end

Expand Down
2 changes: 2 additions & 0 deletions test/DistributedTests/sequential/CutterTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ with_debug() do distribute
main(distribute,np=(2,2,2),nc=(8,8,8))
main(distribute,np=(2,2,2),nc=(4,4,4),simplex=true)
main(distribute,np=(2,2,2),nc=(8,8,8),simplex=true)
main(distribute,np=(2,2,2),nc=(8,8,8),geoname="Bunny-LowPoly")

# Distributed with propagation
main(distribute,np=(3,3,3),nc=(9,9,9))
main(distribute,np=(3,3,3),nc=(9,9,9),simplex=true)
main(distribute,np=(3,3,3),nc=(9,9,9),geoname="Bunny-LowPoly")

# Untouched subdomain interiors
main(distribute,np=(3,3,3),nc=(9,9,9),δ=0.5)
Expand Down
16 changes: 16 additions & 0 deletions test/DistributedTests/sequential/PoissonTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module PoissonTestsSeq
using PartitionedArrays
include("../Poisson.jl")
main = DistributedPoissonTests.main

with_debug() do distribute

# Degenerated Case
main(distribute,np=(1,1,1),nc=(4,4,4))

# Distributed without propagation
main(distribute,np=(2,2,2),nc=(4,4,4))
main(distribute,np=(2,2,2),nc=(8,8,8))

end
end

0 comments on commit d06626b

Please sign in to comment.