/[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 1878 by gross, Tue Oct 14 03:39:13 2008 UTC revision 1956 by gross, Mon Nov 3 05:08:42 2008 UTC
# Line 1257  class ArithmeticTuple(object): Line 1257  class ArithmeticTuple(object):
1257         @rtype: L{ArithmeticTuple}         @rtype: L{ArithmeticTuple}
1258         """         """
1259         out=[]         out=[]
1260         other=1.*other         try:  
1261         if isinstance(other,float):             l=len(other)
1262      for i in range(len(self)):             if l!=len(self):
1263             out.append(self[i]*other)                 raise ValueError,"length of of arguments don't match."
1264         else:             for i in range(l): out.append(self[i]*other[i])
1265          for i in range(len(self)):         except TypeError:
1266             out.append(self[i]*other[i])         for i in range(len(self)): out.append(self[i]*other)
1267         return ArithmeticTuple(*tuple(out))         return ArithmeticTuple(*tuple(out))
1268    
1269     def __rmul__(self,other):     def __rmul__(self,other):
# Line 1276  class ArithmeticTuple(object): Line 1276  class ArithmeticTuple(object):
1276         @rtype: L{ArithmeticTuple}         @rtype: L{ArithmeticTuple}
1277         """         """
1278         out=[]         out=[]
1279         other=1.*other         try:  
1280         if isinstance(other,float):             l=len(other)
1281      for i in range(len(self)):             if l!=len(self):
1282             out.append(other*self[i])                 raise ValueError,"length of of arguments don't match."
1283         else:             for i in range(l): out.append(other[i]*self[i])
1284          for i in range(len(self)):         except TypeError:
1285             out.append(other[i]*self[i])         for i in range(len(self)): out.append(other*self[i])
1286         return ArithmeticTuple(*tuple(out))         return ArithmeticTuple(*tuple(out))
1287    
 #########################  
 # Added by Artak  
 #########################  
1288     def __div__(self,other):     def __div__(self,other):
1289         """         """
1290         dividing from the right         dividing from the right
# Line 1297  class ArithmeticTuple(object): Line 1294  class ArithmeticTuple(object):
1294         @return: itemwise self/other         @return: itemwise self/other
1295         @rtype: L{ArithmeticTuple}         @rtype: L{ArithmeticTuple}
1296         """         """
1297         out=[]         return self*(1/other)
        other=1.*other  
        if isinstance(other,float):  
     for i in range(len(self)):  
            out.append(self[i]*(1./other))  
        else:  
         for i in range(len(self)):  
            out.append(self[i]*(1./other[i]))  
        return ArithmeticTuple(*tuple(out))  
1298    
1299     def __rdiv__(self,other):     def __rdiv__(self,other):
1300         """         """
# Line 1317  class ArithmeticTuple(object): Line 1306  class ArithmeticTuple(object):
1306         @rtype: L{ArithmeticTuple}         @rtype: L{ArithmeticTuple}
1307         """         """
1308         out=[]         out=[]
1309         other=1.*other         try:  
1310         if isinstance(other,float):             l=len(other)
1311          for i in range(len(self)):             if l!=len(self):
1312             out.append(other*(1./self[i]))                 raise ValueError,"length of of arguments don't match."
1313         else:             for i in range(l): out.append(other[i]/self[i])
1314          for i in range(len(self)):         except TypeError:
1315             out.append(other[i]*(1./self[i]))         for i in range(len(self)): out.append(other/self[i])
1316         return ArithmeticTuple(*tuple(out))         return ArithmeticTuple(*tuple(out))
1317        
 ##########################################33  
   
1318     def __iadd__(self,other):     def __iadd__(self,other):
1319         """         """
1320         in-place add of other to self         in-place add of other to self
# Line 1348  class ArithmeticTuple(object): Line 1335  class ArithmeticTuple(object):
1335         @param other: increment         @param other: increment
1336         @type other: C{ArithmeticTuple}         @type other: C{ArithmeticTuple}
1337         """         """
1338  #      if not isinstance(other,float):         out=[]
1339         if len(self) != len(other):         try:  
1340            raise ValueError,"tuple length must match."             l=len(other)
1341         for i in range(len(self)):             if l!=len(self):
1342            self.__items[i]+=other[i]                 raise ValueError,"length of of arguments don't match."
1343  #       else:             for i in range(l): out.append(self[i]+other[i])
1344  #        for i in range(len(self)):         except TypeError:
1345  #           self.__items[i]+=other         for i in range(len(self)): out.append(self[i]+other)
1346           return ArithmeticTuple(*tuple(out))
        return self  
1347    
1348     def __sub__(self,other):     def __sub__(self,other):
1349         """         """
# Line 1366  class ArithmeticTuple(object): Line 1352  class ArithmeticTuple(object):
1352         @param other: increment         @param other: increment
1353         @type other: C{ArithmeticTuple}         @type other: C{ArithmeticTuple}
1354         """         """
1355         if len(self) != len(other):         out=[]
1356             raise ValueError,"tuple length must match."         try:  
1357         for i in range(len(self)):             l=len(other)
1358             self.__items[i]-=other[i]             if l!=len(self):
1359         return self                 raise ValueError,"length of of arguments don't match."
1360               for i in range(l): out.append(self[i]-other[i])
1361           except TypeError:
1362           for i in range(len(self)): out.append(self[i]-other)
1363           return ArithmeticTuple(*tuple(out))
1364        
1365     def __isub__(self,other):     def __isub__(self,other):
1366         """         """
# Line 1390  class ArithmeticTuple(object): Line 1380  class ArithmeticTuple(object):
1380         negate         negate
1381    
1382         """         """
1383           out=[]
1384         for i in range(len(self)):         for i in range(len(self)):
1385             self.__items[i]=-self.__items[i]             out.append(-self[i])
1386         return self         return ArithmeticTuple(*tuple(out))
1387    
1388    
1389  class HomogeneousSaddlePointProblem(object):  class HomogeneousSaddlePointProblem(object):
# Line 1613  class HomogeneousSaddlePointProblem(obje Line 1604  class HomogeneousSaddlePointProblem(obje
1604    
1605  def MaskFromBoundaryTag(domain,*tags):  def MaskFromBoundaryTag(domain,*tags):
1606     """     """
1607     create a mask on the Solution(domain) function space which one for samples     creates a mask on the Solution(domain) function space which one for samples
1608     that touch the boundary tagged by tags.     that touch the boundary tagged by tags.
1609    
1610     usage: m=MaskFromBoundaryTag(domain,"left", "right")     usage: m=MaskFromBoundaryTag(domain,"left", "right")
# Line 1626  def MaskFromBoundaryTag(domain,*tags): Line 1617  def MaskFromBoundaryTag(domain,*tags):
1617     @rtype: L{escript.Data} of rank 0     @rtype: L{escript.Data} of rank 0
1618     """     """
1619     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)     pde=linearPDEs.LinearPDE(domain,numEquations=1, numSolutions=1)
1620     d=escript.Scalar(0.,escript.FunctionOnBoundary(function_space.getDomain()))     d=escript.Scalar(0.,escript.FunctionOnBoundary(domain))
1621     for t in tags: d.setTaggedValue(t,1.)     for t in tags: d.setTaggedValue(t,1.)
1622     pde.setValue(y=d)     pde.setValue(y=d)
1623     return util.whereNonZero(pde.getRightHandSide())     return util.whereNonZero(pde.getRightHandSide())

Legend:
Removed from v.1878  
changed lines
  Added in v.1956

  ViewVC Help
Powered by ViewVC 1.1.26