converting COMSOL results into readable format for mumax3

2,099 views
Skip to first unread message

maha khademi

unread,
Mar 10, 2021, 11:36:59 AM3/10/21
to mumax2

Hi everyone,

I’ve done a simulation in COMSOL in order to find the Oersted field. Now I need to convert the result (Oersted field profile in a plane) into a format of which I can use as an input for mumax3. Can anyone help me on how to convert the COMSOL results into a readable format for mumax3 (such as OVF)? Generally, COMSOL lets you save files in these formats: text, VTK, STL binary file, STL text file, PLY binary file, PLY text file and 3MF files.

An example of an Oersted field saved as text file is attached here, the first three columns are the coordinates and the last one is the intensity of the field.

Thanks in advance

Oersted field example.txt

Felipe Garcia

unread,
Mar 15, 2021, 8:04:57 AM3/15/21
to mumax2
Hi Maha Khademi,

I think the easiest way is to construct an OVF file from your data. The format in text is simple. One has to run a script with your system dimensions. Then one has to keep the header and the footer of the generated file.

For example, if you run the following script
Nx:=128
Ny:=64

SetGridSize(Nx, Ny, 1)
SetCellSize(4e-9, 4e-9, 4e-9)
Msat = 1e6
Aex = 10e-12
alpha = 1
m = RandomMag()

OutputFormat = OVF2_TEXT

mask := newVectorMask(Nx, Ny, 1)

for i:=0; i<Nx; i++{
for j:=0; j<Ny; j++{
r := index2coord(i, j, 0)
x := r.X()
y := r.Y()
mask.setVector(i, j, 0, vector(x, y,0))
}
}

B_ext.add(mask,1)

save(B_ext)

Then if you take a look to B_ext000000.ovf. The header is everything before the vectorial data.
The header is
# OOMMF OVF 2.0
# Segment count: 1
# Begin: Segment
# Begin: Header
# Title: B_ext
# meshtype: rectangular
# meshunit: m
# xmin: 0
# ymin: 0
# zmin: 0
# xmax: 5.12e-07
# ymax: 2.56e-07
# zmax: 4e-09
# valuedim: 3
# valuelabels: B_ext_x B_ext_y B_ext_z
# valueunits: T T T
# Desc: Total simulation time:  0  s
# xbase: 2e-09
# ybase: 2e-09
# zbase: 2e-09
# xnodes: 128
# ynodes: 64
# znodes: 1
# xstepsize: 4e-09
# ystepsize: 4e-09
# zstepsize: 4e-09
# End: Header
# Begin: Data Text

The data part is the vector B_ext for each point of the grid. One can see that if the index are i, j, k, it starts increasing i and then j.

The footer is just:
# End: Data Text
# End: Segment

If you use your system geometry and save B_ext (this will produce the proper header for your case), I think you can easily adapt your file to ovf. After that one can load from file using B_ext.Add(LoadFile("comsol.ovf"),1) or replace 1 by a time dependent function.

Best regards,
Felipe


--
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/1ba9ae35-d476-4acf-a33d-f23bffbda5a8n%40googlegroups.com.

PRADEEP KUMAR ROUT

unread,
Jun 25, 2021, 6:38:07 AM6/25/21
to mumax2
Dear  Felipe,

Thanks a lot for the information. 
I have simulated a current density distribution for Ta layer for my geometry in COMSOL by considering the same geometry size I want to use in mumax.
The mesh I used in COMSOL is tetrahedral with a different size to the cuboidal mesh of mumax3. Then, could you please help me to understand, in this case how the COMSOL output could be feed into the mumax input having a different mesh type and size?

I thank you a lot for your help and assistance.

Best wishes
Pradeep

Felipe Garcia

unread,
Jun 25, 2021, 12:28:51 PM6/25/21
to mumax2
Dear Pradeep,

One can export the Data of Comsol using the option Grid or Regular grid. Using parameters compatible with your discretization one can obtain the desired output. One can use the same procedure to generate the geometry of mumax so that the geometries of mumax and Comsol match perfectly.

Best regards,
Felipe

