/[escript]/trunk/escript/py_src/heat.py
ViewVC logotype

Contents of /trunk/escript/py_src/heat.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3793 - (show annotations)
Wed Feb 1 07:39:43 2012 UTC (7 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 5977 byte(s)
new implementation of FCT solver with some modifications to the python interface
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 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-2010 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__="https://launchpad.net/escript-finley"
21
22 """
23 Some models for heat advection-diffusion
24
25 :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 """
32
33 __author__="Lutz Gross, l.gross@uq.edu.au"
34
35 # from escript import *
36 from . import escript
37 from . import util
38 from .linearPDEs import TransportPDE
39
40 class TemperatureCartesian(TransportPDE):
41 """
42 Represents and solves the temperature advection-diffusion problem
43
44 *rhocp(T_{,t} + v_i T_{,i} - ( k T_{,i})_i = Q*
45
46 *k T_{,i}*n_i=surface_flux* and *T_{,t} = 0* where ``given_T_mask``>0.
47
48 If surface_flux is not given 0 is assumed.
49
50 Typical usage::
51
52 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 def __init__(self,domain,**kwargs):
64 """
65 Initializes the temperature advection-diffusion problem.
66
67 :param domain: domain of the problem
68 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
69 """
70 TransportPDE.__init__(self,domain,numEquations=1, **kwargs)
71 order=escript.Solution(domain).getApproximationOrder()
72 if order>1:
73 if escript.ReducedSolution(domain).getApproximationOrder()>1: raise ValueError("Reduced order needs to be equal to 1.")
74 self.setReducedOrderOn()
75 else:
76 self.setReducedOrderOff()
77 self.__rhocp=None
78 self.__v=None
79
80 def setInitialTemperature(self,T):
81 """
82 Same as `setInitialSolution`.
83 """
84 self.setInitialSolution(T)
85
86 def setValue(self,rhocp=None,v=None,k=None,Q=None,surface_flux=None,given_T_mask=None):
87 if rhocp!=None:
88 self.__rhocp=rhocp
89 if v!=None:
90 self.__v=v
91 if rhocp!=None:
92 super(TemperatureCartesian,self).setValue(M=self.__rhocp)
93 if (rhocp!=None or v!=None) and self.__rhocp!=None and self.__v!=None:
94 super(TemperatureCartesian,self).setValue(C=-self.__rhocp*self.__v)
95 if k!=None:
96 super(TemperatureCartesian,self).setValue(A=-k*util.kronecker(self.getDomain()))
97 if Q!=None:
98 super(TemperatureCartesian,self).setValue(Y=Q)
99 if surface_flux!=None:
100 super(TemperatureCartesian,self).setValue(y=surface_flux)
101 if given_T_mask!=None:
102 super(TemperatureCartesian,self).setValue(q=given_T_mask)
103
104 def getTemperature(self,dt,**kwargs):
105 """
106 Same as `getSolution`.
107 """
108 return self.getSolution(dt,**kwargs)
109
110
111 class Tracer(TransportPDE):
112 """
113 Represents and solves the tracer problem
114
115 *C_{,t} + v_i C_{,i} - ( k T_{,i})_i) = 0*
116
117 *C_{,t} = 0* where ``given_C_mask``>0.
118 *C_{,i}*n_i=0*
119
120 Typical usage::
121
122 sp = Tracer(domain)
123 sp.setTolerance(1.e-4)
124 t = 0
125 T = ...
126 sp.setValues(given_C_mask=...)
127 sp.setInitialTracer(C)
128 while t < t_end:
129 sp.setValue(v=...)
130 dt.getSaveTimeStepSize()
131 C = sp.getTracer(dt)
132 t += dt
133 """
134 def __init__(self,domain,useBackwardEuler=False,**kwargs):
135 """
136 Initializes the Tracer advection problem
137
138 :param domain: domain of the problem
139 :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.
140 :type useBackwardEuler: ``bool``
141 :note: the approximation order is switched to reduced if the approximation order is nnot linear (equal to 1).
142 """
143 TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
144 order=escript.Solution(domain).getApproximationOrder()
145 if order>1:
146 if escript.ReducedSolution(domain).getApproximationOrder()>1: raise ValueError("Reduced order needs to be equal to 1.")
147 self.setReducedOrderOn()
148 else:
149 self.setReducedOrderOff()
150 super(Tracer,self).setValue(M=1.)
151
152 def setInitialTracer(self,C):
153 """
154 Same as `setInitialSolution`.
155 """
156 self.setInitialSolution(C)
157
158 def setValue(self,v=None,given_C_mask=None, k=None):
159 if v!=None:
160 super(Tracer,self).setValue(C=-v)
161 if k!=None:
162 super(Tracer,self).setValue(A=-k*util.kronecker(self.getDomain()))
163 if given_C_mask!=None:
164 super(Tracer,self).setValue(q=given_C_mask)
165
166 def getTracer(self,dt,**kwargs):
167 """
168 Same as `getSolution`.
169 """
170 return self.getSolution(dt,**kwargs)
171

  ViewVC Help
Powered by ViewVC 1.1.26