Multiple energy terms of the same class#
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:
[1]:
import micromagneticmodel as mm
zeeman1 = mm.Zeeman(H=(0, 0, 1e6))
zeeman1.name
[1]:
'zeeman'
However, we can explicitly set up the name of the object:
[2]:
zeeman2 = mm.Zeeman(H=(0, 0, 1e6), name="my_zeeman_term")
zeeman2.name
[2]:
'my_zeeman_term'
Now, we can try to add multiple energy terms to the energy equation:
[3]:
try:
energy = zeeman1 + zeeman1
except ValueError:
print("Exception raised.")
Exception raised.
[4]:
energy = zeeman1 + zeeman2
This is allowed because both terms have different names.