Thanks, that's really helpful. I tried implementing it though and the
program's crashing so I've got a couple of questions about that sample
code.
What is var.elementshape? It seems to be empty in my program.

What exactly is _calcValue supposed to return? Is it expected to
return a single number or an array with all the values of the field?
I'm getting an error message that says something about a shape mismatch.

Thanks again,

-Ranjit


On Tue, Aug 25, 2009 at 10:29 AM, Jonathan Guyer <[email protected]> wrote:

>
>
> On Aug 24, 2009, at 11:20 AM, Ranjit Chacko wrote:
>
>  Thanks for the reply. What's the format of the array when the variable is
>> defined on a 2D grid? Both methods seem to return a 1D array. Is there a way
>> to get out the values in a 2D array?
>>
>
> The value of a MeshVariable does not know anything about the geometry or
> topology of the data. It's just a bunch of numbers. Higher-ranks are
> reflected in the value (value.shape will be (N,), (2, N), (3, 3, N), etc.),
> but N is just the number of points; it knows nothing about 1D, 2D, or 3D
> geometry. Since FiPy handles unstructured meshes, in the general case a
> NumPy array can't represent geometry in any obvious way.
>
> For this reason, and the fact that what Daniel showed requires manually
> converting back and forth, I'd be inclined to encapsulate all of this in a
> specialized variable type:
>
> class ConvolutionVariable(CellVariable):
>    def __init__(self, var):
>        CellVariable.__init__(self,
>                              mesh=var.getMesh(),
>                              elementshape=var.elementshape,
>                              hasOld=False)
>        self.var = self._requires(var)
>
>    def _calcValue(self):
>        a = self.var.getValue()
>        a = a.reshape(self.getMesh().getShape())
>        return scipy.something(a)
>
>
> This is obviously more work than what Daniel wrote, but it's cleaner to
> use:
>
> eqn = someTerms + ConvolutionVariable(var)
>
> while True:
>    eqn.solve(var)
>
>
>
>
>

Reply via email to