def test_unique_vertices_average_loc_unique_vert(self):
        """
        get values based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({'bottom':[0,1],
                                                 'top':[4,5],
                                                 'not_bottom':[2,3,4,5]})

        #Set friction
        domain.set_quantity('friction', add_x_y)
        av_bottom = 2.0/3.0
        add = 60.0
        calc_frict = av_bottom + add
        domain.set_tag_region(Add_value_to_region('bottom', 'friction', add,
                          initial_quantity='friction',
                           location='unique vertices',
                           average=True
                          ))

        #print domain.quantities['friction'].get_values()
        frict_points = domain.quantities['friction'].get_values()
        assert num.allclose(frict_points[0],\
                            [ calc_frict, calc_frict, calc_frict])
        assert num.allclose(frict_points[1],\
                            [ calc_frict, calc_frict, calc_frict])
        assert num.allclose(frict_points[2],\
                            [ calc_frict, 1.0 + 2.0/3.0, calc_frict])
        assert num.allclose(frict_points[3],\
                            [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0])
    def test_bigger(self):
        """test_bigger
        
        test larger mesh
        """

        points, vertices, boundary = rectangular(4, 4, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
            
            found, s0, s1, s2, k = root.search_fast(ensure_numeric(x))                                   
                                         
            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_polygon(x, V)
                assert found is True
                #print k, x
            else:
                assert found is False                
    def test_unique_verticesII(self):
        """
        get values based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({'bottom':[0,1],
                                                 'top':[4,5],
                                                 'all':[0,1,2,3,4,5]})

        #Set friction
        manning = 0.07
        domain.set_quantity('friction', manning)

        domain.set_tag_region(Add_value_to_region('bottom', 'friction', 1.0,initial_quantity='friction', location = 'unique vertices'))

        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),\
                            [[ 1.07,  1.07,  1.07],
                             [ 1.07,  1.07,  1.07],
                             [ 1.07,  0.07,  1.07],
                             [ 0.07,  1.07,  0.07],
                             [ 0.07,  0.07,  0.07],
                             [ 0.07,  0.07,  0.07]])
示例#4
0
    def test_get_edge_midpoint_coordinates_triangle_id(self):
        """test_get_vertex_coordinates_triangle_id
        Test that vertices for one triangle can be returned.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        assert num.allclose(domain.get_nodes(), nodes)

        M = domain.number_of_triangles

        for i in range(M):
            E = domain.get_edge_midpoint_coordinates(triangle_id=i)
            assert E.shape[0] == 3

            k0 = triangles[i, 0]  #Index of vertex 0 in triangle i
            k1 = triangles[i, 1]  #Index of vertex 0 in triangle i
            k2 = triangles[i, 2]  #Index of vertex 0 in triangle i

            assert num.allclose(E[0, :], 0.5 * (nodes[k1] + nodes[k2]))
            assert num.allclose(E[1, :], 0.5 * (nodes[k0] + nodes[k2]))
            assert num.allclose(E[2, :], 0.5 * (nodes[k1] + nodes[k0]))

            E0 = domain.get_edge_midpoint_coordinate(i, 0)
            E1 = domain.get_edge_midpoint_coordinate(i, 1)
            E2 = domain.get_edge_midpoint_coordinate(i, 2)

            assert num.allclose(E0, 0.5 * (nodes[k1] + nodes[k2]))
            assert num.allclose(E1, 0.5 * (nodes[k0] + nodes[k2]))
            assert num.allclose(E2, 0.5 * (nodes[k1] + nodes[k0]))
示例#5
0
    def test_advection_example(self):
        #Test that system can evolve

        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        points, vertices, boundary = rectangular(6, 6)

        #Create advection domain with direction (1,-1)
        domain = Advection_Domain(points, vertices, boundary,
                                        velocity=[1.0, -1.0])

        # Initial condition is zero by default

        #Boundaries
        T = Transmissive_boundary(domain)
        D = Dirichlet_boundary(num.array([3.1415]))

        domain.set_boundary( {'left': D, 'right': T, 'bottom': T, 'top': T} )
        domain.check_integrity()

        #Check that the boundary value gets propagated to all elements
        for t in domain.evolve(yieldstep = 0.05, finaltime = 10):
            if num.allclose(domain.quantities['stage'].centroid_values, 3.1415):
                break

        assert num.allclose(domain.quantities['stage'].centroid_values, 3.1415)
    def test_large(self):
        """test_larger mesh and different quad trees
        """

        points, vertices, boundary = rectangular(10, 12, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        

        root = MeshQuadtree(mesh)
        root.set_last_triangle()
        #print m, root.show()

        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
            
            found, s0, s1, s2, k = root.search_fast(x)

            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_triangle(x, V, closed=True)
                assert is_inside_polygon(x, V)
                assert found is True
            else:
                assert found is False                

        
            if k == 0: return    
示例#7
0
    def test_large(self):
        """test_larger mesh and different quad trees
        """

        points, vertices, boundary = rectangular(10, 12, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        

        root = MeshQuadtree(mesh)
        root.set_last_triangle()
        #print m, root.show()

        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
            
            found, s0, s1, s2, k = root.search_fast(x)

            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_triangle(x, V, closed=True)
                assert is_inside_polygon(x, V)
                assert found is True
            else:
                assert found is False                

        
            if k == 0: return    
示例#8
0
    def test_bigger(self):
        """test_bigger
        
        test larger mesh
        """

        points, vertices, boundary = rectangular(4, 4, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
            
            found, s0, s1, s2, k = root.search_fast(ensure_numeric(x))                                   
                                         
            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_polygon(x, V)
                assert found is True
                #print k, x
            else:
                assert found is False                
示例#9
0
    def test_unique_verticesII(self):
        """
        get values based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({
            'bottom': [0, 1],
            'top': [4, 5],
            'all': [0, 1, 2, 3, 4, 5]
        })

        #Set friction
        manning = 0.07
        domain.set_quantity('friction', manning)

        domain.set_tag_region(
            Add_value_to_region('bottom',
                                'friction',
                                1.0,
                                initial_quantity='friction',
                                location='unique vertices'))

        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),\
                            [[ 1.07,  1.07,  1.07],
                             [ 1.07,  1.07,  1.07],
                             [ 1.07,  0.07,  1.07],
                             [ 0.07,  1.07,  0.07],
                             [ 0.07,  0.07,  0.07],
                             [ 0.07,  0.07,  0.07]])
示例#10
0
    def test_vertex_value_indices(self):
        """Check that structures are correct.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        a = [0.0, 0.0]
        b = [0.0, 2.0]
        c = [2.0, 0.0]
        d = [0.0, 4.0]
        e = [2.0, 2.0]
        f = [4.0, 0.0]

        nodes = num.array([a, b, c, d, e, f])
        #bac, bce, ecf, dbe, daf, dae
        triangles = num.array([[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]])

        domain1 = General_mesh(nodes, triangles)

        #Create larger mesh
        nodes, triangles, _ = rectangular(3, 6)
        domain2 = General_mesh(nodes, triangles)

        # Test both meshes
        for domain in [domain1, domain2]:
            assert sum(domain.number_of_triangles_per_node) ==\
                   len(domain.vertex_value_indices)

            # Check number of triangles per node
            count = [0] * domain.number_of_nodes
            for triangle in domain.triangles:
                for i in triangle:
                    count[i] += 1

            #print count
            #
            assert num.allclose(count, domain.number_of_triangles_per_node)

            # Check indices
            current_node = 0
            k = 0  # Track triangles touching on node
            for index in domain.vertex_value_indices:
                k += 1

                triangle = old_div(index, 3)
                vertex = index % 3

                assert domain.triangles[triangle, vertex] == current_node

                if domain.number_of_triangles_per_node[current_node] == k:
                    # Move on to next node
                    k = 0
                    current_node += 1
    def test_vertex_value_indices(self):
        """Check that structures are correct.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        a = [0.0, 0.0]
        b = [0.0, 2.0]
        c = [2.0, 0.0]
        d = [0.0, 4.0]
        e = [2.0, 2.0]
        f = [4.0, 0.0]

        nodes = num.array([a, b, c, d, e, f])
        #bac, bce, ecf, dbe, daf, dae
        triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])

        domain1 = General_mesh(nodes, triangles)
        
        #Create larger mesh
        nodes, triangles, _ = rectangular(3, 6)
        domain2 = General_mesh(nodes, triangles)

        # Test both meshes
        for domain in [domain1, domain2]:
            assert sum(domain.number_of_triangles_per_node) ==\
                   len(domain.vertex_value_indices)

            # Check number of triangles per node
            count = [0]*domain.number_of_nodes
            for triangle in domain.triangles:
                for i in triangle:
                    count[i] += 1

            #print count
            #
            assert num.allclose(count, domain.number_of_triangles_per_node)
            
            # Check indices
            current_node = 0
            k = 0 # Track triangles touching on node
            for index in domain.vertex_value_indices:
                k += 1
                
                triangle = index / 3
                vertex = index % 3

                assert domain.triangles[triangle, vertex] == current_node

                if domain.number_of_triangles_per_node[current_node] == k:
                    # Move on to next node
                    k = 0
                    current_node += 1
示例#12
0
    def test_region_indices(self):
        """create region based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)

        region = Region(domain, indices=[0, 2, 3])

        expected_indices = [0, 2, 3]
        assert num.allclose(region.indices, expected_indices)
示例#13
0
    def test_get_unique_vertex_values(self):
        """
        get unique_vertex based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        domain = General_mesh(points, vertices)

        assert domain.get_unique_vertices() == [0, 1, 2, 3, 4, 5, 6, 7]
        unique_vertices = domain.get_unique_vertices([0, 1, 4])
        assert unique_vertices == [0, 1, 2, 4, 5, 6, 7]

        unique_vertices = domain.get_unique_vertices([0, 4])
        assert unique_vertices == [0, 2, 4, 5, 6, 7]
