On Feb 4, 2013, at 11:59 AM, William McFadden wrote:

> From the FAQ, I'm setting it up by defining CellVariables that can be set to 
> vary spatially 
> 
> n_xx = CellVariable(mesh=mesh, value = x) 
> n_yx = CellVariable(mesh=mesh,value= x) 
> 
> then I generate a few diffusion terms. 
> the first term works fine when isolated 
> 
> eq_ux = DiffusionTerm(coeff=CellVariable(mesh=mesh, value = 
> [[2*n_xx,0],[0,0]]), var=ux) 
> 
> but the second term 
> 
> + DiffusionTerm(coeff=CellVariable(mesh=mesh, value = [[0,0],[n_yx,0]]), 
> var=uy) 
> 
> fails with error 
> 
> File 
> "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/FiPy-3.0-py2.7.egg/fipy/variables/meshVariable.py",
>  line 64, in __init__ 
>    value = numerix.array(value) 
> ValueError: setting an array element with a sequence. 
> 
> I can't see what the difference would be.


I frankly don't understand why either one of them seems to work. Whatever the 
behavior, it's due to the underlying numpy library, not anything that FiPy is 
doing:

>>> import numpy as np
>>> np.array([[[1, 2, 3], 0], [0, 0]])
array([[[1, 2, 3], 0],
       [0, 0]], dtype=object)
>>> np.array([[0, [1, 2, 3]], [0, 0]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.

The first case doesn't really "work" as evinced by the "dtype=object". That 
means that NumPy doesn't think you've created an array of numbers, but rather 
an array of objects. objects can be anything, but they're not useful unless 
everything that deals with them knows how. We need an array of numbers.

You need to create an anisotropic coefficient where each entry has the same 
shape (2*n_xx and n_xy are lists of length N, whereas 0 is a scalar). The 
easiest way to do this is

D_xx = CellVariable(mesh=mesh, rank=2, value=0.)
D_xx[0, 0] = 2 * n_xx

D_yx = CellVariable(mesh=mesh, rank=2, value=0.)
D_yx[1, 0] = n_yx



_______________________________________________
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