/[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 628 - (hide 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 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     Runs through time until t_end is reached.
16     """
17 gross 423 def __init__(self,debug=False):
18 jgs 148 """
19 jgs 149 @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 jgs 127
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     true when t has reached t_end
48     """
49     return self.t >= self.t_end
50 jgs 147
51 jgs 148 def getSafeTimeStepSize(self, dt):
52     """
53     returns dt_max
54     """
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 jgs 149 @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 jgs 127
69 jgs 148 In the case that the spatial dimension is two, The third component of
70     x_c is dropped
71 jgs 127 """
72     def __init__(self,debug=False):
73 jgs 148 ParameterSet.__init__(self,debug=debug)
74 jgs 147 self.declareParameter(domain=None,
75     x_c=numarray.zeros([3]),
76     A=1.,
77     width=0.1,
78     r=0)
79 jgs 127
80     def out(self):
81 jgs 149 """
82     Generate the Gaussian profile
83     """
84 jgs 148 x = self.domain.getX()
85     dim = self.domain.getDim()
86     l = length(x-self.x_c[:dim])
87 gross 323 m = whereNegative(l-self.r)
88 jgs 148
89 jgs 127 return (m+(1.-m)*exp(-log(2.)*(l/self.width)**2))*self.A
90    
91 jgs 148 class InterpolateOverBox(ParameterSet):
92 jgs 147 """
93 jgs 148 Returns values at each time. The values are defined through given values
94     at time node.
95 jgs 147
96 jgs 149 @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 jgs 147 """
113    
114 jgs 148 def __init__(self, debug=False):
115     ParameterSet.__init__(self, debug=debug)
116 jgs 147 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 jgs 148 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 jgs 147 else:
143 jgs 148 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 jgs 147 return out
161    
162    
163 jgs 148 class InterpolatedTimeProfile(ParameterSet):
164     """
165    
166     Returns values at each time. The values are defined through given
167     values at time node.
168 jgs 147
169 jgs 148 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 jgs 147
175 jgs 149 @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 jgs 148 """
180 jgs 127
181     def __init__(self,debug=False):
182 jgs 148 ParameterSet.__init__(self,debug=debug)
183 jgs 147 self.declareParameter(t=0., \
184     nodes=[0.,1.],\
185     values=[1.,1.])
186     def out(self):
187 jgs 148 l = len(self.nodes) - 1
188     t = self.t
189     if t <= self.nodes[0]:
190     return self.values[0]
191 jgs 147 else:
192     for i in range(1,l):
193 jgs 148 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 jgs 147 return self.values[l]
198 jgs 127
199 jgs 147 class LinearCombination(Model):
200 jgs 148 """
201     Returns a linear combination of the f0*v0+f1*v1+f2*v2+f3*v3+f4*v4
202 jgs 147
203 jgs 149 @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 jgs 148 """
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 jgs 147
228 jgs 148 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 jgs 147
234 jgs 148 if not self.f1 == None and not self.v1 == None:
235     fv1 = self.f1*self.v1
236     else:
237     fv1 = None
238 jgs 147
239 jgs 148 if not self.f2 == None and not self.v2 == None:
240     fv2 = f2*v2
241     else:
242     fv2 = None
243 jgs 147
244 jgs 148 if not self.f3 == None and not self.v3 == None:
245     fv3 = self.f3*self.v3
246     else:
247     fv3 = None
248 jgs 147
249 jgs 148 if not self.f4 == None and not self.v4 == None:
250     fv4 = self.f4*self.v4
251     else:
252     fv4 = None
253 jgs 147
254 jgs 148 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 jgs 147
266 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