• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Arbitrary Shape Room Mode Simulator

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
This opening post is to show how to simulate room modes using Mathematica. The other room mode calculators I could find on the web can only handle rectangular box shaped rooms. Mathematica can solve for arbitrarily shaped room. I only attempted 2D, but theoretically Mathematica should be able to compute 3D too. I'll leave that for the ASR high achievers :D

Mathematica comes free with Raspberry Pi (Raspbian). I don't have a Pi with me so I haven't tested my notebook on a Pi. This example notebook took several seconds to run on my i7-10750H laptop, with the vast majority of it on generating the plots. I am guessing it wouldn't be too bad on a Pi. I'd love to have some feedback if any of you try it on a Pi. I'd recommend running it on one of the models with larger amounts of RAM.

A brief look at the those few (7) lines of code (looks so simple, isn't it ;)):

room mode code.PNG

  1. 'c' is the speed of sound.
  2. 'Ω' is the domain, which in this case is the room. It is a polygon defined by its vertices. I used 8 vertices in the example. (Rectangular room with 2 corners taken out.)
  3. Show us the room we are simulating.
  4. This line does all the computations. It numerically computes the eigenvalues (related to room mode frequencies) and eigenfunctions (room mode shapes). In this example I specified solving for the first 20 modes.
  5. The returned eigenvalues λ are the square of the acoustic wavenumbers. This line convert them into frequencies in Hz.
  6. The last two statements are to display the results. The first set of figures shows the mode shape in 3D. The second set shows the contour plots from top so the mode peak locations are easier to see. The reds and greens are locations when the effects of the mode are strong. The white areas are where it is unaffected the nulls.
The number at the top of each plot is the mode frequency in Hz. The first mode is the trivial solution at basically 0 Hz and can be ignored. The outputs are below.

room mode 1.PNG room mode 2.PNG room mode 3.PNG
 

Attachments

  • Room Mode Simulator 2D v2021-02-27-1.zip
    1.4 KB · Views: 254
Last edited:
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
I compared my results with the web calculator from AMcoustics.
https://amcoustics.com/tools/amroc?l=400&w=400&h=400&r60=0.6

The AMcoustics room mode calculator calculates for box shaped room. I simulated a 4m X 4m X 4m room with it, and compare to my 2D results. Here are the outputs from AMcoustics and from my simulator.

amacoustics.PNG verification 1.PNG

Since my 2D simulator doesn't have the z-dimension, it won't simulate the oblique modes nor ones that have a '1' in the z-direction. But you can see that both gave frequencies of 42.88 Hz for the 1-0-0 and 0-1-0 axial modes. Both also gave 60.63 Hz for the 1-1-0 tangential mode. As you go down the list of the room mode frequencies (those that apply), you can see pretty much perfect agreement :)
 
Last edited:

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
I hadn't realised how big the wolfram-engine package for raspbian is - 617MB!

Evaluating the notebook took long enough for me to decide to have a look in top and see that it's only using one core, but only just - so it's not excessively slow. That's a 4GB Pi 4. Unsurprisingly the results look like your screenshots.
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
Thank you very much for the feedback :)

When Wolfram first released Mathematica 12, they didn't optimize the BLAS (Basic Linear Algebra Subprograms) library for the Cortex A72 in Pi 4. Solving linear systems was actually slower on 4 than on 3B+ (Wolfram blog, see the comments). That was in July 2019. I don't know if they had sped things up in their latest 12.1 release.

Mathematica is an extremely powerful and complete system, and has the steep learning curve to match. It comes with its well known symbolic math solver, image processing/recognition system, finite element (FEM) solver, and include full functionalities for signal processing and control systems analysis and design. I'd consider 600+ MB is pretty small IMHO. My old Windows release 11 is almost 3 GB.
 

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
It's also all in one package, whereas something like Octave gets split into smaller packages and external libraries so the size isn't so apparent. It's moved on somewhat since I last touched it in the early '90s.
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
... but theoretically Mathematica should be able to compute 3D too. I'll leave that for the ASR high achievers :D
OK, nobody took my bait. So I guess I'll do it. Here is a full-on 3D arbitrary shape room mode simulation.

Much thanks to @pierre for letting me know of the free (at this time) Wolfram engine. I want this to be an economical experiment for those who want to try. One of the reasons for me for not attempting 3D initially was that running 3D simulations on a Raspberry Pi is quite impractical. You'll need a great deal of patience. My estimate is that a Pi 4B (WolframMark ~0.18) is on the average ~15 times slower than my i7-10750H laptop (WolframMark 3.16).

