source: trunk/anuga_work/development/mem_time_tests/scenarios/vel2/ex1.py @ 8326

Last change on this file since 8326 was 8326, checked in by pittj, 12 years ago

formatted the experiment scripts

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#------------------------------------------------------------------------------
2# Import necessary modules
3#------------------------------------------------------------------------------
4import anuga
5import time
6import random
7import os
8from anuga.abstract_2d_finite_volumes.util import add_directories
9from anuga.utilities import log
10
11# set up the variables for the temporary files
12home = os.getenv('INUNDATIONHOME')
13scenariodir = add_directories(home, ["data","mem_time_test", "scenarios",
14                                     "velocity"])
15store ='store.txt'
16file_path_store = os.path.join(scenariodir, store)
17storen = 'storen.txt'
18file_path_storen = os.path.join(scenariodir, storen)
19storea = 'storea.txt'
20file_path_storea = os.path.join(scenariodir, storea)
21
22# read the velocity and the map side length from the text files
23f = open(file_path_store,'r+')
24k = float(f.readline())
25f.close()
26f = open(file_path_storen,'r+')
27l = float(f.readline())
28f.close()
29
30#set up variables for the simulation output and the log files
31scenariodirV = add_directories(home, ["data","mem_time_test", "scenarios",
32                                       "velocity", "velocity-" + str(k) +"-"+ str(l)])
33log.log_filename = os.path.join(scenariodirV, "anuga.log")
34log._setup = False
35
36log.resource_usage_timing(prefix = 'BeforeSimulation') #get memory usage
37#------------------------------------------------------------------------------
38# Setup computational domain
39#------------------------------------------------------------------------------
40points, vertices, boundary = anuga.rectangular_cross(100,300, len1=1000, len2=500) # Mesh
41domain = anuga.Domain(points, vertices, boundary) # Create domain
42domain.set_name('channel1') # Output name
43domain.set_datadir(scenariodirV) 
44
45log.resource_usage_timing(prefix = 'AfterMesh')  #get memory usage
46
47#get the number of triangles
48number = len(domain)
49
50#--------------------------------------------------------------------------
51# Setup initial conditions
52#--------------------------------------------------------------------------
53def topography(x, y):
54    return  0.0
55domain.set_quantity('elevation', topography) # Use function for elevation
56domain.set_quantity('friction', 0.01) # Constant friction
57domain.set_quantity('stage', -1000.0)
58
59log.resource_usage_timing(prefix='afterinitialconditions')#get memory usage
60
61#------------------------------------------------------------------------------
62# Setup boundary conditions
63#------------------------------------------------------------------------------
64Bi = anuga.Dirichlet_boundary([0.5, k, 0]) # Inflow
65Br = anuga.Reflective_boundary(domain) # Solid reflective wall
66Bo = anuga.Dirichlet_boundary([-0.5, 0, 0]) # Outflow
67domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
68
69log.resource_usage_timing(prefix='afterboundary')#get memory usage
70
71#------------------------------------------------------------------------------
72# Evolve system through time
73#------------------------------------------------------------------------------
74for t in domain.evolve(yieldstep=0.2, finaltime=40.0):
75    domain.write_time()
76
77log.resource_usage_timing(prefix='aftersimulation')  #get memory usage
78
79#write the number of triangles to the file
80c = open(file_path_storea,'r+')
81c.write(str(number))
Note: See TracBrowser for help on using the repository browser.