{ "cells": [ { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Multiple energy terms of the same class\n", "\n", "Sometimes it is necessary to allow adding multiple energy terms of the same class to the same equation. In that case, terms must have a different name. By default, if at initialisation, no name was provided, the name of the term is going to be the same as the name of the class in lowercase:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'zeeman'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import micromagneticmodel as mm\n", "\n", "zeeman1 = mm.Zeeman(H=(0, 0, 1e6))\n", "\n", "zeeman1.name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, we can explicitly set up the name of the object:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'my_zeeman_term'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "zeeman2 = mm.Zeeman(H=(0, 0, 1e6), name=\"my_zeeman_term\")\n", "\n", "zeeman2.name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we can try to add multiple energy terms to the energy equation:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exception raised.\n" ] } ], "source": [ "try:\n", " energy = zeeman1 + zeeman1\n", "except ValueError:\n", " print(\"Exception raised.\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "energy = zeeman1 + zeeman2" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "This is allowed because both terms have different names." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }