|
| 1 | +# AMGNet for Flow Field Prediction around a Cylinder |
| 2 | + |
| 3 | +## 1. Background |
| 4 | + |
| 5 | +This case utilizes the AM-gNet (Anisotropic Mesh-based Graph Network) model to predict the steady-state flow field around a cylinder. The model is trained on simulation data generated on a specific mesh and can then be used to rapidly predict the flow field (velocity and pressure) for different inlet velocities. |
| 6 | + |
| 7 | +This example is based on a graph neural network, and the input is unstructured mesh data. |
| 8 | + |
| 9 | +## 2. How to run |
| 10 | + |
| 11 | +### 2.1. Prepare data and environment |
| 12 | + |
| 13 | +The dataset required for this case can be downloaded from [GitHub](https://github.com/PaddlePaddle/PaddleScience/tree/develop/examples/amgnet/data). After downloading, place the `cylinderdata` directory in the `amgnet/data/` folder. |
| 14 | + |
| 15 | +Please ensure that PaddlePaddle and PaddleScience are installed correctly. You may also need to install the dependencies for this case: |
| 16 | + |
| 17 | +```bash |
| 18 | +pip install -r requirements.txt |
| 19 | +``` |
| 20 | + |
| 21 | +### 2.2. Run commands |
| 22 | + |
| 23 | +You can run the different modes of this case using the main script `amgnet_cylinder.py`. The running mode is controlled by the `mode` parameter. |
| 24 | + |
| 25 | +#### Train the model |
| 26 | + |
| 27 | +```bash |
| 28 | +python amgnet_cylinder.py mode=train |
| 29 | +``` |
| 30 | + |
| 31 | +#### Evaluate the model |
| 32 | + |
| 33 | +Use the following command to evaluate the model's performance on the test set. You need to specify the path to the pretrained model. |
| 34 | + |
| 35 | +```bash |
| 36 | +python amgnet_cylinder.py mode=eval EVAL.pretrained_model_path=/path/to/your/pretrained_model.pdparams |
| 37 | +``` |
| 38 | +*Note: We have provided a pretrained model in the configuration file `amgnet/conf/amgnet_cylinder.yaml`, which will be downloaded automatically.* |
| 39 | + |
| 40 | +#### Export the model |
| 41 | + |
| 42 | +This command exports the trained model to a static inference format. |
| 43 | + |
| 44 | +```bash |
| 45 | +python amgnet_cylinder.py mode=export |
| 46 | +``` |
| 47 | +The exported model will be saved in the directory specified by `INFER.export_path` in the YAML configuration file (defaults to `./inference/amgnet_cylinder`). |
| 48 | + |
| 49 | +#### Run Python inference |
| 50 | + |
| 51 | +This command uses the exported model to perform inference on the test data. |
| 52 | + |
| 53 | +```bash |
| 54 | +python amgnet_cylinder.py mode=infer |
| 55 | +``` |
| 56 | + |
| 57 | +## 3. Results visualization |
| 58 | + |
| 59 | +After running training, evaluation, or inference, the script will generate visualization images of the predicted flow field compared to the ground truth. These images will be saved in the output directory (e.g., `outputs_amgnet_cylinder/...`). |
| 60 | + |
| 61 | +## 4. Parameter explanation |
| 62 | + |
| 63 | +The model and training parameters are controlled by the configuration file `amgnet/conf/amgnet_cylinder.yaml`. |
| 64 | + |
| 65 | +### Model Parameters (`MODEL`) |
| 66 | +- `input_dim`: Dimension of the node input features. |
| 67 | +- `output_dim`: Dimension of the model output. |
| 68 | +- `latent_dim`: Dimension of the latent space in the graph network. |
| 69 | +- `num_layers`: Number of layers in the encoder/decoder. |
| 70 | +- `message_passing_steps`: Number of message passing steps in the processor. |
| 71 | + |
| 72 | +### Training Parameters (`TRAIN`) |
| 73 | +- `epochs`: Total number of training epochs. |
| 74 | +- `learning_rate`: Learning rate for the optimizer. |
| 75 | +- `batch_size`: Training batch size. |
| 76 | +- `eval_freq`: Frequency (in epochs) for running evaluation during training. |
| 77 | + |
| 78 | +### Inference Parameters (`INFER`) |
| 79 | +- `batch_size`: Batch size for inference (Note: AMGNet only supports a batch size of 1). |
| 80 | +- `pretrained_model_path`: Path to the model weights used for exporting. |
| 81 | +- `export_path`: Directory to save the exported inference model. |
0 commit comments