/[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 1858 by gross, Fri Oct 3 03:57:52 2008 UTC revision 1859 by gross, Wed Oct 8 03:03:37 2008 UTC
# Line 535  class LinearProblem(object): Line 535  class LinearProblem(object):
535       @raise UndefinedPDEError: if the number of equations is not be specified yet.       @raise UndefinedPDEError: if the number of equations is not be specified yet.
536       """       """
537       if self.__numEquations==None:       if self.__numEquations==None:
538           raise UndefinedPDEError,"Number of equations is undefined. Please specify argument numEquations."           if self.__numSolutions==None:
539       else:              raise UndefinedPDEError,"Number of equations is undefined. Please specify argument numEquations."
540           return self.__numEquations           else:
541                self.__numEquations=self.__numSolutions
542         return self.__numEquations
543    
544     def getNumSolutions(self):     def getNumSolutions(self):
545       """       """
# Line 548  class LinearProblem(object): Line 550  class LinearProblem(object):
550       @raise UndefinedPDEError: if the number of unknowns is not be specified yet.       @raise UndefinedPDEError: if the number of unknowns is not be specified yet.
551       """       """
552       if self.__numSolutions==None:       if self.__numSolutions==None:
553          raise UndefinedPDEError,"Number of solution is undefined. Please specify argument numSolutions."          if self.__numEquations==None:
554       else:              raise UndefinedPDEError,"Number of solution is undefined. Please specify argument numSolutions."
555          return self.__numSolutions          else:
556                self.__numSolutions=self.__numEquations
557         return self.__numSolutions
558    
559     def reduceEquationOrder(self):     def reduceEquationOrder(self):
560       """       """
# Line 1540  class LinearPDE(LinearProblem): Line 1544  class LinearPDE(LinearProblem):
1544        """        """
1545        returns the system type which needs to be used by the current set up.        returns the system type which needs to be used by the current set up.
1546        """        """
1547        return self.getDomain().getSystemMatrixTypeId(self.getSolverMethod()[0],self.getSolverPackage(),self.isSymmetric())        return self.getDomain().getSystemMatrixTypeId(self.getSolverMethod()[0],self.getSolverMethod()[1],self.getSolverPackage(),self.isSymmetric())
1548    
1549     def checkSymmetry(self,verbose=True):     def checkSymmetry(self,verbose=True):
1550        """        """
# Line 2269  class TransportPDE(LinearProblem): Line 2273  class TransportPDE(LinearProblem):
2273            u=p.solve(dt)            u=p.solve(dt)
2274    
2275     """     """
2276     def __init__(self,domain,num_equations=None,numSolutions=None, theta=0.5,debug=False):     def __init__(self,domain,numEquations=None,numSolutions=None, theta=0.5,debug=False):
2277       """       """
2278       initializes a linear problem       initializes a linear problem
2279    
# Line 2284  class TransportPDE(LinearProblem): Line 2288  class TransportPDE(LinearProblem):
2288    
2289       """       """
2290       if theta<0 or theta>1:       if theta<0 or theta>1:
2291                raise ValueError,"theta (=%s) needs to be between 0 and 1 (inclusive)."                raise ValueError,"theta (=%s) needs to be between 0 and 1 (inclusive)."%theta
2292       super(TransportPDE, self).__init__(domain,num_equations,numSolutions,debug)       super(TransportPDE, self).__init__(domain,numEquations,numSolutions,debug)
2293    
2294       self.__theta=theta       self.__theta=theta
2295       #       #
# Line 2334  class TransportPDE(LinearProblem): Line 2338  class TransportPDE(LinearProblem):
2338        @rtype: float        @rtype: float
2339        """        """
2340        return self.__theta        return self.__theta
2341     def getRequiredSystemType(self):  
       """  
       returns the system type which needs to be used by the current set up.  
       """  
       return 0  
       return self.getDomain().getTransportMatrixTypeId(self.getSolverMethod()[0],self.getSolverMethod()[1],self.getSolverPackage(),self.isSymmetric())  
2342    
2343     def checkSymmetry(self,verbose=True):     def checkSymmetry(self,verbose=True):
2344        """        """
# Line 2429  class TransportPDE(LinearProblem): Line 2428  class TransportPDE(LinearProblem):
2428        """        """
2429        super(TransportPDE,self).setValue(**coefficients)        super(TransportPDE,self).setValue(**coefficients)
2430    
2431    
2432     def createOperator(self):     def createOperator(self):
2433         """         """
2434         returns an instance of a new transport operator         returns an instance of a new transport operator
# Line 2440  class TransportPDE(LinearProblem): Line 2440  class TransportPDE(LinearProblem):
2440                                 self.getFunctionSpaceForSolution(), \                                 self.getFunctionSpaceForSolution(), \
2441                                 self.getSystemType())                                 self.getSystemType())
2442    
2443       def setInitialSolution(self,u):
2444           """
2445           sets the initial solution
2446        
2447           @param u: new initial solution
2448           @type u: any object that can ne interpolated to a L{Data<escript.Data>} object on on L{Solution<escript.Solution>} or L{ReducedSolution<escript.ReducedSolution>}.
2449           @note: C{u} must be non negative.
2450           """
2451           u2=util.interpolate(u,self.getFunctionSpaceForSolution())
2452           if self.getNumSolutions() == 1:
2453              if u2.getShape()!=():
2454                  raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)
2455           else:
2456              if u2.getShape()!=(self.getNumSolutions(),):
2457                  raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)
2458           self.getOperator().setInitialValue(u2)
2459       def getRequiredSystemType(self):
2460          """
2461          returns the system type which needs to be used by the current set up.
2462    
2463          @return: a code to indicate the type of transport problem scheme used.
2464          @rtype: C{float}
2465          """
2466          return self.getDomain().getTransportTypeId(self.getSolverMethod()[0],self.getSolverMethod()[1],self.getSolverPackage(),self.isSymmetric())
2467    
2468       def getUnlimitedTimeStepSize(self):
2469          """
2470          returns the value returned by the C{getSafeTimeStepSize} method to indicate no limit on the save time step size.
2471    
2472           @return: the value used to indicate that no limit is set to the time step size
2473           @rtype: C{float}
2474           @note: Typically the biggest positive float is returned.
2475          """
2476          return self.getOperator().getUnlimitedTimeStepSize()
2477    
2478       def getSafeTimeStepSize(self):
2479           """
2480           returns a safe time step size to do the next time step.
2481    
2482           @return: safe time step size
2483           @rtype: C{float}
2484           @note: If not C{getSafeTimeStepSize()} < C{getUnlimitedTimeStepSize()} any time step size can be used.
2485           """
2486           return self.getOperator().getSafeTimeStepSize()
2487       #====================================================================
2488     def getSolution(self,dt,**options):     def getSolution(self,dt,**options):
2489         """         """
2490         returns the solution of the problem         returns the solution of the problem
# Line 2448  class TransportPDE(LinearProblem): Line 2493  class TransportPDE(LinearProblem):
2493    
2494         @note: This method is overwritten when implementing a particular linear problem.         @note: This method is overwritten when implementing a particular linear problem.
2495         """         """
2496         if not self.isSolutionValid():         if dt<=0:
2497             options[self.TOLERANCE_KEY]=self.getTolerance()             raise ValueError,"step size needs to be positive."
2498             self.setSolution(self.getOperator().solve(self.getRightHandSide(),dt,options))         options[self.TOLERANCE_KEY]=self.getTolerance()
2499             self.validSolution()         self.setSolution(self.getOperator().solve(self.getRightHandSide(),dt,options))
2500           self.validSolution()
2501         return self.getCurrentSolution()         return self.getCurrentSolution()
    def setInitialSolution(self,u):  
        self.getOperator().setInitialValue(util.interpolate(u,self.getFunctionSpaceForSolution()))  
    def getSafeTimeStepSize(self):  
        return self.getOperator().getSafeTimeStepSize()  
