Dear Jonathan, many thanks for the prompt reply.
On 25 May 2011, at 14:32, Jonathan Guyer wrote: > >> >> Here is a question to which I couldn't find the answer in the manual, >> examples, or by inspecting the variable and mesh classes: > > We clearly need to do a better job of documenting this. > >> Given a CellVariable that contains the solution of a (scalar) field >> phi (through an instance of the CellVariable class), I would like to >> know the value of phi at a particular position. > > The CellVariable.__call__() operator provides this, such that > > phi((x,y)) > > provides what you want. This works for both single points > > phi((2.5, 3.2)) > > and sets of points > > phi(((2.5, 7.8, 9.9), > (3.2, 1.7, 0.2))) > Very nice; just what I need. > > I see that the Sphinx tool that generates our documentation is omitting the > special Python methods like __call__. We'll have to figure out how to fix > that. In the meantime, you can find the documentation here: > > > http://matforge.org/fipy/browser/branches/version-2_1/fipy/variables/cellVariable.py#L159 Running the example from that URL: Python 2.7.1 |EPD 7.0-2 (32-bit)| (r271:86832, Dec 3 2010, 15:41:32) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from fipy import * >>> m = Grid2D(nx=3, ny=2) >>> v = CellVariable(mesh=m, value=m.getCellCenters()[0]) I can use the command as you describe for the set of points: >>> v(((2.5, 7.8, 9.9), .. (3.2, 1.7, 0.2))) array([ 2.5, 2.5, 2.5]) The command doesn't seem to work for a single item: >>> v((2.5,3.2)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/FiPy-2.1.1-py2.7.egg/fipy/variables/cellVariable.py", line 197, in __call__ nearestCellIDs = self.getMesh()._getNearestCellID(points) File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/FiPy-2.1.1-py2.7.egg/fipy/meshes/numMesh/uniformGrid2D.py", line 598, in _getNearestCellID i[i < 0] = 0 IndexError: 0-d arrays can't be indexed. But works in the multi-point syntax (so solves my problem): >>> v(((2.5,),(3.2,))) array([ 2.5]) Many thanks! Best wishes, Hans
