Field from Magnetization (3D): computefield

Inspired by the 2D-solver based mag2hfield, the computefield application uses the 3D Oxs solver engine to compute demagnetization and other fields from a magnetization snapshot. Various options allow fields to be computed outside the original simulation volume (say the stray field above a thin film sample) or to isolate the field arising from one portion of the sample (for example from one layer in a multilayer structure).

Launching
The computefield launch command is:

tclsh oommf.tcl computefield [standard options] \
   [-cwd directory] [-meshOvf meshovffile] [-Msfile Msinputfile] \
   [-Msmask maskexpr] [-Msspec spec] [-outdemagenergy demagenergyfile] \
   [-outM magfile] [-outmif miffile] [-pbc axes] [-runboxsi <0|1>] \
   [-runopts boxsiopts] [-simulationbox xmin ymin zmin xmax ymax zmax] \
   [-useroutputs "name1 file1 ..."] \
   [-userscriptfile energyscriptfile] <m0_infile> [outdemagfile]
where
-cwd directory
Make directory the active working directory.

-meshOvf meshovffile
Normally the mesh cell sizes and simulation dimensions are inferred from the m0_infile, but the -meshOvf option overrides the default with values from meshovffile. This is useful primarily in settings where the initial magnetization is prescribed generically using a coarser mesh than the one intended for the simulation—for example, the left half of the simulation is to have magnetization pointing up, the right half pointing down, defined via a mesh with only two (large) cells. In this case a separate OVF file may be used as an argument to both -Msfile and -meshOvf to define the part geometry and meshing.

-Msfile Msinputfile
Set pointwise saturation magnetization values from Msinputfile, overriding $M_s$ values from m0_infile. Any points outside the span of Msinputfile have $M_s$ set to 0.

-Msmask maskexpr
At each point in the simulation volume, the Tcl expr-expression maskexpr is evaluated to rescale (multiply) the otherwise set saturation magnetization $M_s$. The expr-expression may include the special variables $x, $y, $z, $rx, $ry, $rz, $Ms, $mx, $my, and $mz. The first three are the raw pointwise location in meters, the second three are the relative location (each in the range [0,1]), $Ms is the saturation magnetization at the point, and ($mx,$my,$mz) is the reduced (unit normalized) magnetization. Analogous to the -wgtfunc option of avf2odt, maskexpr is typically a 0/1 valued function used to mask off a portion of the simulation part. See the first example below.

-Msspec spec
Override the $M_s$ values from m0_infile with the (quoted) spec string in the form of an inline Specify block. Note: If spec is a single numeric value representing a uniform saturation magnetization (in A/m), then that value is applied but restricted to the simulation volume described by m0_infile or meshovffile, with $M_s$ set to 0 A/m in any extended volume requested by the -simulationbox option.

At most one of -Msfile and -Msspec may be used.

-outdemagenergy demagenergyfile
Write the demagnetization energy density scalar field (.oef) to demagenergyfile.

-outM magfile
Saves a copy of the magnetization as used in the computation, incorporating m0_infile, meshovffile, and Ms/file/spec/mask options. This can be helpful for checking that input parameters, in particular -Msmask, are behaving as expected.

-outmif miffile
The computefield application creates a temporary MIF used as input for running boxsi. This MIF file is deleted after boxsi exits, but the -outmif option will save a copy in miffile.

-pbc axes
Creates a periodic mesh for the simulation. The axes should be a string of one or more of the letters `x', `y', and `z', denoting the periodic direction(s), as used by the periodic option to the Oxs_PeriodicRectangularMesh Specify block.

-runboxsi <0|1>
By default, computefield runs boxsi on its constructed MIF file to compute the requested output fields. This behavior is short circuited with -runboxsi 0, which can be used in conjunction with -outmif to allow additional user edits to the MIF file preceding a manual boxsi run.

-runopts boxsiopts
Command line options passed to the automatic boxsi run. The boxsiopts string must be quoted as a single argument to computefield.

-simulationbox xmin ymin zmin xmax ymax zmax
Use the specified values for the simulation volume, overriding the extents in the input m0_infile or meshovffile files. The x/y/z/min/max values can be listed as either six individual values or quoted as a single element to computefield. Any entry specified as a single hyphen (`-') will inherit the corresponding value from m0_infile/meshovffile. (The -info option to the command line utility avf2ovf can be used to view OVF file extents.)

The simulationbox option is typically used to compute stray fields outside the original simulation volume. If the original volume extends outside the requested volume, then magnetization outside the requested volume is ignored and a warning is printed.

-useroutputs "name1 file1 ..."
A list, quoted as a single element on the command line, of alternating outputs and filenames, referring to Oxs_Energy objects specified in the separate -userscriptfile. This command line option augments and amends any user_outputs setting in the script file.

-userscriptfile energyscriptfile
The only outputs computefield directly supports on the command line are demagnetization field, demagnetization energy density, and magnetization. However, the user can create an energyscriptfile, which is a separate Tcl script with additional Oxs_Energy objects to be included in the run. (See second example below.) The name of each desired output and the associated filename should be appended to the “user_outputs” Tcl list, either directly inside the script file, or via the -useroutputs command line option.

m0infile
Input magnetization (.omf) file. Required. This file sets the magnetization direction at each point, i.e., the MIF m0 value in the Oxs_TimeDriver and Oxs_MinDriver Specify blocks. The pointwise saturation magnetization (MIF Ms option) and simulation volume extents (MIF atlas object) are also derived from this file unless overridden by other options.

outdemagfile
Demagnetization output file name. Optional. If not specified then the demagnetization field is not output.

Examples
Consider a multilayer thin film having total thickness 30 nm, with the top layer 10 nm thick. A simulation is run and the magnetization at some interesting point is saved to the file foo.omf. For efficiency, the simulation volume was set to contain only the film itself, but for analysis we want to know the stray field out to 150 nm above the top of the film. Moreover, we would like to know the portion of the stray field coming from just the top 10 nm layer. The command

tclsh oommf.tcl computefield -simulationbox - - - - - 180e-9 \
  -Msmask '20e-9<$z && $z<30e-9 ? 1 : 0' foo.omf foo-toplayer.ohf
will compute this and save the results in foo-toplayer.ohf. (On the Windows command line, remove or replace the backslash line continuation character with a caret, ^, and replace the single quotes with double quotes.)

As another example, suppose bar.omf holds Oxs_MinDriver::Spin normalized magnetization output for a sample with uniform saturation magnetization of 1400 kA/m. If we want to know the magnetocrystalline anisotropy field at that magnetization state, we can construct a separate file, say barK.tcl, that contains the anisotropy block from the original simulation:

Specify Oxs_UniaxialAnisotropy:K {
   K1 520e3
   axis {0 0 1}
}
lappend user_outputs Oxs_UniaxialAnisotropy:K:Field barK.ohf
The last line requests the field output be written to the file barK.ohf. We will feed this file to computefield using the -userscriptfile option. After closing barK.tcl we decide we would also like to have the anisotropy energy density, so we'll use the -useroutput option to request that, and for good measure request the demagnetization energy density with -outdemagenergy as well. The accompanying computefield command is
tclsh oommf.tcl computefield -Msspec 1.4e6 -userscriptfile barK.tcl \
   -useroutputs "Oxs_UniaxialAnisotropy:K:Energy\ density barK.oef" \
   -outdemagenergy bar-demag.oef bar.omf
Note that the demagnetization field is not requested and so won't be saved. (If that field is wanted, just add the filename after bar.omf.)


OOMMF Documentation Team
September 27, 2024