Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jul 23, 2024
1 parent 094cafc commit 06ea0a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
26 changes: 12 additions & 14 deletions src/Adaptivity/FineToCoarseFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,20 @@ function Geometry.return_cache(a::FineToCoarseField,x::AbstractArray{<:Point})

# Generic caches
child_ids = map(i -> x_to_cell(rr,getindex!(xi_cache,x,i)),eachindex(x))
pos = findfirst(id -> !is_zero[id],child_ids)
xi = getindex!(xi_cache,x,pos)
id = child_ids[pos]
id = x_to_cell(rr,xi)

xi = first(x)
id = first(child_ids)
mi = getindex!(mi_cache,cmaps,id)
fi = getindex!(fi_cache,fields,id)

zi_cache = Fields.return_cache(mi,xi)
zi = evaluate!(zi_cache,mi,xi)
zi = zero(evaluate!(zi_cache,mi,xi))

yi_type = Fields.return_type(fi,zi)
yi_cache = map(fii -> Fields.return_cache(fii,zi), fields)
yi_types = map(fii -> Fields.return_type(fii,zi), fields)
yi_type = first(yi_types)
@assert all(t -> yi_type == t, yi_types)
y_cache = Arrays.CachedArray(zeros(yi_type,size(x)))

# Evaluation caches
fi_zero = ZeroField(fi)
yi_nonzero_cache = Fields.return_cache(fi,zi)
yi_zero_cache = Fields.return_cache(fi_zero,zi)
yi_cache = (yi_nonzero_cache,yi_zero_cache)

return fi_cache, mi_cache, xi_cache, zi_cache, yi_cache, y_cache
end

Expand All @@ -79,13 +74,16 @@ function Geometry.evaluate!(cache,a::FineToCoarseField,x::AbstractArray{<:Point}

Arrays.setsize!(y_cache, size(x))

display(yi_cache)

for i in eachindex(x)
xi = getindex!(xi_cache,x,i)
child_id = x_to_cell(rr,xi)
fi = getindex!(fi_cache,fields,child_id)
mi = getindex!(mi_cache,cmaps,child_id)
zi = Fields.evaluate!(zi_cache,mi,xi)
_yi_cache = yi_cache[is_zero[child_id]+1]
_yi_cache = yi_cache[child_id]
display(child_id)
y_cache.array[i] = Fields.evaluate!(_yi_cache,fi,zi)
end
return y_cache.array
Expand Down
37 changes: 32 additions & 5 deletions src/Adaptivity/MacroFEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,22 @@ ReferenceFEs for the subcells.
"""
function MacroReferenceFE(
rrule::RefinementRule,
reffes::AbstractVector{<:ReferenceFE},
reffes::AbstractVector{<:ReferenceFE};
conformity = Conformity(first(reffes))
)
@check length(reffes) == num_subcells(rrule)

grid = rrule.ref_grid
space = FESpace(grid,reffes)
space = FESpace(grid,reffes;conformity=conformity)

conn = get_cell_dof_ids(space)
basis = FineToCoarseArray(rrule,collect(map(get_shapefuns,reffes)),conn)
dofs = FineToCoarseArray(rrule,collect(map(get_dof_basis,reffes)),conn)
face_dofs = get_macro_face_own_dofs(rrule,space,reffes)
face_dofs = get_macro_face_own_dofs(conformity,rrule,space,reffes)

ndofs = num_free_dofs(space)
poly = get_polytope(rrule)
prebasis = FineToCoarseArray(rrule,collect(map(get_prebasis,reffes)))
conformity = Conformity(first(reffes))
@check all(r -> Conformity(r) == conformity,reffes)
metadata = (rrule,conn)

return GenericRefFE{MacroRefFE}(
Expand All @@ -236,6 +235,21 @@ function ReferenceFEs.get_face_own_dofs(reffe::GenericRefFE{MacroRefFE}, conf::C
return get_face_dofs(reffe)
end

function ReferenceFEs.get_face_own_dofs(reffe::GenericRefFE{MacroRefFE}, conf::L2Conformity)
@check conf == Conformity(reffe)
return get_face_dofs(reffe)
end

function ReferenceFEs.Conformity(reffe::GenericRefFE{MacroRefFE},sym::Symbol)
if sym == :L2
L2Conformity()
elseif sym == :H1
H1Conformity()
else
@notimplemented
end
end

"""
get_macro_face_own_dofs(rrule::RefinementRule,space::FESpace,reffes::AbstractVector{<:ReferenceFE})
Expand All @@ -244,6 +258,7 @@ returns the dofs owned by each face of the macro-element (i.e each face of the
underlying polytope).
"""
function get_macro_face_own_dofs(
::Conformity,
rrule::RefinementRule{<:Polytope{Dc}},
space::FESpace,
reffes::AbstractVector{<:ReferenceFE}
Expand Down Expand Up @@ -292,3 +307,15 @@ function get_macro_face_own_dofs(

return face_to_dof
end

function get_macro_face_own_dofs(
::L2Conformity,
rrule::RefinementRule{<:Polytope{Dc}},
space::FESpace,
reffes::AbstractVector{<:ReferenceFE}
) where Dc
nfaces = sum(d -> num_faces(get_polytope(rrule),d),0:Dc)
face_to_dof = [Int[] for i in 1:nfaces]
face_to_dof[nfaces] = collect(1:num_free_dofs(space))
return face_to_dof
end

0 comments on commit 06ea0a5

Please sign in to comment.