Pavel Panchekha

By Pavel Panchekha, Jeffrey Prouty

Share under CC-BY-SA.

Faraday's Law Simulation

Background

Faraday's law states that a changing magnetic field induces a current; in particular, it says that the rate of change of magnetic flux is equal to an induced voltage in a circuit. Mathematically, this is \[\oint_{\partial S} E \cdot d l = - \frac{d}{d t} \iint_S B \cdot d A\] though often the more succinct form \(V_{ind} = - \frac{d \Phi_B}{d t}\) is used.

If you place a square conduction loop near a wire, and apply a force, the force will accelerate the loop; but Faraday's law will cause a current to flow through the loop, which will experience a Lorentz force resisting its motion. Often the two effects counteract each other.

Demo

In the demo below, the force applied to the loop is proportional to the distance from your cursor to the left side of the loop. Alternatively, you may click to fix the force at its current value (and click again to return to a proportional force). The loop will display various variables like velocity and acceleration; the color of the loop represents the current power generated by Joule heating.

Try to move the loop to the right, then hard to the left – see how the loop rapidly slows down once it hits a region where the magnetic field is rapidly changing.

Another thing to think about: if the force is proportional to distance, we ought to have harmonic oscillation. Try to get the loop to oscillate about a stationary cursor. The loop seems to slow down! Why? There is no built-in friction or anything similar in the simulation.

Code Documentation

The simulation is written in Javascript, embedded above in an iframe. To see the source, you can right-click the simulation, select "View Frame" or similar, and then right-click the resulting page and select "View Source". The gist of the simulation is the step function, which looks like this:

 1: function step() {
 2:     var b1 = b_at(pos);
 3:     var b2 = b_at(pos + w);
 4: 
 5:     /* d Phi / d t: (\frac{d}{dt} \int_r^{r + w} B(x) \, d x */
 6:     i2 = l * w * vel / (pos * (pos+w)) * (mu_0 * i1) / (2 * Math.PI) / res;
 7:     var f_lrz = l * i2 * (b1 - b2), f = -f_lrz + f0;
 8: 
 9:     if (Math.abs(acc) < .06) logging = true;
10:     if (pos < 0 || pos > 1000) logging = false;
11:     if (debug && logging) console.log("v:", vel, " f1:", f_lrz, " f0:", f0);
12: 
13:     pos += vel * dt;
14:     // Numerical stability magic
15:     if (approx_same(f_lrz, f0)) {
16:         vel *= 1 - Math.abs((f_lrz - f0) / (f_lrz + f0)) * 2 * Math.Pi;
17:     } else {
18:         vel += acc * dt;
19:     }
20:     acc = f / mass;
21: }

First, we compute the field at the left (line 2) and right (line 3), using a utility function, b_at, defined as so:

function b_at(x) {
    return (mu_0 * i1) / (2 * Math.PI * x);
}

This, of course, is simply the standard definition of the magnetic field of an infinite wire.

Next, we compute the induced current (line 6). The large algebraic expression results from the calculation of \[I_2 = \frac{1}{R} \frac{d}{d t} \int_r^{r+w} B(x)\,d x;\] in the program, the result of the calculation is hard-coded for numerical accuracy.

Next we compute the Lorentz force and total force on the object in line 7. The next three lines starting at line 9 deal with printing debugging output if a debug flag is on.

Finally, we need to update the position, velocity, and acceleration of the object. We update position in 13 and acceleration in 20. However, setting the velocity has to be done more carefully. The issue, you see, is that if we just naively update velocity, like in 18, we run into issues when the Lorentz force and the applied force are nearly equal. In this case the fact that our time is discreet (we run step every 5 milliseconds) can create a fake "resonance" effect. So our loop would slow down and then suddenly start vibrating and fly off the page. Woops!

To fix this, we detect (on line 15) this effect (that is, the two forces being very similar) and instead of naively update velocity, we simply decrease it geometrically. At this point the velocity is approximately zero anyway.

For a more in-depth look at the code just open it up and look inside; it should be rather readable.