source: trunk/anuga_validation/validation_tests/validation.py @ 8538

Last change on this file since 8538 was 8212, checked in by steve, 14 years ago

Committing Sudi's changes

File size: 3.9 KB
Line 
1import sys
2import anuga
3from math import cos
4from numpy import zeros, float
5from time import localtime, strftime, gmtime
6
7
8class Validation:
9    """
10    """
11
12    def __init__(self, output_file, output_dir):
13        """
14        """
15        self.output_file = output_file
16        self.output_dir = output_dir
17       
18       
19    def set_up_domain(self, dx, dy, length, width):
20        """
21        """
22        points, vertices, boundary = anuga.rectangular_cross(int(length/dx), int(width/dy), length, width, (0.0, -width/2))
23
24        self.domain = anuga.Domain(points, vertices, boundary) 
25
26        self.domain.set_name(self.output_file)               
27        self.domain.set_datadir(self.output_dir) 
28       
29    def set_up_algorithm(self, 
30                         timestepping_method, 
31                         default_order,
32                         use_edge_limiter,
33                         tight_slope_limiters,
34                         use_centroid_velocities,
35                         CFL,
36                         beta_w,
37                         beta_uh,
38                         beta_vh):
39        """
40        """
41        self.domain.set_timestepping_method(timestepping_method)
42        self.domain.set_default_order(default_order)
43
44        self.domain.use_edge_limiter = use_edge_limiter
45        self.domain.tight_slope_limiters = tight_slope_limiters
46        self.domain.use_centroid_velocities = use_centroid_velocities
47
48        self.domain.CFL = CFL
49
50        self.domain.beta_w = beta_w
51        self.domain.beta_uh = beta_uh
52        self.domain.beta_vh = beta_vh
53       
54    def set_initial_conditions(self,
55                               elevation,
56                               friction,
57                               h0,
58                               h1):
59        """
60        """
61        self.domain.set_quantity('elevation', elevation)
62        self.domain.set_quantity('friction', friction)
63
64        def height(x,y):
65            z = zeros(len(x), float)
66            for i in range(len(x)):
67                if x[i]<=50000.0:
68                    z[i] = h0
69                else:
70                    z[i] = h1
71            return z
72
73        self.domain.set_quantity('stage', height)
74       
75    def set_boundary_conditions(self):
76        """
77        """
78        from math import sin, pi, exp
79        Br = anuga.Reflective_boundary(self.domain)      # Solid reflective wall
80        Bt = anuga.Transmissive_boundary(self.domain)    # Continue all values on boundary
81        Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values
82
83        # Associate boundary tags with boundary objects
84        self.domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br})
85
86    def evolve(self, yieldstep=None, finaltime=None, duration=None):
87        """
88        """
89        for t in self.domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
90            print t
91       
92       
93if __name__ == "__main__":
94   
95    time = strftime('%Y%m%d_%H%M%S', localtime())
96
97    output_dir = 'dam_break_' + time
98    output_file = 'dam_break'
99
100    #anuga.copy_code_files(output_dir,__file__)
101   
102    valid = Validation(output_file, output_dir)
103   
104    dx = 1000.
105    dy = dx
106    length = 100000.
107    width = 10*dx
108   
109    valid.set_up_domain(dx, dy, length, width)
110
111    CFL = 1.0
112    beta_w = 0.6
113    beta_uh = 0.6
114    beta_vh = 0.6
115
116    valid.set_up_algorithm(timestepping_method = 'rk2',
117                           default_order =2,
118                           use_edge_limiter = True,
119                           tight_slope_limiters = True,
120                           use_centroid_velocities = False,
121                           CFL = CFL,
122                           beta_w = beta_w,
123                           beta_uh = beta_uh,
124                           beta_vh = beta_vh)
125
126    h0 = 10.0
127    h1 = 1.0
128   
129    valid.set_initial_conditions(0, 0, h0, h1)
130    valid.set_boundary_conditions()
131    valid.evolve(yieldstep = 100.0, finaltime = 60*60.)
132   
133               
134           
Note: See TracBrowser for help on using the repository browser.