示例#14
0
    def test_region_polygon_expanded(self):
        """create region based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)

        region = Region(domain,
                        polygon=[[0.0, 0.0], [0.5, 0.0], [0.5, 0.5]],
                        expand_polygon=True)

        expected_indices = [0, 1, 2, 3]
        assert num.allclose(region.indices, expected_indices)
示例#15
0
    def test_region_polygon(self):
        """create region based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)

        poly = [[0.0, 0.0], [0.5, 0.0], [0.5, 0.5]]

        #print poly
        region = Region(domain, polygon=poly)

        expected_indices = [1]
        assert num.allclose(region.indices, expected_indices)
    def test_small(self):
        """test_small: Two triangles
        """

        points, vertices, boundary = rectangular(1, 1, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        x = [0.2, 0.7]
        found, s0, s1, s2, k = root.search_fast(x)
        assert k == 1 # Triangle one
        assert found is True        
    def test_get_unique_vertex_values(self):
        """
        get unique_vertex based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        domain = General_mesh(points, vertices)                

        assert  domain.get_unique_vertices() == [0,1,2,3,4,5,6,7]
        unique_vertices = domain.get_unique_vertices([0,1,4])
        unique_vertices.sort()
        assert unique_vertices == [0,1,2,4,5,6,7]

        unique_vertices = domain.get_unique_vertices([0,4])
        unique_vertices.sort()
        assert unique_vertices == [0,2,4,5,6,7]
示例#18
0
    def test_small(self):
        """test_small: Two triangles
        """

        points, vertices, boundary = rectangular(1, 1, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        x = [0.2, 0.7]
        found, s0, s1, s2, k = root.search_fast(x)
        assert k == 1 # Triangle one
        assert found is True        
示例#19
0
    def test_get_vertex_coordinates(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        assert num.allclose(domain.get_nodes(), nodes)

        M = domain.number_of_triangles

        V = domain.get_vertex_coordinates()
        assert V.shape[0] == 3 * M

        for i in range(M):
            for j in range(3):
                k = triangles[i, j]  #Index of vertex j in triangle i
                assert num.allclose(V[3 * i + j, :], nodes[k])
    def test_off_and_boundary(self):
        """test_off: Test a point off the mesh
        """

        points, vertices, boundary = rectangular(1, 1, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        found, s0, s1, s2, k = root.search_fast([-0.2, 10.7])
        assert found is False

        found, s0, s1, s2, k = root.search_fast([0, 0])
        assert found is True
示例#21
0
    def test_off_and_boundary(self):
        """test_off: Test a point off the mesh
        """

        points, vertices, boundary = rectangular(1, 1, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        #Test that points are arranged in a counter clock wise order
        mesh.check_integrity()

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        found, s0, s1, s2, k = root.search_fast([-0.2, 10.7])
        assert found is False

        found, s0, s1, s2, k = root.search_fast([0, 0])
        assert found is True
示例#22
0
    def test_get_vertex_values(self):
        """Get connectivity based on triangle lists.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        msg = ("domain.get_triangles()=\n%s\nshould be the same as "
               "'triangles'=\n%s" %
               (str(domain.get_triangles()), str(triangles)))
        assert num.allclose(domain.get_triangles(), triangles), msg
        msg = ("domain.get_triangles([0,4])=\n%s\nshould be the same as "
               "'[triangles[0], triangles[4]]' which is\n%s" %
               (str(domain.get_triangles(
                   [0, 4])), str([triangles[0], triangles[4]])))
        assert num.allclose(domain.get_triangles([0, 4]),
                            [triangles[0], triangles[4]]), msg
    def test_get_vertex_values(self):
        """Get connectivity based on triangle lists.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        msg = ("domain.get_triangles()=\n%s\nshould be the same as "
               "'triangles'=\n%s"
               % (str(domain.get_triangles()), str(triangles)))
        assert num.allclose(domain.get_triangles(), triangles), msg
        msg = ("domain.get_triangles([0,4])=\n%s\nshould be the same as "
               "'[triangles[0], triangles[4]]' which is\n%s"
               % (str(domain.get_triangles([0,4])),
                  str([triangles[0], triangles[4]])))
        assert num.allclose(domain.get_triangles([0,4]),
                            [triangles[0], triangles[4]]), msg
    def test_underlying_function(self):
        """test_larger mesh and different quad trees
        """
        return
        points, vertices, boundary = rectangular(2, 2, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        # One point
        x = ensure_numeric([0.5, 0.5])

        found, sigma0, sigma1, sigma2, k = \
               root._search_triangles_of_vertices(root.search(x), x)

        if k >= 0:
            V = mesh.get_vertex_coordinates(k) # nodes for triangle k
            assert is_inside_polygon(x, V)
            assert found is True
        else:
            assert found is False                

        

        # More points    
        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
                
            triangles = root.search(x)

            #print x, candidate_vertices
            found, sigma0, sigma1, sigma2, k = \
                   root._search_triangles_of_vertices(triangles,
                                                 ensure_numeric(x))
            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_polygon(x, V)
                assert found is True
            else:
                assert found is False
示例#25
0
    def test_underlying_function(self):
        """test_larger mesh and different quad trees
        """
        return
        points, vertices, boundary = rectangular(2, 2, 1, 1)
        mesh = Mesh(points, vertices, boundary)

        root = MeshQuadtree(mesh)
        root.set_last_triangle()

        # One point
        x = ensure_numeric([0.5, 0.5])

        found, sigma0, sigma1, sigma2, k = \
               root._search_triangles_of_vertices(root.search(x), x)

        if k >= 0:
            V = mesh.get_vertex_coordinates(k) # nodes for triangle k
            assert is_inside_polygon(x, V)
            assert found is True
        else:
            assert found is False                

        

        # More points    
        for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7],
                  [0.1,0.9], [0.4,0.6], [0.9,0.1],
                  [10, 3]]:
                
            triangles = root.search(x)

            #print x, candidate_vertices
            found, sigma0, sigma1, sigma2, k = \
                   root._search_triangles_of_vertices(triangles,
                                                 ensure_numeric(x))
            if k >= 0:
                V = mesh.get_vertex_coordinates(k) # nodes for triangle k
                assert is_inside_polygon(x, V)
                assert found is True
            else:
                assert found is False
    def test_get_vertex_coordinates(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)


        assert num.allclose(domain.get_nodes(), nodes)


        M = domain.number_of_triangles        

        V = domain.get_vertex_coordinates()
        assert V.shape[0] == 3*M

        for i in range(M):
            for j in range(3):
                k = triangles[i,j]  #Index of vertex j in triangle i
                assert num.allclose(V[3*i+j,:], nodes[k])
示例#27
0
    def test_unique_vertices_average_loc_unique_vert_1_5(self):
        """
        get values based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.set_flow_algorithm('1_5')
        domain.build_tagged_elements_dictionary({
            'bottom': [0, 1],
            'top': [4, 5],
            'not_bottom': [2, 3, 4, 5]
        })

        #Set friction
        domain.set_quantity('friction', add_x_y)
        av_bottom = 2.0 / 3.0
        add = 60.0
        calc_frict = av_bottom + add
        domain.set_tag_region(
            Add_value_to_region('bottom',
                                'friction',
                                add,
                                initial_quantity='friction',
                                location='unique vertices',
                                average=True))

        #print domain.quantities['friction'].get_values()
        frict_points = domain.quantities['friction'].get_values()


        assert num.allclose(frict_points[0],\
                            [ calc_frict, calc_frict, calc_frict])
        assert num.allclose(frict_points[1],\
                            [ calc_frict, calc_frict, calc_frict])
        assert num.allclose(frict_points[2],\
                            [ calc_frict, 1.0 + 2.0/3.0, calc_frict])
        assert num.allclose(frict_points[3],\
                            [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0])
示例#28
0
    def test_get_vertex_coordinates_triangle_id(self):
        """test_get_vertex_coordinates_triangle_id
        Test that vertices for one triangle can be returned.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        assert num.allclose(domain.get_nodes(), nodes)

        M = domain.number_of_triangles

        for i in range(M):
            V = domain.get_vertex_coordinates(triangle_id=i)
            assert V.shape[0] == 3

            for j in range(3):
                k = triangles[i, j]  #Index of vertex j in triangle i
                assert num.allclose(V[j, :], nodes[k])
示例#29
0
    def test_unique_vertices_average_loc_unique_vert_de0(self):
        """
        get values based on triangle lists.
        """

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({
            'bottom': [0, 1],
            'top': [4, 5],
            'not_bottom': [2, 3, 4, 5]
        })

        #Set friction
        domain.set_quantity('friction', add_x_y)
        av_bottom = 2.0 / 3.0
        add = 60.0
        calc_frict = av_bottom + add
        domain.set_tag_region(
            Add_value_to_region('bottom',
                                'friction',
                                add,
                                initial_quantity='friction',
                                location='unique vertices',
                                average=True))

        #print domain.quantities['friction'].get_values()
        frict_points = domain.quantities['friction'].get_values()

        expected0 = [60.77777778, 60.77777778, 60.77777778]
        expected1 = [60.77777778, 60.77777778, 60.77777778]
        expected2 = [60.77777778, 1.66666667, 60.77777778]
        expected3 = [0.66666667, 60.77777778, 1.66666667]

        assert num.allclose(frict_points[0], expected0)
        assert num.allclose(frict_points[1], expected1)
        assert num.allclose(frict_points[2], expected2)
        assert num.allclose(frict_points[3], expected3)
示例#30
0
    def test_get_edge_midpoint_coordinates(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)

        assert num.allclose(domain.get_nodes(), nodes)

        M = domain.number_of_triangles

        E = domain.get_edge_midpoint_coordinates()
        assert E.shape[0] == 3 * M

        for i in range(M):
            k0 = triangles[i, 0]  #Index of vertex 0 in triangle i
            k1 = triangles[i, 1]  #Index of vertex 1 in triangle i
            k2 = triangles[i, 2]  #Index of vertex 2 in triangle i

            assert num.allclose(E[3 * i + 0, :], 0.5 * (nodes[k1] + nodes[k2]))
            assert num.allclose(E[3 * i + 1, :], 0.5 * (nodes[k0] + nodes[k2]))
            assert num.allclose(E[3 * i + 2, :], 0.5 * (nodes[k1] + nodes[k0]))
    def test_get_vertex_coordinates_triangle_id(self):
        """test_get_vertex_coordinates_triangle_id
        Test that vertices for one triangle can be returned.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)


        assert num.allclose(domain.get_nodes(), nodes)


        M = domain.number_of_triangles        

        for i in range(M):
            V = domain.get_vertex_coordinates(triangle_id=i)
            assert V.shape[0] == 3

            for j in range(3):
                k = triangles[i,j]  #Index of vertex j in triangle i
                assert num.allclose(V[j,:], nodes[k])
