Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define a system with particular spin postions to be read via file #210

Open
Shobhn opened this issue Jun 28, 2022 · 7 comments
Open

Comments

@Shobhn
Copy link

Shobhn commented Jun 28, 2022

Hi,

So I have 6 column data file in format of (x,y,z,Sx,Sy,Sz) representing each spin positions and directions in a lattice. I want to create a MFM image simulation for this artificial spin ice lattice. Could anybody please explain me how to read these positions and spin directions to define a system in Ubermag. I am confused about how to put spins in these specific positions after defining the region.

Any Help is really appreciated. Thanks

@Shobhn
Copy link
Author

Shobhn commented Jun 29, 2022

Hi ,

I am sorry for the urgency, but please could anyone help me through above issue . Thanks

@marijanbeg
Copy link
Member

Hi @Shobhn, thank you for your message and apologies for the wait. The majority of the team is at the conference.

Could you please send us the file?

@Shobhn
Copy link
Author

Shobhn commented Jun 29, 2022

yes sure! And thank you very much for the urgent reply :)
Large_area_00000_arrows.txt

@samjrholt
Copy link
Member

Hi @Shobhn, as you do not have magnetisation values for every single point in the region I have written a short example about how you might convert this to a Field object.

import numpy as np
import discretisedfield as df

txt_file = np.loadtxt('Large_area_00000_arrows.txt', skiprows=2)
coords = txt_file[:, :3]
mag = txt_file[:, 3:]

cell = (1, 1, 1)
p1 = np.min(coords, axis=0) - np.divide(cell, 2)
p2 = np.max(coords, axis=0) + np.divide(cell, 2)
mesh = df.Mesh(p1=p1, p2=p2, cell=cell)

def val_fun(pos):
    arr = np.all(np.isclose(coords, pos), axis=1)
    if np.any(arr):
        return mag[arr].squeeze()
    else:
        return (0, 0, 0)
    
m_field = df.Field(mesh=mesh, dim=3, value=val_fun)

Please remember that the mfm function expects SI units for the mesh and the magnetisation values.

@Shobhn
Copy link
Author

Shobhn commented Jul 2, 2022

Hi @samjrholt ,

Thank you, and the team, very much for the quick response and for this answer, I really appreciate your help.

The code above helped me lot. Thanks again! :)

@lang-m lang-m reopened this Jul 4, 2022
@Shobhn
Copy link
Author

Shobhn commented Jul 4, 2022

Hi team,

Thanks again for your help earlier ! :)

I have one more query regarding this issue, so I have more data files with different positions and spins, I wanted to ask that what should be the approach while defining the cell and the mesh so that the region can be discretised correctly with all spins at the centre of each cell.
I want to learn how should we go about thinking while defining the cell for particular sets of positions. Since I tried various cell dimension for my other files but I was not able to discretised the region correctly.

I have attached a file here for example : [DL_sat_0.txt](url)

It would be great if some one can help me through this.

Thanks Again!
Best.

@DebanjanPolley
Copy link

Hello,
I have encountered a similar problem. I have attached an image and the corresponding data file (including the position and magnetization vector ). However, I fail to achieve the required spin configuration using a similar code. The idea is that the white portion of the image should have a large magnetization, and the black portion should have zero magnetization.

Screenshot 1

example.txt

import numpy as np
import discretisedfield as df
import micromagneticmodel as mm
import oommfc as oc
import matplotlib.pyplot as plt
from PIL import Image

system = mm.System(name='testpos1')

Data   = np.genfromtxt("example.txt", delimiter='\t', skip_header = 2, skip_footer=1) 

coords = Data[:, :3]
mag    = Data[:, 3:]

cell   = (5, 5, 1)
p1     = (0,0,0)                     # np.min(coords, axis=0) - np.divide(cell, 2)
p2     = (300, 270, 1)               # np.max(coords, axis=0) + np.divide(cell, 2)

mesh   = df.Mesh(p1=p1, p2=p2, cell=cell)

def val_fun(pos):
    arr = np.all(np.isclose(coords, pos), axis=1)
    if np.any(arr):
        return mag[arr].squeeze()
    else:
        return (0, 0, 0)
    
system.m = df.Field(mesh=mesh, nvdim=3, value=val_fun)
mesh.mpl()
system.m.sel('z').mpl()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants