Hello,
I'm trying to use the matplotlib vector viewer for fipy but i'm having
problems: could anyone take a look and tell me what's wrong?
Tom
#!/usr/bin/env python
import os
os.environ["FIPY_VIEWER"]="matplotlib"
from fipy.tools.parser import parse
import time
start = time.time()
numberOfElements = parse('--numberOfElements', action = 'store', type
= 'int', default = 6400)
numberOfSteps = parse('--numberOfSteps', action = 'store', type =
'int', default = 5000)
import fipy.tools.numerix as numerix
nx = int(numerix.sqrt(numberOfElements))
ny = int(numerix.sqrt(numberOfElements))
steps = numberOfSteps
dx = 1.0/float(nx)
dy = 1.0/float(ny)
kappa = 1e-4
M = 1.0
from fipy.meshes.grid2D import Grid2D
mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
from fipy.variables.cellVariable import CellVariable
from fipy.tools.numerix import random
P = 1.0
E = 0.0
var = CellVariable(name = "phase field",
mesh = mesh,
value = 2.0*P*random.random(nx * ny) - P)
##
a = -1.0
b = 1.0
c = 0.0
from fipy.tools.numerix import sin
doubleWellDerivative = M * (a * var + b * var*var*var + c * var**5 - E)
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
gamma = M*kappa
diffTerm = ImplicitDiffusionTerm(coeff = M*kappa)
eqch = TransientTerm() - diffTerm + doubleWellDerivative
## from fipy.solvers.linearPCGSolver import LinearPCGSolver
from fipy.solvers.pysparse.linearLUSolver import LinearLUSolver
solver = LinearLUSolver(tolerance = 1e-7,steps = 1000)
##solver = LinearPCGSolver(tolerance = 1e-15,iterations = 1000)
from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.boundaryConditions.fixedFlux import FixedFlux
from fipy.boundaryConditions.nthOrderBoundaryCondition import
NthOrderBoundaryCondition
BCs = (FixedFlux(mesh.getFacesRight(), 0),
FixedFlux(mesh.getFacesLeft(), 0),
FixedFlux(mesh.getFacesTop(), 0),
FixedFlux(mesh.getFacesBottom(), 0) ) ####,
## NthOrderBoundaryCondition(mesh.getFacesLeft(), 0, 3),
## NthOrderBoundaryCondition(mesh.getFacesRight(), 0, 3),
## NthOrderBoundaryCondition(mesh.getFacesTop(), 0, 3),
## NthOrderBoundaryCondition(mesh.getFacesBottom(), 0, 3))
if __name__ == '__main__':
import fipy.viewers.matplotlibViewer.matplotlibVectorViewer
viewer = fipy.viewers.make(vars = var,
limits = {'datamin': -1.0e0,
'datamax': 1.0e-0}
)
viewer.plot()
dexp=-5
for step in range(steps):
dt = numerix.exp(dexp)
dt = min(100, dt)
dexp += 0.01
var.updateOld()
eqch.solve(var, boundaryConditions = BCs, solver = solver, dt
= dt)
thenumber=(int)(step/20)
if thenumber*20==step:
viewer.plot()
print 'step',step,'dt',dt
end = time.time()
print end - start
def _run():
pass