/[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 877 by gross, Wed Oct 25 03:06:58 2006 UTC revision 1122 by gross, Tue May 1 03:21:04 2007 UTC
# Line 132  class Projector: Line 132  class Projector:
132      self.__pde.setValue(D = 1.)      self.__pde.setValue(D = 1.)
133      return      return
134    
   def __del__(self):  
     return  
   
135    def __call__(self, input_data):    def __call__(self, input_data):
136      """      """
137      Projects input_data onto a continuous function      Projects input_data onto a continuous function
# Line 142  class Projector: Line 139  class Projector:
139      @param input_data: The input_data to be projected.      @param input_data: The input_data to be projected.
140      """      """
141      out=escript.Data(0.,input_data.getShape(),self.__pde.getFunctionSpaceForSolution())      out=escript.Data(0.,input_data.getShape(),self.__pde.getFunctionSpaceForSolution())
142        self.__pde.setValue(Y = escript.Data(), Y_reduced = escript.Data())
143      if input_data.getRank()==0:      if input_data.getRank()==0:
144          self.__pde.setValue(Y = input_data)          self.__pde.setValue(Y = input_data)
145          out=self.__pde.getSolution()          out=self.__pde.getSolution()
# Line 297  class Locator: Line 295  class Locator:
295         Initializes a Locator to access values in Data objects on the Doamin         Initializes a Locator to access values in Data objects on the Doamin
296         or FunctionSpace where for the sample point which         or FunctionSpace where for the sample point which
297         closest to the given point x.         closest to the given point x.
298    
299           @param where: function space
300           @type where: L{escript.FunctionSpace}
301           @param x: coefficient of the solution.
302           @type x: L{numarray.NumArray} or C{list} of L{numarray.NumArray}
303         """         """
304         if isinstance(where,escript.FunctionSpace):         if isinstance(where,escript.FunctionSpace):
305            self.__function_space=where            self.__function_space=where
306         else:         else:
307            self.__function_space=escript.ContinuousFunction(where)            self.__function_space=escript.ContinuousFunction(where)
308         self.__id=util.length(self.__function_space.getX()-x[:self.__function_space.getDim()]).mindp()         if isinstance(x, list):
309               self.__id=[]
310               for p in x:
311                  self.__id.append(util.length(self.__function_space.getX()-p[:self.__function_space.getDim()]).minGlobalDataPoint())
312           else:
313               self.__id=util.length(self.__function_space.getX()-x[:self.__function_space.getDim()]).minGlobalDataPoint()
314    
315       def __str__(self):       def __str__(self):
316         """         """
317         Returns the coordinates of the Locator as a string.         Returns the coordinates of the Locator as a string.
318         """         """
319         return "<Locator %s>"%str(self.getX())         x=self.getX()
320           if instance(x,list):
321              out="["
322              first=True
323              for xx in x:
324                if not first:
325                    out+=","
326                else:
327                    first=False
328                out+=str(xx)
329              out+="]>"
330           else:
331              out=str(x)
332           return out
333    
334         def getX(self):
335            """
336        Returns the exact coordinates of the Locator.
337        """
338            return self(self.getFunctionSpace().getX())
339    
340       def getFunctionSpace(self):       def getFunctionSpace(self):
341          """          """
# Line 316  class Locator: Line 343  class Locator:
343      """      """
344          return self.__function_space          return self.__function_space
345    
346       def getId(self):       def getId(self,item=None):
347          """          """
348      Returns the identifier of the location.      Returns the identifier of the location.
349      """      """
350          return self.__id          if item == None:
351               return self.__id
352            else:
353               if isinstance(self.__id,list):
354                  return self.__id[item]
355               else:
356                  return self.__id
357    
      def getX(self):  
         """  
     Returns the exact coordinates of the Locator.  
     """  
         return self(self.getFunctionSpace().getX())  
358    
359       def __call__(self,data):       def __call__(self,data):
360          """          """
# Line 342  class Locator: Line 370  class Locator:
370      """      """
371          if isinstance(data,escript.Data):          if isinstance(data,escript.Data):
372             if data.getFunctionSpace()==self.getFunctionSpace():             if data.getFunctionSpace()==self.getFunctionSpace():
373               #out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])               dat=data
              out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1],self.getId()[2])  
