### DMI setup method Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/micro/dmi.html The setup method configures the DMI vector based on the specified dmi_type (bulk, interfacial, or D_2d). ```python def setup(self, mesh, spin, Ms, Ms_inv): super().setup(mesh, spin, Ms, Ms_inv) if self.dmi_type == 'bulk': self.dmi_vector = np.array([-1., 0, 0, 1., 0, 0, 0, -1., 0, 0, 1., 0, 0, 0, -1., 0, 0, 1. ]) elif self.dmi_type == 'interfacial': self.dmi_vector = np.array([0, -1., 0, # -x 0, 1., 0, # +x 1., 0, 0, # -y -1., 0, 0, # +y 0, 0, 0, # -z 0, 0, 0 # +z ]) elif self.dmi_type == 'D_2d': self.dmi_vector = np.array([1., 0, 0, # -x -1., 0, 0, # +x 0, -1., 0, # -y 0, 1., 0, # +y 0, 0, 0, # -z 0, 0, 0 # +z ]) ``` -------------------------------- ### Install all optional dependencies Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Installs the optional dev and docs dependencies for Fidimag. ```bash uv sync --all-extras ``` -------------------------------- ### Start IPython inside container Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/tutorial-docker-container.ipynb.txt Starts IPython inside the container. The output shows the IPython banner and prompt. ```bash jovyan@4df962d27520:~/work$ ipython Python 3.5.1 |Continuum Analytics, Inc.| (default, Jun 15 2016, 15:32:45) Type "copyright", "credits" or "license" for more information. IPython 4.2.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: ``` -------------------------------- ### Energy class definition and setup method Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/atomistic/energy.html Defines the Energy abstract class with a setup method that initializes mesh properties, spin, and material constants. It also allocates arrays for field and energy. ```python import numpy as np #from constant import mu_0 [docs] class Energy: """ An abstract class to implement the basic functions such as setup for atomic dynamics. """ [docs] def setup(self, mesh, spin, mu_s, mu_s_inv): self.mesh = mesh self.dx = mesh.dx * mesh.unit_length self.dy = mesh.dy * mesh.unit_length self.dz = mesh.dz * mesh.unit_length self.nx = mesh.nx self.ny = mesh.ny self.nz = mesh.nz self.spin = spin self.n = mesh.n self.n_ngbs = mesh.n_ngbs self.mesh_type = mesh.mesh_type self.total_energy = 0 self.mu_s = mu_s self.field = np.zeros(3 * self.n, dtype=np.float64) self.energy = np.zeros(mesh.n, dtype=np.float64) self.total_energy = 0.0 self.mu_s_inv = mu_s_inv self.xperiodic, self.yperiodic = (mesh.periodicity[0], mesh.periodicity[1]) self.neighbours = mesh.neighbours try: self.coordinates = self.mesh.coordinates except: self.coordinates = np.array(self.mesh.pos) ``` -------------------------------- ### Install cmake and GCC on OS X Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Installs cmake and a GCC version compatible with OpenMP on OS X via brew. ```bash brew install cmake gcc@15 ``` -------------------------------- ### Install uv on Linux Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Command to install the uv package manager, required for managing the Python environment and building Fidimag. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Start IPython in container Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/tutorial-docker-container.html Launch an interactive IPython session within the container. ```bash jovyan@4df962d27520:~/work$ ipython Python 3.5.1 |Continuum Analytics, Inc.| (default, Jun 15 2016, 15:32:45) Type "copyright", "credits" or "license" for more information. IPython 4.2.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: ``` -------------------------------- ### Initialize CuboidMesh Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/common/cuboid_mesh.html Example of creating a CuboidMesh instance with specified dimensions, cell sizes, and periodicity. ```python mesh = CuboidMesh(2, 2, 2, 250, 25, 2, periodicity=(True, False, False)) # create a mesh of dimensions 500 x 50 x 4 nm, with cellsize # of 2 nm in any direction and periodic along the x-axis. ``` -------------------------------- ### DemagHexagonal setup method Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/atomistic/demag_hexagonal.html Configures the hexagonal mesh parameters and initializes the equivalent cuboid mesh for demagnetization calculations. ```python [docs] def setup(self, mesh, spin, mu_s, mu_s_inv): if mesh.mesh_type != 'hexagonal': raise Exception('This interaction is only defined' 'for hexagonal meshes' ) # `mesh`, `spin`, `n`, `field`, `energy` and `total_energy` come from # the base class, so that this reports an energy the same way as every # other interaction super().setup(mesh, spin, mu_s, mu_s_inv) # The equivalent cuboid mesh is built in mesh units rather than in # metres, the unit length being carried by `scale` below, so the # spacings the base class stores in metres are replaced here self.dx = mesh.dx self.dx_c = 0.5 * mesh.dx self.dy = mesh.dy self.dz = mesh.dz self.nx_c = 2 * mesh.nx self.spin_c = np.zeros(2 * len(spin)) self.n_c = mesh.n * 2 # self.n_c = self.mesh_c.n self.field_c = np.zeros(3 * self.n_c, dtype=np.float64) self.energy_c = np.zeros(self.n_c, dtype=np.float64) unit_length = mesh.unit_length self.mu_s_scale_c = np.zeros(2 * self.n, dtype=np.float64) # note that the 1e-7 comes from \frac{\mu_0}{4\pi} self.scale = 1e-7 / unit_length ** 3 # could be wrong, needs carefully tests!!! # David Tue 19 Jun 2018: this variable is upated in the sim class # in case mu_s changes self.mu_s_scale = mu_s * self.scale # This seems not to be necessary # self.create_cuboid_mesh() self.scalar2cuboid(self.mu_s_scale, self.mu_s_scale_c) # Compute demag using the cuboid mesh with the double # number of x finite differences self.demag = clib.FFTDemag(self.dx_c, self.dy, self.dz, self.nx_c, self.ny, self.nz, tensor_type='dipolar') ``` -------------------------------- ### Nickel class usage example Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/atomistic/materials.html Demonstrates how to instantiate the Nickel class and print its physical properties. ```python if __name__ == '__main__': ni = Nickel() print(ni.K) print('gamma', ni.gamma) print('mu_s', ni.mu_s) print('J', ni.J) print('D', ni.D) print('D/J:', ni.D / ni.J) K = 1e5 * ni.a**3 print(K) print((ni.J / K)**0.5) ``` -------------------------------- ### Example run.py script Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/tutorial-docker-container.ipynb.txt A sample Python script that imports fidimag and writes data to a file within the container environment. ```python import fidimag # to proof we can import it print("Hello from the container") # and write to a file open("data.txt", "w").write("Data from the container.\n") ``` -------------------------------- ### Set up simulation with LLG driver for comparison Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/hubert_minimiser_atomistic.html Creates an atomistic simulation with the 'llg' driver, sets the magnetic moment, adds the same interactions as the Hubert example, and defines the same initial magnetisation function. ```python sim = fidimag.atomistic.Sim(mesh, name='one_dim', driver='llg') # Define the magnetisation sim.set_mu_s(mus) # Add the magnetic interactions sim.add(fidimag.atomistic.Exchange(J)) sim.add(fidimag.atomistic.Anisotropy(Ku, axis=(0, 0, 1))) sim.add(fidimag.atomistic.DMI(D, dmi_type='interfacial')) sim.add(fidimag.atomistic.Zeeman((0, 0, B))) xs = mesh.coordinates[:, 0] centre_x = (xs.max() + xs.min()) * 0.5 + xs.min() def m_initial(r): x, y, z = r[0], r[1], r[2] if np.abs(x - centre_x) < 2: return (0, 0.1, -.9) else: return (0, 0.1, .9) # sim.set_m((0.1, 0, 0.9)) sim.set_m(m_initial) ``` -------------------------------- ### Setting current via functions Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/micro/llg_stt.html Example of configuring the driver to use functions for current components. ```python driver.jx_function = func_x driver.jy_function = func_y driver.jz_function = func_z ``` -------------------------------- ### Import fidimag in Python Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/tutorial-docker-container.html Start Python inside the container and import the fidimag library. ```bash jovyan@4df962d27520:~/work$ python Python 3.5.1 |Continuum Analytics, Inc.| (default, Jun 15 2016, 15:32:45) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import fidimag ``` -------------------------------- ### Plot initial magnetisation for LLG example Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/hubert_minimiser_atomistic.html Plots the z-component of the initial spin configuration for the LLG simulation. ```python plt.plot(sim.mesh.coordinates[:, 0], sim.spin.reshape(-1, 3)[:, 2], 'o-') plt.show() n ``` -------------------------------- ### Stop the last started Docker container Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/tutorial-docker-container.ipynb.txt Stops the most recently started container by combining docker ps -l -q to get the container ID and docker stop to stop it. ```bash docker stop $(docker ps -l -q) ``` -------------------------------- ### Energy.setup() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.energy.html Sets up the energy computation with the given mesh, spin, and magnetic moment parameters. ```APIDOC ## Energy.setup() ### Description Sets up the energy computation with the given mesh, spin, and magnetic moment parameters. ### Method setup(_mesh_, _spin_, _mu_s_, _mu_s_inv_) ### Parameters - **_mesh** - The mesh object. - **_spin** - The spin configuration. - **_mu_s** - The saturation magnetic moment. - **_mu_s_inv** - The inverse of the saturation magnetic moment. ``` -------------------------------- ### DemagFull.setup() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.demag_full.html Sets up the DemagFull object with the mesh, spin, and magnetic moment parameters. ```APIDOC ## DemagFull.setup() ### Description Sets up the DemagFull object with the mesh, spin, and magnetic moment parameters. ### Method setup ### Signature setup(_mesh_, _spin_, _mu_s_, _mu_s_inv_) ### Parameters - **mesh** (Mesh) - Required - The simulation mesh. - **spin** (array-like) - Required - The spin configuration. - **mu_s** (array-like) - Required - The saturation magnetic moment. - **mu_s_inv** (array-like) - Required - The inverse of the saturation magnetic moment. ``` -------------------------------- ### Get Docker machine IP address Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/tutorial-docker-container.ipynb.txt On a Mac, run this command to find the IP address to connect to the notebook. For example, if it returns 192.168.99.100, use http://192.168.99.100:30000. ```bash docker-machine ip ``` -------------------------------- ### Relaxation Process Output Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/standard_problem_4.html Example output showing the progression of the relaxation process with time steps and maximum dmdt values. ```text #1 t=1e-13 dt=1e-13 max_dmdt=517 #2 t=2e-13 dt=1e-13 max_dmdt=510 #3 t=3e-13 dt=1e-13 max_dmdt=502 #4 t=4e-13 dt=1e-13 max_dmdt=495 #5 t=5e-13 dt=1e-13 max_dmdt=489 #6 t=6e-13 dt=1e-13 max_dmdt=482 #7 t=7e-13 dt=1e-13 max_dmdt=476 #8 t=8e-13 dt=1e-13 max_dmdt=470 #9 t=9e-13 dt=1e-13 max_dmdt=464 #10 t=1e-12 dt=1e-13 max_dmdt=459 #11 t=1.14e-12 dt=1.43e-13 max_dmdt=453 #12 t=1.29e-12 dt=1.43e-13 max_dmdt=445 #13 t=1.43e-12 dt=1.43e-13 max_dmdt=439 #14 t=1.57e-12 dt=1.43e-13 max_dmdt=433 #15 t=1.72e-12 dt=1.43e-13 max_dmdt=428 #16 t=1.86e-12 dt=1.43e-13 max_dmdt=422 #17 t=2e-12 dt=1.43e-13 max_dmdt=417 #18 t=2.15e-12 dt=1.43e-13 max_dmdt=412 #19 t=2.29e-12 dt=1.43e-13 max_dmdt=407 #20 t=2.51e-12 dt=2.15e-13 max_dmdt=401 #21 t=2.72e-12 dt=2.15e-13 max_dmdt=394 #22 t=2.94e-12 dt=2.15e-13 max_dmdt=387 #23 t=3.15e-12 dt=2.15e-13 max_dmdt=381 #24 t=3.37e-12 dt=2.15e-13 max_dmdt=375 #25 t=3.58e-12 dt=2.15e-13 max_dmdt=369 #26 t=3.8e-12 dt=2.15e-13 max_dmdt=364 #27 t=4.01e-12 dt=2.15e-13 max_dmdt=358 #28 t=4.23e-12 dt=2.15e-13 max_dmdt=353 #29 t=4.44e-12 dt=2.15e-13 max_dmdt=348 #30 t=4.66e-12 dt=2.15e-13 max_dmdt=343 #31 t=4.87e-12 dt=2.15e-13 max_dmdt=338 #32 t=5.09e-12 dt=2.15e-13 max_dmdt=333 #33 t=5.3e-12 dt=2.15e-13 max_dmdt=328 #34 t=5.52e-12 dt=2.15e-13 max_dmdt=324 #35 t=5.73e-12 dt=2.15e-13 max_dmdt=320 #36 t=5.95e-12 dt=2.15e-13 max_dmdt=315 #37 t=6.16e-12 dt=2.15e-13 max_dmdt=311 #38 t=6.38e-12 dt=2.15e-13 max_dmdt=307 #39 t=6.59e-12 dt=2.15e-13 max_dmdt=303 #40 t=6.81e-12 dt=2.15e-13 max_dmdt=299 #41 t=7.02e-12 dt=2.15e-13 max_dmdt=295 #42 t=7.24e-12 dt=2.15e-13 max_dmdt=291 #43 t=7.45e-12 dt=2.15e-13 max_dmdt=288 #44 t=7.78e-12 dt=3.29e-13 max_dmdt=283 #45 t=8.11e-12 dt=3.29e-13 max_dmdt=278 #46 t=8.44e-12 dt=3.29e-13 max_dmdt=273 #47 t=8.77e-12 dt=3.29e-13 max_dmdt=268 #48 t=9.09e-12 dt=3.29e-13 max_dmdt=263 #49 t=9.42e-12 dt=3.29e-13 max_dmdt=258 #50 t=9.75e-12 dt=3.29e-13 max_dmdt=254 #51 t=1.01e-11 dt=3.29e-13 max_dmdt=249 #52 t=1.04e-11 dt=3.29e-13 max_dmdt=245 #53 t=1.07e-11 dt=3.29e-13 max_dmdt=240 #54 t=1.11e-11 dt=3.29e-13 max_dmdt=236 #55 t=1.14e-11 dt=3.29e-13 max_dmdt=232 #56 t=1.17e-11 dt=3.29e-13 max_dmdt=229 #57 t=1.21e-11 dt=3.29e-13 max_dmdt=225 #58 t=1.24e-11 dt=3.29e-13 max_dmdt=221 #59 t=1.27e-11 dt=3.29e-13 max_dmdt=218 #60 t=1.3e-11 dt=3.29e-13 max_dmdt=214 #61 t=1.34e-11 dt=3.29e-13 max_dmdt=211 #62 t=1.37e-11 dt=3.29e-13 max_dmdt=208 #63 t=1.4e-11 dt=3.29e-13 max_dmdt=204 #64 t=1.45e-11 dt=4.94e-13 max_dmdt=201 #65 t=1.5e-11 dt=4.94e-13 max_dmdt=196 #66 t=1.55e-11 dt=4.94e-13 max_dmdt=192 #67 t=1.6e-11 dt=4.94e-13 max_dmdt=188 #68 t=1.65e-11 dt=4.94e-13 max_dmdt=184 #69 t=1.7e-11 dt=4.94e-13 max_dmdt=180 #70 t=1.75e-11 dt=4.94e-13 max_dmdt=177 #71 t=1.8e-11 dt=4.94e-13 max_dmdt=173 #72 t=1.85e-11 dt=4.94e-13 max_dmdt=170 #73 t=1.9e-11 dt=4.94e-13 max_dmdt=167 #74 t=1.95e-11 dt=4.94e-13 max_dmdt=164 #75 t=2e-11 dt=4.94e-13 max_dmdt=161 #76 t=2.04e-11 dt=4.94e-13 max_dmdt=159 #77 t=2.09e-11 dt=4.94e-13 max_dmdt=156 #78 t=2.17e-11 dt=7.48e-13 max_dmdt=153 #79 t=2.24e-11 dt=7.48e-13 max_dmdt=150 #80 t=2.32e-11 dt=7.48e-13 max_dmdt=147 #81 t=2.39e-11 dt=7.48e-13 max_dmdt=144 #82 t=2.47e-11 dt=7.48e-13 max_dmdt=141 #83 t=2.54e-11 dt=7.48e-13 max_dmdt=138 #84 t=2.62e-11 dt=7.48e-13 max_dmdt=136 #85 t=2.69e-11 dt=7.48e-13 max_dmdt=134 #86 t=2.77e-11 dt=7.48e-13 max_dmdt=131 #87 t=2.84e-11 dt=7.48e-13 max_dmdt=129 #88 t=2.92e-11 dt=7.48e-13 max_dmdt=127 #89 t=2.99e-11 dt=7.48e-13 max_dmdt=125 #90 t=3.07e-11 dt=7.48e-13 max_dmdt=124 #91 t=3.14e-11 dt=7.48e-13 max_dmdt=122 #92 t=3.22e-11 dt=7.48e-13 max_dmdt=120 #93 t=3.29e-11 dt=7.48e-13 max_dmdt=119 #94 t=3.37e-11 dt=7.48e-13 max_dmdt=118 ``` -------------------------------- ### Main execution of BatchTasks Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/common/batch_task.html Creates a BatchTasks instance with the task function and two parameters, adds parameters p1 and p2, and starts the batch tasks. ```python if __name__ == "__main__": tasks = BatchTasks(task, 2) tasks.add_parameters('p1', ['a', 'b', 'c']) tasks.add_parameters('p2', range(1, 5)) tasks.start() ``` -------------------------------- ### Demag.setup() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.demag.html Sets up the Demag energy term with the given mesh, spin, saturation magnetization, and inverse saturation magnetization. This method is part of the Demag class. ```APIDOC ## Demag.setup(mesh, spin, Ms, Ms_inv) ### Description Sets up the Demag energy term with the given mesh, spin, saturation magnetization, and inverse saturation magnetization. This method is part of the Demag class. ### Method setup ### Parameters - **mesh** (Mesh) - Required - The mesh object for the simulation. - **spin** (array) - Required - The spin configuration. - **Ms** (float) - Required - Saturation magnetization. - **Ms_inv** (float) - Required - Inverse saturation magnetization. ``` -------------------------------- ### Energy.setup(_mesh_, _spin_, _Ms_, _Ms_inv_) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.energy.html Sets up the energy interaction with the given mesh, spin, saturation magnetization, and inverse saturation magnetization. ```APIDOC ## Energy.setup(_mesh_, _spin_, _Ms_, _Ms_inv_) ### Description Sets up the energy interaction with the given mesh, spin, saturation magnetization, and inverse saturation magnetization. ### Method setup(_mesh_, _spin_, _Ms_, _Ms_inv_) ### Parameters - _mesh_ - The mesh object. - _spin_ - The spin field. - _Ms_ - Saturation magnetization. - _Ms_inv_ - Inverse saturation magnetization. ``` -------------------------------- ### List running Docker containers Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/tutorial-docker-container.ipynb.txt Shows all running containers. Use -q to show only container IDs, and -l to show only the last started container. ```bash docker ps ``` ```bash docker ps -q ``` ```bash docker ps -l ``` -------------------------------- ### Set up simulation with material parameters and energies Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/isolated_skyrmion.html Creates the simulation object, sets material parameters (Ms, A, D, alpha, gamma), adds exchange, DMI, and demagnetisation energies, and initialises the magnetisation. ```python # FeGe material paremeters. Ms = 3.84e5 # saturation magnetisation (A/m) A = 8.78e-12 # exchange energy constant (J/m) D = 1.58e-3 # Dzyaloshinkii-Moriya energy constant (J/m**2) alpha = 1 # Gilbert damping gamma = 2.211e5 # gyromagnetic ration (m/As) # Create simulation object. sim = Sim(mesh) # sim = Sim(mesh, driver='steepest_descent') sim.Ms = Ms_function(Ms) sim.driver.alpha = alpha sim.driver.gamma = gamma # Add energies. sim.add(UniformExchange(A=A)) sim.add(DMI(D=D)) sim.add(Demag()) # Since the magnetisation dynamics is not important in this stage, # the precession term in LLG equation can be set to artificially zero. # sim.driver.do_precession = False # Initialise the system. sim.set_m(init_m) ``` -------------------------------- ### DemagHexagonal.setup(mesh, spin, mu_s, mu_s_inv) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.demag_hexagonal.html Sets up the DemagHexagonal object with mesh, spin, and magnetic moment data. ```APIDOC ## DemagHexagonal.setup(mesh, spin, mu_s, mu_s_inv) ### Description Sets up the DemagHexagonal object with the given mesh, spin configuration, and magnetic moment arrays. ### Parameters - `mesh` - The mesh object. - `spin` - The spin configuration. - `mu_s` - The magnetic moment array. - `mu_s_inv` - The inverse magnetic moment array. ``` -------------------------------- ### Relaxation.setup(mesh, m, Ms) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.relax.html Sets up the relaxation computation with the given mesh, magnetization, and saturation magnetization. ```APIDOC ## Relaxation.setup(mesh, m, Ms) ### Description Sets up the relaxation computation with the given mesh, magnetization, and saturation magnetization. ### Method setup ### Parameters - **mesh** (Mesh) - Required - The mesh on which the computation is performed. - **m** (field) - Required - The magnetization field. - **Ms** (float) - Required - Saturation magnetization. ### Returns None ``` -------------------------------- ### Import Fidimag and dependencies Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/Simulating%20an%20Anisotropic%20Grain%20Structure.ipynb.txt Imports the Fidimag library, scipy's cKDTree for spatial queries, and numpy for numerical operations. Required for the grain simulation example. ```python import fidimag from scipy.spatial import cKDTree import numpy as np ``` -------------------------------- ### Initialize Periodic System Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/spin-waves-in-periodic-system.ipynb.txt Sets up a periodic mesh and initializes the magnetic system for spin wave calculations. ```python import numpy as np from fidimag.atomistic import Sim from fidimag.atomistic.hamiltonian import Exchange, DMI, Zeeman from fidimag.common.mesh import PeriodicMesh # Define mesh and system mesh = PeriodicMesh(nx=100, ny=1, nz=1, dx=1e-9) sim = Sim(mesh, name='spin_wave_periodic') # Add interactions sim.hamiltonian.add(Exchange(1e-12)) # Set initial state sim.set_m((0, 0, 1)) ``` -------------------------------- ### Example spatial_Ms TCL function Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.oommf.html Example of a spatial_Ms function that returns 2e4 inside a circular region and 0 elsewhere. This is passed as a string to the spatial_Ms parameter. ```tcl spatial_Ms = """ if { $x * $x + $y * $y < 5e-9 * 5e-9 } { return 2e4 } else { return 0 } """ ``` -------------------------------- ### ExchangeRKKY.setup(mesh, spin, Ms, Ms_inv) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.exchange_rkky.html Sets up the energy term with the mesh, spin, and saturation magnetization data. This method is called during initialization to prepare the term for computation. ```APIDOC ## ExchangeRKKY.setup(mesh, spin, Ms, Ms_inv) ### Description Sets up the energy term with the mesh, spin, and saturation magnetization data. This method is called during initialization to prepare the term for computation. ### Parameters - **mesh** (Mesh) - The mesh object defining the simulation geometry. - **spin** (array-like) - The initial spin configuration. - **Ms** (array-like) - Saturation magnetization values. - **Ms_inv** (array-like) - Inverse saturation magnetization values. ### Returns - None ``` -------------------------------- ### LLG_STT_CPP.get_p() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.llg_stt_cpp.html Method to get the polarization p. ```APIDOC ## LLG_STT_CPP.get_p() ### Description Returns the polarization p. ### Returns - The value of p. ``` -------------------------------- ### LLG_STT_CPP.get_a_J() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.llg_stt_cpp.html Method to get the current density a_J. ```APIDOC ## LLG_STT_CPP.get_a_J() ### Description Method to get the current density a_J. ### Method Getter ### Signature get_a_J() ### Returns The current density a_J. ``` -------------------------------- ### SimBase.get_alpha(alpha) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.common.sim_base.html Gets the damping parameter alpha. ```APIDOC ## SimBase.get_alpha(alpha) ### Description Gets the damping parameter alpha. ### Parameters - **alpha** - Required - The alpha value to get. ### Returns The alpha value. ``` -------------------------------- ### DMI.setup(mesh, spin, mu_s, mu_s_inv) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.dmi.html Sets up the DMI interaction with the given mesh, spin, and magnetic moment parameters. ```APIDOC ## DMI.setup(mesh, spin, mu_s, mu_s_inv) ### Description Initializes the DMI interaction with the simulation mesh and spin configuration. ### Parameters - **mesh** (Mesh) - Required - The simulation mesh. - **spin** (array) - Required - Spin configuration. - **mu_s** (array) - Required - Saturation magnetic moments. - **mu_s_inv** (array) - Required - Inverse saturation magnetic moments. ### Returns None. ``` -------------------------------- ### LLG_STT_CPP.p Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.llg_stt_cpp.html Property to get or set the spin polarization p. ```APIDOC ## LLG_STT_CPP.p ### Description Property to get or set the spin polarization p. ### Method Property getter and setter ### Getter Returns the spin polarization p. ### Setter Sets the spin polarization p. ### Parameters (Setter) - **value** - Required - The new value for p. ``` -------------------------------- ### Exchange.setup(mesh, spin, mu_s, mu_s_inv) Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/atomistic/exchange.html Sets up the exchange interaction for a given mesh, spin, and magnetic moments. It determines the appropriate computation method based on the type of J provided: uniform, spatial, or full exchange calculation. ```APIDOC ## Exchange.setup(mesh, spin, mu_s, mu_s_inv) ### Description Sets up the exchange interaction energy term for the given mesh and spin configuration. Based on the type of J provided, it selects the appropriate computation method: uniform exchange for scalar J, spatial exchange for callable J, or full exchange for a list of shell constants. ### Parameters - **mesh** (Mesh) - Required - The mesh object defining the lattice structure. - **spin** (array) - Required - The spin configuration. - **mu_s** (array) - Required - The magnetic moment magnitudes. - **mu_s_inv** (array) - Required - The inverse magnetic moment magnitudes. ### Behavior - If J is a float or int, it sets Jx, Jy, Jz to the same value and uses `compute_field_uniform`. - If J is callable, it evaluates the function at each lattice site to build a spatial exchange tensor and uses `compute_field_spatial`. - If J is a list or numpy array with length equal to the number of neighbour shells, it stores the shell constants and uses `compute_field_full`. ### Notes - The spatial function must return either a float/int or a list/array/tuple of length 6. Otherwise, an exception is raised. - The number of shells should not be larger than 8 (checked in the mesh class). ``` -------------------------------- ### LLG_STT_CPP.a_J Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.llg_stt_cpp.html Property to get or set the current density a_J. ```APIDOC ## LLG_STT_CPP.a_J ### Description Property to get or set the current density a_J. ### Method Property getter and setter ### Getter Returns the current density a_J. ### Setter Sets the current density a_J. ### Parameters (Setter) - **value** - Required - The new value for a_J. - **args** - Optional - Additional arguments. ``` -------------------------------- ### LLG_STT_CPP.get_a_J() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.llg_stt_cpp.html Method to get the spin torque coefficient a_J. ```APIDOC ## LLG_STT_CPP.get_a_J() ### Description Returns the spin torque coefficient a_J. ### Returns - The value of a_J. ``` -------------------------------- ### DMI.setup(mesh, spin, Ms, Ms_inv) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.dmi.html Sets up the DMI interaction with the given mesh, spin, and saturation magnetization values. This method initializes necessary internal data. ```APIDOC ## DMI.setup(mesh, spin, Ms, Ms_inv) ### Description Sets up the DMI interaction with the provided mesh and spin configuration. ### Parameters - **mesh** (Mesh) - Required - The mesh object. - **spin** (array) - Required - The spin configuration. - **Ms** (float) - Required - Saturation magnetization. - **Ms_inv** (float) - Required - Inverse saturation magnetization. ``` -------------------------------- ### Create environment and build C/C++ modules Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Creates the Python environment and builds the C/C++ modules in editable mode. ```bash uv sync ``` -------------------------------- ### LLG_STT.get_jz() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.llg_stt.html Method to get the jz component of the LLG_STT driver. ```APIDOC ## LLG_STT.get_jz() ### Description Method to get the jz component of the LLG_STT driver. ### Signature LLG_STT.get_jz() ``` -------------------------------- ### LLG_STT.get_jy() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.llg_stt.html Method to get the jy component of the LLG_STT driver. ```APIDOC ## LLG_STT.get_jy() ### Description Method to get the jy component of the LLG_STT driver. ### Signature LLG_STT.get_jy() ``` -------------------------------- ### Configure Simulation and Initial State Source: https://fidimag.readthedocs.io/en/latest/user_guide/ipynb/hubert_minimiser_atomistic.html Initialize the simulation with the Hubert minimiser, set physical parameters, and define the initial magnetisation state. ```python sim = fidimag.micro.Sim(mesh, name='1Dmicro', driver='hubert_minimiser') Ms = 0.86e6 A = 13e-12 Ku = 0.4e6 # Define the magnetisation sim.set_Ms(Ms) # Add the magnetic interactions sim.add(fidimag.micro.UniformExchange(A)) sim.add(fidimag.micro.UniaxialAnisotropy(Ku, axis=(0, 0, 1))) # sim.add(fidimag.atomistic.DMI(D, dmi_type='interfacial')) # sim.add(fidimag.micro.Zeeman((0, 0, B))) xs = mesh.coordinates[:, 0] centre_x = (xs.max() + xs.min()) * 0.5 + xs.min() def m_initial(r): x, y, z = r[0], r[1], r[2] if x < centre_x: return (0, 0.1, -.9) else: return (0, 0.1, .9) # sim.set_m((0.1, 0, 0.9)) sim.set_m(m_initial) mesh_vol = mesh.n * mesh.dx * mesh.dy * mesh.dz * 1e-27 Kd = C.mu_0 * (Ms ** 2) * 0.5 * mesh_vol sim.driver.energyScale = Kd ``` -------------------------------- ### LLG_STT.get_jx() Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.llg_stt.html Method to get the jx component of the LLG_STT driver. ```APIDOC ## LLG_STT.get_jx() ### Description Method to get the jx component of the LLG_STT driver. ### Signature LLG_STT.get_jx() ``` -------------------------------- ### Set up simulation mesh and parameters Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/Simulating%20an%20Anisotropic%20Grain%20Structure.ipynb.txt Defines material parameters (A, Ms), mesh dimensions (n=40, d=5), creates a CuboidMesh with periodic boundary conditions in x and y, and initializes a micromagnetic simulation with damping alpha=1.0. ```python A=1.3e-11 Ms=8.6e5 n = 40 d = 5 mesh = fidimag.common.CuboidMesh(nx=n, ny=n, nz=1, dx=d, dy=d, dz=d, unit_length=1e-9, periodicity=(True, True, False)) sim = fidimag.micro.Sim(mesh, name="Grains") sim.alpha = 1.0 ``` -------------------------------- ### MonteCarlo.mu_s (property) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.monte_carlo.html Property that gets or sets the saturation magnetic moment. ```APIDOC ## MonteCarlo.mu_s (property) ### Description Property for accessing the saturation magnetic moment (mu_s). ### Getter Returns the current mu_s value. ### Setter Sets the mu_s value. ``` -------------------------------- ### Get Saturation Magnetization Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/micro/sim.html Method to retrieve the saturation magnetization array. ```python def get_Ms(self): """ Returns the array with the saturation magnetisation values per mesh site """ return self._Ms ``` -------------------------------- ### Vector field reshaping example for vector2cuboid Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.atomistic.demag_hexagonal.html Example showing how a vector field array is reshaped from a 1D array into a 3D matrix with shape (ny, nx, 3) for a 2x3 system. The cuboid version doubles the number of columns, resulting in a (ny, 2*nx, 3) matrix. ```text Original: vector_field = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] Reshaped: [ [ [ 0, 1, 2], [ 3, 4, 5] ], [ [ 6, 7, 8], [ 9, 10, 11] ], [ [12, 13, 14], [15, 16, 17] ] ] So we have 2 sites per row,as the original system, where a 3-vector is associated to each entry, making a (2, 3, 3) matrix --> (ny, nx, 3) in general Thus, for the cuboid version, we would have the double of columns, i.e. a (ny, 2 * nx, 3) matrix and copy the elements as in the scalar field ``` -------------------------------- ### fidimag.micro.oommf.setup_logger Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.micro.oommf.html Set up the logger for the OOMMF module. ```APIDOC # fidimag.micro.oommf.setup_logger ## Parameters `setup_logger()` ## Description Initialise the logging system for this module. No parameters required. ``` -------------------------------- ### Test import Fidimag Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Runs a Python command to verify the Fidimag installation. ```bash uv run python -c "import fidimag" ``` -------------------------------- ### Initialize simulation object Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/standard_problem_4.ipynb.txt Create the simulation object, set tolerances, and add energy terms for the relaxation stage. ```python from fidimag.micro import Sim, UniformExchange, Demag, Zeeman, TimeZeeman sim = Sim(mesh) # create simulation object sim.driver.set_tols(rtol=1e-10, atol=1e-10) sim.Ms = Ms sim.driver.alpha = 0.5 # large value since the magnetisation dynamics is not important in the relexation stage sim.driver.gamma = gamma sim.driver.do_precession = False # speeds up the simulation # Starting magnetisation. sim.set_m((1, 0.25, 0.1)) sim.add(UniformExchange(A=A)) sim.add(Demag()) ``` -------------------------------- ### 1D Domain Wall Simulation with Fidimag Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/1d_domain_wall.ipynb.txt This example demonstrates how to set up and relax a one-dimensional domain wall using Fidimag. It defines a 1D mesh, a material with given parameters, an initial magnetisation profile, and then relaxes the system. The final magnetisation profile is plotted. ```python import fidimag import numpy as np import matplotlib.pyplot as plt # Define a one-dimensional mesh with 100 cells and a cell size of 1 nm. mesh = fidimag.common.Mesh(nx=100, ny=1, nz=1, dx=1.0, dy=1.0, dz=1.0) # Define a material with saturation magnetisation Ms = 1e6 A/m and exchange constant A = 1e-11 J/m. material = fidimag.common.Material(mesh) material.Ms = 1e6 material.A = 1e-11 # Define a one-dimensional domain wall initial magnetisation. def m_init(pos): x, y, z = pos if x < 50: return (0, 0, 1) else: return (0, 0, -1) # Create a simulation object. sim = fidimag.micro.Sim(mesh, material) sim.set_m(m_init) # Relax the system to its equilibrium state. sim.driver.relax(dt=1e-13, stopping_dmdt=0.01, max_steps=5000, save_m_steps=None, save_vtk_steps=None) # Plot the magnetisation profile. plt.plot(sim.m[0], label='mx') plt.plot(sim.m[1], label='my') plt.plot(sim.m[2], label='mz') plt.legend() plt.show() ``` -------------------------------- ### SimBase.pins (property) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.common.sim_base.html Property that gets or sets the array with pinned spins in the sample. ```APIDOC ## SimBase.pins (property) ### Description Property that gets or sets the array with pinned spins in the sample. ### Returns The array with pinned spins. ``` -------------------------------- ### SimBase.alpha (property) Source: https://fidimag.readthedocs.io/en/latest/api/generated/fidimag.common.sim_base.html Property that gets or sets the damping parameter alpha for the simulation. ```APIDOC ## SimBase.alpha (property) ### Description Property that gets or sets the damping parameter alpha for the simulation. ### Returns The current value of alpha. ``` -------------------------------- ### Set OOMMF path Source: https://fidimag.readthedocs.io/en/latest/_sources/install.rst.txt Sets the environment variable pointing to the OOMMF installation directory. ```bash export OOMMF_PATH=/path/to/folder/containing/OOMMF ``` -------------------------------- ### Set up simulation with anisotropy, exchange, and demag Source: https://fidimag.readthedocs.io/en/latest/_sources/user_guide/ipynb/Simulating%20an%20Anisotropic%20Grain%20Structure.ipynb.txt Initializes the magnetization along +z, sets saturation magnetization, adds a UniaxialAnisotropy with the grain-dependent functions, adds UniformExchange and Demag (with 2D periodic boundary conditions) to the simulation. ```python sim.set_m((0, 0, 1), normalise=True) sim.set_Ms(Ms) anisotropy = fidimag.micro.UniaxialAnisotropy(K_mag, K_axis) sim.add(anisotropy) sim.add(fidimag.micro.UniformExchange(A)) sim.add(fidimag.micro.Demag(pbc_2d=True)) ``` -------------------------------- ### Defining a spatial current function Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/micro/llg_stt.html Example of a function definition for spatial current dependency. ```python def myfunc_x(pos): x, y, z = pos jx = # some function of x, y, and z. return jx ``` -------------------------------- ### Setting constant current Source: https://fidimag.readthedocs.io/en/latest/_modules/fidimag/micro/llg_stt.html Example of setting constant current components for the LLG_STT driver. ```python driver.jx = 1.0 driver.jy = 0.0 driver.jz = 0.0 ```