1 | """Simple water flow example using ANUGA |
---|
2 | Water flowing down a channel |
---|
3 | """ |
---|
4 | #------------------------------------------------------------------------------ |
---|
5 | # Import necessary modules |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | # Import standard shallow water domain and standard boundaries. |
---|
8 | import anuga |
---|
9 | import time |
---|
10 | import os |
---|
11 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
12 | from anuga.utilities import log |
---|
13 | |
---|
14 | home = os.getenv('INUNDATIONHOME') |
---|
15 | scenariodir = add_directories(home, ["data","mem_time_test", "parameters", |
---|
16 | "friction"]) |
---|
17 | |
---|
18 | |
---|
19 | #store = 'store.txt' |
---|
20 | #file_path_store = os.path.join(scenariodir, store) |
---|
21 | |
---|
22 | f = open(os.path.join(scenariodir, "store.txt"),'r+') # SQRT extent this is set |
---|
23 | friction = float(f.readline()) |
---|
24 | f.close() |
---|
25 | |
---|
26 | scenariodirV = add_directories(home, ["data","mem_time_test", "parameters", |
---|
27 | "friction","friction-" + str(friction)]) |
---|
28 | |
---|
29 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
30 | log._setup = False |
---|
31 | |
---|
32 | log.resource_usage_timing(prefix = 'BeforeSimulation') |
---|
33 | |
---|
34 | #------------------------------------------------------------------------------ |
---|
35 | # Setup computational domain |
---|
36 | #------------------------------------------------------------------------------ |
---|
37 | points, vertices, boundary = anuga.rectangular_cross(100,300,len1=1000.0, len2=500.0) # Mesh |
---|
38 | domain = anuga.Domain(points, vertices, boundary) # Create domain |
---|
39 | domain.set_datadir(scenariodirV) |
---|
40 | domain.set_name('channel1') # Output name |
---|
41 | |
---|
42 | log.resource_usage_timing(prefix = 'AfterMesh') |
---|
43 | |
---|
44 | #------------------------------------------------------------------------------ |
---|
45 | # Setup initial conditions |
---|
46 | #------------------------------------------------------------------------------ |
---|
47 | def topography(x, y): |
---|
48 | return -x/10 # linear bed slope |
---|
49 | |
---|
50 | log.resource_usage_timing(prefix = 'BeforeInitial') |
---|
51 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
52 | domain.set_quantity('friction', friction) # Constant friction |
---|
53 | domain.set_quantity('stage', # Dry bed |
---|
54 | expression='elevation') |
---|
55 | log.resource_usage_timing(prefix = 'AfterInitial') |
---|
56 | |
---|
57 | #------------------------------------------------------------------------------ |
---|
58 | # Setup boundary conditions |
---|
59 | #------------------------------------------------------------------------------ |
---|
60 | log.resource_usage_timing(prefix = 'BeforeBoundary') |
---|
61 | Bi = anuga.Dirichlet_boundary([0.4, 0, 0]) # Inflow |
---|
62 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
63 | domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
64 | log.resource_usage_timing(prefix = 'AfterBoundary') |
---|
65 | |
---|
66 | #------------------------------------------------------------------------------ |
---|
67 | # Evolve system through time |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | for t in domain.evolve(yieldstep=0.2, finaltime=40.0): |
---|
70 | print domain.timestepping_statistics() |
---|
71 | |
---|
72 | log.resource_usage_timing(prefix = 'AfterSimulation') |
---|