示例#32
0
    def test_unique_vertices_average_loc_vert(self):
        """Get values based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({
            'bottom': [0, 1],
            'top': [4, 5],
            'not_bottom': [2, 3, 4, 5]
        })

        #Set friction
        domain.set_quantity('friction', add_x_y)
        av_bottom = 2.0 / 3.0
        add = 60.0
        calc_frict = av_bottom + add
        domain.set_tag_region(
            Add_value_to_region('bottom',
                                'friction',
                                add,
                                initial_quantity='friction',
                                location='vertices',
                                average=True))

        frict_points = domain.quantities['friction'].get_values()

        expected = [calc_frict, calc_frict, calc_frict]
        msg = ('frict_points[0]=%s\nexpected=%s' %
               (str(frict_points[0]), str(expected)))
        assert num.allclose(frict_points[0], expected), msg

        msg = ('frict_points[1]=%s\nexpected=%s' %
               (str(frict_points[1]), str(expected)))
        assert num.allclose(frict_points[1], expected), msg
    def test_get_edge_midpoint_coordinates_triangle_id(self):
        """test_get_vertex_coordinates_triangle_id
        Test that vertices for one triangle can be returned.
        """
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)


        assert num.allclose(domain.get_nodes(), nodes)


        M = domain.number_of_triangles        

        for i in range(M):
            E = domain.get_edge_midpoint_coordinates(triangle_id=i)
            assert E.shape[0] == 3


            k0 = triangles[i,0]  #Index of vertex 0 in triangle i
            k1 = triangles[i,1]  #Index of vertex 0 in triangle i
            k2 = triangles[i,2]  #Index of vertex 0 in triangle i

            assert num.allclose(E[0,:], 0.5*(nodes[k1]+nodes[k2]))
            assert num.allclose(E[1,:], 0.5*(nodes[k0]+nodes[k2]))
            assert num.allclose(E[2,:], 0.5*(nodes[k1]+nodes[k0]))

            E0 = domain.get_edge_midpoint_coordinate(i, 0 )
            E1 = domain.get_edge_midpoint_coordinate(i, 1 )
            E2 = domain.get_edge_midpoint_coordinate(i, 2 )

            assert num.allclose(E0, 0.5*(nodes[k1]+nodes[k2]))
            assert num.allclose(E1, 0.5*(nodes[k0]+nodes[k2]))
            assert num.allclose(E2, 0.5*(nodes[k1]+nodes[k0]))
    def test_get_edge_midpoint_coordinates(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh
        nodes, triangles, _ = rectangular(1, 3)
        domain = General_mesh(nodes, triangles)


        assert num.allclose(domain.get_nodes(), nodes)


        M = domain.number_of_triangles        

        E = domain.get_edge_midpoint_coordinates()
        assert E.shape[0] == 3*M

        for i in range(M):
            k0 = triangles[i,0]  #Index of vertex 0 in triangle i
            k1 = triangles[i,1]  #Index of vertex 1 in triangle i
            k2 = triangles[i,2]  #Index of vertex 2 in triangle i

            assert num.allclose(E[3*i+0,:], 0.5*(nodes[k1]+nodes[k2]) )
            assert num.allclose(E[3*i+1,:], 0.5*(nodes[k0]+nodes[k2]) )
            assert num.allclose(E[3*i+2,:], 0.5*(nodes[k1]+nodes[k0]) )
    def test_merge_swwfiles(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular, \
            rectangular_cross
        from anuga.shallow_water.shallow_water_domain import Domain
        from anuga.file.sww import SWW_file
        from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
            Dirichlet_boundary

        Bd = Dirichlet_boundary([0.5, 0., 0.])

        # Create shallow water domain
        domain = Domain(*rectangular_cross(2, 2))
        domain.set_name('test1')
        domain.set_quantity('elevation', 2)
        domain.set_quantity('stage', 5)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
        for t in domain.evolve(yieldstep=0.5, finaltime=1):
            pass

        domain = Domain(*rectangular(3, 3))
        domain.set_name('test2')
        domain.set_quantity('elevation', 3)
        domain.set_quantity('stage', 50)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
        for t in domain.evolve(yieldstep=0.5, finaltime=1):
            pass

        outfile = 'test_out.sww'
        _sww_merge(['test1.sww', 'test2.sww'], outfile)
        self.assertTrue(os.access(outfile, os.F_OK))

        # remove temp files
        if not sys.platform == 'win32':
            os.remove('test1.sww')
            os.remove('test2.sww')
            os.remove(outfile)
    def test_merge_swwfiles(self):
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular, \
                                                                    rectangular_cross
        from anuga.shallow_water.shallow_water_domain import Domain
        from anuga.file.sww import SWW_file
        from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
            Dirichlet_boundary

        Bd = Dirichlet_boundary([0.5, 0., 0.])

        # Create shallow water domain
        domain = Domain(*rectangular_cross(2, 2))
        domain.set_name('test1')
        domain.set_quantity('elevation', 2)
        domain.set_quantity('stage', 5)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
        for t in domain.evolve(yieldstep=0.5, finaltime=1):
            pass
            
        domain = Domain(*rectangular(3, 3))
        domain.set_name('test2')
        domain.set_quantity('elevation', 3)
        domain.set_quantity('stage', 50)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
        for t in domain.evolve(yieldstep=0.5, finaltime=1):
            pass
                
        outfile = 'test_out.sww'
        _sww_merge(['test1.sww', 'test2.sww'], outfile)
        self.assertTrue(os.access(outfile, os.F_OK))  
        
        # remove temp files
        if not sys.platform == 'win32':		
			os.remove('test1.sww')
			os.remove('test2.sww')
			os.remove(outfile)      
示例#37
0
    def test_get_mesh_and_quantities_from_de0_sww_file(self):
        """test_get_mesh_and_quantities_from_sww_file(self):
        """     
        
        # Generate a test sww file with non trivial georeference
        
        import time, os

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (100m x 5m)
        width = 5
        length = 50
        t_end = 10
        points, vertices, boundary = rectangular(length, width, 50, 5)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary,
                        geo_reference = Geo_reference(56,308500,6189000))

        domain.set_name('test_get_mesh_and_quantities_from_sww_file')
        swwfile = domain.get_name() + '.sww'
        domain.set_datadir('.')
        domain.set_flow_algorithm('DE0')

        Br = Reflective_boundary(domain)    # Side walls
        Bd = Dirichlet_boundary([1, 0, 0])  # inflow

        domain.set_boundary( {'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = t_end):
            pass

        
        # Read it

        # Get mesh and quantities from sww file
        X = get_mesh_and_quantities_from_file(swwfile,
                                              quantities=['elevation',
                                                          'stage',
                                                          'xmomentum',
                                                          'ymomentum'], 
                                              verbose=False)
        mesh, quantities, time = X
        

        
        # Check that mesh has been recovered
        assert num.alltrue(mesh.triangles == domain.get_triangles())
        assert num.allclose(mesh.nodes, domain.get_nodes())

        # Check that time has been recovered
        assert num.allclose(time, range(t_end+1))

        # Check that quantities have been recovered
        # (sww files use single precision)
        z=domain.get_quantity('elevation').get_values(location='unique vertices')
        assert num.allclose(quantities['elevation'], z)

        for q in ['stage', 'xmomentum', 'ymomentum']:
            # Get quantity at last timestep
            q_ref=domain.get_quantity(q).get_values(location='unique vertices')

            #print q,quantities[q]
            q_sww=quantities[q][-1,:]
            
            msg = 'Quantity %s failed to be recovered' %q
            assert num.allclose(q_ref, q_sww, atol=1.0e-2), msg
    def test_get_energy_through_cross_section(self):
        """test_get_energy_through_cross_section(self):

        Test that the specific and total energy through a cross section can be
        correctly obtained from an sww file.
        
        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected energies.

        The specifics are
        u = 2 m/s
        h = 1 m
        w = 3 m (width of channel)

        q = u*h*w = 6 m^3/s
        Es = h + 0.5*v*v/g  # Specific energy head [m]
        Et = w + 0.5*v*v/g  # Total energy head [m]        


        This test uses georeferencing
        
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 1
        points, vertices, boundary = rectangular(length, width,
                                                 length, width)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary,
                        geo_reference = Geo_reference(56,308500,6189000))

        domain.default_order = 2
        domain.set_minimum_storable_height(0.01)

        domain.set_name('flowtest')
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        e = -1.0
        w = 1.0
        h = w-e
        u = 2.0
        uh = u*h

        Br = Reflective_boundary(domain)     # Side walls
        Bd = Dirichlet_boundary([w, uh, 0])  # 2 m/s across the 3 m inlet: 

        
        domain.set_quantity('elevation', e)
        domain.set_quantity('stage', w)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary( {'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = t_end):
            pass

        # Check that momentum is as it should be in the interior

        I = [[0, width/2.],
             [length/2., width/2.],
             [length, width/2.]]
        
        I = domain.geo_reference.get_absolute(I)
        f = file_function(swwfile,
                          quantities=['stage', 'xmomentum', 'ymomentum'],
                          interpolation_points=I,
                          verbose=False)

        for t in range(t_end+1):
            for i in range(3):
                #print i, t, f(t, i)
                assert num.allclose(f(t, i), [w, uh, 0], atol=1.0e-6)
            

        # Check energies through the middle
        for i in range(5):
            x = length/2. + i*0.23674563 # Arbitrary
            cross_section = [[x, 0], [x, width]]

            cross_section = domain.geo_reference.get_absolute(cross_section)            
            
            time, Es = get_energy_through_cross_section(swwfile,
                                                       cross_section,
                                                       kind='specific',
                                                       verbose=False)
            assert num.allclose(Es, h + 0.5*u*u/g)
            
            time, Et = get_energy_through_cross_section(swwfile,
                                                        cross_section,
                                                        kind='total',
                                                        verbose=False)
            assert num.allclose(Et, w + 0.5*u*u/g)            
示例#39
0
    def test_sww2domain1(self):
        ################################################
        #Create a test domain, and evolve and save it.
        ################################################
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        #Create basic mesh

        yiel=0.01
        points, vertices, boundary = rectangular(10,10)

        #print "=============== boundary rect ======================="
        #print boundary

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.geo_reference = Geo_reference(56,11,11)
        domain.smooth = False
        domain.store = True
        domain.set_name('bedslope')
        domain.default_order=2
        #Bed-slope and friction
        domain.set_quantity('elevation', lambda x,y: -x/3)
        domain.set_quantity('friction', 0.1)
        # Boundary conditions
        from math import sin, pi
        Br = Reflective_boundary(domain)
        Bt = Transmissive_boundary(domain)
        Bd = Dirichlet_boundary([0.2,0.,0.])
        Bw = Time_boundary(domain=domain,function=lambda t: [(0.1*sin(t*2*pi)), 0.0, 0.0])

        #domain.set_boundary({'left': Bd, 'right': Br, 'top': Br, 'bottom': Br})
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})

        domain.quantities_to_be_stored['xmomentum'] = 2
        domain.quantities_to_be_stored['ymomentum'] = 2
        #Initial condition
        h = 0.05
        elevation = domain.quantities['elevation'].vertex_values
        domain.set_quantity('stage', elevation + h)

        domain.check_integrity()
        #Evolution
        #domain.tight_slope_limiters = 1
        for t in domain.evolve(yieldstep = yiel, finaltime = 0.05):
            #domain.write_time()
            pass

        #print boundary


        filename = domain.datadir + os.sep + domain.get_name() + '.sww'
        domain2 = load_sww_as_domain(filename, None, fail_if_NaN=False,
                                        verbose=self.verbose)

        # Unfortunately we loss the boundaries top, bottom, left and right,
        # they are now all lumped into "exterior"

        #print "=============== boundary domain2 ======================="
        #print domain2.boundary
        

        #print domain2.get_boundary_tags()
        
        #points, vertices, boundary = rectangular(15,15)
        #domain2.boundary = boundary
        ###################
        ##NOW TEST IT!!!
        ###################

        os.remove(filename)

        bits = ['vertex_coordinates']
        for quantity in ['stage']:
            bits.append('get_quantity("%s").get_integral()' % quantity)
            bits.append('get_quantity("%s").get_values()' % quantity)

        for bit in bits:
            #print 'testing that domain.'+bit+' has been restored'
            #print bit
            #print 'done'
            #print eval('domain.'+bit)
            #print eval('domain2.'+bit)
            assert num.allclose(eval('domain.'+bit),eval('domain2.'+bit))

        ######################################
        #Now evolve them both, just to be sure
        ######################################x
        from time import sleep

        final = .1
        domain.set_quantity('friction', 0.1)
        domain.store = False
        domain.set_boundary({'exterior': Bd, 'left' : Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})


        for t in domain.evolve(yieldstep = yiel, finaltime = final):
            #domain.write_time()
            pass

        #BUT since domain2 gets time hacked back to 0:
        

        # Load_sww_as_domain sets starttime for domain2 to the last time in the 
        # sww file (which is the value of time+domain.starttime
        final2 = final - domain2.get_starttime()

        domain2.smooth = False
        domain2.store = False
        domain2.default_order=2
        domain2.set_quantity('friction', 0.1)
        #Bed-slope and friction
        # Boundary conditions
        Bd2=Dirichlet_boundary([0.2,0.,0.])
        domain2.boundary = domain.boundary
        #print 'domain2.boundary'
        #print domain2.boundary
        domain2.set_boundary({'exterior': Bd, 'left' : Bd,  'right': Bd, 'top': Bd, 'bottom': Bd})
        #domain2.set_boundary({'exterior': Bd})

        domain2.check_integrity()
        

        for t in domain2.evolve(yieldstep = yiel, finaltime = final2):
            #domain2.write_time()
            pass

        ###################
        ##NOW TEST IT!!!
        ##################

        bits = ['vertex_coordinates']

        for quantity in ['elevation','stage', 'ymomentum','xmomentum']:
            bits.append('get_quantity("%s").get_integral()' %quantity)
            bits.append('get_quantity("%s").get_values()' %quantity)

        #print bits
        for bit in bits:
            #print bit
            #print eval('domain.'+bit)
            #print eval('domain2.'+bit)
            
            #print eval('domain.'+bit+'-domain2.'+bit)
            msg = 'Values in the two domains are different for ' + bit
            assert num.allclose(eval('domain.'+bit),eval('domain2.'+bit),
                                rtol=5.e-2, atol=5.e-2), msg
    def test_get_maximum_inundation_de0(self):
        """Test that sww information can be converted correctly to maximum
        runup elevation and location (without and with georeferencing)

        This test creates a slope and a runup which is maximal (~11m) at around 10s
        and levels out to the boundary condition (1m) at about 30s.
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        #Setup

        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (100m x 100m)
        points, vertices, boundary = rectangular(20, 5, 100, 50)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.default_order = 2
        domain.set_minimum_storable_height(0.01)

        filename = 'runup_test_3'
        domain.set_name(filename)
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        # FIXME (Ole): Backwards compatibility
        # Look at sww file and see what happens when
        # domain.tight_slope_limiters = 1
        domain.tight_slope_limiters = 0
        domain.use_centroid_velocities = 0 # Backwards compatibility (7/5/8)        
        
        Br = Reflective_boundary(domain)
        Bd = Dirichlet_boundary([1.0,0,0])


        #---------- First run without geo referencing
        
        domain.set_quantity('elevation', lambda x,y: -0.2*x + 14) # Slope
        domain.set_quantity('stage', -6)
        domain.set_boundary( {'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = 50):
            pass


        # Check maximal runup
        runup = get_maximum_inundation_elevation(swwfile)
        location = get_maximum_inundation_location(swwfile)
        #print 'Runup, location', runup, location
        assert num.allclose(runup, 4.66666666667)
        assert num.allclose(location[0], 46.666668) 
               
        # Check final runup
        runup = get_maximum_inundation_elevation(swwfile, time_interval=[45,50])
        location = get_maximum_inundation_location(swwfile, time_interval=[45,50])
        #print 'Runup, location:',runup, location

        assert num.allclose(runup, 3.81481488546)
        assert num.allclose(location[0], 51.666668)

        # Check runup restricted to a polygon
        p = [[50,1], [99,1], [99,49], [50,49]]
        runup = get_maximum_inundation_elevation(swwfile, polygon=p)
        location = get_maximum_inundation_location(swwfile, polygon=p)
        #print runup, location

        assert num.allclose(runup, 3.81481488546) 
        assert num.allclose(location[0], 51.6666666)                

        # Check that mimimum_storable_height works
        fid = NetCDFFile(swwfile, netcdf_mode_r) # Open existing file
        
        stage = fid.variables['stage_c'][:]
        z = fid.variables['elevation_c'][:]
        xmomentum = fid.variables['xmomentum_c'][:]
        ymomentum = fid.variables['ymomentum_c'][:]
        
        for i in range(stage.shape[0]):
            h = stage[i]-z # depth vector at time step i
            
            # Check every node location
            for j in range(stage.shape[1]):
                # Depth being either exactly zero implies
                # momentum being zero.
                # Or else depth must be greater than or equal to
                # the minimal storable height
                if h[j] == 0.0:
                    assert xmomentum[i,j] == 0.0
                    assert ymomentum[i,j] == 0.0                
                else:
                    assert h[j] >= 0.0
        
        fid.close()

        # Cleanup
        os.remove(swwfile)
        


        #------------- Now the same with georeferencing

        domain.time=0.0
        E = 308500
        N = 6189000
        #E = N = 0
        domain.geo_reference = Geo_reference(56, E, N)

        domain.set_quantity('elevation', lambda x,y: -0.2*x + 14) # Slope
        domain.set_quantity('stage', -6)
        domain.set_boundary( {'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = 50):
            pass

        # Check maximal runup
        runup = get_maximum_inundation_elevation(swwfile)
        location = get_maximum_inundation_location(swwfile)

        #print runup, location

        assert num.allclose(runup,4.66666666667)
        assert num.allclose(location[0], 308546.66) 

        # Check final runup
        runup = get_maximum_inundation_elevation(swwfile, time_interval=[45,50])
        location = get_maximum_inundation_location(swwfile, time_interval=[45,50])
        
        #print runup, location
        #1.66666666667 [308561.66, 6189006.5]

        assert num.allclose(runup, 3.81481488546)
        assert num.allclose(location[0], 308551.66)

        # Check runup restricted to a polygon
        p = num.array([[50,1], [99,1], [99,49], [50,49]], num.int) + num.array([E, N], num.int)      #array default#

        runup = get_maximum_inundation_elevation(swwfile, polygon=p)
        location = get_maximum_inundation_location(swwfile, polygon=p)

        #print runup, location

        assert num.allclose(runup, 3.81481488546)
        assert num.allclose(location[0], 308551.66)                


        # Cleanup
        os.remove(swwfile)
    def test_get_flow_through_cross_section_stored_uniquely(self):
        """test_get_flow_through_cross_section_stored_uniquely(self):

        Test that the total flow through a cross section can be
        correctly obtained from an sww file.
        
        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected flow.

        The specifics are
        u = 2 m/s
        h = 1 m
        w = 3 m (width of channel)

        q = u*h*w = 6 m^3/s
       
        
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 3
        points, vertices, boundary = rectangular(length, width,
                                                 length, width)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.default_order = 2
        domain.set_minimum_storable_height(0.01)

        domain.set_name('flowtest_uniquely')
        swwfile = domain.get_name() + '.sww'

        domain.set_store_vertices_uniquely()
        
        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        h = 1.0
        u = 2.0
        uh = u*h

        Br = Reflective_boundary(domain)     # Side walls
        Bd = Dirichlet_boundary([h, uh, 0])  # 2 m/s across the 3 m inlet: 


        
        domain.set_quantity('elevation', 0.0)
        domain.set_quantity('stage', h)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary( {'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = t_end):
            pass

        # Check that momentum is as it should be in the interior

        I = [[0, width/2.],
             [length/2., width/2.],
             [length, width/2.]]
        
        f = file_function(swwfile,
                          quantities=['stage', 'xmomentum', 'ymomentum'],
                          interpolation_points=I,
                          verbose=False)
        for t in range(t_end+1):
            for i in range(3):
                assert num.allclose(f(t, i), [1, 2, 0], atol=1.0e-6)
            

        # Check flows through the middle
        for i in range(5):
            x = length/2. + i*0.23674563 # Arbitrary
            cross_section = [[x, 0], [x, width]]
            time, Q = get_flow_through_cross_section(swwfile,
                                                     cross_section,
                                                     verbose=False)

            assert num.allclose(Q, uh*width)


       
        # Try the same with partial lines
        x = length/2.
        for i in range(5):
            start_point = [length/2., i*width/5.]
            #print start_point
                            
            cross_section = [start_point, [length/2., width]]
            time, Q = get_flow_through_cross_section(swwfile,
                                                     cross_section,
                                                     verbose=False)

            #print i, Q, (width-start_point[1])
            assert num.allclose(Q, uh*(width-start_point[1]))


        # Verify no flow when line is parallel to flow
        cross_section = [[length/2.-10, width/2.], [length/2.+10, width/2.]]
        time, Q = get_flow_through_cross_section(swwfile,
                                                 cross_section,
                                                 verbose=False)

        #print i, Q
        assert num.allclose(Q, 0, atol=1.0e-5)        


        # Try with lines on an angle (all flow still runs through here)
        cross_section = [[length/2., 0], [length/2.+width, width]]
        time, Q = get_flow_through_cross_section(swwfile,
                                                 cross_section,
                                                 verbose=False)

        assert num.allclose(Q, uh*width)        
##############################################
# Change min_depth and see how larger values aggravate the problem
yieldstep = 0.1
finaltime = 10.0
#min_depth = 1.0e-4
min_depth = 1.0e-2


from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
from anuga.shallow_water import Domain, Reflective_boundary



#Create shallow water domain
points, vertices, boundary = rectangular(50, 50, len1=500, len2=500)
domain = Domain(points, vertices, boundary)
domain.smooth = False
domain.visualise = True
domain.default_order = 1
domain.minimum_allowed_height = min_depth
print 'Extent', domain.get_extent()

# Set initial condition
class Set_IC:
    """Set an initial condition with a constant value, for x0<x<x1
    """

    def __init__(self, x0=0.25, x1=0.5, h=1.0):
        self.x0 = x0
        self.x1 = x1
示例#43
0
    def test_get_flow_through_cross_section_with_geo(self):
        """test_get_flow_through_cross_section(self):

        Test that the total flow through a cross section can be
        correctly obtained at run-time from the ANUGA domain.

        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected flow.

        The specifics are
        e = -1 m
        u = 2 m/s
        h = 2 m
        w = 3 m (width of channel)

        q = u*h*w = 12 m^3/s

        This run tries it with georeferencing and with elevation = -1
        """

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 1
        points, vertices, boundary = rectangular(length, width, length, width)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary,
                        geo_reference=Geo_reference(56, 308500, 6189000))

        domain.default_order = 2
        domain.set_quantities_to_be_stored(None)

        e = -1.0
        w = 1.0
        h = w-e
        u = 2.0
        uh = u*h

        Br = Reflective_boundary(domain)     # Side walls
        Bd = Dirichlet_boundary([w, uh, 0])  # 2 m/s across the 3 m inlet: 


        # Initial conditions
        domain.set_quantity('elevation', e)
        domain.set_quantity('stage', w)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        # Interpolation points down the middle
        I = [[0, width/2.],
             [length/2., width/2.],
             [length, width/2.]]
        interpolation_points = domain.geo_reference.get_absolute(I)

        for t in domain.evolve(yieldstep=0.1, finaltime=0.5):
            # Shortcuts to quantites
            stage = domain.get_quantity('stage')
            xmomentum = domain.get_quantity('xmomentum')
            ymomentum = domain.get_quantity('ymomentum')

            # Check that quantities are they should be in the interior
            w_t = stage.get_values(interpolation_points)
            uh_t = xmomentum.get_values(interpolation_points)
            vh_t = ymomentum.get_values(interpolation_points)

            assert num.allclose(w_t, w)
            assert num.allclose(uh_t, uh)
            assert num.allclose(vh_t, 0.0, atol=1.0e-6)

            # Check flows through the middle
            for i in range(5):
                x = length/2. + i*0.23674563    # Arbitrary
                cross_section = [[x, 0], [x, width]]

                cross_section = domain.geo_reference.get_absolute(cross_section)
                Q = domain.get_flow_through_cross_section(cross_section,
                                                          verbose=False)

                assert num.allclose(Q, uh*width)

        import cPickle        
        cPickle.dump(domain, open('domain_pickle.pickle', 'w'))
        domain_restored = cPickle.load(open('domain_pickle.pickle'))

        
        for t in domain_restored.evolve(yieldstep=0.1, finaltime=1.0):
            # Shortcuts to quantites
            stage = domain_restored.get_quantity('stage')
            xmomentum = domain_restored.get_quantity('xmomentum')
            ymomentum = domain_restored.get_quantity('ymomentum')
            
            # Check that quantities are they should be in the interior
            w_t = stage.get_values(interpolation_points)
            uh_t = xmomentum.get_values(interpolation_points)
            vh_t = ymomentum.get_values(interpolation_points)

            assert num.allclose(w_t, w)
            assert num.allclose(uh_t, uh)
            assert num.allclose(vh_t, 0.0, atol=1.0e-6)

            # Check flows through the middle
            for i in range(5):
                x = length/2. + i*0.23674563    # Arbitrary
                cross_section = [[x, 0], [x, width]]

                cross_section = domain_restored.geo_reference.get_absolute(cross_section)
                Q = domain_restored.get_flow_through_cross_section(cross_section,
                                                          verbose=False)

                assert num.allclose(Q, uh*width)
#
#
#########################################################

##############################################
# Change min_depth and see how larger values aggravate the problem
yieldstep = 0.1
finaltime = 10.0
#min_depth = 1.0e-4
min_depth = 1.0e-2

from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
from anuga.shallow_water import Domain, Reflective_boundary

#Create shallow water domain
points, vertices, boundary = rectangular(50, 50, len1=500, len2=500)
domain = Domain(points, vertices, boundary)
domain.smooth = False
domain.visualise = True
domain.default_order = 1
domain.minimum_allowed_height = min_depth
print 'Extent', domain.get_extent()


# Set initial condition
class Set_IC:
    """Set an initial condition with a constant value, for x0<x<x1
    """
    def __init__(self, x0=0.25, x1=0.5, h=1.0):
        self.x0 = x0
        self.x1 = x1
示例#45
0
    def test_get_flow_through_cross_section_stored_uniquely(self):
        """test_get_flow_through_cross_section_stored_uniquely(self):

        Test that the total flow through a cross section can be
        correctly obtained from an sww file.
        
        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected flow.

        The specifics are
        u = 2 m/s
        h = 1 m
        w = 3 m (width of channel)

        q = u*h*w = 6 m^3/s
       
        
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 3
        points, vertices, boundary = rectangular(length, width, length, width)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.default_order = 2
        domain.set_minimum_storable_height(0.01)

        domain.set_name('flowtest_uniquely')
        swwfile = domain.get_name() + '.sww'

        domain.set_store_vertices_uniquely()

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        h = 1.0
        u = 2.0
        uh = u * h

        Br = Reflective_boundary(domain)  # Side walls
        Bd = Dirichlet_boundary([h, uh, 0])  # 2 m/s across the 3 m inlet:

        domain.set_quantity('elevation', 0.0)
        domain.set_quantity('stage', h)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime=t_end):
            pass

        # Check that momentum is as it should be in the interior

        I = [[0, width / 2.], [length / 2., width / 2.], [length, width / 2.]]

        f = file_function(swwfile,
                          quantities=['stage', 'xmomentum', 'ymomentum'],
                          interpolation_points=I,
                          verbose=False)
        for t in range(t_end + 1):
            for i in range(3):
                assert num.allclose(f(t, i), [1, 2, 0], atol=1.0e-6)

        # Check flows through the middle
        for i in range(5):
            x = length / 2. + i * 0.23674563  # Arbitrary
            cross_section = [[x, 0], [x, width]]
            time, Q = get_flow_through_cross_section(swwfile,
                                                     cross_section,
                                                     verbose=False)

            assert num.allclose(Q, uh * width)

        # Try the same with partial lines
        x = length / 2.
        for i in range(5):
            start_point = [length / 2., i * width / 5.]
            #print start_point

            cross_section = [start_point, [length / 2., width]]
            time, Q = get_flow_through_cross_section(swwfile,
                                                     cross_section,
                                                     verbose=False)

            #print i, Q, (width-start_point[1])
            assert num.allclose(Q, uh * (width - start_point[1]))

        # Verify no flow when line is parallel to flow
        cross_section = [[length / 2. - 10, width / 2.],
                         [length / 2. + 10, width / 2.]]
        time, Q = get_flow_through_cross_section(swwfile,
                                                 cross_section,
                                                 verbose=False)

        #print i, Q
        assert num.allclose(Q, 0, atol=1.0e-5)

        # Try with lines on an angle (all flow still runs through here)
        cross_section = [[length / 2., 0], [length / 2. + width, width]]
        time, Q = get_flow_through_cross_section(swwfile,
                                                 cross_section,
                                                 verbose=False)

        assert num.allclose(Q, uh * width)
    def test_region_tags(self):
        """get values based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({'bottom': [0,1],
                                                 'top': [4,5],
                                                 'all': [0,1,2,3,4,5]})

        #Set friction
        manning = 0.07
        domain.set_quantity('friction', manning)

        a = Set_tag_region('bottom', 'friction', 0.09)
        b = Set_tag_region('top', 'friction', 1.0)
        domain.set_tag_region([a, b])

        expected = [[ 0.09,  0.09,  0.09],
                    [ 0.09,  0.09,  0.09],
                    [ 0.07,  0.07,  0.07],
                    [ 0.07,  0.07,  0.07],
                    [ 1.0,   1.0,   1.0],
                    [ 1.0,   1.0,   1.0]]
        msg = ("\ndomain.quantities['friction']=%s\nexpected value=%s"
               % (str(domain.quantities['friction'].get_values()),
                  str(expected)))
        assert num.allclose(domain.quantities['friction'].get_values(),
                            expected), msg

        #c = Add_Value_To_region('all', 'friction', 10.0)
        domain.set_tag_region(Add_value_to_region('all', 'friction', 10.0))
        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),
                            [[ 10.09, 10.09, 10.09],
                             [ 10.09, 10.09, 10.09],
                             [ 10.07, 10.07, 10.07],
                             [ 10.07, 10.07, 10.07],
                             [ 11.0,  11.0,  11.0],
                             [ 11.0,  11.0,  11.0]])

        # trying a function
        domain.set_tag_region(Set_tag_region('top', 'friction', add_x_y))
        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),
                            [[ 10.09, 10.09, 10.09],
                             [ 10.09, 10.09, 10.09],
                             [ 10.07, 10.07, 10.07],
                             [ 10.07, 10.07, 10.07],
                             [ 5./3,  2.0,  2./3],
                             [ 1.0,  2./3,  2.0]])

        domain.set_quantity('elevation', 10.0)
        domain.set_quantity('stage', 10.0)
        domain.set_tag_region(Add_value_to_region('top', 'stage', 1.0,initial_quantity='elevation'))
        #print domain.quantities['stage'].get_values()
        assert num.allclose(domain.quantities['stage'].get_values(),
                            [[ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 11.0,  11.0,  11.0],
                             [ 11.0,  11.0,  11.0]])

        
        domain.set_quantity('elevation', 10.0)
        domain.set_quantity('stage', give_me_23)
        #this works as well, (is cleaner, but doesn't work for regions)
        #domain.set_quantity('stage',
        #                    domain.quantities['stage'].vertex_values+ \
        #                    domain.quantities['elevation'].vertex_values)
        domain.set_tag_region(Add_quantities('top', 'elevation','stage'))
        #print domain.quantities['stage'].get_values()
        assert num.allclose(domain.quantities['elevation'].get_values(),
                            [[ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 10., 10., 10.],
                             [ 33.,  33.0,  33.],
                             [ 33.0,  33.,  33.]])
    def test_areas(self):
        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        domain = General_mesh(points, vertices)        

        assert domain.get_area() == 1.0
     Transmissive_boundary, Time_boundary
