How to use the oommfc.scripts function in oommfc

To help you get started, we’ve selected a few oommfc 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 / scripts / evolver.py View on Github external
def evolver_script(evolver):
    mif = ''

    # Prepare parameters depending on what attributes are defined in evolver.
    if hasattr(evolver, 'gamma_G'):
        gamma0mif, gamma0name = oc.scripts.setup_scalar_parameter(
            evolver.gamma_G, 'pr_gamma0')
        evolver.gamma_G = gamma0name
        mif += gamma0mif
    if hasattr(evolver, 'alpha'):
        alphamif, alphaname = oc.scripts.setup_scalar_parameter(
            evolver.alpha, 'dp_alpha')
        evolver.alpha = alphaname
        mif += alphamif
    if hasattr(evolver, 'u'):
        umif, uname = oc.scripts.setup_scalar_parameter(evolver.u, 'zl_u')
        evolver.u = uname
        mif += umif

    # zhangli.beta cannot spatially vary - it has to be a constant.

    if hasattr(evolver, 'J'):
        Jmif, Jname = oc.scripts.setup_scalar_parameter(evolver.J, 'sl_J')
        evolver.J = Jname
        mif += Jmif
    if hasattr(evolver, 'mp'):
        mpmif, mpname = oc.scripts.setup_vector_parameter(evolver.mp, 'sl_mp')
        evolver.mp = mpname
        mif += mpmif
    if hasattr(evolver, 'P'):
        Pmif, Pname = oc.scripts.setup_scalar_parameter(evolver.P, 'sl_P')
        evolver.P = Pname
github ubermag / oommfc / oommfc / scripts / evolver.py View on Github external
def evolver_script(evolver):
    mif = ''

    # Prepare parameters depending on what attributes are defined in evolver.
    if hasattr(evolver, 'gamma_G'):
        gamma0mif, gamma0name = oc.scripts.setup_scalar_parameter(
            evolver.gamma_G, 'pr_gamma0')
        evolver.gamma_G = gamma0name
        mif += gamma0mif
    if hasattr(evolver, 'alpha'):
        alphamif, alphaname = oc.scripts.setup_scalar_parameter(
            evolver.alpha, 'dp_alpha')
        evolver.alpha = alphaname
        mif += alphamif
    if hasattr(evolver, 'u'):
        umif, uname = oc.scripts.setup_scalar_parameter(evolver.u, 'zl_u')
        evolver.u = uname
        mif += umif

    # zhangli.beta cannot spatially vary - it has to be a constant.

    if hasattr(evolver, 'J'):
github ubermag / oommfc / oommfc / compute.py View on Github external
def oxs_class(term, system):
    """Extract the OOMMF ``Oxs_`` class name of an individual term.

    """
    mif = getattr(oc.scripts.energy, f'{term.name}_script')(term, system)
    return re.search(r'Oxs_([\w_]+)', mif).group(1)
github ubermag / oommfc / oommfc / scripts / mesh.py View on Github external
def mesh_script(mesh):
    mif = ''
    # Define atlas.
    if mesh.subregions:
        # The mesh is composed of subregions. Multiple BoxAtlas scripts are
        # generated and the main MultiAtlas.
        for name, subregion in mesh.subregions.items():
            mif += oc.scripts.box_atlas(subregion.pmin, subregion.pmax,
                                        name=name)
        mif += '# MultiAtlas\n'
        mif += 'Specify Oxs_MultiAtlas:main_atlas {\n'
        for name in mesh.subregions.keys():
            mif += f'  atlas :{name}_atlas\n'
        mif += f'  xrange {{ {mesh.region.pmin[0]} {mesh.region.pmax[0]} }}\n'
        mif += f'  yrange {{ {mesh.region.pmin[1]} {mesh.region.pmax[1]} }}\n'
        mif += f'  zrange {{ {mesh.region.pmin[2]} {mesh.region.pmax[2]} }}\n'
        mif += '}\n\n'
    else:
        # There are no subregions in the mesh and only a single BoxAtlas is
        # generated.
        mif += oc.scripts.box_atlas(mesh.region.pmin, mesh.region.pmax,
                                    name='main')

    # Define mesh.
github ubermag / oommfc / oommfc / drivers / driver.py View on Github external
subdir = f'compute-{system.compute_number}'

        dirname = os.path.join(system.name, subdir)

        # Make a directory inside which OOMMF will be run.
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # Change directory to dirname
        with _changedir(dirname):
            # Generate the necessary filenames.
            miffilename = f'{system.name}.mif'
            jsonfilename = 'info.json'

            # Generate and save mif file.
            mif = oc.scripts.system_script(system)
            mif += oc.scripts.driver_script(self, system, compute=compute,
                                            **kwargs)
            with open(miffilename, 'w') as miffile:
                miffile.write(mif)

            # Generate and save json info file for a drive (not compute).
            if compute is None:
                info = {}
                info['drive_number'] = system.drive_number
                info['date'] = datetime.datetime.now().strftime('%Y-%m-%d')
                info['time'] = datetime.datetime.now().strftime('%H:%M:%S')
                info['driver'] = self.__class__.__name__
                info['args'] = kwargs
                with open(jsonfilename, 'w') as jsonfile:
                    jsonfile.write(json.dumps(info))
