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
The following env variables MUST be set:
export REPOSRC=<full-path-to-the-pressio-tutorials-source-repo>/end-to-end-roms export BUILDDIR=<full-path-to-where-you-built-the-tutorials>
To run the demo scripts below, you MUST be inside the correct directory:
cd $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1
Workflow File#
The workflow file 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:
1problem: 2d_swe
2
3parameterSpace:
4 names: ['coriolis', 'pulsemag', 'gravity']
5 trainPoints:
6 0: [-1.0, 0.125, 9.8]
7 1: [ 0.0, 0.125, 9.8]
8 testPoints:
9 0: [-0.5, 0.125, 9.8]
10
11fom:
12 meshSize: [65, 65]
13 inviscidFluxReconstruction: "Weno3"
14 odeScheme: "BDF1"
15 timeStepSize: 0.01
16 nonlinearSolverName: NewtonRaphson
17 nonlinearSolverTolerance: 1e-6
18 train:
19 finalTime: 5.0
20 stateSamplingFreq: 10
21 test:
22 finalTime: 5.0
23 stateSamplingFreq: 10
24
25offlineRom:
26 pod:
27 stateData:
28 useTrainingRuns: all
29 sampleMesh:
30 random: 0.1
31
32onlineRom:
33 algorithm: hyperreducedLspg
34 nonlinearSolverName: GaussNewton
35 nonlinearSolverTolerance: 1e-6
36 podTruncation:
37 energyBased: [99.999, 99.99999]
Step 1: execute FOMs#
The FOM stage is the same as here.
# 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#
# 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:
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):
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”):
Step 3: lspg rom#
# from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1
python3 $REPOSRC/wf_lspg.py --wf wf.yaml
At the end, you should have the following directory structure:
.
├── 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#
# from within $BUILDDIR/end-to-end-roms/2d_swe_lspg_hypred_1
python3 $REPOSRC/wf_reconstruct_on_full_mesh.py
python3 plot.py
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:
==> 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:
==> 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