flaport / fdtd

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

Acoustic simulations? #17

Closed sofroniewn closed 3 years ago

sofroniewn commented 3 years ago

Hello, I know this package is for 3D electromagnetic simulations, but I was wondering what it would take for it to also be used for acoustic simulations (including in situations where the speed of sound was not constant). Would this be something of interest to you, or is it too far outside the scope of this package? My elementary reading suggests that it shouldn't be too hard to have equations also for sound propagation work in this framework, but curious what you think.

flaport commented 3 years ago

Hey @sofroniewn, although it seems that there should be a 1 to 1 mapping (at least in 2D), I don't consider myself to be an acoustics expert at all. Therefore, I cannot confidently implement and maintain this. I think the best way to handle acoustics with this framework would be to indeed find relations like (12.35)-(12.46) for 3D and use those as a 'translation layer' for this package, however I'm afraid I won't be of much more help than the reference you just linked to (which btw was used as a rough guide to make this library).

sofroniewn commented 3 years ago

Ok thanks for the consideration, that all makes sense. I might try the acoustic simulation in a fork of this repo when I find the time!!

flaport commented 3 years ago

Sounds good! Let me know if you get it working 🙂

youssefavx commented 2 years ago

Hey @sofroniewn have you managed to get something working or find an alternative to this? Searching for the same thing to experiment with strange reverb effects but I'm struggling to find acoustics libraries that can do this...especially as a total beginner to even this concept with no physics or math background.

sofroniewn commented 2 years ago

@youssefavx I ended up writing https://github.com/sofroniewn/waver - heavily inspired by the great work from @flaport, but with some slightly different API choices to make my life a little easier. It's definitely pretty rough - I don't think anyone else has used it apart from myself, and some of the boundary condition maths might need improvement. I'm not sure if it will allow you to do what you want, but feel free to poke around

youssefavx commented 2 years ago

@sofroniewn Oh wow! Thank you so much. I'll play around with it. What I basically want to do is the ability to import say a 3D model that's animated, for example a box (representing a room), with objects such as for example a musgrave texture modulating a volume's density:

https://imgur.com/a/aKvHH9d

With that volume also being modulated by different kinds of materials (more reflective of sound, or more absorbing) over time. And then have a sound source somewhere (such as an input audio file), and be able to record audio from different places and export it as audio.

Don't know if this would be possible with your library but perhaps in poking around I might get some ideas about how to bolt on some of the features I have in mind which may not be there.

sofroniewn commented 2 years ago

Don't know if this would be possible with your library but perhaps in poking around I might get some ideas about how to bolt on some of the features I have in mind which may not be there.

I'm not sure, good luck poking around!