[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 | |
---|
| 14 | def __init__(self): |
---|
| 15 | pass |
---|
| 16 | |
---|
| 17 | def __call__(self, tag, elements, domain): |
---|
| 18 | msg = 'Generic class Boundary must be subclassed' |
---|
| 19 | raise msg |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | class Set_Region(Region): |
---|
| 23 | |
---|
| 24 | def __init__(self, tag, quantity, X, location='vertices'): |
---|
| 25 | """ |
---|
| 26 | name: Name of quantity |
---|
| 27 | X: const or function |
---|
| 28 | location: Where values are to be stored. |
---|
| 29 | Permissible options are: vertices, centroid |
---|
| 30 | """ |
---|
| 31 | |
---|
| 32 | Region.__init__(self) |
---|
| 33 | self.tag = tag |
---|
| 34 | self.quantity = quantity |
---|
| 35 | self.location = location |
---|
| 36 | self.X = X |
---|
| 37 | |
---|
| 38 | def __repr__(self): |
---|
| 39 | pass |
---|
| 40 | |
---|
| 41 | def __call__(self, tag, elements, domain): |
---|
| 42 | """ |
---|
| 43 | """ |
---|
| 44 | if tag == self.tag: |
---|
| 45 | domain.set_quantity(self.quantity, self.X, indexes = elements) |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | class Add_Value_To_Region(Region): |
---|
| 49 | """ |
---|
| 50 | Will add a value to the current quantity value. |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | def __init__(self, tag, quantity, X, location='vertex'): |
---|
| 54 | Region.__init__(self) |
---|
| 55 | self.tag = tag |
---|
| 56 | self.quantity = quantity |
---|
| 57 | self.location = location |
---|
| 58 | self.X = X |
---|
| 59 | if callable(X): |
---|
| 60 | raise 'This class does not work with functions' |
---|
| 61 | |
---|
| 62 | def __repr__(self): |
---|
| 63 | pass |
---|
| 64 | |
---|
| 65 | def __call__(self, tag, elements, domain): |
---|
| 66 | """ |
---|
| 67 | """ |
---|
| 68 | if tag == self.tag: |
---|
| 69 | new_values = domain.get_quantity(self.quantity, |
---|
| 70 | indexes = elements) + self.X |
---|
| 71 | domain.set_quantity(self.quantity, new_values, indexes = elements) |
---|