From 6f50ebb3f671f2cac20dc49d480ef663af38ec8c Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 2 Jan 2025 16:31:52 +1100 Subject: [PATCH] Minor bugfixes --- src/FESpaces/Pullbacks.jl | 2 +- src/ReferenceFEs/Dofs.jl | 54 ++++++++++++++++++++++++++++++-- src/ReferenceFEs/Pullbacks.jl | 58 ++--------------------------------- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/FESpaces/Pullbacks.jl b/src/FESpaces/Pullbacks.jl index 8e006a6f2..0b05d2403 100644 --- a/src/FESpaces/Pullbacks.jl +++ b/src/FESpaces/Pullbacks.jl @@ -66,7 +66,7 @@ function SignFlipMap(model) end function return_value(k::SignFlipMap,reffe,facet_own_dofs,cell) - fill(false, num_dofs(reffe)) + Diagonal(fill(one(Float64), num_dofs(reffe))) end function return_cache(k::SignFlipMap,reffe,facet_own_dofs,cell) diff --git a/src/ReferenceFEs/Dofs.jl b/src/ReferenceFEs/Dofs.jl index 42d913929..1a9fb3025 100644 --- a/src/ReferenceFEs/Dofs.jl +++ b/src/ReferenceFEs/Dofs.jl @@ -39,7 +39,7 @@ function linear_combination(a::AbstractMatrix{<:Number}, b::AbstractVector{<:Dof end function return_cache(b::LinearCombinationDofVector,field) - k = LinearCombinationMap(:) + k = Fields.LinearCombinationMap(:) cf = return_cache(b.dofs,field) fx = evaluate!(cf,b.dofs,field) ck = return_cache(k,b.values,fx) @@ -48,11 +48,61 @@ end function evaluate!(cache,b::LinearCombinationDofVector,field) cf, ck = cache - k = LinearCombinationMap(:) + k = Fields.LinearCombinationMap(:) fx = evaluate!(cf,b.dofs,field) return evaluate!(ck,k,b.values,fx) end +""" + struct MappedDofBasis{T<:Dof,MT,BT} <: AbstractVector{T} + F :: MT + σ :: BT + args + end + +Represents η = σ∘F, evaluated as η(φ) = σ(F(φ,args...)) + + - σ : V* -> R is a dof basis + - F : W -> V is a map between function spaces + +Intended combinations would be: + +- σ : V* -> R dof basis in the physical domain and F* : V̂ -> V is a pushforward map. +- ̂σ : V̂* -> R dof basis in the reference domain and (F*)^-1 : V -> V̂ is an inverse pushforward map. + +""" +struct MappedDofBasis{T<:Dof,MT,BT,A} <: AbstractVector{T} + F :: MT + dofs :: BT + args :: A + + function MappedDofBasis(F::Map, dofs::AbstractVector{<:Dof}, args...) + T = eltype(dofs) + MT = typeof(F) + BT = typeof(dofs) + A = typeof(args) + new{T,MT,BT,A}(F,dofs,args) + end +end + +Base.size(b::MappedDofBasis) = size(b.dofs) + +# Technically wrong, but the individual dofs are fake anyway +Base.getindex(b::MappedDofBasis, i) = getindex(b.dofs,i) + +function Arrays.return_cache(b::MappedDofBasis, fields) + f_cache = return_cache(b.F,fields,b.args...) + ffields = evaluate!(f_cache,b.F,fields,b.args...) + dofs_cache = return_cache(b.dofs,ffields) + return f_cache, dofs_cache +end + +function Arrays.evaluate!(cache, b::MappedDofBasis, fields) + f_cache, dofs_cache = cache + ffields = evaluate!(f_cache,b.F,fields,b.args...) + evaluate!(dofs_cache,b.dofs,ffields) +end + """ test_dof(dof,field,v;cmp::Function=(==)) diff --git a/src/ReferenceFEs/Pullbacks.jl b/src/ReferenceFEs/Pullbacks.jl index 02ef0a13a..46602b495 100644 --- a/src/ReferenceFEs/Pullbacks.jl +++ b/src/ReferenceFEs/Pullbacks.jl @@ -43,7 +43,7 @@ end function Arrays.evaluate!( cache, - ::Broadcasting{typeof(∇)}, + ::Broadcasting{typeof(gradient)}, a::Fields.BroadcastOpFieldArray{<:Pushforward} ) v, pf_args... = a.args @@ -111,58 +111,6 @@ function evaluate!( Operation(k)(f_phys,args...) end -# MappedDofBasis - -""" - struct MappedDofBasis{T<:Dof,MT,BT} <: AbstractVector{T} - F :: MT - σ :: BT - args - end - -Represents η = σ∘F, evaluated as η(φ) = σ(F(φ,args...)) - - - σ : V* -> R is a dof basis - - F : W -> V is a map between function spaces - -Intended combinations would be: - -- σ : V* -> R dof basis in the physical domain and F* : V̂ -> V is a pushforward map. -- ̂σ : V̂* -> R dof basis in the reference domain and (F*)^-1 : V -> V̂ is an inverse pushforward map. - -""" -struct MappedDofBasis{T<:Dof,MT,BT,A} <: AbstractVector{T} - F :: MT - dofs :: BT - args :: A - - function MappedDofBasis(F::Map, dofs::AbstractVector{<:Dof}, args...) - T = eltype(dofs) - MT = typeof(F) - BT = typeof(dofs) - A = typeof(args) - new{T,MT,BT,A}(F,dofs,args) - end -end - -Base.size(b::MappedDofBasis) = size(b.dofs) - -# Technically wrong, but the individual dofs are fake anyway -Base.getindex(b::MappedDofBasis, i) = getindex(b.dofs,i) - -function Arrays.return_cache(b::MappedDofBasis, fields) - f_cache = return_cache(b.F,fields,b.args...) - ffields = evaluate!(f_cache,b.F,fields,b.args...) - dofs_cache = return_cache(b.dofs,ffields) - return f_cache, dofs_cache -end - -function Arrays.evaluate!(cache, b::MappedDofBasis, fields) - f_cache, dofs_cache = cache - ffields = evaluate!(f_cache,b.F,fields,b.args...) - evaluate!(dofs_cache,b.dofs,ffields) -end - # Pullback """ @@ -282,7 +230,7 @@ function evaluate!( cache, ::CoVariantPiolaMap, v_ref::Number, Jt::Number ) # we right-multiply to compute the gradient correctly - return v_ref⋅transpose(inv(Jt)) + return v_ref ⋅ transpose(inv(Jt)) end function return_cache( @@ -294,5 +242,5 @@ end function evaluate!( cache, ::InversePushforward{CoVariantPiolaMap}, v_phys::Number, Jt::Number ) - return transpose(Jt)⋅v_phys + return v_phys ⋅ transpose(Jt) end