On Thu, Nov 13, 2008 at 7:30 PM, Thomas Cool <[EMAIL PROTECTED]> wrote:
>
> Thanks for the help
> I was wondering how you would make the values in CellVariable a Vector?
A CellVariable either is or isn't a vector. I don't think it is
possible to change the rank of a CellVariable, or if it is it doesn't
make a whole lot of sense. Why do you want to do this? The value it
holds determine its vector quality.
> or do i have to make a second cellvariable?
If you have a scalar CellVariable, you can make it a vector by
multiplying by a vector. For example, if (1, 1) (the CellVariable
interprets this as (1, 2) vector value for convenience) is the vector
then,
In [1]: from fipy import *
In [2]: m = Grid2D(nx=2, ny=2)
In [3]: x, y = m.getCellCenters()
In [4]: v = CellVariable(mesh=m, value=x * y)
In [5]: v
Out[5]: CellVariable(value=array([ 0.25, 0.75, 0.75, 2.25]),
mesh=UniformGrid2D(dx=1.0, dy=1.0, nx=2, ny=2))
In [6]: v * (1, 1)
Out[6]: (CellVariable(value=array([ 0.25, 0.75, 0.75, 2.25]),
mesh=UniformGrid2D(dx=1.0, dy=1.0, nx=2, ny=2)) * [1 1][index])
In [7]: print v * (1, 1)
[[ 0.25 0.75 0.75 2.25]
[ 0.25 0.75 0.75 2.25]]
In [10]: print (v * (1, 1)).getRank()
1
In [11]: print v.getRank()
0
> Tom
>
> On Nov 12, 2008, at 9:40 AM, Jonathan Guyer wrote:
>
>>
>> On Nov 11, 2008, at 8:52 AM, Thomas Cool wrote:
>>
>>> I'm trying to use the matplotlib vector viewer for fipy but i'm having
>>> problems: could anyone take a look and tell me what's wrong?
>>
>>
>>
>> Other than
>>
>>> import fipy.viewers.matplotlibViewer.matplotlibVectorViewer
>>
>> I don't see any attempt to use the vector viewer.
>>
>>> viewer = fipy.viewers.make(vars = var,
>>
>> doesn't care what imports you've done. It looks at the supplied vars and
>> tries to create appropriate Viewers for them. Since var is scalar:
>>
>>> P = 1.0
>>> E = 0.0
>>>
>>> var = CellVariable(name = "phase field",
>>> mesh = mesh,
>>> value = 2.0*P*random.random(nx * ny) - P)
>>
>> fipy.viewers.make() will return a scalar Viewer.
>>
>> You *could* try to replace
>>
>>> viewer = fipy.viewers.make(vars = var,
>>> limits = {'datamin': -1.0e0,
>>> 'datamax': 1.0e-0}
>>> )
>>
>> with
>>
>>> viewer =
>>> fipy.viewers.matplotlibViewer.matplotlibVectorViewer.MatplotlibVectorViewer(vars
>>> = var,
>>> limits = {'datamin': -1.0e0,
>>> 'datamax': 1.0e-0}
>>> )
>>
>>
>> but this won't work because var is scalar. On the other hand,
>>
>>> viewer = fipy.viewers.make(vars = var.getGrad(),
>>> limits = {'datamin': -1.0e0,
>>> 'datamax': 1.0e-0}
>>> )
>>
>>
>> should work (although I don't know that datamin and datamax are
>> interpreted usefully for a vector viewer (and even if they were, they'd
>> probably refer to magnitude, so -1.0e0 wouldn't be a good value)).
>>
>> There's no reason for the line:
>>
>>> import fipy.viewers.matplotlibViewer.matplotlibVectorViewer
>>
>> as you've already locked in matplotlib:
>>
>>> os.environ["FIPY_VIEWER"]="matplotlib"
>>
>> and viewers.make() will take care of giving you a vector Viewer when
>> that's appropriate.
>>
>>
>
>
>
--
Daniel Wheeler