# Current Extraction for each node over time steps

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

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,

``````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,

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

``````

and get each element with a[i]

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.