Enlong Liu

unread,
Jun 29, 2021, 12:34:24 AM6/29/21
to mum...@googlegroups.com
Dear Felipe,

I also encountered similar problem as Pradeep. According to your reply, it is more clear how to do it. But I still have some questions.

1. In you previous reply to the others, you mentioned a way to introduce magnetic field generated by COMSOL, by making the field into ovf file with certain headlines and endlines, Does it work for current density files, i.e. creating new ovf file containing current density values for each mesh, or we need other file types? And the code in mumax to integrate current density might be different from B_ext.Add(LoadFile("comsol.ovf"),1)?

2. Is that possible to integrate mp distribution in SOT simulation using STT code? If current flowing the SOT channel has a distribution, so should mp. In OOMMF there is a certain way to introduce mp distribution. I just wonder if it can be done similarly in mumax.

Thanks a lot for your old reply and future help.

Best regards,
Enlong

Felipe Garcia <pkwga...@gmail.com> 于2021年6月26日周六 上午12:28写道:


--
Mobile Phone: +86-13703714338
Mailing Address: tbd

PRADEEP KUMAR ROUT

unread,
Jun 29, 2021, 6:06:10 AM6/29/21
to mumax2
Dear Felipe,

Thanks a lot for your quick response. Yes, I now understood how to export the COMSOL output. I just have one more quick question for you, if you may help me with this. I understood from your earlier response that we feed in the COMSOL output by writing the command J.Add(LoadFile("comsol.ovf"),1). Now if I have different regions in my geometry and if I want to set different current distributions in each region then how should I do it ? Normally just for a constant current value I use the command J.SetRegion(1, vector(0, 0, 1e10) and J.SetRegion(2, vector(0, 0, 5e10) etc. Then, could you please let me know then how to add different current distributions for different region in mumax ?

Also, do we have to generate the .ovf file for different regions separately? If so, could you suggest how to do that as well ? Suppose, I have five multilayers in z directions and each layer is defined as one region and I want to feed in different current distribution to each region. 

Thanks a lot for your help. 

Best wishes
Pradeep

Felipe Garcia

unread,
Jun 29, 2021, 11:59:26 AM6/29/21
to mumax2
Dear Enlong,

1) In both cases it is exactly the same procedure changing B_ext by J.

2)I think that in previous versions that was not possible. However, with the newest version one can also do FixedLayer.add(...)  and proceed the same way.

Best regards,
Felipe

Felipe Garcia

unread,
Jun 29, 2021, 12:08:06 PM6/29/21
to mumax2
Dear Pradeed,

This question is not totally clear to me. I think one can generate two current distribution files and merge them in mumax3. Or one can generate the common problem in comsol and load the final file in mumax.
To do this in mumax and as far as I understand, one can do the "add" operations several times. So one can do

J.Add(LoadFile("comsolregion1.ovf"),1)
J.Add(LoadFile("comsolregion2.ovf"),1)

Sorry, not 100% sure it works.  One has  to check that the final result is the desired one.

Best regards,
Felipe

Enlong Liu

unread,
Jun 29, 2021, 10:14:11 PM6/29/21
to mum...@googlegroups.com
Dear Felipe,

Many thanks, it really helps!

Best wishes

Felipe Garcia <pkwga...@gmail.com> 于2021年6月29日周二 下午11:59写道:

PRADEEP KUMAR ROUT

unread,
Aug 26, 2021, 5:22:06 AM8/26/21
to mumax2
Dear Felipe,

Understood. Thanks a lot.

Best wishes
Pradeep

ujjawal rathore

unread,
Oct 9, 2021, 2:22:39 AM10/9/21
to mumax2
Dear all,
I have converted the comsol current density profile data in .ovf file and successfully imported it into the mumax3. There is a linear relationship between current density and current applied. I now simulate current density for different current values and import all into mumax one by 1. But is there any way that gets only one current density profile for a particular value of current and imports into mumax then change the value of current in mumax, The current density values change accordingly. 
I really appreciate any help you can provide.

Josh Lauzier

