/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 7 months ago) by jfenwick
File MIME type: text/x-python
File size: 3760 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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-2008 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 import util
37 from linearPDEs import TransportPDE
38
39 class TemperatureCartesian(TransportPDE):
40 """
41 Represents and solves the temperature advection-diffusion problem
42
43 M{rhocp(T_{,t} + v_i T_{,i} - ( k T_{,i})_i = Q}
44
45 M{k T_{,i}*n_i=surface_flux} and M{T_{,t} = 0} where C{given_T_mask}>0.
46
47 If surface_flux is not given 0 is assumed.
48
49 Typical usage::
50
51 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 def __init__(self,domain,useBackwardEuler=False,**kwargs):
63 """
64 Initializes the temperature advection-diffusion problem.
65
66 @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: C{bool}
69 """
70 TransportPDE.__init__(self,domain,numEquations=1,useBackwardEuler=useBackwardEuler,**kwargs)
71 self.setReducedOrderOn()
72 self.__rhocp=None
73 self.__v=None
74
75 def setInitialTemperature(self,T):
76 """
77 Same as L{setInitialSolution}.
78 """
79 self.setInitialSolution(T)
80
81 def setValue(self,rhocp=None,v=None,k=None,Q=None,surface_flux=None,given_T_mask=None):
82 if rhocp!=None:
83 self.__rhocp=rhocp
84 if v!=None:
85 self.__v=v
86 if rhocp!=None:
87 super(TemperatureCartesian,self).setValue(M=self.__rhocp)
88 if (rhocp!=None or v!=None) and self.__rhocp!=None and self.__v!=None:
89 super(TemperatureCartesian,self).setValue(C=-self.__rhocp*self.__v)
90 if k!=None:
91 super(TemperatureCartesian,self).setValue(A=-k*util.kronecker(self.getDomain()))
92 if Q!=None:
93 super(TemperatureCartesian,self).setValue(Y=Q)
94 if surface_flux!=None:
95 super(TemperatureCartesian,self).setValue(y=surface_flux)
96 if given_T_mask!=None:
97 super(TemperatureCartesian,self).setValue(q=given_T_mask)
98
99 def getTemperature(self,dt,**kwargs):
100 """
101 Same as L{getSolution}.
102 """
103 return self.getSolution(dt,**kwargs)
104

  ViewVC Help
Powered by ViewVC 1.1.26