Skip to content

Wrong computation of the laplacian #406

@GiovanniCanali

Description

@GiovanniCanali

Describe the bug
The Laplace operator applied to a vector field U = (v, w) should be the the vector field of the scalar Laplacian applied to each component. At the moment, the behaviour of the Laplacian applied to a vector field is not correct.

To Reproduce

import torch
from pina import LabelTensor
from pina.operators import laplacian

# Define some input points [x,y] in [0,1]x[3,4].
x = LabelTensor(torch.linspace(0,1,10, requires_grad=True).reshape(-1,1), labels = ['x'])
y = LabelTensor(torch.linspace(3,4,10, requires_grad=True).reshape(-1,1), labels = ['y'])
input_ = LabelTensor(torch.cat((x,y), dim = 1), labels = ['x', 'y'])

# Construct two scalar functions:
# u = x**2 + y**2
# v = x**2 - y**2
u = LabelTensor(input_.extract('x')**2 + input_.extract('y')**2, labels='u')
v = LabelTensor(input_.extract('x')**2 - input_.extract('y')**2, labels='v')

# Define a vector-valued function, whose components are u and v.
f = LabelTensor(torch.cat((u,v), dim = 1), labels = ['u', 'v'])

# Compute the scalar laplacian of both u and v:
# Lap(u) = [4, 4, 4, ..., 4]
# Lap(v) = [0, 0, 0, ..., 0]
lap_u = laplacian(u, input_, components=['u'])
lap_v = laplacian(v, input_, components=['v'])

# Compute the laplacian of f: the two columns should correspond
# to the laplacians of u and v, respectively...
lap_f = laplacian(f, input_, components=['u', 'v'])

# But they don't:
print(all((lap_f.extract(lap_f.labels[0]) - lap_u == 0).flatten()))
print(all((lap_f.extract(lap_f.labels[1]) - lap_v == 0).flatten()))

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions