1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import os |
---|
5 | import time |
---|
6 | import sys |
---|
7 | import random |
---|
8 | import anuga |
---|
9 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
10 | from anuga.utilities import log |
---|
11 | |
---|
12 | # set up the variables for the temporary files |
---|
13 | home = os.getenv('INUNDATIONHOME') |
---|
14 | scenariodir = add_directories(home, ["data","mem_time_test", "triangles", |
---|
15 | "fromregions"]) |
---|
16 | store ='store.txt' |
---|
17 | file_path_store = os.path.join(scenariodir, store) |
---|
18 | storen ='storen.txt' |
---|
19 | file_path_storen = os.path.join(scenariodir, storen) |
---|
20 | storea = 'storea.txt' |
---|
21 | file_path_storea = os.path.join(scenariodir, storea) |
---|
22 | |
---|
23 | #read the maximum triangle area and map side length from the text files |
---|
24 | f = open(file_path_store,'r+') |
---|
25 | a = float(f.readline()) |
---|
26 | f.close() |
---|
27 | f = open(file_path_storen,'r+') |
---|
28 | l = float(f.readline()) |
---|
29 | f.close() |
---|
30 | |
---|
31 | #set up the variables for the simulation output and the log files |
---|
32 | scenariodirV = add_directories(home, ["data","mem_time_test", "triangles", |
---|
33 | "fromregions", "triangles-" + str(a) +"-"+ str(l)]) |
---|
34 | h = 'CAIRNS.msh' |
---|
35 | file_pathh = os.path.join(scenariodirV, h) |
---|
36 | log.log_filename = os.path.join(scenariodirV, "anuga.log") |
---|
37 | log._setup = False |
---|
38 | |
---|
39 | log.resource_usage_timing(prefix = 'BeforeSimulation') #get memory usage |
---|
40 | #------------------------------------------------------------------------------ |
---|
41 | # Create the triangular mesh and domain |
---|
42 | #------------------------------------------------------------------------------ |
---|
43 | domain = anuga.create_domain_from_regions([(0.0,0.0),(l,l),(0.0,l),(l,0.0)], |
---|
44 | boundary_tags={'top': [0], |
---|
45 | 'right': [1], |
---|
46 | 'bottom': [2], |
---|
47 | 'left': [3]}, |
---|
48 | maximum_triangle_area=a, |
---|
49 | mesh_filename=file_pathh |
---|
50 | ) |
---|
51 | domain.set_name('CAIRNS.sww') # Name of sww file |
---|
52 | domain.set_datadir(scenariodirV)# Store sww output here |
---|
53 | log.resource_usage_timing(prefix = 'AfterMesh') #get memory usage |
---|
54 | #------------------------------------------------------------------------------ |
---|
55 | # Setup initial conditions |
---|
56 | #------------------------------------------------------------------------------ |
---|
57 | |
---|
58 | #get the number of triangles |
---|
59 | number=len(domain) |
---|
60 | |
---|
61 | def topography(x,y): |
---|
62 | return 0.0 |
---|
63 | |
---|
64 | tide = 100.0 |
---|
65 | friction = 0.0 |
---|
66 | domain.set_quantity('stage', tide) |
---|
67 | domain.set_quantity('friction', friction) |
---|
68 | domain.set_quantity('elevation',topography,alpha=0.1) |
---|
69 | |
---|
70 | log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage |
---|
71 | |
---|
72 | #------------------------------------------------------------------------------ |
---|
73 | # Setup boundary conditions |
---|
74 | #------------------------------------------------------------------------------ |
---|
75 | Bi = anuga.Dirichlet_boundary([tide, 223.52, 0]) # inflow |
---|
76 | Bo = anuga.Dirichlet_boundary([-tide, 223.52, 0]) # inflow |
---|
77 | Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary |
---|
78 | Br = anuga.Reflective_boundary(domain) |
---|
79 | domain.set_boundary({'right': Bo,'bottom': Br,'left': Bi,'top': Br}) |
---|
80 | |
---|
81 | log.resource_usage_timing(prefix='afterboundary')#get memory usage |
---|
82 | #------------------------------------------------------------------------------ |
---|
83 | # Evolve system through time |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | for t in domain.evolve(yieldstep=120, finaltime=2000): |
---|
86 | print domain.timestepping_statistics() |
---|
87 | |
---|
88 | log.resource_usage_timing(prefix='aftersimulation')#get memory usage |
---|
89 | |
---|
90 | #write the number of triangles to file |
---|
91 | i = open(file_path_storea, 'r+') |
---|
92 | i.write(str(number)) |
---|