DedalusProject / dedalus

A flexible framework for solving PDEs with modern spectral methods.
http://dedalus-project.org/
GNU General Public License v3.0
489 stars 115 forks source link

Matrix construction for Gradient of Curl (cartesian) #299

Closed lecoanet closed 1 month ago

lecoanet commented 1 month ago

I think there's a problem with matrix construction involving the gradient of the curl of a vector in cartesian geometry. Here is a simple example:

import numpy as np
import dedalus.public as d3

coords = d3.CartesianCoordinates('x','y','z')
dist = d3.Distributor(coords, dtype=np.float64)
xbasis = d3.ComplexFourier(coords['x'], size=64, bounds=(0, 1), dealias=3/2)
ybasis = d3.ComplexFourier(coords['y'], size=64, bounds=(0, 1), dealias=3/2)

v = dist.VectorField(coords, name='v', bases=(xbasis,ybasis))
B0 = dist.VectorField(coords,name='B0',bases=ybasis)

problem = d3.IVP(variables=[v], namespace=locals())
problem.add_equation("dt(v) + B0@grad(curl(v)) = 0")

solver = problem.build_solver(d3.SBDF2)

If you run this, you get an error raise SymbolicParsingError("Must build NCC matrices with same variables.") from here. It is complaining that vars does not match with self._ncc_vars. The latter are [v] as expected.

However, the issue seems to be that CartesianGradient is calling

arg.expression_matrices(subproblem, [self.operand])

here when trying to evaluate dx(curl(v)), which means that expression_matrices is called with vars=[curl(v)]. This means that vars doesn't match with self._ncc_vars yielding the above error. I'm not sure what is supposed to be occurring here, but I seem to remember having a similar issue in the past.

lecoanet commented 1 month ago

This issue is related to the following thread on the users list: https://groups.google.com/u/2/g/dedalus-users/c/n2iYFs4WSQI

kburns commented 1 month ago

Related to or same as #264.