In micromagneticmodel
package, base classes micromagneticmodel.Driver
and micromagneticmodel.Evolver
are defined. Their purpose is to build individual evolvers and drivers in a particular micromagnetic calculator. In this tutorial, we will demonstrate some of their basic properties, on an example of a micromagneticmodel.Driver
class. The behaviour of the micromagneticmodel.Evolver
class is the same.
Let us derive MyDriver
class. In order to define it, _allowed_kwargs
list must be defined. It is a list of strings, which lists the kwargs which are allowed to be passed.
import micromagneticmodel as mm
class MyDriver(mm.Driver):
_allowed_kwargs = ['arg1', 'arg2']
Driver
class does not require any parameters to be passed at initialisation. If a keyword argument is from _allowed_kwargs
list, it will be assigned as a class attribute. Otherwise, AttributeError
will be raised.
driver = MyDriver(arg1=1, arg2='value')
The attributes are
driver.arg1
1
driver.arg2
'value'
If we try to pass a keyword argument at initialisation, which is not in the _allowed_kwargs
list, AttributeError
is rased:
try:
driver = MyDriver(arg3=1)
except AttributeError:
print('Exception raised.')
Exception raised.
The main driver method which must be implemented by a derived class is drive
.
try:
driver.drive()
except NotImplementedError:
print('Exception raised.')
Exception raised.
Full description of all existing descriptors can be found in the API Reference.