Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jul 11, 2024
1 parent 5b613dc commit 8fdf735
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
86 changes: 77 additions & 9 deletions test/AdaptivityUnstructuredTests.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,86 @@
using FillArrays
using PartitionedArrays, GridapDistributed
module AdaptivityUnstructuredTests
using Test

using Gridap
using Gridap.Adaptivity, Gridap.Arrays, Gridap.Geometry
using Gridap.Geometry
using Gridap.Adaptivity
using Gridap.FESpaces

using MPI
using GridapDistributed
using PartitionedArrays

using GridapDistributed: i_am_in

function test_adaptivity(ranks,cmodel,fmodel)
if i_am_in(ranks)
sol(x) = sum(x)
order = 3
qorder = 2*order
reffe = ReferenceFE(lagrangian,Float64,order)
amodel = fmodel

Ωf = Triangulation(amodel)
dΩf = Measure(Ωf,qorder)
Vf = FESpace(amodel,reffe)
Uf = TrialFESpace(Vf)
uh_fine = interpolate(sol,Vf)

Ωc = Triangulation(cmodel)
dΩc = Measure(Ωc,qorder)
Vc = FESpace(cmodel,reffe)
Uc = TrialFESpace(Vc)
uh_coarse = interpolate(sol,Vc)

dΩcf = Measure(Ωc,Ωf,qorder)

# Coarse to Fine projection
af(u,v) = (uv)*dΩf
lf(v) = (uh_coarse*v)*dΩf
op = AffineFEOperator(af,lf,Uf,Vf)
uh_coarse_to_fine = solve(op)

using GridapDistributed: GenericDistributedDiscreteModel
eh = uh_fine - uh_coarse_to_fine
@test sum((eheh)*dΩf) < 1e-6

ranks = with_debug() do distribute
distribute(LinearIndices((2,)))
# Fine to Coarse projection
ac(u,v) = (uv)*dΩc
lc(v) = (uh_fine*v)*dΩcf
op = AffineFEOperator(ac,lc,Uc,Vc)
uh_fine_to_coarse = solve(op)

eh = uh_coarse - uh_fine_to_coarse
@test sum((eheh)*dΩc) < 1e-6
end
return true
end

_cmodel = CartesianDiscreteModel(ranks,(2,1),(0,1,0,1),(4,4))
cmodel = UnstructuredDiscreteModel(_cmodel)
############################################################################################

function main(distribute,parts,ncells)
ranks = distribute(LinearIndices((prod(parts),)))

parent = UnstructuredDiscreteModel(
CartesianDiscreteModel(ranks,parts,(0,1,0,1),ncells)
)

child1 = refine(parent, refinement_method = "red_green" )
test_adaptivity(ranks,parent,child1)

fmodel = refine(cmodel)
child2 = refine(parent, refinement_method = "nvb" )
test_adaptivity(ranks,parent,child2)

child3 = refine(parent, refinement_method = "barycentric" )
test_adaptivity(ranks,parent,child3)

child4 = refine(parent, refinement_method = "simplexify" )
test_adaptivity(ranks,parent,child4)

end

function main(distribute)
main(distribute,(2,2),(8,8))
main(distribute,(2,2,1),(4,4,4))
end

end # module AdaptivityUnstructuredTests
1 change: 1 addition & 0 deletions test/TestApp/src/TestApp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module TestApp
include("../../StokesOpenBoundaryTests.jl")
include("../../AdaptivityTests.jl")
include("../../AdaptivityCartesianTests.jl")
include("../../AdaptivityUnstructuredTests.jl")
include("../../AdaptivityMultiFieldTests.jl")
include("../../BlockSparseMatrixAssemblersTests.jl")
end
1 change: 1 addition & 0 deletions test/mpi/runtests_np4_body.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function all_tests(distribute,parts)
TestApp.AdaptivityTests.main(distribute)
TestApp.AdaptivityCartesianTests.main(distribute)
TestApp.AdaptivityMultiFieldTests.main(distribute)
TestApp.AdaptivityUnstructuredTests.main(distribute)
PArrays.toc!(t,"Adaptivity")
end

Expand Down
4 changes: 3 additions & 1 deletion test/sequential/AdaptivityTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module AdaptivityTestsSeq
using PartitionedArrays

include("../AdaptivityCartesianTests.jl")
include("../AdaptivityUnstructuredTests.jl")
with_debug() do distribute
AdaptivityCartesianTests.main(distribute)
end
AdaptivityUnstructuredTests.main(distribute)
end

end # module

0 comments on commit 8fdf735

Please sign in to comment.