本文整理汇总了Python中anuga.Domain.set_time方法的典型用法代码示例。如果您正苦于以下问题:Python Domain.set_time方法的具体用法?Python Domain.set_time怎么用?Python Domain.set_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anuga.Domain
的用法示例。
在下文中一共展示了Domain.set_time方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rate_operator_rate_from_file
# 需要导入模块: from anuga import Domain [as 别名]
# 或者: from anuga.Domain import set_time [as 别名]
#.........这里部分代码省略.........
t = 90 #Halfway between 60 and 120
q = F(t)
assert num.allclose( (120**2 + 60**2)/2, q[1] )
assert num.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
t = 100 #Two thirds of the way between between 60 and 120
q = F(t)
assert num.allclose( 2*120**2/3 + 60**2/3, q[1] )
assert num.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
#os.remove(filename + '.txt')
#os.remove(filename + '.tms')
domain = Domain(points, vertices)
#Flat surface with 1m of water
domain.set_quantity('elevation', 0)
domain.set_quantity('stage', 1.0)
domain.set_quantity('friction', 0)
Br = Reflective_boundary(domain)
domain.set_boundary({'exterior': Br})
# print domain.quantities['elevation'].centroid_values
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
# Apply operator to these triangles
indices = [0,1,3]
rate = file_function(filename + '.tms', quantities=['Attribute1'])
# Make starttime of domain consistent with tms file starttime
domain.set_starttime(rate.starttime)
factor = 1000.0
default_rate= 17.7
operator = Rate_operator(domain, rate=rate, factor=factor, \
indices=indices, default_rate = default_rate)
# Apply Operator
domain.set_time(360.0)
domain.timestep = 1.0
operator()
d = domain.get_time()**2 * factor + 1.0
stage_ex0 = [ d, d, 1., d]
# print d, domain.get_time(), F(360.0)
# print domain.quantities['elevation'].centroid_values
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex0)
assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum())
domain.set_time(-10.0)
domain.timestep = 1.0
try:
operator()
except:
pass
else:
raise Exception('Should have raised an exception, time too early')
domain.set_time(1300.0)
domain.timestep = 1.0
operator()
d = default_rate*factor + d
stage_ex1 = [ d, d, 1., d]
# print domain.quantities['elevation'].centroid_values
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex1)
assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum())
示例2: test_set_stage_operator_function
# 需要导入模块: from anuga import Domain [as 别名]
# 或者: from anuga.Domain import set_time [as 别名]
def test_set_stage_operator_function(self):
from anuga.config import rho_a, rho_w, eta_w
from math import pi, cos, sin
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]
points = [a, b, c, d, e, f]
# bac, bce, ecf, dbe
vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
domain = Domain(points, vertices)
#Flat surface with 1m of water
domain.set_quantity('elevation', 0)
domain.set_quantity('stage', 1.0)
domain.set_quantity('friction', 0)
Br = Reflective_boundary(domain)
domain.set_boundary({'exterior': Br})
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
# Apply operator to these triangles
indices = [0,1,3]
def stage(t):
if t < 10.0:
return 5.0
else:
return 10.0
operator = Set_stage_operator(domain, stage=stage, indices=indices)
# Apply Operator at time t=1.0
domain.set_time(1.0)
operator()
stage_ex = [ 5., 5., 1., 5.]
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
# Apply Operator at time t=15.0
domain.set_time(15.0)
operator()
stage_ex = [ 10., 10., 1., 10.]
# print domain.quantities['stage'].centroid_values
# print domain.quantities['xmomentum'].centroid_values
# print domain.quantities['ymomentum'].centroid_values
assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)