Non-analytical time-dependent excitation

546 views
Skip to first unread message

Silvia Casulleras

unread,
Jun 30, 2021, 8:50:45 AM6/30/21
to mumax2
Dear all,

I would like to implement in my simulation a time-dependent excitation field for which I don't have an analytical expression. I only know the values of the field evaluated at a discrete set of times (calculated externally). I would like to do something similar to:
B_ext.Add(Bfield, f(t)),
where Bfield is a known spatial profile of the field and f(t) is the time-dependent function evaluated at each time step.

Is there a way to implement such a field? Could I import the scalar function f(t) from a file?

Thank you very much in advance.
Best regards,
Silvia Casulleras

jpla...@rams.colostate.edu

unread,
Jun 30, 2021, 4:49:24 PM6/30/21
to mumax2
Hello,

If Bfield is a known spatial profile, you should be able to easily construct an OVF file for it in other software (like python). The format for an OVF file is fairly straightforward- it is basically a header, then the field strength at each point. If the index are i, j, k, it starts increasing i and then j. (I recommend running a test file, and saving some toy model field, and you will be able to reverse the format quickly). You'll want to be careful to try to match the meshsize/system size and everything.

Once you have the OVF files, you can load them using B_ext.Add(LoadFile("antenna.ovf"),f(t) )

The f(t) is a bit trickier. If it is a simple analytic function, you can just plug it in, and it will be evaluated at each time step, as the above sin example. No extra work needed.

If you want it imported from a file, that can be done, although I think perhaps a bit trickier. I can think of a few ways to do so.

The first thing that comes to mind is to load the points of f(t) into an array, and then use a for-loop to step through each time step. It is pretty straightforward to do something like load a textfile in golang, even if it's not built into mumax directly. I don't think mumax's Loadfile method works directly with scalars- it is a Slice object. Although you could probably do some workaround things by making it a fake ovf format, but having the scalar embedded in the OVF. 

You can also construct the mx3 file itself programmatically using say, python. The jupyter notebook from the mumax workshop gives some examples of how to do this. Using python you can easily pipe in variables without the hassle of golang.

They are a bit messy, perhaps someone knows a better way. Out of the above, the python is probably easiest/most straightforward. Or generate it inside the mumax file directly. It depends on the form of f(t).

Best,
Josh L.

Joo-Von Kim

unread,
Jul 1, 2021, 4:37:00 AM7/1/21
to mumax2
Dear Silvia,

We looked at something similar recently in the context of delayed-feedback dynamics of magnetic domain walls in a strip:
There, we used the domain wall position around a pinning site as a feedback signal to modulate the current-driven dynamics.

In essence, you need to construct an interpolation function based on the input points you have for f [i.e., f(t_i)], so that the time integrator can evaluate this quantity at arbitrary times. 

This is probably best done in golang in the interest of speed; there are a number of interpolation packages out there that can be used if you don't want to write your own code. The custom field amplitude f(t) can then be defined based on your input data (imported from a file, for example) using interpolation, along with the spatial field mask in OVF format as usual.

As an aside, I recall that interpolation functions were constructed systematically in MuMax2 (which used a Python interface) even for simple analytic functions. 

Best wishes,
Joo-Von

Silvia Casulleras

unread,
Jul 2, 2021, 5:29:08 AM7/2/21
to mumax2
Dear Josh and Joo-Von,

Thank you very much for your replies. I have implemented it using an interpolation function as you suggested. I used python to generate the script with a for loop that evaluates the function at every time step.

Best regards,
Silvia Casulleras

El dia dijous, 1 de juliol de 2021 a les 10:37:00 UTC+2, Joo-Von Kim va escriure:

Charu Singh

unread,
Nov 25, 2021, 5:49:34 AM11/25/21
to mumax2
Hello all,
I need help. How can I put a magnetic field in step for a single time.

I want to see the change of magnetization wrt time.
Thankyou all...

Nasir Mehmood

unread,
Nov 25, 2021, 8:51:25 PM11/25/21
to mum...@googlegroups.com
Hello!
Simply set the field value and run() in steps.

b_ext= vector(x1, y1, z1)
run(t1)
save(m)

b_ext= vector(x2, y2, z2)
run(t2)
save(m)

