source: inundation/ga/storm_surge/pyvolution/region.py @ 715

Last change on this file since 715 was 715, checked in by duncan, 20 years ago

added getting and setting of unique vertex quantities, with a subset of triangles

File size: 3.1 KB
Line 
1"""boundary.py - Classes for implementing region conditions
2
3NOTE: I've only set it up for testing X values of constants and functions.
4Although it should work for vectors/arrays of values, that implies
5knowing info about the actual triangles, and that is not how the user should
6operate.
7"""
8
9
10class Region:
11    """Base class for modifying quantities based on a region.
12    """   
13
14    def __init__(self, location='vertices'):
15        self.location = location
16       
17    def __call__(self, tag, elements, domain):
18        msg = 'Generic class Boundary must be subclassed'
19        raise msg
20
21
22    def build_indexes(self, elements, domain):
23        """
24        Return a list of triangle_id or vertex_id, depending on the location
25        """
26        if self.location == 'unique vertices':
27            return domain.get_unique_vertices(elements)
28        else:
29            return elements
30               
31class Set_region(Region):
32   
33    def __init__(self, tag, quantity, X, location='vertices'):
34        """
35        name: Name of quantity
36        X: const or function
37        location: Where values are to be stored.
38        Permissible options are: vertices, centroid
39        """
40       
41        Region.__init__(self)
42        self.tag = tag
43        self.quantity = quantity
44        self.location = location
45        self.X = X
46
47    def __repr__(self):
48        pass
49   
50    def __call__(self, tag, elements, domain):
51        """
52        """   
53        if tag == self.tag:
54            domain.set_quantity(self.quantity,
55                                self.X,
56                                location=self.location,
57                                indexes=self.build_indexes(elements, domain))
58
59       
60class Add_value_to_region(Region):
61    """
62    Will add a value to the current quantity value.
63    """
64   
65    def __init__(self, tag, quantity, X, location='vertices', initial_quantity=None):
66        #I have to get this going!
67        #Region.__init__(self)
68        self.tag = tag
69        self.quantity_answer = quantity
70        self.location = location
71        self.X = X
72        if initial_quantity is None:
73            self.quantity_initial_value = quantity
74        else:
75            self.quantity_initial_value = initial_quantity
76        if callable(X):
77            raise 'This class does not work with functions' 
78
79    def __repr__(self):
80        pass
81   
82    def __call__(self, tag, elements, domain):
83        """
84        """   
85        if tag == self.tag:
86            new_values = domain.get_quantity(self.quantity_initial_value,
87                          indexes=self.build_indexes(elements, domain),
88                          location=self.location) + self.X
89            domain.set_quantity(self.quantity_answer, new_values,
90                                indexes=self.build_indexes(elements, domain),
91                                location=self.location)
92
93
94class Stage_no_less_than_elevation(Region):
95    """
96    Will set the stage to not be less than the elevation.
97    This would be good, but it's not region dependent.
98    Wait for it to become a default for pyvolution.
99    """
100   
101    def __init__(self):
102        pass
Note: See TracBrowser for help on using the repository browser.