Magnetic field#

formula.field module#

Cacluations related to the magnetic field.

mrfmsim.formula.field.B_offset(B_tot, f_rf, Gamma)[source]#

Calculate the resonance offset.

mrfmsim.formula.field.field_func(method, grid_array, h)[source]#

Calculate the field value at the given height and grid points.

mrfmsim.formula.field.min_abs_offset(ext_B_offset, ext_pts)[source]#

Minimum absolute value of a matrix in x direction based on the window.

The function is used to calculate the minimum B_offset during a saturation experiment. For each x-data point in the sample, calculate the resonance offset over the expanded grid. The points to the left and right of each grid point give the resonance offset as the cantilever moves. The algorithm finds the minimum resonance offset over the range of array values corresponding to the cantilever motion and computes the saturation polarization using that minimum offset and the given \(B_1\) value.

To calculate the spin polarization profile resulting from the cantilever moving while spin-saturating irradiation is applied, we use the following algorithm:

If the resonance offset changed sign during the sweep, then the spin must have experienced a zero resonance offset during the sweep, so set the resonance offset to zero manually.

This procedure mitigates the problem of previous algorithms not finding the true minimum resonance offset (and polarization) due to the finite grid size. While this new procedure will still not capture the shape of the polarization at the edge of the sensitive slice, it should produce a polarization that is properly saturated inside the sensitive slice.

This is used for calculating \(\delta F\) of the experiment calculate the corresponding gradient based on the grid array points and tip-sample separation (equation 3 in “Overview”). The integral is approximated with Trapezoid summation over \(2 \pi\) with n points. The summation is over pi to increase the performance since it is symmetric in \([-\pi, 0]\) to \([0, \pi]\) for the summation.

\[\Delta f = \frac{\sum_j \int_{-\pi}^{\pi} \mu_z(\vec{r}_j,\theta) \frac{\partial B_z^\mathrm{tip}(x - x_\mathrm{pk} \cos{\theta},y,z)}{\partial x} x_\mathrm{pk} \cos{\theta} d\theta}{\pi x_\mathrm{pk}^2}\]
Parameters:
  • ext_B_offset (float) – resonance offset of extended grid [mT]

  • ext_pts (int) – number of grid points used to determine the minimum offset

mrfmsim.formula.field.xtrapz_field_gradient(Bzx_method, grid_array, h, trapz_pts, x_0p)[source]#

Calculate CERMIT integral using Trapezoidal summation.

The integrand is an odd function. Therefore, we can approximate the integral from \(-\pi\) to \(\pi\) and \(-\pi\) to 0. Here, we make an important assumption that the magnet is symmetric in the x direction. Therefore, we approximate the integral from \(-\pi/2\) to 0 and time the final result by 2. The result has the unit of mT/nm^2.

Parameters:
  • grid_array (list) – ogrid generated by a numpy ogrid For a one-dimensional grid, the ogrid should be encapsulated in a list

  • h (list) – tip-sample separation

  • trapz_pts (int) – points to integrate across :math: pi. In this particular implementation, the number is divided by 2 for [\(-\pi/2\), 0 ] integration.

mrfmsim.formula.field.xtrapz_fxdtheta(method, ogrid, n_pts, xrange, x_0p)[source]#

Calculate the integral of a function over a range of theta.

The calculation is done by extend the original ogrid to a new grid by extend the number of points in the x direction.

\[\int_{x_\mathrm{min}}^{x_\mathrm{max}} f(x - x_0\cos\theta)x_0\cos\theta d\theta\]