From ec4156967bfffee8e45eb6a7765026fa7b41aa2d Mon Sep 17 00:00:00 2001 From: "Jonathan E. Guyer" Date: Thu, 20 Nov 2008 22:08:18 +0000 Subject: [PATCH] The SciPy solvers are not presently useful or adequately tested. They fail completely with newer versions of SciPy (ticket:163). Some day (ticket:167) we'll redo them properly. This resolves ticket:163. git-svn-id: svn+ssh://code.matforge.org/fipy/trunk@2831 d80e17d7-ff13-0410-a124-85740d801063 --- fipy/solvers/__init__.py | 11 --- fipy/solvers/scipy/__init__.py | 3 - fipy/solvers/scipy/linearCGSolver.py | 105 ------------------------ fipy/solvers/scipy/linearGMRESSolver.py | 102 ----------------------- fipy/solvers/scipy/linearLUSolver.py | 93 --------------------- fipy/solvers/scipy/scipySolver.py | 54 ------------ fipy/solvers/scipy/test.py | 47 ----------- 7 files changed, 415 deletions(-) delete mode 100644 fipy/solvers/scipy/__init__.py delete mode 100755 fipy/solvers/scipy/linearCGSolver.py delete mode 100755 fipy/solvers/scipy/linearGMRESSolver.py delete mode 100644 fipy/solvers/scipy/linearLUSolver.py delete mode 100644 fipy/solvers/scipy/scipySolver.py delete mode 100755 fipy/solvers/scipy/test.py diff --git a/fipy/solvers/__init__.py b/fipy/solvers/__init__.py index fa5b8a543a..44119fdda2 100644 --- a/fipy/solvers/__init__.py +++ b/fipy/solvers/__init__.py @@ -13,8 +13,6 @@ from fipy.solvers.trilinos import * elif '--Pysparse' in sys.argv[1:]: from fipy.solvers.pysparse import * -elif '--Scipy' in sys.argv[1:]: - from fipy.solvers.scipy import * else: import os # Next, check for an environment variable telling us which solver to use @@ -23,8 +21,6 @@ from fipy.solvers.pysparse import * elif os.environ['FIPY_SOLVERS'].lower() == 'trilinos': from fipy.solvers.trilinos import * - elif os.environ['FIPY_SOLVERS'].lower() == 'scipy': - from fipy.solvers.scipy import * else: raise ImportError, 'Unknown solver package %s' % os.environ['FIPY_SOLVERS'] else: @@ -45,13 +41,6 @@ except: pass - if not foundSolvers: - try: - from fipy.solvers.scipy import * - foundSolvers = True - except: - pass - if not foundSolvers: raise ImportError, "Could not import any solver package. If you are using Trilinos, make sure you have all of the necessary Trilinos packages installed - Epetra, EpetraExt, AztecOO, Amesos, ML, and IFPACK." diff --git a/fipy/solvers/scipy/__init__.py b/fipy/solvers/scipy/__init__.py deleted file mode 100644 index c5022ce777..0000000000 --- a/fipy/solvers/scipy/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from linearCGSolver import LinearCGSolver -from linearGMRESSolver import LinearGMRESSolver -from linearLUSolver import LinearLUSolver diff --git a/fipy/solvers/scipy/linearCGSolver.py b/fipy/solvers/scipy/linearCGSolver.py deleted file mode 100755 index 486e856b70..0000000000 --- a/fipy/solvers/scipy/linearCGSolver.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python - -## -*-Pyth-*- - # ################################################################### - # FiPy - Python-based finite volume PDE solver - # - # FILE: "linearCGSolver.py" - # - # Author: Jonathan Guyer - # Author: Daniel Wheeler - # Author: James Warren - # mail: NIST - # www: http://www.ctcms.nist.gov/fipy/ - # - # ======================================================================== - # This software was developed at the National Institute of Standards - # and Technology by employees of the Federal Government in the course - # of their official duties. Pursuant to title 17 Section 105 of the - # United States Code this software is not subject to copyright - # protection and is in the public domain. FiPy is an experimental - # system. NIST assumes no responsibility whatsoever for its use by - # other parties, and makes no guarantees, expressed or implied, about - # its quality, reliability, or any other characteristic. We would - # appreciate acknowledgement if the software is used. - # - # This software can be redistributed and/or modified freely - # provided that any derivative works bear some notice that they are - # derived from it, and any modified versions bear some notice that - # they have been modified. - # ======================================================================== - # - # ################################################################### - ## - -__docformat__ = 'restructuredtext' - -import sys - -from fipy.solvers.scipy.scipySolver import ScipySolver - -class LinearCGSolver(ScipySolver): - """ - - The `LinearCGSolver` solves a linear system of equations - using the conjugent gradient. It solves a system with a symmetric - coefficient matrix. - - The `LinearCGSolver` is a wrapper class for the the Scipy_ - `scipy.linalg.iterative.cg()` method. - - .. warning:: - - Currently the solvers that use Scipy_ are only useful for - small systems due to the whole sparse matrix having to be - turned into an array of size N * N. - - .. _Scipy: http://www.scipy.org - - - """ - - def _solve(self, L, x, b): - """ - - Tridiagonal test case, - - >>> N = 10 - >>> L = 1. - >>> dx = L / N - >>> from fipy.tools import numerix - >>> a = numerix.zeros(N, 'd') - >>> a[:] = 2 / dx - >>> a[0] = 3 / dx - >>> a[-1] = 3 / dx - >>> solver = LinearCGSolver() - >>> SparseMatrix = solver._getMatrixClass() - >>> A = SparseMatrix(size = N) - >>> A.addAtDiagonal(a) - >>> ids = numerix.arange(N - 1) - >>> A.addAt(-numerix.ones(N - 1, 'd') / dx, ids, ids + 1) - >>> A.addAt(-numerix.ones(N - 1, 'd') / dx, ids + 1, ids) - >>> b = numerix.zeros(N, 'd') - >>> b[-1] = 2 / dx - >>> x = numerix.zeros(N, 'd') - >>> solver._solve(A, x, b) - >>> numerix.allclose(x, numerix.arange(N) * dx + dx / 2.) - 1 - - """ - from scipy.linalg.iterative import cg - x[:], info = cg(L,b, x0 = x.copy(), tol = self.tolerance, maxiter = self.iterations) - - if (info != 0): - print >> sys.stderr, 'cg not converged' - - def _canSolveAssymetric(self): - return False - - -def _test(): - import doctest - return doctest.testmod() - -if __name__ == "__main__": - _test() diff --git a/fipy/solvers/scipy/linearGMRESSolver.py b/fipy/solvers/scipy/linearGMRESSolver.py deleted file mode 100755 index 4f9c0a3c95..0000000000 --- a/fipy/solvers/scipy/linearGMRESSolver.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python - -## -*-Pyth-*- - # ################################################################### - # FiPy - Python-based finite volume PDE solver - # - # FILE: "linearGMRESSolver.py" - # - # Author: Jonathan Guyer - # Author: Daniel Wheeler - # Author: James Warren - # mail: NIST - # www: http://www.ctcms.nist.gov/fipy/ - # - # ======================================================================== - # This software was developed at the National Institute of Standards - # and Technology by employees of the Federal Government in the course - # of their official duties. Pursuant to title 17 Section 105 of the - # United States Code this software is not subject to copyright - # protection and is in the public domain. FiPy is an experimental - # system. NIST assumes no responsibility whatsoever for its use by - # other parties, and makes no guarantees, expressed or implied, about - # its quality, reliability, or any other characteristic. We would - # appreciate acknowledgement if the software is used. - # - # This software can be redistributed and/or modified freely - # provided that any derivative works bear some notice that they are - # derived from it, and any modified versions bear some notice that - # they have been modified. - # ======================================================================== - # - # ################################################################### - ## - -__docformat__ = 'restructuredtext' - -import sys - -from fipy.solvers.scipy.scipySolver import ScipySolver - -class LinearGMRESSolver(ScipySolver): - """ - - The `LinearGMRESSolver` solves a linear system of equations - using the generalised minimal residual method (GMRES) with no - GMRES solves systems with a general non-symmetric coefficient - matrix. - - The `LinearGMRESSolver` is a wrapper class for the the - Scipy_ `linalg.iterative.gmres()` method. - - .. warning:: - - Currently the solvers that use Scipy_ are only useful for - small systems due to the whole sparse matrix having to be - turned into an array of size N * N. - - .. _Scipy: http://www.scipy.org - - - """ - - def _solve(self, L, x, b): - """ - - Tridiagonal test case, - - >>> N = 10 - >>> L = 1. - >>> dx = L / N - >>> from fipy.tools import numerix - >>> a = numerix.zeros(N, 'd') - >>> a[:] = 2 / dx - >>> a[0] = 3 / dx - >>> a[-1] = 3 / dx - >>> solver = LinearGMRESSolver() - >>> SparseMatrix = solver._getMatrixClass() - >>> A = SparseMatrix(size = N) - >>> A.addAtDiagonal(a) - >>> ids = numerix.arange(N - 1) - >>> A.addAt(-numerix.ones(N - 1, 'd') / dx, ids, ids + 1) - >>> A.addAt(-numerix.ones(N - 1, 'd') / dx, ids + 1, ids) - >>> b = numerix.zeros(N, 'd') - >>> b[-1] = 2 / dx - >>> x = numerix.zeros(N, 'd') - >>> solver._solve(A, x, b) - >>> numerix.allclose(x, numerix.arange(N) * dx + dx / 2.) - 1 - - """ - from scipy.linalg.iterative import gmres - x[:], info = gmres(L,b, x0 = x.copy(), tol = self.tolerance, maxiter = self.iterations) - - if (info != 0): - print >> sys.stderr, 'gmres not converged' - -def _test(): - import doctest - return doctest.testmod() - -if __name__ == "__main__": - _test() diff --git a/fipy/solvers/scipy/linearLUSolver.py b/fipy/solvers/scipy/linearLUSolver.py deleted file mode 100644 index 043f582227..0000000000 --- a/fipy/solvers/scipy/linearLUSolver.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python - -## -*-Pyth-*- - # ################################################################### - # FiPy - Python-based finite volume PDE solver - # - # FILE: "linearLUSolver.py" - # - # Author: Jonathan Guyer - # Author: Daniel Wheeler - # Author: James Warren - # mail: NIST - # www: http://www.ctcms.nist.gov/fipy/ - # - # ======================================================================== - # This software was developed at the National Institute of Standards - # and Technology by employees of the Federal Government in the course - # of their official duties. Pursuant to title 17 Section 105 of the - # United States Code this software is not subject to copyright - # protection and is in the public domain. FiPy is an experimental - # system. NIST assumes no responsibility whatsoever for its use by - # other parties, and makes no guarantees, expressed or implied, about - # its quality, reliability, or any other characteristic. We would - # appreciate acknowledgement if the software is used. - # - # This software can be redistributed and/or modified freely - # provided that any derivative works bear some notice that they are - # derived from it, and any modified versions bear some notice that - # they have been modified. - # ======================================================================== - # - # ################################################################### - ## - -__docformat__ = 'restructuredtext' - -from fipy.tools import numerix - -from fipy.solvers.scipy.scipySolver import ScipySolver - -class LinearLUSolver(ScipySolver): - """ - - The `LinearLUSolver` solves a linear system of equations - using LU-factorisation. This method solves systems of general - non-symmetric matrices with partial pivoting. - - The `LinearLUSolver` is a wrapper class for the the SciPy_ - `scipy.linalg.lu_solve()` method. - - .. warning:: - - Currently the solvers that use Scipy_ are only useful for - small systems due to the whole sparse matrix having to be - turned into an array of size N * N. - - .. _SciPy: http://www.scipy.org - - """ - - def __init__(self, tolerance=1e-10, iterations=10, steps=None, precon=None): - """ - Creates a `LinearScipyLUSolver`. - - :Parameters: - - `tolerance`: The required error tolerance. - - `iterations`: The number of LU decompositions to perform. - - `steps`: A deprecated name for `iterations`. - For large systems a number of iterations is generally required. - - """ - ScipySolver.__init__(self, tolerance=tolerance, iterations=iterations, steps=steps, precon=precon) - - def _solve(self, L, x, b): - from scipy.linalg import lu_factor, lu_solve - -## x[:] = scipy.linalg.solve(numerix.array(L), b) - LU = lu_factor(numerix.array(L)) - x[:] = lu_solve(LU, b) - tol = self.tolerance + 1. - - for iteration in range(self.iterations): - if tol <= self.tolerance: - break - - errorVector = L * x - b - LU = lu_factor(numerix.array(L)) - xError = lu_solve(LU, errorVector) - x[:] = x - xError - - tol = max(numerix.absolute(xError)) - - print tol diff --git a/fipy/solvers/scipy/scipySolver.py b/fipy/solvers/scipy/scipySolver.py deleted file mode 100644 index d7f2629289..0000000000 --- a/fipy/solvers/scipy/scipySolver.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python - -## - # -*-Pyth-*- - # ################################################################### - # FiPy - Python-based finite volume PDE solver - # - # FILE: "scipySolver.py" - # - # Author: Jonathan Guyer - # Author: Daniel Wheeler - # Author: James Warren - # mail: NIST - # www: http://www.ctcms.nist.gov/fipy/ - # - # ======================================================================== - # This software was developed at the National Institute of Standards - # and Technology by employees of the Federal Government in the course - # of their official duties. Pursuant to title 17 Section 105 of the - # United States Code this software is not subject to copyright - # protection and is in the public domain. FiPy is an experimental - # system. NIST assumes no responsibility whatsoever for its use by - # other parties, and makes no guarantees, expressed or implied, about - # its quality, reliability, or any other characteristic. We would - # appreciate acknowledgement if the software is used. - # - # This software can be redistributed and/or modified freely - # provided that any derivative works bear some notice that they are - # derived from it, and any modified versions bear some notice that - # they have been modified. - # ======================================================================== - # - # ################################################################### - ## - -__docformat__ = 'restructuredtext' - -from fipy.tools.pysparseMatrix import _PysparseMatrix -from fipy.solvers.solver import Solver - -class ScipySolver(Solver): - """ - The base `ScipySolver` class. - - .. attention:: This class is abstract. Always create one of its subclasses. - """ - def __init__(self, *args, **kwargs): - if self.__class__ is ScipySolver: - raise NotImplementedError, "can't instantiate abstract base class" - - Solver.__init__(self, *args, **kwargs) - - def _getMatrixClass(self): - return _PysparseMatrix diff --git a/fipy/solvers/scipy/test.py b/fipy/solvers/scipy/test.py deleted file mode 100755 index f7d383c7c3..0000000000 --- a/fipy/solvers/scipy/test.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python - -## - # ################################################################### - # FiPy - Python-based finite volume PDE solver - # - # FILE: "test.py" - # - # Author: Jonathan Guyer - # Author: Daniel Wheeler - # Author: James Warren - # mail: NIST - # www: http://www.ctcms.nist.gov/fipy/ - # - # ======================================================================== - # This software was developed at the National Institute of Standards - # and Technology by employees of the Federal Government in the course - # of their official duties. Pursuant to title 17 Section 105 of the - # United States Code this software is not subject to copyright - # protection and is in the public domain. FiPy is an experimental - # system. NIST assumes no responsibility whatsoever for its use by - # other parties, and makes no guarantees, expressed or implied, about - # its quality, reliability, or any other characteristic. We would - # appreciate acknowledgement if the software is used. - # - # This software can be redistributed and/or modified freely - # provided that any derivative works bear some notice that they are - # derived from it, and any modified versions bear some notice that - # they have been modified. - # ======================================================================== - # - # ################################################################### - ## - -from fipy.tests.doctestPlus import _LateImportDocTestSuite -import fipy.tests.testProgram - -def _suite(): - theSuite = _LateImportDocTestSuite(docTestModuleNames = ( - 'linearGMRESSolver', - 'linearCGSolver', - ), base = __name__) - - return theSuite - -if __name__ == '__main__': - fipy.tests.testProgram.main(defaultTest='_suite')