from anuga.shallow_water.shallow_water_domain import Weir_simple as Weir
import anuga.utilities.log as log

from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular


######################
# Domain
#

N = 12

log.critical('Creating domain')
#Create basic mesh
points, vertices, boundary = rectangular(N, N/2, len1=1.2,len2=0.6,
                                         origin=(-0.07, 0))

log.critical('Number of elements=%d' % len(vertices))
#Create shallow water domain
domain = Domain(points, vertices, boundary)
domain.smooth = False
domain.default_order = 2
domain.set_name('show_balanced_limiters')
domain.store = True
domain.format = 'sww'   #Native netcdf visualisation format

#Set bed-slope and friction
inflow_stage = 0.1
manning = 0.1
Z = Weir(inflow_stage)
示例#49
0
    def test_get_flow_through_cross_section_with_geo(self):
        """test_get_flow_through_cross_section(self):

        Test that the total flow through a cross section can be
        correctly obtained at run-time from the ANUGA domain.

        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected flow.

        The specifics are
        e = -1 m
        u = 2 m/s
        h = 2 m
        w = 3 m (width of channel)

        q = u*h*w = 12 m^3/s

        This run tries it with georeferencing and with elevation = -1
        """

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 1
        points, vertices, boundary = rectangular(length, width, length, width)

        # Create shallow water domain
        domain = Domain(points,
                        vertices,
                        boundary,
                        geo_reference=Geo_reference(56, 308500, 6189000))

        domain.default_order = 2
        domain.set_quantities_to_be_stored(None)

        e = -1.0
        w = 1.0
        h = w - e
        u = 2.0
        uh = u * h

        Br = Reflective_boundary(domain)  # Side walls
        Bd = Dirichlet_boundary([w, uh, 0])  # 2 m/s across the 3 m inlet:

        # Initial conditions
        domain.set_quantity('elevation', e)
        domain.set_quantity('stage', w)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        # Interpolation points down the middle
        I = [[0, width / 2.], [length / 2., width / 2.], [length, width / 2.]]
        interpolation_points = domain.geo_reference.get_absolute(I)

        for t in domain.evolve(yieldstep=0.1, finaltime=0.5):
            # Shortcuts to quantites
            stage = domain.get_quantity('stage')
            xmomentum = domain.get_quantity('xmomentum')
            ymomentum = domain.get_quantity('ymomentum')

            # Check that quantities are they should be in the interior
            w_t = stage.get_values(interpolation_points)
            uh_t = xmomentum.get_values(interpolation_points)
            vh_t = ymomentum.get_values(interpolation_points)

            assert num.allclose(w_t, w)
            assert num.allclose(uh_t, uh)
            assert num.allclose(vh_t, 0.0, atol=1.0e-6)

            # Check flows through the middle
            for i in range(5):
                x = length / 2. + i * 0.23674563  # Arbitrary
                cross_section = [[x, 0], [x, width]]

                cross_section = domain.geo_reference.get_absolute(
                    cross_section)
                Q = domain.get_flow_through_cross_section(cross_section,
                                                          verbose=False)

                assert num.allclose(Q, uh * width)

        import cPickle
        cPickle.dump(domain, open('domain_pickle.pickle', 'w'))
        domain_restored = cPickle.load(open('domain_pickle.pickle'))

        for t in domain_restored.evolve(yieldstep=0.1, finaltime=1.0):
            # Shortcuts to quantites
            stage = domain_restored.get_quantity('stage')
            xmomentum = domain_restored.get_quantity('xmomentum')
            ymomentum = domain_restored.get_quantity('ymomentum')

            # Check that quantities are they should be in the interior
            w_t = stage.get_values(interpolation_points)
            uh_t = xmomentum.get_values(interpolation_points)
            vh_t = ymomentum.get_values(interpolation_points)

            assert num.allclose(w_t, w)
            assert num.allclose(uh_t, uh)
            assert num.allclose(vh_t, 0.0, atol=1.0e-6)

            # Check flows through the middle
            for i in range(5):
                x = length / 2. + i * 0.23674563  # Arbitrary
                cross_section = [[x, 0], [x, width]]

                cross_section = domain_restored.geo_reference.get_absolute(
                    cross_section)
                Q = domain_restored.get_flow_through_cross_section(
                    cross_section, verbose=False)

                assert num.allclose(Q, uh * width)
