2D SWE: hyper-reduced Galerkin (example 1)#

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_galerkin_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: "RK4"
15  timeStepSize: 0.005
16  train:
17    finalTime: 5.0
18    stateSamplingFreq: 10
19    rhsSamplingFreq: 10
20  test:
21    finalTime: 5.0
22    stateSamplingFreq: 10
23    rhsSamplingFreq: 100
24
25offlineRom:
26  pod:
27    stateData:
28      useTrainingRuns: all
29    rhsData:
30      useTrainingRuns: all
31  sampleMesh:
32    random: 0.1
33
34onlineRom:
35  algorithm: hyperreducedGalerkin
36  podTruncation:
37    energyBased: [99.999, 99.99999]

Step 1: run FOMs#

python3 $REPOSRC/wf_foms.py --wf wf.yaml

The FOM stage is the same as here.

Step 2: offline rom#

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
├── rhs_left_singular_vectors.bin
├── rhs_singular_values.txt
├── rhs_snapshots.bin
├── 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”):

Sample mesh

Step 3: galerkin rom#

python3 $REPOSRC/wf_galerkin.py --wf wf.yaml

At the end, you should have the following directory structure:

.
├── CMakeFiles
├── Makefile
├── cmake_install.cmake
├── fom_mesh
├── fom_test_runid_0
├── fom_train_runid_0
├── fom_train_runid_1
├── hyperreduced_galerkin_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0
├── hyperreduced_galerkin_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0
├── hyperreducer_99.99999_sample_mesh_random_0.100
├── hyperreducer_99.999_sample_mesh_random_0.100
├── offline_rom
├── plot.py
└── wf.yaml

Step 4: process results#

Accuracy#

# from within $BUILDDIR/end-to-end-roms/2d_swe_default_galerkin
python3 $REPOSRC/wf_reconstruct_on_full_mesh.py
python3 plot.py
FOM ROM, 22 modes 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:

==> fom_test_runid_0/out.log <==
elapsed 6.71033
[info] [1806179] Finalizing pressio logger

==> fom_train_runid_0/out.log <==
elapsed 6.86063
[info] [1805967] Finalizing pressio logger

==> fom_train_runid_1/out.log <==
elapsed 6.75992
[info] [1806103] Finalizing pressio logger

Then do tail -n 2 hyperreduced_*/out.log, you will see:

==> hyperreduced_galerkin_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/out.log <==
elapsed 0.854369
[info] [1812457] Finalizing pressio logger

==> hyperreduced_galerkin_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/out.log <==
elapsed 1.01332
[info] [1812527] Finalizing pressio logger