github ubermag / oommfc / oommfc / scripts / driver.py View on Github external
def driver_script(driver, system, compute=None, **kwargs):
    mif = ''
    if isinstance(driver, oc.MinDriver):
        # Check evolver and set default if not passed.
        if not hasattr(driver, 'evolver'):
            driver.evolver = oc.CGEvolver()
        elif not isinstance(driver.evolver, oc.CGEvolver):
            msg = f'Cannot use {type(driver.evolver)} for evolver.'
            raise TypeError(msg)

        # Define default stopping_mxHxm if not passed. OOMMF cannot run without
        # this value.
        if not hasattr(driver, 'stopping_mxHxm'):
            driver.stopping_mxHxm = 0.1

        mif += oc.scripts.evolver_script(driver.evolver)

        # Minimisation driver script.
        mif += '# MinDriver\n'
        mif += 'Specify Oxs_MinDriver {\n'
        mif += '  evolver :evolver\n'
        mif += '  mesh :mesh\n'
        mif += '  Ms :m0_norm\n'
        mif += '  m0 :m0\n'
        for attr, value in driver:
            if attr != 'evolver':
                mif += f'  {attr} {value}\n'
        mif += '}\n\n'

        # Saving results.
        mif += 'Destination table mmArchive\n'
        mif += 'Destination mags mmArchive\n\n'
github ubermag / oommfc / oommfc / scripts / mesh.py View on Github external
# generated and the main MultiAtlas.
        for name, subregion in mesh.subregions.items():
            mif += oc.scripts.box_atlas(subregion.pmin, subregion.pmax,
                                        name=name)
        mif += '# MultiAtlas\n'
        mif += 'Specify Oxs_MultiAtlas:main_atlas {\n'
        for name in mesh.subregions.keys():
            mif += f'  atlas :{name}_atlas\n'
        mif += f'  xrange {{ {mesh.region.pmin[0]} {mesh.region.pmax[0]} }}\n'
        mif += f'  yrange {{ {mesh.region.pmin[1]} {mesh.region.pmax[1]} }}\n'
        mif += f'  zrange {{ {mesh.region.pmin[2]} {mesh.region.pmax[2]} }}\n'
        mif += '}\n\n'
    else:
        # There are no subregions in the mesh and only a single BoxAtlas is
        # generated.
        mif += oc.scripts.box_atlas(mesh.region.pmin, mesh.region.pmax,
                                    name='main')

    # Define mesh.
    if any(i in mesh.bc for i in 'xyz'):
        mif += '# PeriodicRectangularMesh\n'
        mif += 'Specify Oxs_PeriodicRectangularMesh:mesh {\n'
        mif += '  cellsize {{ {} {} {} }}\n'.format(*mesh.cell)
        mif += '  atlas :main_atlas\n'
        mif += '  periodic {}\n'.format(''.join(sorted(mesh.bc)))
        mif += '}\n\n'
    else:
        mif += '# RectangularMesh\n'
        mif += 'Specify Oxs_RectangularMesh:mesh {\n'
        mif += '  cellsize {{ {} {} {} }}\n'.format(*mesh.cell)
        mif += '  atlas :main_atlas\n'
        mif += '}\n\n'
github ubermag / oommfc / oommfc / scripts / system.py View on Github external
def system_script(system, **kwargs):
    mif = '# MIF 2.2\n\n'
    # Output options
    mif += 'SetOptions {\n'
    mif += f'  basename {system.name}\n'
    mif += '  scalar_output_format %.12g\n'
    mif += '  scalar_field_output_format {text %#.15g}\n'
    mif += '  vector_field_output_format {text %#.15g}\n'
    mif += '}\n\n'

    # Mesh and energy scripts.
    mif += oc.scripts.mesh_script(system.m.mesh)
    mif += oc.scripts.energy_script(system)

    # Magnetisation script.
    m0mif, _, _ = oc.scripts.setup_m0(system.m, 'm0')
    mif += m0mif

    return mif
github ubermag / oommfc / oommfc / drivers / driver.py View on Github external
dirname = os.path.join(system.name, subdir)

        # Make a directory inside which OOMMF will be run.
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # Change directory to dirname
        with _changedir(dirname):
            # Generate the necessary filenames.
            miffilename = f'{system.name}.mif'
            jsonfilename = 'info.json'

            # Generate and save mif file.
            mif = oc.scripts.system_script(system)
            mif += oc.scripts.driver_script(self, system, compute=compute,
                                            **kwargs)
            with open(miffilename, 'w') as miffile:
                miffile.write(mif)

            # Generate and save json info file for a drive (not compute).
            if compute is None:
                info = {}
                info['drive_number'] = system.drive_number
                info['date'] = datetime.datetime.now().strftime('%Y-%m-%d')
                info['time'] = datetime.datetime.now().strftime('%H:%M:%S')
                info['driver'] = self.__class__.__name__
                info['args'] = kwargs
                with open(jsonfilename, 'w') as jsonfile:
                    jsonfile.write(json.dumps(info))

            # Get right OOMMF runner depending on whether there is DMI.