# README: PINNs for CFD Validation with DeepXDE and OpenFOAM

## Overview
This repository implements Physics-Informed Neural Networks (PINNs) using DeepXDE and OpenFOAM for 2D laminar lid-driven cavity flow (Re=40, 100). PINNs solve Navier-Stokes equations mesh-free, while OpenFOAM uses finite-volume methods. Results are compared by evaluating PINN predictions on points from OpenFOAM's .vtk output.

## Structure
- `deepxde/`: PINN scripts (`lid\_driven\_cavity.py`), models (`model-lid-re40.pt`, `model-lid-re100.pt`).
- `openfoam/`: OpenFOAM cases (`re40\_case/`, `re100\_case/`), .vtk results.
- `comparison/`: Comparison script (`compare\_results.py`), plots (`plots/`).
- `figures/`: Report images.
- `report.tex`, `references.bib`: LaTeX report and bibliography.

## Prerequisites
- Python 3.8+: `deepxde`, `pyvista`, `numpy`, `matplotlib`, `tensorflow`/`pytorch`.
- OpenFOAM v2406
- Optional: ParaView.

## DeepXDE Workflow
1. Define Navier-Stokes PDEs and residuals.
2. Set geometry: Unit square [0,1]x[0,1].
3. Apply BCs: Top wall (u=1, v=0), others (u=0, v=0), p=0 at (0.5, 0.5).
4. Neural network: 6 layers, 50 neurons, tanh activation.
5. Train: 20,000 iterations, Adam (1e-3), 20,000 interior + 4,000 boundary points.
Run and save the parameters for each case and load them to evaluate error between Openfoam Result.
python lid_driven_cavity.py --re 40
python lid_driven_cavity.py --re 100

## Openfoam Workflow:

Setup: Unit square, same BCs, ν=1/Re.
Mesh: blockMesh (100x100 grid).
Solve: icoFoam until steady-state.
Export: foamToVTK -latestTime.
Run:

cd openfoam/re40_case
blockMesh
icoFoam
foamToVTK -latestTime
Comparison of results from Openfoam and PINN(DeepXDE)
1.Extract OpenFOAM Data:
Use pyvista to read .vtk files (e.g., cavity_Re40.vtk).
Extract grid points (x, y) and fields: u_ref, v_ref, p_ref.
2.Evaluate PINN:
Load trained model (e.g., model-lid-re40.pt).
Predict u_pred, v_pred, p_pred on the .vtk grid points.
Compute Errors:
Absolute errors: |u_pred - u_ref|, |v_pred - v_ref|, |p_pred - p_ref|.
L2-norm errors across the domain.
4.Visualize:

Contour plots: Velocity magnitude, pressure, streamlines.
Error maps: Absolute differences.
Plots saved in comparison/plots/ using Matplotlib.


### Change the Reynolds number in both the code and openfoam case setup according to the problem simulating.For example , if you are simulating for Re = 40 case , change the Reynolds number in the PINN code and also in openfoam case.

1.After getting the vtk file from openfoam simulation , extract the grid points (x,y) and evaluate PINN performance on those grid points.
2.Compare both the results by plotting error.
