source: anuga_work/development/flow_1d/sww_flow/sww_boundary_conditions.py @ 7827

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

Putting 1d stuff in one folder

File size: 2.3 KB
Line 
1#! /usr/bin/python
2
3"""
4Boundaries - specific to the shallow water wave equation
5"""
6__author__="Stephen Roberts"
7__date__ ="$05/06/2010 5:44:05 PM$"
8
9from generic_domain import *
10
11class Dirichlet_boundary(Boundary):
12    """Dirichlet boundary returns constant values for the
13    conserved quantities
14    """
15
16    def __init__(self, quantities=None):
17        Boundary.__init__(self)
18
19        if quantities is None:
20            msg = 'Must specify one value for each evolved quantity, w,uh,z,h,u'
21            raise msg
22
23        self.quantities=numpy.array(quantities, numpy.float)
24
25    def __repr__(self):
26        return 'Dirichlet boundary (%s)' %self.quantities
27
28    def evaluate(self, vol_id=None, edge_id=None):
29        return self.quantities
30
31
32class Reflective_boundary(Boundary):
33    """Reflective boundary returns same conserved quantities as
34    those present in its neighbour volume but reflected.
35
36    This class is specific to the shallow water equation as it
37    works with the momentum quantities assumed to be the second
38    and third conserved quantities.
39    """
40
41    def __init__(self, domain = None):
42        Boundary.__init__(self)
43
44        if domain is None:
45            msg = 'Domain must be specified for reflective boundary'
46            raise msg
47
48        #Handy shorthands
49        self.normals  = domain.normals
50        self.stage    = domain.quantities['stage'].vertex_values
51        self.xmom     = domain.quantities['xmomentum'].vertex_values
52        self.bed      = domain.quantities['elevation'].vertex_values
53        self.height   = domain.quantities['height'].vertex_values
54        self.velocity = domain.quantities['velocity'].vertex_values
55
56
57        self.quantities = numpy.zeros(5, numpy.float)
58
59    def __repr__(self):
60        return 'Reflective_boundary'
61
62
63    def evaluate(self, vol_id, edge_id):
64        """Reflective boundaries reverses the outward momentum
65        of the volume they serve.
66        """
67
68        q = self.quantities
69        q[0] =  self.stage[vol_id, edge_id]
70        q[1] = -self.xmom[vol_id, edge_id]
71        q[2] =  self.bed[vol_id, edge_id]
72        q[3] =  self.height[vol_id, edge_id]
73        q[4] = -self.velocity[vol_id, edge_id]
74
75        #normal = self.normals[vol_id,edge_id]
76
77        return q
78
79
80
81
82if __name__ == "__main__":
83    print "Hello World";
Note: See TracBrowser for help on using the repository browser.