# Vector Fields¶

The standard way to represent $$N$$-dimensional vector fields in tntorch is via a list of $$N$$ tensors, each of which has $$N$$ dimensions. Functions that accept or return vector fields do so in that form. For example, gradient():

:

import torch
import tntorch as tn

t = tn.rand(*3, ranks_tt=10)

[3D TT tensor:

64  64  64
|   |   |
(0) (1) (2)
/ \ / \ / \
1   10  10  1
, 3D TT tensor:

64  64  64
|   |   |
(0) (1) (2)
/ \ / \ / \
1   10  10  1
, 3D TT tensor:

64  64  64
|   |   |
(0) (1) (2)
/ \ / \ / \
1   10  10  1
]


We can check that the curl of any gradient is 0:

:

curl = tn.curl(tn.gradient(t))  # List of 3 3D tensors
print(tn.norm(curl))
print(tn.norm(curl))
print(tn.norm(curl))

tensor(1.0344e-06)
tensor(1.4569e-06)
tensor(2.5995e-06)


Let’s also check that the divergence of any curl is zero (we’ll use a random, non-gradient vector field here):

:

vf = [tn.rand(*3, ranks_tt=1) for n in range(3)]
tn.norm(tn.divergence(tn.curl(vf)))

:

tensor(4.8832e-08)


… and that the Laplacian of a scalar field t equals the divergence of t’s gradient:

:

tn.norm(tn.laplacian(t) - tn.divergence(tn.gradient(t)))

:

tensor(0.)