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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 323 by gross, Tue Dec 6 06:18:00 2005 UTC revision 904 by gross, Fri Nov 17 08:49:44 2006 UTC
# Line 1  Line 1 
1  # $Id$  # $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 *  from esys.escript import *
10  from esys.escript.modelframe import Model,ParameterSet  from esys.escript.modelframe import Model,ParameterSet
11  from math import log  from math import log
12    
13  class Sequencer(Model):  class Sequencer(Model):
14      """      """
15      Runs through time until t_end is reached.      Runs through time until t_end is reached.
16    
17        @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      """      """
25      def __init__(self,t=0.,t_end=Model.UNDEF_DT,dt_max=Model.UNDEF_DT,debug=False):      def __init__(self,debug=False):
26          """          """
         @param t_end: - model is terminated when t_end is passed    
                    (exposed in writeXML)  
         @type t_end: float  
         @param dt_max: - maximum time step size  
         @type dt_max: float  
         @param t: - initial time  
         @type t: float  
   
27          """          """
28          Model.__init__(self,debug=debug)          super(Sequencer,self).__init__(debug=debug)
29          self.declareParameter(t=t,          self.declareParameter(t=0.,
30                                t_end=t_end,                                t_end=1.,
31                                dt_max=dt_max)                                dt_max=Model.UNDEF_DT)
32    
33      def doInitialization(self):      def doInitialization(self):
34          """          """
# Line 37  class Sequencer(Model): Line 44  class Sequencer(Model):
44    
45      def finalize(self):      def finalize(self):
46          """          """
47          true when t has reached t_end          returns true when L{t} has reached L{t_end}
48          """          """
49          return self.t >= self.t_end          return self.t >= self.t_end
50    
51      def getSafeTimeStepSize(self, dt):      def getSafeTimeStepSize(self, dt):
52          """          """
53          returns dt_max          returns L{dt_max}
54          """          """
55          return self.dt_max          return self.dt_max
56    
# Line 52  class GaussianProfile(ParameterSet): Line 59  class GaussianProfile(ParameterSet):
59      Generates a Gaussian profile at center x_c, width width and height A      Generates a Gaussian profile at center x_c, width width and height A
60      over a domain      over a domain
61    
62      @ivar domain (in): domain      @ivar domain: domain
63      @ivar x_c (in): center of the Gaussian profile (default [0.,0.,0.])      @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.)      @ivar A: (in) height of the profile. A maybe a vector. (default 1.)
65      @ivar width (in): width of the profile (default 0.1)      @ivar width: (in) width of the profile (default 0.1)
66      @ivar r (in): radius of the circle (default = 0)      @ivar r: (in) radius of the circle (default = 0)
     @ivar out (callable): profile  
67    
68      In the case that the spatial dimension is two, The third component of      In the case that the spatial dimension is two, The third component of
69      x_c is dropped      x_c is dropped.
70      """      """
71      def __init__(self,debug=False):      def __init__(self,debug=False):
72          ParameterSet.__init__(self,debug=debug)          ParameterSet.__init__(self,debug=debug)
# Line 73  class GaussianProfile(ParameterSet): Line 79  class GaussianProfile(ParameterSet):
79      def out(self):      def out(self):
80          """          """
81          Generate the Gaussian profile          Generate the Gaussian profile
82    
83            Link against this method to get the output of this model.
84          """          """
85          x = self.domain.getX()          x = self.domain.getX()
86          dim = self.domain.getDim()          dim = self.domain.getDim()
# Line 84  class GaussianProfile(ParameterSet): Line 92  class GaussianProfile(ParameterSet):
92  class InterpolateOverBox(ParameterSet):  class InterpolateOverBox(ParameterSet):
93      """      """
94      Returns values at each time. The values are defined through given values      Returns values at each time. The values are defined through given values
95      at time node.      at time node. For two dimensional domains back values are ignored.
96    
97      @ivar domain (in): domain      @ivar domain: domain
98      @ivar left_bottom_front (in): coordinates of left, bottom, front corner      @ivar value_left_bottom_front: (in) value at left,bottom,front corner
99                of the box      @ivar value_right_bottom_front: (in) value at right, bottom, front corner
100      @ivar right_top_back (in): coordinates of the right, top, back corner      @ivar value_left_top_front: (in) value at left,top,front corner
101                of the box      @ivar value_right_top_front: (in) value at right,top,front corner
102      @ivar value_left_bottom_front (in): value at left,bottom,front corner      @ivar value_left_bottom_back: (in) value at  left,bottom,back corner
103      @ivar value_right_bottom_front (in): value at right, bottom, front corner      @ivar value_right_bottom_back: (in) value at right,bottom,back corner
104      @ivar value_left_top_front (in): value at left,top,front corner      @ivar value_left_top_back: (in) value at left,top,back  corner
105      @ivar value_right_top_front (in): value at right,top,front corner      @ivar value_right_top_back: (in) value at right,top,back corner
     @ivar value_left_bottom_back (in): value at  left,bottom,back corner  
     @ivar value_right_bottom_back (in): value at right,bottom,back corner  
     @ivar value_left_top_back (in): value at left,top,back  corner  
     @ivar value_right_top_back (in): value at right,top,back corner  
     @ivar out (callable): values at domain locations by bilinear  
               interpolation.  For two dimensional domains back values are  
               ignored.  
