def __init__(self, config): self.config = config self.S = sym.S self.iteration = 0 self.need_sync_flag = False # For use in unit tests only. if config is not None: grid = util.get_grid_from_config(config) if grid is None: raise util.GridError('Invalid grid selected: {0}'.format(config.grid)) self.grids = [grid]
def _init_subdomain_envelope(self, sim_class, subdomain_specs): """Sets the size of the ghost node envelope for all subdomains.""" envelope_size = sim_class.nonlocality grid = util.get_grid_from_config(self.config) for vec in grid.basis: for comp in vec: envelope_size = max(sim_class.nonlocality, abs(comp)) # Get rid of any Sympy wrapper objects. envelope_size = int(envelope_size) for subdomain in subdomain_specs: subdomain.set_actual_size(envelope_size)
def _connect_subdomains(self, config): self._init_lower_coord_map(config) connected = set() # TOOD(michalj): Fix this for multi-grid models. grid = util.get_grid_from_config(config) def try_connect(subdomain, pair): # Cannot connect the domain to itself. if subdomain.id == pair.real.id: return False if subdomain.connect(pair, grid): connected.add(subdomain.id) connected.add(pair.real.id) return True return False # Special processing for local periodicity (PBC within a single # subdomain). periodicity = [config.periodic_x, config.periodic_y] if self.dim == 3: periodicity.append(config.periodic_z) for axis in range(self.dim): if not periodicity[axis]: continue for real, virtual in self._coord_map_list[axis][0]: # If the subdomain spans a whole axis of the domain, mark it # as locally periodic. if real.end_location[axis] == self.gsize[axis]: real.enable_local_periodicity(axis) for axis in range(self.dim): for subdomain in sorted(self.subdomains, key=lambda x: x.location[axis]): higher_coord = subdomain.end_location[axis] if higher_coord not in self._coord_map_list[axis]: continue for neighbor_candidate in \ self._coord_map_list[axis][higher_coord]: try_connect(subdomain, neighbor_candidate) # Ensure every subdomain is connected to at least one other subdomain. if len(self.subdomains) > 1 and len(connected) != len(self.subdomains): raise GeometryError('Not all subdomains are connected.')