2D SWE: default Galerkin#

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_default

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: 5
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
32onlineRom:
33  algorithm: defaultGalerkin
34  podTruncation:
35    energyBased: [99.999, 99.99999]

Step 1: execute FOMs#

# from within $BUILDDIR/end-to-end-roms/2d_swe_galerkin_default
python3 $REPOSRC/wf_foms.py --wf wf.yaml

This driver script automates this first stage by creating input files, generating run directories and running the C++ executable to generate all the FOM train and test data at the points specified in the yaml file.

At the end, doing tree -L 1 . should produce:

.
├── CMakeFiles
├── Makefile
├── cmake_install.cmake
├── fom_mesh
├── fom_test_runid_0
├── fom_train_runid_0
├── fom_train_runid_1
├── plot.py
└── wf.yaml

Where we see the run train and test directories and their corresponding IDs.

Step 2: offline rom#

# from within $BUILDDIR/end-to-end-roms/2d_swe_galerkin_default
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, and creates all data into an “offline_rom” subdirectory. Specifically, in this case the demo specifies that all the training runs should be used to compute POD modes.

./offline_rom/
├── pod_input.yaml
├── rhs_left_singular_vectors.bin
├── rhs_singular_values.txt
├── rhs_snapshots.bin
├── state_left_singular_vectors.bin
├── state_singular_values.txt
└── state_snapshots.bin

Step 3: galerkin rom#

# from within $BUILDDIR/end-to-end-roms/2d_swe_galerkin_default
python3 $REPOSRC/wf_galerkin.py --wf wf.yaml

This driver script automates all the Galerkin runs. Specifically, it creates all the run directories, writes all input files, prepares initial conditions and runs the actual Galerkin run at every test point.

More specifically, what happens here is the following:

  • the total number of modes used varies and is computed by truncating the basis using the energy values specified in the workflow file at the top: the higher the target energy, the more modes it uses (the code doing this computes the energy of the singular values of the POD modes and truncate based on the target energy, and again this is done automatically by our driver script)

  • the reduced initial condition is read from file but here simply corresponds to the projection of the FOM initial condition onto the basis

  • note that we also monitor the evolution of the reduced state and store its history into file (this will be used for the postprocessing)

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

.
├── CMakeFiles
├── Makefile
├── cmake_install.cmake
├── default_galerkin_truncation_energybased_99.99999_runid_0
├── default_galerkin_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#

# from within $BUILDDIR/end-to-end-roms/2d_swe_galerkin_default
python3 $REPOSRC/wf_reconstruct_on_full_mesh.py
python3 plot.py
FOM ROM, 22 modes ROM, 55 modes

Step 5: things you can try#

This section suggests a few things you can experiment with. Note: before you run a new experiment in the same directory, to avoid conflicts you need to cleanup all the existing content, which can you easily do as follows:

# from within $BUILDDIR/end-to-end-roms/2d_swe_galerkin_default
python3 clean.py
  • a different simulation time for the train and test runs so that you can assess how the ROM performs in a time extrapolation regime. This can easily be done by just replacing:

    fom:
      # ...
      train:
        finalTime: 5.0
      # ...
      test:
        finalTime: 6.0
    
  • add new test points to the parameterSpace section of the workflow file to as follows:

    parameterSpace:
      # ...
      testPoints:
        0: [-0.5, 0.125, 9.8]
        1: [-0.9, 0.125, 9.8]
        2: [ 0.1, 0.125, 9.8] # this test point is outside of training range