How to use the micromagneticmodel.Energy function in micromagneticmodel

To help you get started, we’ve selected a few micromagneticmodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubermag / oommfc / oommfc / hamiltonian / hamiltonian.py View on Github external
import micromagneticmodel as mm


class Hamiltonian(mm.Energy):
    """Hamiltonian

    This class implements the sum of individual energy terms. It is
    obtained as a result of addition of two or more energy terms.

    Examples
    --------
    1. Adding an energy term to the Hamiltonian.

    >>> import oommfc as oc
    ...
    >>> hamiltonian = oc.Hamiltonian()
    >>> hamiltonian += mm.DMI(D=1e-3, crystalclass='Cnv')

    2. Creating the Hamiltoninan as a sum of two energy terms
github ubermag / oommfc / oommfc / compute.py View on Github external
def schedule_script(func, system):
    """Generate OOMMF ``Schedule...`` line for saving an individual value.

    """
    if func.__name__ == 'energy':
        return ''  # Datatable with energies is saved by default.
    elif func.__name__ == 'effective_field':
        if isinstance(func.__self__, mm.Energy):
            output = 'Oxs_RungeKuttaEvolve:evolver:Total field'
        else:
            output = (f'Oxs_{oxs_class(func.__self__, system)}:'
                      f'{func.__self__.name}:Field')
    elif func.__name__ == 'density':
        if isinstance(func.__self__, mm.Energy):
            output = 'Oxs_RungeKuttaEvolve:evolver:Total energy density'
        else:
            output = (f'Oxs_{oxs_class(func.__self__, system)}:'
                      f'{func.__self__.name}:Energy density')
    else:
        msg = f'Computing the value of {func} is not supported.'
        raise ValueError(msg)

    return 'Schedule \"{}\" archive Step 1\n'.format(output)
github ubermag / oommfc / oommfc / compute.py View on Github external
compute=schedule_script(func, system))

    if func.__name__ == 'energy':
        extension = '*.odt'
    elif func.__name__ == 'effective_field':
        extension = '*.ohf'
    elif func.__name__ == 'density':
        extension = '*.oef'

    dirname = os.path.join(system.name, f'compute-{system.compute_number-1}')
    output_file = max(glob.iglob(os.path.join(dirname, extension)),
                      key=os.path.getctime)

    if func.__name__ == 'energy':
        table = ut.Table.fromfile(output_file, rename=False)
        if isinstance(func.__self__, mm.Energy):
            output = table.data['RungeKuttaEvolve:evolver:Total energy'][0]
        else:
            output = table.data[(f'{oxs_class(func.__self__, system)}:'
                                 f'{func.__self__.name}:Energy')][0]
    else:
        output = df.Field.fromfile(output_file)

    return output