Hi Clara,

Is your spline function returning a numpy array? I think what is happening is that FiPy is seeing it as a tensor diffusion coefficient rather than just a list of the values throughout your simulation. I'm a little rusty with FiPy these days, but I think you could so something like this:


Diff = CellVariable(mesh=mesh)

Diff.setValue(d2G(Xf))

and then update the value in the loop like this:

while time < duration:
 res0 = eq.sweep(X_var, dt=dt, solver=solver)


         Diff.setValue(d2G(Xf))


Maybe 'Diff' should be FaceVariable? whichever way it should be, it should be fine in the equation definition then.

Best,
-Mike




On 8/9/17 4:48 PM, Clara Maurel wrote:
Hello,

I would like to model the Cahn Hilliard equation with a diffusion coefficient that depends on the cell variable (concentration X) and time. The diffusion coefficient (Diff) is proportional to the second derivative of the free energy (d2G), for which I have the values in an external file, for a range of concentrations. Initially I interpolated d2G with a polynomial function and could easily express Diff as a function of Xf = X.arithmeticFaceValue

However, I realised that this interpolation was not appropriate in my case. The only way I found to obtain a correct interpolation of d2G is to use a B-spline interpolation, with scipy.interpolate.UnivariateSpline. The piece of code is as follows (d2G_fit is the array of values that I imported from an external file):


X = np.arange(0.011,1.0,0.001)

X_var = CellVariable(name=r"$X_{at}$", mesh=mesh, hasOld=True)

noise = GaussianNoiseVariable(mesh=mesh, mean=X_mean, variance=1.0e-7).value
X_var[:] =  noise
X_var.updateOld()
Xf = X_var.arithmeticFaceValue

d2G = UnivariateSpline(X, d2G_fit[id_mean_spino], k=3, s=0)
Diff = d2G(Xf)


My problem is that when I start looping with:

while time < duration:
 res0 = eq.sweep(X_var, dt=dt, solver=solver)

I have the error message:

IndexError: diffusion coefficent tensor is not an appropriate shape for this mesh


I also tried:

Diff = Variable(value=d2G(Xf))
and
Diff =  d2G(Xf)*Variable(list(d2G(Xf)))

but I have the same error.

Could you tell me how I could work this out? Additional comment: Diff evolves with time, I update it at selected timestep in the loop.


Any hint would be greatly appreciated!

Thank you in advance!
Clara





_______________________________________________
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 ]

Reply via email to