Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@danieljfarrell
danieljfarrell / NSimageToCGColorRef.mm
Created January 26, 2013 10:35
Functions to convert an NSImage (*pattern image*) to a CGColorRef color, following the advice from http://stackoverflow.com/questions/2520978/how-to-tile-the-contents-of-a-calayer
/* http://stackoverflow.com/questions/2520978/how-to-tile-the-contents-of-a-calayer */
// callback for CreateImagePattern.
static void DrawPatternImage (void *info, CGContextRef ctx) {
CGImageRef image = (CGImageRef) info;
CGContextDrawImage(ctx,
CGRectMake(0,0, CGImageGetWidth(image),CGImageGetHeight(image)),
image);
}
@danieljfarrell
danieljfarrell / gist:5804708
Created June 18, 2013 11:44
iPython notebook with really poor performance and a latex cell that does not render.
{
"metadata": {
"name": "Cell centered finite volumes"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@danieljfarrell
danieljfarrell / fishers_equation_method1.py
Last active December 22, 2021 21:27
Solving Fisher's nonlinear reaction-diffusion equation in python. Two method are used, 1) a time step method where the nonlinear reaction term is treated fully implicitly 2) a full implicit/explicit approach where a Newton iteration is used to find the solution variable at the next time step. More information http://scicomp.stackexchange.com/que…
from __future__ import division
import numpy as np
from scipy.integrate import simps
from scipy.sparse import spdiags, coo_matrix, csc_matrix, dia_matrix, dok_matrix, identity
from scipy.sparse.linalg import spsolve
from itertools import chain
import pylab
import scipy
print "scipy", scipy.__version__
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danieljfarrell
danieljfarrell / odesolver.py
Last active December 22, 2015 13:59
Fleshing out a ode solver interface for scipy.
# Instantiation.
# Make a solver object, created automatically with default options. The solve is instantiated
# only with the variables that are common to all of the solvers. This means 1) the r.h.s. of
# function to solve, 2) a start time, 3) initial conditions, 4) Jacobian function. Strictly
# speaking the Jacobian is optional here because only some solvers will require it. As a
# compromise lets pass it as a keyword argument, this also gets around any awkward 'use_jac'
# options because the solver either has a Jacobian function at init time or it does not.
solver = odesolver("cvodes", ode_function, time_start, initial_conditions, jacobian_function=None)
# Solver options.
@danieljfarrell
danieljfarrell / fvm_half_cell.ipynb
Last active December 25, 2015 04:09
Implementation a finite volume method with a half cell at one end.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danieljfarrell
danieljfarrell / Polarisation matrix.ipynb
Created November 8, 2013 07:54
Attenuation of laser beam with crossed polarisers and optical isolators.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danieljfarrell
danieljfarrell / fipy_nonuniform_poisson_electrostatics.py
Created January 17, 2014 00:52
This script illustrates a failure with the finite volume method for an elliptical problem on a non-uniform mesh. For more information see the question and answer here, http://scicomp.stackexchange.com/questions/8577/peculiar-error-when-solving-the-poisson-equation-on-a-non-uniform-mesh-1d-only
from fipy import *
import numpy as np
"""
This script illustrates a failure with the finite volume method for an elliptical problem on a non-uniform mesh.
For more information see the question and answer here,
http://scicomp.stackexchange.com/questions/8577/peculiar-error-when-solving-the-poisson-equation-on-a-non-uniform-mesh-1d-only
"""
def fipy_step_charge():
@danieljfarrell
danieljfarrell / log.txt
Created April 3, 2014 09:44
Building scikits.odes
daniel@DJF2:~/dev/git/odes*development$ rm -rf build/
daniel@DJF2:~/dev/git/odes*development$ python setup.py install
=============================================
parent package is scikits
top path is /Users/daniel/dev/git/odes
=============================================
lapack_opt_info:
FOUND:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
define_macros = [('NO_ATLAS_INFO', 3)]
@danieljfarrell
danieljfarrell / gist:4dbe7c322c90318d78dc
Last active August 29, 2015 14:17
Generic parameter 'U' cannot be bound to non-@objc protocol type 'SceneObject'
extension Array {
mutating func removeObject<U: Equatable>(object: U) {
var index: Int?
for (idx, objectToCompare) in enumerate(self) {
if let to = objectToCompare as? U {
if object == to {
index = idx
}
}
}