1 """ from fipy.meshes.tri2D import Tri2D from fipy.boundaryConditions.fixedValue import FixedValue from fipy.variables.cellVariable import CellVariable import fipy.viewers from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm nx = 50 ny = 50 dx = 1. valueLeft = 0. valueRight = 1. mesh = Tri2D(dx=dx, nx=nx, ny=ny) var = CellVariable(name="solution variable", mesh=mesh, value=valueLeft) boundaryConditions = (FixedValue(mesh.getFacesLeft(), valueLeft), FixedValue(mesh.getFacesRight(), valueRight)) if __name__ == '__main__': ImplicitDiffusionTerm().solve(var, boundaryConditions=boundaryConditions) viewer = fipy.viewers.make(vars=var) viewer.plot() raw_input("finished")
from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm from fipy.terms.transientTerm import TransientTerm from fipy.tools import numerix dx = 1. dy = 1. nx = 10 ny = 2 valueLeft = 0. valueRight = 1. timeStepDuration = 0.005 steps = 10000 gridMesh = Grid2D(dx, dy, nx, ny) triMesh = Tri2D(dx, dy, nx, 1) + (dx * nx, 0) bigMesh = gridMesh + triMesh ## filter functions def leftSide(face): a = face.getCenter()[0] if (((a**2) < 0.000000000000001) and (face.getID() in bigMesh.getExteriorFaces())): return 1 else: return 0 def inMiddle(face):
import fipy.viewers from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm nx = 10 ny = 1 valueLeft = 0. fluxRight = 1. timeStepDuration = 1. L = 10. dx = L / nx dy = 1. mesh = Tri2D(dx, dy, nx, ny) var = CellVariable(name="solution variable", mesh=mesh, value=valueLeft) from fipy.variables.faceVariable import FaceVariable diffCoeff = FaceVariable(mesh=mesh, value=1.0) x = mesh.getFaceCenters()[..., 0] diffCoeff.setValue(0.1, where=(L / 4. <= x) & (x < 3. * L / 4.)) boundaryConditions = (FixedValue(mesh.getFacesLeft(), valueLeft), FixedFlux(mesh.getFacesRight(), fluxRight)) if __name__ == '__main__': ImplicitDiffusionTerm(coeff=diffCoeff).solve( var, boundaryConditions=boundaryConditions)
>>> print var.allclose(analyticalArray) 1 """ __docformat__ = 'restructuredtext' from fipy.variables.cellVariable import CellVariable from fipy.boundaryConditions.fixedValue import FixedValue import fipy.viewers from fipy.meshes.tri2D import Tri2D from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm nx = 50 dx = 1. mesh = Tri2D(dx = dx, nx = nx) valueLeft = 0 valueRight = 1 var = CellVariable(name = "solution-variable", mesh = mesh, value = valueLeft) boundaryConditions = (FixedValue(mesh.getFacesLeft(),valueLeft), FixedValue(mesh.getFacesRight(),valueRight)) if __name__ == '__main__': from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm ImplicitDiffusionTerm().solve(var, boundaryConditions = boundaryConditions) viewer = fipy.viewers.make(vars = var) viewer.plot() raw_input("finished")