Subtraction between form on the whole domain and the form on a subdomain

I first create a nested rectangles with a subdomain by using

# Create outer rectangle domain
    domain = mesh.create_rectangle(
        comm=MPI.COMM_WORLD,
        points=((0.0, 0.0), (0.4, 0.4)),
        n=(32, 32)
    )

    def inner_domain(x):
        return np.logical_and(
            np.logical_and(x[0] >= 0.1, x[0] <= 0.3),
            np.logical_and(x[1] >= 0.15, x[1] <= 0.25)
        )

    dim = domain.topology.dim
    domain.topology.create_entities(dim)
    inner_cells = mesh.locate_entities(domain, dim, inner_domain)

    # Create default values for all cells
    num_cells = domain.topology.index_map(dim).size_local
    markers_array = np.zeros(num_cells, dtype=np.int32)

    # Set values for inner domain cells
    markers_array[inner_cells] = 1

    # Create MeshTags object
    markers = mesh.meshtags(domain, dim, np.arange(num_cells), markers_array)

    return domain, markers

then I want to define dx and dx_s on the whole domain and the subdomain, and I also want to create form contains the subtraction between the integral on the whole domain and the integral on the subdomain, could you please recommend some documents that contains such things

I think you will need to create submeshes for all the domains and subdomains and also create an entity map to “translate ids” from the different submeshes into the parent mesh. See this script. The hdg demo is another example.

Hello, in the second example it seems that you define another dx on a facet, could you please recommend some doc for integral on subdomain instead of facets

Hello, do you think it is possible to define a scalar function which takes 1 in the subdomain and 0 outsides so we can then use this indicator function to transform the integral on subdomain to integral on the whole domain?

I would suggest reading: Integration measures — FEniCS Tutorial @ Sorbonne