Periodic Boundary Conditions

217 views
Skip to first unread message

J Harr

unread,
Jan 25, 2022, 9:23:58 AM1/25/22
to Dedalus Users

Hi,

I would like to solve a periodic BC problem (with real values on the LHS) using Dedalus. However a "Factor is exactly singular" error keeps popping.
I am aware of other threads dealing with this problem but since I don't have BCs I don't see how to relate it to my situation.
As I am very new to Dedalus and spectral methods I am sure the error is right under my nose but I can't seem to find it.

Here is my code:
Lx, Ly = (28, 28)
x_basis = de.Fourier('x', 152, interval=(0, Lx))
y_basis = de.Fourier('y', 152, interval=(0, Ly))
domain = de.Domain([x_basis, y_basis], grid_dtype=np.float64)

def func():
       return one

Gfunc=de.operators.GeneralFunction(domain, 'g', func)
de.operators.parseables["f"] = Gfunc

problem = de.LBVP(domain, variables=['u'])
problem.substitutions["uxx"] = "dx(dx(u))"
problem.substitutions["uyy"] = "dy(dy(u))"
problem.substitutions["uxxxx"] = "dx(dx(dx(dx(u))))"
problem.substitutions["uyyyy"] = "dy(dy(dy(dy(u))))"
problem.add_equation("uxx + uyy + uxxxx + uyyyy = f ")

solver = problem.build_solver()
solver.solve()

Where "one" is a numpy.ndarray of shape (28,28) composed of ones and zeros (describing a shape).

Do you have an idea where the error comes from ?

Kind regards,
Josquin

Daniel Lecoanet

unread,
Jan 25, 2022, 9:29:09 AM1/25/22
to Dedalus Users
Hi Josquin,

The horizontally-averaged mode has dx(u) = dy(u) = 0. For that mode, the equation becomes 0*u = average(f). You can fix this by telling Dedalus to not solve that equation for the horizontally-averaged mode:

problem.add_equation(“uxx + uyy + uxxxx + uyyyy = f”, condition = “(nx !=0) or (ny != 0)”)
problem.add_equation(“u = 0”, condition = “(nx == 0) and (ny == 0)”)

Here I set the horizontal average of u to zero — maybe you want it to be non-zero!

Daniel

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/600a11b9-65e0-4b71-b757-7bdb78064c45n%40googlegroups.com.

J Harr

unread,
Jan 25, 2022, 10:14:32 AM1/25/22
to Dedalus Users
Hi Daniel,

Many thanks for the fast reply, everything works fine now !
I am not sure about the impact of setting the horizontal average to zero but I guess this last equation is necessary for Dedalus ?
If I get rid of it I get a ValueError: Pencil [0, 0] has 0 equations for 1 variables.
If I understand well I can set the horizontal average to n by changing in the last equation "u=n", I think this is fine for my problem.

Kind regards,
Josquin

Daniel Lecoanet

unread,
Jan 25, 2022, 11:03:57 AM1/25/22
to Dedalus Users
Hi Josquin,

Your equation does not set the horizontal average of u. If u = u_0(x, y) is a solution to the equation, so would u_0(x, y) + a + b x + c y, for a, b, c constants. By periodicity, b = c = 0 (assuming the average of f is zero). But you can shift everything by a constant a. This is a degree of freedom that must be specified in order to completely determine u. I think “u=n” is close to what you’re looking for. I think that might set the integral of u to n, not the average. You can experiment to see which it is.

Daniel

J Harr

unread,
Jan 25, 2022, 11:53:17 AM1/25/22
to Dedalus Users
Hi Daniel,

Ok, I get it now.
I've tried changing the constant in "u=n", we can see it shifts everything.

Thanks for the help !

Josquin
Reply all
Reply to author
Forward
0 new messages