How to give two arguments to meshView function

Hi sir,
I created mesh from gmsh with 4 subdomains but in some parts of the code, I want to use only 2 subdomains. So, I am using the Meshview function but it is giving a problem.

thermal_mesh=MeshView.create(interior, 1, 2)

error is

Traceback (most recent call last):
  File "FEM_rz.py", line 377, in <module>
    T=Temperature(mesh, cf, mf, dt, t_max)
  File "FEM_rz.py", line 308, in Temperature
    thermal_mesh=MeshView.create(interior, 1,2)
TypeError: create(): incompatible function arguments. The following argument types are supported:
    1. (self: dolfin::MeshFunction<unsigned long>, arg0: int) -> dolfin::Mesh

Invoked with: <dolfin.cpp.mesh.MeshFunctionSizet object at 0x7fcc72d7b9b0>, 1, 2

A MeshView can only take in one integer.
You need to create a new MeshFunction containing the combination of the two.
Consider the following minimal example, where we have one mf with 3 values; 1,2,3, and we want to make a meshview of those cells marked 1 and 3:

from dolfin import *

mesh = UnitSquareMesh(10, 10)
mf = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)


class Domain1(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] <= 0.2


class Domain2(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] >= 0.2 and x[0] <= 0.5


class Domain3(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] >= 0.5


d1 = Domain1()
d2 = Domain2()
d3 = Domain3()
d1.mark(mf, 1)
d2.mark(mf, 2)
d3.mark(mf, 3)
File("marker.pvd") << mf

mf2 = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
mf2.array()[mf.where_equal(1)] = 1
mf2.array()[mf.where_equal(3)] = 1
view = MeshView.create(mf2, 1)
File("view.pvd") << view
1 Like

Thank you @Dokken,
I appreciate your enthusiasm towards helping or teaching.