dedalus icon indicating copy to clipboard operation
dedalus copied to clipboard

GeneralFunction includes old syntax

Open catieterrey opened this issue 2 years ago • 1 comments

Note: My version of Dedalus3 was installed using conda as described here

I have been trying to couple my PDE system to gravity, which involves solving the Poisson equation on an unbounded domain. The easiest way to do this would be to calculate the solution directly using the Greens' function in Fourier space.

Here are the important parts of that code:

kx = dist.local_modes(xbasis)
ky = dist.local_modes(ybasis)
kz = dist.local_modes(zbasis)
knorm = np.sqrt(kx**2+ky**2+kz**2)
def convolve_green_func(field):
    return field.data/knorm
def convolve_green_func_op(field):
    return d3.GeneralFunction(
        field.domain,
        layout='c',
        func = convolve_green_func,
        args=(field,)
    )

First off, is there a way to do this without using GeneralFunc?

When I run this it breaks on line 447 of operators.py:

line 447, in __init__
    self.layout = domain.distributor.get_layout_object(layout)
AttributeError: 'Domain' object has no attribute 'distributor'

If I fix this line manually by changing "distributor" to "dist" it works, but then breaks again on line 450:

line 450, in <listcomp>
    self._field_arg_indices = [i for (i,arg) in enumerate(self.args) if is_fieldlike(arg)]
NameError: name 'is_fieldlike' is not defined

I also fixed this in my code by looking at this code in the v2 repo. However, I then get the following errors if I try to include a term of the form grad(V) in my add_equation calls.

File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 17, in __call__
    coordsys = operand.dist.single_coordsys
AttributeError: 'GeneralFunction' object has no attribute 'dist'
 File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 43, in __call__
    args = [Differentiate(operand, coord) for coord in coordsys.coords]
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 43, in __call__
    return subclass(*args, **kw)
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 22, in __call__
    return subclass(*args, **kw)
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 22, in __call__
    self.tensorsig = operand.tensorsig
    return super().__call__(*args, **kw)
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/core/operators.py", line 1297, in __init__
AttributeError: 'GeneralFunction' object has no attribute 'tensorsig'
    return super().__call__(*args, **kw)
    return subclass(*args, **kw)
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/tools/dispatch.py", line 22, in __call__
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/core/operators.py", line 1297, in __init__
    return super().__call__(*args, **kw)
  File "/home/USER/miniconda3/envs/dedalus3/lib/python3.9/site-packages/dedalus/core/operators.py", line 1297, in __init__
    self.tensorsig = operand.tensorsig
AttributeError: 'GeneralFunction' object has no attribute 'tensorsig'

catieterrey avatar Apr 06 '22 00:04 catieterrey

Thanks, yes the GeneralFunction class has not been updated yet. But if you're doing a triply-periodic problem, the easiest option might be just to implicitly solve Poisson's equation for the gravitational potential alongside the rest of your PDE. Have you tried that approach?

kburns avatar Apr 08 '22 15:04 kburns

General Functions are added to v3 with #227.

kburns avatar Feb 06 '23 21:02 kburns