Dear Daniel, This is the current script referred to in the previous email, where I have removed the phi.set value for phi.
Were can one find the function that results as the solution to the given PDE in FiPY? For isntance, if this solution was phi = sec²(x) can FiPY print it out? Thanks Sergio dphi/dt + d^2phi/dx² + |phi|² phi = 0 #!/usr/bin/env python # testing a non-complex variant of the NLSE import numpy import cmath as math from fipy import * from fipy import numerix nx = 50 dx = 1. / float(nx) mesh = Grid1D(nx=nx,dx=dx) X = mesh.cellCenters[0] phi = CellVariable(mesh=mesh, name="Solution") #phi.setValue(0.5-0.5*numerix.exp((1j*X))) vi = Viewer(vars=phi,datamin=0.0, datamax=1.0) vi.plot() raw_input("Initialization ...") phi.constrain(1., mesh.facesLeft) phi.constrain(0., mesh.facesRight) phi_sq = CellVariable(mesh=mesh) phi_sq.setValue( phi*phi ) #We now represent the equation, where u = phi, du/dt + d^2u/dx^2 + u^2 = 0 in fipy commands. du/dx : is a convection term with a unit scalar coefficient, i.e. <SpecificConvectionTerm>(coeff=(1.,), var=u) , # du/dt : is a transient term that one can treat as before, i.e. TransientTerm(var=u). one can add a second order derivative as ExplicitDiffusionTerm(coeff=D) eq = TransientTerm(coeff=1., var=phi) + ExponentialConvectionTerm(coeff=(1.,), var=phi) + abs((phi_sq))*(phi) == 0.0 dt = 0.01 steps = 100 for step in range(steps): eq.sweep(dt=dt) # phi_sq.setValue( phi * phi ) # vi.plot() phiAnalytical = CellVariable(name="Analytical value", mesh=mesh) vi = Viewer(vars=(phi, phiAnalytical)) vi.plot() raw_input("Press <return> ...") Sergio Manzetti [ http://www.fjordforsk.no/logo_hr2.jpg ] [ http://www.fjordforsk.no/ | Fjordforsk AS ] [ http://www.fjordforsk.no/ | ] Midtun 6894 Vangsnes Norge Org.nr. 911 659 654 Tlf: +47 57695621 [ http://www.oekolab.com/ | Økolab ] | [ http://www.nanofact.no/ | Nanofactory ] | [ http://www.aq-lab.no/ | AQ-Lab ] | [ http://www.phap.no/ | FAP ] From: "Daniel Wheeler" <daniel.wheel...@gmail.com> To: "fipy" <fipy@nist.gov> Sent: Monday, May 22, 2017 6:05:25 PM Subject: Re: Complex conjugates in FiPY On Sat, May 20, 2017 at 5:02 AM, Sergio Manzetti <sergio.manze...@fjordforsk.no> wrote: > > Dear Daniel, I am wondering if you can clarify a small. thing. > > In the given script, phi is set as e^ix, and the numerical simulation treats > the given PDE. Is phi tested for wether it is a result of the given PDE in > this script ? Or does the script do something else? I'm not quite sure what you're asking, but I'm sure that the script below does not work as you intend it to work. > #!/usr/bin/env python > # testing a non-complex variant of the NLSE > > import numpy > import cmath as math > from fipy import * > from fipy import numerix > > nx = 50 > dx = 1. / float(nx) > > mesh = Grid1D(nx=nx,dx=dx) > X = mesh.cellCenters[0] > > phi = CellVariable(mesh=mesh, name="Solution") > phi.setValue(0.5-0.5*numerix.exp((1j*X))) At this point your script is broken, "phi.value.imag" is all zero while "(0.5-0.5*numerix.exp((1j*X))).value.imag" is non-zero. The type of the CellVariable is wrong initially and the type doesn't change when the value is reset. -- Daniel Wheeler _______________________________________________ fipy mailing list fipy@nist.gov http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
_______________________________________________ fipy mailing list fipy@nist.gov http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]