/[escript]/branches/3.4.1/modellib/py_src/input.py
ViewVC logotype

Contents of /branches/3.4.1/modellib/py_src/input.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 628 - (show annotations)
Thu Mar 23 02:27:57 2006 UTC (13 years, 1 month ago) by elspeth
Original Path: trunk/modellib/py_src/input.py
File MIME type: text/x-python
File size: 9764 byte(s)
Copyright information added.

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