source: anuga_core/source/anuga/interface/test_model.py @ 7728

Last change on this file since 7728 was 7728, checked in by hudson, 14 years ago

Added framework and tests for new model API.

File size: 2.7 KB
Line 
1#!/usr/bin/env python
2
3import tempfile
4import unittest
5
6from model import Model
7from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
8
9
10
11class modelTestCase(unittest.TestCase):
12    def setUp(self):
13        self.model = Model()     
14        pass
15
16    def tearDown(self):
17        pass
18
19    def test_construction(self):
20        """ Test initial setup of model. """
21
22        a = [0.0, 0.0]
23        b = [0.0, 2.0]
24        c = [2.0, 0.0]
25        d = [0.0, 4.0]
26        e = [2.0, 2.0]
27        f = [4.0, 0.0]
28
29        points = [a, b, c, d, e, f]
30        #              bac,     bce,     ecf,     dbe
31        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
32
33        self.model.set_geometry(points, vertices)
34
35    def test_simple_example(self):
36        """ Run a new version of the channel1 example. """
37        from anuga.shallow_water import Reflective_boundary
38        from anuga.shallow_water import Dirichlet_boundary
39       
40        self.model.set_geometry(*rectangular_cross(10, 5, len1=10.0, len2=5.0))  # Create domain       
41        self.model.set_name('channel1')                  # Output name
42
43        #------------------------------------------------------------------------------
44        # Setup initial conditions
45        #------------------------------------------------------------------------------
46        def topography(x, y):
47            return -x/10                             # linear bed slope
48
49        self.model.set_quantity('elevation', topography) # Use function for elevation
50        self.model.set_quantity('friction', 0.01)        # Constant friction
51        self.model.set_quantity('stage',                 # Dry bed
52                            expression='elevation') 
53
54        self.model.build()
55       
56        #------------------------------------------------------------------------------
57        # Setup boundary conditions
58        #------------------------------------------------------------------------------
59        Bi = Dirichlet_boundary([0.4, 0, 0])         # Inflow
60    #    Br = Reflective_boundary(domain)             # Solid reflective wall
61
62     #   domain.set_boundary({'left': Bi, 'right': Bi, 'top': Bi, 'bottom': Bi})
63
64        #------------------------------------------------------------------------------
65        # Evolve system through time
66        #------------------------------------------------------------------------------
67   #     for t in domain.evolve(yieldstep=0.2, finaltime=40.0):
68   #         print domain.timestepping_statistics()       
69       
70
71
72################################################################################
73
74if __name__ == '__main__':
75    suite = unittest.makeSuite(modelTestCase,'test')
76    runner = unittest.TextTestRunner() #verbosity=2)
77    runner.run(suite)
78
Note: See TracBrowser for help on using the repository browser.