# Diff of /trunk/escript/py_src/heat.py

revision 2169 by caltinay, Wed Dec 17 03:08:58 2008 UTC revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC
# Line 1  Line 1
1
2  ########################################################  ########################################################
3  #  #
4  # Copyright (c) 2003-2008 by University of Queensland  # Copyright (c) 2003-2009 by University of Queensland
5  # Earth Systems Science Computational Center (ESSCC)  # Earth Systems Science Computational Center (ESSCC)
6  # http://www.uq.edu.au/esscc  # http://www.uq.edu.au/esscc
7  #  #
# Line 17  http://www.uq.edu.au/esscc Line 17  http://www.uq.edu.au/esscc
21
22  """  """
# Line 59  class TemperatureCartesian(TransportPDE) Line 59  class TemperatureCartesian(TransportPDE)
59              T = sp.getTemperature(dt)              T = sp.getTemperature(dt)
60              t += dt              t += dt
61      """      """
62      def __init__(self,domain,theta=0.5,**kwargs):      def __init__(self,domain,useBackwardEuler=False,**kwargs):
63          """          """
65
66          @param domain: domain of the problem          @param domain: domain of the problem
67          @param theta: method control:          @param useBackwardEuler: if set the backward Euler scheme is used. Otherwise the Crank-Nicholson scheme is applied. Not that backward Euler scheme will return a safe time step size which is practically infinity as the scheme is unconditional unstable. So other measures need to be applied to control the time step size. The Crank-Nicholson scheme provides a higher accuracy but requires to limit the time step size to be stable.
68              - theta=1.0: backward Euler          @type useBackwardEuler: C{bool}
- theta=0.5: Crank-Nicholson scheme
- theta=0.0: forward Euler (not recommended)
69          """          """
70          TransportPDE.__init__(self,domain,numEquations=1,theta=theta,**kwargs)          TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
71          self.setReducedOrderOn()          self.setReducedOrderOn()
72          self.__rhocp=None          self.__rhocp=None
73          self.__v=None          self.__v=None
# Line 102  class TemperatureCartesian(TransportPDE) Line 100  class TemperatureCartesian(TransportPDE)
100          """          """
101          Same as L{getSolution}.          Same as L{getSolution}.
102          """          """
103            return self.getSolution(dt,**kwargs)
104
105
106    class Tracer(TransportPDE):
107        """
108        Represents and solves the tracer problem
109
110        M{C_{,t} + v_i C_{,i} - ( k T_{,i})_i) = 0}
111
112        M{C_{,t} = 0} where C{given_C_mask}>0.
113        M{C_{,i}*n_i=0}
114
115        Typical usage::
116
117            sp = Tracer(domain)
118            sp.setTolerance(1.e-4)
119            t = 0
120            T = ...
122            sp.setInitialTracer(C)
123            while t < t_end:
124                sp.setValue(v=...)
125                dt.getSaveTimeStepSize()
126                C = sp.getTracer(dt)
127                t += dt
128        """
129        def __init__(self,domain,useBackwardEuler=False,**kwargs):
130            """
131            Initializes the Tracer advection problem
132
133            @param domain: domain of the problem
134            @param useBackwardEuler: if set the backward Euler scheme is used. Otherwise the Crank-Nicholson scheme is applied. Not that backward Euler scheme will return a safe time step size which is practically infinity as the scheme is unconditional unstable. So other measures need to be applied to control the time step size. The Crank-Nicholson scheme provides a higher accuracy but requires to limit the time step size to be stable.
135            @type useBackwardEuler: C{bool}
136            """
137            TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
138            self.setReducedOrderOn()
139            super(Tracer,self).setValue(M=1.)
140
141        def setInitialTracer(self,C):
142            """
143            Same as L{setInitialSolution}.
144            """
145            self.setInitialSolution(C)
146
148            if v!=None:
149                super(Tracer,self).setValue(C=-v)
150            if k!=None:
151                super(Tracer,self).setValue(A=-k*util.kronecker(self.getDomain()))