Changeset 2726 for trunk

Show
Ignore:
Timestamp:
08/21/2008 12:35:40 PM (5 months ago)
Author:
wd15
Message:

added a sign method to Variable and numerix in order for the ImplicitSourceTerm? to correctly calculate when the coefficient value changes sign during a simulation

Location:
trunk/fipy
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/fipy/terms/implicitSourceTerm.py

    r2228 r2726  
    5858    """ 
    5959    def _calcCoeffVectors(self, var, equation=None): 
     60        """ 
     61        Test for a bug due to the sign operator not being updating 
     62        correctly. 
     63 
     64            >>> from fipy import * 
     65            >>> m = Grid1D(nx=1) 
     66            >>> v = CellVariable(mesh=m, value=1.) 
     67            >>> eq = TransientTerm() == ImplicitSourceTerm(v) 
     68            >>> eq.solve(v) 
     69            >>> print v 
     70            [ 2.] 
     71            >>> v.setValue(-1.) 
     72            >>> eq.solve(v) 
     73            >>> print v 
     74            [-0.5] 
     75             
     76        """ 
     77 
    6078        coeff = self._getGeomCoeff(var.getMesh()) 
    6179        from fipy.tools.numerix import sign 
     
    6785            'new value': numerix.zeros(var.getMesh().getNumberOfCells(), 'd') 
    6886        } 
     87 
     88def _test():  
     89    import doctest 
     90    return doctest.testmod() 
     91     
     92if __name__ == "__main__":  
     93    _test()  
  • trunk/fipy/terms/test.py

    r2443 r2726  
    5757            'equation', 
    5858            'upwindConvectionTerm', 
    59             'collectedDiffusionTerm' 
     59            'collectedDiffusionTerm', 
     60            'implicitSourceTerm' 
    6061        ), base = __name__) 
    6162 
  • trunk/fipy/tools/numerix.py

    r2590 r2726  
    834834        return umath.ceil(arr) 
    835835 
     836 
     837def sign(arr): 
     838    if _isPhysical(arr): 
     839        return arr.sign() 
     840    elif type(arr) is type(array((0))): 
     841        return NUMERIX.sign(arr) 
     842    else: 
     843        return umath.sign(arr) 
     844 
    836845def exp(arr): 
    837846    r""" 
  • trunk/fipy/variables/variable.py

    r2581 r2726  
    11941194    def ceil(self): 
    11951195        return self._UnaryOperatorVariable(lambda a: numerix.ceil(a)) 
     1196 
     1197    def sign(self): 
     1198        return self._UnaryOperatorVariable(lambda a: numerix.sign(a), canInline=False) 
    11961199         
    11971200    def conjugate(self):