# Edge orientation

**URL:** <https://community.freefem.org/t/edge-orientation/1486>\
**Category:** General Discussion\
**Created:** [February 10, 2022, 9:46pm UTC](https://community.freefem.org/t/edge-orientation/1486 "2022-02-10T21:46:07Z")\
**Posts on this page:** 9\
**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:** [February 10, 2022, 9:46pm UTC](https://community.freefem.org/t/edge-orientation/1486/1 "2022-02-10T21:46:07Z")

</div>

Is it possible to find the edge orientation on a mesh?

```auto
mesh P = square(2,2);
int NbTriangles = P.nt; //number of triangles
plot(P, wait=1);

fespace LambdaH(P, P0edge);
fespace V0(P,P0);

V0 u0;
LambdaH l0;

int nDoFu0 = V0.ndof;
int nDoFl0 = LambdaH.ndof;

int nDoFu0K = V0.ndofK;
int nDoFl0K = LambdaH.ndofK;

V0 uX = x, uY = y;
LambdaH lX = x, lY = y;

real[int,int] CoordDoFl0(nDoFl0,2);

for(int i= 0; i< nDoFu0; i++)
 cout << uX[][i] << " " << uY[][i] << "\n";

for(int i= 0; i <nDoFl0; i++){
 CoordDoFl0(i,0) = lX[][i];
 CoordDoFl0(i,1) = lY[][i];
 cout << CoordDoFl0 << "\n";
 //cout << lX[][i] << " " << lY[][i] << "\n";
}

```

I’ve built a matrix with the coordinates of each DoF, now I would like to know the edge orientation.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 12, 2022, 1:34pm UTC](https://community.freefem.org/t/edge-orientation/1486/2 "2022-02-12T13:34:15Z")

</div>

Yes the edge orientation is given by the vertex number go form the lowest vertex number to the biggest vertex number.

Otherwise in intalledge integral the function edgeOrientation get +1 or -1 depending of the orientation.

---

<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:** [February 14, 2022, 1:54pm UTC](https://community.freefem.org/t/edge-orientation/1486/3 "2022-02-14T13:54:17Z")

</div>

One more question, for example, I defined the following space:

```auto
fespace LambdaH(P, P0edge);

```

and I have the DoF for each element

```auto
8 3	
	   6 9 5
	  12 10 9
	   0 2 1
	   4 6 2
	  11 13 12
	  14 15 13
	   3 7 4
	   8 11 7

```

I want to build a matrix with the edge orientation, something like:  
for element 1: 1 1 -1

Is it possible?

---

<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:** [February 14, 2022, 3:02pm UTC](https://community.freefem.org/t/edge-orientation/1486/4 "2022-02-14T15:02:07Z")

</div>

I tried to use the function edgeOriention as shown in the manual, but it is not working. I know the nodes of each element, so for example:

element 1: nodes 0 1 4  
the sign of edge from 0 to 1: +1  
the sign of edge from 1 to 4: +1  
the sign of edge from 4 to 1: -1

those are the values that I want to store in a vector (or matrix)

## edgeOrientation

Sign of i−j if the current edge is [qi,qj].

real S = int1d(Th, 1)(edgeOrientation);

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 17, 2022, 1:35pm UTC](https://community.freefem.org/t/edge-orientation/1486/5 "2022-02-17T13:35:22Z")

</div>

Yes the code :

```auto
mesh Th=square(4,4);
fespace LambdaH(Th, P0edge);
matrix orient(Th.nt,LambdaH.ndof);
for(int k=0; k<Th.nt;++k)
  for( int i=0; i<3;++i)
   {
      int j = LambdaH(k,i); 
      int i1 = Th[k][(i+1)%3]; 
      int i2 = Th[k][(i+2)%3]; 
      orient(k,j) = i1 < i2 ? 1 : -1; 
     
}
cout << orient << endl;

```

---

<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:** [February 19, 2022, 5:00pm UTC](https://community.freefem.org/t/edge-orientation/1486/6 "2022-02-19T17:00:55Z")

</div>

I’m getting th following error

```auto
Error line number 3, in file C:\Users\LARISS~1\AppData\Local\Temp\.ffcs21024.edp, before token )

  current line = 3
Compile error : 
	line number :3, )
error Compile error : 
	line number :3, )
 code = 1 mpirank: 0
FreeFem++ returned error 1

```

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 19, 2022, 5:05pm UTC](https://community.freefem.org/t/edge-orientation/1486/7 "2022-02-19T17:05:54Z")

</div>

You FreeFem version is too old , cf:

tions/FreeFem++.app/Contents/ff-4.10/bin/ffglut’ ;exit;  
– FreeFem++ v4.10 (Lun 14 fév 2022 22:27:04 CET - git v4.10-60-g89b58302)  
file : bbbbb.edp  
Load: lg\_fem lg\_mesh lg\_mesh3 eigenvalue  
1 : mesh Th=square(4,4);  
2 : fespace LambdaH(Th, P0edge);  
3 : matrix orient(Th.nt,LambdaH.ndof);  
4 : for(int k=0; k\<Th.nt;++k)  
5 : for( int i=0; i\<3;++i)  
6 : {  
7 : int j = LambdaH(k,i);  
8 : int i1 = Th[k][(i+1)%3];  
9 : int i2 = Th[k][(i+2)%3];  
10 : orient(k,j) = i1 \< i2 ? 1 : -1;  
11 :  
12 : }  
13 : cout \<\< orient \<\< endl; sizestack + 1024 =1384 ( 360 )

– Square mesh : nb vertices =25 , nb triangles = 32 , nb boundary edges 16

# HashMatrix Matrix (COO) 0x600000f74000

# n m nnz half fortran state

32 56 96 0 0 0 0  
0 36 1  
0 30 -1  
0 29 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:** [February 19, 2022, 5:09pm UTC](https://community.freefem.org/t/edge-orientation/1486/8 "2022-02-19T17:09:24Z")

</div>

I’m using FreeFem++ -cs 14.3

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 19, 2022, 5:38pm UTC](https://community.freefem.org/t/edge-orientation/1486/9 "2022-02-19T17:38:33Z")

</div>

I need the FreeFeM++ version not the version of FreeFem+±cs.

Sorry I think the version is 3.xx for me (too old) except is Antoine do a new version

In the FAQ it say :

Yes, starting from [FreeFEM-cs](http://www.ljll.math.upmc.fr/lehyaric/ffcs/index.htm) version 15, [FreeFEM-cs](http://www.ljll.math.upmc.fr/lehyaric/ffcs/index.htm) and [FreeFEM](http://www.freefem.org/ff++) are kept in separate packages to allow everyone to pick the versions that they need.

so please use the version 4.10 !!!
