# Current Extraction for each node over time steps

**URL:** <https://community.freefem.org/t/current-extraction-for-each-node-over-time-steps/2963>\
**Category:** General Discussion\
**Created:** [February 14, 2024, 11:31am UTC](https://community.freefem.org/t/current-extraction-for-each-node-over-time-steps/2963 "2024-02-14T11:31:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MehranK1](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MehranK1](https://community.freefem.org/u/MehranK1)\
**Post date:** [February 14, 2024, 11:31am UTC](https://community.freefem.org/t/current-extraction-for-each-node-over-time-steps/2963/1 "2024-02-14T11:31:35Z")

</div>

Hello,

I have a code for electromagnetics simulation and analysis in FreeFem over a time period. I need to extract three different files. One is a file that contains all the coordinates, the second one is the indices of the nodes that are creating each element in mesh that corresponds to the previous file, and the last one is the current density based on the defined formula. Here is the important part of the code:

// problem  
problem eddyCurrent(Az, v) = int2d(Th)(nu0 \* Grad(Az)’ \* Grad(v)) + int2d(Th)(alpha \* Az \* v / dt) - int2d(Th)(alpha \* Azold \* v / dt) - int2d(Th)(J \* v) + on(C2, Az = 0);

ofstream ffJz(“Jz\_AllTimesteps.txt”);

// time iteration  
for(real t = 0; t \< T; t += dt)  
{  
Azold = Az;

```
// update total current from the power supply
J = J0 * Ipk * sin(2.0*pi*f*t);

// solve
eddyCurrent;

Ph Jz = -J + alpha * (Az - Azold) / dt;

 // This part is not working.
//for (int i = 0; i < Th.nt; i++) {
// for (int j = 0; j < 3; ++j) {
// ffJz << Jz[][Vh(i, j)] << " ";
// }
//}

cout << "current time = " << t << " sec" << endl;
cout << "total current (by integration) = " << int1d(Th, C1)(nu0 * (- dy(Az) * N.y - dx(Az) * N.x)) << " Amp" << endl;
cout << "total current (by source) = " << Ipk * sin(2 * pi * f * t) << " Amp" << endl;

plot(Az, wait = true, fill = true, value = true);

```

}

I am new to FreeFem, so I appreciate your help.

Regards,  
Mehran

---

<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:** [February 14, 2024, 6:30pm UTC](https://community.freefem.org/t/current-extraction-for-each-node-over-time-steps/2963/2 "2024-02-14T18:30:07Z")

</div>

Generally everyone seems to suggest just picking and x and y and letting FF interpolate  
rather than caring about exactly what points are where. Interpolation occurs with  
the element using the syntax u(x,y) or you can dump vertex by vertex and first put the  
x and y locations into two arrays. In any case, you probably want “Th.nv” if you want  
to loop over verticies but you can just go right to the arrays with u.

See if this does what you want,

```auto
for(int i=0; i< Th.nv; ++i)
{
    cout << Th(i).x << " " << Th(i).y << " " << Th(i).y << " " << Th(i).label << endl;
}

```

Or you can put the x and y locations into their own arrays,

```auto

fespace Xh(Th,P1);
Xh b,c,p,q,w;
Xh a=x;
Xh ay=y;

```

and get each element with a[i]

---

<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:** [February 14, 2024, 8:49pm UTC](https://community.freefem.org/t/current-extraction-for-each-node-over-time-steps/2963/4 "2024-02-14T20:49:44Z")

</div>

Did you look at the code I posted? Th.nt is the number of triangles  
as you apparently know by then trying to loop over 3. If you  
don’t care about elements, look at the code i sent to iterate  
over nodes and get the xy values. Then just do it as each time step.  
You can also save the mesh which gives you all that if you want to sort  
through it.
