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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (hide annotations)
Tue Aug 23 01:24:31 2005 UTC (17 years, 7 months ago) by jgs
Original Path: trunk/esys2/modellib/py_src/input.py
File MIME type: text/x-python
File size: 9478 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-08-23

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