def test_nosympy_const_expr(): mesh = UnitSquareMesh(3, 3) a = Constant(3) x, y = SpatialCoordinate(mesh) f = a*(x + 2*y) a_ = sp.Symbol('a') # The idea here to say to compile f effectively into # a*(x[0] + x[1]), a=parameter (see the name of the symbol) fe = Expression(f, subs={a: a_}, degree=1, a=2) # Then we can to refer to it fe.a = 4 check = lambda a, b: sqrt(abs(assemble(inner(a-b, a-b)*dx))) < 1E-10 a.assign(Constant(4)) assert check(f, fe)
def test_nosympy_fconst_expr(): mesh = UnitSquareMesh(3, 3) a, b = Constant(3), Constant(4) x, y = SpatialCoordinate(mesh) z = sin(a+b) f = z*(x + 2*y) a_, b_ = sp.symbols('a, b') # The idea here to say to compile f effectively into # a*(x[0] + x[1]), a=parameter (see the name of the symbol) fe = Expression(f, subs={a: a_, b: b_}, degree=1, a=1, b=1) # Then we can to refer to it fe.a = 4 fe.b = 2 check = lambda a, b: sqrt(abs(assemble(inner(a-b, a-b)*dx))) < 1E-10 a.assign(Constant(4)) b.assign(Constant(2)) assert check(f, fe)