Float to scalar conversion

164 views
Skip to first unread message

Apu Kumar Jana

unread,
Jun 3, 2022, 3:58:14 AM6/3/22
to mum...@googlegroups.com
Hi all,
I want to multiply B with the mx = m.comp(0). I am attaching the code below:

for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B*m.Comp(0), 0, 0)
    print(m.comp(0))
    minimize()   // small changes best minimized by minimize()
    tablesave()
}

 The error is always:  "type mismatch: can not use type engine.ScalarField as float64"

I have used Mul also but the same error as output. 
Please let me know how I can resolve this issue. Or else If I can convert the float (m.Comp(0)) to a scalar, I can use this. Please advise me how to do it.

Thanks in advance.
Regards
Apu Kumar Jana


Disclaimer:- This footer text is to convey that this email is sent by one of the users of IITH. So, do not mark it as SPAM.

Josh Lauzier

unread,
Jun 3, 2022, 5:00:42 AM6/3/22
to mumax2
Hello,

m.comp(0) gives you the x component of m for each cell. So if m is a LxMxN array of 3-component vectors, m.comp(0) is an LxMxN array of 1 component vectors/scalars (just the x component).

If you want just the average, you want something like "m.comp(0).average()".

It's a bit confusing, if you try "print(m.comp(0))", it does the averaging implicitly for you, so really it's doing "print(m.comp(0).average())" to the command line instead. But you can see the full details if you "save(m.comp(0))".



Best,
Josh L.

Apu Kumar Jana

unread,
Jun 3, 2022, 5:43:51 AM6/3/22
to mum...@googlegroups.com
Thanks Josh L for your help.
Now it is working fine. 
But it seems that the initial value of the "m.Comp(0).average" is being multiplied for each loop. I want to update the m.Comp(0).average() value at the end of the loop and want to be multiplied in the next loop.
Can you please suggest me what is the procedure to do this?

Thanks in advance.

Regards
Apu Kumar Jana
--
You received this message because you are subscribed to the Google Groups "mumax2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mumax2+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mumax2/f2eb622d-1e8e-490c-b280-ec0ca76c7ad2n%40googlegroups.com.

Josh Lauzier

unread,
Jun 3, 2022, 7:17:29 AM6/3/22
to mumax2
Can you post your full code?

It should update as is, with the way you posted it.

However, I suspect what is happening is that it is updating properly, however, you need to consider your loop

for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B*m.Comp(0), 0, 0)
    print(m.comp(0))
    minimize()   // small changes best minimized by minimize()
    tablesave()
}

For this particular choice, B*m.comp(0) will continously converge to 0 for each step

In the first step, B=0. and m_x will average to ~0 (assuming you used a random configuration to begin with). So B*m.comp(0)=0*0. So it goes to the next step. However, in the next step, B=bstep, but B*m.comp(0) is still ~0, because m_x is still ~0. It wil forever be stuck at 0, because m_x will never break away since you're always applying ~0 field. It may not be exactly 0, there will be some slight fluctuation due to numerical noise etc, but essentially still 0.

Your field is not well defined, in some sense. If you start at 0 for both B and m, B*m_x will sit around 0. Your external field is kind of like trying to do an MvsH loop, but H is just proportional to M, so MvsM, as if the magnet is trying to magnetize itself. Which if you start from 0, of course will just stay at 0 in a demagnetized state. If you start the hysteresis loop like


for B:=Bmax; B<=-Bmax; B-=Bstep{

    B_ext = vector(B*m.Comp(0), 0, 0)
    print(m.comp(0))
    minimize()   // small changes best minimized by minimize()
    tablesave()
}

It will work differently.

Cheers,
Josh L.


Apu Kumar Jana

unread,
Jun 3, 2022, 7:53:54 AM6/3/22
to mum...@googlegroups.com
Thanks Josh L.  a lot.
Yes, I was using the same code as in the example file "Hysteresis ", where the initial m is the random state. If I change to a uniform initial state it is keep on updating. 

Thank you.
The code is here for your information.

SetGridsize(128, 32, 1)
SetCellsize(4e-9, 4e-9, 30e-9)

Msat  = 800e3
Aex   = 13e-12

m = uniform(1, 1, 0)
relax()         // high-energy states best minimized by relax()


Bmax  := 1000.0e-3
Bstep :=  10.0e-3
MinimizerStop = 1e-6

TableAdd(B_ext)
y := m.comp(1).average()
TableAddVar(y, "y", "ymomemt")


for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B*y, 0, 0)

    minimize()   // small changes best minimized by minimize()
    tablesave()
}
Reply all
Reply to author
Forward
0 new messages