Skip to content
Discussion options

You must be logged in to vote

Hi!

This is definitely possible! You could do this in two different ways:

  1. Use numpy arrays of shape (3, nz, ny, nx). For example
import numpy as np
Bext = np.zeros(magnet.bias_magnetic_field.shape)
Bext[0, :, :, :] = 1          # x-comp is 1 everywhere
Bext[1, :, :, :nx//2] = 1   # y-comp is 1 in left half
Bext[1, :, :, nx//2:] = -1  # y-comp is -1 in right half
magnet.bias_magnetic_field = Bext
  1. Use a function which takes grid coordinates and returns a vector with 3 components. For example:
def my_Bext(x,y,z):
    return (x*y, 1, 2*z)
magnet.bias_magnetic_field = my_Bext

This is also explained in this tutorial for the case of magnetization setting. The methodology is the same, apart f…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lamoreel
Comment options

@lamoreel
Comment options

@MiroPol21
Comment options

Answer selected by ilateur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants