"""boundary.py - Classes for implementing region conditions NOTE: I've only set it up for testing X values of constants and functions. Although it should work for vectors/arrays of values, that implies knowing info about the actual triangles, and that is not how the user should operate. """ class Region: """Base class for modifying quantities based on a region. """ def __init__(self, location='vertices'): self.location = location def __call__(self, tag, elements, domain): msg = 'Generic class Boundary must be subclassed' raise msg def build_indexes(self, elements, domain): """ Return a list of triangle_id or vertex_id, depending on the location """ if self.location == 'unique vertices': return domain.get_unique_vertices(elements) else: return elements class Set_region(Region): def __init__(self, tag, quantity, X, location='vertices'): """ name: Name of quantity X: const or function location: Where values are to be stored. Permissible options are: vertices, centroid """ Region.__init__(self) self.tag = tag self.quantity = quantity self.location = location self.X = X def __repr__(self): pass def __call__(self, tag, elements, domain): """ """ if tag == self.tag: domain.set_quantity(self.quantity, self.X, location=self.location, indexes=self.build_indexes(elements, domain)) class Add_value_to_region(Region): """ Will add a value to the current quantity value. """ def __init__(self, tag, quantity, X, location='vertices', initial_quantity=None): #I have to get this going! #Region.__init__(self) self.tag = tag self.quantity_answer = quantity self.location = location self.X = X if initial_quantity is None: self.quantity_initial_value = quantity else: self.quantity_initial_value = initial_quantity if callable(X): raise 'This class does not work with functions' def __repr__(self): pass def __call__(self, tag, elements, domain): """ """ if tag == self.tag: new_values = domain.get_quantity(self.quantity_initial_value, indexes=self.build_indexes(elements, domain), location=self.location) + self.X domain.set_quantity(self.quantity_answer, new_values, indexes=self.build_indexes(elements, domain), location=self.location) class Stage_no_less_than_elevation(Region): """ Will set the stage to not be less than the elevation. This would be good, but it's not region dependent. Wait for it to become a default for pyvolution. """ def __init__(self): pass