示例#50
0
    def test_get_mesh_and_quantities_from_unique_vertices_DE0_sww_file(self):
        """test_get_mesh_and_quantities_from_unique_vertices_sww_file(self):
        """     
        
        # Generate a test sww file with non trivial georeference
        
        import time, os

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (100m x 5m)
        width = 5
        length = 50
        t_end = 10
        points, vertices, boundary = rectangular(10, 1, length, width)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary,
                        geo_reference = Geo_reference(56,308500,6189000))

        domain.set_name('test_get_mesh_and_quantities_from_unique_vertices_sww_file')
        swwfile = domain.get_name() + '.sww'
        domain.set_datadir('.')
        domain.set_flow_algorithm('DE0')
        domain.set_store_vertices_uniquely()

        Br = Reflective_boundary(domain)    # Side walls
        Bd = Dirichlet_boundary([1, 0, 0])  # inflow

        domain.set_boundary( {'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime = t_end):
            pass

        
        # Read it

        # Get mesh and quantities from sww file
        X = get_mesh_and_quantities_from_file(swwfile,
                                              quantities=['elevation',
                                                          'stage',
                                                          'xmomentum',
                                                          'ymomentum'], 
                                              verbose=False)
        mesh, quantities, time = X 

        #print quantities
        #print time

        dhash = domain.get_nodes()[:,0]*10+domain.get_nodes()[:,1]
        mhash = mesh.nodes[:,0]*10+mesh.nodes[:,1]        


        #print 'd_nodes',len(dhash)
        #print 'm_nodes',len(mhash)
        di = num.argsort(dhash)
        mi = num.argsort(mhash)
        minv = num.argsort(mi)
        dinv = num.argsort(di)

        #print 'd_tri',len(domain.get_triangles())
        #print 'm_tri',len(mesh.triangles)
        
        # Check that mesh has been recovered
        # triangle order should be ok
        assert num.allclose(mesh.nodes[mi,:],domain.get_nodes()[di,:])
        assert num.alltrue(minv[mesh.triangles] == dinv[domain.get_triangles()])


        # Check that time has been recovered
        assert num.allclose(time, range(t_end+1))

        z=domain.get_quantity('elevation').get_values(location='vertices').flatten()
        

        
        assert num.allclose(quantities['elevation'], z)

        for q in ['stage', 'xmomentum', 'ymomentum']:
            # Get quantity at last timestep
            q_ref=domain.get_quantity(q).get_values(location='vertices').flatten()

            #print q,quantities[q]
            q_sww=quantities[q][-1,:]
            
            msg = 'Quantity %s failed to be recovered' %q
            assert num.allclose(q_ref, q_sww, atol=1.0e-6), msg
示例#51
0
    def test_sww2pts_centroids_de0(self):
        """Test that sww information can be converted correctly to pts data at specified coordinates
        - in this case, the centroids.
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile
        # Used for points that lie outside mesh
        NODATA_value = 1758323

        # Setup
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create shallow water domain
        domain = Domain(*rectangular(2, 2))

        B = Transmissive_boundary(domain)
        domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})

        domain.set_name('datatest_de0')

        ptsfile = domain.get_name() + '_elevation.pts'
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.set_quantity('elevation', lambda x,y: -x-y)

        domain.geo_reference = Geo_reference(56,308500,6189000)

        sww = SWW_file(domain)
        sww.store_connectivity()
        sww.store_timestep()

        #self.domain.tight_slope_limiters = 1
        domain.evolve_to_end(finaltime = 0.01)
        sww.store_timestep()

        # Check contents in NetCDF
        fid = NetCDFFile(sww.filename, netcdf_mode_r)

        # Get the variables
        x = fid.variables['x'][:]
        y = fid.variables['y'][:]
        elevation = fid.variables['elevation'][:]
        time = fid.variables['time'][:]
        stage = fid.variables['stage'][:]

        volumes = fid.variables['volumes'][:]


        # Invoke interpolation for vertex points       
        points = num.concatenate( (x[:,num.newaxis],y[:,num.newaxis]), axis=1 )
        points = num.ascontiguousarray(points)
        sww2pts(domain.get_name() + '.sww',
                quantity = 'elevation',
                data_points = points,
                NODATA_value = NODATA_value)
        ref_point_values = elevation
        point_values = Geospatial_data(ptsfile).get_attributes()
        #print 'P', point_values
        #print 'Ref', ref_point_values        
        assert num.allclose(point_values, ref_point_values)        



        # Invoke interpolation for centroids
        points = domain.get_centroid_coordinates()
        #print points
        sww2pts(domain.get_name() + '.sww',
                quantity = 'elevation',
                data_points = points,
                NODATA_value = NODATA_value)
        #ref_point_values = [-0.5, -0.5, -1, -1, -1, -1, -1.5, -1.5]   #At centroids

        ref_point_values = [-0.77777777, -0.77777777, -0.99999998, -0.99999998, 
                             -0.99999998, -0.99999998, -1.22222221, -1.22222221]
        point_values = Geospatial_data(ptsfile).get_attributes()
        #print 'P', point_values
        #print 'Ref', ref_point_values        
        assert num.allclose(point_values, ref_point_values)        

        fid.close()

        #Cleanup
        os.remove(sww.filename)
        os.remove(ptsfile)
示例#52
0
    def test_get_maximum_inundation_de0(self):
        """Test that sww information can be converted correctly to maximum
        runup elevation and location (without and with georeferencing)

        This test creates a slope and a runup which is maximal (~11m) at around 10s
        and levels out to the boundary condition (1m) at about 30s.
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        verbose = False
        #Setup

        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (100m x 100m)
        points, vertices, boundary = rectangular(20, 5, 100, 50)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)

        domain.set_flow_algorithm('DE0')
        domain.set_low_froude(0)
        domain.set_minimum_storable_height(0.01)

        filename = 'runup_test_3'
        domain.set_name(filename)
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        # FIXME (Ole): Backwards compatibility
        # Look at sww file and see what happens when
        # domain.tight_slope_limiters = 1
        domain.tight_slope_limiters = 0
        domain.use_centroid_velocities = 0  # Backwards compatibility (7/5/8)

        Br = Reflective_boundary(domain)
        Bd = Dirichlet_boundary([1.0, 0, 0])

        #---------- First run without geo referencing

        domain.set_quantity('elevation', lambda x, y: -0.2 * x + 14)  # Slope
        domain.set_quantity('stage', -6)
        domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime=50):
            pass

        # Check maximal runup
        runup, location, max_time = get_maximum_inundation_data(
            swwfile, return_time=True)
        if verbose:
            print('Runup, location', runup, location, max_time)

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332, 43.333332])
        assert num.allclose(max_time, 10.0)

        # Check runup in restricted time interval
        runup, location, max_time = get_maximum_inundation_data(
            swwfile, time_interval=[0, 9], return_time=True)
        if verbose:
            print('Runup, location:', runup, location, max_time)

        assert num.allclose(runup, 2.66666674614)
        assert num.allclose(location, [56.666668, 16.666666])
        assert num.allclose(max_time, 9.0)

        # Check final runup
        runup, location = get_maximum_inundation_data(swwfile,
                                                      time_interval=[45, 50])
        if verbose:
            print('Runup, location:', runup, location, max_time)

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332, 33.333332])
        #assert num.allclose(max_time, 45.0)

        # Check runup restricted to a polygon
        p = [[50, 1], [99, 1], [99, 40], [50, 40]]
        runup, location = get_maximum_inundation_data(swwfile, polygon=p)
        #runup = get_maximum_inundation_elevation(swwfile, polygon=p)
        #location = get_maximum_inundation_location(swwfile, polygon=p)
        #print runup, location, max_time

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332, 33.333332])
        #assert num.allclose(max_time, 11.0)

        # Check that mimimum_storable_height works
        fid = NetCDFFile(swwfile, netcdf_mode_r)  # Open existing file

        stage = fid.variables['stage_c'][:]
        z = fid.variables['elevation_c'][:]
        xmomentum = fid.variables['xmomentum_c'][:]
        ymomentum = fid.variables['ymomentum_c'][:]

        for i in range(stage.shape[0]):
            h = stage[i] - z  # depth vector at time step i

            # Check every node location
            for j in range(stage.shape[1]):
                # Depth being either exactly zero implies
                # momentum being zero.
                # Or else depth must be greater than or equal to
                # the minimal storable height
                if h[j] == 0.0:
                    assert xmomentum[i, j] == 0.0
                    assert ymomentum[i, j] == 0.0
                else:
                    assert h[j] >= 0.0

        fid.close()

        # Cleanup
        os.remove(swwfile)

        #------------- Now the same with georeferencing

        domain.time = 0.0
        E = 308500
        N = 6189000
        #E = N = 0
        domain.geo_reference = Geo_reference(56, E, N)

        domain.set_quantity('elevation', lambda x, y: -0.2 * x + 14)  # Slope
        domain.set_quantity('stage', -6)
        domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime=50):
            pass

        # Check maximal runup
        runup, location = get_maximum_inundation_data(swwfile)
        #print 'Runup, location', runup, location, max_time

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332 + E, 43.333332 + N])
        #assert num.allclose(max_time, 10.0)

        # Check runup in restricted time interval
        runup, location = get_maximum_inundation_data(swwfile,
                                                      time_interval=[0, 9])
        #print 'Runup, location:',runup, location, max_time

        assert num.allclose(runup, 2.66666674614)
        assert num.allclose(location, [56.666668 + E, 16.666666 + N])
        #assert num.allclose(max_time, 9.0)

        # Check final runup
        runup, location = get_maximum_inundation_data(swwfile,
                                                      time_interval=[45, 50])
        #print 'Runup, location:',runup, location, max_time

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332 + E, 33.333332 + N])
        #assert num.allclose(max_time, 45.0)

        # Check runup restricted to a polygon
        p = num.array([[50, 1], [99, 1], [99, 40], [50, 40]],
                      num.int) + num.array([E, N], num.int)
        runup, location = get_maximum_inundation_data(swwfile, polygon=p)
        #print runup, location, max_time

        assert num.allclose(runup, 3.33333325386)
        assert num.allclose(location, [53.333332 + E, 33.333332 + N])
        #assert num.allclose(max_time, 11.0)

        # Cleanup
        os.remove(swwfile)
