/[escript]/trunk/doc/examples/usersguide/int_save.py
ViewVC logotype

Diff of /trunk/doc/examples/usersguide/int_save.py

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

revision 5287 by jfenwick, Wed Apr 9 05:41:57 2014 UTC revision 5288 by sshaw, Tue Dec 2 23:18:40 2014 UTC
# Line 27  __url__="https://launchpad.net/escript-f Line 27  __url__="https://launchpad.net/escript-f
27    
28  from esys.escript import saveDataCSV, sup, interpolateTable  from esys.escript import saveDataCSV, sup, interpolateTable
29  import numpy  import numpy
30  from esys.finley import Rectangle  try:
31        from esys.finley import Rectangle
32        HAVE_FINLEY = True
33    except ImportError:
34        HAVE_FINLEY = False
35    
36  n=4     #Change this to whatever you like  if not HAVE_FINLEY:
37  r=Rectangle(n,n)      print("Finley module not available")
38  x=r.getX()  else:
 x0=x[0]  
 x1=x[1]    #we'll use this later  
 toobig=100  #An exception will be thrown if interpolation produces a value larger than this  
39    
40  #First one dimensional interpolation      n=4     #Change this to whatever you like
41        r=Rectangle(n,n)
42        x=r.getX()
43        x0=x[0]
44        x1=x[1]    #we'll use this later
45        toobig=100  #An exception will be thrown if interpolation produces a value larger than this
46    
47  #In this example we will interpolate a sine curve      #First one dimensional interpolation
 #The values we take from the domain will range from 0 to 1 (inclusive)  
48    
49  sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0, -0.70710678118654746, -1, -0.70710678118654746, 0]      #In this example we will interpolate a sine curve
50        #The values we take from the domain will range from 0 to 1 (inclusive)
51    
52  numslices=len(sine_table)-1      sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0, -0.70710678118654746, -1, -0.70710678118654746, 0]
53    
54  minval=0      numslices=len(sine_table)-1
 maxval=1  
55    
56  step=sup(maxval-minval)/numslices   #The width of the gap between entries in the table      minval=0
57        maxval=1
58    
59  result=interpolateTable(sine_table, x0, minval, step, toobig)      step=sup(maxval-minval)/numslices   #The width of the gap between entries in the table
60    
61  #Now we save the input and output for comparison      result=interpolateTable(sine_table, x0, minval, step, toobig)
62    
63  saveDataCSV("1d.csv", inp=x0, out=result)      #Now we save the input and output for comparison
64    
65  #Now 2D interpolation      saveDataCSV("1d.csv", inp=x0, out=result)
66    
67  #This time the sine curve will be at full height along the x (ie x0) axis.      #Now 2D interpolation
 #Its amplitude will decrease to a flat line along x1=1.1  
68    
69  #Interpolate works with numpy arrays so we'll use them      #This time the sine curve will be at full height along the x (ie x0) axis.
70  st=numpy.array(sine_table)      #Its amplitude will decrease to a flat line along x1=1.1
71    
72  table=[st, 0.5*st, 0*st ]   #Note that this table is 2D      #Interpolate works with numpy arrays so we'll use them
73        st=numpy.array(sine_table)
74    
75  #The y dimension should be the outer the dimension of the table      table=[st, 0.5*st, 0*st ]   #Note that this table is 2D
76  #Note that the order of tuples for the 2nd and 3rd param is (x,y)  
77  result2=interpolateTable(table, x, (minval,0), (0.55, step), toobig)      #The y dimension should be the outer the dimension of the table
78  saveDataCSV("2d.csv",inp0=x0, inp2=x1, out=result2)      #Note that the order of tuples for the 2nd and 3rd param is (x,y)
79        result2=interpolateTable(table, x, (minval,0), (0.55, step), toobig)
80        saveDataCSV("2d.csv",inp0=x0, inp2=x1, out=result2)

Legend:
Removed from v.5287  
changed lines
  Added in v.5288

  ViewVC Help
Powered by ViewVC 1.1.26