Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of multiplying MeshVariable by list can be strange #957

Open
guyer opened this issue Sep 28, 2023 · 0 comments
Open

Behavior of multiplying MeshVariable by list can be strange #957

guyer opened this issue Sep 28, 2023 · 0 comments

Comments

@guyer
Copy link
Member

guyer commented Sep 28, 2023

It is often desired to use a scalar field as a vector; as a convection coefficient, for instance. In 1D, this can be achieved by

>>> mesh1D = fp.Grid1D(nx=5)
>>> var1D = fp.CellVariable(mesh=mesh1D, value=mesh1D.x)
>>> print(var1D)
[0.5 1.5 2.5 3.5 4.5]
>>> var1D.rank
0
>>> print(var1D * [[1]])
[[0.5 1.5 2.5 3.5 4.5]]
>>> (var1D * [[1]]).rank
1

Note that

>>> print(var1D * [1])
[0.5 1.5 2.5 3.5 4.5]
>>> (var1D * [1]).rank
0

does not work.

In 2D, FiPy is tolerant about the orientation of the "vector" list:

>>> mesh2D = fp.Grid2D(nx=2, ny=3)
>>> var2D = fp.CellVariable(mesh=mesh2D, value=mesh2D.x * mesh2D.y)
>>> print(var2D)
[0.25 0.75 0.75 2.25 1.25 3.75]
>>> var2D.rank
0
>>> print(var2D * [1,2])
[[0.25 0.75 0.75 2.25 1.25 3.75]
 [0.5  1.5  1.5  4.5  2.5  7.5 ]]
>>> (var2D * [1,2]).rank
1
>>> print(var2D * [[1],[2]])
[[0.25 0.75 0.75 2.25 1.25 3.75]
 [0.5  1.5  1.5  4.5  2.5  7.5 ]]
>>> (var2D * [[1],[2]]).rank
1

It's possible to get strange results if the vector-like list is not of the same dimension as the CellVariable:

>>> print(var2D * [[1]])
[[0.25 0.75 0.75 2.25 1.25 3.75]]
>>> (var2D * [[1]]).rank
1

Multiplying by a singly-nested list always seems to be interpreted as multiplication by a scalar:

>>> print(var2D * [1])
[0.25 0.75 0.75 2.25 1.25 3.75]
>>> (var2D * [1]).rank
0
@guyer guyer changed the title Behavior of multiplying MeshVariable by list is strange Behavior of multiplying MeshVariable by list can be strange Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant