How to import xdmf mesh generated by gmsh into fenics

I have cell neighbours of each element. How can I differentiate the two and define different material.

As I told you

So start at a marked interface, find the two cells connected to that facet.
Give each of the cells a unique number (say cell0 is marked with 5 cell1 is marked with 7).
in sudo-code this is what you need to do for each cell:

def mark_neigbours(cell, tag, interface_markers, volume_markers, visited_cells):
    if c in visited_cells:
         return
    c_facets = facets(cell)
    for facet in c_facets:
        if facet in (interface markers):
            pass
        else
            connected_cells=cells(facet)
            for c in connected_cells:
                if c!= cell
                   volume_markers[c] = tag
                   visited_cells.append(c)
                   mark_neigbours(c, tag, interface_markers, visited_cells)

As I said, this is a recursive algorithm, which is going to be quite complex (and I might have made mistakes in the pseudo code). You should really let the mesh generator handle the tagging of cells.

after marking neighbours how will define the different material for each cell?

That is the whole point of volume_markers, which should be a MeshFunction, which you can modify the array of, with the appropriate tags, such that you can compute integrals over subdomains.

OO I’m such a dumb.

I imported the mesh file

mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

Than I found the cell_neighbours:

tdim = mesh.topology().dim()
mesh.init(tdim - 1, tdim)


cell_neighbours = {}
for cell in cells(mesh):
    index = cell.index()
    cell_neighbours[index] = []
    for facet in facets(cell):
        facet_cells = facet.entities(tdim)
        for facet_cell in facet_cells:
            if (index!=facet_cell):
                cell_neighbours[index].append(facet_cell)
~~~~~~~





to mark the Interface, have to use this function 

~~~~~
def mark_neigbours(cell, tag, interface_markers, volume_markers, visited_cells):
    if c in visited_cells:
         return
    c_facets = facets(cell)
    for facet in c_facets:
        if facet in (interface_markers):
            pass
        else:
            connected_cells=cells(facet)
            for c in connected_cells:
                if (c!= cell):
                   volume_markers[c] = tag
                   visited_cells.append(c)
                   mark_neigbours(c, tag, interface_markers, visited_cells)

I have not understood a single thing what to give in this function and proceed next.

1 Like

As I’ve stated, this is a complicated way of doing it, as the mesh generator should have a way easier time of determining these volumes. I do not have time to write out this algorithm for you.

I’m getting this error. Any Idea? Solution???

UMFPACK V5.7.9 (Oct 20, 2019): ERROR: out of memory

Traceback (most recent call last):
  File "/mnt/c/downloads/run.py", line 90, in <module>
    solve(A_ass, u.vector(), L_ass)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 240, in solve
    return dolfin.la.solver.solve(*args)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/la/solver.py", line 72, in solve
    return cpp.la.solve(A, x, b, method, preconditioner)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to successfully call PETSc function 'KSPSolve'.
*** Reason:  PETSc error code is: 76 (Error in external library).
*** Where:   This error was encountered inside ./dolfin/la/PETScKrylovSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset:  unknown

See for instance UMFPACK error: out of memory despite system having free memory - #2 by plugged