On Oct 19, 2010, at 2:31 PM, Akhil Shah wrote:

> Hello, 
> I am very new to FiPy and trying to solve a 2D diffusion problem with a 
> random source using a method that requires sampling from a conditional 
> distribution (derived from the associated Fokker-Plank equation) at each time 
> step then evolving the deterministic part of the PDE.  
> 
> The conditional distribution (it's a combination of Beta/Gamma but doesn't 
> matter for my question) would require field-dependent parameters (for the 
> mean/variance/etc.).  For example, the following does NOT work (1D example):
> 
> mesh=Grid1D(nx=50,dx=1.)
> phi=CellVariable(name="my field at time 0",mesh=mesh)
> x=mesh.getCellCenters()[0]
> from scipy.special import erf
> phi.setValue(1-erf(x))
> noise=ExponentialNoiseVariable(mesh=mesh,mean=phi) #mean depends on phi 

You don't say what happens, but when I test this, I get "ValueError: scale <= 
0". I'm not sure why I wrote the ExponentialNoiseVariable() with a "mean" 
argument; "mean" is passed to numpy.random.exponential() as "scale" \beta in: 
f(x; \frac{1}{\beta}) = \frac{1}{\beta} \exp(-\frac{x}{\beta}).

\beta must be positive.

You should be able to address this by doing something like:

offset = min(phi) + epsilon
noise=ExponentialNoiseVariable(mesh=mesh,mean=phi - offset) + offset


> Do I just have to create a "for" loop across the mesh, extract phi at the 
> cell center, generate the corresponding noise at that cell center (using the 
> phi at that cell center as the parameter for whatever distribution) and 
> somehow re-assemble the noise field?

That would be very slow, if nothing else.




Reply via email to