Skip to content

Instantly share code, notes, and snippets.

View rleegates's full-sized avatar

Robert Lee Gates rleegates

View GitHub Profile
function *{T1<:AbstractDataBlock,T2<:AbstractDataBlock}(A::SparseMatrixCSC{T1,Int}, B::SparseMatrixCSC{T2,Int})
# modified from julia base (put into license!!!!)
mA, nA = size(A)
mB, nB = size(B)
nA==mB || throw(DimensionMismatch())
colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval
colptrB = B.colptr; rowvalB = B.rowval; nzvalB = B.nzval
# TODO: Need better estimation of result space
nnzC = min(mA*nB, length(nzvalA) + length(nzvalB))
module SimplePolynomials
typealias ExponentInt Int
import StaticArrays: SVector
import Base: (+), (*), (^), zero, one
immutable Polynomial{T,NV}
exps::Vector{SVector{NV,ExponentInt}}
coeffs::Vector{T}
@rleegates
rleegates / WebInterface.jl
Created March 23, 2015 00:36
A simple Servlet
module WebInterface
using Morsel
app = Morsel.app()
using Debug
import JSON
route(app, GET | POST | PUT, "/") do req, res
@rleegates
rleegates / Quad8.m
Created December 15, 2014 08:07
Quad8 Shape Functions
N = [ 0.25* (1+s) * (1+r) * (r+s-1),...
0.25* (1+s) * (r-1) * (r+1-s),...
-0.25* (s-1) * (r-1) * (r+s+1),...
-0.25* (s-1) * (1+r) * (r-1-s),...
-0.5 * (1+r) * (r-1) * (1+s) ,...
0.5 * (r-1) * (1+s) * (s-1) ,...
0.5 * (1+r) * (r-1) * (s-1) ,...
-0.5 * (1+r) * (1+s) * (s-1) ]';
dN = [ 0.25* (1+s) * (s+2*r) ,...
0.25* (1+s) * (-s+2*r),...
@rleegates
rleegates / keTest.jl
Last active August 29, 2015 14:11
Element stiffness benchmark
function keTestVec(N::Int64, gradN::Array{Float64,2}, kappa::Array{Float64,2}, keDim::Int64, sdim::Int64)
ke = zeros(Float64,keDim,keDim)
detJ = 1.0
w = 1.0/2.0
for n = 1:N
fill!(ke,0.0)
ke += (w*detJ).*(gradN*kappa*gradN')
end
return ke
end
@rleegates
rleegates / intervalsGC.jl
Last active August 29, 2015 14:11
Run GC at intervals
function doSomethingOften(n::Int64)
intv = 1000
try
gc_disable()
for i = 1:n
doSomething()
if i == intv
gc()
end
end
@rleegates
rleegates / globalToLocal.m
Created December 5, 2014 14:41
Computes element coordinate from global coordinate
% local coordinates from global coordinates
function eta = globalToLocal(obj, xPt, nodalX)
% tolerance
tol = 1e-13;
% get an initial guess at [0,0]
eta = zeros(size(xPt));
% NR iteration
deta = 1;
iter = 0;
maxIter = 20;
# parallelTest.jl
# automatic differentiation of a function at n = 100e6 points using dual numbers
# compare parallel to serial implementation
# benchmark timings were observed on a 2.66GHz Quad-Core Xeon after an initial warm up run
# initialize processors
availProcs = 8;
addprocs(availProcs-nprocs());