temperature = CellVariable( name='temperature', mesh=mesh, value=initialTemperature, hasOld=1 ) bench.stop('variables') bench.start() from fipy.tools import numerix mVar = phase - 0.5 - kappa1 / numerix.pi * \ numerix.arctan(kappa2 * temperature) phaseY = phase.getFaceGrad().dot((0, 1)) phaseX = phase.getFaceGrad().dot((1, 0)) psi = theta + numerix.arctan2(phaseY, phaseX) Phi = numerix.tan(N * psi / 2) PhiSq = Phi**2 beta = (1. - PhiSq) / (1. + PhiSq) betaPsi = -N * 2 * Phi / (1 + PhiSq) A = alpha**2 * c * (1.+ c * beta) * betaPsi D = alpha**2 * (1.+ c * beta)**2 dxi = phase.getFaceGrad()._take((1, 0), axis = 1) * (-1, 1) anisotropySource = (A * dxi).getDivergence() from fipy.terms.transientTerm import TransientTerm from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm from fipy.terms.implicitSourceTerm import ImplicitSourceTerm phaseEq = TransientTerm(tau) == ExplicitDiffusionTerm(D) + \ ImplicitSourceTerm(mVar * ((mVar < 0) - phase)) + \
sweeps=10 from fipy.meshes.grid2D import Grid2D mesh = Grid2D(nx=N, ny=N, dx=dL, dy=dL) from fipy.variables.cellVariable import CellVariable psi = CellVariable(mesh=mesh, name='stream function') Xhat=(1,0) Yhat=(0,1) u=psi.getGrad().dot(Yhat) v=-psi.getGrad().dot(Xhat) U=psi.getFaceGrad() from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm eq=ImplicitDiffusionTerm(0.00001) \ + u * u.getGrad().dot(Xhat) \ + v * u.getGrad().dot(Yhat) \ - 2 * u.getGrad().dot(Yhat).getGrad().dot(Yhat) from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition from fipy.boundaryConditions.fixedValue import FixedValue BC = (NthOrderBoundaryCondition(faces=mesh.getFacesBottom(), value=0,order=1), FixedValue(faces=mesh.getFacesBottom(), value=0), NthOrderBoundaryCondition(faces=mesh.getFacesLeft(), value=0,order=1), NthOrderBoundaryCondition(faces=mesh.getFacesTop(), value=1,order=1),
where=(x - seedCenter[0])**2 + (y - seedCenter[1])**2 < radius**2) temperature = CellVariable(name='temperature', mesh=mesh, value=initialTemperature, hasOld=1) bench.stop('variables') bench.start() from fipy.tools import numerix mVar = phase - 0.5 - kappa1 / numerix.pi * \ numerix.arctan(kappa2 * temperature) phaseY = phase.getFaceGrad().dot((0, 1)) phaseX = phase.getFaceGrad().dot((1, 0)) psi = theta + numerix.arctan2(phaseY, phaseX) Phi = numerix.tan(N * psi / 2) PhiSq = Phi**2 beta = (1. - PhiSq) / (1. + PhiSq) betaPsi = -N * 2 * Phi / (1 + PhiSq) A = alpha**2 * c * (1. + c * beta) * betaPsi D = alpha**2 * (1. + c * beta)**2 dxi = phase.getFaceGrad()._take((1, 0), axis=1) * (-1, 1) anisotropySource = (A * dxi).getDivergence() from fipy.terms.transientTerm import TransientTerm from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm from fipy.terms.implicitSourceTerm import ImplicitSourceTerm phaseEq = TransientTerm(tau) == ExplicitDiffusionTerm(D) + \ ImplicitSourceTerm(mVar * ((mVar < 0) - phase)) + \
sweeps=10 from fipy.meshes.grid2D import Grid2D mesh = Grid2D(nx=N, ny=N, dx=dL, dy=dL) from fipy.variables.cellVariable import CellVariable u = CellVariable(mesh=mesh, name='X velocity') v = CellVariable(mesh=mesh, name='Y velocity') from fipy.variables.vectorFaceVariable import VectorFaceVariable velocity = VectorFaceVariable(mesh=mesh) Xhat=(1,0) Yhat=(0,1) velocity=u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm diffTerm=ImplicitDiffusionTerm(coeff=viscosity) from fipy.terms.exponentialConvectionTerm import ExponentialConvectionTerm convTerm = ExponentialConvectionTerm(coeff = velocity,diffusionTerm = diffTerm) eq1= diffTerm - u * u.getGrad().dot(Xhat) - v * u.getGrad().dot(Yhat) eq2= velocity.getDivergence() #eq2= u.getGrad() + v.getGrad() eq2=u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat eq2= u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat) eq2= ImplicitDiffusionTerm(1) + u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)
sweeps = 10 from fipy.meshes.grid2D import Grid2D mesh = Grid2D(nx=N, ny=N, dx=dL, dy=dL) from fipy.variables.cellVariable import CellVariable u = CellVariable(mesh=mesh, name='X velocity') v = CellVariable(mesh=mesh, name='Y velocity') from fipy.variables.vectorFaceVariable import VectorFaceVariable velocity = VectorFaceVariable(mesh=mesh) Xhat = (1, 0) Yhat = (0, 1) velocity = u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm diffTerm = ImplicitDiffusionTerm(coeff=viscosity) from fipy.terms.exponentialConvectionTerm import ExponentialConvectionTerm convTerm = ExponentialConvectionTerm(coeff=velocity, diffusionTerm=diffTerm) eq1 = diffTerm - u * u.getGrad().dot(Xhat) - v * u.getGrad().dot(Yhat) eq2 = velocity.getDivergence() #eq2= u.getGrad() + v.getGrad() eq2 = u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat eq2 = u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat) eq2 = ImplicitDiffusionTerm(1) + u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)