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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3372 - (hide annotations)
Mon Nov 22 23:10:03 2010 UTC (11 years, 8 months ago) by caltinay
File MIME type: text/x-python
File size: 2194 byte(s)
Added missing import to fix unit test

1 jfenwick 2646
2     ########################################################
3     #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 jfenwick 2646 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 jfenwick 2646 Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20     __url__="https://launchpad.net/escript-finley"
21    
22    
23    
24     # This example demonstrates both interpolation and saving data in CSV format
25    
26 caltinay 3372 from esys.escript import saveDataCSV, sup, interpolateTable
27 jfenwick 2646 import numpy
28     from esys.finley import Rectangle
29    
30     n=4 #Change this to whatever you like
31     r=Rectangle(n,n)
32     x=r.getX()
33     x0=x[0]
34     x1=x[1] #we'll use this later
35     toobig=100 #An exception will be thrown if interpolation produces a value larger than this
36    
37     #First one dimensional interpolation
38    
39     #In this example we will interpolate a sine curve
40     #The values we take from the domain will range from 0 to 1 (inclusive)
41    
42 jfenwick 2677 sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0, -0.70710678118654746, -1, -0.70710678118654746, 0]
43 jfenwick 2646
44     numslices=len(sine_table)-1
45    
46     minval=0
47 jfenwick 2677 maxval=1
48 jfenwick 2646
49     step=sup(maxval-minval)/numslices #The width of the gap between entries in the table
50    
51 jfenwick 3368 result=interpolateTable(sine_table, x0, minval, step, toobig)
52 jfenwick 2646
53     #Now we save the input and output for comparison
54    
55     saveDataCSV("1d.csv", inp=x0, out=result)
56    
57     #Now 2D interpolation
58    
59     #This time the sine curve will be at full height along the x (ie x0) axis.
60     #Its amplitude will decrease to a flat line along x1=1.1
61    
62     #Interpolate works with numpy arrays so we'll use them
63 jfenwick 2677 st=numpy.array(sine_table)
64 jfenwick 2646
65 jfenwick 2677 table=[st, 0.5*st, 0*st ] #Note that this table is 2D
66 jfenwick 2646
67 jfenwick 3368 #The y dimension should be the outer the dimension of the table
68 caltinay 3372 result2=interpolateTable(table, x, (minval,0), (0.55, step), toobig)
69     saveDataCSV("2d.csv",inp0=x0, inp2=x1, out=result2)

  ViewVC Help
Powered by ViewVC 1.1.26