def test_single_scalar(self): grid = Grid(shape=(4, 4)) f = Function(name='f', grid=grid) assign(f, 4) assert np.all(f.data == 4)
def test_multiple_fns_single_scalar(self): grid = Grid(shape=(4, 4)) f = Function(name='f', grid=grid) g = Function(name='g', grid=grid) h = Function(name='h', grid=grid) functions = [f, g, h] assign(functions, 2) assert np.all(f.data == 2) assert np.all(g.data == 2) assert np.all(h.data == 2)
def test_assign_parallel(self): a = np.arange(64).reshape((8, 8)) grid = Grid(shape=a.shape) f = Function(name='f', grid=grid, dtype=np.int32) f.data[:] = a g = Function(name='g', grid=grid, dtype=np.int32) assign(g, f) loc_shape = np.array(grid._distributor.shape) loc_coords = np.array(grid._distributor.mycoords) start = loc_shape * loc_coords stop = loc_shape * (loc_coords + 1) slices = [] for i, j in zip(start, stop): slices.append(slice(i, j, 1)) slices = as_tuple(slices) assert np.all(a[slices] - np.array(g.data[:]) == 0)
def wrapper(self): if self._data is None: debug("Allocating memory for %s%s" % (self.name, self.shape_allocated)) self._data = Data(self.shape_allocated, self.dtype, modulo=self._mask_modulo, allocator=self._allocator) if self._first_touch: assign(self, 0) if callable(self._initializer): if self._first_touch: warning("`first touch` together with `initializer` causing " "redundant data initialization") try: self._initializer(self.data_with_halo) except ValueError: # Perhaps user only wants to initialise the physical domain self._initializer(self.data) else: self.data_with_halo.fill(0) return func(self)
def test_equations_with_options(self): class CompDomain(SubDomain): name = 'comp_domain' def define(self, dimensions): return {d: ('middle', 1, 1) for d in dimensions} comp_domain = CompDomain() grid = Grid(shape=(4, 4), subdomains=comp_domain) f = Function(name='f', grid=grid) g = Function(name='g', grid=grid) functions = [f, g] scalars = 2 options = [None, {'subdomain': grid.subdomains['comp_domain']}] assign(functions, scalars, options=options) assert np.all(f.data == 2) assert np.all( np.array(g.data) == [[0, 0, 0, 0], [0, 2, 2, 0], [0, 2, 2, 0], [0, 0, 0, 0]])