{ "cells": [ { "cell_type": "markdown", "id": "36dccb97", "metadata": {}, "source": [ "# (Generalised) Empirical Interpolation Method - (G)EIM\n", "\n", "This notebook presents the basic applications of the (Generalised) Empirical Interpolation Method ((G)EIM) for the dimensionality reduction and sensor placement in fluid dynamics problems. The (G)EIM is a powerful technique that allows to approximate complex functions using a reduced number of basis functions and interpolation points, making it suitable for real-time simulations and monitoring applications.\n", "\n", "In this tutorial, you will learn:\n", "\n", "- How to build `FunctionsList` objects from spatio-temporal matrices of data.\n", "- How to use the EIM and GEIM classes in *pyforce* to perform dimensionality reduction and sensor placement.\n", "- How to reconstruct the field from sparse measurements using the EIM and GEIM methods." ] }, { "cell_type": "markdown", "id": "a6d0a5a7", "metadata": {}, "source": [ "The data for this tutorial comes from a [ROM4FOAM](https://github.com/ERMETE-Lab/ROSE-ROM4FOAM) tutorial, the Buoyant Cavity (see [Introini et al. (2023)](https://doi.org/10.1016/j.anucene.2022.109538)). It is a steady-state simulation of a square cavity with a hot left wall and a cold right wall, leading to natural convection inside the cavity. The simulation is performed using OpenFOAM 2412: the results have been stored in an `npz` file." ] }, { "cell_type": "markdown", "id": "642b98b5", "metadata": {}, "source": [ "## Import OpenFOAM cases from npz files" ] }, { "cell_type": "markdown", "id": "18695ee2", "metadata": {}, "source": [ "The data are parametric with respect to the Reynolds and Richardson number (Re and Ri, respectively). The snapshots of velocity, pressure and temperature are stored in an `npz` file, which can be easily loaded using the `numpy` library. Each variable is stored as a 2D array, where each column represents a snapshot at a given parameter value, and each row represents a spatial point in the domain.\n", "\n", "`FunctionsList` objects can be built directly from these matrices, specifying the spatial coordinates of the points in the domain.\n", "\n", "Among the available variables, we will focus on the temperature field, which is generally easier to measure." ] }, { "cell_type": "code", "execution_count": 1, "id": "4a85ae0b", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "_data = np.load('Datasets/BuoyantCavity_OF2412/buoyant_cavity.npz', allow_pickle=True)\n", "\n", "parameters = _data['parameters']\n", "\n", "field = 'T'\n", "\n", "from pyforce.tools.functions_list import FunctionsList\n", "dataset = FunctionsList(snap_matrix = _data[field] - 300)" ] }, { "cell_type": "markdown", "id": "0c980f23", "metadata": {}, "source": [ "Let us also extract the grid needed by *pyforce* using the `mesh` method, to make a plot of the snapshots" ] }, { "cell_type": "code", "execution_count": 2, "id": "b3d7e852", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
| UnstructuredGrid | Information |
|---|---|
| N Cells | 16384 |
| N Points | 33282 |
| X Bounds | 0.000e+00, 1.000e+00 |
| Y Bounds | 0.000e+00, 1.000e+00 |
| Z Bounds | 0.000e+00, 1.000e-01 |
| N Arrays | 0 |