Hi everyone,
I am currently struggling with the usage of anonymous functions. I have a function dirichlet!
that takes a function as one of its inputs. The function returns a value based on the position x
.
function dirichlet!(f, K::SparseMatrixCSC{Tv,Ti}, F::Vector{Tv}, nodes::Matrix{Tv}, elements::GFMat{<:Int}, axis::NTuple{N,<:Int}) where {Ti,Tv,N}
dofAxes = Vector{Int}()
for i in eachindex(axis)
if axis[i] > 0
push!(dofAxes, i)
end
end
for i in axes(elements, 1)
e = elements[i]
for n in e
dofs = dofAxes .+ (n - 1) * N
x::Vector{Tv} = nodes[1:N, n]
pval::NTuple{N,Tv} = f(x)
_prescribef!(dofs, K, F, pval)
_zerorow!(dofs, K)
_zerocolumn!(dofs, K)
K[dofs, dofs] .= 1.0
end
end
dropzeros!(K)
return F
end
However, when I actually use the function there is an almost 100% compilation time each time i run the code. If I set pval
manually the compilation time goes back to 0%.
I run the code like this:
fr = (::Vector{Float64}) -> (0.0, 0.0)
F = dirichlet!(fl, K, F, mesh.nodes, left, (1, 0))
I have tried different methods of inputting the function, and changing the input type of function, but nothing seemed to work.
Any help would be greatly appreciated.
Kind regards,
Thomas