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

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

  ViewVC Help
Powered by ViewVC 1.1.26