On Feb 15, 2012, at 8:30 AM, Jesper Friis wrote:

> I am trying to solve a pure convection problem with a dirac-shaped source 
> term depending both in size and position on the solution variable. The 
> problem is that the source term becomes a OperatorVariable, while a 
> CellVariable is required by the equation. If I try to do something like this
> 
>>>> import fipy as fp
>>>> mesh = fp.Grid1D(dx=L/nr, nx=nr)
>>>> b = mesh.getFaceCenters()[0]
>>>> dr = mesh.getCellVolumes()
>>>> j = some_scalar_function(phi)
>>>> rbirth = another_scalar_function(phi)
>>>> S = j / dr * (b[:-1] <= rbirth) * (rbirth < b[1:])

The issue is not that S is an OperatorVariable (we do that all the time), but 
that that OperatorVariable is a FaceVariable, through b.

There isn't really a FiPyish way to tell what cell a particular position lies 
in, although I think this is close:

>>> x = mesh.getCellCenters()[0]
>>> S = j / dr * (abs(rbirth - x) < dr)

For a single value, or even a field of values, you can use 
mesh._getNearestCellID(points), but this doesn't tell you which cells are 
positioned nearest to rbirth, which is what I gather you're trying to calculate.

This situation doesn't usually arise for us in the solution of phase field and 
level set problems that we designed FiPy for. In those cases, any boundary is 
diffuse and so any delta function has some width to it. In a phase field 
problem, I would make the source proportional to the barrier function, e.g. 
phi**2 * (1 - phi)**2. In a level set problem, you would set the source to 
wherever the level set has the desired value +/- some tolerance. That's kind of 
what I tried to do above with abs(rbirth - x) < dr.


> Another question. When coupling FiPy with other models, it would be very 
> useful if one could construct a Variable or CellVariable that will call an 
> user-supplied function when it needs to calculate its value. How can this be 
> achieved?

You need to subclass either Variable or CellVariable and write an appropriate 
_calcValue() routine. See any of the NoiseVariable classes for this use case: 
http://matforge.org/fipy/browser/trunk/fipy/variables/noiseVariable.py


_______________________________________________
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