|
50 | 50 | { |
51 | 51 | "cell_type": "markdown", |
52 | 52 | "id": "2221ea27-c37b-41e4-b203-a716c742897d", |
53 | | - "metadata": {}, |
| 53 | + "metadata": { |
| 54 | + "jp-MarkdownHeadingCollapsed": true |
| 55 | + }, |
54 | 56 | "source": [ |
55 | 57 | "# 2- Basics: configuration, compilation, run on CPUs\n", |
56 | 58 | "<a id=\"compilation\"></a>\n", |
|
382 | 384 | "to see the effect on compressibility. You can also try to use [parallelism with MPI](#mpi) to speed up the computation\n" |
383 | 385 | ] |
384 | 386 | }, |
| 387 | + { |
| 388 | + "cell_type": "markdown", |
| 389 | + "id": "c8659a27-6da2-4bdf-85bb-a58e54940253", |
| 390 | + "metadata": {}, |
| 391 | + "source": [ |
| 392 | + "# 5- a python-based setup\n", |
| 393 | + "\n", |
| 394 | + "In this example, we're going to use `pydefix`, an Idefix module designed to allow Idefix to talk directly to a python interpreter, on-the-fly, without needing disk access.\n", |
| 395 | + "\n", |
| 396 | + "## The problem\n", |
| 397 | + "\n", |
| 398 | + "The problem we consider is a 1D isothermal problem. The flow is initially at rest, and we have already coded a forcing in the middle of the domain which forces a sinusoidal oscillation on VX1. This forcing is going to lead to a stationary sound wave with a sinusoidal wave pattern. Our goal is to measure the wavelength of this sound wave.\n", |
| 399 | + "\n", |
| 400 | + "To do this, we are going to fourier-transform the spatial domain on the fly. To avoid rewriting an fft routine, we will simply use the fft library from numpy.\n", |
| 401 | + "\n", |
| 402 | + "We first move to the problem directory\n", |
| 403 | + "\n", |
| 404 | + "```shell\n", |
| 405 | + "cd <path_to_idefix_tutorial>/PythonSetup/problem/\n", |
| 406 | + "```\n", |
| 407 | + "\n", |
| 408 | + "## Your tasks\n", |
| 409 | + "\n", |
| 410 | + "1 - configure the code (with cmake) to enable Python support and recompile (feel free to choose a CPU or a GPU target). The [pydefix documentation](https://idefix.readthedocs.io/latest/modules/pydefix.html) will probably be handy.\n", |
| 411 | + "\n", |
| 412 | + "2 - if you try to run the code straight away, you will see an error asking you to experiment with pydefix. This is because while idefix has been compiled with python support, pydefix has not yet been enabled. This is done in the `Python` block of idefix.ini. Check the [pydefix documentation](https://idefix.readthedocs.io/latest/modules/pydefix.html) and add a `Python` block in idefix.ini to use the script \"myscript\" and the function \"initflow\" (already defined) to make your initial conditions (constant density, no velocity). Have a look at the script \"myscript.py\" to see how this is done.\n", |
| 413 | + "\n", |
| 414 | + "3- if you now run the code, you can check that the code effectively generates a sound wave from the domain center. Let's open the vtk file series and plot VX1 to see that:" |
| 415 | + ] |
| 416 | + }, |
| 417 | + { |
| 418 | + "cell_type": "code", |
| 419 | + "execution_count": null, |
| 420 | + "id": "473343ff-eaa5-4e52-976b-895e3665a216", |
| 421 | + "metadata": {}, |
| 422 | + "outputs": [], |
| 423 | + "source": [ |
| 424 | + "# Load the VTK file series produced by Idefix\n", |
| 425 | + "plt.figure()\n", |
| 426 | + "for n in range(10):\n", |
| 427 | + " V=readVTK(\"./PythonSetup/solution/data.%04d.vtk\"%n)\n", |
| 428 | + " plt.plot(V.x,V.data[\"VX1\"][:,0,0])\n", |
| 429 | + "plt.show()" |
| 430 | + ] |
| 431 | + }, |
| 432 | + { |
| 433 | + "cell_type": "markdown", |
| 434 | + "id": "af4f6947-41ec-409f-afe5-4dfc61f57429", |
| 435 | + "metadata": {}, |
| 436 | + "source": [ |
| 437 | + "4- now the meat: let's make an output function in python. We have already defined an output function in \"myscript.py\", so let's tell idefix that we to call this output function in the `Python` block of idefix.ini (check the doc, again)\n", |
| 438 | + "\n", |
| 439 | + "5- in the `Output` block, we need to enable `Python` output and specify an output period. Let's use the same output period as the vtk output: 1.0\n", |
| 440 | + "\n", |
| 441 | + "6- now you need to finish coding the output function in python. Most of it is already done: you just need to find the location of the maximum of the spectrum, get its associated spatial frequency, and compute the associated sound speed (keep in mind $c_s=f \\lambda$)\n", |
| 442 | + "\n", |
| 443 | + "7- if you did your job well, the output function should now print directly the measured wavelength and sound speed. You can now vary the forcing frequency, amplitude, and sound speed directly in idefix.ini and check how this works!" |
| 444 | + ] |
| 445 | + }, |
385 | 446 | { |
386 | 447 | "cell_type": "markdown", |
387 | 448 | "id": "16d63439-77e0-4c7b-852a-f12abd705834", |
388 | 449 | "metadata": { |
389 | 450 | "tags": [] |
390 | 451 | }, |
391 | 452 | "source": [ |
392 | | - "# 5- A more advanced setup\n", |
| 453 | + "# 6- A more advanced setup\n", |
393 | 454 | "\n", |
394 | 455 | "## Before we start\n", |
395 | 456 | "\n", |
396 | 457 | "\n", |
397 | | - "In this tutorial we will introduce several important aspects hidden in the Simple Setup tutorial: Host and Device memory space, the `idefix_loop` construct and the tricks associated with it.\n", |
| 458 | + "In this part of the tutorial we will introduce several important aspects hidden in the Simple Setup tutorial: Host and Device memory space, the `idefix_loop` construct and the tricks associated with it.\n", |
398 | 459 | "\n", |
399 | 460 | "This tutorial is not intended to duplicate Idefix documentation. It is strongly recommended to read the introduction in the programming guide regarding [Host and device](https://idefix.readthedocs.io/latest/programmingguide.html#host-and-device), [Arrays](https://idefix.readthedocs.io/latest/programmingguide.html#arrays) and [Loops](https://idefix.readthedocs.io/latest/programmingguide.html#execution-space-and-loops).\n", |
400 | 461 | "\n", |
|
588 | 649 | "id": "e0db2593-d0c6-4779-9dfd-5da4ba886d75", |
589 | 650 | "metadata": {}, |
590 | 651 | "source": [ |
591 | | - "# 6- Programming in Idefix: Debugging and profiling\n", |
| 652 | + "# 7- Programming in Idefix: Debugging and profiling\n", |
592 | 653 | "\n", |
593 | 654 | "## Problem1: a CPU segmentation fault\n", |
594 | 655 | "\n", |
|
0 commit comments