femhub-esco2010: FiPy: Mesh20x20 (04/23/2010)

32 days ago by ondrej

# FiPy: Example mesh20x20 # This example solves a diffusion problem and demonstrates the use of # applying boundary condition patches. # # .. index:: Grid2D # from fipy import * # nx = 20 ny = nx dx = 1. dy = dx L = dx * nx mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny) # # We create a :class:`~fipy.variables.cellVariable.CellVariable` and initialize it to zero: # phi = CellVariable(name = "solution variable", mesh = mesh, value = 0.) # # and then create a diffusion equation. This is solved by default with an # iterative conjugate gradient solver. # D = 1. eq = TransientTerm() == DiffusionTerm(coeff=D) # # We apply Dirichlet boundary conditions # valueTopLeft = 0 valueBottomRight = 1 # # to the top-left and bottom-right corners. Neumann boundary conditions # are automatically applied to the top-right and bottom-left corners. # # .. index:: FixedValue # x, y = mesh.getFaceCenters() facesTopLeft = ((mesh.getFacesLeft() & (y > L / 2)) | (mesh.getFacesTop() & (x < L / 2))) facesBottomRight = ((mesh.getFacesRight() & (y < L / 2)) | (mesh.getFacesBottom() & (x > L / 2))) # BCs = (FixedValue(faces=facesTopLeft, value=valueTopLeft), FixedValue(faces=facesBottomRight, value=valueBottomRight)) # # We create a viewer to see the results # # .. index:: # module: fipy.viewers # viewer = Viewer(vars=phi, datamin=0., datamax=1.) viewer.plot(filename="a.png") # # and solve the equation by repeatedly looping in time: # timeStepDuration = 10 * 0.9 * dx**2 / (2 * D) steps = 10 for step in range(steps): eq.solve(var=phi, boundaryConditions=BCs, dt=timeStepDuration) viewer.plot(filename="b%02d.png" %step) # # .. image:: mesh20x20transient.* # :width: 90% # :align: center # # We can test the value of the bottom-right corner cell. # print numerix.allclose(phi(((L,), (0,))), valueBottomRight, atol = 1e-2) # Expected: ## 1 # #raw_input("Implicit transient diffusion. Press <return> to proceed...") # # ----- # # We can also solve the steady-state problem directly # DiffusionTerm().solve(var=phi, boundaryConditions = BCs) viewer.plot(filename="c.png") # # .. image:: mesh20x20steadyState.* # :width: 90% # :align: center # # and test the value of the bottom-right corner cell. # print numerix.allclose(phi(((L,), (0,))), valueBottomRight, atol = 1e-2) 
       
/home/ondrej/ext/femhub-0.9.9-debian32/local/lib/python2.6/site-pack\
ages/FiPy-2.1-py2.6.egg/fipy/solvers/pysparse/linearPCGSolver.py:70:
DeprecationWarning: PyArray_FromDimsAndDataAndDescr: use
PyArray_NewFromDescr.
  info, iter, relres = itsolvers.pcg(A, b, x, self.tolerance,
self.iterations, Assor)
True
True