The Jupyter notebook and the PDF printout (divided into 2 files due to size) is attached. I start with a very quick summary of the theory.

fig1.PNG


To start, I clear all existing variable definitions. Then get the speed of sound from the standard atmosphere data which is included with Wolfram (340.29 m/s).

fig2.PNG


The example room is a cabin style house with a loft. It is built using 3D solid primatives: Cuboid, prism, and hexahedron.

fig3.PNG


These solid primatives are joined together to form the interior space of the room.

fig4.PNG


The interior space is converted into a finite element mesh (48207 cells in this example).

fig5.PNG


Compute the first 20 room modes. The first mode is 0 Hz and is discarded. For the math geeks, this says that the Laplacian matrix is singular, as we have an eigenvalue of 0. The computation took 38.4 seconds on my laptop. The mode frequencies are listed. Since the room geometry is a pretty complicated, there are lot of room modes.

fig6.PNG


Generating the 3D plots can actually required more computations than solving them problem. In this case I made a 3D density plot of mode #12, and it took 316.6 seconds!

fig7.PNG


The returned plot is a 3D graphics object. Wolfram does not support interactive graphics on Jupyter notebooks, so I generated multiple views of it.

fig8.PNG


Other types of plots require much less CPU time. Here are 2 examples of density plots of sliced surfaces.

fig9.PNG


fig10.PNG


[Edit] Updated the ZIP file: I forgot to include the PNG files I used for explaining how I build the solid model. They are added to the ZIP archive. I also included the Mathematica notebook version. I used slightly different options in the Mathematica notebook, and commented out the lines for the 3D density plot.
 

Attachments

  • Room Mode Simulator 3D pages 1-2.pdf
    926.9 KB · Views: 208
  • Room Mode Simulator 3D pages 3-5.pdf
    654.7 KB · Views: 204
  • Room Mode Simulator 3D.zip
    63.7 KB · Views: 174
Last edited:

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
I thought I'd give it a quick run on the Pi 4 just to see how long it would take, but I'm missing a step.
Code:
sudo apt install jupyter
is enough to get the notebook interface, but I'm missing the step to get the Wolfram kernel. Not sure if I just haven't spotted the right package, or if it needs installing manually. I'll have to have a more careful look later. It's got me intrigued about the possibility of generating the mesh, and possibly presenting the results, via FreeCAD's FEA interface.
 

pierre

Addicted to Fun and Learning
Forum Donor
Joined
Jul 1, 2017
Messages
962
Likes
3,045
Location
Switzerland
I thought I'd give it a quick run on the Pi 4 just to see how long it would take, but I'm missing a step.
Code:
sudo apt install jupyter
is enough to get the notebook interface, but I'm missing the step to get the Wolfram kernel. Not sure if I just haven't spotted the right package, or if it needs installing manually. I'll have to have a more careful look later. It's got me intrigued about the possibility of generating the mesh, and possibly presenting the results, via FreeCAD's FEA interface.

You are missing a few steps:
1. Download the engine https://www.wolfram.com/developer/
2. Register, get a license (free)
3. Follow the instructions from https://github.com/WolframResearch/WolframLanguageForJupyter
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
I thought I'd give it a quick run on the Pi 4 just to see how long it would take, but I'm missing a step.
Code:
sudo apt install jupyter
is enough to get the notebook interface, but I'm missing the step to get the Wolfram kernel. Not sure if I just haven't spotted the right package, or if it needs installing manually. I'll have to have a more careful look later. It's got me intrigued about the possibility of generating the mesh, and possibly presenting the results, via FreeCAD's FEA interface.
I apologize. I made the assumption that those interested in the Jupyter notebook / Wolfram engine version will be using it on more powerful hardware than a Raspberry Pi. I have updated the ZIP file in post #7 to include the Mathematica notebook version. I think it makes more sense to use Mathematica on a Pi instead of Jupyter notebook. You can spin 3D graphics interactively in Mathematica. The notebook, without the 3D density plot, took less than a minute to run of my laptop. I'd expect a Pi can finish it in 10-20 minutes.

@pierre Thank you very much for providing the instructions.
 

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
You are missing a few steps:
1. Download the engine https://www.wolfram.com/developer/
2. Register, get a license (free)
3. Follow the instructions from https://github.com/WolframResearch/WolframLanguageForJupyter
Thanks. That's what I'd gathered from a quick search, but since Wolfram have worked with the Pi foundation to package the engine and Mathematica for the Pi, and jupyter is also packaged, I thought it was worth checking for a packaged version of the bindings as it's usually less painful in the long run. I still can't find a package, so it looks like it'll have to be the manual way if I really want to get it going.

