source: trunk/anuga_work/development/2010-projects/anuga_1d/channel/var_depth_only.py

Last change on this file was 8241, checked in by steve, 12 years ago

Got the ctac figures working

File size: 3.0 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
9print "Variable Width Only Test"
10
11# Define functions for initial quantities
12
13
14
15#def initial_area(x):
16#    y = zeros(len(x),'f')
17#    for i in range(len(x)):
18#        y[i]=(10-randomarray[i])
19#    return y
20
21
22
23def bed(x):
24
25    y = zeros(len(x),'f')
26    for i in range(len(x)):
27        y[i]=randomarray[i]
28        randomarray[i]=random.normalvariate(3,1)
29    return y
30
31
32 
33
34
35def width(x):
36    y = zeros(len(x),'f')
37    return y+1
38
39
40stage = 6.0
41
42def initial_area(x):
43
44    a_bed = bed(x)
45    a_width = width(x)
46
47    a_height = 6.0 - a_bed
48
49    y = a_height*a_width
50
51    return y
52
53
54import time
55
56
57
58# Length of channel (m)
59L = 1000.0   
60# Define the number of cells
61number_of_cells = [50]
62
63# Define cells for finite volume and their size
64N = int(number_of_cells[0])     
65print "Evaluating domain with %d cells" %N
66cell_len = L/N # Origin = 0.0
67points = zeros(N+1,'f')
68
69# Define the centroid points
70for j in range(N+1):
71    points[j] = j*cell_len
72
73# Create domain with centroid points as defined above       
74domain = Domain(points)
75
76# Define random array for width
77
78randomarray=zeros(len(points),'f')
79for j in range(N+1):
80    randomarray[j]=random.normalvariate(3,1)
81
82
83# Set initial values of quantities - default to zero
84#domain.set_quantity('stage',6.0)
85domain.set_quantity('elevation',bed, location='centroids')
86domain.set_quantity('width',width, location='centroids')
87domain.set_quantity('area', initial_area, location='centroids')
88
89
90#domain.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
100#domain.distribute_to_vertices_and_edges()
101
102
103AreaC = domain.quantities['area'].centroid_values
104BedC = domain.quantities['elevation'].centroid_values
105WidthC = domain.quantities['width'].centroid_values
106#
107AreaC[:] = (8.0 - BedC)* WidthC
108
109#domain.set_quantity('area', initial_area)
110
111#domain.distribute_to_vertices_and_edges()
112
113# Start timer
114t0 = time.time()
115i=0
116
117print 'elevation vertex values'
118print domain.quantities['elevation'].vertex_values
119print 'stage vertex values'
120print domain.quantities['stage'].vertex_values
121print 'area vertex values'
122print domain.quantities['area'].vertex_values
123print 'width vertex values'
124print domain.quantities['width'].vertex_values
125
126
127domain.distribute_to_vertices_and_edges()
128
129
130
131# Set final time and yield time for simulation
132finaltime = 100.0
133yieldstep = 1.0
134
135domain.initialize_plotting(stage_lim = [-2.0, 12.0],
136                           width_lim = [0.0, 2.0],
137                           velocity_lim = [-10.0, 10.0])
138
139for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
140    domain.write_time()
141
142    domain.update_plotting()
143
144
145print domain.quantities['elevation'].vertex_values
146
147domain.hold_plotting(save="not_well_balanced_random_depth")
148
149
Note: See TracBrowser for help on using the repository browser.