This example shows how to declare a bilinear form using sympde, then create and evaluate a GLT symbol.
We first start by importing what is needed from sympde and gelato:
# imports from sympde, to write bilinear forms
from sympde.core import Constant
from sympde.calculus import grad, dot
from sympde.topology import ScalarFunctionSpace
from sympde.topology import Domain
from sympde.topology import elements_of
from sympde.expr import BilinearForm
from sympde.expr import integral
# imports from gelato
from gelato import gelatize, GltExpr
A domain is created as follows
domain = Domain('Omega', dim=2)
Then we declare a space of function over our domain
V = ScalarFunctionSpace('V', domain)
and define dummy test functions living in the space V
u,v = elements_of(V, names='u,v')
Finaly, we declare a blinear form, as a lambda expression
# declaring a constant from sympde
c = Constant('c')
expr = dot(grad(v), grad(u)) + c*v*u
a = BilinearForm((u,v), integral(domain, expr))
Now we can create the associated GLT expression to the bilinear form a
glt = GltExpr(a)
The following instruction inspects what is a GltExpr: it is a lambda expression, that has two tuples as inputs: fourier space variables denoted by (tx,ty) and no space variables in this case.
print(glt)
GltExpr([tx, ty], [], BilinearForm(((u,), (v,)), DomainIntegral(Dot(Grad(u), Grad(v)), Omega) + DomainIntegral(c*u*v, Omega)))
We can use a partial evaluation of the GLT expression, by providing the spline degrees
print(glt(degrees=[2,2]))
c*(13*cos(tx)/30 + cos(2*tx)/60 + 11/20)*(13*cos(ty)/30 + cos(2*ty)/60 + 11/20)/(nx*ny) + nx*(-2*cos(tx)/3 - cos(2*tx)/3 + 1)*(13*cos(ty)/30 + cos(2*ty)/60 + 11/20)/ny + ny*(13*cos(tx)/30 + cos(2*tx)/60 + 11/20)*(-2*cos(ty)/3 - cos(2*ty)/3 + 1)/nx
Or numerically, evaluate it, although we are relaying on sympy to perform the evaluation, which is not the right way to proceed. One may use the lambdify function from sympy, or rely on PsyDac to generate automaticaly the discrete GltExpr, when having more complicated expressions (involving a mpping or fields)
print(glt(tx=0.1, ty=0.2, degrees=[2,2], n_elements=[16,16]))
0.00385771212059162*c + 0.0493788050561308
# css style
from IPython.core.display import HTML
def css_styling():
styles = open("../styles/custom.css", "r").read()
return HTML(styles)
css_styling()