Created
November 19, 2015 21:37
-
-
Save guyer/88f76581a7f41bbe6a55 to your computer and use it in GitHub Desktop.
FiPy script to test time scaling with dimension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fipy import * | |
import time | |
# Spatial parameters | |
nx = 27000 # bins | |
dx = 1. | |
L = nx * dx | |
# Diffusion and time step | |
D = 1. | |
dt = 10. * dx**2 / (2 * D) | |
steps = 10 | |
# radius of nucleus | |
r = 3.0 | |
mesh = Grid1D(nx=nx, dx=dx) | |
X = mesh.cellCenters[0] # These are large arrays | |
phi = CellVariable(mesh=mesh, name=r"$\phi$", value=0., hasOld=True) | |
eq = TransientTerm() == DiffusionTerm(coeff=D) | |
# Initial concentration is a segment located in the center of a bounded line | |
phi.setValue(1.0, where=( ((X-L/2)**2) < r**2) ) | |
# Solve | |
print "1D" | |
start_time = time.time() | |
last_time = start_time | |
for step in range(steps): | |
phi.updateOld() | |
eq.solve(var=phi, dt=dt) | |
print step, 'elapsed:', time.time() - last_time | |
last_time = time.time() | |
print 'Total time elapsed:', time.time() - start_time | |
# Spatial parameters | |
nx = ny = 164 # bins | |
dx = dy = 1. | |
L = nx * dx | |
mesh = Grid2D(nx=nx, ny=ny, dx=dx, dy=dy) | |
X, Y = mesh.cellCenters # These are large arrays | |
phi = CellVariable(mesh=mesh, name=r"$\phi$", value=0., hasOld=True) | |
eq = TransientTerm() == DiffusionTerm(coeff=D) | |
# Initial concentration is a circle located in the center of a bounded square | |
phi.setValue(1.0, where=( ((X-L/2)**2 + (Y-L/2)**2) < r**2) ) | |
# Solve | |
print "2D" | |
start_time = time.time() | |
last_time = start_time | |
for step in range(steps): | |
phi.updateOld() | |
eq.solve(var=phi, dt=dt) | |
print step, 'elapsed:', time.time() - last_time | |
last_time = time.time() | |
print 'Total time elapsed:', time.time() - start_time | |
# Spatial parameters | |
nx = ny = nz = 30 # bins | |
dx = dy = dz = 1. | |
L = nx * dx | |
# radius of nucleus | |
r = 3.0 | |
mesh = Grid3D(nx=nx, ny=ny, nz=nz, dx=dx, dy=dy, dz=dz) | |
X, Y, Z = mesh.cellCenters # These are large arrays | |
phi = CellVariable(mesh=mesh, name=r"$\phi$", value=0., hasOld=True) | |
eq = TransientTerm() == DiffusionTerm(coeff=D) | |
# Initial concentration is a sphere located in the center of a bounded cube | |
phi.setValue(1.0, where=( ((X-L/2)**2 + (Y-L/2)**2 + (Z-L/2)**2) < r**2) ) | |
# Solve | |
print "3D" | |
start_time = time.time() | |
last_time = start_time | |
for step in range(steps): | |
phi.updateOld() | |
eq.solve(var=phi, dt=dt) | |
print step, 'elapsed:', time.time() - last_time | |
last_time = time.time() | |
print 'Total time elapsed:', time.time() - start_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment