On Wed, Aug 26, 2009 at 3:36 PM, Jonathan Guyer <[email protected]> wrote:

>
>
> On Aug 26, 2009, at 11:10 AM, Ranjit Chacko wrote:
>
>  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.
>>
>
> var.elementshape is the shape of each element in the variable [ () for a
> scalar field, (2,) for a 2D vector field, and so on]. This has been assigned
> for all _MeshVariables for over two years. What version of FiPy are you
> using?
>
> When you say "empty", do you mean unassigned or is it the empty tuple () ?
> If the latter, then you're fine.
>

I meant the empty tuple.

>
>
>  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.
>>
>
> I reshaped the value going to scipy.something(), but I neglected to change
> the shape back for FiPy. Try this:
>
> 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):
>        mesh = self.getMesh()
>
>        a = self.var.getValue()
>        a = a.reshape(mesh.getShape() + self.elementshape)
>
>        a = scipy.something(a)
>
>        return a.reshape((mesh.getNumberOfCells(),) + self.elementshape)
>
>
>
The shape mismatch error is gone, but now I have a TypeError. It says the
array cannot be safely cast to the required type.

Reply via email to