How to imply PML in fenicsx?

Then add this to your PYTHONPATH

Yeah, I’ve already add it and it could recognize dolfinx now. But some new problems occur with a Lagrange vector and a N1curl vector hhh(about conj after leading complex module), and I’m checking it. :confounded: There are much more effort I need to pay than I expected haha. Thanks for your help Prof. dokken!! :smiley:

I would suggest having a look at:
https://jsdokken.com/dolfinx-tutorial/chapter1/complex_mode.html
which does mention some common issues.

Thank you for your advice and I will see it carefully to find out the mistake if I can.

I am sorry, but I don’t understand what version of dolfiinx you are using. The link on github brings you to a script that is compatible with dolfinx complex 0.9.0.

If you wish to use an older version where VectorFunctionSpace is still in use, you will fin at the same link the v0.6.0 compatible code:
github.com/bayswiss/autogen_LC_PML/tree/0.6.0

Anyway, the quickest way that I know to install a ready-to-use complex version compatible with such scripts is the following:

conda create -n fenics-env-complex-c conda-forge fenics-dolfinx petsc=*=complex* mpich

Thank you! I remember I see “VectorFunctionSpace” and “ScalarType” in version 0.9.0, but maybe I misremember it. Anyway, thanks for your help! :smiley: I’m trying to adopt the code into a complex dtype version and I will carefully read PML code later.

PETSc.ScalarType occurs here The Poisson problem with complex numbers — FEniCSx tutorial, but PETSc.ScalarType seems not be supported in my PETSC, so can I choose default_scalar_type(1+j) as a alternative of something like ScalarType(1+j)?

In the code at the first link there is no VectorFunctionSpace and the code is compatible with dolfinx v0.9.0 complex. Can you please explain how you installed fenics and which version of dolfinx are you running?

I’m sorry that I misremember it, there is no VectorFunctionSpace and ScalarType is also compatible with is dolfinx v0.9.0. Sorry about it.

If you install fenicsx 0.9.0 complex with conda using the command that I wrote above and you run the script, it will work.

Thanks for your advice! The code is so helpful. However, when reading the passage and the code, I am confused about how I can apply it into my code and I notice that the solution provided in autogen_LC_PML.py seems different from traditional PML.
So, I want to ask if there any guidance documents or samples of autogen_LC_PML.py. (ps: I know that I can get everything from def PML_Functions, but how to apply LAMBDA_PML, detJ, omega, k0, msh, cell_tags, facet_tags into my code and what kind of CAD
document should I input into the function are all my confusions.)

Inside the autogen_LC_PML script I also put some references for this method, that explain how to apply complex coordinate stretch in general:

Y. Mi, X. Yu - Isogeometric locally-conformal perfectly matched layer for time-harmonic acoustics, 2021
H. Beriot, A. Modave - An automatic perfectly matched layer for acoustic finite element simulations in convex domains of general shape, 2020
O. Ozgun, M. Kuzoglus - Locally-Conformal Perfeclty Matched Layer implementation for finite element mesh truncation, 2006

You will need to apply the same coordinate stretch to the Maxwell equations and retrieve a formulation where the \Lambda_{PML} tensor is needed.

Dear Prof. dokken,
I learnt some basic principle of PML from the link you provide and I tried for a few times, the program could run, but something still wrong. Could you tell me where I can find some examples about how to apply PML in EM field? Thanks for your help! :smiley:

Thanks for your help! I would also want to know what ‘air.step’ means. Can I just understand it as a .step document shows the shape of the real domain.
Like, if I get a cube mesh

domain = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, numberofmesh, numberofmesh, numberofmesh)

whether i could create a .step document by:

import gmsh
gmsh.initialize()
gmsh.model.add("cube")
gmsh.model.occ.addBox(0,0,0, 1,1,1)
gmsh.model.occ.synchronize()
gmsh.write("cube.step") 
gmsh.finalize()

I’m a green hand and I’m sorry that I may not understand your model totally. From helmhlze_with_PML.py, I learn that I may only need to add this into the weak forminner(LAMBDA_PML * grad(u), grad(v)) * dx(2) - detJ * k0 ** 2 * inner(u, v) * dx(2) , is this right? And I wonder that how I can get the boundary of real domain since I need to define boundary condition in the real domain, I guess I can only get the whole domain(msh) from this?

LAMBDA_PML, detJ, omega, k0, msh, cell_tags, facet_tags = PML_Functions(CAD_name, mesh_size_max, Num_layers, d_PML,
                                                                        elem_degree=deg)

If you are working with electromagnetic Helmholtz equations, then yes, it will be enough to add the two terms you highlighted to the weak formulation.
If you are working with the full set of Maxwell equations, you will need to derive (yourself) the equations where complex coordinate stretch has been applied.

P.S. Yes, the script was built with real-world applications in mind, where the cad files (.step in this case) are altready available or could be made from someone else. You can create a step file just like you did in gmsh or using another CAD software like FreeCAD. Your choice.

Thanks for your advices!
Yeah, I only need to consider EM field propagating freely in space outside the real domain now I set. So I need a PML to give extra boundary conditions of E and M! Does it consist with electromagnetic Helmholtz equations you mentioned? :smiley:

Dear bay_swiss,
I’m sorry to disturb you. Now I have apply autogen_LC_PML into my script. However, I don’t know how to change the number of grids divided in the main domain other than the PML layer. I read your code and I think that I may achieve it from changing mesh_size_max ? Besides, is .step document just describe the real domain I set and will autogen_LC_PML create PML out the real domain or .step describe the total domain?
Thanks for your help and PML creator, it’s really helpful. :smiley:

The input step file needs to be the physical domain, while the PML layer is automatically extruded by the script. The mesh_size_max sets the elements size for the internal domain mesh. In order to control the pml mesh parameters, you need to play around with the number of layers and thickness of the PML (in the helmholtz script)

So if I can’t tell the frequency of EM field exactly, can I just estimate it approximately?