本文整理汇总了Python中fidimag.atomistic.Sim.compute_energy方法的典型用法代码示例。如果您正苦于以下问题:Python Sim.compute_energy方法的具体用法?Python Sim.compute_energy怎么用?Python Sim.compute_energy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fidimag.atomistic.Sim
的用法示例。
在下文中一共展示了Sim.compute_energy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hexagonal_demags_2D
# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import compute_energy [as 别名]
def test_hexagonal_demags_2D():
"""
Comparison of the FFT approach for hexagonal meshes, named
DemagHexagonal, where it is used a system with the double number
of nodes along the x direction (i.e. a mesh with twice the number
of nodes of the original mesh), against the full calculation
of the Demag field
"""
# Number of atoms
N = 15
a = 0.4
mesh = HexagonalMesh(a * 0.5, N, N,
unit_length=1e-9,
alignment='square')
# Centre
xc = (mesh.Lx * 0.5)
yc = (mesh.Ly * 0.5)
mu_s = 2 * const.mu_B
sim = Sim(mesh)
sim.mu_s = mu_s
sim.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))
# Brute force demag calculation
sim.add(DemagFull())
sim.get_interaction('demag_full').compute_field()
sim.get_interaction('demag_full').field
demag_full_energy = sim.compute_energy() / const.meV
# Demag using the FFT approach and a larger mesh
sim2 = Sim(mesh)
sim2.mu_s = mu_s
sim2.set_m(lambda pos: m_init_2Dvortex(pos, (xc, yc)))
sim2.add(DemagHexagonal())
sim2.get_interaction('demag_hex').compute_field()
sim2.compute_energy()
demag_2fft_energy = sim2.compute_energy() / const.meV
# We compare both energies scaled in meV
assert (demag_full_energy - demag_2fft_energy) < 1e-10
示例2: test_cuboid_demags_1Dchain
# 需要导入模块: from fidimag.atomistic import Sim [as 别名]
# 或者: from fidimag.atomistic.Sim import compute_energy [as 别名]
def test_cuboid_demags_1Dchain():
"""
Test a brute force calculation of the demagnetising field, called
DemagFull, based on the sum of the dipolar contributions of the whole
system for every lattice site, against the default FFT approach for the
demag field. We compute the energies scaled in meV.
This test is performed in a cuboid mesh to assure that the DemagFull
library is calculating the same than the default demag function
"""
N = 12
a = 0.4
mesh = CuboidMesh(a, a, a, N, 1, 1, unit_length=1e-9)
mu_s = 2 * const.mu_B
sim = Sim(mesh)
sim.mu_s = mu_s
sim.set_m(lambda pos: m_init_dw(pos, N, a))
# Brute force demag calculation
sim.add(DemagFull())
sim.get_interaction('demag_full').compute_field()
# print sim.get_interaction('demag_full').field
demag_full_energy = sim.compute_energy() / const.meV
# Demag using the FFT approach
sim2 = Sim(mesh)
sim2.mu_s = mu_s
sim2.set_m(lambda pos: m_init_dw(pos, N, a))
sim2.add(Demag())
sim2.get_interaction('demag').compute_field()
sim2.compute_energy()
demag_fft_energy = sim2.compute_energy() / const.meV
# We compare both energies scaled in meV
assert (demag_full_energy - demag_fft_energy) < 1e-10