Load OOMMF file to Matlab array

The function imports vector file (.omf/.ovf) from micromagnetic simulation output (OOMMF, mumax3 or Boris) into Matlab arrays
54 download
Aggiornato 30 apr 2024

Visualizza la licenza

The function imports vector file archives from oommf [1], mumax3 [2], Boris [3] into Matlab arrays.
*with mumax3 was not tested, but should work with proper saving .ovf as a text. See comments about saving in OOMMF and Boris
The file is inspired by H. Corte and his function oommf2matlab.m
ChatGPT [4] was used also.
Main modification: fileToRead is processed with fileread function, not line-by-line. It works much faster for large files (100+Mb)
OOMMF vector files must be writen with the output Specifications "text %g" instead of the default "binary 4" option. And the type of grid must be rectangular. In Boris use ns.saveovf2mag('text', output_file, bufferCommand=True)
Vector files will be imported into the object "data" which will have this fields (if exist in fileToRead):
datax: component x of vector on data file
datay: component y of vector on data file
dataz: component z of vector on data file
time: total simulation time
xmin: minimum x value
xnodes: number of nodes used along x
xmax: maximum x value
ymin: minimum y value
ynodes: number of nodes used along y
ymax: maximum y value
zmin: minimum z value
znodes: number of nodes used along z
zmax: maximum z value
positionx: x positions of vectors
positiony: y positions of vectors
positionz: z positions of vectors
The number of fields could be extended easily
Basic usage:
dataOMF = oommf2matlab("your_file_name.ovf")% it loads the data to variable dataOMF
% and you can use it as next
Mx = dataOMF.datax % returns array of Mx components
% replace 'datax' with the desired vector (see above)
% be careful - it returns 1D array other the nodes.
% to plot 2D data correctly refer to next example:
Example: Plot 2D images from all files in directory:
%% read file names
dir_name = './DirName/';
file_extention = '*.ovf'; % .omf is also good
f_n = dir([dir_name file_extention]);
%% sort files by date
[~,idx] = sort([f_n.datenum]);
f_n = f_n(idx);
fileNames = {f_n.name};
mult = 1e6; % switch dimentions to microns
for ff = 1:length(fileNames)
dataOMF = omf2matlab([dir_name fileNames{ff}]);
Xvector = mult* linspace(dataOMF.xmin, dataOMF.xmax, dataOMF.xnodes);
Yvector = mult* linspace(dataOMF.ymin, dataOMF.ymax, dataOMF.ynodes);
Magn_z = dataOMF.dataz
imagesc(Xvector, Yvector, Magn_z');
drawnow;
end;
References:
[1] OOMMF: Object Oriented MicroMagnetic Framework, NIST,
[2] mumax3, a GPU-accelerated micromagnetic simulation
[3] Boris Computational Spintronics,
Multi-physics magnetisation dynamics and spin transport simulations,
This function was written by N. Khokhlov

Cita come

Nikolai Khokhlov (2024). Load OOMMF file to Matlab array (https://www.mathworks.com/matlabcentral/fileexchange/129674-load-oommf-file-to-matlab-array), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2021b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.4

Fields "x/y/zstepsize" are added

1.0.3

Description updated

1.0.2

Basic example is added;
2D animation example is fixed

1.0.1

Fixed an issue with "# Begin: Data Text" and "# Begin: data text" recognition. Now both versions are readeble

1.0.0