unread,
Oct 14, 2021, 5:30:59 AM10/14/21
to mumax2
Hello,

If the current density profile is fairly simple, you should be able to recreate this using regions. Current density J has a J.setregions command.

For example, if your geometry was 2 cylinders, one could do something like

defregion(1,cylinder(10e-9,50e-9))
defregion(2,cylinder(5e-9,50e-9))

jtot:=10
J.setregion(1,vector(jot/10,0,0) )
J.setregion(2, vector(jot/5,0,0) )

This defines two cylinders, one with a diameter of 10nm and 50nm of length, and then a smaller one inside it with diameter 5nm and 50nm of length. It sets the current density for the outer at 1 A/m^2, and 2 A/m^2 for the inner region, both along the +x direction. Both are easily re-scaled by tweaking jtot (a throwaway variable for total current)

It will take you some time to correlate your ovf file to a corresponding regions, but you only need to do it once. unfortunately, I don't believe current density has a loadfile command, so you can't simply load J directly from the ovf. If your geometry is complicated and not amenable to using the built in shape commands like cylinder(), the j.ovf can very easily be converted (using an outside scripting language like python/matlab) into a regions.ovf which can be loaded using regions.loadfile() command. The formatting is nearly identical, except regions are scalars instead of vectors.

Best,
Josh Lauzier

Felipe Garcia

unread,
Oct 14, 2021, 6:12:32 AM10/14/21
to mumax2
Dear Ujjawal Rathore,

I think you uploaded the current ovt with something like
J.Add(LoadFile("current.ovf"), 1)
1 is a proportionality factor. If one uses instead
J.Add(LoadFile("current.ovf"), 2)
then one uses a double amount of current density. Using this parameter one can control the current values using one single current density file.

Best regards,
Felipe

ujjawal rathore

unread,
Oct 14, 2021, 9:09:16 AM10/14/21
to mumax2
Dear Felipe and Josh,
Felipe's suggestion is working.
Thanks for the help.

Regards,
Ujjawal Rathore

Joshua Lauzier

unread,
Oct 14, 2021, 5:20:39 PM10/14/21
to mumax2
Hello,

Felipe's way is much easier! Glad it works. I forgot there is a separate Loadfile command.

Cheers

Message has been deleted

PRADEEP KUMAR ROUT

unread,
Mar 17, 2022, 7:20:19 AM3/17/22
to mumax2
  Dear Felipe,

I tried to create an ovf file for current density as per your suggestion above, but unfortunately, I am getting error (panic:unknown header: # OOMMF OVF 2.0) while uploading it in mumax. Here I attach a screenshot of the error and the  Current ovf file as well. Could you please let me know how to solve this problem or where I am doing the mistake?

Thanks a lot.
Best wishes

On Monday, March 15, 2021 at 1:04:57 PM UTC+1 pkwgarcias wrote:
Screenshot (52).png

Felipe Garcia

unread,
Mar 18, 2022, 4:17:29 AM3/18/22
to mumax2
Dear Pradeep,

You have used a Windows text editor. The problem is that the format of mumax3 corresponds to Linux/Unix files. You have to convert them to that format. One can do this by installing dos2unix. This is included in cywgin (https://cygwin.com/), so a minimal installation including dos2unix is fine. Then you do in the cygwin console:
dos2unix J_150nm.ovf
And it should work.
 
Best regards,
Felipe

PRADEEP KUMAR ROUT

unread,
Mar 18, 2022, 6:34:01 AM3/18/22
to mumax2
Dear Felipe,

Many many thanks for the detailed clarification. Now, it works. 

Best wishes
Pradeep

Message has been deleted

YL M

unread,
Feb 26, 2023, 3:54:56 AM2/26/23
to mumax2
Hi, I'm just starting to study SHNO and I'm having some problems. Can anyone teach me how to model in COMSOL to get current and magnetic field distribution? In particular, is "electric field and magnetic field module" selected for simulation? In addition, which component is used for current injection? I would appreciate it if you could upload or send me a related mph file,It will be very important to me.(email: 20506...@qq.com 
Reply all
Reply to author
Forward
0 new messages