How to check the convergence of the simulation

How long it takes to run a simulation? This depends very much on what you are simulating and under what conditions (applied field, current, etc). Sometimes, however, your simulation may not be ending quickly as you expected and you may want to check what is happening. It may be, indeed, that the simulation is not converging, which means that it may actually never end. One thing you can do in such a case is to take a look at the file *_progress.txt, where * stands for the simulation name (given to the Simulation class when creating the simulation oject). For example, if you created your simulation object with a line such as

s = nmag.Simulation('one')

Then you may be looking for a file with name one_progress.txt. If you used simply s = nmag.Simulation() and your file is named then you should look for a file with name two_progress.txt. This file contains statistics about the time integrator. You'll first get the current time, step number, etc. Then you'll get a list of rows each containing four columns, such as

123 0.456 0.123 None

Column 1 is the step reached, an integer number which always increases. The file shows convergence statistics for the last few steps (it doesn't contain statistics for all the steps, since this would make it quickly very big). Column 2 contains the current value of max || dM/dt ||. Column 3 contains the stopping value of dM/dt. Convergence is reached when column 2 < column 3 for at least two times. If the simulations is going well, then you should see that column 2 contains numbers which are not oscillating rapidly and are rather decreasing or increasing "smoothly". This is what typically should happen, even if it can be that your simulation has really a bizarre dynamics which really oscillates in a frenetic way, so one should be careful when analysing the data. The fourth column contains an evaluation of the quality of the convergence according to what we just said. This number should be close to one when the convergence is smooth and close to zero when it is oscillating frenetically.

What to do in case of convergence problems

If your simulation has really a convergence problem, you can do two things:
  1. improve the tolerances ts_abs_err and ts_rel_err (decrease these numbers) by using the method set_params of the Simulation object;
  2. use a do=[('next_stage', at('stage_time', SI(x, 's')))] as an argument to the hysteresis method. This way you impose a maximum time x to spend in the computation of a stage (you should make sure this makes sense in your case).

Also available in: HTML TXT