/[escript]/trunk/escript/py_src/linearPDEs.py
ViewVC logotype

Diff of /trunk/escript/py_src/linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2479 by gross, Thu Jun 18 06:50:37 2009 UTC revision 2549 by jfenwick, Mon Jul 20 06:43:47 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 11  Line 11 
11  #  #
12  ########################################################  ########################################################
13    
14  __copyright__="""Copyright (c) 2003-2008 by University of Queensland  __copyright__="""Copyright (c) 2003-2009 by University of Queensland
15  Earth Systems Science Computational Center (ESSCC)  Earth Systems Science Computational Center (ESSCC)
16  http://www.uq.edu.au/esscc  http://www.uq.edu.au/esscc
17  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
# Line 94  class SolverOptions(object): Line 94  class SolverOptions(object):
94      @cvar YAIR_SHAPIRA_COARSENING: AMG coarsening method by Yair-Shapira      @cvar YAIR_SHAPIRA_COARSENING: AMG coarsening method by Yair-Shapira
95      @cvar RUGE_STUEBEN_COARSENING: AMG coarsening method by Ruge and Stueben      @cvar RUGE_STUEBEN_COARSENING: AMG coarsening method by Ruge and Stueben
96      @cvar AGGREGATION_COARSENING: AMG coarsening using (symmetric) aggregation      @cvar AGGREGATION_COARSENING: AMG coarsening using (symmetric) aggregation
97        @cvar MIN_COARSE_MATRIX_SIZE: minimum size of the coarsest level matrix to use direct solver.
98      @cvar NO_PRECONDITIONER: no preconditioner is applied.      @cvar NO_PRECONDITIONER: no preconditioner is applied.
99      """      """
100      DEFAULT= 0      DEFAULT= 0
# Line 132  class SolverOptions(object): Line 133  class SolverOptions(object):
133      RUGE_STUEBEN_COARSENING=34      RUGE_STUEBEN_COARSENING=34
134      AGGREGATION_COARSENING=35      AGGREGATION_COARSENING=35
135      NO_PRECONDITIONER=36      NO_PRECONDITIONER=36
136        MIN_COARSE_MATRIX_SIZE=37
137        
138      def __init__(self):      def __init__(self):
139          self.setLevelMax()          self.setLevelMax()
140          self.setCoarseningThreshold()          self.setCoarseningThreshold()
# Line 156  class SolverOptions(object): Line 159  class SolverOptions(object):
159          self.setSolverMethod()          self.setSolverMethod()
160          self.setPreconditioner()          self.setPreconditioner()
161          self.setCoarsening()          self.setCoarsening()
162            self.setMinCoarseMatrixSize()
163          self.setRelaxationFactor()                  self.setRelaxationFactor()        
164          self.resetDiagnostics(all=True)          self.resetDiagnostics(all=True)
165    
# Line 189  class SolverOptions(object): Line 193  class SolverOptions(object):
193              if self.getPreconditioner() == self.AMG:              if self.getPreconditioner() == self.AMG:
194                  out+="\nMaximum number of levels = %s"%self.LevelMax()                  out+="\nMaximum number of levels = %s"%self.LevelMax()
195                  out+="\nCoarsening method = %s"%self.getName(self.getCoarsening())                  out+="\nCoarsening method = %s"%self.getName(self.getCoarsening())
196                  out+="\nCoarsening threshold = %e"%self.getCoarseningThreshold()                  out+="\nCoarsening threshold = %e"%self.getMinCoarseMatrixSize()
197                    out+="\nMinimum size of the coarsest level matrix = %e"%self.getCoarseningThreshold()
198                  out+="\nNumber of pre / post sweeps = %s / %s, %s"%(self.getNumPreSweeps(), self.getNumPostSweeps(), self.getNumSweeps())                  out+="\nNumber of pre / post sweeps = %s / %s, %s"%(self.getNumPreSweeps(), self.getNumPostSweeps(), self.getNumSweeps())
199              if self.getPreconditioner() == self.GAUSS_SEIDEL:              if self.getPreconditioner() == self.GAUSS_SEIDEL:
200                  out+="\nNumber of sweeps = %s"%self.getNumSweeps()                  out+="\nNumber of sweeps = %s"%self.getNumSweeps()
# Line 242  class SolverOptions(object): Line 247  class SolverOptions(object):
247          if key == self.RUGE_STUEBEN_COARSENING: return "RUGE_STUEBEN_COARSENING"          if key == self.RUGE_STUEBEN_COARSENING: return "RUGE_STUEBEN_COARSENING"
248          if key == self.AGGREGATION_COARSENING: return "AGGREGATION_COARSENING"          if key == self.AGGREGATION_COARSENING: return "AGGREGATION_COARSENING"
249          if key == self.NO_PRECONDITIONER: return "NO_PRECONDITIONER"          if key == self.NO_PRECONDITIONER: return "NO_PRECONDITIONER"
250            if key == self.MIN_COARSE_MATRIX_SIZE: return "MIN_COARSE_MATRIX_SIZE"
251                    
252      def resetDiagnostics(self,all=False):      def resetDiagnostics(self,all=False):
253          """          """
# Line 341  class SolverOptions(object): Line 347  class SolverOptions(object):
347          if not method in [self.DEFAULT, self.YAIR_SHAPIRA_COARSENING, self.RUGE_STUEBEN_COARSENING, self.AGGREGATION_COARSENING]:          if not method in [self.DEFAULT, self.YAIR_SHAPIRA_COARSENING, self.RUGE_STUEBEN_COARSENING, self.AGGREGATION_COARSENING]:
348               raise ValueError,"unknown coarsening method %s"%method               raise ValueError,"unknown coarsening method %s"%method
349          self.__coarsening=method          self.__coarsening=method
350        
351      def getCoarsening(self):      def getCoarsening(self):
352          """          """
353          Returns the key of the coarsening algorithm to be applied AMG.          Returns the key of the coarsening algorithm to be applied AMG.
# Line 349  class SolverOptions(object): Line 356  class SolverOptions(object):
356          L{SolverOptions.RUGE_STUEBEN_COARSENING}, L{SolverOptions.AGGREGATION_COARSENING}          L{SolverOptions.RUGE_STUEBEN_COARSENING}, L{SolverOptions.AGGREGATION_COARSENING}
357          """          """
358          return self.__coarsening          return self.__coarsening
359          
360        def setMinCoarseMatrixSize(self,size=500):
361            """
362            Sets the minumum size of the coarsest level matrix in AMG.
363    
364            @param size: minumum size of the coarsest level matrix .
365            @type size: positive C{int} or C{None}
366            """
367            size=int(size)
368            if size<0:
369               raise ValueError,"minumum size of the coarsest level matrix must be non-negative."
370        if size==None: size=500
371            self.__MinCoarseMatrixSize=size
372            
373        def getMinCoarseMatrixSize(self):
374            """
375            Returns the minumum size of the coarsest level matrix in AMG.
376    
377            @rtype: C{int}
378            """
379            return self.__MinCoarseMatrixSize
380          
381      def setPreconditioner(self, preconditioner=10):      def setPreconditioner(self, preconditioner=10):
382          """          """
383          Sets the preconditioner to be used.          Sets the preconditioner to be used.
# Line 1331  class LinearProblem(object): Line 1360  class LinearProblem(object):
1360       @rtype: L{Domain<escript.Domain>}       @rtype: L{Domain<escript.Domain>}
1361       """       """
1362       return self.__domain       return self.__domain
1363       def getDomainStatus(self):
1364         """
1365         Return the status indicator of the domain
1366         """
1367         return self.getDomain().getStatus()
1368    
1369       def getSystemStatus(self):
1370         """
1371         Return the domain status used to build the current system
1372         """
1373         return self.__system_status
1374       def setSystemStatus(self,status=None):
1375         """
1376         Sets the system status to C{status} if C{status} is not present the
1377         current status of the domain is used.
1378         """
1379         if status == None:
1380             self.__system_status=self.getDomainStatus()
1381         else:
1382             self.__system_status=status
1383    
1384     def getDim(self):     def getDim(self):
1385       """       """
# Line 1844  class LinearProblem(object): Line 1893  class LinearProblem(object):
1893         """         """
1894         Returns True if the solution is still valid.         Returns True if the solution is still valid.
1895         """         """
1896           if not self.getDomainStatus()==self.getSystemStatus(): self.invalidateSolution()
1897         if self.__solution_rtol>self.getSolverOptions().getTolerance() or \         if self.__solution_rtol>self.getSolverOptions().getTolerance() or \
1898            self.__solution_atol>self.getSolverOptions().getAbsoluteTolerance():            self.__solution_atol>self.getSolverOptions().getAbsoluteTolerance():
1899           self.invalidateSolution()             self.invalidateSolution()  
# Line 1867  class LinearProblem(object): Line 1917  class LinearProblem(object):
1917         """         """
1918         Returns True if the operator is still valid.         Returns True if the operator is still valid.
1919         """         """
1920         if self.getRequiredOperatorType()==self.getOperatorType(): self.invalidateOperator()         if not self.getDomainStatus()==self.getSystemStatus(): self.invalidateOperator()
1921           if not self.getRequiredOperatorType()==self.getOperatorType(): self.invalidateOperator()
1922         return self.__is_operator_valid         return self.__is_operator_valid
1923    
1924     def validRightHandSide(self):     def validRightHandSide(self):
# Line 1880  class LinearProblem(object): Line 1931  class LinearProblem(object):
1931         """         """
1932         Indicates the right hand side has to be rebuilt next time it is used.         Indicates the right hand side has to be rebuilt next time it is used.
1933         """         """
1934         if self.isRightHandSideValid(): self.trace("Right hand side has to be rebuilt.")         self.trace("Right hand side has to be rebuilt.")
1935         self.invalidateSolution()         self.invalidateSolution()
1936         self.__is_RHS_valid=False         self.__is_RHS_valid=False
1937    
# Line 1888  class LinearProblem(object): Line 1939  class LinearProblem(object):
1939         """         """
1940         Returns True if the operator is still valid.         Returns True if the operator is still valid.
1941         """         """
1942           if not self.getDomainStatus()==self.getSystemStatus(): self.invalidateRightHandSide()
1943         return self.__is_RHS_valid         return self.__is_RHS_valid
1944    
1945     def invalidateSystem(self):     def invalidateSystem(self):
# Line 1910  class LinearProblem(object): Line 1962  class LinearProblem(object):
1962         """         """
1963         self.trace("New System has been created.")         self.trace("New System has been created.")
1964         self.__operator_type=None         self.__operator_type=None
1965           self.setSystemStatus()
1966         self.__operator=escript.Operator()         self.__operator=escript.Operator()
1967         self.__righthandside=escript.Data()         self.__righthandside=escript.Data()
1968         self.__solution=escript.Data()         self.__solution=escript.Data()
# Line 2555  class LinearPDE(LinearProblem): Line 2608  class LinearPDE(LinearProblem):
2608                   self.insertConstraint(rhs_only=False)                   self.insertConstraint(rhs_only=False)
2609                   self.trace("New operator has been built.")                   self.trace("New operator has been built.")
2610                   self.validOperator()                   self.validOperator()
2611           self.setSystemStatus()
2612           self.trace("System status is %s."%self.getSystemStatus())
2613         return (self.getCurrentOperator(), self.getCurrentRightHandSide())         return (self.getCurrentOperator(), self.getCurrentRightHandSide())
2614    
2615     def insertConstraint(self, rhs_only=False):     def insertConstraint(self, rhs_only=False):
# Line 3491  class TransportPDE(LinearProblem): Line 3546  class TransportPDE(LinearProblem):
3546            self.trace("New system has been built.")            self.trace("New system has been built.")
3547            self.validOperator()            self.validOperator()
3548            self.validRightHandSide()            self.validRightHandSide()
3549           self.setSystemStatus()
3550           self.trace("System status is %s."%self.getSystemStatus())
3551         return (self.getCurrentOperator(), self.getCurrentRightHandSide())         return (self.getCurrentOperator(), self.getCurrentRightHandSide())
3552    
3553     def setDebug(self, flag):     def setDebug(self, flag):

Legend:
Removed from v.2479  
changed lines
  Added in v.2549

  ViewVC Help
Powered by ViewVC 1.1.26