# 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():

[11]:

import torch
import tntorch as tn

t = tn.rand([64]*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:

[12]:

curl = tn.curl(tn.gradient(t))  # List of 3 3D tensors
print(tn.norm(curl[0]))
print(tn.norm(curl[1]))
print(tn.norm(curl[2]))

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):

[3]:

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

[3]:

tensor(4.8832e-08)


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

[5]:

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

[5]:

tensor(0.)