Yun -

The problem with `update_signal()` is that you overwrite varS each time you 
call it, but eq is defined in terms of the first declaration of varS.

You should get a better result from changing `update_signal()` to

    def update_signal(rate):
        ido = np.random.multivariate_normal([55,35+rate], [[0,0],[0,0]], 100)
        ido = np.floor(ido).astype(int)
        og = np.zeros((nxy, nxy))
        np.add.at(og, (ido[:,0], ido[:,1]), 1)
        dd = fftconvolve(og, ker, mode='same')
        return dd.flat

and then writing in your iteration loop:

    varS.value = update_signal(time*50)  

You could further automate the dependency by declaring a subclass of 
`CellVariable` that provides a `_calcValue()` method that performs the work of 
`update_signal()`. See fipy/variables/noiseVariable.py for an example.


You might get some insight from how we declare a Langevin noise term in 

http://www.ctcms.nist.gov/fipy/fipy/generated/fipy.variables.html#module-fipy.variables.gaussianNoiseVariable


- Jon



On Oct 27, 2015, at 3:48 PM, Yun Tao <[email protected]> wrote:

> Hi Jonathan,
> 
> I finally got a chance to test out the solution. However, it still doesn't 
> work and I suspect I'm overlooking something relatively. I have made the 
> following changes:
>  
> - inserted time=Variable(): line 25
> - updated the time-dependent variable varS using time in the while loop: line 
> 101
> - updated time.value during the iterations: line 103
> 
> I still do not see changes in either var or varS. My modified code is 
> attached below -- note that the time-dependency doesn't operate according to 
> a source term but rather relates to the component inside the convection term: 
> varS.faceValue. 
> 
> Is my use of an embedded function update_signal inside the iteration loop 
> messing things up?
> 
> Thanks,
> Yun
> 
> On Mon, Oct 19, 2015 at 4:35 PM, Guyer, Jonathan E. Dr. 
> <[email protected]> wrote:
> You would do this in a similar way to how time-dependent boundary conditions 
> are illustrated in examples/diffusion/mesh1D.py:
> 
> >>> phi = CellVariable(mesh=..., value=...)
> >>> time = Variable()
> >>> source1 = phi * time
> 
> or, e.g.,
> 
> >>> source2 = mesh.x * time
> 
> 
> Then as you iterate in timesteps, you would update time with:
> 
> >>> time.value = time.value + dt
> 
> source1 and source2 will automatically reflect the new value of time.
> 
> On Oct 12, 2015, at 4:15 PM, Yun Tao <[email protected]> wrote:
> 
> > Hi FiPy community,
> >
> > This is a potentially helpful update to a recent question I submitted, 
> > where my goal was to spatially vary the convection strength of a 
> > Fokker-Planck equation for random variable var(x,t) as a simple function of 
> > local signal distribution varS(x,t). Specifically, I wanted to solve for 
> > the transient dynamics of var(x,t), given that, at each location x, its 
> > probability surface is pulled towards a fixed, central point-attractor to a 
> > degree that is proportional to the estimated value of varS(x,t).
> >
> > I like to thank Jon for his tremendous amount of help, from which I was 
> > able to generate a working script on the condition that varS(x,t) is 
> > time-invariant. The code is attached here as signals_static.py. var(x,t) is 
> > plotted over time in the left panel of the animation, and varS(x) is on the 
> > right. The increasing topological distortion shown in the simulation is 
> > consistent with how we expect var(x,t) to behave.
> >
> > My current goal is to solve for var(x,t) on the condition that varS(x,t) 
> > also varies, partially stochastically, over time. Note that this doesn't 
> > involve coupling the Fokker-Plank equation with another differential 
> > equation. I've attempted to do this in the attached script: 
> > signals_dynamic.py. The only addition from the previous script is a "signal 
> > updating function', through which we force the spatial distribution of 
> > varS(x,t) to shift rightward every time step. However, for some reason, 
> > var(x,t) is unresponsive to these changes.
> >
> > Therefore, my question is: how can I base the convection term on a 
> > CellVariable that gets temporally updated outside of the equation 
> > definition?
> >
> > Thanks,
> > Yun
> >
> > On Wed, Aug 26, 2015 at 2:47 PM, Guyer, Jonathan E. Dr. 
> > <[email protected]> wrote:
> > Yun -
> >
> > I've gotten your script to "work" and posted the changes to:
> >
> >   https://gist.github.com/guyer/caca956463dfc3835722/revisions
> >
> > The main changes I made were:
> >
> > * to get rid of the intrep2d, as it wasn't working properly [signal_fct(xf, 
> > yf) generates a result of shape
> >   (len(xf), len(xf)) instead of (len(xf),).] I was able to get it working a 
> > bit better, but not completely, and I
> >   realized that it doesn't really do anything for you that simply placing 
> > your signals in a CellVariable and then
> >   letting it calculate its .faceValue doesn't accomplish.
> >
> > * simplify the calculation of faceVelocity (m.faceValues is already a 
> > rank-1 FaceVariable)
> >
> > Although this script functions, I suspect it's not really what you're 
> > looking for. The signals are all extremely localized and faceVelocity is 
> > really not responsive to the density of signals, but just discretely to 
> > whether there's a signal in a given cell. If that's so, I think you'll want 
> > to calculate a density field for the signals, rather than placing them in 
> > discrete locations.
> >
> > - Jon
> >
> > On Aug 19, 2015, at 8:00 PM, Yun Tao <[email protected]> wrote:
> >
> > > Hi FiPy community,
> > >
> > > I'm currently trying to combine the powerful tool of FiPy with 
> > > agent-based modeling. The problem I'm trying to solve is this:
> > >
> > > In a 2D landscape scattered with "deterrent point signals", I want to 
> > > solve for the transient solution of a convection-diffusion 
> > > (Fokker-Planck) equation that increases its advection towards its central 
> > > attractor in a way that is proportional to the interpolated density of 
> > > local signals. I therefore expect to see gradual deformation, and slowing 
> > > down of spread, in the solution boundary as diffusion brings it closer to 
> > > clustered signals.
> > >
> > > However, since the point signals are located on mesh cell centers and the 
> > > convection coefficient in FiPy requires FaceVariable inputs, there is a 
> > > problem with dimensionality I cannot quite understand. How should I 
> > > integrate these two processes?
> > >
> > > I've attached my current script, which has the convection term commented 
> > > out for now. Left figure is the PDE solution; right figure is the 
> > > locations of the signal points.
> > >
> > > Any help would be greatly appreciated.
> > >
> > > Thanks,
> > > Yun
> > >
> > >
> > > --
> > > Yun Tao
> > > PhD
> > > University of California, Davis
> > > Department of Environmental Science and Policy
> > > One Shields Avenue
> > > Davis, CA 95616
> > > <fipy-ibm2_test_forum.py>_______________________________________________
> > > fipy mailing list
> > > [email protected]
> > > http://www.ctcms.nist.gov/fipy
> > >  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> >
> >
> > _______________________________________________
> > fipy mailing list
> > [email protected]
> > http://www.ctcms.nist.gov/fipy
> >   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> >
> >
> >
> > --
> > Yun Tao
> > PhD
> > University of California, Davis
> > Department of Environmental Science and Policy
> > One Shields Avenue
> > Davis, CA 95616
> > <signals_static.py><signals_dynamic.py>_______________________________________________
> > fipy mailing list
> > [email protected]
> > http://www.ctcms.nist.gov/fipy
> >  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> 
> 
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> 
> 
> 
> -- 
> Yun Tao
> PhD
> University of California, Davis
> Department of Environmental Science and Policy
> One Shields Avenue
> Davis, CA 95616
> <signals_dynamic2.py>_______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to