source: inundation/pyvolution/region.py @ 2126

Last change on this file since 2126 was 1751, checked in by ole, 19 years ago

Changed misspelled 'indexes' to 'indices'

File size: 4.2 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# FIXME (DSG-DSG) add better comments
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_indices(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                                indices=self.build_indices(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                          indices=self.build_indices(elements, domain),
88                          location=self.location) + self.X
89            domain.set_quantity(self.quantity_answer, new_values,
90                                indices=self.build_indices(elements, domain),
91                                location=self.location)
92
93class Add_quantities(Region):
94    """
95    Will add a value to the current quantity value.
96    """
97   
98    def __init__(self, tag, quantity_answer, adding_quantity, location='vertices'):
99        #I have to get this going!
100        #Region.__init__(self)
101        self.tag = tag
102        self.quantity_answer = quantity_answer
103        self.adding_quantity = adding_quantity
104        self.location = location
105
106    def __repr__(self):
107        pass
108   
109    def __call__(self, tag, elements, domain):
110        """
111        """   
112        if tag == self.tag:
113           
114            new_values = domain.get_quantity(self.quantity_answer,
115                          indices=self.build_indices(elements, domain),
116                          location=self.location) \
117                          + domain.get_quantity(self.adding_quantity,
118                          indices=self.build_indices(elements, domain),
119                          location=self.location)
120            domain.set_quantity(self.quantity_answer, new_values,
121                                indices=self.build_indices(elements, domain),
122                                location=self.location)
123
124
125class Stage_no_less_than_elevation(Region):
126    """
127    Will set the stage to not be less than the elevation.
128    This would be good, but it's not region dependent.
129    Wait for it to become a default for pyvolution.
130    """
131   
132    def __init__(self):
133        pass
Note: See TracBrowser for help on using the repository browser.