# Edge mesh on FreeFem++

**URL:** <https://community.freefem.org/t/edge-mesh-on-freefem/2687>\
**Category:** General Discussion\
**Created:** [September 6, 2023, 1:38pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687 "2023-09-06T13:38:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 6, 2023, 1:38pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/1 "2023-09-06T13:38:52Z")

</div>

Hi guys, is it possible to build a edge mesh on FreeFem++?

For example, given a triangle, I wish to partition each edge in 2 and build a FEM space on each piece.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 6, 2023, 3:05pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/2 "2023-09-06T15:05:30Z")

</div>

buildmeshL and then use periodic boundary conditions ?

[https://doc.freefem.org/documentation/mesh-generation.html](https://doc.freefem.org/documentation/mesh-generation.html)

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 6, 2023, 6:56pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/3 "2023-09-06T18:56:11Z")

</div>

I’ve tried like this:

```auto
load "msh3"

mesh Th = square(3,3);

meshL ThEdge = extract(Th);

```

but I can’t quite figure it out how to split ThEdge.

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 6, 2023, 7:03pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/4 "2023-09-06T19:03:46Z")

</div>

The extract function doesn’t extract the internal edges, is that right?

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 6, 2023, 7:44pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/5 "2023-09-06T19:44:52Z")

</div>

This came up with 12 dofs although I’m not sure if there is just someway to  
save a meshL. Curious though if you wanted an actual closed rung.  
That is, what would eigenvalues look like for some problem? Derivatives  
zero at ends or merely solution same at both ends?

[lari.edp](https://community.freefem.org/uploads/short-url/dWMcAUsTeWiscVSgzWpdZBc02NZ.edp) (215 Bytes)

```auto

-- FreeFem++ v4.12 (Sat 20 May 2023 07:29:03 PM EDT - git no git)
   file : lari.edp
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue 
    1 : load "msh3"
    2 : mesh Th = square(3,3);
    3 : meshL ThEdge = extract(Th);
    4 : fespace Vh(ThEdge,P1);
    5 : Vh vx=x;
    6 : Vh vy=y;
    7 : Vh vz=z;
    8 : for(int i=0; i<vx[].n; ++i)
    9 : {
   10 : cout<<i<<" "<<vx[][i]<<" "<<vy[][i]<<" "<<vz[][i]<<endl;
   11 : 
   12 : }
   13 : cout.flush;
   14 : sizestack + 1024 =1816 ( 792 )

  -- Square mesh : nb vertices =16 , nb triangles = 18 , nb boundary edges 12
 empty list label, extract all boundaries
  -- FESpace: Nb of Nodes 12 Nb of DoF 12
0 0 0 0
1 0.333333 0 0
2 0.666667 0 0
3 1 0 0
4 1 0.333333 0
5 1 0.666667 0
6 1 1 0
7 0 1 0
8 0.333333 1 0
9 0.666667 1 0
10 0 0.333333 0
11 0 0.666667 0
times: compile 0.003532s, execution 0.000165s, mpirank:0
 CodeAlloc : nb ptr 3839, size :513424 mpirank: 0
Ok: Normal End

```

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 6, 2023, 7:48pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/6 "2023-09-06T19:48:26Z")

</div>

But when it creates the mshL, it just extracts the square and not the inner boundary.  
Is there some way to get all of then?

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 6, 2023, 7:49pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/7 "2023-09-06T19:49:51Z")

</div>

![Screenshot from 2023-09-06 20-49-29](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/0c805419e1898a1aa2ec7ee3e166b9297d69ec16.png)

for example, I need a mesh with all five edges

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 6, 2023, 11:59pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/8 "2023-09-06T23:59:15Z")

</div>

Probably mesh Th=square(1,1) would work.

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 7, 2023, 9:43am UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/9 "2023-09-07T09:43:33Z")

</div>

I’ve tried with square(1,1) but no luck. I can only get external boundaries

```auto
load "msh3"

mesh Th = square(1,1);

meshL ThEdge = extract(Th);
ThEdge = trunc(ThEdge, 1, split=1);

plot(ThEdge, wait=1);

fespace Eh(ThEdge, P0);
Eh xx = x, yy=y;

int nDoFl0 = Eh.ndof;
int nDoFl0K = Eh.ndofK;

cout << nDoFl0 << "\n";

```

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 7, 2023, 11:55am UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/10 "2023-09-07T11:55:07Z")

</div>

What problem are you trying to solve? I guess you could start with something  
close and modify the matrix by hand.

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 7, 2023, 12:27pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/11 "2023-09-07T12:27:11Z")

</div>

I’m trying to implement a method to solve the Darcy equation  
I’m gonna solve the Darcy equation on each element of the mesh and then assemble to the global mesh, but I need to build the location Matrix  
For that, I need the global DoF numbers, so I can find the right places to assemble the values

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 7, 2023, 12:55pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/12 "2023-09-07T12:55:34Z")

</div>

The example you posted earlier gets the dof coords and for boundaries  
in the 2d case you just used int1d over the labelled boundary. There  
are a lot of examples for that.

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [September 7, 2023, 1:46pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/13 "2023-09-07T13:46:18Z")

</div>

Yes, but in thar example I can only get 4 boundaries, the ones that form the square  
I need all five of them, the 4 boundaries from the square and the middle one

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [September 8, 2023, 3:13pm UTC](https://community.freefem.org/t/edge-mesh-on-freefem/2687/14 "2023-09-08T15:13:44Z")

</div>

I guess you could add something like this to the mesh

border ba(t=0, 1){x=t; y=t; label=1;}  
and then every element edge is a boundary.

or there is the “intAllEdge” if that helps.
