Marking surfaces of a 3D mesh (mshr) to apply b.c

Thanks a lot. Unfortunately I am unable to install vtkplotter, I get

Collecting vtkplotter
Downloading vtkplotter-2020.2.4.tar.gz (18.2 MB)
|████████████████████████████████| 18.2 MB 7.3 MB/s
ERROR: Could not find a version that satisfies the requirement vtk (from vtkplotter) (from versions: none)
ERROR: No matching distribution found for vtk (from vtkplotter)

From what I understand from https://github.com/marcomusy/vtkplotter-examples/issues/4, I would need to compile VTK from scratch first. Another can of worms I guess. I’ll go with gmsh and without a program to visualize the solution.

Oh well, no luck with Gmsh either! After having successfully generated a file.msh with the 3D geometry I wanted (same as above with mshr), I cannot work with meshio because of an already reported h5py error message about a version error. The solution proposed at Gmsh 4.4.1 in FEniCS? Meshio to uninstall meshio and h5py and then to reinstall them but h5py with a special command, does not work. It produces a gigantic error message that I reported in that link above.

Thus, I am left unable to work with any mesh generated by Gmsh.

So, I am completely lost after all these efforts. I cannot seem to work with neither mshr (not fixable because it’s too limited) nor Gmsh (due to the h5py problem) at the moment. What are my options left?

What kind of system are you using to run your code? I have never encountered a system Where all of the approaches that has been proposed has failed.

I am using a standard Arch Linux and I run dolfin through docker.

a workaround to use pygmsh is to use the docker image dolfinx/real Which has meshio and pygmsh installed. Then you can create your GEO files and visualize then on your own system with Gmsh.

Hmm I see, thanks a lot. So the dolfinx image would help me in that meshio should work?

Maybe I wasn’t clear, I have no problem with Gmsh itself (I have created a correct file.geo and the corresponding file.msh that I can both check with Gmsh), the problem is with meshio and its h5py relationship. They cannot handle the Gmsh mesh.

Now I can think about another workaround, please let me know what you think. Since I deal with extremely simple meshes that mshr can in principle handle, can I just use the hack to use say numpy and create an array of “positions” and then I’d seek the solution at those positions, and then I do a manual averaging. This would kind of give me the average temperature over the surface (or over lines across the surface). Very far from perfect, but at least it should work, right?

The idea of my suggestion was that using the dolfinx image will speed up your mesh generation efficiency (as you can use pygmsh), and that you can use meshio.

There are probably many ways to hack around your issue, and They might become quite complicated if you want them to run in parallel.

1 Like

@raboynics,

Recently I faced the same annoying issue, but this time I didn’t found any “special command” like in the past. What I did was installing FEniCS and the complementary packages (e.g., meshio, Gmsh, VTKplotter…) using conda since I could find no solution with pip. With conda I didn’t have any further issues.

Regards,
Santiago

2 Likes

Thanks again @dokken. If it’s not too much asked, how can I use the dolfinx image? https://fenicsproject.org/docs/dolfinx/dev/python/installation.html suggests Quay but I cannot visit the website (I don’t have a redhat account).

I tried

docker run -ti -v $(pwd):/home/fenics/shared --name simple_fenics_dolfinx quay.io/fenicsproject/dolfinx

to no avail.

The repository is on dockerhub, thus run docker pull dolfinx/real to Get the image

Thank you once more! The command worked and the files have been downloaded and extracted.

I have a docker question now, after having cd’ed to the working directory, I usually launch the command

docker run -ti -v $(pwd):/home/fenics/shared --name simple_fenics_dolfin quay.io/fenicsproject/dolfin

then I can see the files of the current directory and use the docker image on them.

I am trying something similar with the dolfinx version:

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

I tried with and without the --rm (since I never used it before), to no avail. I mean, it launches the image just fine, but I do not see any of my files, as if it ignored the fact that I had cd’ed to the correct directory before running the command. Do you have an idea how I could fix this?

Just do cd /home/fenics/shared in your container, or add -w /home/fenics/shared to your launch command

There is no folder in the container, so I cannot cd to /home/fenics/shared. It is at /root.

When I do

docker run -ti -v $(pwd):/home/fenics/shared --name fenics_dolfinx -w /home/fenics/shared --rm dolfinx/real

the container starts at /home/fenics/shared, which is an empty directory. When I exit docker and I type “ls”, I can see all my files.

Try this: docker run -ti -v $(pwd):/home/shared -w /home/shared/ --rm dolfinx/real

1 Like

That worked! I don’t really understand why though, but good enough.

I am now trying to adapt my code to dolfinx. Right off the bat I get:

mesh = Mesh()

TypeError: Mesh() missing 5 required positional arguments: ‘comm’, ‘cell_type’, ‘x’, ‘cells’, and ‘ghosts’

