Skip to content

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jan 24, 2023
1 parent 0175bc2 commit ca122b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Adaptivity/EdgeBasedRefinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ end

function _get_green_vertex_permutation(p::Polytope{2},ref_edge::Integer)
if p == TRI
perm = circshift([1,2,3],3-ref_edge)
perm = circshift([1,2,3],ref_edge-3)
elseif p == QUAD
# Vertices and edges are not circularly labeled in QUAD, so
# we have to be inventive:
Expand Down
24 changes: 14 additions & 10 deletions src/Adaptivity/FineToCoarseFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ function Geometry.return_cache(a::FineToCoarseField,x::Point)
cm_cache = array_cache(cmaps)
xi_cache = Fields.return_cache(first(cmaps),x)
yi_cache = Fields.return_cache(first(fields),x)
return cmaps, fi_cache, cm_cache, xi_cache, yi_cache
return fi_cache, cm_cache, xi_cache, yi_cache
end

function Geometry.evaluate!(cache,a::FineToCoarseField,x::Point)
cmaps, fi_cache, cm_cache, xi_cache, yi_cache = cache
fi_cache, cm_cache, xi_cache, yi_cache = cache
fields, rr = a.fine_fields, a.rrule
cmaps = get_inverse_cell_map(rr)

child_id = x_to_cell(rr,x) # Find correct subcell
fi = getindex!(fi_cache,fields,child_id)
Expand Down Expand Up @@ -69,12 +70,13 @@ function Geometry.return_cache(a::FineToCoarseField,x::AbstractArray{<:Point})
yi_cache = Fields.return_cache(fi,zi)
y_cache = Arrays.CachedArray(yi_type,1)

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

function Geometry.evaluate!(cache,a::FineToCoarseField,x::AbstractArray{<:Point})
cmaps, fi_cache, mi_cache, xi_cache, zi_cache, yi_cache, y_cache = cache
fi_cache, mi_cache, xi_cache, zi_cache, yi_cache, y_cache = cache
fields, rr = a.fine_fields, a.rrule
cmaps = get_inverse_cell_map(rr)

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

Expand Down Expand Up @@ -113,12 +115,13 @@ function Geometry.return_cache(a::FineToCoarseField,x::Table{<:Point})
yi_cache = Fields.return_cache(fi,zi)
y_cache = Arrays.CachedArray(yi_type,1)

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

function Geometry.evaluate!(cache,a::FineToCoarseField,x::Table{<:Point})
@check length(x) == num_subcells(a.rrule)
cmaps, fi_cache, mi_cache, xi_cache, zi_cache, yi_cache, y_cache = cache
fi_cache, mi_cache, xi_cache, zi_cache, yi_cache, y_cache = cache
cmaps = get_inverse_cell_map(a.rrule)
fields = a.fine_fields

Arrays.setsize!(y_cache, size(x.data))
Expand All @@ -134,7 +137,7 @@ function Geometry.evaluate!(cache,a::FineToCoarseField,x::Table{<:Point})
return y_cache.array
end

function Geometry.return_cache(a::FineToCoarseField,x::AbstractArray{<:Point},child_ids::AbstractArray{Integer})
function Geometry.return_cache(a::FineToCoarseField,x::AbstractArray{<:Point},child_ids::AbstractArray{<:Integer})
fields = a.fine_fields
cmaps = get_inverse_cell_map(a.rrule)

