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

Adding to a Constant with Multidimensional Bases #302

Open
lecoanet opened this issue Aug 10, 2024 · 0 comments
Open

Adding to a Constant with Multidimensional Bases #302

lecoanet opened this issue Aug 10, 2024 · 0 comments
Assignees

Comments

@lecoanet
Copy link
Member

We seem to have an issue when adding a constant to a boundary-restricted field in problems with multidimensional bases. Here is an example inspired by a post to the users list:

import numpy as np
import dedalus.public as d3

coords = d3.PolarCoordinates('phi', 'r')
dist   = d3.Distributor(coords, dtype=np.float64)
disk   = d3.DiskBasis(coords, shape=(16, 16), radius=1, dtype=np.float64)
cb     = dist.Field(name='cb', bases=disk.edge)

(1+cb).evaluate()

Running this produces an error ValueError: non-broadcastable output operand with shape (1,1) doesn't match the broadcast shape (16,1). This is because the out field in AddFields has shape (1,1) even though its shape should be (16,1). Note that if the operator is cb+1, it code runs. The issue seems to be when building the bases for the out field. This occurs in Add’s _build_bases function. This loops over the coords in args[0].domain.bases_by_coord, and then adds up the bases of the two arguments coord by coord. The issue is that args[0] is 1, and its coords are the PolarCoordinates. However, cb's coords are phi. This means that the bases of the output are also None, which yields the shape of (1,1).

Is the issue that the 1 is not being converted to the proper field? Or is the behavior of _build_bases not expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants