ubermag / help

Repository for raising issues and requesting help on Ubermag
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

The problem of time-dependent field and multiple identical energy terms #191

Closed code-whale closed 2 years ago

code-whale commented 2 years ago

Dear Ubemag Team, I want to realize the following functions: apply sinusoidal variation field in one specific region and uniform field in another region. Therefore, I wrote the following two codes:

    x, y, z = pos
    if -320e-9<x<-280e-9 and -20e-9<y<20e-9:
        return 0.2/mm.consts.mu0
    else:
        return 0
def H2_fun(pos):
    x, y, z = pos
    if -280e-9<x<400e-9:
        return 0.05/mm.consts.mu0
    else:
        return 0

H1 = df.Field(mesh, dim=3, value=(0,0,1), norm=H1_fun)
H2 = df.Field(mesh, dim=3, value=(0,0,1), norm=H2_fun)
system.energy = mm.Exchange(A=1e-11)+mm.DMI(D=2.5e-3,crystalclass='Cnv_z')+mm.Zeeman(H=H1,wave='sin', f=1e10, t0=0, name='zeeman1')+mm.Zeeman(H=H2, name='zeeman2')+mm.Demag()+mm.UniaxialAnisotropy(K=1.2e6,u=(0,0,1))

and

def t_func(t):
    omega = 2 * np.pi / 1e-9 
    return np.sin(omega*t)

system.energy = mm.Exchange(A=1e-11)+mm.DMI(D=2.5e-3,crystalclass='Cnv_z')+mm.Zeeman(H=H1,func=t_func, dt=1e-10)+mm.Zeeman(H=H2, name='zeeman2')+mm.Demag()+mm.UniaxialAnisotropy(K=1.2e6,u=(0,0,1))

However, they all reported errors. For the method of defining the time field, I refer to question #184 . I want to know whether there is an error in my input, or whether the function cannot be implemented in the current version. I will attach the detailed notebook in the attachment for your inspection. Thank you very much for your help! Merry Christmas to you! Best regards test.zip

lang-m commented 2 years ago

Hi @code-whale, thank you for providing detailed information. This is actually a bug in Ubermag. Your first attempt (cell 8) should work fine. [@marijanbeg We're ignoring the term.name when writing the df.Field Zeeman field (or any other field) to disk and end up reusing the same name twice.]

The second version (cell 9) is expected to fail as the new syntax will only be available with the next version of Ubermag.

marijanbeg commented 2 years ago

Well spotted @code-whale! Thank you very much.

code-whale commented 2 years ago

@lang-m @marijanbeg Thank you for your reply and thank you for your help. I will wait for this bug to be fixed and the next version of Ubermag.

lang-m commented 2 years ago

@code-whale This is fixed in version 0.61.0 which has just been released.