def view(var): # pragma: no cover """View the phase field data: var: variable to view """ fp.Viewer(var).plot()
mesh = fp.PeriodicGrid2D(dx=dx, nx=nx, dy=dy, ny=ny) phi = fp.CellVariable(mesh=mesh, name="$\phi$", value=0., hasOld=True) elapsed = fp.Variable(name="$t$", value=0.) x, y = mesh.cellCenters[0], mesh.cellCenters[1] X, Y = mesh.faceCenters[0], mesh.faceCenters[1] # In[6]: if isnotebook: viewer = fp.Viewer(vars=phi, datamin=0., datamax=1.) viewer.plot() # ## Define governing equation # > use only the nondimensional forms of the phase-field and nucleation equations, but without the tildes, for simplicity # # > [Set] the driving force to $\Delta f = 1 / (15\sqrt{2})$ # In[7]: Delta_f = 1. / (15 * fp.numerix.sqrt(2.))
def plot_phi(record, timestep=5000.0): fname = "Data/{}/t={}.tar.gz".format(record["label"], timestep) phi, = fp.tools.dump.read(fname) vw = fp.Viewer(vars=phi) vw.plot()
D = fp.CellVariable(mesh=mesh, value=1.) for i in range(0, 2500): D()[i] = K[i] coeffD = D() * fp.numerix.exp(0.01 * phi) # --- Assign boundary conditions valueTop = -1.5 valueGradBottom = 0. phi.constrain(valueTop, where=mesh.facesTop) phi.constrain(valueGradBottom, where=mesh.facesBottom) if __name__ == '__main__': viewer = fp.Viewer(vars=phi) #, datamin=-1.5, datamax=0.) viewer.plot() # --- Solve steady state groundwater flow equation eqSteady = (fp.DiffusionTerm(coeff=D() * fp.numerix.exp(0.01 * phi)) + np.gradient(coeffD())[0]) eqSteady.solve(var=phi) print phi() if __name__ == '__main__': viewer.plot() if __name__ == '__main__': raw_input("Implicit steady-state diffusion. Press <return> to proceed...") ################################################################################ ################################################################################
dx, nx = _dnl(dx=params['dx'], nx=None, Lx=Lx) dy, ny = _dnl(dx=params['dx'], nx=None, Lx=Ly) mesh = fp.Grid2D(dx=dx, nx=nx, dy=dy, ny=ny) phi = fp.CellVariable(mesh=mesh, name="$\phi$", value=0., hasOld=True) elapsed = fp.Variable(name="$t$", value=0.) x, y = mesh.cellCenters[0], mesh.cellCenters[1] X, Y = mesh.faceCenters[0], mesh.faceCenters[1] # In[6]: if isnotebook: viewer = fp.Viewer(vars=phi, datamin=0., datamax=1.) viewer.plot() # ## Define governing equation # > use only the nondimensional forms of the phase-field and nucleation equations, but without the tildes, for simplicity # # > [Set] the driving force to $\Delta f = 1 / (6\sqrt{2})$ # In[7]: Delta_f = 1. / (6 * fp.numerix.sqrt(2.)) # > $$r_c = \frac{1}{3\sqrt{2}}\frac{1}{\Delta f} = 2.0$$ # In[8]:
elapsed = 0.0 steps = 0 dt = 0.01 total_sweeps = 2 tolerance = 1e-1 #total_steps = 2 #from 1000 to 100 c_var[:] = c_0 + epsilon * np.cos((q[:, None] * r).sum(0)) c_var.updateOld() from fipy.solvers.pysparse import LinearLUSolver as Solver solver = Solver() viewer = fp.Viewer(c_var) while steps < total_steps: res0 = eqn.sweep(c_var, dt=dt, solver=solver) for sweeps in range(total_sweeps): res = eqn.sweep(c_var, dt=dt, solver=solver) print ' ' print 'steps',steps print 'res',res print 'sweeps',sweeps print 'dt',dt if res < res0 * tolerance: steps += 1
def showResult(self): viewer = FP.Viewer(vars=[self.T], FIPY_VIEWER='mayavi') viewer.plotMesh() raw_input("Press <return> to proceed...")
def make_porous_mesh(r, R, dx, L): gmsh_text = gmsh_text_box % {'dx': dx[0], 'Lx': L[0], 'Ly': L[1]} loop_indexes = [1] if r is not None and len(r) and R: gmsh_text += gmsh_text_radius % {'R': R} for i in range(len(r)): index = 5 * (i + 1) gmsh_text += gmsh_text_circle % { 'x': r[i][0], 'y': r[i][1], 'i': index } loop_indexes += [index] surface_args = ', '.join([str(index) for index in loop_indexes]) gmsh_text += gmsh_text_surface % {'args': surface_args} return fipy.Gmsh2D(gmsh_text) if __name__ == '__main__': r = np.array([[0.0, 0.1], [0.3, 0.3]]) R = 0.1 dx = np.array([0.02, 0.02]) L = np.array([1.0, 1.0]) m = make_porous_mesh(r, R, dx, L) phi = fipy.CellVariable(m) v = fipy.Viewer(vars=phi, xmin=-L[0] / 2.0, xmax=L[0] / 2.0) v.plotMesh() raw_input()
# res = eq_h_convection.sweep(var=h_convection, dt=dt) # if abs(res - resOld) < 1e-7: break # theta version of the eqn. res = 0.0 for r in range(MAX_SWEEPS): resOld=res res = eq_theta.sweep(var=theta, dt=dt) if abs(res - resOld) < 1e-7: break if __name__ == '__main__' and step%PLOT_EVERY == 0: h_from_theta = (numerix.log(theta) -s0)/s1 viewer = fp.Viewer(vars=(h, h_from_theta, h_implicit_source), datamin=0, datamax=2) viewer.plot() #%% """ Compare solutions for h and theta """ h_sol = h.value h_implicit_source_sol = h_implicit_source.value theta_sol = theta.value theta_sol_from_h = np.exp(s0 + s1 * h_sol) if (abs(theta_sol - theta_sol_from_h) < 1e-2).all(): print('both versions of the eq give same result!')