Ignore:
Timestamp:
Nov 4, 2005, 5:18:28 PM (19 years ago)
Author:
duncan
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/benchmark_least_squares.py

    r1974 r2004  
    1616
    1717
    18 import unittest
    19 from math import sqrt
     18import os
     19import sys
    2020import time
    21 
     21from random import seed, random
    2222
    2323from pyvolution.least_squares import Interpolation
    24 from Numeric import allclose, array, transpose
    25 import os
    26 import sys
     24from pmesh.mesh import Mesh
    2725
    2826def mem_usage():
     
    4846
    4947
    50 class Test_Least_Squares(unittest.TestCase):
     48class BenchmarkLeastSquares:
    5149
    52     def setUp(self):
     50
     51    def __init__(self):
    5352        pass
    5453
    55     def tearDown(self):
    56         pass
     54    def trial(self,
     55              num_of_points=20000,
     56              maxArea=1000,
     57              max_points_per_cell=4,
     58              save=False):
     59        #print "num_of_points",num_of_points
     60        #print "maxArea",maxArea
     61        #print "max_points_per_cell", max_points_per_cell
    5762
    58     def ztest_expand_search2(self):
    59         from random import seed, random
    60         from pmesh.mesh import Mesh
    61        
    62         seed(2)
    63         m = Mesh()
    64         verts_per_sector = 100 #100
    65         num_of_points = 300
    66         sec_side = 9.0
    67 
    68         vert_atts = []
    69         for vert in range(verts_per_sector):
    70             m.addUserVertex(random()*sec_side, random()*sec_side)
    71             vert_atts.append(random())
    72         for vert in range(verts_per_sector):
    73             m.addUserVertex(90.0+random()*sec_side, 90.0+random()*sec_side)
    74             vert_atts.append(random())
    75         for vert in range(verts_per_sector):
    76             m.addUserVertex(random()*sec_side, 90.0+random()*sec_side)
    77             vert_atts.append(random())
    78         for vert in range(verts_per_sector):
    79             m.addUserVertex(90.0+random()*sec_side, random()*sec_side)
    80             vert_atts.append(random())
    81         #for vert in range(verts_per_sector):
    82         #    m.addUserVertex(40.0+random()*sec_side, 40.0+random()*sec_side)
    83         #    vert_atts.append(random())
    84            
    85         m.autoSegment(alpha = 100 )
    86         m.generateMesh(mode = "Q")
    87         m.export_mesh_file("aaaa.tsh")
    88         mesh_dict =  m.Mesh2IOTriangulationDict()
    89 
    90         points = []
    91         point_atts = []
    92         for point in range(num_of_points):
    93             points.append([random()*100, random()*100])
    94             point_atts.append(10.0)
    95         m.autoSegment(alpha = 100 )
    96 
    97         #print 'points', points
    98         t0 = time.time()
    99 
    100         interp = Interpolation(mesh_dict['vertices'],
    101                                mesh_dict['triangles'], points,
    102                                alpha=0.2, expand_search=True,
    103                                verbose = False,
    104                                max_points_per_cell = 4)
    105         calc = interp.fit_points(point_atts )
    106         #print "interp.expanded_quad_searches", interp.expanded_quad_searches
    107         #print "calc", calc
    108         print 'That took %.2f seconds' %(time.time()-t0)
    109 
    110        
    111     def test_expand_search3(self):
    112         from random import seed, random
    113         from pmesh.mesh import Mesh
    114 
    115         # takes 7.73 seconds
    116         #num_of_points = 20000
    117         #maxArea = 1000
    118         #max_points_per_cell = 4
    119 
    120         # took 9.84 secs
    121         #num_of_points = 20000
    122         #maxArea = 100
    123         #max_points_per_cell = 4
    124 
    125         # 16.61 secs
    126         num_of_points = 20000
    127         maxArea = 10 #836 basis functions
    128         #max_points_per_cell = 4 #16.61 sec
    129        
    130         #max_points_per_cell = 30 #31.17 sec
    131         #max_points_per_cell = 2 #16.125 sec
    132         max_points_per_cell = 8 #17.66 sec
    133 
    134        
    135         # 16.61 secs
    136         num_of_points = 20000
    137         maxArea = 1 #7917 basis functions
    138         max_points_per_cell = 4 # 76.047 sec
    139        
    140         #max_points_per_cell = 30 #
    141         #max_points_per_cell = 2 #78.97 sec
    142         #max_points_per_cell = 16 # 82.33 sec
    143         #max_points_per_cell = 8 #77.984 sec
    144        
    145         # 8.44 secs
    146         #num_of_points = 20000
    147         #maxArea = 1
    148        
    149        
    150         seed(2)
     63        # make a mesh
     64        # pretty regular size, with some segments thrown in.
    15165        m = Mesh()
    15266        m.addUserVertex(0,0)
     
    18094        dict['segment_tags'] = ['wall4']   
    18195        m.addVertsSegs(dict)
    182        
    183         m.addVertsSegs(dict)
    184         m.generateMesh(mode = "Q", maxArea = maxArea)
    185         m.export_mesh_file("aaaa.tsh")
     96
     97        m.generateMesh(mode = "Q", maxArea = maxArea)       
     98        if save is True:
     99            m.export_mesh_file("aaaa.tsh")
    186100        mesh_dict =  m.Mesh2IOTriangulationDict()
    187101
     
    191105            points.append([random()*100, random()*100])
    192106            point_atts.append(10.0)
    193         #m.autoSegment(alpha = 100 )
     107           
     108        #Initial time and memory
     109        t0 = time.time()
     110        #m0 = None on windows
     111        m0 = mem_usage()
    194112
    195         #print 'points', points
    196         t0 = time.time()
    197113        interp = Interpolation(mesh_dict['vertices'],
    198114                               mesh_dict['triangles'], points,
    199115                               alpha=0.2, expand_search=True,
    200                                verbose = True, #False,
    201                                max_points_per_cell = max_points_per_cell)
     116                               verbose = False,
     117                               max_points_per_cell = 4)
    202118        calc = interp.fit_points(point_atts )
    203         print "interp.expanded_quad_searches", interp.expanded_quad_searches
     119        #print "interp.expanded_quad_searches", interp.expanded_quad_searches
    204120        #print "calc", calc
    205         print 'That took %.2f seconds' %(time.time()-t0)
    206        
    207 #-------------------------------------------------------------
    208 if __name__ == "__main__":
    209     import os
    210     suite = unittest.makeSuite(Test_Least_Squares,'test')
    211     runner = unittest.TextTestRunner(verbosity=1)
    212     runner.run(suite)
    213     val = mem_usage()
    214     print 'RSS', val
     121        time_taken_sec = (time.time()-t0)
     122        m1 = mem_usage()
     123        if m0 is None or m1 is None:
     124            memory_used = None
     125        else:
     126            memory_used = (m1 - m0)
     127        #print 'That took %.2f seconds' %time_taken_sec
     128        return time_taken_sec, memory_used
Note: See TracChangeset for help on using the changeset viewer.