{ "cells": [ { "cell_type": "markdown", "id": "f1dce0b3-e06f-49ae-9c17-a52a0d0e4ce3", "metadata": {}, "source": [ "# Restart and resolution change\n", "\n", "Fluidsim provides 2 command-line tools to restart a simulation (`fluidsim-restart`) \n", "and create a new file with a modified resolution (`fluidsim-modif-resolution`). \n", "Let's present these very useful tools!\n", "\n", "First, one can get help by invoking these tools with the `-h` option:" ] }, { "cell_type": "code", "execution_count": null, "id": "859a2448-8e87-49b7-816a-b620c6009496", "metadata": {}, "outputs": [], "source": [ "!fluidsim-restart -h" ] }, { "cell_type": "code", "execution_count": null, "id": "45998ecb-188b-419b-b5a0-f59f01b7e102", "metadata": {}, "outputs": [], "source": [ "!fluidsim-modif-resolution -h" ] }, { "cell_type": "code", "execution_count": null, "id": "10b0ba37-bacc-42d5-b667-caa2d6e5599e", "metadata": { "tags": [ "hide-cell" ] }, "outputs": [], "source": [ "from pathlib import Path\n", "import shutil\n", "\n", "path_fls = \"/tmp/sim_data\"\n", "path_base = Path(path_fls) / \"doc_aniso\"\n", "shutil.rmtree(path_base, ignore_errors=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "110dde77-c159-4c1f-ba06-f67290b1a994", "metadata": { "tags": [ "hide-cell" ] }, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"FLUIDSIM_PATH\"] = path_fls\n", "os.environ[\"TRANSONIC_BACKEND\"] = \"python\"" ] }, { "cell_type": "markdown", "id": "3634c512-df0a-4716-bbfb-472353d55dd3", "metadata": {}, "source": [ "Then, let's use these tools. First we need a simulation directory. " ] }, { "cell_type": "code", "execution_count": null, "id": "a14010ba-fe29-4dc6-926e-a59a25b6a616", "metadata": { "tags": [ "remove-stderr" ] }, "outputs": [], "source": [ "from fluidsim.util.scripts.turb_trandom_anisotropic import main\n", "\n", "params, sim = main(\n", " args=(\n", " '--sub-directory \"doc_aniso\" -nz 12 --ratio-nh-nz 2 --t_end 1 '\n", " '--modify-params \"params.output.periods_print.print_stdout = 0.25; '\n", " 'params.output.periods_save.spect_energy_budg = 0\"'\n", " )\n", ")" ] }, { "cell_type": "markdown", "id": "465b6db5-6ec2-43e4-a47b-51c6d4b06ab5", "metadata": {}, "source": [ "We then define a variable with the path of the directory containing the results of the simulation." ] }, { "cell_type": "code", "execution_count": null, "id": "7bc0d08a-1882-416a-b341-b68e16215c28", "metadata": {}, "outputs": [], "source": [ "sim.output.path_run" ] }, { "cell_type": "code", "execution_count": null, "id": "e035f9b9-35d7-4f8a-9a52-899fd47741ce", "metadata": {}, "outputs": [], "source": [ "from pprint import pprint\n", "\n", "\n", "def ls_path_run(glob=\"*\"):\n", " pprint(sorted(p.name for p in Path(sim.output.path_run).glob(glob)))\n", "\n", "\n", "ls_path_run()" ] }, { "cell_type": "code", "execution_count": null, "id": "d79d54ea-3db7-497a-be92-476cf6dad549", "metadata": {}, "outputs": [], "source": [ "sim.output.spatial_means.plot()" ] }, { "cell_type": "markdown", "id": "e3948e8d-cf69-4e62-9521-312e45445ca5", "metadata": {}, "source": [ "Ah, we see that `t_end = 1` was not enough to obtain a statistically steady state. We need to run the simulation longer. Let's restart it to run until `t_end = 2`:" ] }, { "cell_type": "code", "execution_count": null, "id": "8387162e-7c03-49de-9286-bf5a8a0c4b7a", "metadata": { "tags": [ "remove-stderr" ] }, "outputs": [], "source": [ "!fluidsim-restart {sim.output.path_run} --t_end 2.0" ] }, { "cell_type": "code", "execution_count": null, "id": "21a6bcff-30ce-42a0-a257-637bc1b0c38c", "metadata": {}, "outputs": [], "source": [ "ls_path_run()" ] }, { "cell_type": "code", "execution_count": null, "id": "f52cbc23-53ee-42cf-afad-d52a82da273a", "metadata": { "tags": [] }, "outputs": [], "source": [ "sim.output.spatial_means.plot()" ] }, { "cell_type": "markdown", "id": "e4f15fab-8a8a-409f-b470-3fb8807bae6c", "metadata": {}, "source": [ "Finally, we are not far from a statistically steady state. We can relaunch the simulation to save results about this state. Here we show how to restart a simulation with the spatiotemporal spectra output activated:" ] }, { "cell_type": "code", "execution_count": null, "id": "452a2a30-4358-484f-b666-857c85038e8e", "metadata": {}, "outputs": [], "source": [ "!fluidsim-restart {sim.output.path_run} --t_end 3.0 --modify-params \"params.output.periods_save.spatiotemporal_spectra = 2 * pi / (4 * params.N)\"" ] }, { "cell_type": "code", "execution_count": null, "id": "26919f71-b361-419a-8298-7bb7b1be88d6", "metadata": {}, "outputs": [], "source": [ "ls_path_run()" ] }, { "cell_type": "markdown", "id": "11ad70f1-60e0-4b53-9e99-7279ec4a2e9b", "metadata": {}, "source": [ "`spatiotemporal` is a directory containing the data that can be used to compute spatiotemporal spectra:" ] }, { "cell_type": "code", "execution_count": null, "id": "f3811502-d957-46bc-908f-aabd24eafd51", "metadata": {}, "outputs": [], "source": [ "ls_path_run(\"spatiotemporal/*\")" ] }, { "cell_type": "code", "execution_count": null, "id": "a409d832-21b1-4703-ad6b-962a8d95beca", "metadata": {}, "outputs": [], "source": [ "sim.output.spatial_means.plot()" ] }, { "cell_type": "markdown", "id": "37aeec81-21e5-44fe-aef4-2f4d93efd34b", "metadata": {}, "source": [ "We want to start a larger simulation from the last state of this small simulation. We first need to create a larger file:" ] }, { "cell_type": "code", "execution_count": null, "id": "4a2cc4d2-ba33-4805-b60b-54688d98c077", "metadata": {}, "outputs": [], "source": [ "!fluidsim-modif-resolution {sim.output.path_run} 5/4" ] }, { "cell_type": "markdown", "id": "927ffff4-25b1-41b3-bd4d-72f50eb935eb", "metadata": {}, "source": [ "We can now launch the last simulation from the file just created." ] }, { "cell_type": "code", "execution_count": null, "id": "b9b1f74f-d0da-4579-9788-8ecbe6245361", "metadata": {}, "outputs": [], "source": [ "path_new_state = next(Path(sim.output.path_run).glob(\"State_phys*\"))\n", "str(path_new_state)" ] }, { "cell_type": "code", "execution_count": null, "id": "d2f368ae-52b3-482e-8708-188ee7022dad", "metadata": {}, "outputs": [], "source": [ "!fluidsim-restart {path_new_state} --t_end 3.1 --modify-params \"params.NEW_DIR_RESULTS = True; params.nu_2 /= 2; params.output.periods_print.print_stdout = 0.05; params.output.periods_save.spatial_means = 0.01;\"" ] }, { "cell_type": "code", "execution_count": null, "id": "e203da2c-8f2c-418e-b2b1-57850e9418f9", "metadata": {}, "outputs": [], "source": [ "[p.name for p in path_base.glob(\"*\")]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python3", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "metadata": { "execution": { "allow_errors": true, "timeout": 150 } } }, "nbformat": 4, "nbformat_minor": 5 }