/[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 3792 by jfenwick, Wed Jan 18 02:30:48 2012 UTC revision 3793 by gross, Wed Feb 1 07:39:43 2012 UTC
# Line 109  class SolverOptions(object): Line 109  class SolverOptions(object):
109      :cvar PASO_FALGOUT_COARSENING: BoomerAMG parallel coarsening method falgout      :cvar PASO_FALGOUT_COARSENING: BoomerAMG parallel coarsening method falgout
110      :cvar PASO_PMIS_COARSENING: BoomerAMG parallel coarsening method PMIS      :cvar PASO_PMIS_COARSENING: BoomerAMG parallel coarsening method PMIS
111      :cvar PASO_HMIS_COARSENING: BoomerAMG parallel coarsening method HMIS      :cvar PASO_HMIS_COARSENING: BoomerAMG parallel coarsening method HMIS
112        :cvar BACKWARD_EULER: backward Euler scheme
113        :cvar CRANK_NICOLSON: Crank-Nicolson scheme
114        :cvar LINEAR_CRANK_NICOLSON: linerized Crank-Nicolson scheme
115    
116      """      """
117      DEFAULT= 0      DEFAULT= 0
# Line 160  class SolverOptions(object): Line 163  class SolverOptions(object):
163      FALGOUT_COARSENING=63      FALGOUT_COARSENING=63
164      PMIS_COARSENING=64      PMIS_COARSENING=64
165      HMIS_COARSENING=65      HMIS_COARSENING=65
166        LINEAR_CRANK_NICOLSON=66
167        CRANK_NICOLSON=67
168        BACKWARD_EULER=68
169    
170      def __init__(self):      def __init__(self):
171          self.setLevelMax()          self.setLevelMax()
# Line 197  class SolverOptions(object): Line 203  class SolverOptions(object):
203          self.setDiagonalDominanceThreshold()          self.setDiagonalDominanceThreshold()
204          self.setAMGInterpolation()          self.setAMGInterpolation()
205      self.setCycleType()      self.setCycleType()
206        self.setODESolver()
207                    
208    
209      def __str__(self):      def __str__(self):
# Line 260  class SolverOptions(object): Line 267  class SolverOptions(object):
267                  out+="\nStorage increase = %e"%self.getDropStorage()                  out+="\nStorage increase = %e"%self.getDropStorage()
268              if self.getPreconditioner() == self.RILU:              if self.getPreconditioner() == self.RILU:
269                  out+="\nRelaxation factor = %e"%self.getRelaxationFactor()                  out+="\nRelaxation factor = %e"%self.getRelaxationFactor()
270                out+="\nODE solver = %s"%self.getName(self.getODESolver())
271          return out          return out
272                    
273      def getName(self,key):      def getName(self,key):
# Line 315  class SolverOptions(object): Line 323  class SolverOptions(object):
323      if key == self.FALGOUT_COARSENING: return "FALGOUT_COARSENING"      if key == self.FALGOUT_COARSENING: return "FALGOUT_COARSENING"
324      if key == self.PMIS_COARSENING: return "PMIS_COARSENING"      if key == self.PMIS_COARSENING: return "PMIS_COARSENING"
325      if key == self.HMIS_COARSENING: return "HMIS_COARSENING"      if key == self.HMIS_COARSENING: return "HMIS_COARSENING"
326                if key == self.LINEAR_CRANK_NICOLSON: return "LINEAR_CRANK_NICOLSON"
327            if key == self.CRANK_NICOLSON: return "CRANK_NICOLSON"
328            if key == self.BACKWARD_EULER: return "BACKWARD_EULER"
329    
330        
331        
332      def resetDiagnostics(self,all=False):      def resetDiagnostics(self,all=False):
333          """          """
334          resets the diagnostics          resets the diagnostics
# Line 1193  class SolverOptions(object): Line 1206  class SolverOptions(object):
1206          :rtype: in the list `SolverOptions.CLASSIC_INTERPOLATION_WITH_FF_COUPLING`, `SolverOptions.CLASSIC_INTERPOLATION', `SolverOptions.DIRECT_INTERPOLATION`          :rtype: in the list `SolverOptions.CLASSIC_INTERPOLATION_WITH_FF_COUPLING`, `SolverOptions.CLASSIC_INTERPOLATION', `SolverOptions.DIRECT_INTERPOLATION`
1207          """          """
1208          return self.__amg_interpolation_method          return self.__amg_interpolation_method
1209        
1210        def setODESolver(self, method=None):
1211            """
1212            Set the solver method for ODEs .
1213    
1214            :param method: key of the ODE solver method to be used.
1215            :type method: in `SolverOptions.CRANK_NICOLSON, `SolverOptions.BACKWARD_EULER', `SolverOptions.LINEAR_CRANK_NICOLSON
1216            """
1217        if method==None: method=self.CRANK_NICOLSON
1218            if not method in [ SolverOptions.CRANK_NICOLSON, SolverOptions.BACKWARD_EULER, SolverOptions.LINEAR_CRANK_NICOLSON ]:
1219                 raise ValueError("unknown ODE solver method %s"%method)
1220            self.__ode_solver=method
1221    
1222        def getODESolver(self, method=None):
1223            """
1224             Returns key of the solver method for ODEs .
1225    
1226            :param method: key of the ODE solver method to be used.
1227            :type method: in `SolverOptions.CRANK_NICOLSON, `SolverOptions.BACKWARD_EULER', `SolverOptions.LINEAR_CRANK_NICOLSON
1228            """
1229            return self.__ode_solver
1230            
1231            
1232  class IllegalCoefficient(ValueError):  class IllegalCoefficient(ValueError):
1233      
1234     """     """
1235     Exception that is raised if an illegal coefficient of the general or     Exception that is raised if an illegal coefficient of the general or
1236     particular PDE is requested.     particular PDE is requested.
# Line 3588  class TransportPDE(LinearProblem): Line 3623  class TransportPDE(LinearProblem):
3623             u = p.solve(dt)             u = p.solve(dt)
3624    
3625     """     """
3626     def __init__(self,domain,numEquations=None,numSolutions=None, useBackwardEuler=False, debug=False):     def __init__(self,domain,numEquations=None,numSolutions=None, useBackwardEuler=None, debug=False):
3627       """       """
3628       Initializes a transport problem.       Initializes a transport problem.
3629    
# Line 3600  class TransportPDE(LinearProblem): Line 3635  class TransportPDE(LinearProblem):
3635                            of solution components is extracted from the                            of solution components is extracted from the
3636                            coefficients.                            coefficients.
3637       :param debug: if True debug information is printed       :param debug: if True debug information is printed
      :param useBackwardEuler: if set the backward Euler scheme is used. Otherwise the Crank-Nicolson scheme is applied. Note that backward Euler scheme will return a safe time step size which is practically infinity as the scheme is unconditional unstable. The Crank-Nicolson scheme provides a higher accuracy but requires to limit the time step size to be stable.  
      :type useBackwardEuler: ``bool``  
3638       """       """
      if useBackwardEuler:  
          self.__useBackwardEuler=True  
      else:  
          self.__useBackwardEuler=False  
3639       super(TransportPDE, self).__init__(domain,numEquations,numSolutions,debug)       super(TransportPDE, self).__init__(domain,numEquations,numSolutions,debug)
3640    
3641       self.setConstraintWeightingFactor()       self.setConstraintWeightingFactor()
# Line 3642  class TransportPDE(LinearProblem): Line 3671  class TransportPDE(LinearProblem):
3671         y_dirac=PDECoef(PDECoef.DIRACDELTA,(PDECoef.BY_EQUATION,),PDECoef.RIGHTHANDSIDE),         y_dirac=PDECoef(PDECoef.DIRACDELTA,(PDECoef.BY_EQUATION,),PDECoef.RIGHTHANDSIDE),
3672         r=PDECoef(PDECoef.SOLUTION,(PDECoef.BY_SOLUTION,),PDECoef.RIGHTHANDSIDE),         r=PDECoef(PDECoef.SOLUTION,(PDECoef.BY_SOLUTION,),PDECoef.RIGHTHANDSIDE),
3673         q=PDECoef(PDECoef.SOLUTION,(PDECoef.BY_SOLUTION,),PDECoef.BOTH) )         q=PDECoef(PDECoef.SOLUTION,(PDECoef.BY_SOLUTION,),PDECoef.BOTH) )
3674         if not useBackwardEuler == None:
3675            import warnings
3676            warnings.warn("Argument useBackwardEuler has expired and will be removed in a later release. Please use SolverOptions.setODESolver() instead.", PendingDeprecationWarning, stacklevel=2)
3677            if useBackwardEuler: self.getSolverOptions().setODESolver(SolverOptions.BACKWARD_EULER)
3678    
3679     def __str__(self):     def __str__(self):
3680       """       """
# Line 3652  class TransportPDE(LinearProblem): Line 3685  class TransportPDE(LinearProblem):
3685       """       """
3686       return "<TransportPDE %d>"%id(self)       return "<TransportPDE %d>"%id(self)
3687    
    def useBackwardEuler(self):  
       """  
       Returns true if backward Euler is used. Otherwise false is returned.  
       :rtype: bool  
       """  
       return self.__useBackwardEuler  
   
   
