|
| 1 | +module HcurlProjectionTests |
| 2 | + |
| 3 | +using Gridap |
| 4 | +using PartitionedArrays |
| 5 | +using GridapDistributed |
| 6 | +using Test |
| 7 | + |
| 8 | +u_ex_2D((x,y)) = 2*VectorValue(-y,x) |
| 9 | +f_ex_2D(x) = u_ex_2D(x) |
| 10 | +u_ex_3D((x,y,z)) = 2*VectorValue(-y,x,0.) - VectorValue(0.,-z,y) |
| 11 | +f_ex_3D(x) = u_ex_3D(x) |
| 12 | + |
| 13 | +function get_analytical_functions(Dc) |
| 14 | + if Dc==2 |
| 15 | + return u_ex_2D, f_ex_2D |
| 16 | + else |
| 17 | + @assert Dc==3 |
| 18 | + return u_ex_3D, f_ex_3D |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | +function solve_hcurl_projection(model::GridapDistributed.DistributedDiscreteModel{Dc},order) where {Dc} |
| 23 | + u_ex, f_ex=get_analytical_functions(Dc) |
| 24 | + |
| 25 | + V = FESpace(model, |
| 26 | + ReferenceFE(nedelec,order), |
| 27 | + conformity=:Hcurl, |
| 28 | + dirichlet_tags="boundary") |
| 29 | + |
| 30 | + U = TrialFESpace(V,u_ex) |
| 31 | + |
| 32 | + trian = Triangulation(model) |
| 33 | + degree = 2*(order+1) |
| 34 | + dΩ = Measure(trian,degree) |
| 35 | + |
| 36 | + a(u,v) = ∫( (∇×u)⋅(∇×v) + u⋅v )dΩ |
| 37 | + l(v) = ∫(f_ex⋅v)dΩ |
| 38 | + |
| 39 | + op = AffineFEOperator(a,l,U,V) |
| 40 | + if (num_free_dofs(U)==0) |
| 41 | + # UMFPACK cannot handle empty linear systems |
| 42 | + uh = zero(U) |
| 43 | + else |
| 44 | + uh = solve(op) |
| 45 | + end |
| 46 | + uh,U |
| 47 | + end |
| 48 | + |
| 49 | + function check_error_hcurl_projection(model::GridapDistributed.DistributedDiscreteModel{Dc},order,uh) where {Dc} |
| 50 | + trian = Triangulation(model) |
| 51 | + degree = 2*(order+1) |
| 52 | + dΩ = Measure(trian,degree) |
| 53 | + |
| 54 | + u_ex, f_ex = get_analytical_functions(Dc) |
| 55 | + |
| 56 | + eu = u_ex - uh |
| 57 | + |
| 58 | + l2(v) = sqrt(sum(∫(v⋅v)*dΩ)) |
| 59 | + hcurl(v) = sqrt(sum(∫(v⋅v + (∇×v)⋅(∇×v))*dΩ)) |
| 60 | + |
| 61 | + eu_l2 = l2(eu) |
| 62 | + eu_hcurl = hcurl(eu) |
| 63 | + |
| 64 | + tol = 1.0e-6 |
| 65 | + @test eu_l2 < tol |
| 66 | + @test eu_hcurl < tol |
| 67 | +end |
| 68 | + |
| 69 | + function test_2d(ranks,parts,order) |
| 70 | + domain = (0,1,0,1) |
| 71 | + model = CartesianDiscreteModel(ranks,parts,domain,(4,4)) |
| 72 | + solve_hcurl_projection(model,order) |> x -> check_error_hcurl_projection(model,order,x[1]) |
| 73 | + end |
| 74 | + |
| 75 | + function test_3d(ranks,parts,order) |
| 76 | + domain = (0,1,0,1,0,1) |
| 77 | + model = CartesianDiscreteModel(ranks,parts,domain,(4,4,4)) |
| 78 | + solve_hcurl_projection(model,order) |> x -> check_error_hcurl_projection(model,order,x[1]) |
| 79 | + end |
| 80 | + |
| 81 | +function main(distribute,parts) |
| 82 | + ranks = distribute(LinearIndices((prod(parts),))) |
| 83 | + |
| 84 | + if length(parts)==2 |
| 85 | + for order=0:2 |
| 86 | + test_2d(ranks,parts,order) |
| 87 | + end |
| 88 | + elseif length(parts)==3 |
| 89 | + for order=0:2 |
| 90 | + test_3d(ranks,parts,order) |
| 91 | + end |
| 92 | + else |
| 93 | + @assert false |
| 94 | + end |
| 95 | +end |
| 96 | + |
| 97 | +end #module |
0 commit comments