"need to set mesh first" Error

150 views
Skip to first unread message

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 3:35:18 AM9/12/18
to mumax2
Dear all,
             I want to observe minimized enegy state for specific initial magnetization configuration in a specific structure (the picture is attached herewith). Even after setting proper grid size and cell size I am getting above mentioned error.
             The code is geven below. Kindly help me in this matter.

Code:

// The exchange length lex = {Aex/ (0.5*mu0*Msat^2)}^0.5
// In this model lex = 7.58 nm approx
// We are considering cell dimension 0.5nm X 0.5nm X 3nm

// Define gridsize & cellsize
SetGridSize(256, 256, 1)
SetCellSize(128e-09/256, 128e-09/256, 3e-09/1)

// Setting the key-value
key := 000

//Define geometry
edgesmooth = 10
L := 50e-09
W := 10e-09
struc1 := cuboid(L,W,3e-09).transl(L/2,0,0)
struc2 := cuboid(L,W,3e-09).transl(-L/2,-W/2,0).rotz(pi/3)
struc3 := cuboid(L,W,3e-09).transl(-L/2,W/2,0).rotz(-pi/3)
main_struc := struc1.add(struc2).add(struc3)
setgeom(main_struc)

//Define regions
defregion(1,struc1)
defregion(2,struc2)
defregion(3,struc3)
save(regions)

//Define Material parameters for Leg#1
Msat.setregion(1,800e3)                        // Saturation Magnetization in A/m
Ku1.setregion(1,1e05)                          // 1st order uniaxial anisotropy constant in J/m^3
Aex.setregion(1,1.3e-11)                       // Exchange stiffness in J/m^3
alpha.setregion(1,0.02)                        // Landau-Lifshitz damping constant
anisU.setregion(1,vector(1,0,0))

Define Material parameters for Leg#2
Msat.setregion(2,800e3)                        // Saturation Magnetization in A/m
Ku1.setregion(2,1e05)                          // 1st order uniaxial anisotropy constant in J/m^3
Aex.setregion(2,1.3e-11)                       // Exchange stiffness in J/m^3
alpha.setregion(2,0.02)                        // Landau-Lifshitz damping constant
anisU.setregion(2,vector(1,0,0))

Define Material parameter for Leg#3
Msat.setregion(3,800e3)                        // Saturation Magnetization in A/m
Ku1.setregion(3,1e05)                          // 1st order uniaxial anisotropy constant in J/m^3
Aex.setregion(3,1.3e-11)                       // Exchange stiffness in J/m^3
alpha.setregion(3,0.02)                        // Landau-Lifshitz damping constant
anisU.setregion(3,vector(1,0,0))

//Define Initial Reduced Magnetization
m1 := uniform(1,0,0)
m2 := uniform(cos((-2*pi)/3),sin((-2*pi)/3),0)
m3 := uniform(cos((2*pi)/3),sin((2*pi)/3),0)

// 0 is equivalent to -, towards vertex
// 1 is equivalent to +, away from the vertex
if key == 000 {
m.setregion(1,-m1)
m.setregion(2,-m2)
m.setregion(3,-m3)               
}

else if key == 001 {
m.setregion(1,-m1)
m.setregion(2,-m2)
m.setregion(3,m3)               
}

else if key == 010 {
m.setregion(1,-m1)
m.setregion(2,-m2)
m.setregion(3,-m3)               
}

else if key == 011 {
m.setregion(1,-m1)
m.setregion(2,m2)
m.setregion(3,m3)               
}

else if key == 100 {
m.setregion(1,m1)
m.setregion(2,-m2)
m.setregion(3,-m3)               
}

else if key == 101 {
m.setregion(1,m1)
m.setregion(2,-m2)
m.setregion(3,m3)               
}

else if key == 110 {
m.setregion(1,m1)
m.setregion(2,m2)
m.setregion(3,-m3)               
}

else key == 111 {
m.setregion(1,m1)
m.setregion(2,m2)
m.setregion(3,m3)               
}

relax()
saveas(m,"m_<k>",key)

