On Mar 19, 2008, at 11:25 AM, Michael Waters wrote:

I'm running into a new error however, and was hoping someone could explain to me what is happening. I am trying to create a simple solidification model.
The problem comes up as this:
    TypeError: unsupported operand type(s) for +: 'binOp' and 'unOp'
I am new to fipy and python so im having trouble conceptualizing binOp vs. unOp. The error comes up around line 120.
thanks!

I believe that the immediate problem is that

    dxi = (A*phase).getGrad()._take((1, 0), axis = 1) * (-1, 1)

returns a VectorCellVariable (because of getGrad()), such that

    anisotropySource =(dxi).getDivergence()

returns a FaceVariable. Then, when you do

    thetaMag + anisotropySource

you're trying to add a CellVariable to a FaceVariable, which is not allowed. The "unsupported operand type(s) for +: 'binOp' and 'unOp'" or "'unOp' and 'unOp'" is generated by Python, and we don't have a great deal of control over it (but we recognize that it's not very helpful). A 'unOp' is a unary operator (like sin(x)) and a 'binOp' is a binary operator (like a + b). That's not what's important; FiPy is quite capable of adding upOp's and binOp's (they're designed for that); the problem is that an OperatorVariable can be either a FaceVariable or a CellVariable, and it's those that are incompatible. I'll will try to figure out a way to make Python return a more informative error message, but I'm not optimistic.

I couldn't even swear that VectorCellVariable.getDivergence() is even doing the right thing (we don't test it, and I don't believe we ever use it). It's not very useful, even if it does work. If we don't get rid of it, we should probably make it return a CellVariable. phi.getGrad().getDivergence() would be a 1st order Laplacian, but at least it you'd be able to use it where probably everybody would expect to; I don't know what you'd want a divergence as a FaceVariable for (and I think I wrote it), but I'll see if Daniel has any thoughts on keeping the status quo.

Instead, if you do this

    dxi = (A*phase).getFaceGrad()._take((1, 0), axis = 1) * (-1, 1)

you'll get a VectorFaceVariable, and then

    anisotropySource =(dxi).getDivergence()

will return a CellVariable (desirably 2nd order), which is a proper source to use in your equation.

Reply via email to