dedalus icon indicating copy to clipboard operation
dedalus copied to clipboard

Integrate not working on S2 basis?

Open kgb0255 opened this issue 1 year ago • 1 comments

Hi!

I'm a new user trying to use dedalus to calculate some integrals with spherical harmonics. I was testing the following simple code snippet to see if the normalization is consistent.

In the code snippet below I attempt to integrate the square of l=2, m=0 spherical harmonics over theta and phi.

import numpy as np
import dedalus.public as d3
from scipy.special import sph_harm


Nphi, Ntheta = 256, 128
dealias = 1
dtype = np.complex128
mesh = None


coords = d3.S2Coordinates('phi', 'theta')
dist = d3.Distributor(coords, dtype=dtype, mesh=mesh)
sphere = d3.SphereBasis(coords, shape=(Nphi, Ntheta), dealias=dealias, radius=1, dtype=dtype)
phi, theta = dist.local_grids(sphere)
phigrid, thetagrid = np.meshgrid(phi[:, 0], theta[0, :], indexing='ij')


Y20 = dist.Field(name='Y20', bases=sphere)
Y20['g'] = sph_harm(0, 2, phigrid, thetagrid)[...]
Y20_sq = Y20*Y20

norm = d3.Integrate(Y20_sq, coords).evaluate()['g'] # should give 1

And I get the following error message.

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[122], line 1
----> 1 d3.Integrate(Y20_sq, coords).evaluate()['g']

File /usr/local/lib/python3.11/site-packages/dedalus/tools/dispatch.py:35, in MultiClass.__call__(cls, *args, **kw)
     32     return exception.output
     34 if len(passlist) == 0:
---> 35     raise NotImplementedError("No subclasses of {} found for the supplied arguments: {}, {}".format(cls, args, kw))
     36 elif len(passlist) > 1:
     37     raise ValueError("Degenerate subclasses of {} found for the supplied arguments {}, {}: {}".format(cls, args, kw, passlist))

NotImplementedError: No subclasses of <class 'dedalus.core.operators.Integrate'> found for the supplied arguments: (Mul(<Field 4825733392>, <Field 4825733392>), <dedalus.core.coords.S2Coordinates object at 0x11f34d450>), {}

Is the integration on 2-sphere not supported?

kgb0255 avatar Jan 16 '25 02:01 kgb0255

This question was asked a while ago, but d3.Average should work multiplied by the area (4*np.pi) as an alternative to d3.Integrate. Though I am not sure what the difference between the two is supposed to be and why both exist.

hifabian avatar Sep 05 '25 08:09 hifabian