/[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 2474 by gross, Tue Jun 16 06:32:15 2009 UTC revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC
# Line 1  Line 1 
1    
2  ########################################################  ########################################################
3  #  #
4  # Copyright (c) 2003-2008 by University of Queensland  # Copyright (c) 2003-2009 by University of Queensland
5  # Earth Systems Science Computational Center (ESSCC)  # Earth Systems Science Computational Center (ESSCC)
6  # http://www.uq.edu.au/esscc  # http://www.uq.edu.au/esscc
7  #  #
# Line 326  class Locator: Line 326  class Locator:
326    
327         @param where: function space         @param where: function space
328         @type where: L{escript.FunctionSpace}         @type where: L{escript.FunctionSpace}
329         @param x: coefficient of the solution         @param x: location(s) of the Locator
330         @type x: C{numpy.ndarray} or C{list} of C{numpy.ndarray}         @type x: C{numpy.ndarray} or C{list} of C{numpy.ndarray}
331         """         """
332         if isinstance(where,escript.FunctionSpace):         if isinstance(where,escript.FunctionSpace):
333            self.__function_space=where            self.__function_space=where
334         else:         else:
335            self.__function_space=escript.ContinuousFunction(where)            self.__function_space=escript.ContinuousFunction(where)
336           iterative=False
337         if isinstance(x, list):         if isinstance(x, list):
338               if len(x)==0:
339                  raise "ValueError", "At least one point must be given."
340               try:
341                 iter(x[0])
342                 iterative=True
343               except TypeError:
344                 iterative=False
345           if iterative:
346             self.__id=[]             self.__id=[]
347             for p in x:             for p in x:
348                self.__id.append(util.length(self.__function_space.getX()-p[:self.__function_space.getDim()]).minGlobalDataPoint())                self.__id.append(util.length(self.__function_space.getX()-p[:self.__function_space.getDim()]).minGlobalDataPoint())
# Line 396  class Locator: Line 405  class Locator:
405          object otherwise the object is returned.          object otherwise the object is returned.
406          """          """
407          if isinstance(data,escript.Data):          if isinstance(data,escript.Data):
408             if data.getFunctionSpace()==self.getFunctionSpace():             dat=util.interpolate(data,self.getFunctionSpace())
              dat=data  
            else:  
              dat=data.interpolate(self.getFunctionSpace())  
409             id=self.getId()             id=self.getId()
410             r=data.getRank()             r=data.getRank()
411             if isinstance(id,list):             if isinstance(id,list):
412                 out=[]                 out=[]
413                 for i in id:                 for i in id:
414                    o=numpy.array(data.getTupleForGlobalDataPoint(*i))                    o=numpy.array(dat.getTupleForGlobalDataPoint(*i))
415                    if data.getRank()==0:                    if data.getRank()==0:
416                       out.append(o[0])                       out.append(o[0])
417                    else:                    else:
418                       out.append(o)                       out.append(o)
419                 return out                 return out
420             else:             else:
421               out=numpy.array(data.getTupleForGlobalDataPoint(*id))               out=numpy.array(dat.getTupleForGlobalDataPoint(*id))
422               if data.getRank()==0:               if data.getRank()==0:
423                  return out[0]                  return out[0]
424               else:               else:
# Line 1738  def MaskFromBoundaryTag(domain,*tags): Line 1744  def MaskFromBoundaryTag(domain,*tags):
1744     pde.setValue(y=d)     pde.setValue(y=d)
1745     return util.whereNonZero(pde.getRightHandSide())     return util.whereNonZero(pde.getRightHandSide())
1746    
1747    def MaskFromTag(domain,*tags):
1748       """
1749       Creates a mask on the Solution(domain) function space where the value is
1750       one for samples that touch regions tagged by tags.
1751    
1752       Usage: m=MaskFromTag(domain, "ham")
1753    
1754       @param domain: domain to be used
1755       @type domain: L{escript.Domain}
1756       @param tags: boundary tags
1757       @type tags: C{str}
1758       @return: a mask which marks samples that are touching the boundary tagged
1759                by any of the given tags
1760       @rtype: L{escript.Data} of rank 0
1761       """
1762       pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)
1763       d=escript.Scalar(0.,escript.Function(domain))
1764       for t in tags: d.setTaggedValue(t,1.)
1765       pde.setValue(Y=d)
1766       return util.whereNonZero(pde.getRightHandSide())
1767    
1768    

Legend:
Removed from v.2474  
changed lines
  Added in v.2548

  ViewVC Help
Powered by ViewVC 1.1.26