Changeset 3012


Ignore:
Timestamp:
May 30, 2006, 11:00:57 AM (18 years ago)
Author:
duncan
Message:

started fixing the black screen of death at the fit.py end.

Location:
inundation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/examples/bedslope_bsod_test.py

    r2998 r3012  
    3030c3 = [331000, 6267000]
    3131bound_poly = [c0, c1, c2, c3]
    32 # duplicate point, this should fail, i.e. conjugate gradient doesn't converge
    33 #bound_poly = [c0, c1, c2, c3, c2]
    3432
    3533# set up internal region
     
    4038interior_polygon = [p0, p1, p2, p3]
    4139# duplicate point, this should fail, i.e. conjugate gradient doesn't converge
    42 #interior_polygon = [p0, p1, p2, p3, p0]
     40interior_polygon = [p0, p1, p2, p3, p0]
    4341
    44 interior_regions = [[interior_polygon, 25000]]
     42interior_region_area = 2500000000 #25000
     43interior_regions = [[interior_polygon, interior_region_area]]
    4544
    46 meshname = 'bedslope_bsod.msh'
     45meshname = 'bedslope_bsod.tsh'
    4746
     47exterior_region_area = 10000000000000000 #100000
    4848# create a mesh
    4949_ = cache(create_mesh_from_regions,
     
    5151          {'boundary_tags': {'bottom': [0], 'right': [1],
    5252                             'top': [2], 'left': [3]},
    53            'maximum_triangle_area': 100000,
     53           'maximum_triangle_area': exterior_region_area,
    5454           'filename': meshname,           
    5555           'interior_regions': interior_regions},
  • inundation/fit_interpolate/fit.py

    r2939 r3012  
    2121"""
    2222
    23 from Numeric import zeros, Float, ArrayType
     23from Numeric import zeros, Float, ArrayType,take
    2424
    2525from geospatial_data.geospatial_data import Geospatial_data, ensure_absolute
     
    7373              a mesh origin, since geospatial has its own mesh origin.
    7474        """
    75 
    7675        # Initialise variabels
    77         #self._A_can_be_reused = False
    78         #self._point_coordinates = None
    7976
    8077        if alpha is None:
     
    307304                                                geo_reference=point_origin)
    308305            self.build_fit_subset(point_coordinates, z, verbose)
    309        
     306
     307        #FIXME: Move this down
    310308        #Check sanity
    311309        m = self.mesh.coordinates.shape[0] #Nbr of basis functions (1/vertex)
     
    320318
    321319        self._build_coefficient_matrix_B(verbose)
     320        indexes = range(0,m)
     321        loners = self.mesh.get_lone_vertices()
     322        #print "loners",loners
     323        loners.sort()
     324        loners.reverse()
     325        #print "loners",loners
     326        for lone_index in loners:
     327            indexes.pop(lone_index)
     328        #print "fit self.Atz",take(self.Atz,indexes)
     329       
    322330        return conjugate_gradient(self.B, self.Atz, self.Atz,
    323331                                  imax=2*len(self.Atz) )
  • inundation/fit_interpolate/test_fit.py

    r2939 r3012  
    804804        os.remove(point_file)
    805805
     806
     807    def test_smooth_att_to_mesh_with_excess_verts(self):
     808
     809        a = [0.0, 0.0]
     810        b = [0.0, 5.0]
     811        c = [5.0, 0.0]
     812        d = [1.0, 1.0]
     813        e = [18.0, 1000.0]
     814       
     815        points = [a, b, c, d, e]
     816        triangles = [ [1,0,2] ]   #bac
     817
     818        d1 = [1.0, 1.0]
     819        d2 = [1.0, 2.0]
     820        d3 = [3.0,1.0]
     821        d4 = [2.0,3.0]
     822        d5 = [2.0,2.0]
     823        d6 = [1.0,3.0]
     824        data_coords = [d1, d2, d3, d4, d5, d6]
     825        z = linear_function(data_coords)
     826        #print "z",z
     827
     828        interp = Fit(points, triangles, alpha=0.0)
     829        f = interp.fit(data_coords, z)
     830        answer = linear_function(points)
     831
     832        #  Removing the bad verts that we don't care about
     833        f = f[0:3]
     834        answer = answer[0:3]
     835
     836        #print "f\n",f
     837        #print "answer\n",answer
     838
     839        assert allclose(f, answer)
     840        # Note: This test is iffy. Fit can fail if lone verts are inputted.
     841
    806842#-------------------------------------------------------------
    807843if __name__ == "__main__":
    808844    suite = unittest.makeSuite(Test_Fit,'test')
    809     #suite = unittest.makeSuite(Test_Fit,'test_smoothing_and_interpolation')
     845    #suite = unittest.makeSuite(Test_Fit,'test_smooth_att_to_mesh_with_excess_verts')
    810846    #suite = unittest.makeSuite(Test_Fit,'test_smooth_attributes_to_mesh_one_point')
    811847    runner = unittest.TextTestRunner(verbosity=1)
  • inundation/pyvolution/mesh.py

    r2982 r3012  
    616616                assert x < epsilon, msg
    617617
    618 
     618        self.lone_vertices = []
    619619        #Check that all vertices have been registered
    620620        for v_id, v in enumerate(self.vertexlist):
    621621
    622             msg = 'Vertex %s does not belong to an element.'
     622            #msg = 'Vertex %s does not belong to an element.'
    623623            #assert v is not None, msg
    624624            if v is None:
    625                 print msg%v_id
     625                #print msg%v_id
     626                self.lone_vertices.append(v_id)
    626627
    627628        #Check integrity of neighbour structure
     
    673674        #See domain.set_boundary
    674675
     676    def get_lone_vertices(self):
     677        """Return a list of vertices that are not connected to any triangles.
     678
     679        Precondition
     680        FIXME(DSG - DSG) Pull the code out of check integrity that builds this
     681                         structure.
     682        check_integrity has to have been called.
     683        """
     684        return self.lone_vertices
    675685
    676686    def get_centroid_coordinates(self):
  • inundation/pyvolution/test_mesh.py

    r2709 r3012  
    912912
    913913
     914
     915    def test_lone_vertices(self):
     916        a = [2.0, 1.0]
     917        b = [6.0, 2.0]
     918        c = [1.0, 3.0]
     919        d = [2.0, 4.0]
     920
     921        points = [a, b, c, d]
     922        vertices = [[0,1,2]]
     923
     924        mesh = Mesh(points, vertices)
     925        mesh.check_integrity()
     926        loners = mesh.get_lone_vertices()
     927        self.failUnless(loners==[3],
     928                        'FAILED!')
     929
     930       
     931        a = [2.0, 1.0]
     932        b = [6.0, 2.0]
     933        c = [1.0, 3.0]
     934        d = [2.0, 4.0]
     935
     936        points = [d, a, b, c]
     937        vertices = [[3,1,2]]
     938
     939        mesh = Mesh(points, vertices)
     940        mesh.check_integrity()
     941        loners = mesh.get_lone_vertices()
     942        self.failUnless(loners==[0],
     943                        'FAILED!')
     944       
    914945#-------------------------------------------------------------
    915946if __name__ == "__main__":
    916     suite = unittest.makeSuite(Test_Mesh,'test_boundary_polygon')
    917     #suite = unittest.makeSuite(Test_Mesh,'test')
     947    #suite = unittest.makeSuite(Test_Mesh,'test_boundary_polygon')
     948    suite = unittest.makeSuite(Test_Mesh,'test')
    918949    runner = unittest.TextTestRunner()
    919950    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.