# Analytical mapping


```python
from sympy.core.containers import Tuple
from sympy import Matrix
from sympy.tensor import IndexedBase
from sympy import symbols, simplify, Symbol
from sympy import expand
from sympy import cos, sin, sqrt, pi
from sympy import lambdify

from numpy import linspace, meshgrid
from matplotlib import pyplot as plt

from sympde.topology import Mapping, DetJacobian
from sympde.topology import Domain

from sympde.core import Constant
from sympde.calculus import grad, dot, inner, cross, rot, curl, div
from sympde.calculus import laplace, hessian, bracket, convect
from sympde.topology import (dx, dy, dz)
from sympde.topology import (dx1, dx2, dx3)
from sympde.topology import ScalarFunctionSpace, VectorFunctionSpace
from sympde.topology import ScalarTestFunction
from sympde.topology import VectorTestFunction
from sympde.topology import LogicalExpr
from sympde.topology import SymbolicExpr
from sympde.topology import element_of
from sympde.topology import IdentityMapping
from sympde.topology import PolarMapping
from sympde.topology import TargetMapping
from sympde.topology import CzarnyMapping
from sympde.topology import CollelaMapping
from sympde.topology import TorusMapping
from sympde.topology import TwistedTargetMapping
```

## Collela mapping


```python
DIM = 2
M = CollelaMapping('M', DIM)
```


```python
x1, x2 = symbols('x1, x2')

constants = ['eps', 'k1', 'k2']
eps, k1, k2 = [Constant(i) for i in constants]
```


```python
x = LogicalExpr(M, M[0])
y = LogicalExpr(M, M[1])
```


```python
fx = lambdify((x1,x2,eps,k1,k2), x, 'numpy')
fy = lambdify((x1,x2,eps,k1,k2), y, 'numpy')
```


```python
eps = 0.1 ; k1 = 1. ; k2 = 1.
```


```python
T1 = linspace(0., 1., 50)
T2 = linspace(0., 1., 50)
```


```python
ax = plt.axes()
ax.set_aspect('equal')    

# plot columns
for t1 in T1:
    X = fx(t1, T2, eps, k1, k2)
    Y = fy(t1, T2, eps, k1, k2)
    plt.plot(X, Y, '-b',linewidth=0.7)

# plot lines
for t2 in T2:
    X = fx(T1, t2, eps, k1, k2)
    Y = fy(T1, t2, eps, k1, k2)
    plt.plot(X, Y, '-b', linewidth=0.7)    
```

## User mapping


```python
class CustomMapping(Mapping):
    _expressions = {'x': 'A*(x1**2-x2**2)',
                    'y': '2*A*x1*x2'}
```


```python
DIM = 2
M = CustomMapping('M', DIM)
```


```python
x1, x2 = symbols('x1, x2')
A = Constant('A')
```


```python
fx = lambdify((x1,x2,A), LogicalExpr(M, M[0]), 'numpy')
fy = lambdify((x1,x2,A), LogicalExpr(M, M[1]), 'numpy')
```


```python
A = 1.
```


```python
T1 = linspace(-1., 1., 50)
T2 = linspace(-1., 1., 50)
```


```python
ax = plt.axes()
ax.set_aspect('equal')    

# plot columns
for t1 in T1:
    X = fx(t1, T2, A)
    Y = fy(t1, T2, A)
    plt.plot(X, Y, '-b',linewidth=0.7)

# plot lines
for t2 in T2:
    X = fx(T1, t2, A)
    Y = fy(T1, t2, A)
    plt.plot(X, Y, '-b', linewidth=0.7)   
```


```python

```


```python

```

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