/[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 3981 by jfenwick, Fri Sep 21 02:47:54 2012 UTC revision 3995 by jfenwick, Wed Sep 26 12:43:17 2012 UTC
# Line 40  Currently includes: Line 40  Currently includes:
40  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
41    
42    
43  from . import escript  #from . import escript
44    from . import escriptcpp
45    escore=escriptcpp
46  from . import linearPDEs  from . import linearPDEs
47  import numpy  import numpy
48  from . import util  from . import util
# Line 168  class Projector: Line 170  class Projector:
170    
171      :param input_data: the data to be projected      :param input_data: the data to be projected
172      """      """
173      out=escript.Data(0.,input_data.getShape(),self.__pde.getFunctionSpaceForSolution())      out=escore.Data(0.,input_data.getShape(),self.__pde.getFunctionSpaceForSolution())
174      self.__pde.setValue(Y = escript.Data(), Y_reduced = escript.Data())      self.__pde.setValue(Y = escore.Data(), Y_reduced = escore.Data())
175      if input_data.getRank()==0:      if input_data.getRank()==0:
176          self.__pde.setValue(Y = input_data)          self.__pde.setValue(Y = input_data)
177          out=self.__pde.getSolution()          out=self.__pde.getSolution()
# Line 248  class NoPDE: Line 250  class NoPDE:
250           self.__q=q           self.__q=q
251           self.__r=r           self.__r=r
252           self.__u=None           self.__u=None
253           self.__function_space=escript.Solution(self.__domain)           self.__function_space=escore.Solution(self.__domain)
254    
255       def setReducedOn(self):       def setReducedOn(self):
256           """           """
257           Sets the `FunctionSpace` of the solution to `ReducedSolution`.           Sets the `FunctionSpace` of the solution to `ReducedSolution`.
258           """           """
259           self.__function_space=escript.ReducedSolution(self.__domain)           self.__function_space=escore.ReducedSolution(self.__domain)
260           self.__u=None           self.__u=None
261    
262       def setReducedOff(self):       def setReducedOff(self):
263           """           """
264           Sets the `FunctionSpace` of the solution to `Solution`.           Sets the `FunctionSpace` of the solution to `Solution`.
265           """           """
266           self.__function_space=escript.Solution(self.__domain)           self.__function_space=escore.Solution(self.__domain)
267           self.__u=None           self.__u=None
268    
269       def setValue(self,D=None,Y=None,q=None,r=None):       def setValue(self,D=None,Y=None,q=None,r=None):
# Line 301  class NoPDE: Line 303  class NoPDE:
303           if self.__u==None:           if self.__u==None:
304              if self.__D==None:              if self.__D==None:
305                 raise ValueError("coefficient D is undefined")                 raise ValueError("coefficient D is undefined")
306              D=escript.Data(self.__D,self.__function_space)              D=escore.Data(self.__D,self.__function_space)
307              if D.getRank()>1:              if D.getRank()>1:
308                 raise ValueError("coefficient D must have rank 0 or 1")                 raise ValueError("coefficient D must have rank 0 or 1")
309              if self.__Y==None:              if self.__Y==None:
310                 self.__u=escript.Data(0.,D.getShape(),self.__function_space)                 self.__u=escore.Data(0.,D.getShape(),self.__function_space)
311              else:              else:
312                 self.__u=1./D*self.__Y                 self.__u=1./D*self.__Y
313              if not self.__q==None:              if not self.__q==None:
314                  q=util.wherePositive(escript.Data(self.__q,self.__function_space))                  q=util.wherePositive(escore.Data(self.__q,self.__function_space))
315                  self.__u*=(1.-q)                  self.__u*=(1.-q)
316                  if not self.__r==None: self.__u+=q*self.__r                  if not self.__r==None: self.__u+=q*self.__r
317           return self.__u           return self.__u
# Line 334  class Locator: Line 336  class Locator:
336         :param x: location(s) of the Locator         :param x: location(s) of the Locator
337         :type x: ``numpy.ndarray`` or ``list`` of ``numpy.ndarray``         :type x: ``numpy.ndarray`` or ``list`` of ``numpy.ndarray``
338         """         """
339         if isinstance(where,escript.FunctionSpace):         if isinstance(where,escore.FunctionSpace):
340            self.__function_space=where            self.__function_space=where
341         else:         else:
342            self.__function_space=escript.ContinuousFunction(where)            self.__function_space=escore.ContinuousFunction(where)
343         iterative=False         iterative=False
344         if isinstance(x, list):         if isinstance(x, list):
345             if len(x)==0:             if len(x)==0:
# Line 410  class Locator: Line 412  class Locator:
412          Returns the value of ``data`` at the Locator if ``data`` is a `Data`          Returns the value of ``data`` at the Locator if ``data`` is a `Data`
413          object otherwise the object is returned.          object otherwise the object is returned.
414          """          """
415          if isinstance(data,escript.Data):          if isinstance(data,escore.Data):
416             dat=util.interpolate(data,self.getFunctionSpace())             dat=util.interpolate(data,self.getFunctionSpace())
417             id=self.getId()             id=self.getId()
418             r=data.getRank()             r=data.getRank()
# Line 436  class Locator: Line 438  class Locator:
438        """        """
439        Sets the value of the ``data`` at the Locator.        Sets the value of the ``data`` at the Locator.
440        """        """
441        if isinstance(data, escript.Data):        if isinstance(data, escore.Data):
442           if data.getFunctionSpace()!=self.getFunctionSpace():           if data.getFunctionSpace()!=self.getFunctionSpace():
443             raise TypeError, "setValue: FunctionSpace of Locator and Data object must match."             raise TypeError, "setValue: FunctionSpace of Locator and Data object must match."
444           data.expand()             data.expand()  
# Line 454  def getInfLocator(arg): Line 456  def getInfLocator(arg):
456      """      """
457      Return a Locator for a point with the inf value over all arg.      Return a Locator for a point with the inf value over all arg.
458      """      """
459      if not isinstance(arg, escript.Data):      if not isinstance(arg, escore.Data):
460         raise TypeError("getInfLocator: Unknown argument type.")         raise TypeError("getInfLocator: Unknown argument type.")
461      a_inf=util.inf(arg)      a_inf=util.inf(arg)
462      loc=util.length(arg-a_inf).minGlobalDataPoint() # This gives us the location but not coords      loc=util.length(arg-a_inf).minGlobalDataPoint() # This gives us the location but not coords
# Line 466  def getSupLocator(arg): Line 468  def getSupLocator(arg):
468      """      """
469      Return a Locator for a point with the sup value over all arg.      Return a Locator for a point with the sup value over all arg.
470      """      """
471      if not isinstance(arg, escript.Data):      if not isinstance(arg, escore.Data):
472         raise TypeError("getInfLocator: Unknown argument type.")         raise TypeError("getInfLocator: Unknown argument type.")
473      a_inf=util.sup(arg)      a_inf=util.sup(arg)
474      loc=util.length(arg-a_inf).minGlobalDataPoint() # This gives us the location but not coords      loc=util.length(arg-a_inf).minGlobalDataPoint() # This gives us the location but not coords
# Line 1894  def MaskFromBoundaryTag(domain,*tags): Line 1896  def MaskFromBoundaryTag(domain,*tags):
1896     :rtype: `escript.Data` of rank 0     :rtype: `escript.Data` of rank 0
1897     """     """
1898     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)
1899     d=escript.Scalar(0.,escript.FunctionOnBoundary(domain))     d=escore.Scalar(0.,escore.FunctionOnBoundary(domain))
1900     for t in tags: d.setTaggedValue(t,1.)     for t in tags: d.setTaggedValue(t,1.)
1901     pde.setValue(y=d)     pde.setValue(y=d)
1902     return util.whereNonZero(pde.getRightHandSide())     return util.whereNonZero(pde.getRightHandSide())
# Line 1915  def MaskFromTag(domain,*tags): Line 1917  def MaskFromTag(domain,*tags):
1917     :rtype: `escript.Data` of rank 0     :rtype: `escript.Data` of rank 0
1918     """     """
1919     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)
1920     d=escript.Scalar(0.,escript.Function(domain))     d=escore.Scalar(0.,escore.Function(domain))
1921     for t in tags: d.setTaggedValue(t,1.)     for t in tags: d.setTaggedValue(t,1.)
1922     pde.setValue(Y=d)     pde.setValue(Y=d)
1923     return util.whereNonZero(pde.getRightHandSide())     return util.whereNonZero(pde.getRightHandSide())

Legend:
Removed from v.3981  
changed lines
  Added in v.3995

  ViewVC Help
Powered by ViewVC 1.1.26