From a08de423b965555a363f133a1239cf82b1f8c69e Mon Sep 17 00:00:00 2001 From: Stephan Hilb <stephan@ecshi.net> Date: Mon, 19 Jul 2021 20:43:48 +0200 Subject: [PATCH] avoid allocations --- src/function.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/function.jl b/src/function.jl index c454677..31ffbac 100644 --- a/src/function.jl +++ b/src/function.jl @@ -211,8 +211,9 @@ function integrate(mesh::Mesh, expr; params...) end function bind!(f::FeFunction, cell) - # TODO: make this non-allocating - f.ldata .= vec(f.data[f.space.dofmap[:, :, cell]]) + gdofs_view = view(f.space.dofmap, :, :, cell) + gdofs = SArray{Tuple{prod(f.space.size) * ndofs(f.space.element)}}(gdofs_view) + f.ldata .= f.data[gdofs] return f end @@ -223,6 +224,7 @@ evaluate(f::FeFunction, x) = evaluate(f.space, f.ldata, x) bind!(c, cell) = c evaluate(c, xloc) = c + # TODO: inherit from some abstract function type struct Derivative{F, M} f::F @@ -242,6 +244,7 @@ function bind!(df::Derivative, cell) delmap = jacobian(elmap(df.f.space.mesh, cell), SA[0., 0.]) df.delmapinv .= inv(delmap) end + function evaluate(df::Derivative, x) # size: (:, d) jac = jacobian(x -> evaluate(df.f.space, df.f.ldata, x), x) -- GitLab