MagneticFriction is a many-body simulation software that calculates the magnetic friction resulting from the relative motion of two periodic magnetic layers (one with moments that can rotate around an axis perpendicular to the movement direction). It utilizes the Verlet algorithm known from Molecular dynamics simulations in combination with a Stokes law model for the single particle dissipation and integrates the rotations of the moments of the slider, which is the layer with the movable moments. MagneticFriction is a part of the supporting information of
[1] Gu, H., Lüders, A. & Bechinger, C. Non-monotonic magnetic friction from collective rotor dynamics. Nat. Mater. (2026). https://doi.org/10.1038/s41563-026-02538-1
The simulation software reproduces the qualitative and quantitative results of the experiments of [1] remarkably well. All information and methods employed by MagneticFriction are described in detail in the supporting information of [1]. While MagneticFriction can be used to repeat the corresponding simulations, we strongly encourage a full independent reproduction using the information in said supplemental information.
- Requirements
- How to use MagneticFriction
- What MagneticFriction does
- How to interpret the generated data
- Assumptions and simplifications
- Contents of the particular files
- Further information and examples
- Disclaimer
- Additional folders independent of MagneticFriction
- Cite this software
The simulation software is written as a MATLAB script, and it can be started as usual from within MATLAB. The code was tested with MatlabR2023b and MatlabR2024b, where the latter was used to generate the data given in [1]. There are no requirements for the operating system, as long as MATLAB can be installed. Since MATLAB is an interpreter language, no additional installations of MagneticFriction must be carried out (i.e., the install time is zero).
To run the software, all files must be in the same folder. The main script is MagneticArray.m, which must be started via MATLAB. The parameters for the simulation can be adjusted at the top of MagneticArray.m. The ones used to generate the data for [1] are given below as an example.
%%=======================================================================%%
% Input parameter
%========================================================================%%
% Micromagnet specific parameters ========================================%
friction_coefficient = 2.5*10^(-6); % [kg*m^2/s]
moment_of_inertia = 7.48*10^(-10); % [kg*m^2]
magnetic_moment = 4.57*10^(-2); % [A*m^2]
% Probe parameters =======================================================%
dim_x = 7; % Number of spin in x-direction
dim_y = 7; % Number of spin in y-direction
lattice_constant_x = 0.016; % [m] Distance between spins in x-direction
lattice_constant_y = 0.016; % [m] Distance between spins in y-direction
v_x = 0.008; % [m/s] Translational velocity in x-direction
v_y = 0.000; % [m/s] Translational velocity in y-direction
% Substrat parameters ====================================================%
substrat_dim_x = 4; % Size in x-direction (multiples of dim_x)
substrat_dim_y = 4; % Size in y-direction (multiples of dim_y)
angle_substrat = 0; % Orientation of micromagnets
magnetic_moment_sub = 5.03*10^(-2); % [Am^2] magnetic moment of substrat
tilt_substrat = 0.0;
% Relative parameters ====================================================%
shift_x = 0; % Shift in x_direction relative to the substrat
shift_y = 0.000; % [m] Shift in y_direction relative to the substrat
shift_z = 0.0075; % [m] Shift in z_direction relative to the substrat
tilt_angle = 0.0; % Angle between substrat and probe
% Simulation parameters ==================================================%
time_step = 0.0003; % [s] length of simulation step
max_time = 10.5; % [s] Total simulation time
start_t_time = 0.5; % [s] Time before the translation starts
. . .
scan_value = 0.0050:0.0001:0.013; % Varied paramter of the simulations
for scan=1:length(scan_value)
shift_z=scan_value(scan);
. . .
Notes: The parameters in the example are matched to the experiments of [1] (the shaft friction and the number of moments on the substrate are free parameters). Also, substrat_dim_x and substrate_dim_y set the number of substrate moments in multiples of the slider array size. In detail, they control the number of additional slider-sized layers of moments that are added to the substrate. A value of 4 means that the substrate has a width of 5 slider-sized layers of moments, where the slider is centered in the middle at the start of the simulation. Please only use even numbers for these parameters.
Using the example parameters listed above, simulations are performed for slider-substrate separations ranging from 5mm to 13mm in increments of 0.1mm (see scan_value). Consequently, the sliding process is simulated 80 times, resulting in a total simulation time of 20 hours (real time) on an AMD Ryzen 7 PRO 7730U (for which this test was conducted). For each slider-substrate separation, roughly 900 seconds are needed.
See further information for more details regarding the parameters.
Detailed information about the simulation software is given in the Methods section and the supporting information of [1]. Using the defined parameters, the script generates a rigid array of magnetic moments (i.e., the slider) that hovers over a substrate of magnetic moments. Here, the magnetic moments of the slider can rotate in the xz-plane while the moments of the substrate are fixed. The dynamics of the moments of the slider are updated using a Molecular dynamics simulation scheme (Verlet algorithm) with an additional dissipation term, which models the shaft friction.
After an equilibration time (defined by the user), the slider starts to translate over the substrate. Because of the magnetic interactions between the moments on the slider and between the moments of the slider and the substrate, magnetic torques act, and the moments start to rotate (in complex patterns) while translating. All magnetic interactions are modeled via standard point dipole interactions. During the sliding, the simulation code calculates observables, such as the total interaction force between the slider and the substrate. This total interaction force can be averaged to obtain the finite magnetic friction. The calculations are repeated for multiple different separations between the slider and the substrate.
All data are given in SI units. For each separation between the slider and the substrate, the simulation software generates a .mat file, which stores the corresponding data. Given a predefined sampling rate (Force_calc_rate in MagneticArray.m), the codes stores for each sampling frame
- the corresponding simulation time (time),
- the current orientation of the moments (array),
- the magnetic interaction force between the slider and the substrate (force - x-component, y-component, z-component),
- the particular subsrate torques acting on the different moments of the slider (torque_grid),
- all information needed to extract the sum of the torques and the torque hysteresis (hysteresis - sum of torques acting on moments of sublattice one, sum of torque acting on sublattice two, x-component average magnetic field, y-component average magnetic field, z-component average magnetic field, x-component of the magnetization of sublattice one, y-component of the magnetization of sublattice one, z-component of the magnetization of sublattice one, x-component of the magnetization of sublattice two, y-component of the magnetization of sublattice two, z-component of the magnetization of sublattice two; see [1] for information on how the slider is divided in two sublattices and the simplified model),
- and the energy terms of the system (energy - twice the internal magnetic energy, total interaction energy between the slider and the substrate).
See also further information for examples on how to analyze the output data from MagneticFriction.
Compared to the experimental setup of [1], MagneticFriction utilizes the following approximations and simplifications:
- Dipole interactions All magnetic interactions between the ring- and cylinder-shaped magnets are modeled via classical point dipole interactions, ignoring the size and the shape of the real components.
-
Stokes-like shaft friction For the dissipation term
$f$ that enters the equations of motion of the particular moments of the slider (see the main text and the Methods section of [1]), a Stokes law$f(\omega) = - \gamma \omega$ is utilized. - Angular velocity The angular velocities of the particular moments are approximated via a simple difference quotient. Note that this angular velocity enters the integration step through the Stokes friction law that models the shaft friction at each simulation step.
For a detailed description of the limitations of the simulations, see the supporting information of [1]. Note that MagneticFriction generates data with excellent qualitative and quantitative agreement with the experiments of [1].
MagneticFriction consists of multiple MATLAB functions stored in their individual files. Here, a summary of the corresponding content of the particular files is given.
- MagneticArray.m: Main file which contains the simulation loop. It calls functions stored in the other files. Here, the parameters are adjusted, and a simulation is started by running this script.
- CalcVelocity.m Approximates the angular velocities of the moments, which are later used to calculate the shaft friction.
- CalcTorque.m Calculates the total torque (shaft friction, internal magnetic interactions of the slider, and torques resulting from the substrate). These torques are used to update the angles of the moments in the integration step.
- Move.m Integration step based on the Verlet algorithm.
- Translate.m Moves the slider relative to the substrate.
- CalcForce.m Calculates twice tthe total magnetic forces acting on the slider. The average of the x-component of this force is the magnetic friction.
- CalcEnegery.m Determines the total internal interaction energy of the slider and the total energy of the interactions between the slider and the substrate.
- CalcHysteresis.m Calculates the sum of the torques affecting the moments due to the substrate, the magnetization of the slider, and the average substrate field.
- CalcTorqueGrid.m Evaluates and stores the total substrate torque acting on each moment of the slider separately.
To understand how MagneticFriction works, it is suggested to start by reading the main simulation loop in MagneticArray.m. If details for the specific function used in the main loop are needed, it is then possible to navigate to the correct subfile that contains the particular function. See also further information for pseudocode.
A detailed explanation of the parameters needed to run the simulations is given in Parameters.
Pseudocode for MagneticFriction can be found in Pseudocode.
Please read the Method section and Section S17 of the supporting information of [1] for information on the employed model, the simulation algorithms, and the physics behind MagenticFriction.
For examples on how to use and analyze data generated by MagneticFriction, see Examples. These examples also act as a small demo for the software. They also contain valuable information and tools to reproduce most of the data presented in [1].
Note that the presented code is not an ongoing software project with active support. Instead, it is part of the supplemental information of [1] and reflects the state of the software used to obtain the corresponding numerical results. For any questions regarding [1] and the corresponding data, please contact the corresponding authors.
This repository also contains the folder SimplifiedModel with Matlab code to solve the simplified model (as introduced in [1]) numerically. These files are not related to the main simulation code. For questions regarding the numerical solution of the simplified model, please contact the corresponding authors.
If you use this simulation software or parts of it, please cite
[1] Gu, H., Lüders, A. & Bechinger, C. Non-monotonic magnetic friction from collective rotor dynamics. Nat. Mater. (2026). https://doi.org/10.1038/s41563-026-02538-1