Skip to content

Commit 3129b0d

Browse files
authored
Merge pull request #64 from Pressio/63-end-to-end-1-d-burgers-equation
#63: End-To-End 1-D Burgers' Equation
2 parents 36561ea + bb1a8fa commit 3129b0d

File tree

14 files changed

+1582
-9
lines changed

14 files changed

+1582
-9
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
6262

6363
enable_testing()
6464
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/end-to-end-roms)
65+
66+
# Build the standalone full tutorial (burgers example)
67+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/full-tutorial)

docs/build_requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Sphinx==5.0.1
2-
furo==2022.6.4.1
3-
myst-parser==0.18.0
1+
Sphinx>=7.2.0
2+
furo>=2024.1.29
3+
myst-parser>=2.0.0
44
sphinx-copybutton==0.5.0
55
m2r2==0.3.2
66
sphinx-design

docs/source/build.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Verify the build
3636

3737
.. code-block:: cpp
3838
39-
cd $BUIlDDIR
39+
cd $BUILDDIR
4040
ctest
4141
4242
Then what?

docs/source/index.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@ Find us on `Slack <https://pressioteam.slack.com>`_.
3939

4040
.. toctree::
4141
:maxdepth: 1
42-
:hidden:
4342

4443
build
45-
Join our Slack <https://pressioteam.slack.com>
46-
GitHub Repo <https://github.com/Pressio/pressio-tutorials>
47-
Open an issue/feature req. <https://github.com/Pressio/pressio-tutorials/issues>
4844
license
4945

46+
.. toctree::
47+
:maxdepth: 0
48+
:hidden:
49+
:caption: 1. Full Tutorial: 1-D Burgers' Equation
50+
51+
./tutorial/overview
5052

5153
.. toctree::
5254
:maxdepth: 0
5355
:hidden:
54-
:caption: 1. End-to-end ROMs using pressio-demoapps
56+
:caption: 2. End-to-end ROMs Using pressio-demoapps
5557

5658
./endtoend/readthisfirst
5759
./endtoend/swe_galerkin_default
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Background
2+
==========
3+
4+
Reduced-order models (ROMs) can be used to simulate a variety of physical phenomena
5+
modeled by partial differential equations (PDEs). In this tutorial, we will focus
6+
on the 1-D Burgers' equation as a representative example.
7+
8+
1-D Burgers' Equation
9+
----------------------
10+
11+
The 1-D Burgers' equation is a fundamental partial differential equation
12+
that models various physical phenomena, including fluid dynamics and traffic flow.
13+
It is given by:
14+
15+
.. math::
16+
17+
\frac{\partial u}{\partial t} + u \frac{\partial u}{\partial x} = \nu \frac{\partial^2 u}{\partial x^2}
18+
19+
where :math:`u` is the velocity field, :math:`t` is time, :math:`x` is the spatial coordinate,
20+
and :math:`\nu` is the viscosity coefficient.
21+
22+
While a more comprehensive introduction to the Burgers' equation is beyond the scope of this tutorial,
23+
numerical methods for solving it typically involve discretizing the spatial domain
24+
using finite difference or finite volume methods, and then integrating the resulting
25+
system of ordinary differential equations (ODEs) in time using methods such as
26+
Forward Euler, Runge-Kutta, or implicit schemes.
27+
28+
In this tutorial, we will focus on setting up a reduced-order model (ROM)
29+
for the 1-D Burgers' equation using the Pressio library.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Hyper-Reduction
2+
===============
3+
4+
This tutorial builds off of the information presented in
5+
:doc:`understand` to demonstrate how to set up and run a hyper-reduced
6+
reduced-order model (ROM) for the 1-D Burgers' equation using the Pressio library.
7+
8+
If you have not completed that initial tutorial, please do so before proceeding.
9+
10+
This page will follow the same structure as the previous tutorial,
11+
going through the enumerated steps but only highlighting the differences
12+
needed to implement hyper-reduction.
13+
14+
First: Why use hyper-reduction?
15+
-------------------------------
16+
17+
As discussed above, a typical ROM uses only the state snapshots
18+
to build the reduced basis.
19+
20+
This reduces the dimensionality of the system, but
21+
we still evaluate the full-order RHS at each time step,
22+
which can be computationally expensive. **Hyper-reduction**
23+
addresses this issue by approximating the RHS using a
24+
reduced basis constructed from the RHS snapshots.
25+
26+
So instead of a reduced state basis alone, we will
27+
also build a reduced basis for the RHS using the
28+
RHS snapshots we collected earlier.
29+
30+
With this, we can begin the tutorial.
31+
32+
Steps 0-1: As Before
33+
--------------------
34+
35+
Setting up Pressio and constructing your FOM is done exactly
36+
the same, regardless of the type of ROM you will build.
37+
38+
Step 2: Run the FOM to generate snapshots
39+
-----------------------------------------
40+
41+
In the original tutorial, we defined a ``SnapshotSet``
42+
to collect snapshots for both the ``state`` and the
43+
right-hand side ``rhs`` of the full-order model (FOM).
44+
45+
You may have noticed that the default ROM did not use
46+
the RHS snapshots at all. However, for hyper-reduction,
47+
we will need these RHS snapshots to build the
48+
hyper-reduction basis.
49+
50+
We will explain this further in subsequent steps.
51+
52+
If you are not implementing hyper-reduction, there is no
53+
need to store the RHS snapshots. You can simply return
54+
the state snapshots directly.
55+
56+
Step 3: Build the ROM from the snapshot matrix
57+
----------------------------------------------
58+
59+
The process begins identically to before: we use the
60+
state snapshots to compute the trial space, and then use
61+
that to get the reduced state. We will also use the same
62+
``ForwardEuler`` time stepper as before.
63+
64+
The key difference is in the definition of a **hyper-reducer**.
65+
66+
The hyper-reducer is a functor that takes in a sampled
67+
FOM RHS vector and projects it into a reduced space.
68+
69+
The process is similar to that of the trial space: we
70+
compute a POD basis from the RHS snapshots using SVD,
71+
and then use that basis to project the FOM RHS onto
72+
a lower-dimensional subspace.
73+
74+
There are refined techniques for selecting which rows
75+
of the RHS to sample, such as the Discrete Empirical
76+
Interpolation Method (DEIM). For simplicity in this tutorial,
77+
we will use a basic sampling approach that selects rows at
78+
a uniform interval (or stride).
79+
80+
Here is a general outline of how the hyper-reducer functor
81+
is defined:
82+
83+
.. code-block:: cpp
84+
85+
auto svdRhs = /* compute SVD of RHS snapshot matrix */;
86+
auto rhsBasis = /* extract leading left singular vectors from SVD */;
87+
88+
auto sampleIndices = /* select sample indices uniformly */;
89+
auto sampledBasis = /* extract rows of rhsBasis at sampleIndices */;
90+
91+
auto trialBasis /* aka Phi */ = trialSpace.basisOfTranslatedSpace();
92+
auto hypredMatrix = /* (Phi^T rhsBasis) * pinv(sampledBasis) */;
93+
94+
// Construct hyperreducer functor
95+
ExplicitGalerkinHyperReducer hyperReducer(hypredMatrix, sampleIndices);
96+
97+
This code is implemented fully in the ``hyperreduction.h`` file
98+
by the ``buildHyperReducer`` function.
99+
100+
The ``ExplicitGalerkinHyperReducer`` above is a
101+
user-defined functor that implements an ``operator()`` method
102+
that takes in a sampled FOM RHS vector and outputs the reduced RHS vector.
103+
104+
Like with the other Pressio interfaces, you can define your
105+
hyperreducer in any way you like, as long as it meets the API requirements.
106+
107+
Now that we have defined the hyper-reducer, we can
108+
build the ROM almost identically to before, but passing
109+
the hyperreducer functor as an additional argument:
110+
111+
.. code-block:: cpp
112+
113+
auto rom = pressio::rom::galerkin::create_default_problem_with_hyperreduction(
114+
stepScheme,
115+
trialSpace,
116+
fom,
117+
hyperReducer
118+
);
119+
120+
Step 4-6: As Before
121+
-------------------
122+
123+
The rest of the steps are identical regardless of whether
124+
you are using hyper-reduction or not. You can refer to the
125+
:doc:`understand` page for details on how to run the ROM,
126+
reconstruct the full-order solution, compare to the FOM,
127+
and examine the output files.