3688     def checkSymmetry(self,verbose=True):     def checkSymmetry(self,verbose=True):
3689        """        """
3690        Tests the transport problem for symmetry.        Tests the transport problem for symmetry.
# Line 3788  class TransportPDE(LinearProblem): Line 3813  class TransportPDE(LinearProblem):
3813         optype=self.getRequiredOperatorType()         optype=self.getRequiredOperatorType()
3814         self.trace("New Transport problem pf type %s is allocated."%optype)         self.trace("New Transport problem pf type %s is allocated."%optype)
3815         return self.getDomain().newTransportProblem( \         return self.getDomain().newTransportProblem( \
                                self.useBackwardEuler(),  
3816                                 self.getNumEquations(), \                                 self.getNumEquations(), \
3817                                 self.getFunctionSpaceForSolution(), \                                 self.getFunctionSpaceForSolution(), \
3818                                 optype)                                 optype)
# Line 3975  class TransportPDE(LinearProblem): Line 3999  class TransportPDE(LinearProblem):
3999       """       """
4000       super(TransportPDE,self).setDebugOff()       super(TransportPDE,self).setDebugOff()
4001            
4002  def SingleTransportPDE(domain,useBackwardEuler=False, debug=False):  def SingleTransportPDE(domain, debug=False):
4003     """     """
4004     Defines a single transport problem     Defines a single transport problem
4005    
4006     :param domain: domain of the PDE     :param domain: domain of the PDE
4007     :type domain: `Domain`     :type domain: `Domain`
4008     :param debug: if True debug information is printed     :param debug: if True debug information is printed
    :param useBackwardEuler: if set the backward Euler scheme is used. Otherwise the Crank-Nicolson scheme is applied. Note that backward Euler scheme will return a safe time step size which is practically infinity as the scheme is unconditional unstable. The Crank-Nicolson scheme provides a higher accuracy but requires to limit the time step size to be stable.  
4009     :rtype: `TransportPDE`     :rtype: `TransportPDE`
4010     """     """
4011     return TransportPDE(domain,numEquations=1,numSolutions=1, useBackwardEuler=useBackwardEuler, debug=debug)     return TransportPDE(domain,numEquations=1,numSolutions=1, debug=debug)

Legend:
Removed from v.3792  
changed lines
  Added in v.3793

  ViewVC Help
Powered by ViewVC 1.1.26