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

Simulation of metals (complex refractive index) #62

Closed hajanssen closed 7 months ago

hajanssen commented 1 year ago

Hello,

i love this package and use it regularly, but now I encounter an error. i want to simulate a metal cylinder, to my knowledge this shut be done by using a complex refractive index. Has anyone tried this? I get a type error because by default not everything has a complex type(probably more efficient, when not needed).

[/usr/local/lib/python3.10/dist-packages/fdtd/grid.py](https://localhost:8080/#) in step(self)
    269         updating the magnetic field
    270         """
--> 271         self.update_E()
    272         self.update_H()
    273         self.time_steps_passed += 1

[/usr/local/lib/python3.10/dist-packages/fdtd/grid.py](https://localhost:8080/#) in update_E(self)
    285         # update objects
    286         for obj in self.objects:
--> 287             obj.update_E(curl)
    288 
    289         # update boundaries: step 2

[/usr/local/lib/python3.10/dist-packages/fdtd/objects.py](https://localhost:8080/#) in update_E(self, curl_H)
    119         """
    120         loc = (self.x, self.y, self.z)
--> 121         self.grid.E[loc] += (
    122             self.grid.courant_number * self.inverse_permittivity * curl_H[loc]
    123         )

UFuncTypeError: Cannot cast ufunc 'add' output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'

What would be a good way of making this work?

Have a good day. Hauke

flaport commented 1 year ago

complex permittivities/fields are currently not supported. I would be happy to accept a PR for this though... 😉

alternatively, if all you want is a perfect metal region, you could also artificially set the fields to zero within that region...

hajanssen commented 1 year ago

Alright thanks for the info :) I might try to make it work, i will get back to you if I got something.

flaport commented 7 months ago

closing this for now as it's not really on the roadmap. I'm still accepting PRs for this though.