emsig/emg3d

Generalize `get_source_field` for arbitrarily shaped sources

prisae opened this issue · 0 comments

The function get_source_field returns the field for a dipole source. Source fields can be summed up to yield arbitrary sources, e.g. a square loop (hence providing a 'magnetic' source). An example of this is given in the example magnetic_source_el_loop in the gallery:

# Initiate a zero-valued source field.
sfield = emg3d.fields.SourceField(pgrid, freq=freq)

# Define the four dipole segments.
srcloop = [
    np.r_[src[0]-0.5, src[0]+0.5, src[1]-0.5, src[1]-0.5, src[2], src[2]],
    np.r_[src[0]+0.5, src[0]+0.5, src[1]-0.5, src[1]+0.5, src[2], src[2]],
    np.r_[src[0]+0.5, src[0]-0.5, src[1]+0.5, src[1]+0.5, src[2], src[2]],
    np.r_[src[0]-0.5, src[0]-0.5, src[1]+0.5, src[1]-0.5, src[2], src[2]],
]

# Add the source fields up.
for srcl in srcloop:
    sfield += emg3d.fields.get_source_field(pgrid, srcl, freq, strength)

The function get_source_field should be extended to do this in one call, get_source_field(grid, src, freq, strength), where each parameter in the tuple src=(x0, x1, y0, y1, z0, z1) will be an array instead of a float.