本文整理汇总了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)