2D SWE: hyper-reduced LSPG (example 1) ====================================== - ROM technique: hyper-reduced LSPG - problem: `2D shallow water equations (SWE) `_ Prerequisites ------------- - A valid build of the tutorials, see `here <../build.html>`__ - The following env variables MUST be set: .. code-block:: bash export REPOSRC=/end-to-end-roms export BUILDDIR= .. admonition:: To run the demo scripts below, you MUST be inside the correct directory: :class: important .. code-block:: bash cd $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1 Workflow File ------------- The `workflow file <../../../end-to-end-roms/2d_swe_lspg_hypred_1/wf.yaml>`_ for this demo is shown below for exposition purposes, but it is automatically copied to the build directory, so you don't need to do anything: .. literalinclude:: ../../../end-to-end-roms/2d_swe_lspg_hypred_1/wf.yaml :language: yaml :lines: 1-37 :linenos: Step 1: execute FOMs -------------------- The FOM stage is the same as `here `_. .. code-block:: bash # from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1 python3 $REPOSRC/wf_foms.py --wf wf.yaml .. warning:: This might take a few mins to run, be patient! Step 2: offline rom ------------------- .. code-block:: bash # from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1 python3 $REPOSRC/wf_offline_rom.py --wf wf.yaml The offline rom takes care of using the FOM training data to compute the POD modes, computing samples meshes, and puts everything into an "offline_rom" subdirectory: .. code-block:: bash offline_rom/ ├── pod_input.yaml ├── sample_mesh_random_0.100 ├── state_left_singular_vectors.bin ├── state_singular_values.txt └── state_snapshots.bin Sample mesh ^^^^^^^^^^^ In this demo, we use the sample mesh which is generated by keeping randomly 10% of the mesh cells. The whole sample mesh is done by presssio-demoapps. Note the generated sample mesh directory ``sample_mesh_random_0.100``. We can visualize the sample mesh as follows (note that given its random nature, your plot might look slightly different): .. code-block:: bash python3 $REPOSRC/../tpls/pressio-demoapps/meshing_scripts/plot_mesh.py \ --wdir ./offline_rom/sample_mesh_random_0.100/ -p show which shows a plot like the following (yellow cells denote the "sample mesh", white cells denote the "stencil mesh"): .. image:: ../../../end-to-end-roms/2d_swe_lspg_hypred_1/mesh.png :width: 50 % :alt: Sample mesh :align: center Step 3: lspg rom -------------------- .. code-block:: bash # from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1 python3 $REPOSRC/wf_lspg.py --wf wf.yaml .. The following C++ code is being executed: .. literalinclude:: ../../../end-to-end-roms/cpp/run_hyperreduced_lspg.hpp :language: cpp :lines: 58-155 .. literalinclude:: ../../../end-to-end-roms/cpp/lspg_pick_solver_and_run.hpp :language: cpp :lines: 52-64, 67-78, 111 At the end, you should have the following directory structure: .. code-block:: bash . ├── CMakeFiles ├── Makefile ├── cmake_install.cmake ├── hyperreduced_lspg_truncation_energybased_99.99999_runid_0 ├── hyperreduced_lspg_truncation_energybased_99.999_runid_0 ├── fom_mesh ├── fom_test_runid_0 ├── fom_train_runid_0 ├── fom_train_runid_1 ├── offline_rom ├── plot.py └── wf.yaml Step 4: process results ----------------------- Accuracy ^^^^^^^^ .. code-block:: bash # from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1 python3 $REPOSRC/wf_reconstruct_on_full_mesh.py python3 plot.py .. image:: ../../../end-to-end-roms/2d_swe_lspg_hypred_1/FOM.png :width: 32 % :alt: FOM .. image:: ../../../end-to-end-roms/2d_swe_lspg_hypred_1/ROM_18.png :width: 32 % :alt: ROM, 22 modes .. image:: ../../../end-to-end-roms/2d_swe_lspg_hypred_1/ROM_36.png :width: 32 % :alt: ROM, 55 modes Runtime comparison ^^^^^^^^^^^^^^^^^^ The results above show the accuracy, but we also want to assess the computational gain. Thanks to the sample mesh, the runtime of the ROMs are just a fraction of the FOM runtime. You can check this by doing If you do ``tail -n 2 fom_*/out.log``, you see something as follows: .. code-block:: text ==> fom_test_runid_0/out.log <== elapsed 102.308 [info] [1136219] Finalizing pressio logger ==> fom_train_runid_0/out.log <== elapsed 99.1657 [info] [1133529] Finalizing pressio logger ==> fom_train_runid_1/out.log <== elapsed 99.8976 [info] [1134515] Finalizing pressio logger Then do ``tail -n 2 hyperreduced_*/out.log``, you should see something as: .. code-block:: text ==> hyperreduced_lspg_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/out.log <== elapsed 5.53887 [info] [1138950] Finalizing pressio logger ==> hyperreduced_lspg_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/out.log <== elapsed 6.52652 [info] [1139027] Finalizing pressio logger