Skip to content
Snippets Groups Projects
Commit 9fd2afec authored by Stephan Hilb's avatar Stephan Hilb
Browse files

fix derivative

we embarrassingly missed out the transformation
parent 576b9f12
No related branches found
No related tags found
No related merge requests found
using Statistics: mean using Statistics: mean
using StaticArrays: SA, SArray, MVector using StaticArrays: SA, SArray, MVector, MMatrix
export FeSpace, Mapper, FeFunction, P1, DP0, DP1 export FeSpace, Mapper, FeFunction, P1, DP0, DP1
export interpolate!, sample, bind!, evaluate, nabla export interpolate!, sample, bind!, evaluate, nabla
...@@ -198,18 +198,28 @@ bind!(c, cell) = c ...@@ -198,18 +198,28 @@ bind!(c, cell) = c
evaluate(c, xloc) = c evaluate(c, xloc) = c
# TODO: inherit from some abstract function type # TODO: inherit from some abstract function type
struct Derivative{F} struct Derivative{F, M}
f::F f::F
delmapinv::M
end end
Base.show(io::IO, ::MIME"text/plain", x::Derivative) = Base.show(io::IO, ::MIME"text/plain", x::Derivative) =
print("$(nameof(typeof(x))) of $(typeof(x.f))") print("$(nameof(typeof(x))) of $(typeof(x.f))")
nabla(f) = Derivative(f) function nabla(f)
d = ndims_domain(f.space.mesh)
Derivative(f, zero(MMatrix{d, d, Float64}))
end
bind!(df::Derivative, cell) = bind!(df.f, cell) function bind!(df::Derivative, cell)
bind!(df.f, cell)
delmap = jacobian(elmap(df.f.space.mesh, cell), SA[0., 0.])
df.delmapinv .= inv(delmap)
end
function evaluate(df::Derivative, x) function evaluate(df::Derivative, x)
# size: (:, d)
jac = jacobian(x -> evaluate(df.f.space, df.f.ldata, x), x) jac = jacobian(x -> evaluate(df.f.space, df.f.ldata, x), x)
jac *= df.delmapinv
return SArray{Tuple{df.f.space.size..., length(x)}}(jac) return SArray{Tuple{df.f.space.size..., length(x)}}(jac)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment