/[escript]/temp/escript/py_src/pdetools.py
ViewVC logotype

Diff of /temp/escript/py_src/pdetools.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 877 by gross, Wed Oct 25 03:06:58 2006 UTC revision 880 by gross, Wed Oct 25 23:58:16 2006 UTC
# Line 297  class Locator: Line 297  class Locator:
297         Initializes a Locator to access values in Data objects on the Doamin         Initializes a Locator to access values in Data objects on the Doamin
298         or FunctionSpace where for the sample point which         or FunctionSpace where for the sample point which
299         closest to the given point x.         closest to the given point x.
300    
301           @param where: function space
302           @type where: L{escript.FunctionSpace}
303           @param x: coefficient of the solution.
304           @type x: L{numarray.NumArray} or C{list} of L{numarray.NumArray}
305         """         """
306         if isinstance(where,escript.FunctionSpace):         if isinstance(where,escript.FunctionSpace):
307            self.__function_space=where            self.__function_space=where
308         else:         else:
309            self.__function_space=escript.ContinuousFunction(where)            self.__function_space=escript.ContinuousFunction(where)
310         self.__id=util.length(self.__function_space.getX()-x[:self.__function_space.getDim()]).mindp()         if isinstance(x, list):
311               self.__id=[]
312               for p in x:
313                  self.__id.append(util.length(self.__function_space.getX()-p[:self.__function_space.getDim()]).mindp())
314           else:
315               self.__id=util.length(self.__function_space.getX()-x[:self.__function_space.getDim()]).mindp()
316    
317       def __str__(self):       def __str__(self):
318         """         """
319         Returns the coordinates of the Locator as a string.         Returns the coordinates of the Locator as a string.
320         """         """
321         return "<Locator %s>"%str(self.getX())         x=self.getX()
322           if instance(x,list):
323              out="["
324              first=True
325              for xx in x:
326                if not first:
327                    out+=","
328                else:
329                    first=False
330                out+=str(xx)
331              out+="]>"
332           else:
333              out=str(x)
334           return out
335    
336         def getX(self):
337            """
338        Returns the exact coordinates of the Locator.
339        """
340            return self(self.getFunctionSpace().getX())
341    
342       def getFunctionSpace(self):       def getFunctionSpace(self):
343          """          """
# Line 316  class Locator: Line 345  class Locator:
345      """      """
346          return self.__function_space          return self.__function_space
347    
348       def getId(self):       def getId(self,item=None):
349          """          """
350      Returns the identifier of the location.      Returns the identifier of the location.
351      """      """
352          return self.__id          if item == None:
353               return self.__id
354            else:
355               if isinstance(self.__id,list):
356                  return self.__id[item]
357               else:
358                  return self.__id
359    
      def getX(self):  
         """  
     Returns the exact coordinates of the Locator.  
     """  
         return self(self.getFunctionSpace().getX())  
360    
361       def __call__(self,data):       def __call__(self,data):
362          """          """
# Line 342  class Locator: Line 372  class Locator:
372      """      """
373          if isinstance(data,escript.Data):          if isinstance(data,escript.Data):
374             if data.getFunctionSpace()==self.getFunctionSpace():             if data.getFunctionSpace()==self.getFunctionSpace():
375               #out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])               dat=data
              out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1],self.getId()[2])  
376             else:             else:
377               #out=data.interpolate(self.getFunctionSpace()).convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])               dat=data.interpolate(self.getFunctionSpace())
378               out=data.interpolate(self.getFunctionSpace()).convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1],self.getId()[2])             id=self.getId()
379             if data.getRank()==0:             r=data.getRank()
380                return out[0]             if isinstance(id,list):
381                   out=[]
382                   for i in id:
383                      o=data.convertToNumArrayFromDPNo(*i)
384                      if data.getRank()==0:
385                         out.append(o[0])
386                      else:
387                         out.append(o)
388                   return out
389             else:             else:
390                return out               out=data.convertToNumArrayFromDPNo(*id)
391                 if data.getRank()==0:
392                    return out[0]
393                 else:
394                    return out
395          else:          else:
396             return data             return data
397    

Legend:
Removed from v.877  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC 1.1.26