示例#53
0
    def test_region_tags(self):
        """get values based on triangle lists."""

        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)

        #Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.build_tagged_elements_dictionary({
            'bottom': [0, 1],
            'top': [4, 5],
            'all': [0, 1, 2, 3, 4, 5]
        })

        #Set friction
        manning = 0.07
        domain.set_quantity('friction', manning)

        a = Set_tag_region('bottom', 'friction', 0.09)
        b = Set_tag_region('top', 'friction', 1.0)
        domain.set_tag_region([a, b])

        expected = [[0.09, 0.09, 0.09], [0.09, 0.09, 0.09], [0.07, 0.07, 0.07],
                    [0.07, 0.07, 0.07], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]
        msg = (
            "\ndomain.quantities['friction']=%s\nexpected value=%s" %
            (str(domain.quantities['friction'].get_values()), str(expected)))
        assert num.allclose(domain.quantities['friction'].get_values(),
                            expected), msg

        #c = Add_Value_To_region('all', 'friction', 10.0)
        domain.set_tag_region(Add_value_to_region('all', 'friction', 10.0))
        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),
                            [[10.09, 10.09, 10.09], [10.09, 10.09, 10.09],
                             [10.07, 10.07, 10.07], [10.07, 10.07, 10.07],
                             [11.0, 11.0, 11.0], [11.0, 11.0, 11.0]])

        # trying a function
        domain.set_tag_region(Set_tag_region('top', 'friction', add_x_y))
        #print domain.quantities['friction'].get_values()
        assert num.allclose(domain.quantities['friction'].get_values(),
                            [[10.09, 10.09, 10.09], [10.09, 10.09, 10.09],
                             [10.07, 10.07, 10.07], [10.07, 10.07, 10.07],
                             [5. / 3, 2.0, 2. / 3], [1.0, 2. / 3, 2.0]])

        domain.set_quantity('elevation', 10.0)
        domain.set_quantity('stage', 10.0)
        domain.set_tag_region(
            Add_value_to_region('top',
                                'stage',
                                1.0,
                                initial_quantity='elevation'))
        #print domain.quantities['stage'].get_values()
        assert num.allclose(
            domain.quantities['stage'].get_values(),
            [[10., 10., 10.], [10., 10., 10.], [10., 10., 10.],
             [10., 10., 10.], [11.0, 11.0, 11.0], [11.0, 11.0, 11.0]])

        domain.set_quantity('elevation', 10.0)
        domain.set_quantity('stage', give_me_23)
        #this works as well, (is cleaner, but doesn't work for regions)
        #domain.set_quantity('stage',
        #                    domain.quantities['stage'].vertex_values+ \
        #                    domain.quantities['elevation'].vertex_values)
        domain.set_tag_region(Add_quantities('top', 'elevation', 'stage'))
        #print domain.quantities['stage'].get_values()
        assert num.allclose(
            domain.quantities['elevation'].get_values(),
            [[10., 10., 10.], [10., 10., 10.], [10., 10., 10.],
             [10., 10., 10.], [33., 33.0, 33.], [33.0, 33., 33.]])
