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

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

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

revision 146 by jgs, Fri Jul 29 01:44:29 2005 UTC revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC
# Line 67  class Projector: Line 67  class Projector:
67      return out      return out
68    
69    
70  class Location:  class Locator:
71       """Location provides a factory to access the values of data objects at a given spatial coordinate x.       """
         In fact, a Location object finds the sample in the set of samples of a given function space or domain which is closest  
         to the given point x. """  
72    
73       def __init__(self,x,where):          Locator provides a  access the values of data objects at a given spatial coordinate x.
74         """initializes a Location to access values in Data objects on the Doamin or FunctionSpace where for the sample point which          In fact, a Locator object finds the sample in the set of samples of a given function space or domain where which is closest
75            to the given point x.
76    
77         """
78    
79         def __init__(self,where,x=numarray.zeros((3,))):
80           """initializes a Locator to access values in Data objects on the Doamin or FunctionSpace where for the sample point which
81            closest to the given point x"""            closest to the given point x"""
82         if isinstance(where,FunctionSpace):         if isinstance(where,FunctionSpace):
83            self.__where=where            self.__function_space=where
84         else:         else:
85            self.__where=ContinuousFunction(where)            self.__function_space=ContinuousFunction(where)
86         self.__id=length(x-self.__where.getX()).minarg()         self.__id=length(x[:self.__function_space.getDim()]-self.__function_space.getX()).mindp()
87    
88       def getValue(self,data):       def __str__(self):
89          """returns the value of data at the Location at a numarray object"""         """returns the coordinates of the Locator as a string"""
90          if isinstance(data,Data):         return "<Locator %s>"%str(self.getX())
            return data  
         else:  
            if not data.getFunctionSpace()==self.getFunctionSpace():  
              raise ValueError,"function space of data obejct does not match function space of Location"  
            else:  
              return data.getValue(self.getId())  
      def getX(self):  
         """returns the exact coordinates of the Location"""  
         return self.getValue(self.getFunctionSpace().getX())  
   
      def getId(self):  
         """returns the identifier of the location"""  
         return self.__id  
91    
92       def getFunctionSpace(self):       def getFunctionSpace(self):
93          """returns the function space of the Location"""          """returns the function space of the Locator"""
94          return self.__function_space          return self.__function_space
95    
96       def __str__(self):       def getId(self):
97         """returns the coordinates of the Location as a string"""          """returns the identifier of the location"""
98         return str(self.getX())          return self.__id
   
 def testProjector(domain):  
       """runs a few test of the Projector factory and returns the largest error plus a description of the test this error occured"""  
       error_max=0.  
       error_text=""  
       x=ContinuousFunction(domain).getX()  
       for f in [True,False]:  
          p=Projector(domain,reduce=False,fast=f)  
          for r in range(5):  
             text="range %s , fast=%s"%(r,f)  
             if r==0:  
                td_ref=x[0]  
             elif r==1:  
                td_ref=x  
             elif r==2:  
                td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])  
             elif r==3:  
                td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])  
             elif r==3:  
                td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])  
             td=p(td_ref.interpolate(Function(domain)))  
             er=Lsup(td-td_ref)/Lsup(td_ref)  
             print text," error = ",er  
             if er>error_max:  
                  error_max=er  
                  error_text=text  
       return error_max,error_text  
   
   
 # this should be removed later  
 if __name__=="__main__":  
     from esys.finley import Rectangle  
     txt=testProjector(Rectangle(56,61))  
     print "test Projector: ",txt  
99    
100         def getX(self):
101            """returns the exact coordinates of the Locator"""
102            return self(self.getFunctionSpace().getX())
103    
104         def __call__(self,data):
105            """returns the value of data at the Locator of a Data object otherwise the object is returned."""
106            return self.getValue(data)
107    
108         def getValue(self,data):
109            """returns the value of data at the Locator if data is a Data object otherwise the object is returned."""
110            if isinstance(data,Data):
111               if data.getFunctionSpace()==self.getFunctionSpace():
112                 out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])
113               else:
114                 out=data.interpolate(self.getFunctionSpace()).convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])
115               if data.getRank()==0:
116                  return out[0]
117               else:
118                  return out
119            else:
120               return data

Legend:
Removed from v.146  
changed lines
  Added in v.147

  ViewVC Help
Powered by ViewVC 1.1.26