computationalmodelling / fidimag

Finite DIfference microMAGnetic code, based on Python, Cython and C
http://computationalmodelling.github.io/fidimag/
Other
60 stars 24 forks source link

FloatingPointError in atomistic llg #77

Closed davidcortesortuno closed 7 years ago

davidcortesortuno commented 8 years ago

In one of my simulations I'm getting a FloatingPointError when the llg calls the spin_length function. It seems that some spins that are zero, are represented by a very small number:

spin : [ 0.          0.70710678 -0.70710678]
step=1, time=1e-13, max_dmdt=0.215 ode_step=0
spin : [ 0.          0.70710678 -0.70710678]
step=2, time=3.53e-12, max_dmdt=0.216 ode_step=3.43e-12
spin : [ 0.          0.70710678 -0.70710678]
step=3, time=3.79e-11, max_dmdt=0.216 ode_step=3.43e-11
spin : [ 0.          0.70710678 -0.70710678]
step=4, time=3.81e-10, max_dmdt=0.216 ode_step=3.43e-10
spin : [ 0.          0.70710678 -0.70710678]
step=5, time=3.81e-09, max_dmdt=0.216 ode_step=3.43e-09
spin : [ 0.          0.70710678 -0.70710678]
step=6, time=3.81e-08, max_dmdt=0.216 ode_step=3.43e-08
spin : [ 0.          0.70710677 -0.7071068 ]
step=7, time=3.81e-07, max_dmdt=0.216 ode_step=3.43e-07
spin : [ 0.          0.70710664 -0.70710692]
step=8, time=3.81e-06, max_dmdt=0.216 ode_step=3.43e-06
spin : [ 0.          0.70710539 -0.70710817]
step=9, time=3.81e-05, max_dmdt=0.216 ode_step=3.43e-05
spin : [ 0.          0.70709973 -0.70711383]
step=10, time=0.000193, max_dmdt=0.216 ode_step=0.000155
spin : [ 0.          0.70708614 -0.70712742]
step=11, time=0.000565, max_dmdt=0.216 ode_step=0.000372
spin : [ 0.          0.70705933 -0.70715423]
step=12, time=0.0013, max_dmdt=0.216 ode_step=0.000734
spin : [ 0.          0.70700611 -0.70720743]
step=13, time=0.00276, max_dmdt=0.216 ode_step=0.00146
spin : [ 0.          0.70691448 -0.70729903]
step=14, time=0.00526, max_dmdt=0.216 ode_step=0.00251
spin : [ 0.          0.70682285 -0.7073906 ]
step=15, time=0.00777, max_dmdt=0.216 ode_step=0.00251
spin : [ 0.          0.70673121 -0.70748216]
step=16, time=0.0103, max_dmdt=0.216 ode_step=0.00251
spin : [ 0.          0.70663956 -0.70757369]
step=17, time=0.0128, max_dmdt=0.215 ode_step=0.00251
spin : [ 0.          0.70646962 -0.70774337]
step=18, time=0.0174, max_dmdt=0.215 ode_step=0.00465
spin : [ 0.          0.7063657  -0.70784709]
step=19, time=0.0203, max_dmdt=0.215 ode_step=0.00284
spin : [ 0.          0.7061864  -0.70802597]
step=20, time=0.0252, max_dmdt=0.215 ode_step=0.00491
spin : [  3.67751620e-131   7.06007079e-001  -7.08204776e-001]
step=21, time=0.0301, max_dmdt=0.214 ode_step=0.00491
spin : [ -8.84428918e-120   7.05827738e-001  -7.08383515e-001]
step=22, time=0.035, max_dmdt=0.214 ode_step=0.00491
spin : [ -2.15089946e-119   7.05648377e-001  -7.08562183e-001]
step=23, time=0.0399, max_dmdt=0.213 ode_step=0.00491
spin : [ -8.49783632e-103   7.05377407e-001  -7.08831937e-001]
step=24, time=0.0473, max_dmdt=0.213 ode_step=0.00741
spin : [ -4.56490129e-94   7.05106390e-01  -7.09101529e-01]
step=25, time=0.0547, max_dmdt=0.212 ode_step=0.00741
Traceback (most recent call last):

In the output, there is a very small number at the 20th step.

When spin_length tries to square the spin, the simulation throws a numpy underflow error. I wonder if this is also the cause of other problems in Fidimag. For now, it's difficult for me to debug, because my system doesn't have a trivial mesh geometry.

ww1g11 commented 8 years ago

Hi @davidcortesortuno, do you have a small piece of codes to repeat this?

davidcortesortuno commented 8 years ago

I'm trying to prepare one now, since the simulation that gives the error uses a custom library to generate meshes with polygonal shapes, It could be that when we have a lot of points with mu_s=0, we have the error