docs/source/tutorial/overview.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
End-to-end Tutorial: 1-D Burgers' Equation
2+
==========================================
3+
4+
This tutorial demonstrates how to set up and run a reduced order model (ROM)
5+
for the 1-D Burgers' equation using the Pressio library. The tutorial covers
6+
the following key steps:
7+
8+
1. Setting up the full order model (FOM).
9+
2. Running the FOM to generate a snapshot matrix.
10+
3. Building both basic and hyper-reduced ROMs.
11+
4. Running the ROMs and capturing trajectories.
12+
5. Comparing the ROM solutions with the FOM solution.
13+
6. Writing trajectories to CSV files for further analysis.
14+
15+
The tutorial is implemented in C++ and leverages Pressio's capabilities for
16+
model reduction and time integration.
17+
18+
.. toctree::
19+
:maxdepth: 1
20+
21+
background
22+
start
23+
understand
24+
hyperreduction

docs/source/tutorial/start.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Quick Start
2+
===========
3+
4+
These instructions assume the following env variables
5+
are set:
6+
7+
.. code-block:: bash
8+
9+
export SRC=<path-to-your-cloned-repo>
10+
export BUILD=<path-to-your-build-directory>
11+
12+
The main driver for the tutorial is defined in
13+
``$SRC/full-tutorial/burgers.cpp``.
14+
It is fully commented to help you understand each
15+
step of the implementation.
16+
17+
18+
Additionally, a full discussion of the tutorial can be found
19+
in the :doc:`understand` page.
20+
21+
Build
22+
-----
23+
24+
25+
The full tutorial will build with the rest of the repository.
26+
See :doc:`../build` for instructions. Be sure to install the Python dependencies
27+
listed in ``py_requirements.txt`` in order to use the plotting
28+
utility at the end of the tutorial.
29+
30+
Once you have built the repository, the tutorial will be in
31+
``$BUILD/full-tutorial/burgers``.
32+
33+
.. note::
34+
35+
This tutorial requires C++20 support in your compiler.
36+
37+
Run
38+
---
39+
40+
Run the tutorial with:
41+
42+
.. code-block:: bash
43+
44+
cd $BUILD/full-tutorial
45+
./burgers
46+
47+
This will run the tutorial and generate output files
48+
in the ``output/`` subdirectory.
49+
50+
You can generate plots with the output by running the
51+
python script in the same directory. It is hard-coded
52+
to find the output files in the ``output/`` subdirectory.
53+
54+
.. code-block:: bash
55+
56+
cd $BUILD/full-tutorial
57+
python plot.py
58+
59+
For a detailed breakdown of what you just ran, see
60+
the :doc:`understand` page.

0 commit comments

Comments
 (0)