Skip to content

Commit

Permalink
Added printing for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Nov 11, 2024
1 parent d321890 commit e39b580
Showing 1 changed file with 63 additions and 4 deletions.
67 changes: 63 additions & 4 deletions test/seq/EmbeddedTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Gridap, Gridap.Geometry, Gridap.Adaptivity
using GridapEmbedded, GridapEmbedded.LevelSetCutters

using Gridap.Arrays: Operation
using GridapTopOpt: get_conormal_vector
using GridapTopOpt: get_conormal_vector,get_subfacet_normal_vector,get_ghost_normal_vector

function generate_model(D,n)
domain = (D==2) ? (0,1,0,1) : (0,1,0,1,0,1)
Expand Down Expand Up @@ -41,8 +41,11 @@ function level_set(shape::Symbol)
end
end

function main(model,φ::Function,f::Function)

function main(
model,φ::Function,f::Function;
vtk=false,
name="embedded"
)
order = 1
reffe = ReferenceFE(lagrangian,Float64,order)
V_φ = TestFESpace(model,reffe)
Expand Down Expand Up @@ -109,13 +112,69 @@ function main(model,φ::Function,f::Function)
dJ_int_exact_vec = assemble_vector(dJ_int_exact,V_φ)

@test norm(dJ_int_AD_vec - dJ_int_exact_vec) < 1e-10

if vtk
path = "results/$(name)"
Ω_bg = Triangulation(model)
writevtk(
Ω_bg,"$(path)_results",
cellfields = [
"φh" => φh,"∇φh" => (φh),
"dJ_bulk_AD" => FEFunction(V_φ,dJ_bulk_AD_vec),
"dJ_bulk_exact" => FEFunction(V_φ,dJ_bulk_exact_vec),
"dJ_int_AD" => FEFunction(V_φ,dJ_int_AD_vec),
"dJ_int_exact" => FEFunction(V_φ,dJ_int_exact_vec)
],
celldata = [
"inoutcut" => GridapEmbedded.Interfaces.compute_bgcell_to_inoutcut(model,geo)
];
append = false
)

writevtk(
Ω, "$(path)_bulk"; append = false
)
writevtk(
Γ, "$(path)_boundary"; append = false
)

n_∂Ω_Λ = get_subfacet_normal_vector(Λ)
n_k_Λ = get_ghost_normal_vector(Λ)
writevtk(
Λ, "$(path)_skeleton",
cellfields = [
"n_∂Ω.plus" => n_∂Ω_Λ.plus,"n_∂Ω.minus" => n_∂Ω_Λ.minus,
"n_k.plus" => n_k_Λ.plus,"n_k.minus" => n_k_Λ.minus,
"n_S" => n_S_Λ,
"m_k.plus" => m_k_Λ.plus,"m_k.minus" => m_k_Λ.minus,
"∇ˢφ" => ∇ˢφ_Λ,
"∇φh_Γs_plus" => (φh).plus,"∇φh_Γs_minus" => (φh).minus,
"jump(fh*m_k)" => jump(fh*m_k_Λ)
];
append = false
)

if num_cells(Σ) > 0
n_∂Ω_Σ = get_subfacet_normal_vector(Σ)
n_k_Σ = get_ghost_normal_vector(Σ)
writevtk(
Σ, "$(path)_skeleton",
cellfields = [
"n_∂Ω" => n_∂Ω_Σ, "n_k" => n_k_Σ,
"n_S" => n_S_Σ, "m_k" => m_k_Σ,
"∇ˢφ" => ∇ˢφ_Σ, "∇φh_Γs" => (φh),
];
append = false
)
end
end
end

D = 2
n = 10
model = generate_model(D,n)
φ = level_set(:circle)
f = x -> 1.0
main(model,φ,f)
main(model,φ,f;vtk=true)

end

0 comments on commit e39b580

Please sign in to comment.