source: inundation-numpy-branch/fit_interpolate/benchmark_least_squares.py @ 3514

Last change on this file since 3514 was 3514, checked in by duncan, 18 years ago

Hi all,
I'm doing a change in the anuga structure, moving the code to

\anuga_core\source\anuga

After you have done an svn update, the PYTHONPATH has to be changed to;
PYTHONPATH = anuga_core/source/

This is part of changes required to make installation of anuga quicker and reducing the size of our sandpits.

If any imports are broken, try fixing them. With adding anuga. to them for example. If this seems to have really broken things, email/phone me.

Cheers
Duncan

File size: 4.2 KB
Line 
1"""Least squares smooting and interpolation.
2
3   measure the speed of least squares.
4
5   ________________________
6   General comments
7   
8   The max_points_per_cell does effect the time spent solving a
9   problem.  The best value to use is probably dependent on the number
10   of triangles.  Maybe develop a simple imperical algorithm, based on
11   test results.
12   
13   Duncan Gray
14   Geoscience Australia, 2004.
15"""
16
17
18import os
19import sys
20import time
21from random import seed, random
22
23from anuga.pyvolution.least_squares import Interpolation
24from pmesh.mesh import Mesh
25
26def mem_usage():
27    '''
28    returns the rss.
29
30  RSS  The total amount of physical memory used by  the  task,  in  kilo-
31            bytes,  is  shown  here.  For ELF processes used library pages are
32            counted here, for a.out processes not.
33           
34    Only works on nix systems.
35    '''
36    import string
37    p=os.popen('ps uwp %s'%os.getpid()) 
38    lines=p.readlines()
39    #print "lines", lines
40    status=p.close() 
41    if status or len(lines)!=2 or sys.platform == 'win32': 
42        return None 
43    return int(string.split(lines[1])[4]) 
44
45
46
47
48class BenchmarkLeastSquares:
49
50
51    def __init__(self):
52        pass
53
54    def trial(self,
55              num_of_points=20000,
56              maxArea=1000,
57              max_points_per_cell=4,
58              is_fit=True,
59              save=False):
60        '''
61        num_of_points
62        '''
63       
64        #print "num_of_points",num_of_points
65        #print "maxArea",maxArea
66        #print "max_points_per_cell", max_points_per_cell
67
68        # make a mesh
69        # pretty regular size, with some segments thrown in.
70        m = Mesh()
71        m.addUserVertex(0,0)
72        m.addUserVertex(1.0,0)
73        m.addUserVertex(0,1.0)
74        m.addUserVertex(1.0,1.0)
75       
76        m.auto_segment(alpha = 100 )
77       
78        dict = {}
79        dict['points'] = [[.10,.10],[.90,.20]]
80        dict['segments'] = [[0,1]] 
81        dict['segment_tags'] = ['wall1']   
82        m.addVertsSegs(dict)
83   
84        dict = {}
85        dict['points'] = [[.10,.90],[.40,.20]]
86        dict['segments'] = [[0,1]] 
87        dict['segment_tags'] = ['wall2']   
88        m.addVertsSegs(dict)
89       
90        dict = {}
91        dict['points'] = [[.20,.90],[.60,.60]]
92        dict['segments'] = [[0,1]] 
93        dict['segment_tags'] = ['wall3'] 
94        m.addVertsSegs(dict)
95       
96        dict = {}
97        dict['points'] = [[.60,.20],[.90,.90]]
98        dict['segments'] = [[0,1]] 
99        dict['segment_tags'] = ['wall4']   
100        m.addVertsSegs(dict)
101
102        m.generateMesh(mode = "Q", maxArea = maxArea)       
103        if save is True:
104            m.export_mesh_file("aaaa.tsh")
105        mesh_dict =  m.Mesh2IOTriangulationDict()
106        #print "mesh_dict",mesh_dict
107        points = []
108        point_atts = []
109        vertex_atts = []
110
111             
112           
113        for point in range(num_of_points):
114            points.append([random()*100, random()*100])
115            point_atts.append(10.0)
116
117        # There has to be a better way of doing this..
118        for vertex in mesh_dict['vertices']:
119            vertex_atts.append(10.0)
120           
121        #Initial time and memory
122        t0 = time.time()
123        #m0 = None on windows
124        m0 = mem_usage()
125
126        interp = Interpolation(mesh_dict['vertices'],
127                               mesh_dict['triangles'], points,
128                               alpha=0.2, expand_search=True,
129                               verbose = False,
130                               max_points_per_cell = 4)
131        if is_fit is True:
132            calc = interp.fit_points(point_atts)
133
134        else:
135            # run an interploate problem.
136            print "Interpolate!"
137            calc = interp.interpolate(vertex_atts)
138           
139        time_taken_sec = (time.time()-t0)
140        m1 = mem_usage()
141        if m0 is None or m1 is None:
142            memory_used = None
143        else:
144            memory_used = (m1 - m0)
145        #print 'That took %.2f seconds' %time_taken_sec
146        return time_taken_sec, memory_used, len(mesh_dict['triangles'])
Note: See TracBrowser for help on using the repository browser.