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