Jeroen Mulkers

unread,
Sep 12, 2018, 4:00:57 AM9/12/18
to mum...@googlegroups.com
I do not get the error "need to set mesh first", but I do see some errors in your script.

1) Put 'else' directly after the closing brace of the if statement.

2) In the last case you have "else key==111". You should remove the condition or change it to an else if statement.

2) Putting a minus sign before a magnetization configuration is not allowed (e.g. -m1 will lead to an error).

--
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.
For more options, visit https://groups.google.com/d/optout.

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 4:45:28 AM9/12/18
to mumax2
Thanks for the reply. I have changed the code according to your suggestions. But I am still having the same problem. I do not understand  the source or nature of the error. I have attached the code below.


Code:
// The exchange length lex = {Aex/ (0.5*mu0*Msat^2)}^0.5
// In this model lex = 7.58 nm approx
// We are considering cell dimension 0.5nm X 0.5nm X 3nm

//Define gridsize & cellsize
// 0 is equivalent to -, towards vertex
// 1 is equivalent to +, away from the vertex
if key == 000 {
m.setregion(1,uniform(-1,0,0))
m.setregion(2,uniform(-cos((-2*pi)/3),-sin((-2*pi)/3),0))
m.setregion(3,uniform(-cos((2*pi)/3),-sin((2*pi)/3),0))               
}

else if key == 001 {
m.setregion(1,uniform(-1,0,0))
m.setregion(2,uniform(-cos((-2*pi)/3),-sin((-2*pi)/3),0))
m.setregion(3,uniform(cos((2*pi)/3),sin((2*pi)/3),0))               
}

else if key == 010 {
m.setregion(1,uniform(-1,0,0))
m.setregion(2,uniform(cos((-2*pi)/3),sin((-2*pi)/3),0))
m.setregion(3,uniform(-cos((2*pi)/3),-sin((2*pi)/3),0))               
}

else if key == 011 {
m.setregion(1,uniform(-1,0,0))
m.setregion(2,uniform(cos((-2*pi)/3),sin((-2*pi)/3),0))
m.setregion(3,uniform(cos((2*pi)/3),sin((2*pi)/3),0))               
}

else if key == 100 {
m.setregion(1,uniform(1,0,0))
m.setregion(2,uniform(-cos((-2*pi)/3),-sin((-2*pi)/3),0))
m.setregion(3,uniform(-cos((2*pi)/3),-sin((2*pi)/3),0))               
}

else if key == 101 {
m.setregion(1,uniform(1,0,0))
m.setregion(2,uniform(-cos((-2*pi)/3),-sin((-2*pi)/3),0))
m.setregion(3,uniform(cos((2*pi)/3),sin((2*pi)/3),0))               
}

else if key == 110 {
m.setregion(1,uniform(1,0,0))
m.setregion(2,uniform(cos((-2*pi)/3),sin((-2*pi)/3),0))
m.setregion(3,uniform(-cos((2*pi)/3),-sin((2*pi)/3),0))               
}

else if key == 111 {
m.setregion(1,uniform(1,0,0))
m.setregion(2,uniform(cos((-2*pi)/3),sin((-2*pi)/3),0))
m.setregion(3,uniform(cos((2*pi)/3),sin((2*pi)/3),0))               
}
else{
return 0}

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 4:49:08 AM9/12/18
to mumax2
I am using MuMax3.9.1 on Windows 10 Home machine. I have attached the snapshot of the error. Thanks in advance.

Jeroen Mulkers

unread,
Sep 12, 2018, 4:56:46 AM9/12/18
to mum...@googlegroups.com
Again, put 'else' directly after the closing brace of the if statement.
Furthermore, remove the last else block or change 'return 0' to 'exit()'

Do you get the "need to set mesh first" error if you use a more recent version (e.g. mumax3.10beta)?
https://github.com/mumax/3/releases

Alexander Schäffer

unread,
Sep 12, 2018, 5:11:22 AM9/12/18
to mumax2
Hi Anirban,
I also can't reproduce the Error you receive, maybe because of the more recent version I am using.
Anyway, I remember a problem I had some time ago, when I defined regions that were not disjunct. You should try to define them as

