```python
# some imports
from IPython.display import Math
from sympy import sin, cos, pi
from sympy.abc import x,y

from sympde.core import Constant
from sympde.calculus import grad, dot, inner, cross, rot, curl, div
from sympde.calculus import laplace, hessian, bracket, D, conv
from sympde.calculus import jump, avg, minus, plus, Dn

from sympde.topology import (dx, dy, dz)
from sympde.topology import ScalarFunctionSpace, VectorFunctionSpace
from sympde.topology import ScalarField, VectorField
from sympde.topology import ProductSpace
from sympde.topology import Domain, Square
from sympde.topology import element_of, elements_of
from sympde.expr import BilinearForm, LinearForm, integral, find
from sympde.expr import TerminalExpr
from sympde.printing.latex import latex
```


```python
DIM = 2
domain = Domain('Omega', dim=DIM)
```


```python
domain = Square('Omega')
```


```python
V = ScalarFunctionSpace('V', domain)
```


```python
v = element_of(V, name='v')
u = element_of(V, name='u')
```


```python
a = BilinearForm((v,u), integral(domain, dot(grad(v), grad(u))))
```


```python
Math(latex(a))
```




$\displaystyle \left( v, u \right) \mapsto \int_{\Omega} \nabla{u} \cdot \nabla{v} ~d\mathbf{x}$




```python
b = LinearForm(v, integral(domain, cos(x+y)*v))
```


```python
Math(latex(b))
```




$\displaystyle v \mapsto \int_{\Omega} v \cos{\left (x + y \right )} ~d\mathbf{x}$




```python
Math(latex(jump(u)))
```




$\displaystyle [\![ u ]\!]$




```python
Math(latex(avg(u)))
```




$\displaystyle \{ u \}$




```python
Math(latex(minus(u)))
```




$\displaystyle u_{-}$




```python
Math(latex(Dn(u)))
```




$\displaystyle \nabla u \cdot \mathbf{n}$




```python
Math(latex(jump(Dn(u))))
```




$\displaystyle [\![ \nabla u \cdot \mathbf{n} ]\!]$




```python
Math(latex(minus(Dn(u))))
```




$\displaystyle \nabla{u_{-}} \cdot \mathbf{n}_{-}$




```python
Math(latex(plus(Dn(u))))
```




$\displaystyle \nabla{u_{+}} \cdot \mathbf{n}_{+}$




```python
a = BilinearForm((v,u), integral(domain, dot(grad(v), grad(u)) + jump(u)*avg(v) - avg(u)*jump(v)))
```


```python
Math(latex(a))
```




$\displaystyle \left( v, u \right) \mapsto \int_{\Omega} - \{ u \} [\![ v ]\!] ~d\mathbf{x} + \int_{\Omega} \{ v \} [\![ u ]\!] ~d\mathbf{x} + \int_{\Omega} \nabla{u} \cdot \nabla{v} ~d\mathbf{x}$




```python
Math(latex(laplace(u)))
```




$\displaystyle \nabla^2u$




```python
Math(latex(hessian(u)))
```




$\displaystyle \mathrm{hess}( u )$




```python
Math(latex(conv(u, v)))
```




$\displaystyle u \ast v$




```python
W = VectorFunctionSpace('W', domain)
```


```python
w = element_of(W, name='w')
```


```python
Math(latex(D(w)))
```




$\displaystyle \mathrm{D}\left( \mathbf{w} \right)$




```python
l = LinearForm(v, integral(domain.boundary, cos(x+y)*v))
```


```python
Math(latex(l))
```




$\displaystyle v \mapsto \int_{\Gamma_1} v \cos{\left (x + y \right )} ~ds + \int_{\Gamma_2} v \cos{\left (x + y \right )} ~ds + \int_{\Gamma_3} v \cos{\left (x + y \right )} ~ds + \int_{\Gamma_4} v \cos{\left (x + y \right )} ~ds$




```python
equation = find(u, forall=v, lhs=a(u,v), rhs=l(v))
```


```python
Math(latex(equation))
```