2502    
2503     def getSystem(self):     def getSystem(self):
2504         """         """
# Line 2486  class TransportPDE(LinearProblem): Line 2528  class TransportPDE(LinearProblem):
2528                              self.getCoefficient("y"),                              self.getCoefficient("y"),
2529                              self.getCoefficient("d_contact"),                              self.getCoefficient("d_contact"),
2530                              self.getCoefficient("y_contact"))                              self.getCoefficient("y_contact"))
2531              self.getDomain().addPDEToTransportProblem(
2532                                operator,
2533                                righthandside,
2534                                self.getCoefficient("M_reduced"),
2535                                self.getCoefficient("A_reduced"),
2536                                self.getCoefficient("B_reduced"),
2537                                self.getCoefficient("C_reduced"),
2538                                self.getCoefficient("D_reduced"),
2539                                self.getCoefficient("X_reduced"),
2540                                self.getCoefficient("Y_reduced"),
2541                                self.getCoefficient("d_reduced"),
2542                                self.getCoefficient("y_reduced"),
2543                                self.getCoefficient("d_contact_reduced"),
2544                                self.getCoefficient("y_contact_reduced"))
2545            operator.insertConstraint(righthandside,self.getCoefficient("q"),self.getCoefficient("r"))            operator.insertConstraint(righthandside,self.getCoefficient("q"),self.getCoefficient("r"))
2546            self.trace("New system has been built.")            self.trace("New system has been built.")
2547            self.validOperator()            self.validOperator()

Legend:
Removed from v.1858  
changed lines
  Added in v.1859

  ViewVC Help
Powered by ViewVC 1.1.26