Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
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.
40 changes: 40 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,40 @@
"""
Hybrid ML-SU2 Coupling Example
Demonstrates real-time coupling between SU2 solver and PyTorch ML model
"""
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:
print("Initializing SU2-PyTorch Hybrid Coupling Example...")

surrogate_model = SimpleSurrogate(input_dim=1, output_dim=1)
optimizer = torch.optim.Adam(surrogate_model.parameters(), lr=0.001)
Comment thread Fixed
criterion = nn.MSELoss()
Comment thread Fixed

for i in range(10):
Comment thread Fixed
dummy_input = torch.randn(1, 1)
dummy_target = torch.randn(1, 1)
optimizer.zero_grad()
output = surrogate_model(dummy_input)
loss = criterion(output, dummy_target)
loss.backward()
optimizer.step()

print("Setup complete. Ready for hybrid simulation.")

MPI.Finalize()
Loading