當前位置: 首頁>>代碼示例>>Python>>正文


Python Domain.get_quantity_names方法代碼示例

本文整理匯總了Python中anuga.shallow_water.shallow_water_domain.Domain.get_quantity_names方法的典型用法代碼示例。如果您正苦於以下問題:Python Domain.get_quantity_names方法的具體用法?Python Domain.get_quantity_names怎麽用?Python Domain.get_quantity_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在anuga.shallow_water.shallow_water_domain.Domain的用法示例。


在下文中一共展示了Domain.get_quantity_names方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_read_sww

# 需要導入模塊: from anuga.shallow_water.shallow_water_domain import Domain [as 別名]
# 或者: from anuga.shallow_water.shallow_water_domain.Domain import get_quantity_names [as 別名]

#.........這裏部分代碼省略.........

        # ------------------------------------------------------------------
        # Setup boundary conditions
        # ------------------------------------------------------------------
        Bi = Dirichlet_boundary([0.4, 0, 0])  # Inflow
        Br = Reflective_boundary(domain)  # Solid reflective wall
        Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow

        domain.set_boundary({"left": Bi, "right": Bo, "top": Br, "bottom": Br})

        # -------------------------------------------------------------------
        # Evolve system through time
        # -------------------------------------------------------------------

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

        # Check that quantities have been stored correctly
        source = domain.get_name() + ".sww"

        # x = fid.variables['x'][:]
        # y = fid.variables['y'][:]
        # stage = fid.variables['stage'][:]
        # elevation = fid.variables['elevation'][:]
        # fid.close()

        # assert len(stage.shape) == 2
        # assert len(elevation.shape) == 2

        # M, N = stage.shape

        sww_file = sww.Read_sww(source)

        # print 'last frame number',sww_file.get_last_frame_number()

        assert num.allclose(sww_file.x, domain.get_vertex_coordinates()[:, 0])
        assert num.allclose(sww_file.y, domain.get_vertex_coordinates()[:, 1])

        assert num.allclose(sww_file.time, [0.0, 1.0, 2.0, 3.0, 4.0])

        M = domain.get_number_of_triangles()

        assert num.allclose(num.reshape(num.arange(3 * M), (M, 3)), sww_file.vertices)

        last_frame_number = sww_file.get_last_frame_number()
        assert last_frame_number == 4

        assert num.allclose(sww_file.get_bounds(), [0.0, length, 0.0, width])

        assert "stage" in sww_file.quantities.keys()
        assert "friction" in sww_file.quantities.keys()
        assert "elevation" in sww_file.quantities.keys()
        assert "xmomentum" in sww_file.quantities.keys()
        assert "ymomentum" in sww_file.quantities.keys()

        for qname, q in sww_file.read_quantities(last_frame_number).items():

            # print qname
            # print num.linalg.norm(num.abs((domain.get_quantity(qname).get_values()-q).flatten()), ord=1)

            assert num.allclose(domain.get_quantity(qname).get_values(), q)

        # -----------------------------------------
        # Start the evolution off again at frame 3
        # -----------------------------------------
        sww_file.read_quantities(last_frame_number - 1)

        points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width)
        new_domain = Domain(points, vertices, boundary)
        new_domain.set_quantities_to_be_stored(None)

        new_domain.set_store_vertices_uniquely(True)

        for qname, q in sww_file.read_quantities(last_frame_number - 1).items():
            new_domain.set_quantity(qname, q)

        # ------------------------------------------------------------------
        # Setup boundary conditions
        # ------------------------------------------------------------------
        Bi = Dirichlet_boundary([0.4, 0, 0])  # Inflow
        Br = Reflective_boundary(new_domain)  # Solid reflective wall
        Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow

        new_domain.set_boundary({"left": Bi, "right": Bo, "top": Br, "bottom": Br})

        # -------------------------------------------------------------------
        # Evolve system through time
        # -------------------------------------------------------------------

        for t in new_domain.evolve(yieldstep=1.0, finaltime=1.0):
            pass

        # Compare  new_domain and domain quantities
        for quantity in domain.get_quantity_names():
            dv = domain.get_quantity(quantity).get_values()
            ndv = new_domain.get_quantity(quantity).get_values()

            # print dv-ndv

            assert num.allclose(dv, ndv, rtol=5.0e-2, atol=5.0e-2)
開發者ID:xuexianwu,項目名稱:anuga_core,代碼行數:104,代碼來源:test_read_sww.py


注:本文中的anuga.shallow_water.shallow_water_domain.Domain.get_quantity_names方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。