I do not want to bother you with all the problems I might encounter, is there a tutorial or some document that could tell me how to roughly transition to dolfinx?

Edit: Ok I found an example at https://fenicsproject.org/docs/dolfinx/dev/python/demos/poisson/demo_poisson.py.html but I have no idea how to adapt it in my case where the mesh comes from gmsh.

I would not suggest you to rewrite your code to dolfinx, just use pygmsh/meshio features and save files you use in dolfin.

Hmm but then I get errors, like the one I mention above. My current code looks like

from dolfinx import *
import numpy as np
import matplotlib.pyplot as plt
#import mshr

import meshio
msh = meshio.read("simple_gmsh_mesh.msh")
for key in msh.cell_data_dict["gmsh:physical"].keys():
    if key == "triangle":
        triangle_data = msh.cell_data_dict["gmsh:physical"][key]
    elif key == "tetra":
        tetra_data = msh.cell_data_dict["gmsh:physical"][key]
for cell in msh.cells:
    if cell.type == "tetra":
        tetra_cells = cell.data
    elif cell.type == "triangle":
        triangle_cells = cell.data
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells},
                         cell_data={"name_to_read":[tetra_data]})
triangle_mesh =meshio.Mesh(points=msh.points,
                           cells=[("triangle", triangle_cells)],
                           cell_data={"name_to_read":[triangle_data]})
meshio.write("file2.xdmf", tetra_mesh)
meshio.write("mf2.xdmf", triangle_mesh)


#set_log_level(LogLevel.ERROR) # works fine with dolfin but not dolfinx.

mesh = Mesh()  # this line produces the error I mention above. I need to modify it and adapt it to dolfinx, right?
with XDMFFile("file2.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf2.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)


mvc2 = MeshValueCollection("size_t", mesh, 3)
with XDMFFile("file2.xdmf") as infile:
    infile.read(mvc2, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc2)

dx = Measure("dx", domain=mesh,subdomain_data=cf)
ds = Measure("ds", domain=mesh, subdomain_data=mf)

subdomains = cf
boundary_parts = mf

I still need to at least perform some adjustments, right?

Just run the quoted code in dolfinx, that creates the xdmf files you Need in dolfin. There should be no Need for import dolfinx to create the mesh files

1 Like

Ah! Bright!

Now I get

Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
  File "file.py", line 303, in <module>
    solve(a == L, u, bcs = bc0)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py", line 220, in solve
    _solve_varproblem(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/fem/solving.py", line 242, in _solve_varproblem
    form_compiler_parameters=form_compiler_parameters)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/fem/problem.py", line 56, in __init__
    a = Form(a, form_compiler_parameters=form_compiler_parameters)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/fem/form.py", line 45, in __init__
    mpi_comm=mesh.mpi_comm())
  File "/usr/local/lib/python3.6/dist-packages/dolfin/jit/jit.py", line 47, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/jit/jit.py", line 97, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/usr/local/lib/python3.6/dist-packages/ffc/jitcompiler.py", line 214, in jit
    kind, module_name = compute_jit_prefix(ufl_object, parameters)
  File "/usr/local/lib/python3.6/dist-packages/ffc/jitcompiler.py", line 143, in compute_jit_prefix
    object_signature = ufl_object.signature()
  File "/usr/local/lib/python3.6/dist-packages/ufl/form.py", line 234, in signature
    self._compute_signature()
  File "/usr/local/lib/python3.6/dist-packages/ufl/form.py", line 471, in _compute_signature
    self._compute_renumbering())
  File "/usr/local/lib/python3.6/dist-packages/ufl/algorithms/signature.py", line 143, in compute_form_signature
    terminal_hashdata = compute_terminal_hashdata(integrands, renumbering)
  File "/usr/local/lib/python3.6/dist-packages/ufl/algorithms/signature.py", line 75, in compute_terminal_hashdata
    data = expr._ufl_signature_data_(renumbering)
  File "/usr/local/lib/python3.6/dist-packages/ufl/argument.py", line 122, in _ufl_signature_data_
    fsdata = self._ufl_function_space._ufl_signature_data_(renumbering)
  File "/usr/local/lib/python3.6/dist-packages/ufl/functionspace.py", line 103, in _ufl_signature_data_
    ddata = domain._ufl_signature_data_(renumbering)
  File "/usr/local/lib/python3.6/dist-packages/ufl/domain.py", line 131, in _ufl_signature_data_
    return ("Mesh", renumbering[self], self._ufl_coordinate_element)
KeyError: Mesh(VectorElement(FiniteElement('Lagrange', tetrahedron, 1), dim=3), 21)

Does this hint at a faulty mesh? I get no error with Gmsh whatsoever, but I know this isn’t a good indicator of a correct mesh.

You Need to supply a minimal working example for anyone to help you. Please supply the mesh files in XDMF-ASCII format , and the dolfin code to produce such an error should be no longer than 20 lines.