flaport / fdtd

A 3D electromagnetic FDTD simulator written in Python with optional GPU support
https://fdtd.readthedocs.io
MIT License
454 stars 116 forks source link

Field in position of source #43

Open GenB31415 opened 2 years ago

GenB31415 commented 2 years ago

Hi @flaport, Happy New Year! At FDTD calculations I need to periodically change the power of a source (initially F_0) dependently on the local field amplitude E_0. So first I have to know the amplitude of field E0 in current position of a source in 3D. Latter I will modify the power of this source periodically as F{n+1} = f(E_n)*F_n with the interval dt. As I understand, to do that I have to periodically remove old source (n) from the grid and insert in this position new source (n+1). What is the optimal way to do all of that? Thank you in advance.

flaport commented 2 years ago

hey @GenB31415 ,

It's probably best to write a custom source for this. The grid to which the source is attached is available as self.grid, and hence you have access to the field values at the current time step.

To write a custom source you just have to an update_E and an update_H method (look for example at sources.py).

For example, you could do something like this:

class MyPointSource(PointSource):
    def update_E(self):
        E_n = self.grid.E[self.x, self.y, self.z, 2]
        E_n[:, :, :] = my_func(E_n) * En
GenB31415 commented 1 year ago

Hi @flaport, please specify the formula of spatial shape of the fdtd.LineSource. In the docs it is only indicated “""Create a LineSource with a gaussian profile. Does it mean \exp(-(x-x0)^2-(y-y0)^2-(z-z0)^2) ? Is it possible to indicate a width of a gaussian? Thanks

GenB31415 commented 1 year ago

May be it is better to replace the word LineSource by PlaneSource in the description of PlaneSource ?

PlaneSource class

class PlaneSource: """A source along a plane in the FDTD grid"""

def __init__(...)
    """Create a **_LineSource_** with a gaussian profile