374             else:             else:
375               #out=data.interpolate(self.getFunctionSpace()).convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1])               dat=data.interpolate(self.getFunctionSpace())
376               out=data.interpolate(self.getFunctionSpace()).convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1],self.getId()[2])             id=self.getId()
377             if data.getRank()==0:             r=data.getRank()
378                return out[0]             if isinstance(id,list):
379                   out=[]
380                   for i in id:
381                      o=data.getValueOfGlobalDataPoint(*i)
382                      if data.getRank()==0:
383                         out.append(o[0])
384                      else:
385                         out.append(o)
386                   return out
387             else:             else:
388                return out               out=data.getValueOfGlobalDataPoint(*id)
389                 if data.getRank()==0:
390                    return out[0]
391                 else:
392                    return out
393          else:          else:
394             return data             return data
395    
# Line 363  class SaddlePointProblem(object): Line 402  class SaddlePointProblem(object):
402    
403     for u and p. The problem is solved with an inexact Uszawa scheme for p:     for u and p. The problem is solved with an inexact Uszawa scheme for p:
404    
405     M{Q_f (u^{k+1}-u^{k}) = - f(u^{k},p^{k})     M{Q_f (u^{k+1}-u^{k}) = - f(u^{k},p^{k})}
406     M{Q_g (p^{k+1}-p^{k}) =   g(u^{k+1})}     M{Q_g (p^{k+1}-p^{k}) =   g(u^{k+1})}
407    
408     where Q_f is an approximation of the Jacobiean A_f of f with respect to u  and Q_f is an approximation of     where Q_f is an approximation of the Jacobiean A_f of f with respect to u  and Q_f is an approximation of
# Line 375  class SaddlePointProblem(object): Line 414  class SaddlePointProblem(object):
414         """         """
415         initializes the problem         initializes the problem
416    
417         @parm verbose: switches on the printing out some information         @param verbose: switches on the printing out some information
418         @type verbose: C{bool}         @type verbose: C{bool}
419         @note: this method may be overwritten by a particular saddle point problem         @note: this method may be overwritten by a particular saddle point problem
420         """         """
421           if not isinstance(verbose,bool):
422                raise TypeError("verbose needs to be of type bool.")
423         self.__verbose=verbose         self.__verbose=verbose
424         self.relaxation=1.         self.relaxation=1.
425    
# Line 386  class SaddlePointProblem(object): Line 427  class SaddlePointProblem(object):
427         """         """
428         prints text if verbose has been set         prints text if verbose has been set
429    
430         @parm text: a text message         @param text: a text message
431         @type text: C{str}         @type text: C{str}
432         """         """
433         if self.__verbose: print "%s: %s"%(str(self),text)         if self.__verbose: print "%s: %s"%(str(self),text)
# Line 551  class SaddlePointProblem(object): Line 592  class SaddlePointProblem(object):
592                 tol_eq_f=tolerance_u*norm_df2/norm_f*norm_u_new                 tol_eq_f=tolerance_u*norm_df2/norm_f*norm_u_new
593                 if norm_g_new <= tol_eq_g and norm_f_new <= tol_eq_f:                 if norm_g_new <= tol_eq_g and norm_f_new <= tol_eq_f:
594                     converged=True                     converged=True
                    break  
595              f, norm_f, u, norm_u, g, norm_g, p, norm_p = f_new, norm_f_new, u_new, norm_u_new, g_new, norm_g_new, p_new, norm_p_new              f, norm_f, u, norm_u, g, norm_g, p, norm_p = f_new, norm_f_new, u_new, norm_u_new, g_new, norm_g_new, p_new, norm_p_new
596          self.trace("convergence after %s steps."%self.iter)          self.trace("convergence after %s steps."%self.iter)
597          return u,p          return u,p

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

  ViewVC Help
Powered by ViewVC 1.1.26