.. _interface:

**************
Interface Grid
**************

Consider a domain :math:`\Omega \subset \mathbb{R}^d, d \in \{2,3\},` that includes a
:math:`(d-1)`-dimensional interface :math:`\Gamma \subset \Omega`.
We assume the domain is triangulated conforming to the interface :math:`\Gamma`.

.. include:: together.msh.rst

Let us denote this triangulation by :math:`\mathcal{T}` and the set of facets by :math:`\mathcal{F}`.
Due to conforming meshing, there exists a subset of facets :math:`\mathcal{F}_\Gamma \subset \mathcal{F}`
that belong to the interface :math:`\Gamma`.
Therefore, these facets in :math:`\mathcal{F}_\Gamma` can also be interpreted as a triangulation of a surface.
We call this surface triangulation the `interface grid` and denote it by :math:`\mathcal{T}_\Gamma`.

Dune-MMesh features a second implementation of the Dune grid interface that represents the interface triangulation :math:`\mathcal{T}_\Gamma`.
Therefore, facets have to be marked as belonging to the interface - usually this is done when parsing a .msh file.

The interface grid can be used like any other Dune grid as it implements all necessary functionality.

A codim-0 entity of the interface grid is represented by a CGAL cell-index pair as used for the codim-1 entities of the wrapper implementation.
This representation is made unique by taking the representation where the cell has the lower index - which
is also considered to be the positive side of the facet.

All subentity objects can be generated by this representation using the right indexing of vertices.
The geometry representations and element ids are made unique by ascending order of vertex ids as it is done
in the full-dimensional wrapper implementation.

For iteration, CGAL's :code:`finite_edges_iterator` or :code:`finite_facets_iterator` is used skipping all facets not belonging to the interface.
Intersections and neighbor relationships are obtained by CGAL's :code:`incident_edges` or :code:`incident_facets` iterators.
Index sets are implemented by mappings of vertex ids.

The interface grid also supports networks. For this purpose, the intersection iterator returns all common intersections with
adjacent cells. Note that this can be more than one for a single codim-1 subentity.
However, the intersection's outer normal is always independent of the neighbor entity.

.. tikz:: Outer normals at junctions.
  :xscale: 20

  \coordinate (J) at (0,0);
  \coordinate (A) at (-1,0);
  \coordinate (B) at (0.8,0.8);
  \coordinate (C) at (0.2,-0.8);

  \draw[thick] (A) -- (J);
  \draw[->] (J) -- (0.3,0);
  \draw[thick] (B) -- (J);
  \draw[->] (J) -- (-0.21,-0.21);
  \draw[thick] (C) -- (J);
  \draw[->] (J) -- (-0.075,0.3);

Each bulk grid intersection can be identified belonging to the interface or not.
It is also possible to convert bulk intersections to interface grid elements and vice versa as the underlying representation is the same.
When converting an interface grid entity to a bulk intersection, Dune-MMesh returns the intersection as seen from the cell with the lower index.
