/[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 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 2987 by gross, Tue Mar 16 01:32:43 2010 UTC
# Line 2053  class LinearProblem(object): Line 2053  class LinearProblem(object):
2053             self.__solution.setToZero()             self.__solution.setToZero()
2054             self.trace("Solution is reset to zero.")             self.trace("Solution is reset to zero.")
2055    
2056     def setSolution(self,u):     def setSolution(self,u, validate=True):
2057         """         """
2058         Sets the solution assuming that makes the system valid with the tolrance         Sets the solution assuming that makes the system valid with the tolrance
2059         defined by the solver options         defined by the solver options
2060         """         """
2061         self.__solution_rtol=self.getSolverOptions().getTolerance()         if validate:
2062         self.__solution_atol=self.getSolverOptions().getAbsoluteTolerance()        self.__solution_rtol=self.getSolverOptions().getTolerance()
2063          self.__solution_atol=self.getSolverOptions().getAbsoluteTolerance()
2064          self.validSolution()
2065         self.__solution=u         self.__solution=u
        self.validSolution()  
   
2066     def getCurrentSolution(self):     def getCurrentSolution(self):
2067         """         """
2068         Returns the solution in its current state.         Returns the solution in its current state.
# Line 3445  class TransportPDE(LinearProblem): Line 3445  class TransportPDE(LinearProblem):
3445         """         """
3446         Returns an instance of a new transport operator.         Returns an instance of a new transport operator.
3447         """         """
        if self.useBackwardEuler():  
          theta=1.  
        else:  
          theta=0.5  
3448         optype=self.getRequiredOperatorType()         optype=self.getRequiredOperatorType()
3449         self.trace("New Transport problem pf type %s is allocated."%optype)         self.trace("New Transport problem pf type %s is allocated."%optype)
3450         return self.getDomain().newTransportProblem( \         return self.getDomain().newTransportProblem( \
3451                                 theta,                                 self.useBackwardEuler(),
3452                                 self.getNumEquations(), \                                 self.getNumEquations(), \
3453                                 self.getFunctionSpaceForSolution(), \                                 self.getFunctionSpaceForSolution(), \
3454                                 optype)                                 optype)
3455    
    def setInitialSolution(self,u):  
        """  
        Sets the initial solution.  
   
        :param u: new initial solution  
        :type u: any object that can be interpolated to a `Data`  
                 object on `Solution` or `ReducedSolution`  
        :note: ``u`` must be non-negative  
        """  
        u2=util.interpolate(u,self.getFunctionSpaceForSolution())  
        if self.getNumSolutions() == 1:  
           if u2.getShape()!=():  
               raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)  
        else:  
           if u2.getShape()!=(self.getNumSolutions(),):  
               raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)  
        self.getOperator().setInitialValue(u2)  
3456    
3457     def getRequiredOperatorType(self):     def getRequiredOperatorType(self):
3458        """        """
# Line 3528  class TransportPDE(LinearProblem): Line 3507  class TransportPDE(LinearProblem):
3507         """         """
3508         return self.__constraint_factor         return self.__constraint_factor
3509     #====================================================================     #====================================================================
3510     def getSolution(self,dt):     def getSolution(self, dt=None, u0=None):
3511         """         """
3512         Returns the solution of the problem.         Returns the solution by marching forward by time step dt. if ''u0'' is present,
3513           ''u0'' is used as the initial value otherwise the solution from the last call is used.
3514    
3515           :param dt: time step size. If ``None`` the last solution is returned.
3516           :type dt: positive ``float`` or ``None``
3517           :param u0: new initial solution or ``None``
3518           :type u0: any object that can be interpolated to a `Data`
3519                    object on `Solution` or `ReducedSolution`
3520         :return: the solution         :return: the solution
3521         :rtype: `Data`         :rtype: `Data`
3522         """         """
3523         option_class=self.getSolverOptions()         if not dt == None:
3524         if dt<=0:        option_class=self.getSolverOptions()
3525             raise ValueError,"step size needs to be positive."        if dt<=0:
3526         self.setSolution(self.getOperator().solve(self.getRightHandSide(),dt,option_class))            raise ValueError,"step size needs to be positive."
3527         self.validSolution()        if u0 == None:
3528              u0=self.getCurrentSolution()
3529          else:
3530              u0=util.interpolate(u0,self.getFunctionSpaceForSolution())
3531              if self.getNumSolutions() == 1:
3532            if u0.getShape()!=():
3533                raise ValueError,"Illegal shape %s of initial solution."%(u0.getShape(),)
3534            else:
3535                if u0.getShape()!=(self.getNumSolutions(),):
3536                  raise ValueError,"Illegal shape %s of initial solution."%(u0.getShape(),)
3537          self.setSolution(self.getOperator().solve(u0, self.getRightHandSide(),dt,option_class))
3538          self.validSolution()
3539         return self.getCurrentSolution()         return self.getCurrentSolution()
3540    
3541       def setInitialSolution(self,u):
3542           """
3543           Sets the initial solution.
3544    
3545           :param u: initial solution
3546           :type u: any object that can be interpolated to a `Data`
3547                    object on `Solution` or `ReducedSolution`
3548           """
3549           u2=util.interpolate(u,self.getFunctionSpaceForSolution())
3550           if self.getNumSolutions() == 1:
3551              if u2.getShape()!=():
3552                  raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)
3553           else:
3554              if u2.getShape()!=(self.getNumSolutions(),):
3555                  raise ValueError,"Illegal shape %s of initial solution."%(u2.getShape(),)
3556           self.setSolution(u2,validate=False)
3557    
3558    
3559     def getSystem(self):     def getSystem(self):
3560         """         """
3561         Returns the operator and right hand side of the PDE.         Returns the operator and right hand side of the PDE.

Legend:
Removed from v.2881  
changed lines
  Added in v.2987

  ViewVC Help
Powered by ViewVC 1.1.26