示例#54
0
    def test_get_energy_through_cross_section(self):
        """test_get_energy_through_cross_section(self):

        Test that the specific and total energy through a cross section can be
        correctly obtained from an sww file.
        
        This test creates a flat bed with a known flow through it and tests
        that the function correctly returns the expected energies.

        The specifics are
        u = 2 m/s
        h = 1 m
        w = 3 m (width of channel)

        q = u*h*w = 6 m^3/s
        Es = h + 0.5*v*v/g  # Specific energy head [m]
        Et = w + 0.5*v*v/g  # Total energy head [m]        


        This test uses georeferencing
        
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile

        # Setup
        #from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create basic mesh (20m x 3m)
        width = 3
        length = 20
        t_end = 1
        points, vertices, boundary = rectangular(length, width, length, width)

        # Create shallow water domain
        domain = Domain(points,
                        vertices,
                        boundary,
                        geo_reference=Geo_reference(56, 308500, 6189000))

        domain.default_order = 2
        domain.set_minimum_storable_height(0.01)

        domain.set_name('flowtest')
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.smooth = True

        e = -1.0
        w = 1.0
        h = w - e
        u = 2.0
        uh = u * h

        Br = Reflective_boundary(domain)  # Side walls
        Bd = Dirichlet_boundary([w, uh, 0])  # 2 m/s across the 3 m inlet:

        domain.set_quantity('elevation', e)
        domain.set_quantity('stage', w)
        domain.set_quantity('xmomentum', uh)
        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Br, 'bottom': Br})

        for t in domain.evolve(yieldstep=1, finaltime=t_end):
            pass

        # Check that momentum is as it should be in the interior

        I = [[0, width / 2.], [length / 2., width / 2.], [length, width / 2.]]

        I = domain.geo_reference.get_absolute(I)
        f = file_function(swwfile,
                          quantities=['stage', 'xmomentum', 'ymomentum'],
                          interpolation_points=I,
                          verbose=False)

        for t in range(t_end + 1):
            for i in range(3):
                #print i, t, f(t, i)
                assert num.allclose(f(t, i), [w, uh, 0], atol=1.0e-6)

        # Check energies through the middle
        for i in range(5):
            x = length / 2. + i * 0.23674563  # Arbitrary
            cross_section = [[x, 0], [x, width]]

            cross_section = domain.geo_reference.get_absolute(cross_section)

            time, Es = get_energy_through_cross_section(swwfile,
                                                        cross_section,
                                                        kind='specific',
                                                        verbose=False)
            assert num.allclose(Es, h + 0.5 * u * u / g)

            time, Et = get_energy_through_cross_section(swwfile,
                                                        cross_section,
                                                        kind='total',
                                                        verbose=False)
            assert num.allclose(Et, w + 0.5 * u * u / g)
示例#55
0
    def test_sww2pts_centroids_de0(self):
        """Test that sww information can be converted correctly to pts data at specified coordinates
        - in this case, the centroids.
        """

        import time, os
        from anuga.file.netcdf import NetCDFFile
        # Used for points that lie outside mesh
        NODATA_value = 1758323

        # Setup
        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular

        # Create shallow water domain
        domain = Domain(*rectangular(2, 2))

        B = Transmissive_boundary(domain)
        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})

        domain.set_name('datatest_de0')

        ptsfile = domain.get_name() + '_elevation.pts'
        swwfile = domain.get_name() + '.sww'

        domain.set_datadir('.')
        domain.format = 'sww'
        domain.set_quantity('elevation', lambda x, y: -x - y)

        domain.geo_reference = Geo_reference(56, 308500, 6189000)

        sww = SWW_file(domain)
        sww.store_connectivity()
        sww.store_timestep()

        #self.domain.tight_slope_limiters = 1
        domain.evolve_to_end(finaltime=0.01)
        sww.store_timestep()

        # Check contents in NetCDF
        fid = NetCDFFile(sww.filename, netcdf_mode_r)

        # Get the variables
        x = fid.variables['x'][:]
        y = fid.variables['y'][:]
        elevation = fid.variables['elevation'][:]
        time = fid.variables['time'][:]
        stage = fid.variables['stage'][:]

        volumes = fid.variables['volumes'][:]

        # Invoke interpolation for vertex points
        points = num.concatenate((x[:, num.newaxis], y[:, num.newaxis]),
                                 axis=1)
        points = num.ascontiguousarray(points)
        sww2pts(domain.get_name() + '.sww',
                quantity='elevation',
                data_points=points,
                NODATA_value=NODATA_value)
        ref_point_values = elevation
        point_values = Geospatial_data(ptsfile).get_attributes()
        #print 'P', point_values
        #print 'Ref', ref_point_values
        assert num.allclose(point_values, ref_point_values)

        # Invoke interpolation for centroids
        points = domain.get_centroid_coordinates()
        #print points
        sww2pts(domain.get_name() + '.sww',
                quantity='elevation',
                data_points=points,
                NODATA_value=NODATA_value)
        #ref_point_values = [-0.5, -0.5, -1, -1, -1, -1, -1.5, -1.5]   #At centroids

        ref_point_values = [
            -0.77777777, -0.77777777, -0.99999998, -0.99999998, -0.99999998,
            -0.99999998, -1.22222221, -1.22222221
        ]
        point_values = Geospatial_data(ptsfile).get_attributes()
        #print 'P', point_values
        #print 'Ref', ref_point_values
        assert num.allclose(point_values, ref_point_values)

        fid.close()

        #Cleanup
        os.remove(sww.filename)
        os.remove(ptsfile)
示例#56
0
    def test_areas(self):
        #Create basic mesh
        points, vertices, boundary = rectangular(1, 3)
        domain = General_mesh(points, vertices)

        assert domain.get_area() == 1.0
示例#57
0
    def setUp(self):
        import time

        self.verbose = Test_File_Conversion.verbose
        # Create basic mesh
        points, vertices, boundary = rectangular(2, 2)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.default_order = 2

        # Set some field values
        domain.set_quantity('elevation', lambda x, y: -x)
        domain.set_quantity('friction', 0.03)

        ######################
        # Boundary conditions
        B = Transmissive_boundary(domain)
        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})

        ######################
        #Initial condition - with jumps
        bed = domain.quantities['elevation'].vertex_values
        stage = num.zeros(bed.shape, num.float)

        h = 0.3
        for i in range(stage.shape[0]):
            if i % 2 == 0:
                stage[i, :] = bed[i, :] + h
            else:
                stage[i, :] = bed[i, :]

        domain.set_quantity('stage', stage)

        domain.distribute_to_vertices_and_edges()
        self.initial_stage = copy.copy(
            domain.quantities['stage'].vertex_values)

        self.domain = domain

        C = domain.get_vertex_coordinates()
        self.X = C[:, 0:6:2].copy()
        self.Y = C[:, 1:6:2].copy()

        self.F = bed

        #Write A testfile (not realistic. Values aren't realistic)
        self.test_MOST_file = 'most_small'

        longitudes = [150.66667, 150.83334, 151., 151.16667]
        latitudes = [-34.5, -34.33333, -34.16667, -34]

        long_name = 'LON'
        lat_name = 'LAT'

        nx = 4
        ny = 4
        six = 6

        for ext in ['_ha.nc', '_ua.nc', '_va.nc', '_e.nc']:
            fid = NetCDFFile(self.test_MOST_file + ext, netcdf_mode_w)

            fid.createDimension(long_name, nx)
            fid.createVariable(long_name, netcdf_float, (long_name, ))
            fid.variables[long_name].point_spacing = 'uneven'
            fid.variables[long_name].units = 'degrees_east'
            fid.variables[long_name][:] = longitudes

            fid.createDimension(lat_name, ny)
            fid.createVariable(lat_name, netcdf_float, (lat_name, ))
            fid.variables[lat_name].point_spacing = 'uneven'
            fid.variables[lat_name].units = 'degrees_north'
            fid.variables[lat_name][:] = latitudes

            fid.createDimension('TIME', six)
            fid.createVariable('TIME', netcdf_float, ('TIME', ))
            fid.variables['TIME'].point_spacing = 'uneven'
            fid.variables['TIME'].units = 'seconds'
            fid.variables['TIME'][:] = [0.0, 0.1, 0.6, 1.1, 1.6, 2.1]

            name = ext[1:3].upper()
            if name == 'E.': name = 'ELEVATION'
            fid.createVariable(name, netcdf_float,
                               ('TIME', lat_name, long_name))
            fid.variables[name].units = 'CENTIMETERS'
            fid.variables[name].missing_value = -1.e+034

            fid.variables[name][:] = [
                [[0.3400644, 0, -46.63519, -6.50198], [-0.1214216, 0, 0, 0],
                 [0, 0, 0, 0], [0, 0, 0, 0]],
                [[0.3400644, 2.291054e-005, -23.33335, -6.50198],
                 [-0.1213987, 4.581959e-005, -1.594838e-007, 1.421085e-012],
                 [2.291054e-005, 4.582107e-005, 4.581715e-005, 1.854517e-009],
                 [0, 2.291054e-005, 2.291054e-005, 0]],
                [[0.3400644, 0.0001374632, -23.31503, -6.50198],
                 [-0.1212842, 0.0002756907, 0.006325484, 1.380492e-006],
                 [0.0001374632, 0.0002749264, 0.0002742863, 6.665601e-008],
                 [0, 0.0001374632, 0.0001374632, 0]],
                [[0.3400644, 0.0002520159, -23.29672, -6.50198],
                 [-0.1211696, 0.0005075303, 0.01264618, 6.208276e-006],
                 [0.0002520159, 0.0005040318, 0.0005027961, 2.23865e-007],
                 [0, 0.0002520159, 0.0002520159, 0]],
                [[0.3400644, 0.0003665686, -23.27842, -6.50198],
                 [-0.1210551, 0.0007413362, 0.01896192, 1.447638e-005],
                 [0.0003665686, 0.0007331371, 0.0007313463, 4.734126e-007],
                 [0, 0.0003665686, 0.0003665686, 0]],
                [[0.3400644, 0.0004811212, -23.26012, -6.50198],
                 [-0.1209405, 0.0009771062, 0.02527271, 2.617787e-005],
                 [0.0004811212, 0.0009622425, 0.0009599366, 8.152277e-007],
                 [0, 0.0004811212, 0.0004811212, 0]]
            ]

            fid.close()
    def setUp(self):
        import time
        
        self.verbose = Test_File_Conversion.verbose
        # Create basic mesh
        points, vertices, boundary = rectangular(2, 2)

        # Create shallow water domain
        domain = Domain(points, vertices, boundary)
        domain.default_order = 2

        # Set some field values
        domain.set_quantity('elevation', lambda x,y: -x)
        domain.set_quantity('friction', 0.03)


        ######################
        # Boundary conditions
        B = Transmissive_boundary(domain)
        domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})


        ######################
        #Initial condition - with jumps
        bed = domain.quantities['elevation'].vertex_values
        stage = num.zeros(bed.shape, num.float)

        h = 0.3
        for i in range(stage.shape[0]):
            if i % 2 == 0:
                stage[i,:] = bed[i,:] + h
            else:
                stage[i,:] = bed[i,:]

        domain.set_quantity('stage', stage)


        domain.distribute_to_vertices_and_edges()               
        self.initial_stage = copy.copy(domain.quantities['stage'].vertex_values)


        self.domain = domain

        C = domain.get_vertex_coordinates()
        self.X = C[:,0:6:2].copy()
        self.Y = C[:,1:6:2].copy()

        self.F = bed

        #Write A testfile (not realistic. Values aren't realistic)
        self.test_MOST_file = 'most_small'

        longitudes = [150.66667, 150.83334, 151., 151.16667]
        latitudes = [-34.5, -34.33333, -34.16667, -34]

        long_name = 'LON'
        lat_name = 'LAT'

        nx = 4
        ny = 4
        six = 6


        for ext in ['_ha.nc', '_ua.nc', '_va.nc', '_e.nc']:
            fid = NetCDFFile(self.test_MOST_file + ext, netcdf_mode_w)

            fid.createDimension(long_name,nx)
            fid.createVariable(long_name,netcdf_float,(long_name,))
            fid.variables[long_name].point_spacing='uneven'
            fid.variables[long_name].units='degrees_east'
            fid.variables[long_name][:] = longitudes

            fid.createDimension(lat_name,ny)
            fid.createVariable(lat_name,netcdf_float,(lat_name,))
            fid.variables[lat_name].point_spacing='uneven'
            fid.variables[lat_name].units='degrees_north'
            fid.variables[lat_name][:] = latitudes

            fid.createDimension('TIME',six)
            fid.createVariable('TIME',netcdf_float,('TIME',))
            fid.variables['TIME'].point_spacing='uneven'
            fid.variables['TIME'].units='seconds'
            fid.variables['TIME'][:] = [0.0, 0.1, 0.6, 1.1, 1.6, 2.1]


            name = ext[1:3].upper()
            if name == 'E.': name = 'ELEVATION'
            fid.createVariable(name,netcdf_float,('TIME', lat_name, long_name))
            fid.variables[name].units='CENTIMETERS'
            fid.variables[name].missing_value=-1.e+034

            fid.variables[name][:] = [[[0.3400644, 0, -46.63519, -6.50198],
                                              [-0.1214216, 0, 0, 0],
                                              [0, 0, 0, 0],
                                              [0, 0, 0, 0]],
                                             [[0.3400644, 2.291054e-005, -23.33335, -6.50198],
                                              [-0.1213987, 4.581959e-005, -1.594838e-007, 1.421085e-012],
                                              [2.291054e-005, 4.582107e-005, 4.581715e-005, 1.854517e-009],
                                              [0, 2.291054e-005, 2.291054e-005, 0]],
                                             [[0.3400644, 0.0001374632, -23.31503, -6.50198],
                                              [-0.1212842, 0.0002756907, 0.006325484, 1.380492e-006],
                                              [0.0001374632, 0.0002749264, 0.0002742863, 6.665601e-008],
                                              [0, 0.0001374632, 0.0001374632, 0]],
                                             [[0.3400644, 0.0002520159, -23.29672, -6.50198],
                                              [-0.1211696, 0.0005075303, 0.01264618, 6.208276e-006],
                                              [0.0002520159, 0.0005040318, 0.0005027961, 2.23865e-007],
                                              [0, 0.0002520159, 0.0002520159, 0]],
                                             [[0.3400644, 0.0003665686, -23.27842, -6.50198],
                                              [-0.1210551, 0.0007413362, 0.01896192, 1.447638e-005],
                                              [0.0003665686, 0.0007331371, 0.0007313463, 4.734126e-007],
                                              [0, 0.0003665686, 0.0003665686, 0]],
                                             [[0.3400644, 0.0004811212, -23.26012, -6.50198],
                                              [-0.1209405, 0.0009771062, 0.02527271, 2.617787e-005],
                                              [0.0004811212, 0.0009622425, 0.0009599366, 8.152277e-007],
                                              [0, 0.0004811212, 0.0004811212, 0]]]


            fid.close()