Skip to content

Commit 46b09cb

Browse files
authored
Merge pull request #26 from Steriva/main
Code and paper update following comments from reviewer 2
2 parents acd3b9b + 8f9defa commit 46b09cb

12 files changed

Lines changed: 188 additions & 112 deletions

File tree

README.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
- [How to cite *pyforce*](#how-to-cite-pyforce)
1818
- [Selected works with *pyforce*](#selected-works-with-pyforce)
1919
- [Installation](#installation)
20+
- [Package Structure](#package-structure)
2021
- [Tutorials](#tutorials)
22+
- [Demo results](#demo-results)
2123
- [Authors and contributions](#authors-and-contributions)
2224
- [Community Guidelines](#community-guidelines)
2325
- [Contribute to the Software](#contribute-to-the-software)
@@ -37,10 +39,10 @@ The techniques implemented here follow the same underlying idea expressed in the
3739

3840
At the moment, the following techniques have been implemented:
3941

40-
- **Proper Orthogonal Decomposition** with Projection and Interpolation for the Online Phase
41-
- **Generalised Empirical Interpolation Method**, either regularised with Tikhonov or not
42-
- **Parameterised-Background Data-Weak formulation**
43-
- an **Indirect Reconstruction** algorithm to reconstruct non-observable fields
42+
- **Proper Orthogonal Decomposition** with Projection and Interpolation for the Online Phase -> [`pyforce.offline.POD`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/offline/pod.html#POD), [`pyforce.online.pod_projection`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/online/pod_projection.html#PODproject), [`pyforce.online.pod_interpolation`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/online/pod_interpolation.html#PODI)
43+
- **Generalised Empirical Interpolation Method**, either regularised with Tikhonov or not -> [`pyforce.offline.geim`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/offline/geim.html#GEIM), [`pyforce.online.geim`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/online/geim.html#GEIM), [`pyforce.online.tr_geim`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/online/tr_geim.html#TRGEIM)
44+
- **Parameterised-Background Data-Weak formulation** -> [`pyforce.online.pbdw`](https://ermete-lab.github.io/ROSE-pyforce/_modules/pyforce/online/pbdw.html#PBDW)
45+
- an **Indirect Reconstruction** algorithm to reconstruct non-observable fields -> [`pyforce.online.indirect_recon`](https://ermete-lab.github.io/ROSE-pyforce/api/pyforce.online.html#module-pyforce.online.indirect_recon)
4446

4547
This package is aimed to be a valuable tool for other researchers, engineers, and data scientists working in various fields, not only restricted in the Nuclear Engineering world.
4648

@@ -104,12 +106,18 @@ create a conda environment using `environment.yml`
104106
cd ROSE-pyforce
105107
conda env create -f pyforce/environment.yml
106108
```
107-
activate the environment and then install the package using `pip`
109+
activate the environment and then install the package using `pip` (be aware than on PyPI there exists another package named *pyforce*, so be sure to install it from the cloned repository)
108110
```bash
109111
conda activate pyforce-env
110-
python -m pip install pyforce/
112+
cd pyforce/
113+
python -m pip install .
111114
```
112115

116+
## Package Structure
117+
The package **pyforce** comprises 3 subpackages: *offline*, *online* and *tools*. The first two collect the main functionalities, in particular the different DDROM techniques; whereas, the last includes importing and storing functions (from *dolfinx* directly or mapping from OpenFOAM), some backend classes for the snapshots and the calculation of integrals/norms. In the following, some figures are sketching how the different classes are connected to each other during the offline and online phases.
118+
119+
More details on how the classes are connected to each other (both during the offline and online phases) can be found in the [docs](https://ermete-lab.github.io/ROSE-pyforce/theory.html#package-structure).
120+
113121
## Tutorials
114122
The *pyforce* package is tested on some tutorials available in the [docs](https://ermete-lab.github.io/ROSE-pyforce/tutorials.html), including fluid dynamics and neutronics problems.
115123

@@ -121,6 +129,45 @@ The *pyforce* package is tested on some tutorials available in the [docs](https:
121129

122130
The snapshots can be either generated by the user or be downloaded at the following link [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.15705990.svg)](https://zenodo.org/records/15705990)
123131

132+
### Demo results
133+
134+
Two demo results are reported here for a quick overview of the package capabilities, for the POD with Interpolation and for the GEIM with Tikhonov Regularisation. More details can be found in the [docs](https://ermete-lab.github.io/ROSE-pyforce/tutorials.html).
135+
136+
- **POD** with **Interpolation** on the Laminar Flow over Cylinder tutorial: in the following block, a code-block will be reported to show how to generate the POD basis from a set of train snapshots (offline phase) and how to perform the online phase and the state reconstruction
137+
```python
138+
# Offline Phase
139+
from pyforce.offline.pod import POD
140+
pod_off = POD(train_snaps : FunctionsList, var_name, verbose = True)
141+
pod_off.compute_basis(train_snaps : FunctionsList, rank)
142+
143+
...
144+
145+
# Online Phase
146+
from pyforce.online.pod_interpolation import PODI
147+
podi = PODI(pod_modes: FunctionsList, coefficients_maps: list, var_name)
148+
reconstruction = podi.reconstruct(test_snaps: FunctionsList, test_params: list, basis_to_use: int)
149+
```
150+
<p align="center">
151+
<img src="images/podi.png" alt="PODI" width="400"/>
152+
</p>
153+
154+
- **GEIM** with **Tikhonov Regularisation** on the Multi-Group Neutron Diffusion tutorial: in the following block, a code-block will be reported to show how to generate the GEIM basis and sensors from a set of train snapshots (offline phase) and how to perform the online phase and the state reconstruction
155+
```python
156+
# Offline Phase
157+
from pyforce.offline.geim import GEIM
158+
geim_off = GEIM(mesh: dolfinx.mesh.Mesh, V: FunctionSpace, var_name, sensor_point_spread)
159+
geim_off.offline(train_snaps : FunctionsList, Max_Sensors: int, verbose = True)
160+
161+
# Online Phase
162+
from pyforce.online.tr_geim import TRGEIM
163+
trgeim = TRGEIM(magic_functions: FunctionsList, magic_sensors: FunctionsList, mean_offline_beta_coeffs: np.ndarray, std_offline_beta_coeffs: np.ndarray, var_name)
164+
trgeim.reconstruct(test_snaps: FunctionsList, M_to_use, noise_value, reg_param = noise_value**2)
165+
```
166+
<p align="center">
167+
<img src="images/geim_anl.png" alt="TR-GEIM" width="400"/>
168+
</p>
169+
170+
124171
## Authors and contributions
125172

126173
**pyforce** is currently developed and mantained at [Nuclear Reactors Group - ERMETE Lab](https://github.com/ERMETE-Lab) by

docs/Tutorials/02_MGDiffusion/02b_offline_GEIM.ipynb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
},
4949
{
5050
"cell_type": "code",
51-
"execution_count": 2,
51+
"execution_count": 3,
5252
"metadata": {},
5353
"outputs": [],
5454
"source": [
5555
"from neutronics import create_anl11a2_mesh\n",
5656
"\n",
57-
"domain, _, _ = create_anl11a2_mesh(use_msh=True, save_mesh=False)\n",
57+
"domain, _, _ = create_anl11a2_mesh(use_msh=False, save_mesh=False)\n",
5858
"\n",
5959
"fuel1_marker = 1\n",
6060
"fuel2_marker = 2\n",
@@ -67,6 +67,26 @@
6767
"clear_output()"
6868
]
6969
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 4,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"data": {
77+
"text/plain": [
78+
"dolfinx.mesh.Mesh"
79+
]
80+
},
81+
"execution_count": 4,
82+
"metadata": {},
83+
"output_type": "execute_result"
84+
}
85+
],
86+
"source": [
87+
"type(domain)"
88+
]
89+
},
7090
{
7191
"cell_type": "markdown",
7292
"metadata": {},
@@ -565,7 +585,7 @@
565585
],
566586
"metadata": {
567587
"kernelspec": {
568-
"display_name": "Python 3 (ipykernel)",
588+
"display_name": "pyforce-old",
569589
"language": "python",
570590
"name": "python3"
571591
},
@@ -581,12 +601,7 @@
581601
"pygments_lexer": "ipython3",
582602
"version": "3.10.14"
583603
},
584-
"orig_nbformat": 4,
585-
"vscode": {
586-
"interpreter": {
587-
"hash": "e5b3af111de828d84cfea01c8e4cc990d7262e947155f31e208c22ad6b78199b"
588-
}
589-
}
604+
"orig_nbformat": 4
590605
},
591606
"nbformat": 4,
592607
"nbformat_minor": 2

docs/installation.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Installation notes
22

3-
**pyforce** has been tested on MacOS and Linux machines with **Python3.10**.
3+
**pyforce** has been tested on MacOS and Linux machines with **Python3.10**, using **conda** as package manager. There is no direct support for Windows machines, but it can work using WSL2.
44

55
## Dependencies
66
The *pyforce* package requires the following dependencies:
@@ -43,7 +43,8 @@ conda env create -f pyforce/environment.yml
4343
activate the environment and then install the package using `pip`
4444
```bash
4545
conda activate pyforce-env
46-
python -m pip install pyforce/
46+
cd pyforce/
47+
python -m pip install .
4748
```
4849

4950
If the previous procedure encounters any issues, you can adopt a step-by-step approach: start by creating a new conda environment
@@ -89,10 +90,10 @@ python -m pip install fluidfoam scikit-learn
8990
```
9091
Once all the dependencies have been installed, *pyforce* can be installed using *pip*: clone the repository
9192
```bash
92-
git clone https://github.com/ROSE-Polimi/pyforce.git
93+
git clone https://github.com/ERMETE-Lab/ROSE-pyforce.git
9394
```
9495
Change directory to *ROSE-pyforce* and install using pip
9596
```bash
96-
cd ROSE-pyforce
97-
python -m pip install pyforce/
97+
cd ROSE-pyforce/pyforce/
98+
python -m pip install .
9899
```

docs/theory.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Theory and package structure
22
This section presents the main ideas behind Reduced Order Modelling (ROM) {cite:p}`Quarteroni2016, MadayChapter2020, Degen2020_conference`, focusing on data-driven paradigm of these techniques. Then, the structure of the package is presented showing how the different classes are connected to each other.
33

4+
The following table summarises the main acronyms used throughout the documentation.
5+
6+
| Acronym | Full Name | Brief Description |
7+
|--------|--------------------------------------------------|-------------------|
8+
| **DA** | Data Assimilation | Methodology to combine model predictions with observational data to improve state estimates. |
9+
| **DDROM** | Data-Driven Reduced Order Model | ROM built only from data without requiring explicit knowledge of the governing equations, including state estimation from sparse measurements. |
10+
| **FOM** | Full Order Model | High-fidelity model, typically a discretized PDE, used to generate snapshots for ROM construction. |
11+
| **GEIM** | Generalized Empirical Interpolation Method | State estimation method able to reconstruct the state from measurements and place sensors in a greedy way. |
12+
| **IR** | Indirect Reconstruction | Technique to reconstruct non-observable fields from measurements of observable ones using ROM. |
13+
| **ODE** | Ordinary Differential Equation | Mathematical equations involving functions of a single variable and their derivatives. |
14+
| **PBDW** | Parametrized-Background Data-Weak formulation | Data assimilation approach combining a background model with experimental measurements in a variational framework. |
15+
| **PDE** | Partial Differential Equation | Mathematical equations involving multivariable functions and their partial derivatives, governing many physical phenomena. |
16+
| **POD** | Proper Orthogonal Decomposition | Technique to extract dominant modes from data/snapshots for reduced modelling. |
17+
| **RB** | Reduced Basis | Set of basis functions derived from FOM snapshots to represent solutions in a low-dimensional space. |
18+
| **ROM** | Reduced Order Model | Low-dimensional surrogate model that approximates high-fidelity simulations. |
19+
| **SVD** | Singular Value Decomposition | Matrix factorization method used in POD to identify dominant spatial modes. |
20+
421
## What is Reduced Order Modelling?
522
In scientific literature, the expression Reduced Order Modelling is related to a set of techniques devoted to the search for an optimal coordinate system onto which some parametric solutions of Partial Differential Equations (PDEs) - typically called High-Fidelity (HF) or Full Order Model (FOM) - can be represented. These methods are very useful in multi-query and real-time scenarios, when quick and efficient solutions of models are required, e.g. optimization, uncertainty quantification and inverse problems {cite:p}`Guo_Veroy2021, Degen2022`. Recently, with the developments in data-driven modelling, a lot of interest in the combination of data and models has been raised. ROM offers new opportunities both to integrate the model with experimental data in real-time and to define methods of sensor positioning, by providing efficient tools to compress the prior knowledge about the system coming from the parametrized mathematical model into low-dimensional forms.
623

@@ -26,7 +43,7 @@ Data-Driven Reduced Order Modelling (DDROM) {cite:p}`RMP_2024, DDMOR_CFR` is a s
2643

2744
The techniques implemented here follow the same underlying idea expressed in the Figure \ref{fig:darom}. They all share the typical offline/online paradigm of ROM techniques: the former is computationally expensive and it is performed only once, whereas the latter is cheap from the computational point of view and allows to have quick and reliable evaluations of the state of the system by merging background model knowledge and real evaluations of quantities of interest {cite:p}`MadayPBDW`.
2845

29-
During the offline (also called training) phase, a *high-fidelity* or Full Order Model (FOM), usually parameterised partial differential equations, is solved several times to obtain a collections of snapshots $\mathbf{u}_{FOM}\in\mathbb{R}^{\mathcal{N}_h}$, given $\mathcal{N}_h$ the dimension of the spatial mesh, which are dependent on some parameters $\boldsymbol{\mu}_n$; then, these snapshots are used to generate a reduced representation through a set of basis functions $\{\psi_n(\mathbf{x})\}$ of size $N$, in this way the degrees of freedom are decreased from $\mathcal{N}_h$ to $N$, provided that $\mathcal{N}_h>>N$. This allows for an approximation of any solution of the FOM as follows
46+
During the offline (also called training) phase, a *high-fidelity* or Full Order Model (FOM), usually parameterised partial differential equations, is solved several times to obtain a collection of snapshots $\mathbf{u}_{FOM}\in\mathbb{R}^{\mathcal{N}_h}$, given $\mathcal{N}_h$ the dimension of the spatial mesh, which are dependent on some parameters $\boldsymbol{\mu}_n$; then, these snapshots are used to generate a reduced representation through a set of basis functions $\{\psi_n(\mathbf{x})\}$ of size $N$, in this way the degrees of freedom are decreased from $\mathcal{N}_h$ to $N$, provided that $\mathcal{N}_h>>N$. This allows for an approximation of any solution of the FOM as follows
3047

3148
```{math}
3249
u_{FOM}(\mathbf{x} ; \boldsymbol{\mu}) \simeq \sum_{n=1}^N\alpha_n(\boldsymbol{\mu})\cdot \psi_n(\mathbf{x})
@@ -41,7 +58,7 @@ The online phase aims to obtain a quick and reliable way a solution of the FOM f
4158
The package **pyforce** comprises 3 subpackages: *offline*, *online* and *tools*. The first two collect the main functionalities, in particular the different DDROM techniques; whereas, the last includes importing and storing functions (from *dolfinx* directly or mapping from OpenFOAM), some backend classes for the snapshots and the calculation of integrals/norms. In the following, some figures are sketching how the different classes are connected to each other during the offline and online phases.
4259

4360
### Offline Phase
44-
Once the snapshots have been generated and collected into the class `FunctionsList`, the aims of this phase consists in generating a proper reduced representation and obtain an optimal sensors configuration.
61+
Once the snapshots have been generated and collected into the class `FunctionsList`, the aim of this phase consists in generating a proper reduced representation and obtain an optimal sensors configuration.
4562

4663
![Offline Phase](images/offline_classes.svg)
4764

images/geim_anl.png

147 KB
Loading

images/podi.png

855 KB
Loading

0 commit comments

Comments
 (0)