source: trunk/anuga_1d_core/channel/var_width_depth.py @ 9737

Last change on this file since 9737 was 9098, checked in by steve, 11 years ago

Moved the channel code over from development

File size: 2.8 KB
Line 
1import os
2import random
3from math import sqrt, pow, pi
4from channel_domain import *
5from numpy import allclose, array, zeros, ones, take, sqrt
6from anuga_1d.config import g, epsilon
7
8
9random.seed(111)
10
11print "Variable Width Only Test"
12
13# Define functions for initial quantities
14def initial_area(x):
15    y = zeros(len(x),'f')
16    for i in range(len(x)):
17        y[i]=(10-randomarray[i])
18
19   
20    return y
21
22def width(x):
23
24    y = zeros(len(x),'f')
25    for i in range(len(x)):
26        y[i]=randomarray[i]
27        randomarray[i]=random.normalvariate(3,1)
28    return y
29
30def bed(x):
31
32    y = zeros(len(x),'f')
33    for i in range(len(x)):
34        y[i]=randomarray2[i]
35        randomarray2[i]=random.normalvariate(3,1)
36    return y
37
38
39
40def stage(x):
41
42    y = zeros(len(x),'f')
43    for i in range(len(x)):
44        if x[i]<200 and x[i]>150:
45            y[i]=8.0
46        else:
47            y[i]=8.0
48    return y
49 
50
51
52 
53import time
54
55# Set final time and yield time for simulation
56finaltime = 10.0
57yieldstep = finaltime
58
59# Length of channel (m)
60L = 1000.0   
61# Define the number of cells
62number_of_cells = [100]
63
64# Define cells for finite volume and their size
65N = int(number_of_cells[0])     
66print "Evaluating domain with %d cells" %N
67cell_len = L/N # Origin = 0.0
68points = zeros(N+1,'f')
69
70# Define the centroid points
71for j in range(N+1):
72    points[j] = j*cell_len
73
74# Create domain with centroid points as defined above       
75domain = Domain(points)
76
77# Define random array for width
78randomarray=zeros(len(points),'f')
79for j in range(N+1):
80    randomarray[j]=random.normalvariate(3,1)
81randomarray2=zeros(len(points),'f')
82for j in range(N+1):
83    randomarray2[j]=random.normalvariate(3,1)
84
85
86# Set initial values of quantities - default to zero
87domain.set_quantity('stage',stage,'centroids')
88domain.set_quantity('elevation', bed)
89domain.set_quantity('width',width)
90domain.setstageflag = True
91# Set boundry type, order, timestepping method and limiter
92domain.set_boundary({'exterior':Reflective_boundary(domain)})
93domain.order = 2
94domain.set_timestepping_method('rk2')
95domain.set_CFL(1.0)
96domain.set_limiter("vanleer")
97#domain.h0=0.0001
98
99# Start timer
100t0 = time.time()
101
102
103AreaC = domain.quantities['area'].centroid_values
104BedC = domain.quantities['elevation'].centroid_values
105WidthC = domain.quantities['width'].centroid_values
106#
107AreaC[:] = (10.0 - BedC)* WidthC
108
109
110#print domain.quantities['elevation'].vertex_values
111
112finaltime = 100.0
113yieldstep = 1.0
114
115domain.initialize_plotting(stage_lim = [-1.0, 20.0],
116                           width_lim = [0.0, 6.0],
117                           velocity_lim = [-15.0, 15.0])
118
119
120for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
121    domain.write_time()
122
123    domain.update_plotting()
124
125#print domain.quantities['elevation'].vertex_values
126
127domain.hold_plotting(save='not_well_balanced_random_depth_and_width')
128
Note: See TracBrowser for help on using the repository browser.