Skip to content

Instantly share code, notes, and snippets.

@PetrKryslUCSD
Created May 20, 2017 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetrKryslUCSD/c4c3a348dcef49690ec12bbc5543cc4b to your computer and use it in GitHub Desktop.
Save PetrKryslUCSD/c4c3a348dcef49690ec12bbc5543cc4b to your computer and use it in GitHub Desktop.
Reproducing the strange allocation
module Driver
using FESetModule
using FEMMBaseModule
function run1()
J = ones(2, 2)
loc = zeros(1,3)
conn = reshape([1,2,3], 1, 3)
N = zeros(3,1)
fes = FESetT3(conn=conn)
femm = FEMMBase(fes)
@time for j = 1:10000000
FEMMBaseModule.Jacobianvolume(femm, J, loc, conn, N)
end
@code_warntype FEMMBaseModule.Jacobianvolume(femm, J, loc, conn, N)
end
end
"""
Define basic types.
"""
module FBaseModule
import Base.Complex
typealias FInt Int
typealias FFlt Float64
typealias FCplxFlt Complex{Float64}
typealias FFltVec Vector{FFlt}
typealias FIntVec Vector{FInt}
typealias FFltMat Matrix{FFlt}
typealias FIntMat Matrix{FInt}
typealias FMat{T<:Number} Matrix{T}
typealias FVec{T<:Number} Vector{T}
export FInt, FFlt, FCplxFlt, FFltVec, FIntVec, FFltMat, FIntMat, FMat, FVec
end
module FEMMBaseModule
using FBaseModule
using FESetModule
type FEMMBase{T<:FESet, F<:Function}
fes::T # finite element set object
otherdimension::F
axisymmetric::Bool
end
export FEMMBase
function FEMMBase{T<:FESet}(fes::T)
return FEMMBase(fes, otherdimensionunity, false)
end
function otherdimensionunity(loc::FFltMat, conn::FIntMat, N::FFltMat)::FFlt
return 1.0
end
function Jacobiansurface{T<:FESet2Manifold}(self::FEMMBase{T}, J::FFltMat,
loc::FFltMat, conn::FIntMat, N::FFltMat)::FFlt
return FESetModule.Jacobian(self.fes, J)
end
function Jacobianvolume{T<:FESet2Manifold}(self::FEMMBase{T}, J::FFltMat,
loc::FFltMat, conn::FIntMat, N::FFltMat)::FFlt
#@code_warntype Jacobiansurface(self, J, loc, conn, N)
Jac = Jacobiansurface(self, J, loc, conn, N)::FFlt
end
end
module FESetModule
using FBaseModule
import Base.count
import Base.cat
abstract FESet
abstract FESet2Manifold <: FESet
export FESet, FESet2Manifold
function Jacobian{T<:FESet2Manifold}(self::T, J::FFltMat)::FFlt
# sdim, ntan = size(J);
# @assert ntan == 2 "Expected number of tangent vectors: 2"
# if sdim == ntan
@inbounds Jac = (J[1, 1]*J[2, 2] - J[2, 1]*J[1, 2])
return Jac::FFlt;# is det(J);% Compute the Jacobian
# else
# return norm(RotationUtilModule.cross(J[:, 1], J[:, 2]))::FFlt;
# end
end
type FESetT3 <: FESet2Manifold
nfensperfe::FInt
conn::FIntMat
label::FIntVec
function FESetT3(; conn::FIntMat=[], label =zero(FInt))
const nfensperfe::FInt = 3
@assert (size(conn, 2) == nfensperfe) "Number of nodes per element mismatched"
# Needs to make a COPY of the input arrays
self = new(nfensperfe, deepcopy(conn), deepcopy(FInt[]))
return self
end
end
export FESetT3
end
include("FBaseModule.jl")
include("FESetModule.jl")
include("FEMMBaseModule.jl")
include("Driver.jl")
include("FESetModule.jl")
include("FEMMBaseModule.jl")
using Driver;
Driver.run1()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment