Tutorial: Manipulating OOMMF vector field files

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:

  • minimum coordinate $c_\text{min} = (0, 0, 0)$ and
  • maximum coordinate $c_\text{max} = (100 \,\text{nm}, 100 \,\text{nm}, 5 \,\text{nm})$,

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


vector_field.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]:
True

Finally we can delete the OOMFF file used in this tutorial.


In [9]:
!rm vector_field.omf