deeponet-fno
repository·main·Indexed 18 days ago
https://github.com/lu-group/deeponet-fnoA research repository providing implementations and datasets for comparing DeepONet and Fourier Neural Operators (FNO) across scientific computing benchmarks. It includes code and data for problems such as the Advection equation, Burgers' equation, Darcy problems (rectangular and triangular domains), linear instability waves, Navier-Stokes, and Euler equations. The repository features FNO1d and FNO2d architectures, spectral convolution implementations, and utilities for data normalization and loading from MAT or H5 files.
What's inside deeponet-fno
- This directory contains the implementation and data for solving the Darcy problem within a triangular domain that includes a notch. This is a specific scientific computing benchmark used for testing DeepONet and FNO models in the context of fluid flow in complex geometries.
Overview of DeepONet & FNO implementations
mainThis repository provides the data and code for the research paper comparing DeepONet and Fourier Neural Operators (FNO) using FAIR data. It includes implementations for various scientific computing problems, including fluid dynamics (Navier-Stokes, Euler equations), transport equations (Advection, Burgers'), and porous media flow (Darcy problems).Overview of Darcy problem in a rectangular domain (piecewise constant)
mainThis directory contains implementation and data related to the Darcy problem simulated in a rectangular domain using piecewise constant coefficients. This is typically used as a benchmark for operator learning models like DeepONet or FNO.Access Darcy problem data for triangular domains with notches
mainThe dataset for the Darcy problem in a triangular domain with a notch is hosted externally. You can access the data files via the following SharePoint link:
https://yaleedu-my.sharepoint.com/:f:/g/personal/lu_lu_yale_edu/Ei-oRTd9XvBEjwdAqOl1kUYBr2cGoeiJigfL1yuvS1mzaw?e=vUoqEbAccess Advection Equation Datasets (I, II, III)
mainThe repository provides datasets for three variations of the Advection equation. These datasets are hosted externally on SharePoint and can be accessed via the following links:
- Advection I and II: Data (I and II)
- Advection III: Data (III)
Access Darcy problem data for rectangular domains
mainThe dataset for the Darcy problem in a rectangular domain (piecewise constant) is sourced from the original Fourier Neural Operator repository. You can download the data via the provided SharePoint link.
Note: This data is specifically for the piecewise constant version of the Darcy problem in a rectangular domain.
Data Link: https://yaleedu-my.sharepoint.com/:f:/g/personal/lu_lu_yale_edu/Ei-oRTd9XvBEjwdAqOl1kUYBr2cGoeiJigfL1yuvS1mzaw?e=vUoqEbAccess DeepONet code for linear instability waves
mainThe implementation for DeepONet prediction of linear instability waves in high-speed boundary layers is documented in the research paper: P. Clark Di Leoni, L. Lu, C. Meneveau, G. E. Karniadakis, & T. A. Zaki. DeepONet prediction of linear instability waves in high-speed boundary layers. arXiv preprint arXiv:2105.08697, 2021.Access Burgers' equation data
mainThe Burgers' equation dataset used in this repository is sourced from the original Fourier Neural Operator implementation. You can download the data via the provided SharePoint link.
Data Link: https://yaleedu-my.sharepoint.com/:f:/g/personal/lu_lu_yale_edu/Ei-oRTd9XvBEjwdAqOl1kUYBr2cGoeiJigfL1yuvS1mzaw?e=vUoqEbAvailable datasets and problem implementations
mainThe repository is organized into datasets and corresponding code implementations for several scientific problems. You can find specific implementations in the
src/directory and their associated data in thedata/directory.Supported Problems:
- Burgers' equation:
data/burgersandsrc/burgers - Darcy problem (Rectangular, Piecewise constant):
data/darcy_rectangular_pwcandsrc/darcy_rectangular_pwc - Darcy problem (Triangular domain with notch):
data/darcy_triangular_notchandsrc/darcy_triangular_notch - Advection equation (Case II & III):
src/advection_II_III - Linear instability waves:
data/instability_waveandsrc/instability_wave
Other problems available (check directories for specific code/data):
- Darcy problem (Continuous, Pentagram with hole, Triangular domain)
- Electroconvection
- Compressible Euler equations
- Flapping airfoil
- Navier-Stokes (vorticity-velocity form)
- Regularized cavity flows (Steady/Unsteady)
- Burgers' equation:
Configure FNO2d Hyperparameters
mainWhen setting up an
FNO2dmodel, consider the following hyperparameter constraints observed in the implementation:modes1&modes2: These define the number of Fourier modes used in the spectral convolution. They should be chosen based on the grid resolution (e.g.,modes1$\le$ $n_t$,modes2$\le$ $n_x/2 + 1$).width: The hidden channel dimension. Increasingwidthincreases model capacity but significantly increases memory usage. For example, a width of 64 is used in the reference implementation, but higher values may cause Out-of-Memory (OOM) errors on consumer GPUs.- Input Channels: The current implementation of
FNO2dusesself.fc0 = nn.Linear(3, self.width), meaning it expects an input with 3 channels (typically representing the coefficient function, spatial coordinates, and time).
DeepONet Hyperparameters and Architecture
mainThe DeepONet architecture in this implementation is defined by the following parameters:
- Output dimension (
p): The dimension of the Branch and Trunk net outputs (default:100). - Branch net layers (
layer_B): Defines the structure of the Branch network. Example:[num, 128, 128, p]wherenumis the input dimension. - Trunk net layers (
layer_T): Defines the structure of the Trunk network. Example:[2, 128, 128, 128, p]where2represents the input coordinates (x, y). - Resolution (
h): The number of points used for resolution (default:num). - Batch size (
bs): Number of samples per training step (default:100). - Input size (
nx): The number of spatial points for the Trunk net (default:2295). - Epochs: Total training iterations (default:
20000).
- Output dimension (
Train a POD-based DeepONet for Darcy flow
mainThis script implements a POD-based (Proper Orthogonal Decomposition) DeepONet training pipeline for the Darcy triangular notch problem. It uses a hybrid architecture where a CNN processes input functions (branch net) and combines them with a pre-computed POD basis to reconstruct the solution field.
Workflow
- Data Loading: Uses
DataSetto generate minibatches and compute the POD basis. - Architecture:
- Branch Net: A combination of an
FNN(Feedforward Neural Network) and aCNN(Convolutional Neural Network) that maps input functions to coefficients. - POD Reconstruction: The output coefficients are multiplied by the
u_basisusingtf.einsumto predict the full solution field.
- Branch Net: A combination of an
- Training: Uses the
AdamOptimizerto minimize the mean squared error between the predicted and ground truth solution fields. - Evaluation: Periodically calculates the relative L2 error on a test batch.
- Saving: Uses
SaveDatato persist results.
Configuration Parameters
The script uses several hardcoded hyperparameters that define the network architecture and data dimensions:
p: Output dimension of Branch/Trunk.modes: Number of POD modes.s,s_in: Dimensions for the FNN layers.layer_B: Dimensions for the Branch net output layers.h,w: Resolution for the CNN input.bs: Batch size.nx: Size of the input for the Trunk net.
Requirements
- TensorFlow 1.x (
tensorflow.compat.v1) - NumPy
- Matplotlib
- Local modules:
dataset,fnn,conv,savedata
import os # Set GPU device os.environ['CUDA_VISIBLE_DEVICES']='1' # The script is executed as a standalone training entrypoint if __name__ == "__main__": main()- Data Loading: Uses