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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26