b_ext= vector(x3, y3, z3)
run(t3)
save(m)

and so on...
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mumax2/eb11dc95-08d2-44c5-8a88-0a223e9ad57dn%40googlegroups.com.


--
Dr. Nasir Mehmood
Post Doc Researcher
Lanzhou University, GS, PRC

Amrit Kumar Mondal

unread,
Jun 12, 2025, 12:02:37 PMJun 12
to mumax2
Hi everyone,
I’m having trouble understanding how to load a .csv file (https://mumax.github.io/api.html#) in my MuMax3 code. Could someone please help me with this?

I have attached both my code and the .csv file for reference.

for i:=1; i<=500; i=i+1{

B_ext.Add(LoadFile("field_vs_step_muMax.csv"))
minimize()
tablesave()
}



Thank you in advance!

field_vs_step_muMax.csv

Антон Луценко

unread,
Jun 12, 2025, 5:13:27 PMJun 12
to mumax2
Hi,
LoadFile usually works with .ovf files, not .csv. There's a few examples on this forum. Also, in your code you use .Add() every time – that would be adding all of the loaded fields together. Is it desired behaviour? If not, you might want to RemoveExtraTerms() within your loop.
The only function which is now documented to work with .csv files is FunctionFromDatafile – though from your code, LoadFile seems to be more fitting.

Amrit Kumar Mondal

unread,
Jun 12, 2025, 8:20:21 PMJun 12
to mum...@googlegroups.com
Hi,
Thank you for your help.
Unfortunately, I’m still having trouble understanding what exactly needs to be done and how to do it. I’ve modified the code as shown below, but I’m still encountering an error (attached image).

SetGridsize(128, 32, 1)
SetCellsize(500e-9/128, 125e-9/32, 3e-9)
Msat  = 800e3
Aex   = 13e-12
alpha = 0.02
m = uniform(1, 0, 0)
relax()
save(m)  // Save relaxed state

// Load B-field values from CSV column 0
Bvals := FunctionFromDatafile("field_vs_step_muMax.csv", 0, 1, "linear")
for i := 0; i < TableLen(Bvals); i++ {
    B := TableValue(Bvals, i)
    B_ext = vector(B, 0, 0)   // Apply new external field in x-direction

    minimize()
    tablesave()               // Save energy, m, etc. to table
    save(m)                   // Optionally save m magnetization state
}



------------------------------------------------------------------------------------------------------------
Best regards,
Amrit



--
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 visit https://groups.google.com/d/msgid/mumax2/c65207c2-ac4b-4b58-b1fd-93cd400ac54an%40googlegroups.com.
custom_error_t1.png

Jonathan Maes

unread,
Jun 13, 2025, 7:43:34 AMJun 13
to mumax2
Dear Amrit,

FunctionFromDataFile is a new function in mumax3.11, but you seem to be using 3.10. Hence, you should download an updated mumax³ executable from the download page.

FunctionFromDataFile loads two columns of a csv file, say "a" and "b", as a continuous function a(b). Since you seem to be implementing a discrete function B(step), I understand why you want to use TableLen and TableValue. However, those are not valid mumax³ functions, so I assume you will have to hard-code the number of rows in the .csv file as a value "N". You can then use the function as follows:

Bvals := FunctionFromDatafile("field_vs_step_muMax.csv", 0, 1, "linear")
for i := 0; i < N; i++ {
    B_ext = vector(Bvals(i), 0, 0)   // Apply new external field in x-direction
    // Do other things in the for loop, like minimize()...
}


Best regards,
Jonathan
Op vrijdag 13 juni 2025 om 02:20:21 UTC+2 schreef amritphy...@gmail.com:

Amrit Kumar Mondal

unread,
Jun 13, 2025, 10:56:41 AMJun 13
to mum...@googlegroups.com
Hi Jonathan,

Thank you very much for your assistance and for informing me about the need to update to the latest version of MuMax3.

You were absolutely right —  FunctionFromDataFile is indeed a new function introduced in MuMax3.11, and it's now working properly on my computer.



Best regards,
Amrit

-------------------------------------------------------------------

Dr. Amrit Kumar Mondal
Postdoctoral Fellow
Department of Physics and Astronomy 
University of Delaware
Newark, DE 19716


Reply all
Reply to author
Forward
0 new messages