@NTK no need to apologize - you'd already described it as impractical. I thought I'd give it a go anyway 'because it's there!' I've just tried the mathematica notebook on the Pi 4 and it took 75s so not too bad - thanks for that. It'll give me something to experiment with later.
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
May be in the not too distant future numerical simulations of waveguides will become accessible to the DIY community.
Aren't they already, between Ath4 and AKABAK? Or am I misunderstanding, not having used either of them? Having more open options are a good thing though. Between 3d printing and low cost CNC it's getting easier to make more complex designs, so being able to model them more easily would be a great bonus.
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
Aren't they already, between Ath4 and AKABAK? Or am I misunderstanding, not having used either of them? Having more open options are a good thing though. Between 3d printing and low cost CNC it's getting easier to make more complex designs, so being able to model them more easily would be a great bonus.
Ha! I have just displayed my ignorance in this subject matter :oops:
 

somebodyelse

Major Contributor
Joined
Dec 5, 2018
Messages
3,680
Likes
2,959
https://www.diyaudio.com/forums/multi-way/338806-acoustic-horn-design-easy-ath4.html
The first post has links to the Ath4 and AKABAK home pages, and to select parts of the thread where interesting things are happening. As I understand it at an overview level Ath4 generates profiles for well terminated oblate spheroid waveguides based on supplied parameters, which can then be simulated in ABEC/AKABAK. Both currently have a 'free for personal, noncommercial use' approach - for AKABAK you need to send them an email to get a license key. I may well have misunderstood the nature of the simulation.
 

Sashoir

Active Member
Forum Donor
Joined
May 15, 2020
Messages
118
Likes
140
This opening post is to show how to simulate room modes using Mathematica. The other room mode calculators I could find on the web can only handle rectangular box shaped rooms. Mathematica can solve for arbitrarily shaped room. I only attempted 2D, but theoretically Mathematica should be able to compute 3D too. I'll leave that for the ASR high achievers :D

Mathematica comes free with Raspberry Pi (Raspbian). I don't have a Pi with me so I haven't tested my notebook on a Pi. This example notebook took several seconds to run on my i7-10750H laptop, with the vast majority of it on generating the plots. I am guessing it wouldn't be too bad on a Pi. I'd love to have some feedback if any of you try it on a Pi. I'd recommend running it on one of the models with larger amounts of RAM.

A brief look at the those few (7) lines of code (looks so simple, isn't it ;)):

View attachment 115285
  1. 'c' is the speed of sound.
  2. 'Ω' is the domain, which in this case is the room. It is a polygon defined by its vertices. I used 8 vertices in the example. (Rectangular room with 2 corners taken out.)
  3. Show us the room we are simulating.
  4. This line does all the computations. It numerically computes the eigenvalues (related to room mode frequencies) and eigenfunctions (room mode shapes). In this example I specified solving for the first 20 modes.
  5. The returned eigenvalues λ are the square of the acoustic wavenumbers. This line convert them into frequencies in Hz.
  6. The last two statements are to display the results. The first set of figures shows the mode shape in 3D. The second set shows the contour plots from top so the mode peak locations are easier to see. The reds and greens are locations when the effects of the mode are strong. The white areas are where it is unaffected the nulls.
The number at the top of each plot is the mode frequency in Hz. The first mode is the trivial solution at basically 0 Hz and can be ignored. The outputs are below.

View attachment 115287 View attachment 115289 View attachment 115290
Thank you so much for this news that Mathematica is bundled with raspbian! I used it extensively as a (mediocre) mathematician, but couldn't really justify the licence cost for something just for fun. Now I'll have an excuse to dust off my cobwebs!
 

MarkS

Major Contributor
Joined
Apr 3, 2021
Messages
1,062
Likes
1,502
This is great! I am a long-time Mathematica user.

"Since the room geometry is a pretty complicated, there are lot of room modes."

The geometry does not much effect the number of modes below a given frequency, which depends primarily just on the total volume: https://en.wikipedia.org/wiki/Weyl_law
 
OP
NTK

NTK

Major Contributor
Forum Donor
Joined
Aug 11, 2019
Messages
2,656
Likes
5,819
Location
US East
Anybody converted this to Matlab?
I have not. I am not much of a MATLAB user. But I think for MATLAB the PDE Toolbox will be required (which I don't have).

Pierre is (was?) experimenting with FireDrake on Python (see post, link below). I am also thinking about doing it with Gridap on Julia, to be fully FOSS, if I can manage to muster enough motivation :facepalm:
 
Top Bottom