/[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 1137 by gross, Thu May 10 08:11:31 2007 UTC revision 1809 by ksteube, Thu Sep 25 06:43:44 2008 UTC
# Line 1  Line 1 
1  # $Id$  
2    ########################################################
3    #
4    # Copyright (c) 2003-2008 by University of Queensland
5    # Earth Systems Science Computational Center (ESSCC)
6    # http://www.uq.edu.au/esscc
7    #
8    # Primary Business: Queensland, Australia
9    # Licensed under the Open Software License version 3.0
10    # http://www.opensource.org/licenses/osl-3.0.php
11    #
12    ########################################################
13    
14    __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15    Earth Systems Science Computational Center (ESSCC)
16    http://www.uq.edu.au/esscc
17    Primary Business: Queensland, Australia"""
18    __license__="""Licensed under the Open Software License version 3.0
19    http://www.opensource.org/licenses/osl-3.0.php"""
20    __url__="http://www.uq.edu.au/esscc/escript-finley"
21    
22  """  """
23  The module provides an interface to define and solve linear partial  The module provides an interface to define and solve linear partial
24  differential equations (PDEs) within L{escript}. L{linearPDEs} does not provide any  differential equations (PDEs) within L{escript}. L{linearPDEs} does not provide any
# Line 19  to define of solve these sepecial PDEs. Line 39  to define of solve these sepecial PDEs.
39  @var __date__: date of the version  @var __date__: date of the version
40  """  """
41    
42    import math
43  import escript  import escript
44  import util  import util
45  import numarray  import numarray
46    
47  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
 __copyright__="""  Copyright (c) 2006 by ACcESS MNRF  
                     http://www.access.edu.au  
                 Primary Business: Queensland, Australia"""  
 __license__="""Licensed under the Open Software License version 3.0  
              http://www.opensource.org/licenses/osl-3.0.php"""  
 __url__="http://www.iservo.edu.au/esys"  
 __version__="$Revision$"  
 __date__="$Date$"  
48    
49    
50  class IllegalCoefficient(ValueError):  class IllegalCoefficient(ValueError):
# Line 112  class PDECoefficient(object): Line 125  class PDECoefficient(object):
125         @param reduced: indicates if reduced         @param reduced: indicates if reduced
126         @type reduced: C{bool}         @type reduced: C{bool}
127         """         """
         
128         super(PDECoefficient, self).__init__()         super(PDECoefficient, self).__init__()
129         self.what=where         self.what=where
130         self.pattern=pattern         self.pattern=pattern
# Line 365  class LinearPDE(object): Line 377  class LinearPDE(object):
377    
378     The PDE is symmetrical if     The PDE is symmetrical if
379    
380     M{A[i,j]=A[j,i]}  and M{B[j]=C[j]} and M{A_reduced[i,j]=A_reduced[j,i]}  and M{B_reduced[j]=C_reduced[j]     M{A[i,j]=A[j,i]}  and M{B[j]=C[j]} and M{A_reduced[i,j]=A_reduced[j,i]}  and M{B_reduced[j]=C_reduced[j]}
381    
382     For a system of PDEs and a solution with several components the PDE has the form     For a system of PDEs and a solution with several components the PDE has the form
383    
# Line 416  class LinearPDE(object): Line 428  class LinearPDE(object):
428     of the solution at side 1 and at side 0, denotes the jump of M{u} across discontinuity along the normal calcualted by     of the solution at side 1 and at side 0, denotes the jump of M{u} across discontinuity along the normal calcualted by
429     L{jump<util.jump>}.     L{jump<util.jump>}.
430     The coefficient M{d_contact} is a rank two and M{y_contact} is a rank one both in the L{FunctionOnContactZero<escript.FunctionOnContactZero>} or L{FunctionOnContactOne<escript.FunctionOnContactOne>}.     The coefficient M{d_contact} is a rank two and M{y_contact} is a rank one both in the L{FunctionOnContactZero<escript.FunctionOnContactZero>} or L{FunctionOnContactOne<escript.FunctionOnContactOne>}.
431      The coefficient M{d_contact_reduced} is a rank two and M{y_contact_reduced} is a rank one both in the L{ReducedFunctionOnContactZero<escript.ReducedFunctionOnContactZero>} or L{ReducedFunctionOnContactOne<escript.ReducedFunctionOnContactOne>}.     The coefficient M{d_contact_reduced} is a rank two and M{y_contact_reduced} is a rank one both in the L{ReducedFunctionOnContactZero<escript.ReducedFunctionOnContactZero>} or L{ReducedFunctionOnContactOne<escript.ReducedFunctionOnContactOne>}.
432     In case of a single PDE and a single component solution the contact condition takes the form     In case of a single PDE and a single component solution the contact condition takes the form
433    
434     M{n[j]*J0_{j}=n[j]*J1_{j}=(y_contact+y_contact_reduced)-(d_contact+y_contact_reduced)*jump(u)}     M{n[j]*J0_{j}=n[j]*J1_{j}=(y_contact+y_contact_reduced)-(d_contact+y_contact_reduced)*jump(u)}
# Line 430  class LinearPDE(object): Line 442  class LinearPDE(object):
442     @cvar CR: The conjugate residual method     @cvar CR: The conjugate residual method
443     @cvar CGS: The conjugate gardient square method     @cvar CGS: The conjugate gardient square method
444     @cvar BICGSTAB: The stabilized BiConjugate Gradient method.     @cvar BICGSTAB: The stabilized BiConjugate Gradient method.
445       @cvar TFQMR: Transport Free Quasi Minimal Residual method.
446       @cvar MINRES: Minimum residual method.
447     @cvar SSOR: The symmetric overrealaxtion method     @cvar SSOR: The symmetric overrealaxtion method
448     @cvar ILU0: The incomplete LU factorization preconditioner  with no fill in     @cvar ILU0: The incomplete LU factorization preconditioner  with no fill in
449     @cvar ILUT: The incomplete LU factorization preconditioner with will in     @cvar ILUT: The incomplete LU factorization preconditioner with will in
# Line 444  class LinearPDE(object): Line 458  class LinearPDE(object):
458     @cvar SCSL: SGI SCSL solver library     @cvar SCSL: SGI SCSL solver library
459     @cvar MKL: Intel's MKL solver library     @cvar MKL: Intel's MKL solver library
460     @cvar UMFPACK: the UMFPACK library     @cvar UMFPACK: the UMFPACK library
461       @cvar TRILINOS: the TRILINOS parallel solver class library from Sandia Natl Labs
462     @cvar ITERATIVE: The default iterative solver     @cvar ITERATIVE: The default iterative solver
463     @cvar AMG: algebraic multi grid     @cvar AMG: algebraic multi grid
464     @cvar RILU: recursive ILU     @cvar RILU: recursive ILU
# Line 473  class LinearPDE(object): Line 488  class LinearPDE(object):
488     PASO= 21     PASO= 21
489     AMG= 22     AMG= 22
490     RILU = 23     RILU = 23
491       TRILINOS = 24
492       NONLINEAR_GMRES = 25
493       TFQMR = 26
494       MINRES = 27
495    
496     SMALL_TOLERANCE=1.e-13     SMALL_TOLERANCE=1.e-13
497     __PACKAGE_KEY="package"     __PACKAGE_KEY="package"
# Line 931  class LinearPDE(object): Line 950  class LinearPDE(object):
950         sets a new solver         sets a new solver
951    
952         @param solver: sets a new solver method.         @param solver: sets a new solver method.
953         @type solver: one of L{DEFAULT}, L{ITERATIVE} L{DIRECT}, L{CHOLEVSKY}, L{PCG}, L{CR}, L{CGS}, L{BICGSTAB}, L{SSOR}, L{GMRES}, L{PRES20}, L{LUMPING}, L{AMG}         @type solver: one of L{DEFAULT}, L{ITERATIVE} L{DIRECT}, L{CHOLEVSKY}, L{PCG}, L{CR}, L{CGS}, L{BICGSTAB}, L{SSOR}, L{GMRES}, L{TFQMR}, L{MINRES}, L{PRES20}, L{LUMPING}, L{AMG}
954         @param preconditioner: sets a new solver method.         @param preconditioner: sets a new solver method.
955         @type preconditioner: one of L{DEFAULT}, L{JACOBI} L{ILU0}, L{ILUT},L{SSOR}, L{RILU}         @type preconditioner: one of L{DEFAULT}, L{JACOBI} L{ILU0}, L{ILUT},L{SSOR}, L{RILU}
956         """         """
957         if solver==None: solve=self.DEFAULT         if solver==None: solver=self.__solver_method
958           if preconditioner==None: preconditioner=self.__preconditioner
959           if solver==None: solver=self.DEFAULT
960         if preconditioner==None: preconditioner=self.DEFAULT         if preconditioner==None: preconditioner=self.DEFAULT
961         if not (solver,preconditioner)==self.getSolverMethod():         if not (solver,preconditioner)==self.getSolverMethod():
962             self.__solver_method=solver             self.__solver_method=solver
# Line 959  class LinearPDE(object): Line 980  class LinearPDE(object):
980         elif m[0]==self.ITERATIVE: method= "ITERATIVE"         elif m[0]==self.ITERATIVE: method= "ITERATIVE"
981         elif m[0]==self.CHOLEVSKY: method= "CHOLEVSKY"         elif m[0]==self.CHOLEVSKY: method= "CHOLEVSKY"
982         elif m[0]==self.PCG: method= "PCG"         elif m[0]==self.PCG: method= "PCG"
983           elif m[0]==self.TFQMR: method= "TFQMR"
984           elif m[0]==self.MINRES: method= "MINRES"
985         elif m[0]==self.CR: method= "CR"         elif m[0]==self.CR: method= "CR"
986         elif m[0]==self.CGS: method= "CGS"         elif m[0]==self.CGS: method= "CGS"
987         elif m[0]==self.BICGSTAB: method= "BICGSTAB"         elif m[0]==self.BICGSTAB: method= "BICGSTAB"
# Line 979  class LinearPDE(object): Line 1002  class LinearPDE(object):
1002         elif p==self.MKL: package= "MKL"         elif p==self.MKL: package= "MKL"
1003         elif p==self.SCSL: package= "SCSL"         elif p==self.SCSL: package= "SCSL"
1004         elif p==self.UMFPACK: package= "UMFPACK"         elif p==self.UMFPACK: package= "UMFPACK"
1005           elif p==self.TRILINOS: package= "TRILINOS"
1006         else : method="unknown"         else : method="unknown"
1007         return "%s solver of %s package"%(method,package)         return "%s solver of %s package"%(method,package)
1008    
# Line 997  class LinearPDE(object): Line 1021  class LinearPDE(object):
1021         sets a new solver package         sets a new solver package
1022    
1023         @param package: sets a new solver method.         @param package: sets a new solver method.
1024         @type package: one of L{DEFAULT}, L{PASO} L{SCSL}, L{MKL}, L{UMFPACK}         @type package: one of L{DEFAULT}, L{PASO} L{SCSL}, L{MKL}, L{UMFPACK}, L{TRILINOS}
1025         """         """
1026         if package==None: package=self.DEFAULT         if package==None: package=self.DEFAULT
1027         if not package==self.getSolverPackage():         if not package==self.getSolverPackage():
# Line 1682  class LinearPDE(object): Line 1706  class LinearPDE(object):
1706                        raise ValueError,"coefficient B in lumped matrix may not be present."                        raise ValueError,"coefficient B in lumped matrix may not be present."
1707                   if not self.getCoefficientOfGeneralPDE("C").isEmpty():                   if not self.getCoefficientOfGeneralPDE("C").isEmpty():
1708                        raise ValueError,"coefficient C in lumped matrix may not be present."                        raise ValueError,"coefficient C in lumped matrix may not be present."
1709                     if not self.getCoefficientOfGeneralPDE("d_contact").isEmpty():
1710                          raise ValueError,"coefficient d_contact in lumped matrix may not be present."
1711                   if not self.getCoefficientOfGeneralPDE("A_reduced").isEmpty():                   if not self.getCoefficientOfGeneralPDE("A_reduced").isEmpty():
1712                        raise ValueError,"coefficient A_reduced in lumped matrix may not be present."                        raise ValueError,"coefficient A_reduced in lumped matrix may not be present."
1713                   if not self.getCoefficientOfGeneralPDE("B_reduced").isEmpty():                   if not self.getCoefficientOfGeneralPDE("B_reduced").isEmpty():
1714                        raise ValueError,"coefficient B_reduced in lumped matrix may not be present."                        raise ValueError,"coefficient B_reduced in lumped matrix may not be present."
1715                   if not self.getCoefficientOfGeneralPDE("C_reduced").isEmpty():                   if not self.getCoefficientOfGeneralPDE("C_reduced").isEmpty():
1716                        raise ValueError,"coefficient C_reduced in lumped matrix may not be present."                        raise ValueError,"coefficient C_reduced in lumped matrix may not be present."
1717                     if not self.getCoefficientOfGeneralPDE("d_contact_reduced").isEmpty():
1718                          raise ValueError,"coefficient d_contact_reduced in lumped matrix may not be present."
1719                   D=self.getCoefficientOfGeneralPDE("D")                   D=self.getCoefficientOfGeneralPDE("D")
1720                     d=self.getCoefficientOfGeneralPDE("d")
1721                     D_reduced=self.getCoefficientOfGeneralPDE("D_reduced")
1722                     d_reduced=self.getCoefficientOfGeneralPDE("d_reduced")
1723                   if not D.isEmpty():                   if not D.isEmpty():
1724                       if self.getNumSolutions()>1:                       if self.getNumSolutions()>1:
1725                          D_times_e=util.matrix_mult(D,numarray.ones((self.getNumSolutions(),)))                          D_times_e=util.matrix_mult(D,numarray.ones((self.getNumSolutions(),)))
# Line 1696  class LinearPDE(object): Line 1727  class LinearPDE(object):
1727                          D_times_e=D                          D_times_e=D
1728                   else:                   else:
1729                      D_times_e=escript.Data()                      D_times_e=escript.Data()
                  d=self.getCoefficientOfGeneralPDE("d")  
1730                   if not d.isEmpty():                   if not d.isEmpty():
1731                       if self.getNumSolutions()>1:                       if self.getNumSolutions()>1:
1732                          d_times_e=util.matrix_mult(d,numarray.ones((self.getNumSolutions(),)))                          d_times_e=util.matrix_mult(d,numarray.ones((self.getNumSolutions(),)))
# Line 1704  class LinearPDE(object): Line 1734  class LinearPDE(object):
1734                          d_times_e=d                          d_times_e=d
1735                   else:                   else:
1736                      d_times_e=escript.Data()                      d_times_e=escript.Data()
1737                   d_contact=self.getCoefficientOfGeneralPDE("d_contact")        
                  if not d_contact.isEmpty():  
                      if self.getNumSolutions()>1:  
                         d_contact_times_e=util.matrixmult(d_contact,numarray.ones((self.getNumSolutions(),)))  
                      else:  
                         d_contact_times_e=d_contact  
                  else:  
                     d_contact_times_e=escript.Data()  
       
                  self.__operator=self.__getNewRightHandSide()  
                  self.getDomain().addPDEToRHS(self.__operator, \  
                                               escript.Data(), \  
                                               D_times_e, \  
                                               d_times_e,\  
                                               d_contact_times_e)  
                  D_reduced=self.getCoefficientOfGeneralPDE("D_reduced")  
1738                   if not D_reduced.isEmpty():                   if not D_reduced.isEmpty():
1739                       if self.getNumSolutions()>1:                       if self.getNumSolutions()>1:
1740                          D_reduced_times_e=util.matrix_mult(D_reduced,numarray.ones((self.getNumSolutions(),)))                          D_reduced_times_e=util.matrix_mult(D_reduced,numarray.ones((self.getNumSolutions(),)))
# Line 1727  class LinearPDE(object): Line 1742  class LinearPDE(object):
1742                          D_reduced_times_e=D_reduced                          D_reduced_times_e=D_reduced
1743                   else:                   else:
1744                      D_reduced_times_e=escript.Data()                      D_reduced_times_e=escript.Data()
                  d_reduced=self.getCoefficientOfGeneralPDE("d_reduced")  
1745                   if not d_reduced.isEmpty():                   if not d_reduced.isEmpty():
1746                       if self.getNumSolutions()>1:                       if self.getNumSolutions()>1:
1747                          d_reduced_times_e=util.matrix_mult(d_reduced,numarray.ones((self.getNumSolutions(),)))                          d_reduced_times_e=util.matrix_mult(d_reduced,numarray.ones((self.getNumSolutions(),)))
# Line 1735  class LinearPDE(object): Line 1749  class LinearPDE(object):
1749                          d_reduced_times_e=d_reduced                          d_reduced_times_e=d_reduced
1750                   else:                   else:
1751                      d_reduced_times_e=escript.Data()                      d_reduced_times_e=escript.Data()
1752                   d_contact_reduced=self.getCoefficientOfGeneralPDE("d_contact_reduced")  
                  if not d_contact_reduced.isEmpty():  
                      if self.getNumSolutions()>1:  
                         d_contact_reduced_times_e=util.matrixmult(d_contact_reduced,numarray.ones((self.getNumSolutions(),)))  
                      else:  
                         d_contact_reduced_times_e=d_contact_reduced  
                  else:  
                     d_contact_reduced_times_e=escript.Data()  
       
1753                   self.__operator=self.__getNewRightHandSide()                   self.__operator=self.__getNewRightHandSide()
1754                   self.getDomain().addPDEToRHS(self.__operator, \                   if False and hasattr(self.getDomain(), "addPDEToLumpedSystem") :
1755                                                escript.Data(), \                      self.getDomain().addPDEToLumpedSystem(self.__operator, D_times_e, d_times_e)
1756                                                D_times_e, \                      self.getDomain().addPDEToLumpedSystem(self.__operator, D_reduced_times_e, d_reduced_times_e)
1757                                                d_times_e,\                   else:
1758                                                d_contact_times_e)                      self.getDomain().addPDEToRHS(self.__operator, \
1759                   self.getDomain().addPDEToRHS(self.__operator, \                                                   escript.Data(), \
1760                                                escript.Data(), \                                                   D_times_e, \
1761                                                D_reduced_times_e, \                                                   d_times_e,\
1762                                                d_reduced_times_e,\                                                   escript.Data())
1763                                                d_contact_reduced_times_e)                      self.getDomain().addPDEToRHS(self.__operator, \
1764                                                     escript.Data(), \
1765                                                     D_reduced_times_e, \
1766                                                     d_reduced_times_e,\
1767                                                     escript.Data())
1768                   self.__operator=1./self.__operator                   self.__operator=1./self.__operator
1769                   self.trace("New lumped operator has been built.")                   self.trace("New lumped operator has been built.")
1770                   self.__operator_is_Valid=True                   self.__operator_is_Valid=True
# Line 2185  class LameEquation(LinearPDE): Line 2195  class LameEquation(LinearPDE):
2195       else:       else:
2196          raise IllegalCoefficient,"illegal coefficient %s requested for general PDE."%name          raise IllegalCoefficient,"illegal coefficient %s requested for general PDE."%name
2197    
2198    def LinearSinglePDE(domain,debug=False):
2199       """
2200       defines a single linear PDEs
2201    
2202       @param domain: domain of the PDE
2203       @type domain: L{Domain<escript.Domain>}
2204       @param debug: if True debug informations are printed.
2205       @rtype: L{LinearPDE}
2206       """
2207       return LinearPDE(domain,numEquations=1,numSolutions=1,debug=debug)
2208    
2209    def LinearPDESystem(domain,debug=False):
2210       """
2211       defines a system of linear PDEs
2212    
2213       @param domain: domain of the PDE
2214       @type domain: L{Domain<escript.Domain>}
2215       @param debug: if True debug informations are printed.
2216       @rtype: L{LinearPDE}
2217       """
2218       return LinearPDE(domain,numEquations=domain.getDim(),numSolutions=domain.getDim(),debug=debug)
2219    
2220    class TransportPDE(object):
2221         """
2222         Warning: This is still a very experimental. The class is still changing!
2223    
2224         Mu_{,t} =-(A_{ij}u_{,j})_j-(B_{j}u)_{,j} + C_{j} u_{,j} + Y_i + X_{i,i}
2225        
2226         u=r where q>0
2227        
2228         all coefficients are constant over time.
2229    
2230         typical usage:
2231    
2232             p=TransportPDE(dom)
2233             p.setValue(M=Scalar(1.,Function(dom),C=Scalar(1.,Function(dom)*[-1.,0.])
2234             p.setInitialSolution(u=exp(-length(dom.getX()-[0.1,0.1])**2)
2235             t=0
2236             dt=0.1
2237             while (t<1.):
2238                  u=p.solve(dt)
2239    
2240         """
2241         def __init__(self,domain,num_equations=1,theta=0.5,useSUPG=False,trace=True):
2242            self.__domain=domain
2243            self.__num_equations=num_equations
2244            self.__useSUPG=useSUPG
2245            self.__trace=trace
2246            self.__theta=theta
2247            self.__matrix_type=0
2248            self.__reduced=True
2249            self.__reassemble=True
2250            if self.__useSUPG:
2251               self.__pde=LinearPDE(domain,numEquations=num_equations,numSolutions=num_equations,debug=trace)
2252               self.__pde.setSymmetryOn()
2253               self.__pde.setReducedOrderOn()
2254            else:
2255               self.__transport_problem=self.__getNewTransportProblem()
2256            self.setTolerance()
2257            self.__M=escript.Data()
2258            self.__A=escript.Data()
2259            self.__B=escript.Data()
2260            self.__C=escript.Data()
2261            self.__D=escript.Data()
2262            self.__X=escript.Data()
2263            self.__Y=escript.Data()
2264            self.__d=escript.Data()
2265            self.__y=escript.Data()
2266            self.__d_contact=escript.Data()
2267            self.__y_contact=escript.Data()
2268            self.__r=escript.Data()
2269            self.__q=escript.Data()
2270    
2271         def trace(self,text):
2272                 if self.__trace: print text
2273         def getSafeTimeStepSize(self):
2274            if self.__useSUPG:
2275                if self.__reassemble:
2276                   h=self.__domain.getSize()
2277                   dt=None
2278                   if not self.__A.isEmpty():
2279                      dt2=util.inf(h**2*self.__M/util.length(self.__A))
2280                      if dt == None:
2281                         dt = dt2
2282                      else:
2283                         dt=1./(1./dt+1./dt2)
2284                   if not self.__B.isEmpty():
2285                      dt2=util.inf(h*self.__M/util.length(self.__B))
2286                      if dt == None:
2287                         dt = dt2
2288                      else:
2289                         dt=1./(1./dt+1./dt2)
2290                   if not  self.__C.isEmpty():
2291                      dt2=util.inf(h*self.__M/util.length(self.__C))
2292                      if dt == None:
2293                         dt = dt2
2294                      else:
2295                         dt=1./(1./dt+1./dt2)
2296                   if not self.__D.isEmpty():
2297                      dt2=util.inf(self.__M/util.length(self.__D))
2298                      if dt == None:
2299                         dt = dt2
2300                      else:
2301                         dt=1./(1./dt+1./dt2)
2302                   self.__dt = dt/2
2303                return self.__dt
2304            else:
2305                return self.__getTransportProblem().getSafeTimeStepSize()
2306         def getDomain(self):
2307            return self.__domain
2308         def getTheta(self):
2309            return self.__theta
2310         def getNumEquations(self):
2311            return self.__num_equations
2312         def setReducedOn(self):
2313              if not self.reduced():
2314                  if self.__useSUPG:
2315                     self.__pde.setReducedOrderOn()
2316                  else:
2317                     self.__transport_problem=self.__getNewTransportProblem()
2318              self.__reduced=True
2319         def setReducedOff(self):
2320              if self.reduced():
2321                  if self.__useSUPG:
2322                     self.__pde.setReducedOrderOff()
2323                  else:
2324                     self.__transport_problem=self.__getNewTransportProblem()
2325              self.__reduced=False
2326         def reduced(self):
2327             return self.__reduced
2328         def getFunctionSpace(self):
2329            if self.reduced():
2330               return escript.ReducedSolution(self.getDomain())
2331            else:
2332               return escript.Solution(self.getDomain())
2333    
2334         def setTolerance(self,tol=1.e-8):
2335            self.__tolerance=tol
2336            if self.__useSUPG:
2337                  self.__pde.setTolerance(self.__tolerance)
2338    
2339         def __getNewTransportProblem(self):
2340           """
2341           returns an instance of a new operator
2342           """
2343           self.trace("New Transport problem is allocated.")
2344           return self.getDomain().newTransportProblem( \
2345                                   self.getTheta(),
2346                                   self.getNumEquations(), \
2347                                   self.getFunctionSpace(), \
2348                                   self.__matrix_type)
2349              
2350         def __getNewSolutionVector(self):
2351             if self.getNumEquations() ==1 :
2352                    out=escript.Data(0.0,(),self.getFunctionSpace())
2353             else:
2354                    out=escript.Data(0.0,(self.getNumEquations(),),self.getFunctionSpace())
2355             return out
2356    
2357         def __getTransportProblem(self):
2358           if self.__reassemble:
2359                 self.__source=self.__getNewSolutionVector()
2360                 self.__transport_problem.reset()
2361                 self.getDomain().addPDEToTransportProblem(
2362                             self.__transport_problem,
2363                             self.__source,
2364                             self.__M,
2365                             self.__A,
2366                             self.__B,
2367                             self.__C,
2368                             self.__D,
2369                             self.__X,
2370                             self.__Y,
2371                             self.__d,
2372                             self.__y,
2373                             self.__d_contact,
2374                             self.__y_contact)
2375                 self.__transport_problem.insertConstraint(self.__source,self.__q,self.__r)
2376                 self.__reassemble=False
2377           return self.__transport_problem
2378         def setValue(self,M=None, A=None, B=None, C=None, D=None, X=None, Y=None,
2379                      d=None, y=None, d_contact=None, y_contact=None, q=None, r=None):
2380                 if not M==None:
2381                      self.__reassemble=True
2382                      self.__M=M
2383                 if not A==None:
2384                      self.__reassemble=True
2385                      self.__A=A
2386                 if not B==None:
2387                      self.__reassemble=True
2388                      self.__B=B
2389                 if not C==None:
2390                      self.__reassemble=True
2391                      self.__C=C
2392                 if not D==None:
2393                      self.__reassemble=True
2394                      self.__D=D
2395                 if not X==None:
2396                      self.__reassemble=True
2397                      self.__X=X
2398                 if not Y==None:
2399                      self.__reassemble=True
2400                      self.__Y=Y
2401                 if not d==None:
2402                      self.__reassemble=True
2403                      self.__d=d
2404                 if not y==None:
2405                      self.__reassemble=True
2406                      self.__y=y
2407                 if not d_contact==None:
2408                      self.__reassemble=True
2409                      self.__d_contact=d_contact
2410                 if not y_contact==None:
2411                      self.__reassemble=True
2412                      self.__y_contact=y_contact
2413                 if not q==None:
2414                      self.__reassemble=True
2415                      self.__q=q
2416                 if not r==None:
2417                      self.__reassemble=True
2418                      self.__r=r
2419    
2420         def setInitialSolution(self,u):
2421                 if self.__useSUPG:
2422                     self.__u=util.interpolate(u,self.getFunctionSpace())
2423                 else:
2424                     self.__transport_problem.setInitialValue(util.interpolate(u,self.getFunctionSpace()))
2425    
2426         def solve(self,dt,**kwarg):
2427               if self.__useSUPG:
2428                    if self.__reassemble:
2429                        self.__pde.setValue(D=self.__M,d=self.__d,d_contact=self.__d_contact,q=self.__q) # ,r=self.__r)
2430                        self.__reassemble=False
2431                    dt2=self.getSafeTimeStepSize()
2432                    nn=max(math.ceil(dt/self.getSafeTimeStepSize()),1.)
2433                    dt2=dt/nn
2434                    nnn=0
2435                    u=self.__u
2436                    self.trace("number of substeps is %d."%nn)
2437                    while nnn<nn :
2438                        self.__setSUPG(u,u,dt2/2)
2439                        u_half=self.__pde.getSolution(verbose=True)
2440                        self.__setSUPG(u,u_half,dt2)
2441                        u=self.__pde.getSolution(verbose=True)
2442                        nnn+=1
2443                    self.__u=u
2444                    return self.__u
2445               else:
2446                   kwarg["tolerance"]=self.__tolerance
2447                   tp=self.__getTransportProblem()
2448                   return tp.solve(self.__source,dt,kwarg)
2449         def __setSUPG(self,u0,u,dt):
2450                g=util.grad(u)
2451                X=0
2452                Y=self.__M*u0
2453                X=0
2454                self.__pde.setValue(r=u0)
2455                if not self.__A.isEmpty():
2456                   X=X+dt*util.matrixmult(self.__A,g)
2457                if not self.__B.isEmpty():
2458                   X=X+dt*self.__B*u
2459                if not  self.__C.isEmpty():
2460                   Y=Y+dt*util.inner(self.__C,g)
2461                if not self.__D.isEmpty():
2462                   Y=Y+dt*self.__D*u
2463                if not self.__X.isEmpty():
2464                   X=X+dt*self.__X
2465                if not self.__Y.isEmpty():
2466                   Y=Y+dt*self.__Y
2467                self.__pde.setValue(X=X,Y=Y)
2468                if not self.__y.isEmpty():
2469                   self.__pde.setValue(y=dt*self.__y)
2470                if not self.__y_contact.isEmpty():
2471                   self.__pde.setValue(y=dt*self.__y_contact)
2472                self.__pde.setValue(r=u0)

Legend:
Removed from v.1137  
changed lines
  Added in v.1809

  ViewVC Help
Powered by ViewVC 1.1.26