/[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 2857 - (hide annotations)
Mon Jan 18 07:44:42 2010 UTC (9 years, 4 months ago) by gross
Original Path: trunk/escript/py_src/heat.py
File MIME type: text/x-python
File size: 6481 byte(s)
test for ApproximationOrder added and Transport type problem now choose reduced when necessary only.
1 ksteube 1809
2     ########################################################
3 gross 1417 #
4 jfenwick 2548 # Copyright (c) 2003-2009 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 2549 __copyright__="""Copyright (c) 2003-2009 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     import util
37     from linearPDEs import TransportPDE
38    
39     class TemperatureCartesian(TransportPDE):
40 caltinay 2169 """
41     Represents and solves the temperature advection-diffusion problem
42 gross 1417
43 jfenwick 2625 *rhocp(T_{,t} + v_i T_{,i} - ( k T_{,i})_i = Q*
44 caltinay 2158
45 jfenwick 2625 *k T_{,i}*n_i=surface_flux* and *T_{,t} = 0* where ``given_T_mask``>0.
46 caltinay 2158
47 caltinay 2169 If surface_flux is not given 0 is assumed.
48 gross 1417
49 caltinay 2169 Typical usage::
50 gross 1417
51 caltinay 2169 sp = TemperatureCartesian(domain)
52     sp.setTolerance(1.e-4)
53     t = 0
54     T = ...
55     sp.setValues(rhocp=..., v=..., k=..., given_T_mask=...)
56     sp.setInitialTemperature(T)
57     while t < t_end:
58     sp.setValue(Q=...)
59     T = sp.getTemperature(dt)
60     t += dt
61     """
62 gross 2337 def __init__(self,domain,useBackwardEuler=False,**kwargs):
63 gross 1417 """
64 caltinay 2169 Initializes the temperature advection-diffusion problem.
65 gross 1417
66 jfenwick 2625 :param domain: domain of the problem
67     :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     :type useBackwardEuler: ``bool``
69 gross 2857 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
70 gross 1417 """
71 gross 2337 TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
72 gross 2857 order=Solution(domain).getApproximationOrder()
73     if order>1:
74     if ReducedSolution(domain).getApproximationOrder()>1: raise ValueError,"Reduced order needs to be equal to 1."
75     self.setReducedOrderOn()
76     else:
77     self.setReducedOrderOff()
78    
79     self.__reduced = reduced
80 gross 1417 self.__rhocp=None
81     self.__v=None
82 caltinay 2158
83 caltinay 2169 def setInitialTemperature(self,T):
84     """
85 jfenwick 2625 Same as `setInitialSolution`.
86 caltinay 2169 """
87 gross 1417 self.setInitialSolution(T)
88 caltinay 2158
89 caltinay 2169 def setValue(self,rhocp=None,v=None,k=None,Q=None,surface_flux=None,given_T_mask=None):
90     if rhocp!=None:
91     self.__rhocp=rhocp
92     if v!=None:
93     self.__v=v
94     if rhocp!=None:
95     super(TemperatureCartesian,self).setValue(M=self.__rhocp)
96     if (rhocp!=None or v!=None) and self.__rhocp!=None and self.__v!=None:
97     super(TemperatureCartesian,self).setValue(C=-self.__rhocp*self.__v)
98     if k!=None:
99     super(TemperatureCartesian,self).setValue(A=-k*util.kronecker(self.getDomain()))
100     if Q!=None:
101     super(TemperatureCartesian,self).setValue(Y=Q)
102     if surface_flux!=None:
103     super(TemperatureCartesian,self).setValue(y=surface_flux)
104     if given_T_mask!=None:
105     super(TemperatureCartesian,self).setValue(q=given_T_mask)
106 caltinay 2158
107 caltinay 2169 def getTemperature(self,dt,**kwargs):
108     """
109 jfenwick 2625 Same as `getSolution`.
110 caltinay 2169 """
111     return self.getSolution(dt,**kwargs)
112 caltinay 2158
113 gross 2479
114     class Tracer(TransportPDE):
115     """
116     Represents and solves the tracer problem
117    
118 jfenwick 2625 *C_{,t} + v_i C_{,i} - ( k T_{,i})_i) = 0*
119 gross 2479
120 jfenwick 2625 *C_{,t} = 0* where ``given_C_mask``>0.
121     *C_{,i}*n_i=0*
122 gross 2479
123     Typical usage::
124    
125     sp = Tracer(domain)
126     sp.setTolerance(1.e-4)
127     t = 0
128     T = ...
129     sp.setValues(given_C_mask=...)
130     sp.setInitialTracer(C)
131     while t < t_end:
132     sp.setValue(v=...)
133     dt.getSaveTimeStepSize()
134     C = sp.getTracer(dt)
135     t += dt
136     """
137     def __init__(self,domain,useBackwardEuler=False,**kwargs):
138     """
139     Initializes the Tracer advection problem
140    
141 jfenwick 2625 :param domain: domain of the problem
142     :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.
143     :type useBackwardEuler: ``bool``
144 gross 2857 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
145 gross 2479 """
146     TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
147 gross 2857 order=Solution(domain).getApproximationOrder()
148     if order>1:
149     if ReducedSolution(domain).getApproximationOrder()>1: raise ValueError,"Reduced order needs to be equal to 1."
150     self.setReducedOrderOn()
151     else:
152     self.setReducedOrderOff()
153 gross 2479 super(Tracer,self).setValue(M=1.)
154    
155     def setInitialTracer(self,C):
156     """
157 jfenwick 2625 Same as `setInitialSolution`.
158 gross 2479 """
159     self.setInitialSolution(C)
160    
161     def setValue(self,v=None,given_C_mask=None, k=None):
162     if v!=None:
163     super(Tracer,self).setValue(C=-v)
164     if k!=None:
165     super(Tracer,self).setValue(A=-k*util.kronecker(self.getDomain()))
166     if given_C_mask!=None:
167     super(Tracer,self).setValue(q=given_C_mask)
168    
169     def getTracer(self,dt,**kwargs):
170     """
171 jfenwick 2625 Same as `getSolution`.
172 gross 2479 """
173     return self.getSolution(dt,**kwargs)
174    

  ViewVC Help
Powered by ViewVC 1.1.26