/[escript]/branches/symbolic_from_3470/escript/py_src/heat.py
ViewVC logotype

Annotation of /branches/symbolic_from_3470/escript/py_src/heat.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 4 months ago) by jfenwick
Original Path: trunk/escript/py_src/heat.py
File MIME type: text/x-python
File size: 6494 byte(s)
Don't panic.
Updating copyright stamps

1 ksteube 1809
2     ########################################################
3 gross 1417 #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1809 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7 gross 1417 #
8 ksteube 1809 # 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 gross 1417 #
12 ksteube 1809 ########################################################
13 gross 1417
14 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1809 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 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1809
22 gross 1417 """
23     Some models for heat advection-diffusion
24    
25 jfenwick 2625 :var __author__: name of author
26     :var __copyright__: copyrights
27     :var __license__: licence agreement
28     :var __url__: url entry point on documentation
29     :var __version__: version
30     :var __date__: date of the version
31 gross 1417 """
32    
33     __author__="Lutz Gross, l.gross@uq.edu.au"
34    
35     # from escript import *
36 gross 2858 import escript
37 gross 1417 import util
38     from linearPDEs import TransportPDE
39    
40     class TemperatureCartesian(TransportPDE):
41 caltinay 2169 """
42     Represents and solves the temperature advection-diffusion problem
43 gross 1417
44 jfenwick 2625 *rhocp(T_{,t} + v_i T_{,i} - ( k T_{,i})_i = Q*
45 caltinay 2158
46 jfenwick 2625 *k T_{,i}*n_i=surface_flux* and *T_{,t} = 0* where ``given_T_mask``>0.
47 caltinay 2158
48 caltinay 2169 If surface_flux is not given 0 is assumed.
49 gross 1417
50 caltinay 2169 Typical usage::
51 gross 1417
52 caltinay 2169 sp = TemperatureCartesian(domain)
53     sp.setTolerance(1.e-4)
54     t = 0
55     T = ...
56     sp.setValues(rhocp=..., v=..., k=..., given_T_mask=...)
57     sp.setInitialTemperature(T)
58     while t < t_end:
59     sp.setValue(Q=...)
60     T = sp.getTemperature(dt)
61     t += dt
62     """
63 gross 2337 def __init__(self,domain,useBackwardEuler=False,**kwargs):
64 gross 1417 """
65 caltinay 2169 Initializes the temperature advection-diffusion problem.
66 gross 1417
67 jfenwick 2625 :param domain: domain of the problem
68     :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.
69     :type useBackwardEuler: ``bool``
70 gross 2857 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
71 gross 1417 """
72 gross 2337 TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
73 gross 2858 order=escript.Solution(domain).getApproximationOrder()
74 gross 2857 if order>1:
75 gross 2858 if escript.ReducedSolution(domain).getApproximationOrder()>1: raise ValueError,"Reduced order needs to be equal to 1."
76 gross 2857 self.setReducedOrderOn()
77     else:
78     self.setReducedOrderOff()
79 gross 1417 self.__rhocp=None
80     self.__v=None
81 caltinay 2158
82 caltinay 2169 def setInitialTemperature(self,T):
83     """
84 jfenwick 2625 Same as `setInitialSolution`.
85 caltinay 2169 """
86 gross 1417 self.setInitialSolution(T)
87 caltinay 2158
88 caltinay 2169 def setValue(self,rhocp=None,v=None,k=None,Q=None,surface_flux=None,given_T_mask=None):
89     if rhocp!=None:
90     self.__rhocp=rhocp
91     if v!=None:
92     self.__v=v
93     if rhocp!=None:
94     super(TemperatureCartesian,self).setValue(M=self.__rhocp)
95     if (rhocp!=None or v!=None) and self.__rhocp!=None and self.__v!=None:
96     super(TemperatureCartesian,self).setValue(C=-self.__rhocp*self.__v)
97     if k!=None:
98     super(TemperatureCartesian,self).setValue(A=-k*util.kronecker(self.getDomain()))
99     if Q!=None:
100     super(TemperatureCartesian,self).setValue(Y=Q)
101     if surface_flux!=None:
102     super(TemperatureCartesian,self).setValue(y=surface_flux)
103     if given_T_mask!=None:
104     super(TemperatureCartesian,self).setValue(q=given_T_mask)
105 caltinay 2158
106 caltinay 2169 def getTemperature(self,dt,**kwargs):
107     """
108 jfenwick 2625 Same as `getSolution`.
109 caltinay 2169 """
110     return self.getSolution(dt,**kwargs)
111 caltinay 2158
112 gross 2479
113     class Tracer(TransportPDE):
114     """
115     Represents and solves the tracer problem
116    
117 jfenwick 2625 *C_{,t} + v_i C_{,i} - ( k T_{,i})_i) = 0*
118 gross 2479
119 jfenwick 2625 *C_{,t} = 0* where ``given_C_mask``>0.
120     *C_{,i}*n_i=0*
121 gross 2479
122     Typical usage::
123    
124     sp = Tracer(domain)
125     sp.setTolerance(1.e-4)
126     t = 0
127     T = ...
128     sp.setValues(given_C_mask=...)
129     sp.setInitialTracer(C)
130     while t < t_end:
131     sp.setValue(v=...)
132     dt.getSaveTimeStepSize()
133     C = sp.getTracer(dt)
134     t += dt
135     """
136     def __init__(self,domain,useBackwardEuler=False,**kwargs):
137     """
138     Initializes the Tracer advection problem
139    
140 jfenwick 2625 :param domain: domain of the problem
141     :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.
142     :type useBackwardEuler: ``bool``
143 gross 2857 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
144 gross 2479 """
145     TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
146 gross 2858 order=escript.Solution(domain).getApproximationOrder()
147 gross 2857 if order>1:
148 gross 2858 if escript.ReducedSolution(domain).getApproximationOrder()>1: raise ValueError,"Reduced order needs to be equal to 1."
149 gross 2857 self.setReducedOrderOn()
150     else:
151     self.setReducedOrderOff()
152 gross 2479 super(Tracer,self).setValue(M=1.)
153    
154     def setInitialTracer(self,C):
155     """
156 jfenwick 2625 Same as `setInitialSolution`.
157 gross 2479 """
158     self.setInitialSolution(C)
159    
160     def setValue(self,v=None,given_C_mask=None, k=None):
161     if v!=None:
162     super(Tracer,self).setValue(C=-v)
163     if k!=None:
164     super(Tracer,self).setValue(A=-k*util.kronecker(self.getDomain()))
165     if given_C_mask!=None:
166     super(Tracer,self).setValue(q=given_C_mask)
167    
168     def getTracer(self,dt,**kwargs):
169     """
170 jfenwick 2625 Same as `getSolution`.
171 gross 2479 """
172     return self.getSolution(dt,**kwargs)
173    

  ViewVC Help
Powered by ViewVC 1.1.26