My problem is actually still somewhere (as @Benny just demonstrated cross3
has been falsely blamed by me). My full MWE is
module mcs002xxx
using LinearAlgebra
using Statistics
using InteractiveUtils
function cross3!(
result::AbstractVector{T1},
theta::AbstractVector{T2},
v::Tuple{T3, T3, T3},
) where {T1, T2, T3}
@assert (length(theta) == 3) && (length(v) == 3) "Inputs must be 3-vectors"
result[1] = -theta[3] * v[2] + theta[2] * v[3]
result[2] = theta[3] * v[1] - theta[1] * v[3]
result[3] = -theta[2] * v[1] + theta[1] * v[2]
return result
end
@views function gen_iso_csmat!(csmatout::Matrix{T}, XYZ::Matrix{T}, tangents::Matrix{T}, feid::IT, qpid::IT) where {T, IT}
sdim, mdim = size(tangents)
if sdim == mdim # finite element embedded in space of the same dimension
for i in 1:size(csmatout, 1), j in 1:size(csmatout, 2)
csmatout[i, j] = (i == j ? one(T) : zero(T))
end
else # lower-dimensional finite element embedded in space of higher dimension
@assert 0 < mdim < sdim
@assert 0 < sdim
csmatout[:, 1] = tangents[:, 1]
csmatout[:, 1] /= norm(csmatout[:, 1])
if mdim == 1 # curve-like finite element in 2d or 3d
# all done
elseif mdim == 2 # surface-like finite element in 3d
e2 = (tangents[1, 2], tangents[2, 2], tangents[3, 2])
cross3!(csmatout[:, 2], csmatout[:, 1], e2)
csmatout[:, 2] /= norm(csmatout[:, 2])
end
end
return csmatout
end
function doit()
XYZ = reshape([0.2, 0.3, 0.4], 1, 3)
tangents = reshape([1.0, 0.0, 0.0], 3, 1)
m = zeros(3, 3)
@time begin @views let
cross3!(m[:, 2], m[:, 1], (1.0, 0.0, 0.010))
end
end
@time gen_iso_csmat!(m, XYZ, tangents, 0, 0)
true
end
doit()
nothing
end
I get
julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\FinEtools.jl\\playn.jl")
WARNING: replacing module mcs002xxx.
0.000001 seconds
0.000002 seconds (1 allocation: 80 bytes)
Main.mcs002xxx
which means gen_iso_csmat!
allocates. The path actually does not involve cross3!
: the empty block # all done
is hit.