# How to implement the function like the "adj" function or how to find its source code

**URL:** https://community.freefem.org/t/how-to-implement-the-function-like-the-adj-function-or-how-to-find-its-source-code/4187
**Category:** General Discussion
**Created:** [January 13, 2026, 1:38am UTC](https://community.freefem.org/t/how-to-implement-the-function-like-the-adj-function-or-how-to-find-its-source-code/4187 "2026-01-13T01:38:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MatrixVector](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@MatrixVector](https://community.freefem.org/u/MatrixVector)
#### Post date: [January 13, 2026, 1:38am UTC](https://community.freefem.org/t/how-to-implement-the-function-like-the-adj-function-or-how-to-find-its-source-code/4187/1 "2026-01-13T01:38:03Z")

</div>

The “adj“ function in mesh connectivity is very useful, which can find the adjacent triangle of the triangle k by edge e using only one statement “`Th[k].adj(e)`”.

I’m doing a FEM analysis work using Python rather than FreeFem++, and I wonder how to implement the “adj“ function when the mesh information is known, i.e., the mapping between mesh k and the corresponding vertex id is known?

Or is it possible to find the source code which implementing the “adj” function

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [January 13, 2026, 3:30pm UTC](https://community.freefem.org/t/how-to-implement-the-function-like-the-adj-function-or-how-to-find-its-source-code/4187/2 "2026-01-13T15:30:37Z")

</div>

I think you can do as  
– First build for each vertex the list of triangles around it, by making a loop on triangles and attributing the triangle index to each of its 3 vertices.  
– Then you make a loop on triangles (index k) and a subloop on its edges (index e), giving two vertices as ends, and for each of these two vertices you look in the list of their neighbouring triangles (built in the first step) to find if there is a common triangle in these two lists (additionally to the current triangle). Then you can register this triangle as the adjacent of (k,e).

---

<div class="post-metadata">

### Author: ![MatrixVector](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@MatrixVector](https://community.freefem.org/u/MatrixVector)
#### Post date: [January 14, 2026, 3:25am UTC](https://community.freefem.org/t/how-to-implement-the-function-like-the-adj-function-or-how-to-find-its-source-code/4187/3 "2026-01-14T03:25:38Z")

</div>

Thanks for your reply, and this method is theoretically feasible.
