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)