Hybrid mesh for PML

Hi again,

I recently posted this question, which helped me to learn how to import .msh files into FEniCS. When I tried to import this mesh


I noticed that only the triangular cells were imported. According to this post, FEniCS does not support such mixed elements. Has it changed since 2018?

These outer layers are PMLs and they are known to be structured. I honestly don’t know how bad would it be if they weren’t. Would you advise me to proceed nevertheless or structured mesh is a must for PMLs?

FEniCS still does not support mixed element meshes. What I would recommend is to switch to dolfinx, as the support for quadrilaterals cells are better there.
I would use unstructured quads in the interior, and structured quads in the PML.

Mixed elements are on the todo list for dolfinx, but it is not a short term goal.

3 Likes

Thank you @dokken. I’ll check it out. So in order to import the mesh you mentioned, what should I change in this snippet?

import numpy as np
import meshio
from fenics import *

msh = meshio.read("<path_to_file>.msh")
clls = np.vstack(( 
    cell.data for cell in msh.cells if cell.type == "triangle"))  # only write 2D cells unless you need lower dimensional elements in your code
meshio.xdmf.write("channel.xdmf", meshio.Mesh(msh.points, cells = {"triangle": clls}))

mesh = Mesh()
XDMFFile("channel.xdmf").read(mesh)

Well, you need to change the underlying msh file to only consist on quadrilaterals. You can use for instance gmsh with a mixture of recombine and transfinite surfaces. See for instance How to create a structured mesh on the L-shape domain? and How to import mixed triangle and quad meshes from gmsh to fenics

1 Like

I’ve remeshed my domain with structured and unstructured quadrilaterals. Now I’m on the process of gueting Dolfinx running properly. To that end, I’m using Docker and I wish to be able to share files between my local system and the Dolfinx container.

I tried

$ sudo docker run -ti -v $(pwd):/home/fenics/shared dolfinx/dolfinx

on the terminal, but then I couldn’t list any file at all. How can this be done?

It would be nice if I could share files between Dolfinx container and Jupyter Lab too (if I’m not asking too much :slightly_smiling_face:)

You can do one out of two things:

  1. Simply do cd /home/fenics/shared after you have started your docker container.
  2. Add the flag -w /home/fenics/shared to the docker command to make it your working directory. Complete command: docker run -ti -v $pwd):/home/fenics/shared -w /home/fenics/shared dolfinx/dolfinx
1 Like

Thank you @dokken, it works. But now I’m facing another problem. I tried running the Poisson and Stokes examples from here. I simply copied the code to a .py file in my shared folder and ran root@6efded275412:/home/fenics/shared# python3 file.py, both gave the error

[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 4 Illegal instruction: Likely due to memory corruption
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors
[0]PETSC ERROR: likely location of problem given in stack below
[0]PETSC ERROR: ---------------------  Stack Frames ------------------------------------
[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,
[0]PETSC ERROR:       INSTEAD the line number of the start of the function
[0]PETSC ERROR:       is given.
application called MPI_Abort(MPI_COMM_WORLD, 50152059) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=50152059
:
system msg for write_line failure : Bad file descriptor

Then I mimicked the code @awarru wrote here. The mesh generation works well, but when I try running the solver I get Illegal instruction (core dumped).

What could it be?

Please provide a minimal example that produces your error. As the interface of dolfin and dolfinx are quite different, consider the demos: https://github.com/FEniCS/dolfinx/tree/master/python/demo

Well, for example the Helmholtz2D example. I created a .py file containing only the headers to see if it runs flawlessly.

helmholtz2D.py

import numpy as np
from mpi4py import MPI
from dolfinx import (Function, FunctionSpace, UnitSquareMesh,has_petsc_complex, solve)
from dolfinx.fem.assemble import assemble_scalar
from dolfinx.io import XDMFFile
from ufl import FacetNormal, TestFunction, TrialFunction, dx, grad, inner

Then I ran on the terminal

$ sudo docker run -ti -v $(pwd):/home/fenics/shared -w /home/fenics/shared dolfinx/dolfinx
root@03fb6df0df2c:/home/fenics/shared# python3 helmholtz2D.py 
Illegal instruction (core dumped)

Have I missed some set-up stage? As I am using the Docker approach I thought everything Dolfinx needs should be self-contained.

I cannot reproduce this error on my system (ubuntu 16.04 running docker with the commands above, except for the sudo in front of docker).
Could you try to single out which of the imports above that causes the error message?

I believe the problem is with the dolfinx library. The Illegal instruction (core dumped) error message is displayed only for

from dolfinx import (Function, FunctionSpace, UnitSquareMesh,has_petsc_complex, solve)
from dolfinx.fem.assemble import assemble_scalar
from dolfinx.io import XDMFFile

imports (I tested them individually)

FEniCS runs ok via Docker though. Maybe some corrupted library in Dolfinx or some hardware limitation could explain this…

As Im am Also running the same docker image, it is most likely a strange hardware limitation. I’ll do another run tomorrow to double check it.
What kind of system and Which version of docker are you using?

Thank you!

Mine is an old machine running ubuntu:

OS: Ubuntu 18.04.4 LTS x86_64 
Kernel: 5.4.0-42-generic 
CPU: AMD Phenom II X6 1090T (6) @ 3.200GHz 
GPU: AMD ATI Radeon 3000 
Memory: 1909MiB / 3681MiB 

and
Docker version 19.03.12, build 48a66213fe

Well, it has something to do with my desktop… I went through this Docker installation guide on my laptop, which runs the same Ubuntu version, and I was able to run the helmholtz2D.py example. Then I uninstalled Docker on my desktop and reinstalled it following the same protocol as for the laptop, but the error remained. As I’ll upgrade my hardware shortly, there’s no need to further investigation. The only thing I’d ask for is a snippet in order to import .msh files with quadrilaterals cells into Dolfinx.
Thanks in advance!

Consider the following example:

import meshio
import numpy as np
mesh = meshio.read("test.msh")

cells = np.vstack(np.array([cells.data for cells in mesh.cells
                            if cells.type == "quad"]))

facet_cells = np.vstack(np.array([cells.data for cells in mesh.cells
                                  if cells.type == "line"]))

facet_data = mesh.cell_data_dict["gmsh:physical"]["line"]
cell_data = mesh.cell_data_dict["gmsh:physical"]["quad"]
triangle_mesh = meshio.Mesh(points=mesh.points,
                            cells=[("quad", cells)],
                            cell_data={"name_to_read": [cell_data]})

facet_mesh = meshio.Mesh(points=mesh.points,
                         cells=[("line", facet_cells)],
                         cell_data={"name_to_read": [facet_data]})
meshio.xdmf.write("mesh.xdmf", triangle_mesh)
meshio.xdmf.write("facet_mesh.xdmf", facet_mesh)

from dolfinx.io import XDMFFile
from mpi4py import MPI
with XDMFFile(MPI.COMM_WORLD, "mesh.xdmf", "r") as xdmf:
    mesh = xdmf.read_mesh(name="Grid")
1 Like