# Define a geometry region using 'for' loop in MuMax3

I was trying to define regions using a 'for' loop.

defregion(0, xrange(-1024e-9, -964e-9))
defregion(1, xrange(-964e-9, -844e-9))
defregion(2, xrange(-844e-9, -784e-9))
defregion(3, xrange(-784e-9, -664e-9))
defregion(4, xrange(-664e-9, -604e-9))
defregion(5, xrange(-604e-9, -484e-9))
...


Here, the periodicity is w1=60e-9, and w2=120e-9.

So I was trying to define the regions using a loop like in the following way:

    l=1024e-9
w1=60e-9
w2=120e-9

for i := 0; i <= 5; i+=2 {
defregion(i, xrange(-l+i*w2, -l+(i+1)*w1));
for j:=i+1; j<= 5; j+=1{
defregion(j, xrange(-l+j*w1, -l+(j+1)*w2))
}
}


In this case, the software forms the geometry only with the w1 value. The w2 value is not taken. However, the required geometry has not been formed.

Could anyone please let me know where I am wrong and how to solve this problem?

I have tried with the following solution (got it from the first answer!)

l=1024e-9
w1=60e-9
w2=120e-9

for i := 0; i <= 5; i+=2 {
defregion(i, xrange(-l+i*w2, -l+(i+1)*w1));
for j:=i+1; j<= 5; j+=1{
defregion(j, xrange(-l+j*w1, -l+(j+1)*w2))
}
}


And, the error looks like this:

• +1 but can you copy and paste that error message into a code block rather than uploading an image which won't load in browsers that have on-site images turned off for faster browsing? Aug 4 at 15:51

I have not used MuMax3 before, so I may be missing something, but I think you are overcomplicating things by trying to use a nested loop. It looks like you define a region in one loop and then redefine in another iteration, so its tough to reason out what values you will get.

Running the equivalent of your loops in Python, I get

0 (-1.024e-06, -9.64e-07)
1 (-9.64e-07, -7.84e-07)
2 (-7.84e-07, -8.440000000000001e-07)
3 (-8.440000000000001e-07, -5.440000000000001e-07)
4 (-5.440000000000001e-07, -7.240000000000001e-07)
5 (-7.240000000000001e-07, -3.040000000000002e-07)


I believe you could instead use a single loop to get the result you want.

l:=1024e-9
w1:=60e-9
w2:=120e-9

start:=0
stop:=0
swap:=0
for i := 0; i <= 5; i+=1 {
stop=stop+w1
defregion(i, xrange(-l+start, -l+stop));
swap=w1
w1=w2
w2=swap
start=start+w2
}


The start and stop store how much you should add to the initial value to get the next interval. At each iteration, w1 and w2 are swapped so that the beginning and end of each region increase by the correct amount, which alternates.

Initially, my answer used = everywhere rather than :=. It seems, based on the examples I could find on the MuMax3 page, that = is used to set options for the program or redefine existing variables while := is used for user created variable assignment.

• @ArindamSamanta Since its getting a little long here, I'm moving this discussion to chat
– Tyberius
Aug 4 at 17:01