Exemplo n.º 1
0
def test_length_of_link():
    """Test length of links."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_almost_equal(graph.length_of_link,
                              [1., 2., 1., 1., 1., 1., 2., 2., 2., 2., 1., 2.])
Exemplo n.º 2
0
    def __init__(self, *args):
        super(StructuredQuadrilateral, self).__init__(*args)

        if self.ndim < 1 or self.ndim > 3:
            raise ValueError(
                "structured_quadrilateral grid must be rank 1, 2, or 3")

        shape = self.bmi.grid_shape(self.grid_id)

        self.metadata = OrderedDict([
            ("cf_role", "grid_topology"),
            (
                "long_name",
                "Topology data of {}D structured quadrilateral".format(
                    self.ndim),
            ),
            ("topology_dimension", self.ndim),
            ("node_coordinates", " ".join(coordinate_names(self.ndim))),
            ("node_dimensions", " ".join(index_names(self.ndim))),
            ("type", self.grid_type),
        ])
        self.set_mesh()
        self.set_shape(shape)
        nodes = self.get_nodes()
        self.set_nodes()

        graph = StructuredQuadGraph(nodes, shape=tuple(shape))

        self.set_connectivity(data=graph.nodes_at_patch.reshape((-1, )))
        self.set_offset(
            data=np.arange(1, graph.number_of_patches + 1, dtype=np.int32) * 4)
Exemplo n.º 3
0
def test_length_of_link():
    """Test length of links."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert graph.length_of_link == approx(
        [1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 1.0, 2.0])
Exemplo n.º 4
0
def test_links_at_patch():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(
        graph.links_at_patch, [[3, 5, 2, 0], [4, 6, 3, 1], [8, 10, 7, 5], [9, 11, 8, 6]]
    )
Exemplo n.º 5
0
def test_nodes_at_patch():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3), sort=True)
    assert_array_equal(
        graph.nodes_at_patch, [[4, 3, 0, 1], [5, 4, 1, 2], [7, 6, 3, 4], [8, 7, 4, 5]]
    )
Exemplo n.º 6
0
def test_nodes_at_link():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(graph.nodes_at_link,
                       [[0, 1], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5],
                        [3, 6], [4, 7], [5, 8], [6, 7], [7, 8]])
Exemplo n.º 7
0
def test_patches_at_link():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(graph.patches_at_link,
                       [[-1, 0], [-1, 1], [0, -1], [1, 0], [-1, 1], [0, 2],
                        [1, 3], [2, -1], [3, 2], [-1, 3], [2, -1], [3, -1]])
Exemplo n.º 8
0
def test_create():
    """Test creating a quad graph."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))

    assert graph.number_of_nodes == 9
    assert graph.number_of_links == 12
    assert graph.number_of_patches == 4
Exemplo n.º 9
0
def test_links_at_node():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(graph.links_at_node,
                       [[ 0,  2, -1, -1], [ 1,  3,  0, -1], [-1,  4,  1, -1],
                        [ 5,  7, -1,  2], [ 6,  8,  5,  3], [-1,  9,  6,  4],
                        [10, -1, -1,  7], [11, -1, 10,  8], [-1, -1, 11,  9]])
Exemplo n.º 10
0
def test_link_dirs_at_node():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(graph.link_dirs_at_node,
                       [[-1, -1,  0,  0], [-1, -1,  1,  0], [ 0, -1,  1,  0],
                        [-1, -1,  0,  1], [-1, -1,  1,  1], [ 0, -1,  1,  1],
                        [-1,  0,  0,  1], [-1,  0,  1,  1], [ 0,  0,  1,  1]])
Exemplo n.º 11
0
def test_nodes():
    graphs = (
        UniformRectilinearGraph((3, 4)),
        StructuredQuadGraph((
            [[0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0]],
            [[0.0, 1.0, 2.0, 3.0], [0.0, 1.0, 2.0, 3.0], [0.0, 1.0, 2.0, 3.0]],
        )),
        RectilinearGraph(([0.0, 1.0, 2.0], [0.0, 1.0, 2.0, 3.0])),
    )

    for graph in graphs:
        assert_array_equal(graph.nodes,
                           [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])
        with raises(ValueError):
            graph.nodes[0, 0] = 99
Exemplo n.º 12
0
def test_area_of_patch():
    """Test areas of patches."""
    y = [0, 0, 0, 1, 1, 1, 3, 3, 3]
    x = [3, 4, 6, 3, 4, 6, 3, 4, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert graph.area_of_patch == approx([1.0, 2.0, 2.0, 4.0])
Exemplo n.º 13
0
def test_perimeter_nodes():
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_equal(graph.perimeter_nodes, [2, 5, 8, 7, 6, 3, 0, 1])
Exemplo n.º 14
0
def test_area_of_patch():
    """Test areas of patches."""
    y = [0, 1, 3, 0, 1, 3, 0, 1, 3]
    x = [3, 3, 3, 4, 4, 4, 6, 6, 6]
    graph = StructuredQuadGraph((y, x), shape=(3, 3))
    assert_array_almost_equal(graph.area_of_patch, [1., 2., 2., 4.])