当前位置: 首页>>代码示例>>Python>>正文


Python Field.average方法代码示例

本文整理汇总了Python中field.Field.average方法的典型用法代码示例。如果您正苦于以下问题:Python Field.average方法的具体用法?Python Field.average怎么用?Python Field.average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在field.Field的用法示例。


在下文中一共展示了Field.average方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Sim

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import average [as 别名]
class Sim(object):
    def __init__(self, mesh, Ms, name=None):
        self.mesh = mesh
        self.atlas = mesh.atlas
        self.Ms = Ms
        self.name = name

        self.energies = []

        # Set default alpha value.
        self.alpha = 1

        self.dirname = self.name + '/'
        if not os.path.exists(self.dirname):
            os.makedirs(self.dirname)
        self.mif_filename = self.dirname + self.name + '.mif'

        self.m =  Field(self.atlas.cmin, self.atlas.cmax, self.mesh.d, dim=3)

        self.t = 0

    def add(self, energy):
        self.energies.append(energy)

    def set_H(self, H):
        for energy in self.energies:
            if isinstance(energy, FixedZeeman):
                self.energies.remove(energy)
        zeeman = FixedZeeman(H)
        self.add(zeeman)

    def run_until(self, stopping_time, stages=1):
        self.m.write_oommf_file(self.dirname + 'm0file.omf')
        self.m0 = 'm0file.omf'

        self.evolver = RungeKuttaEvolve(self.alpha)
        self.driver = TimeDriver('evolver', stopping_time/stages, stages,
                                 'mesh', self.Ms, self.m0, basename=self.name)
        self.relaxation = False
        self.execute_mif()
        self.t += stopping_time

    def m_average(self):
        return self.m.average()

    def relax(self, stopping_mxHxm=0.01):
        self.m.write_oommf_file(self.dirname + 'm0file.omf')
        self.m0 = 'm0file.omf'

        self.evolver = CGEvolve()
        self.driver = MinDriver('evolver', stopping_mxHxm, 'mesh',
                                self.Ms, self.m0, basename=self.name)
        self.relaxation = True
        self.execute_mif()

    def set_m(self, m0):
        if isinstance(m0, (list, tuple)):
            self.m.set(m0)
        elif isinstance(m0, str):
            self.m = load_oommf_file(m0)
        elif hasattr(m0, '__call__'):
            self.m.set(m0)
        elif isinstance(m0, Field):
            self.m = m0
            self.m.write_oommf_file(self.dirname + 'm0file.omf')
        else:
            raise ValueError('m0 type invalid.')

    def get_mif(self):
        mif = '# MIF 2.1\n\n'
        mif += self.atlas.get_mif()
        mif += self.mesh.get_mif()
        for i in self.energies:
            mif += i.get_mif()
        mif += self.evolver.get_mif()
        mif += self.driver.get_mif()
        mif += 'Destination table mmArchive\n'
        mif += 'Destination mags mmArchive\n\n'
        mif += 'Schedule DataTable table Stage 1\n'
        if self.relaxation:
            mif += 'Schedule Oxs_MinDriver::Spin mags Stage 1'
        else:
            mif += 'Schedule Oxs_TimeDriver::Spin mags Stage 1'

        return mif

    def create_mif(self):
        miffile = open(self.mif_filename, 'w')
        miffile.write(self.get_mif())
        miffile.close()

    def last_omf_file(self):
        newest_omf = max(glob.iglob(self.dirname+'*.omf'), key=os.path.getctime)
        return newest_omf

    def last_odt_file(self):
        newest_odt = max(glob.iglob(self.dirname+'*.odt'), key=os.path.getctime)
        return newest_odt

    def update_self(self):
#.........这里部分代码省略.........
开发者ID:fangohr,项目名称:oommf-python,代码行数:103,代码来源:sim.py


注:本文中的field.Field.average方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。