# Meshes.jl - CartesianGrid - FaceElement connectivity

**URL:** <https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [September 16, 2024, 8:10pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473 "2024-09-16T20:10:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [September 16, 2024, 8:10pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/1 "2024-09-16T20:10:36Z")

</div>

How can I build the face-element connectivity of a 2D CartesianGrid in Meshes.jl ? Thx!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2024, 8:17pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/2 "2024-09-16T20:17:06Z")

</div>

@Domenico_Lahaye please tag your questions with `meshes`, otherwise we don’t receive notifications.

Did you check the documentation page on topological relations?

> **[Meshes · Meshes.jl](https://juliageometry.github.io/MeshesDocs/stable/domains/meshes/)**
>
> Documentation for Meshes.jl.

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [September 16, 2024, 8:27pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/3 "2024-09-16T20:27:07Z")

</div>

1/ Sincere apologies for leaving _meshes_ out. Will try to do next time.

2/ Yes, I did see the function connect();

3/ No, however, did not see an example of how to use the function connect() given as input a previously generated mesh (using e.g. the function CartesianGrid() ). It is likely I am overlooking something.

Thx again!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2024, 8:31pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/4 "2024-09-16T20:31:46Z")

</div>

Can you please clarify what you want to achieve? A concrete example?

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [September 16, 2024, 8:49pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/5 "2024-09-16T20:49:18Z")

</div>

Sure.

I would like to construct a face-element connectivity table. Each internal (boundary) face has two (one) adjacant elements. I thus would like to construct a tall skinny matrix that given the face-id as input, retrieves the two (or only one) id’s of the adjacent elements.

Next, I would like to discretize the integro-differential operator by a double loop. Outermost over faces. Innermost over elements. In the inner loop, I need to distinguish between elements adjacent and non-adjacent to the face.

Fine to do the above for 2D Cartesian grids for a first proof of concept.

Does this fully answer your question?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2024, 8:53pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/6 "2024-09-16T20:53:25Z")

</div>

In that doc page I shared you can find the example with the `adjacencymatrix` of a mesh:

```julia
grid = CartesianGrid(10, 10)

adjacencymatrix(grid)

```

```julia
100×100 SparseArrays.SparseMatrixCSC{Int64, Int64} with 360 stored entries:
⎡⠪⡦⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠈⠪⡦⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠑⢄⠀⠀⠪⡦⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠑⢄⠀⠈⠪⡦⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠑⢄⠀⠀⠪⡦⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠪⡦⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠪⡦⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠪⡦⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠪⡦⡀⠀⠱⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠪⡦⠀⠀⠱⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢆⠀⠀⠺⡢⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢆⠀⠈⠺⡢⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠺⡢⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠺⡢⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠺⡢⡀⠀⠑⢄⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠺⡢⠀⠀⠑⢄⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠺⡢⡀⠀⠑⢄⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠺⡢⠀⠀⠑⢄⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠺⡢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠈⠺⡢⎦

```

Isn’t that what you need? There are other matrices (e.g., `laplacematrix`, `measurematrix`) and they have options in their docstrings that you can read.

These matrices are constructed from topological relations. The `adjacencymatrix` is constructred from the `Adjacency` relation, also explained in the docs. The relation takes an id as input and returns the ids of the adjacent elements, vertices, etc.

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [September 16, 2024, 9:03pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/7 "2024-09-16T21:03:58Z")

</div>

This (as far as I currently understand) is node(or point)-element(or quadrilateral) adjacency, either with or without boundary (rank) of the domain. Correct?

Does similar exist for face(or edge) -element(or quadrilateral) adjacency?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 16, 2024, 9:08pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/8 "2024-09-16T21:08:05Z")

</div>

I will copy/paste some examples from the docs here:

```julia
topo = topology(grid)

# create boundary relation mapping
# 2-faces to 0-faces (i.e. vertices)
∂ = Boundary{2,0}(topo)

# list of vertices for first face
∂(1)

# boundary relation from faces (dim=2) to edges (dim=1)
∂ = Boundary{2,1}(topo)

# show boundary of first n-gon
∂(1)

```

Please check the docstrings of `Adjacency`, `Boundary` and `Coboundary`.

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [September 16, 2024, 9:14pm UTC](https://discourse.julialang.org/t/meshes-jl-cartesiangrid-faceelement-connectivity/119473/9 "2024-09-16T21:14:06Z")

</div>

Many thx!

Late here in Europe. More soon.
