[592] | 1 | """boundary.py - Classes for implementing region conditions |
---|
| 2 | |
---|
| 3 | NOTE: I've only set it up for testing X values of constants and functions. |
---|
| 4 | Although it should work for vectors/arrays of values, that implies |
---|
| 5 | knowing info about the actual triangles, and that is not how the user should |
---|
| 6 | operate. |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | class Region: |
---|
| 11 | """Base class for modifying quantities based on a region. |
---|
| 12 | """ |
---|
| 13 | |
---|
[715] | 14 | def __init__(self, location='vertices'): |
---|
| 15 | self.location = location |
---|
[592] | 16 | |
---|
| 17 | def __call__(self, tag, elements, domain): |
---|
| 18 | msg = 'Generic class Boundary must be subclassed' |
---|
| 19 | raise msg |
---|
| 20 | |
---|
| 21 | |
---|
[715] | 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 | |
---|
| 31 | class Set_region(Region): |
---|
[592] | 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: |
---|
[715] | 54 | domain.set_quantity(self.quantity, |
---|
| 55 | self.X, |
---|
| 56 | location=self.location, |
---|
| 57 | indexes=self.build_indexes(elements, domain)) |
---|
[592] | 58 | |
---|
[715] | 59 | |
---|
| 60 | class Add_value_to_region(Region): |
---|
[592] | 61 | """ |
---|
| 62 | Will add a value to the current quantity value. |
---|
| 63 | """ |
---|
| 64 | |
---|
[715] | 65 | def __init__(self, tag, quantity, X, location='vertices', initial_quantity=None): |
---|
| 66 | #I have to get this going! |
---|
| 67 | #Region.__init__(self) |
---|
[592] | 68 | self.tag = tag |
---|
[715] | 69 | self.quantity_answer = quantity |
---|
[592] | 70 | self.location = location |
---|
| 71 | self.X = X |
---|
[715] | 72 | if initial_quantity is None: |
---|
| 73 | self.quantity_initial_value = quantity |
---|
| 74 | else: |
---|
| 75 | self.quantity_initial_value = initial_quantity |
---|
[592] | 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: |
---|
[715] | 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 | |
---|
| 94 | class 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 |
---|