Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jan 2, 2025
1 parent b3002db commit b741a9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
33 changes: 19 additions & 14 deletions src/FESpaces/Pullbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,28 @@ function get_cell_pushforward(
return CoVariantPiolaMap(), change, (Jt,)
end

# SignFlipMap
# NormalSignMap

struct SignFlipMap{T} <: Map
"""
struct NormalSignMap <: Map
...
end
"""
struct NormalSignMap{T} <: Map
model::T
facet_owners::Vector{Int32}
end

function SignFlipMap(model)
function NormalSignMap(model)
facet_owners = compute_facet_owners(model)
SignFlipMap(model,facet_owners)
NormalSignMap(model,facet_owners)
end

function return_value(k::SignFlipMap,reffe,facet_own_dofs,cell)
function return_value(k::NormalSignMap,reffe,facet_own_dofs,cell)
Diagonal(fill(one(Float64), num_dofs(reffe)))

Check warning on line 74 in src/FESpaces/Pullbacks.jl

View check run for this annotation

Codecov / codecov/patch

src/FESpaces/Pullbacks.jl#L73-L74

Added lines #L73 - L74 were not covered by tests
end

function return_cache(k::SignFlipMap,reffe,facet_own_dofs,cell)
function return_cache(k::NormalSignMap,reffe,facet_own_dofs,cell)
model = k.model
Dc = num_cell_dims(model)
topo = get_grid_topology(model)
Expand All @@ -80,33 +85,33 @@ function return_cache(k::SignFlipMap,reffe,facet_own_dofs,cell)
return cell_facets, cell_facets_cache, CachedVector(Float64)
end

function evaluate!(cache,k::SignFlipMap,reffe,facet_own_dofs,cell)
cell_facets,cell_facets_cache,sign_flip_cache = cache
function evaluate!(cache,k::NormalSignMap,reffe,facet_own_dofs,cell)
cell_facets,cell_facets_cache,dof_sign_cache = cache
facet_owners = k.facet_owners

setsize!(sign_flip_cache, (num_dofs(reffe),))
sign_flip = sign_flip_cache.array
fill!(sign_flip, one(eltype(sign_flip)))
setsize!(dof_sign_cache, (num_dofs(reffe),))
dof_sign = dof_sign_cache.array
fill!(dof_sign, one(eltype(dof_sign)))

facets = getindex!(cell_facets_cache,cell_facets,cell)
for (lfacet,facet) in enumerate(facets)
owner = facet_owners[facet]
if owner != cell
for dof in facet_own_dofs[lfacet]
sign_flip[dof] = -1.0
dof_sign[dof] = -1.0
end
end
end

return Diagonal(sign_flip)
return Diagonal(dof_sign)
end

function get_sign_flip(model::DiscreteModel{Dc}, cell_reffe) where Dc
# Comment: lazy_maps on cell_reffes are very optimised, since they are CompressedArray/FillArray
get_facet_own_dofs(reffe) = view(get_face_own_dofs(reffe),get_dimrange(get_polytope(reffe),Dc-1))
cell_facet_own_dofs = lazy_map(get_facet_own_dofs, cell_reffe)
cell_ids = IdentityVector(Int32(num_cells(model)))
return lazy_map(SignFlipMap(model), cell_reffe, cell_facet_own_dofs, cell_ids)
return lazy_map(NormalSignMap(model), cell_reffe, cell_facet_own_dofs, cell_ids)
end

function compute_facet_owners(model::DiscreteModel{Dc}) where {Dc}
Expand Down
4 changes: 0 additions & 4 deletions test/AdaptivityTests/EdgeBasedRefinementTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ function test_grid_transfers(parent,model,order)
U_f = TrialFESpace(V_f,sol)
V_c = TestFESpace(parent,reffe;dirichlet_tags="boundary")
U_c = TrialFESpace(V_c,sol)
V_c_fast = TestFESpace(parent,rrules,reffe;dirichlet_tags="boundary")
U_c_fast = TrialFESpace(V_c_fast,sol)

# CellField: Coarse -> Fine
cf_c_phy = CellField(sol,ctrian)
Expand Down Expand Up @@ -78,14 +76,12 @@ function test_grid_transfers(parent,model,order)
uh_c_inter = interpolate(uh_f,U_c)
uh_c_inter2 = interpolate_everywhere(uh_f,U_c)
uh_c_inter3 = interpolate_dirichlet(uh_f,U_c)
uh_c_inter4 = interpolate(uh_f,U_c_fast)

@test l2_error(uh_f,uh_f_inter,dΩ_f) < 1.e-8
@test l2_error(uh_f,uh_f_inter2,dΩ_f) < 1.e-8

@test l2_error(uh_c,uh_c_inter,dΩ_c) < 1.e-8
@test l2_error(uh_c,uh_c_inter2,dΩ_c) < 1.e-8
@test l2_error(uh_c,uh_c_inter4,dΩ_c) < 1.e-8

# Coarse FEFunction -> Fine FEFunction, by projection
af(u,v) = (vu)*dΩ_f
Expand Down

0 comments on commit b741a9a

Please sign in to comment.