$\displaystyle \mbox{find} ~u \in V ~\mbox{such that}\\\int_{\Omega} - \{ v \} [\![ u ]\!] ~d\mathbf{x} + \int_{\Omega} \{ u \} [\![ v ]\!] ~d\mathbf{x} + \int_{\Omega} \nabla{u} \cdot \nabla{v} ~d\mathbf{x} = \int_{\Gamma_1} \left ( v\right ) \cos{\left (x + y \right )} ~ds + \int_{\Gamma_2} \left ( v\right ) \cos{\left (x + y \right )} ~ds + \int_{\Gamma_3} \left ( v\right ) \cos{\left (x + y \right )} ~ds + \int_{\Gamma_4} \left ( v\right ) \cos{\left (x + y \right )} ~ds,\quad \forall~ v \in V$



### Multiple domains


```python
A = Square(r'A')
B = Square(r'B')

domain = A.join(B, name = 'Omega',
            bnd_minus = A.get_boundary(axis=0, ext=1),
            bnd_plus  = B.get_boundary(axis=0, ext=-1))

I = domain.interfaces
```


```python
V = ScalarFunctionSpace('V', domain, kind=None)
```


```python
u, v = elements_of(V, names='u, v')
```


```python
# Nitsch
kappa = Constant('kappa')
expr_I = ( - jump(u) * jump(Dn(v))
           + kappa * jump(u) * jump(v)
           + plus(Dn(u)) * minus(v)
           + minus(Dn(u)) * plus(v) )
a = BilinearForm((u,v), integral(domain, dot(grad(u),grad(v)))
                      + integral(I,      expr_I))
```


```python
Math(latex(a))
```




$\displaystyle \left( u, v \right) \mapsto \int_{\Omega} \nabla{u} \cdot \nabla{v} ~d\mathbf{x} + \int_{A|B} - [\![ u ]\!] [\![ \nabla v \cdot \mathbf{n} ]\!] ~ds + \int_{A|B} \left(\nabla{u_{-}} \cdot \mathbf{n}_{-}\right) v_{+} ~ds + \int_{A|B} \left(\nabla{u_{+}} \cdot \mathbf{n}_{+}\right) v_{-} ~ds + \int_{A|B} \kappa [\![ u ]\!] [\![ v ]\!] ~ds$




```python
expr = TerminalExpr(a)
```


```python
code = r'\\'.join(latex(e) for e in expr)
Math(code)
#print(code)
```




$\displaystyle \textbf{target}~A|B\\- \kappa u_{-} v_{+} + \left(\nabla{v_{+}} \cdot \mathbf{n}_{+}\right) u_{-}\\\textbf{target}~A|B\\- \kappa v_{-} u_{+} + \left(\nabla{v_{-}} \cdot \mathbf{n}_{-}\right) u_{+}\\\textbf{target}~\Gamma_2\\\kappa u v - u \left(\nabla{v} \cdot \mathbf{n}_{-}\right)\\\textbf{target}~\Gamma_1\\\kappa u v - u \left(\nabla{v} \cdot \mathbf{n}_{+}\right)\\\textbf{target}~A\\\partial_x u_{A} \partial_x v_{A} + \partial_y u_{A} \partial_y v_{A}\\\textbf{target}~B\\\partial_x u_{B} \partial_x v_{B} + \partial_y u_{B} \partial_y v_{B}$




```python

```

7639697f871419f372740e3fa506202a4704ddd6
ipynb
Jupyter Notebook
notebooks/Introduction.ipynb
pyccel/sympde
69e6a6634b2045d46286a0453cb66deab5f2e76c
MIT
2018-09-02T17:50:19.000Z
2022-03-08T01:26:47.000Z
notebooks/Introduction.ipynb
pyccel/sympde
69e6a6634b2045d46286a0453cb66deab5f2e76c
MIT
2019-08-18T14:50:01.000Z
2021-09-16T13:54:58.000Z
notebooks/Introduction.ipynb
pyccel/sympde
69e6a6634b2045d46286a0453cb66deab5f2e76c
MIT
2019-10-04T18:05:48.000Z
2020-10-17T02:15:10.000Z
Qwen/Qwen-72B
1. YES
2. YES