def _calcValue_(self, alpha, id1, id2): distance = numerix.array(self.var) cell1 = numerix.take(distance, id1) cell2 = numerix.take(distance, id2) return numerix.where(numerix.logical_or(cell1 < 0, cell2 < 0), 0, self.diffusionCoeff)
nx = 50 valueLeft = 0. fluxRight = 1. timeStepDuration = 1. L = 1. dx = L / nx mesh = Grid1D(dx = dx, nx = nx) var = CellVariable( name = "solution variable", mesh = mesh, value = valueLeft) x = mesh.getFaceCenters()[:,0] middleFaces = numerix.logical_or(x < L / 4.,x >= 3. * L / 4.) diffCoeff = numerix.where(middleFaces, 1., 0.1) boundaryConditions=(FixedValue(mesh.getFacesLeft(),valueLeft), FixedFlux(mesh.getFacesRight(),fluxRight)) if __name__ == '__main__': import fipy.viewers viewer = fipy.viewers.make(vars = var, limits = {'datamax': L + 18. * L / 4.}) viewer.plot() raw_input('finished')
nx = 2 valueLeft = 0. fluxRight = 1. timeStepDuration = 1. L = 1. dx = L / nx mesh = Grid2D(dx=dx, nx=nx) var = CellVariable(name="solution variable", mesh=mesh, value=valueLeft) x = mesh.getFaceCenters()[:, 0] middleFaces = numerix.logical_or(x < L / 4., x >= 3. * L / 4.) diffCoeff = numerix.where(middleFaces, 1., 0.1) boundaryConditions = (FixedValue(mesh.getFacesLeft(), valueLeft), FixedFlux(mesh.getFacesRight(), fluxRight)) if __name__ == '__main__': ImplicitDiffusionTerm(coeff=diffCoeff).solve( var, boundaryConditions=boundaryConditions) import fipy.viewers viewer = fipy.viewers.make(vars=var, limits={'datamax': L + 18. * L / 4.}) viewer.plot() raw_input('finished')