In this tutorial, reading and writing of OOMMF vector field files (omf and ohf) are demonstrated. As usual, we need to import the Field class, but this time also the read_oommf_file function.
In [1]:
    
from oommffield import Field, read_oommf_file
    
We create a three-dimansional vector field with domain that spans between:
with discretisation $d = (5 \,\text{nm}, 5 \,\text{nm}, 5 \,\text{nm})$.
In [2]:
    
cmin = (0, 0, 0)
cmax = (100e-9, 100e-9, 5e-9)
d = (5e-9, 5e-9, 5e-9)
dim = 3
    
Now, we can create a vector field object and initialise it so that:
$$f(x, y, z) = (x+1, x+y+2, z+3)$$
In [3]:
    
def m_init(pos):
    x, y, z = pos
    
    return (x+1, x+y+2, z+2)
field = Field(cmin, cmax, d, dim=dim, value=m_init)
    
Please note, that in this case we provided a field value as a field argument, which internally calls a set method explained in other tutorials.
If we plot the field, we get:
In [4]:
    
#PYTEST_VALIDATE_IGNORE_OUTPUT
%matplotlib inline
fig = field.plot_slice('z', 2.5e-9, xsize=8)
    
    
This vector field can now be saved in an OOMMF omf file, by using write_oommf_file method and providing a filename.
In [5]:
    
filename = 'vector_field.omf'
field.write_oommf_file(filename)
    
We can now see that, the OOMMF file is saved:
In [6]:
    
!ls *.omf
    
    
Now when we have the OOMMF vector field file, we can read it, which will create a different Field object.
In [7]:
    
field_read = read_oommf_file('vector_field.omf')
    
As expected, two fields must have exactly the same values at all nodes:
In [8]:
    
(field.f == field_read.f).all()
    
    Out[8]:
Finally we can delete the OOMFF file used in this tutorial.
In [9]:
    
!rm vector_field.omf