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