How to establish boundary conditions on inner irregular geometries?

Hi, I’m working with stokes flow on porous medium. To generate the porous medium mesh, I used nanomesh using a binary image. The problem is that I don’t know how to set the no-slip condition on the inner grains. I labeled the porous space as 1 and the solid phase as 2.
image
How can i establish the inner boundary conditions?

Thank you in advance.

You’d have to mark the interface between 1 and 2 with a facet label. This is done with the MeshFunction object in dolfin and with meshtags in dolfinx. Please search the forum for how to use them, or a the very least clarify whether you are using legacy FEniCS or FEniCSx.

1 Like

I’m using FEniCS.
This is the script that reads the mesh from nanomesh. However, when I wrote the .msh file a warning appeared related with the tags.

mesh_from_file = meshio.read('solidone.msh')  # read the mesh from nanomesh
#Warning: Appending zeros to replace the missing physical tag data.

def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points[:,:2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"physical":[cell_data]})
    return out_mesh

triangle_mesh = create_mesh(mesh_from_file, "triangle", prune_z=True)
meshio.write("mesh.xdmf", triangle_mesh)

mesh = Mesh()
xdmf_file = XDMFFile(MPI.comm_world, "mesh.xdmf")
xdmf_file.read(mesh)
mesh.rotate(270)

#plot(mesh)

bndry = MeshFunction("size_t", mesh, mesh.topology().dim()-1)

Could you help me to understand how to set properly the tags?

There is not much we can do about the warning unless you provide us the mesh file, and a complete script (i.e., also add the imports).

Assuming that you have a mesh file with the subdomain markers, I quickly adapted multiphenics/tutorials/07_restrictions_from_gmsh/data/generate_restrictions.py at master · multiphenics/multiphenics · GitHub to generate the interface markers for your case

from dolfin import *

def generate_interface(mesh, subdomains, subdomain_ids):
    assert isinstance(subdomain_ids, set)
    assert len(subdomain_ids) == 2
    D = mesh.topology().dim()
    # Initialize empty MeshFunction
    mesh_function = MeshFunction("size_t", mesh, D - 1)
    mesh_function.set_all(0)
    # Mark mesh_function based on subdomain ids
    for f in facets(mesh):
        subdomains_ids_f = set(subdomains[c] for c in cells(f))
        assert len(subdomains_ids_f) in (1, 2)
        if subdomains_ids_f == subdomain_ids:
            mesh_function[f] = 1
    # Return
    return mesh_function

# Read in mesh
# TODO

# Read in subdomains as a MeshFunction
# TODO

# Generate interface as a MeshFunction
interface = generate_interface(mesh, subdomains, {1, 2})

There may be some small mistakes since I can’t test this because of the lack of your mesh files, but hopefully it should be enough for you to get started.

1 Like

Hi Francesco, I managed to solve the problem. I combined part of these tutorials to solve it:
1- Nanomesh
2- Marking subdomains
Thank you for your replies.