Skip to content

Instantly share code, notes, and snippets.

View danieljfarrell's full-sized avatar

Daniel danieljfarrell

View GitHub Profile
@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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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__
@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 / 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);
}
NSPoint ConstrainPointInsideRect(CGPoint freePoint, NSRect boundaryRect)
{
//NSPoint constrainedViewPoint = DFConstrainPointToRect(viewPoint, boundaryRect);
// Make sure the handle cannot be dragged outside of the plot range
if (NSPointInRect(freePoint, boundaryRect)) {
return freePoint;
}
NSPoint cp = freePoint;
@danieljfarrell
danieljfarrell / sq_thermal.py
Created December 3, 2012 11:08
Openopt thermal pv
from __future__ import division
from openopt import *
from FuncDesigner import *
# Constants
kb = 1.3806503e-23 # Boltzmann's Constant (m2 kg s-2 K-1)
elq = 1.60217646e-19 # Elemental charge (C)
h = 6.626068e-34 # Planck's constant (m2 kg s-1)
c = 299792458.0 # Speed of light (m/s)
fs = 6.8e-5 # Solar etendue (fraction of pi)
@danieljfarrell
danieljfarrell / diff_prob1.py
Created November 8, 2012 09:48
Fipy: problems with flux=0 constraints
from fipy import *
from fipy.tools.numerix import exp
# Basic Setup
nx = 200; dx = 0.01; L = nx * dx
A = 15.0; B = 0.1; phi_0 = 1.; D = 1.
mesh = Grid1D(nx = nx, dx = dx)
# Cell variable and constrains
@danieljfarrell
danieljfarrell / multipass_beer_lambert.py
Created June 11, 2012 08:06 — forked from guyer/multipass_beer_lambert.py
Fipy: Beer-Lambert law with multiple reflections
# http://matforge.org/wd15/blog
from __future__ import division
from fipy import *
# Grid things
N = 1000
D = 1
dx = D / N
m = Grid1D(nx=N+1, dx=dx) + [[-dx/2.]]
I_right = CellVariable(mesh=m, value=1., name='I_right') # Intensity along the positive direction
@danieljfarrell
danieljfarrell / multipass_beer_lambert.py
Created June 7, 2012 02:08
Fipy: Beer-Lambert law with multiple reflections
# http://matforge.org/wd15/blog
from __future__ import division
from fipy import *
# Grid things
N = 1000
D = 1
dx = D / N
m = Grid1D(nx=N, dx=dx)
I_right = CellVariable(mesh=m, value=1., name='I_right') # Intensity along the positive direction