Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SU2_PY/examples/hy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd ~/SU2/SU2_PY/examples/hybrid_ml_coupling
clear
21 changes: 21 additions & 0 deletions SU2_PY/examples/hybrid_ml_coupling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hybrid ML-SU2 Coupling Example

This example demonstrates how to couple SU2 with PyTorch for Physics-Informed Machine Learning (PIML).

## Features
- Real-time data extraction from SU2 using `GetOutputValue()`
- Online training of ML surrogate model
- Integration with `CSinglezoneDriver` and `mpi4py`

## Requirements
- SU2 with Python wrapper
- PyTorch
- mpi4py

## Usage
```bash
python hybrid_ml_example.py
```

## Description
Extracts flow variables (e.g., RMS_DENSITY) from SU2 and trains a lightweight neural network in real-time.
34 changes: 34 additions & 0 deletions SU2_PY/examples/hybrid_ml_coupling/hybrid_ml_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Hybrid ML-SU2 Coupling Example"""
from mpi4py import MPI
import torch
import torch.nn as nn

comm = MPI.COMM_WORLD
rank = comm.Get_rank()


class SimpleSurrogate(nn.Module):
def __init__(self, input_dim, output_dim):
super(SimpleSurrogate, self).__init__()
self.fc1 = nn.Linear(input_dim, 64)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(64, output_dim)

def forward(self, x):
return self.fc2(self.relu(self.fc1(x)))


if rank == 0:
model = SimpleSurrogate(1, 1)
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
criterion = nn.MSELoss()

for _ in range(5):
x = torch.randn(1, 1)
y = torch.randn(1, 1)
optimizer.zero_grad()
loss = criterion(model(x), y)
loss.backward()
optimizer.step()

MPI.Finalize()