defregion(1,struc1.sub(struc2.add(struc3)));
defregion(2,struc2.sub(struc3));
defregion(3,struc3);

The "sub"-statement in region 2 might be redundant but it makes sure that no cell is associated with two different regions.

Best regards
Alex

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 5:51:56 AM9/12/18
to mumax2
Thanks for the help, I am using Windows 10 Home machine and I am not very familiar with installation from the source. I am using version 3.9.1.

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 5:57:27 AM9/12/18
to mumax2
Thanks. I have used the sub command to define disjunct regions.

Felipe Garcia

unread,
Sep 12, 2018, 7:34:03 AM9/12/18
to mumax2
Dear Anirban Mukhopadhyay,

I have the same issue when running in windows. It is because the formating of .txt in windows. Windows adds some characters that mumax3 interprets differently. The way to avoid it is to use a more unix-like editor in windows. This is kind of unix2dos problem. The character is in the first lines and will void the setting of the mesh. This is why when mumax try to execute something, the mesh is not defined yet and gives that error.

This is the reason why someone copying your file to unix systems and running it will have no problems. Some editors for windows show these characters.

Regards,
Felipe

Anirban Mukhopadhyay

unread,
Sep 12, 2018, 7:57:44 AM9/12/18
to mumax2
 Thanks, I have put the else directly after the closing braces of the statement. I could not figure out the source of the error but fortunately the code is working.

Anirban Mukhopadhyay

unread,
Sep 13, 2018, 3:50:13 AM9/13/18
to mumax2
Dear Felipe,
                   Thanks a lot for pointing out the reason of the error.

Anirban Mukhopadhyay

unread,
Sep 13, 2018, 6:34:52 AM9/13/18
to mumax2
Dear Felipe,
                   Could you kindly suggest me such unix like editor. I have already faced this error in sublime text and notepad++.
                   Thanks in advance.

On Wednesday, September 12, 2018 at 5:04:03 PM UTC+5:30, pkwgarcias wrote:

Felipe Garcia

unread,
Sep 13, 2018, 4:30:28 PM9/13/18
to mumax2
Dear Anirban,

Could you send me the .mx3 attached? I will see if it is the same problem and where is the character. Then, I will check and let you know.

Regards,
Felipe
Message has been deleted

jpla...@rams.colostate.edu

unread,
Sep 13, 2018, 9:16:38 PM9/13/18
to mumax2
Like Felipe said, it's when you run an .mx3 script windows, there is an issue with return characters.  It reads your entire file as one command. (If you're using the interactive GUI, it doesn't matter unless you try to copy/paste multiple lines).

A workaround i found is at the end of each line, you should add ";" (no quotes) .

I forget how i found it, but I believe it's because ; is interpreted as a linebreak in Golang. I don't think it required me to change any settings for anything.


I run on Windows 10, using notepad++. I got the exact same error using your code. If i add the ";" the mesh error is gone. You can also see what it reads in if you run the script with the GUI, the input box will show it reading everything as one big string.

I've attached an example .mx3 file that shows how to do so. (Note that some lines i put multiple commands, just for keeping things clean. nice side benefit of using ; . you do not need to do this ). You also need it for loops

It would probably be better to just use a unix editor and set it up properly, but i found this was easier. I have not tried them much, but i believe Sublime has this plug in 


Notepad++ you can change to unix under edit> EOL conversion, and to show endofline under view> show symbol (or just use replace, replacing \r\n with \n, making sure to check the extended box in bottom right. \r\n is the Windows newline default, \n is Unix )

The Notepad++ change alone didn't fix the issue, you might need to tinker a bit more, but at least you can see EOL characters
)
help.mx3

Anirban Mukhopadhyay

unread,
Sep 14, 2018, 5:41:44 AM9/14/18
to mumax2
Kindly find the attachement.

Thanks and regards,
Anirban Mukhopadhyay
ASI.mx3
Reply all
Reply to author
Forward
0 new messages