def test_expr_collection(self): """ Test that expressions with different time dimensions are not collected. """ grid = Grid((10,)) f = TimeFunction(name="f", grid=grid, save=10) f2 = TimeFunction(name="f2", grid=grid, save=10) g = TimeFunction(name="g", grid=grid) g2 = TimeFunction(name="g2", grid=grid) w = Function(name="w", grid=grid) eq = Eq(w, f.dt*g + f2.dt*g2) with timed_region('x'): # Since all Function are time dependent, there should be no collection # and produce the same result as with the pre evaluated expression expr = Operator._lower_exprs([eq])[0] expr2 = Operator._lower_exprs([eq.evaluate])[0] assert expr == expr2
def test_lower_func_as_ind(self): grid = Grid((11, 11)) x, y = grid.dimensions t = grid.stepping_dim h = DefaultDimension("h", default_value=10) u = TimeFunction(name='u', grid=grid, time_order=2, space_order=2) oh = Function(name="ou", dimensions=(h, ), shape=(10, ), dtype=int) eq = [Eq(u.forward, u._subs(x, x + oh))] lowered = LoweredEq( Eq(u[t + 1, x + 2, y + 2], u[t, x + oh[h] + 2, y + 2])) with timed_region('x'): leq = Operator._lower_exprs(eq) assert leq[0] == lowered
def test_subdomain_dim(self): """ Test that all dimensions including ones used as an expression are replaced by the subdimension dimensions. """ class sd0(SubDomain): name = 'd0' def define(self, dimensions): x, y = dimensions return {x: ('middle', 1, 6), y: ('middle', 1, 1)} s_d0 = sd0() grid = Grid(shape=(10, 10), subdomains=(s_d0,)) x, y = grid.dimensions x1, y1 = s_d0.dimensions f = Function(name='f', grid=grid, dtype=np.int32) eq0 = Eq(f, x*f+y, subdomain=grid.subdomains['d0']) with timed_region('x'): expr = Operator._lower_exprs([eq0])[0] assert expr.rhs == x1 * f[x1 + 1, y1 + 1] + y1