Skip to content

Demo Helmholtz CSLP - #5769

Open
KarsKnook wants to merge 5 commits into
releasefrom
knook/helmholtz_cslp
Open

KarsKnook wants to merge 5 commits into
releasefrom
knook/helmholtz_cslp

Conversation

@KarsKnook

@KarsKnook KarsKnook commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Demo Helmholtz CSLP

Demo for complex-shifted Laplacian preconditioning for the Helmholtz equation. I believe this is the first demo for complex Firedrake.

@connorjward how do we set it as a test for complex firedrake and not the normal test suite?

Disclaimer
GPT-6.1 Terra was used to create this demo

@KarsKnook
KarsKnook requested a review from connorjward December 3, 2026 17:29
@KarsKnook KarsKnook added the LLM used An LLM was used in the production of this PR label Dec 3, 2026

eps = 1

class CSLP(AuxiliaryOperatorPC):

@pbrubeck pbrubeck Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not aP = a - (1j*eps) * inner(u, v)*dx?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it errors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/scratch/knook/release_complex/venv-firedrake/lib/python3.12/site-packages/petsctools/init.py:70: UserWarning: The PETSc version (3.25.5) does not match the petsc4py version (3.25.0), this may cause unexpected behaviour
  warnings.warn(
Traceback (most recent call last):
  File "petsc4py/PETSc/petscksp.pxi", line 311, in petsc4py.PETSc.KSP_ComputeOps
  File "/scratch/knook/release_complex/venv-firedrake/lib/python3.12/site-packages/firedrake/solving_utils.py", line 547, in compute_operators
    assert P.handle == ctx._pjac.petscmat.handle
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/knook/Documents/firedrake_demos/test.py", line 95, in <module>
    LVS.solve()
  File "petsc4py/PETSc/Log.pyx", line 250, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 251, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/scratch/knook/release_complex/venv-firedrake/lib/python3.12/site-packages/firedrake/adjoint_utils/variational_solver.py", line 108, in wrapper
    out = solve(self, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/knook/release_complex/venv-firedrake/lib/python3.12/site-packages/firedrake/variational_solver.py", line 398, in solve
    self.snes.solve(None, work)
  File "petsc4py/PETSc/SNES.pyx", line 1740, in petsc4py.PETSc.SNES.solve
petsc4py.PETSc.Error: error code 101
[0] SNESSolve() at /scratch/knook/release_complex/petsc/src/snes/interface/snes.c:4951
[0] SNESSolve_KSPONLY() at /scratch/knook/release_complex/petsc/src/snes/impls/ksponly/ksponly.c:49
[0] KSPSolve() at /scratch/knook/release_complex/petsc/src/ksp/ksp/interface/itfunc.c:1094
[0] KSPSolve_Private() at /scratch/knook/release_complex/petsc/src/ksp/ksp/interface/itfunc.c:841
[0] KSPSetUp() at /scratch/knook/release_complex/petsc/src/ksp/ksp/interface/itfunc.c:428
[0] PCSetUp() at /scratch/knook/release_complex/petsc/src/ksp/pc/interface/precon.c:1120
[0] PCSetUp_MG() at /scratch/knook/release_complex/petsc/src/ksp/pc/impls/mg/mg.c:1167
[0] KSPSetUp() at /scratch/knook/release_complex/petsc/src/ksp/ksp/interface/itfunc.c:378

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, weird. I thought we fixed this. Is this the latest release?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think the firedrake install is from 2-3 months back. I will install a new complex developer release Firedrake and try again

@connorjward

Copy link
Copy Markdown
Contributor

@connorjward how do we set it as a test for complex firedrake and not the normal test suite?

I have pushed an untested commit that does this. I am hoping you can continue development but if you encounter issues let me know.

@KarsKnook
KarsKnook requested a review from pbrubeck December 4, 2026 13:56
"pc_type": "python",
"pc_python_type": f"{__name__}.CSLP",
"aux_pc_type": "mg",
"aux_mg_coarse": sp_smoother,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a direct solver here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done, but it's not what's done in the paper we cite or the paper Colin, Josh and I wrote

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we can delete this option and explain that mg_levels also sets mg_coarse

.. image:: helmholtz_cslp.png
:width: 50%

The solver converges in 26 preconditioned FGMRES iterations. The benefit of the complex-shifted Laplacian preconditioner

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a table with the iteration counts for different values of k or eps to illustrate the point you are trying to make?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problems get big relatively quickly due to mesh refinements agains the pollution effect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you may keep k fixed and choose a few values of eps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will not necessarily see the nonrobustness because CSLP becomes worse but GMG better

@@ -0,0 +1,126 @@
Complex-shifted Laplacian preconditioning for the Helmholtz equation

@pbrubeck pbrubeck Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the file be renamed to complex_shifted_helmoltz.py?


eps = k

class CSLP(AuxiliaryOperatorPC):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have a name like ShiftedOperatorPC?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants