ubermag / help

Repository for raising issues and requesting help on Ubermag
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

stray field in an airbox #227

Closed a-lyrae closed 2 years ago

a-lyrae commented 2 years ago

Hello Ubermag community,

I have two magnets facing each other, and subjected to an external magnetic field. Each magnet has dimensions (l,l,l). The two magnets are contained in a airbox, of given dimensions (L,L,L) with L>>l. The system is not periodic, so I applied open boundary conditions. I'd like to compute the stray field at a certain distance above two magnets.

The problem is that the stray field seems to strongly depend on the dimension L of the airbox. Moreover, although decreasing towards the external boundary of the airbox, its norm is different from zero.

Can you please advise me on this? Which boundary conditions should I consider to get rid of the dependence on L? Is it reasonable for the norm of the stray field to be different from zero at the external boundary?

Thanks in advance!

samjrholt commented 2 years ago

Hi @a-lyrae, thank you for your message. Would it be possible for you to attach some of the code you are using so we can look into it in more detail?

The dimensions of the airbox should not make a large difference to the value of stray field determined. However, it is reasonable for the norm of the stray field to be non-zero at the edge of the external boundary. The stray field will decay as a function of distance from your magnets and will tend to a norm of zero as distance tends to infinity but was we only have a finite region which is arbitrarily picked it is reasonable for it to be non-zero.

a-lyrae commented 2 years ago

Hi @samjrholt

thank you for your reply. I'm attaching an example of the code. The dimension of the discretization cell is chosen to save compute time, the exchange coefficients are modified accordingly. The coefficient K for uniaxial anisotropy can in general be different from zero. I have different subregions to allow for different materials.

When plotting the stray field along a line above the magnets, I see quite different results. In the figure attached, the position of the two peaks move when changing the dimension of the airbox (from air-pad=2um to air-pad=4um). Further increasing the dimension of the airbox does not seem to help.

example.zip

samjrholt commented 2 years ago

Hi @a-lyrae, as it is quite a large system I haven't run your entire code, only sections. I haven't seen the same behaviour you are describing, but I maybe missing it.

To recreate your simulation I have only simulated the original region not the air box and then added the air box at the end.

p1 = (0, 0, -wg/2-lz2-lz3)
p2 = (lx, ly, wg/2+lz0+lz1)
region = df.Region(p1=p1, p2=p2)

Adding the airbox after the energy minimisation and calculating the demag

import mag2exp
field_2 = system.m.pad({'x': (40, 40), 'y': (40, 40), 'z': (40, 40)}, mode='constant')
demag_field_2 = mag2exp.util.calculate_demag_field(field_2)

field_3 = system.m.pad({'x': (80, 80), 'y': (80, 80), 'z': (80, 80)}, mode='constant')
demag_field_3 = mag2exp.util.calculate_demag_field(field_3)

The mag2exp.util.calculate_demag_field is just a utility function to calculate the demag from the magnetisation field object.

p1=(0, -0.01e-6, 0)
p2=(lx, -0.01e-6, 0)
(demag_field_2.z.line(p1, p2, n=100).data['v'] - demag_field_3.z.line(p1, p2, n=100).data['v']).plot(y='v')

gives things on the scale of 1e-11.

Take a look at this slight modification to the method and let me know any updates or if you get the same issue.