106      """      """
107    
108      def __init__(self, debug=False):      def __init__(self, debug=False):
109          ParameterSet.__init__(self, debug=debug)          ParameterSet.__init__(self, debug=debug)
110          self.declareParameter(domain=None,          self.declareParameter(domain=None,
                               left_bottom_front=[0.,0.,0.],  
                               right_top_back=[1.,1.,1.],  
111                                value_left_bottom_front=0.,                                value_left_bottom_front=0.,
112                                value_right_bottom_front=0.,                                value_right_bottom_front=0.,
113                                value_left_top_front=0.,                                value_left_top_front=0.,
# Line 120  class InterpolateOverBox(ParameterSet): Line 119  class InterpolateOverBox(ParameterSet):
119    
120    
121      def out(self):      def out(self):
122            """
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          x = self.domain.getX()          x = self.domain.getX()
128          if self.domain.getDim() == 2:          if self.domain.getDim() == 2:
129              f_right = (x[0] - self.left_bottom_front[0])/\              x0,x1=x[0],x[1]
130           (self.right_top_back[0] - self.left_bottom_front[0])              left_bottom_front0,right_top_back0=inf(x0),sup(x0)
131                left_bottom_front1,right_top_back1=inf(x1),sup(x1)
132                f_right = (x0 - left_bottom_front0)/(right_top_back0 -left_bottom_front0)
133              f_left = 1. - f_right              f_left = 1. - f_right
134              f_top = (x[1] - self.left_bottom_front[1])/\              f_top = (x1 - left_bottom_front1)/(right_top_back1 - left_bottom_front1)
          (self.right_top_back[1] - self.left_bottom_front[1])  
135              f_bottom = 1. - f_top              f_bottom = 1. - f_top
136              out = self.value_left_bottom_front * f_left * f_bottom \              out = f_left * f_bottom * self.value_left_bottom_front \
137                  + self.value_right_bottom_front* f_right * f_bottom \                  + f_right * f_bottom * self.value_right_bottom_front \
138                  + self.value_left_top_front    * f_left * f_top \                  + f_left * f_top * self.value_left_top_front \
139                  + self.value_right_top_front   * f_right * f_top                  + f_right * f_top * self.value_right_top_front
140          else:          else:
141              f_right = (x[0] - self.left_bottom_front[0])/\              x0,x1,x2=x[0],x[1],x[2]
142                      (self.right_top_back[0] - self.left_bottom_front[0])              left_bottom_front0,right_top_back0=inf(x0),sup(x0)
143                left_bottom_front1,right_top_back1=inf(x1),sup(x1)
144                left_bottom_front2,right_top_back2=inf(x2),sup(x2)
145                f_right = (x0 - left_bottom_front0)/(right_top_back0 - left_bottom_front0)
146              f_left = 1. - f_right              f_left = 1. - f_right
147              f_top = (x[1] - self.left_bottom_front[1])/\              f_top = (x1 - left_bottom_front1)/(right_top_back1 - left_bottom_front1)
                     (self.right_top_back[1] - self.left_bottom_front[1])  
148              f_bottom = 1. - f_top              f_bottom = 1. - f_top
149              f_back = (x[2] - self.left_bottom_front[1])/\              f_back = (x2 - left_bottom_front1)/(right_top_back2 - left_bottom_front2)
                     (self.right_top_back[2] - self.left_bottom_front[2])  
150              f_front = 1. - f_back              f_front = 1. - f_back
151              out = self.value_left_bottom_front * f_left * f_bottom * f_front \              out = f_left * f_bottom * f_front * self.value_left_bottom_front\
152                  + self.value_right_bottom_front* f_right * f_bottom * f_front \                  + f_right * f_bottom * f_front * self.value_right_bottom_front\
153                  + self.value_left_top_front    * f_left * f_top * f_front \                  + f_left * f_top * f_front * self.value_left_top_front\
154                  + self.value_right_top_front   * f_right * f_top * f_front \                  + f_right * f_top * f_front * self.value_right_top_front\
155                  + self.value_left_bottom_back  * f_left * f_bottom * f_back \                  + f_left * f_bottom * f_back * self.value_left_bottom_back\
156                  + self.value_right_bottom_back * f_right * f_bottom * f_back \                  + f_right * f_bottom * f_back * self.value_right_bottom_back\
157                  + self.value_left_top_back     * f_left * f_top * f_back \                  + f_left * f_top * f_back * self.value_left_top_back\
158                  + self.value_right_top_back    * f_right * f_top * f_back                  + f_right * f_top * f_back * self.value_right_top_back
159          return out          return out
160    
161    
# Line 165  class InterpolatedTimeProfile(ParameterS Line 171  class InterpolatedTimeProfile(ParameterS
171         For time t<nodes[0], value[0] is used and for t>nodes[l], values[l]         For time t<nodes[0], value[0] is used and for t>nodes[l], values[l]
172         is used where l=len(nodes)-1.         is used where l=len(nodes)-1.
173    
174         @ivar t (in): current time         @ivar t: (in) current time
175         @ivar node (in): list of time nodes         @ivar node: (in) list of time nodes
176         @ivar values (in): list of values at time nodes         @ivar values: (in) list of values at time nodes
        @ivar out (callable): current value  
177         """         """
178    
179         def __init__(self,debug=False):         def __init__(self,debug=False):
# Line 177  class InterpolatedTimeProfile(ParameterS Line 182  class InterpolatedTimeProfile(ParameterS
182                                   nodes=[0.,1.],\                                   nodes=[0.,1.],\
183                                   values=[1.,1.])                                   values=[1.,1.])
184         def out(self):         def out(self):
185               """
186               current value
187      
188               Link against this method to get the output of this model.
189               """
190             l = len(self.nodes) - 1             l = len(self.nodes) - 1
191             t = self.t             t = self.t
192             if t <= self.nodes[0]:             if t <= self.nodes[0]:
# Line 189  class InterpolatedTimeProfile(ParameterS Line 199  class InterpolatedTimeProfile(ParameterS
199                        return m*(t-self.nodes[i-1]) + self.values[i-1]                        return m*(t-self.nodes[i-1]) + self.values[i-1]
200                 return self.values[l]                 return self.values[l]
201    
202  class LinearCombination(Model):  class ScalarDistributionFromTags(ParameterSet):
203        """
204        creates a scalar distribution on a domain from tags
205                
206        @ivar domain: domain
207        @type domain: L{esys.escript.Domain}
208        @ivar default: default value
209        @ivar tag0: tag 0
210        @type tag0: C{int}
211        @ivar value0: value for tag 0
212        @type value0: C{float}
213        @ivar tag1: tag 1
214        @type tag1: C{int}
215        @ivar value1: value for tag 1
216        @type value1: C{float}
217        @ivar tag2: tag 2
218        @type tag2: C{int}
219        @ivar value2: value for tag 2
220        @type value2: C{float}
221        @ivar tag3: tag 3
222        @type tag3: C{int}
223        @ivar value3: value for tag 3
224        @type value3: C{float}
225        @ivar tag4: tag 4
226        @type tag4: C{int}
227        @ivar value4: value for tag 4
228        @type value4: C{float}
229        @ivar tag5: tag 5
230        @type tag5: C{int}
231        @ivar value5: value for tag 5
232        @type value5: C{float}
233        @ivar tag6: tag 6
234        @type tag6: C{int}
235        @ivar value6: value for tag 6
236        @type value6: C{float}
237        @ivar tag7: tag 7
238        @type tag7: C{int}
239        @ivar value7: value for tag 7
240        @type value7: C{float}
241        @ivar tag8: tag 8
242        @type tag8: C{int}
243        @ivar value8: value for tag 8
244        @type value8: C{float}
245        @ivar tag9: tag 9
246        @type tag9: C{int}
247        @ivar value9: value for tag 9
248        @type value9: C{float}
249        """
250        def __init__(self,debug=False):
251            super(ScalarDistributionFromTags, self).__init__(debug=debug)
252            self.declareParameter(domain=None,
253                                  default=0.,
254                                  tag0=None,
255                                  value0=0.,
256                                  tag1=None,
257                                  value1=0.,
258                                  tag2=None,
259                                  value2=0.,
260                                  tag3=None,
261                                  value3=0.,
262                                  tag4=None,
263                                  value4=0.,
264                                  tag5=None,
265                                  value5=0.,
266                                  tag6=None,
267                                  value6=0.,
268                                  tag7=None,
269                                  value7=0.,
270                                  tag8=None,
271                                  value8=0.,
272                                  tag9=None,
273                                  value9=0.)
274    
275    
276        def out(self):
277            """
278            returns a L{esys.escript.Data} object
279            Link against this method to get the output of this model.
280            """
281            d=Scalar(self.default,Function(self.domain))
282            if not self.tag0 == None: d.setTaggedValue(self.tag0,self.value0)
283            if not self.tag1 == None: d.setTaggedValue(self.tag1,self.value1)
284            if not self.tag2 == None: d.setTaggedValue(self.tag2,self.value2)
285            if not self.tag3 == None: d.setTaggedValue(self.tag3,self.value3)
286            if not self.tag4 == None: d.setTaggedValue(self.tag4,self.value4)
287            if not self.tag5 == None: d.setTaggedValue(self.tag5,self.value5)
288            if not self.tag6 == None: d.setTaggedValue(self.tag6,self.value6)
289            if not self.tag7 == None: d.setTaggedValue(self.tag7,self.value7)
290            if not self.tag8 == None: d.setTaggedValue(self.tag8,self.value8)
291            if not self.tag9 == None: d.setTaggedValue(self.tag9,self.value9)
292            return d
293    
294    class LinearCombination(ParameterSet):
295      """      """
296      Returns a linear combination of the f0*v0+f1*v1+f2*v2+f3*v3+f4*v4      Returns a linear combination of the f0*v0+f1*v1+f2*v2+f3*v3+f4*v4
297                            
298      @ivar f0 (in): numerical object or None (default: None)      @ivar f0: numerical object or None, default=None (in)
299      @ivar v0 (in): numerical object or None (default: None)      @ivar v0: numerical object or None, default=None (in)
300      @ivar f1 (in): numerical object or None (default: None)      @ivar f1: numerical object or None, default=None (in)
301      @ivar v1 (in): numerical object or None (default: None)      @ivar v1: numerical object or None, default=None (in)
302      @ivar f2 (in): numerical object or None (default: None)      @ivar f2: numerical object or None, default=None (in)
303      @ivar v2 (in): numerical object or None (default: None)      @ivar v2: numerical object or None, default=None (in)
304      @ivar f3 (in): numerical object or None (default: None)      @ivar f3: numerical object or None, default=None (in)
305      @ivar v3 (in): numerical object or None (default: None)      @ivar v3: numerical object or None, default=None (in)
306      @ivar f4 (in): numerical object or None (default: None)      @ivar f4: numerical object or None, default=None (in)
307      @ivar v4 (in): numerical object or None (default: None)      @ivar v4: numerical object or None, default=None (in)
     @ivar out (callable): current value  
308      """      """
309      def __init__(self,debug=False):      def __init__(self,debug=False):
310          Model.__init__(self,debug=debug)          Model.__init__(self,debug=debug)
# Line 219  class LinearCombination(Model): Line 320  class LinearCombination(Model):
320                                v4=None)                                v4=None)
321    
322      def out(self):      def out(self):
323            """
324            returns f0*v0+f1*v1+f2*v2+f3*v3+f4*v4.
325            Link against this method to get the output of this model.
326            """
327          if not self.f0 == None and not self.v0 == None:          if not self.f0 == None and not self.v0 == None:
328              fv0 = self.f0*self.v0              fv0 = self.f0*self.v0
329          else:          else:
# Line 256  class LinearCombination(Model): Line 361  class LinearCombination(Model):
361              out += fv3              out += fv3
362          return out          return out
363    
364    class MergeConstraints(ParameterSet):
365        """
366        Returns a linear combination of the f0*v0+f1*v1+f2*v2+f3*v3+f4*v4
367        """
368        def __init__(self,debug=False):
369            super(MergeConstraints, self).__init__(debug=debug)
370            self.declareParameter(location_of_constraint0=None, \
371                                  value_of_constraint0=None, \
372                                  location_of_constraint1=None, \
373                                  value_of_constraint1=None, \
374                                  location_of_constraint2=None, \
375                                  value_of_constraint2=None, \
376                                  location_of_constraint3=None, \
377                                  value_of_constraint3=None, \
378                                  location_of_constraint4=None, \
379                                  value_of_constraint4=None)
380        def location_of_constraint(self):
381              """
382              return the values used to constrain a solution
383    
384              @return: the mask marking the locations of the constraints
385              @rtype: L{escript.Vector}
386              """
387              out_loc=0
388              if not self.location_of_constraint0 == None and not self.value_of_constraint0== None:
389                   out_loc=wherePositive(out_loc+wherePositive(self.location_of_constraint0))
390              if not self.location_of_constraint1 == None and not self.value_of_constraint1== None:
391                   out_loc=wherePositive(out_loc+wherePositive(self.location_of_constraint1))
392              if not self.location_of_constraint2 == None and not self.value_of_constraint2== None:
393                   out_loc=wherePositive(out_loc+wherePositive(self.location_of_constraint2))
394              if not self.location_of_constraint3 == None and not self.value_of_constraint3== None:
395                   out_loc=wherePositive(out_loc+wherePositive(self.location_of_constraint3))
396              return out_loc
397    
398        def value_of_constraint(self):
399              """
400              return the values used to constrain a solution
401    
402              @return: values to be used at the locations of the constraints. If
403                      L{value} is not given C{None} is rerturned.
404              @rtype: L{escript.Vector}
405              """
406              out_loc=0
407              out=0
408              if not self.location_of_constraint0 == None and not self.value_of_constraint0== None:
409                   tmp=wherePositive(self.location_of_constraint0)
410                   out=out*out_loc+self.value_of_constraint0*tmp
411                   out_loc=wherePositive(out_loc+tmp)
412              if not self.location_of_constraint1 == None and not self.value_of_constraint1== None:
413                   tmp=wherePositive(self.location_of_constraint1)
414                   out=out*out_loc+self.value_of_constraint1*tmp
415                   out_loc=wherePositive(out_loc+tmp)
416              if not self.location_of_constraint2 == None and not self.value_of_constraint2== None:
417                   tmp=wherePositive(self.location_of_constraint2)
418                   out=out*out_loc+self.value_of_constraint2*tmp
419                   out_loc=wherePositive(out_loc+tmp)
420              if not self.location_of_constraint3 == None and not self.value_of_constraint3== None:
421                   tmp=wherePositive(self.location_of_constraint3)
422                   out=out*out_loc+self.value_of_constraint3*tmp
423                   out_loc=wherePositive(out_loc+tmp)
424              return out
425  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

Legend:
Removed from v.323  
changed lines
  Added in v.904

  ViewVC Help
Powered by ViewVC 1.1.26