/[escript]/trunk/modellib/py_src/input.py
ViewVC logotype

Contents of /trunk/modellib/py_src/input.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 720 - (show annotations)
Thu Apr 27 10:16:05 2006 UTC (16 years, 11 months ago) by gross
File MIME type: text/x-python
File size: 9717 byte(s)
formatting errors in epydoc tags fixed
1 # $Id$
2
3 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4 http://www.access.edu.au
5 Primary Business: Queensland, Australia"""
6 __license__="""Licensed under the Open Software License version 3.0
7 http://www.opensource.org/licenses/osl-3.0.php"""
8
9 from esys.escript import *
10 from esys.escript.modelframe import Model,ParameterSet
11 from math import log
12
13 class Sequencer(Model):
14 """
15 Runs through time until t_end is reached.
16 @cvar t_end: - model is terminated when t_end is passed (exposed in writeXML)
17 @type t_end: float
18 @cvar dt_max: - maximum time step size
19 @type dt_max: float
20 @cvar t: - initial time
21 @type t: float
22
23 """
24 def __init__(self,debug=False):
25 """
26 """
27 super(Sequencer,self).__init__(debug=debug)
28 self.declareParameter(t=0.,
29 t_end=1.,
30 dt_max=Model.UNDEF_DT)
31
32 def doInitialization(self):
33 """
34 initialize time integration
35 """
36 self.__t_old = self.t
37
38 def doStepPreprocessing(self, dt):
39 self.t = self.__t_old+dt
40
41 def doStepPostprocessing(self, dt):
42 self.__t_old = self.t
43
44 def finalize(self):
45 """
46 true when t has reached t_end
47 """
48 return self.t >= self.t_end
49
50 def getSafeTimeStepSize(self, dt):
51 """
52 returns dt_max
53 """
54 return self.dt_max
55
56 class GaussianProfile(ParameterSet):
57 """
58 Generates a Gaussian profile at center x_c, width width and height A
59 over a domain
60
61 @ivar domain (in): domain
62 @ivar x_c (in): center of the Gaussian profile (default [0.,0.,0.])
63 @ivar A (in): height of the profile. A maybe a vector. (default 1.)
64 @ivar width (in): width of the profile (default 0.1)
65 @ivar r (in): radius of the circle (default = 0)
66 @ivar out (callable): profile
67
68 In the case that the spatial dimension is two, The third component of
69 x_c is dropped
70 """
71 def __init__(self,debug=False):
72 ParameterSet.__init__(self,debug=debug)
73 self.declareParameter(domain=None,
74 x_c=numarray.zeros([3]),
75 A=1.,
76 width=0.1,
77 r=0)
78
79 def out(self):
80 """
81 Generate the Gaussian profile
82 """
83 x = self.domain.getX()
84 dim = self.domain.getDim()
85 l = length(x-self.x_c[:dim])
86 m = whereNegative(l-self.r)
87
88 return (m+(1.-m)*exp(-log(2.)*(l/self.width)**2))*self.A
89
90 class InterpolateOverBox(ParameterSet):
91 """
92 Returns values at each time. The values are defined through given values
93 at time node.
94
95 @ivar domain (in): domain
96 @ivar left_bottom_front (in): coordinates of left, bottom, front corner
97 of the box
98 @ivar right_top_back (in): coordinates of the right, top, back corner
99 of the box
100 @ivar value_left_bottom_front (in): value at left,bottom,front corner
101 @ivar value_right_bottom_front (in): value at right, bottom, front corner
102 @ivar value_left_top_front (in): value at left,top,front corner
103 @ivar value_right_top_front (in): value at right,top,front corner
104 @ivar value_left_bottom_back (in): value at left,bottom,back corner
105 @ivar value_right_bottom_back (in): value at right,bottom,back corner
106 @ivar value_left_top_back (in): value at left,top,back corner
107 @ivar value_right_top_back (in): value at right,top,back corner
108 @ivar out (callable): values at domain locations by bilinear
109 interpolation. For two dimensional domains back values are
110 ignored.
111 """
112
113 def __init__(self, debug=False):
114 ParameterSet.__init__(self, debug=debug)
115 self.declareParameter(domain=None,
116 left_bottom_front=[0.,0.,0.],
117 right_top_back=[1.,1.,1.],
118 value_left_bottom_front=0.,
119 value_right_bottom_front=0.,
120 value_left_top_front=0.,
121 value_right_top_front=0.,
122 value_left_bottom_back=0.,
123 value_right_bottom_back=0.,
124 value_left_top_back=0.,
125 value_right_top_back=0.)
126
127
128 def out(self):
129 x = self.domain.getX()
130 if self.domain.getDim() == 2:
131 f_right = (x[0] - self.left_bottom_front[0])/\
132 (self.right_top_back[0] - self.left_bottom_front[0])
133 f_left = 1. - f_right
134 f_top = (x[1] - self.left_bottom_front[1])/\
135 (self.right_top_back[1] - self.left_bottom_front[1])
136 f_bottom = 1. - f_top
137 out = self.value_left_bottom_front * f_left * f_bottom \
138 + self.value_right_bottom_front* f_right * f_bottom \
139 + self.value_left_top_front * f_left * f_top \
140 + self.value_right_top_front * f_right * f_top
141 else:
142 f_right = (x[0] - self.left_bottom_front[0])/\
143 (self.right_top_back[0] - self.left_bottom_front[0])
144 f_left = 1. - f_right
145 f_top = (x[1] - self.left_bottom_front[1])/\
146 (self.right_top_back[1] - self.left_bottom_front[1])
147 f_bottom = 1. - f_top
148 f_back = (x[2] - self.left_bottom_front[1])/\
149 (self.right_top_back[2] - self.left_bottom_front[2])
150 f_front = 1. - f_back
151 out = self.value_left_bottom_front * f_left * f_bottom * f_front \
152 + self.value_right_bottom_front* f_right * f_bottom * f_front \
153 + self.value_left_top_front * f_left * f_top * f_front \
154 + self.value_right_top_front * f_right * f_top * f_front \
155 + self.value_left_bottom_back * f_left * f_bottom * f_back \
156 + self.value_right_bottom_back * f_right * f_bottom * f_back \
157 + self.value_left_top_back * f_left * f_top * f_back \
158 + self.value_right_top_back * f_right * f_top * f_back
159 return out
160
161
162 class InterpolatedTimeProfile(ParameterSet):
163 """
164
165 Returns values at each time. The values are defined through given
166 values at time node.
167
168 value[i] defines the value at time nodes[i]. Between nodes linear
169 interpolation is used.
170
171 For time t<nodes[0], value[0] is used and for t>nodes[l], values[l]
172 is used where l=len(nodes)-1.
173
174 @ivar t (in): current time
175 @ivar node (in): list of time nodes
176 @ivar values (in): list of values at time nodes
177 @ivar out (callable): current value
178 """
179
180 def __init__(self,debug=False):
181 ParameterSet.__init__(self,debug=debug)
182 self.declareParameter(t=0., \
183 nodes=[0.,1.],\
184 values=[1.,1.])
185 def out(self):
186 l = len(self.nodes) - 1
187 t = self.t
188 if t <= self.nodes[0]:
189 return self.values[0]
190 else:
191 for i in range(1,l):
192 if t < self.nodes[i]:
193 m = (self.values[i-1] - self.values[i])/\
194 (self.nodes[i-1] - self.nodes[i])
195 return m*(t-self.nodes[i-1]) + self.values[i-1]
196 return self.values[l]
197
198 class LinearCombination(Model):
199 """
200 Returns a linear combination of the f0*v0+f1*v1+f2*v2+f3*v3+f4*v4
201
202 @ivar f0 (in): numerical object or None (default: None)
203 @ivar v0 (in): numerical object or None (default: None)
204 @ivar f1 (in): numerical object or None (default: None)
205 @ivar v1 (in): numerical object or None (default: None)
206 @ivar f2 (in): numerical object or None (default: None)
207 @ivar v2 (in): numerical object or None (default: None)
208 @ivar f3 (in): numerical object or None (default: None)
209 @ivar v3 (in): numerical object or None (default: None)
210 @ivar f4 (in): numerical object or None (default: None)
211 @ivar v4 (in): numerical object or None (default: None)
212 @ivar out (callable): current value
213 """
214 def __init__(self,debug=False):
215 Model.__init__(self,debug=debug)
216 self.declareParameter(f0=None, \
217 v0=None, \
218 f1=None, \
219 v1=None, \
220 f2=None, \
221 v2=None, \
222 f3=None, \
223 v3=None, \
224 f4=None, \
225 v4=None)
226
227 def out(self):
228 if not self.f0 == None and not self.v0 == None:
229 fv0 = self.f0*self.v0
230 else:
231 fv0 = None
232
233 if not self.f1 == None and not self.v1 == None:
234 fv1 = self.f1*self.v1
235 else:
236 fv1 = None
237
238 if not self.f2 == None and not self.v2 == None:
239 fv2 = f2*v2
240 else:
241 fv2 = None
242
243 if not self.f3 == None and not self.v3 == None:
244 fv3 = self.f3*self.v3
245 else:
246 fv3 = None
247
248 if not self.f4 == None and not self.v4 == None:
249 fv4 = self.f4*self.v4
250 else:
251 fv4 = None
252
253 if fv0 == None:
254 out = 0.
255 else:
256 out = fv0
257 if not fv1 == None:
258 out += fv1
259 if not fv2 == None:
260 out += fv2
261 if not fv3 == None:
262 out += fv3
263 return out
264
265 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26