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

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

Parent Directory Parent Directory | Revision Log Revision Log


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