Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Acoustic Frequency Response to "A Gallery finite element solvers" #230

Open
bayswiss opened this issue Dec 12, 2024 · 1 comment
Open

Comments

@bayswiss
Copy link

bayswiss commented Dec 12, 2024

Dozens of people have been asking why none of my tutorials are available here, so I am working on adding an acoustic frequency response solver example to Chapter 2, if it’s welcome.
Of course, both the matematical derivations and the code will be included, following the same style of other tutorials.

I understand that both .ipynb and .py files are required, and the code needs to work in parallel with mpirun.

Before proceeding further, I’d like to confirm if my approach is acceptable:

I often use 'frequency parallelism,' where the frequency loop is computed as follows:

def frequency_loop(nf):

    # solver setup

    # solver.solve

    return p_values #returns pressure at a microphone location

# frequecy axis definition:
f_axis = np.arange(5,200,1)
nf = range(0,len(f_axis))

from multiprocessing import Pool
n_proc = 4
pool = Pool(n_proc)  
p_mic = pool.map(frequency_loop,nf) # pressure spectrum
pool.close()
pool.join()

Here, each process works on a frequency across the entire mesh. This approach requires more RAM but scales perfectly.

That said, I believe it’s a bad idea to mix multiprocessing.Pool with mpirun, so if you agree, I will make the frequency loop a simple for loop:

# frequecy axis definition:
f_axis = np.arange(5,200,1)

p_mic = np.zeros((len(f_axis),1),dtype=complex)

for nf in range(0,len(frequency_axis):

    # solver setup

    # solver.solve

    p_mic[nf] = # code for evaluating pressure at mic

This way, the chapter will remain consistent with the rest of the tutorials. Perhaps at the end of it, I can add a link to a repository showcasing the multiprocessing.Pool alternative.

If you approve this approach, I will add the scripts before Christmas.

Best regards,
Antonio

@jorgensd
Copy link
Owner

I understand that both .ipynb and .py files are required, and the code needs to work in parallel with mpirun.

You can write either a .ipynb file or a .py file and let jupytext convert it for you.
However, parallel compatibility is a must.

The suggested approach sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants