Hello Everyone,

I am trying to use an ideal chemical free energy formulation for a problem,
where I have terms of the form x*log(x). Computing x*log(x) at x = 0 gives
the error "RuntimeWarning: divide by zero encountered in log".  Even if I
try to prevent computation of x*log(x) at x = 0 by doing (for example):

epsilon = 1.0e-3
G.setValue((x>epsilon)*log(x>epsilon))

or

G.setValue(x*log(x), where=(x>0))

the error persists.

A test script is attached with this email.

Looking up online, I read that "log" is computed before "where". Another
suggestion says to catch and handle the exception (links below).

http://stackoverflow.com/questions/25087769/runtimewarning-divide-by-zero-error-how-to-avoid-python-numpy

http://stackoverflow.com/questions/13497891/python-getting-around-division-by-zero

Any thoughts on how to get rid of the problem, especially for FiPy, and/or
the ideal free energy formulation?

Thank You!

Best regards,
Aniruddha
#!/usr/bin/env python
from fipy.variables.cellVariable import CellVariable
from fipy import Grid2D 
from fipy.tools.numerix import log,where
nx = ny = 100
dx = dy = 1.e-6
mesh = Grid2D(nx=nx, ny=ny, dx=dx,dy=dy)
x = CellVariable(mesh=mesh, value=0.2,hasOld = True)
G = CellVariable(mesh=mesh, value=0.)
width = nx*dx
height = ny*dy
epsilon = 1.0e-3
x.setValue(value=0., where=(mesh.y<0.5*height))
#G.setValue((x>epsilon)*log(x>epsilon))
G.setValue(x*log(x), where=(x>0))

_______________________________________________
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