Skip to content

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Jan 2, 2025
1 parent 4a2cd6b commit 6f50ebb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/FESpaces/Pullbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 52 additions & 2 deletions src/ReferenceFEs/Dofs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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=(==))
Expand Down
58 changes: 3 additions & 55 deletions src/ReferenceFEs/Pullbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end

function Arrays.evaluate!(
cache,
::Broadcasting{typeof()},
::Broadcasting{typeof(gradient)},
a::Fields.BroadcastOpFieldArray{<:Pushforward}
)
v, pf_args... = a.args
Expand Down Expand Up @@ -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

"""
Expand Down Expand Up @@ -282,7 +230,7 @@ function evaluate!(
cache, ::CoVariantPiolaMap, v_ref::Number, Jt::Number
)
# we right-multiply to compute the gradient correctly
return v_reftranspose(inv(Jt))
return v_ref transpose(inv(Jt))
end

function return_cache(
Expand All @@ -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

0 comments on commit 6f50ebb

Please sign in to comment.