Expand All @@ -155,11 +158,12 @@ function Geometry.return_cache(a::FineToCoarseField,x::AbstractArray{<:Point},ch
yi_cache = Fields.return_cache(fi,zi)
y_cache = Arrays.CachedArray(yi_type,1)

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

function Geometry.evaluate!(cache,a::FineToCoarseField,x::AbstractArray{<:Point},child_ids::AbstractArray{Integer})
cmaps, fi_cache, mi_cache, xi_cache, id_cache, zi_cache, yi_cache, y_cache = cache
function Geometry.evaluate!(cache,a::FineToCoarseField,x::AbstractArray{<:Point},child_ids::AbstractArray{<:Integer})
fi_cache, mi_cache, xi_cache, id_cache, zi_cache, yi_cache, y_cache = cache
cmaps = get_inverse_cell_map(a.rrule)
fields = a.fine_fields

Arrays.setsize!(y_cache, size(x))
Expand Down
19 changes: 11 additions & 8 deletions src/Adaptivity/FineToCoarseReferenceFEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ struct FineToCoarseDofBasis{T,A,B,C} <: AbstractVector{T}
child_ids :: C

function FineToCoarseDofBasis(dof_basis::AbstractVector{T},rrule::RefinementRule) where {T<:Dof}
child_ids = map(x -> x_to_cell(rrule,x),dof_basis.nodes)
nodes = get_nodes(dof_basis)
child_ids = map(x -> x_to_cell(rrule,x),nodes)

A = typeof(dof_basis)
B = typeof(rrule)
Expand All @@ -27,8 +28,8 @@ ReferenceFEs.get_nodes(a::FineToCoarseDofBasis) = get_nodes(a.dof_basis)
Arrays.return_cache(b::FineToCoarseDofBasis,field) = return_cache(b.dof_basis,field)
Arrays.evaluate!(cache,b::FineToCoarseDofBasis,field) = evaluate!(cache,b.dof_basis,field)

# Spetialised behaviour
function Arrays.return_cache(s::FineToCoarseDofBasis{<:LagrangianDofBasis},field::FineToCoarseField)
# Spetialized behaviour
function Arrays.return_cache(s::FineToCoarseDofBasis{T,<:LagrangianDofBasis},field::FineToCoarseField) where T
b = s.dof_basis
cf = return_cache(field,b.nodes,s.child_ids)
vals = evaluate!(cf,field,b.nodes,s.child_ids)
Expand All @@ -38,13 +39,13 @@ function Arrays.return_cache(s::FineToCoarseDofBasis{<:LagrangianDofBasis},field
return (c, cf)
end

function Arrays.evaluate!(cache,s::FineToCoarseDofBasis{<:LagrangianDofBasis},field::FineToCoarseField)
function Arrays.evaluate!(cache,s::FineToCoarseDofBasis{T,<:LagrangianDofBasis},field::FineToCoarseField) where T
c, cf = cache
b = s.dof_basis
vals = evaluate!(cf,field,b.nodes,s.child_ids)
ndofs = length(b.dof_to_node)
T = eltype(vals)
ncomps = num_components(T)
T2 = eltype(vals)
ncomps = num_components(T2)
@check ncomps == num_components(eltype(b.node_and_comp_to_dof)) """\n
Unable to evaluate LagrangianDofBasis. The number of components of the
given Field does not match with the LagrangianDofBasis.
Expand All @@ -58,7 +59,7 @@ function Arrays.evaluate!(cache,s::FineToCoarseDofBasis{<:LagrangianDofBasis},fi
ReferenceFEs._evaluate_lagr_dof!(c,vals,b.node_and_comp_to_dof,ndofs,ncomps)
end

function Arrays.return_cache(s::FineToCoarseDofBasis{<:MomentBasedDofBasis},field::FineToCoarseField)
function Arrays.return_cache(s::FineToCoarseDofBasis{T,<:MomentBasedDofBasis},field::FineToCoarseField) where T
b = s.dof_basis
cf = return_cache(field,b.nodes,s.child_ids)
vals = evaluate!(cf,field,b.nodes,s.child_ids)
Expand All @@ -68,7 +69,7 @@ function Arrays.return_cache(s::FineToCoarseDofBasis{<:MomentBasedDofBasis},fiel
return (c, cf)
end

function Arrays.evaluate!(cache,s::FineToCoarseDofBasis{<:MomentBasedDofBasis},field)
function Arrays.evaluate!(cache,s::FineToCoarseDofBasis{T,<:MomentBasedDofBasis},field::FineToCoarseField) where T
c, cf = cache
b = s.dof_basis
vals = evaluate!(cf,field,b.nodes,s.child_ids)
Expand Down Expand Up @@ -101,6 +102,8 @@ ReferenceFEs.Conformity(reffe::FineToCoarseRefFE) = Conformity(reffe.reffe)
ReferenceFEs.get_face_dofs(reffe::FineToCoarseRefFE) = get_face_dofs(reffe.reffe)
ReferenceFEs.get_shapefuns(reffe::FineToCoarseRefFE) = get_shapefuns(reffe.reffe)
ReferenceFEs.get_metadata(reffe::FineToCoarseRefFE) = get_metadata(reffe.reffe)
ReferenceFEs.get_orders(reffe::FineToCoarseRefFE) = get_orders(reffe.reffe)
ReferenceFEs.get_order(reffe::FineToCoarseRefFE) = get_order(reffe.reffe)

ReferenceFEs.Conformity(reffe::FineToCoarseRefFE,sym::Symbol) = Conformity(reffe.reffe,sym)
ReferenceFEs.get_face_own_dofs(reffe::FineToCoarseRefFE,conf::Conformity) = get_face_own_dofs(reffe.reffe,conf)
Expand Down

0 comments on commit ca122b5

Please sign in to comment.