.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "master-tutorial/1_python-library/plot_8_lswt.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_master-tutorial_1_python-library_plot_8_lswt.py: Linear Spin Wave theory *********************** .. include:: ../../exercises/8.inc All methods for linear spin-wave theory are grouped in the :py:class:`magnopy.LSWT` class. To create it we require two things * Spin Hamiltonian * Directions of spins in the ground state .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. code-block:: Python import numpy as np import magnopy .. GENERATED FROM PYTHON SOURCE LINES 19-21 An example of the cubic ferromagnet with nearest-neighbor interactions and easy magnetic axis along :math:`\mathbf{z}`. .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python spinham = magnopy.examples.cubic_ferro_nn(S=1, J_21=(0, 0, -0.5)) # Get the LSWT object from it lswt = magnopy.LSWT(spinham=spinham, spin_directions=[[0, 0, 1]]) .. GENERATED FROM PYTHON SOURCE LINES 29-33 Once created it can be used to compute parts of the magnon Hamiltonian Correction to the classical energy ================================== .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python print(lswt.E_2()) .. rst-class:: sphx-glr-script-out .. code-block:: none -3.5 .. GENERATED FROM PYTHON SOURCE LINES 37-39 Coefficients of the one-operator terms ====================================== .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: Python print(lswt.O()) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.+0.j] .. GENERATED FROM PYTHON SOURCE LINES 43-45 Magnon energies =============== .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python print(lswt.omega(k=[0, 0, 0])) .. rst-class:: sphx-glr-script-out .. code-block:: none [1.+0.j] .. GENERATED FROM PYTHON SOURCE LINES 50-59 Parallelization =============== Typically one wants to compute magnon energies for a set of k-points. Often for a rather large set of k-points. Magnopy offers simple interface to parallelize the calculations over the k-points using multiprocessing. See :py:func:`magnopy.multiprocess_over_k` for details. For example, to compute magnon energies for the set of k-points (that are given as absolute coordinates in reciprocal space) using two processes use .. GENERATED FROM PYTHON SOURCE LINES 59-70 .. code-block:: Python kpoints = np.linspace([0, 0, 0], [1, 0, 0], 1000) results = magnopy.multiprocess_over_k( kpoints=kpoints, relative=False, function=lswt.omega, number_processors=2, ) .. GENERATED FROM PYTHON SOURCE LINES 71-72 Note that ``results[i]`` is equivalent to ``lswt.omega(k=kpoints[i], relative=False)``. .. GENERATED FROM PYTHON SOURCE LINES 72-78 .. code-block:: Python print(results[42]) print(lswt.omega(k=kpoints[42], relative=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none [1.00176727+0.j] [1.00176727+0.j] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.131 seconds) .. _sphx_glr_download_master-tutorial_1_python-library_plot_8_lswt.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_8_lswt.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_8_lswt.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_8_lswt.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_