Transolver is a neural operator model based on the Transformer architecture for learning solution operators of Partial Differential Equations (PDEs). The core innovation of this model lies in its Physics Attention mechanism, which can efficiently handle physical field prediction problems on irregular meshes.
Compared with traditional Transformer models, Transolver has the following characteristics:
Physics-aware Attention Mechanism: Aggregates irregular grid points into regular representations through slice technology, which not only retains spatial physical information, but also greatly reduces computational complexity
Flexible Geometric Adaptability: Able to handle geometric bodies of arbitrary shapes and unstructured meshes
Efficient Computational Performance: Through the slice attention mechanism, the computational complexity is reduced from \(O(N^2)\) to \(O(NG)\), where \(N\) is the number of grid points and \(G\) is the number of slices
This case uses the Transolver model to learn the velocity field and pressure field distribution of the external flow field of a car on the ShapeNet Car dataset. This is a typical Computational Fluid Dynamics (CFD) surrogate modeling problem. By learning a large amount of car shape and corresponding flow field data, the model can quickly predict the flow field distribution of new car shapes, thereby greatly reducing the computational cost of CFD simulation.
The goal of this case is to establish a mapping relationship between car geometry and its surrounding flow field (velocity field and pressure field). Specifically:
Input: Grid point coordinates of the car surface and surrounding space \(\mathbf{x} \in \mathbb{R}^{N \times 7}\), where \(N\) is the number of grid points, and 7 dimensions include geometric information such as spatial coordinates and normal vectors
Output: Velocity vector \(\mathbf{v} \in \mathbb{R}^{N \times 3}\) and pressure scalar \(p \in \mathbb{R}^{N \times 1}\) at each grid point
The training goal is to minimize the mean square error between the predicted flow field and the real CFD simulation results, while ensuring that the model can accurately predict key aerodynamic parameters such as the drag coefficient of the car.
Next, we will explain how to convert the problem into PaddleScience code step by step and solve the problem using deep learning methods.
In order to quickly understand PaddleScience, only key steps such as model construction, constraint construction, and optimizer construction are described below, while other details please refer to API Documentation.
In this problem, we need to establish a mapping function \(f: \mathbb{R}^{N \times 7} \to \mathbb{R}^{N \times 4}\) from grid point coordinates \(\mathbf{x}\) to flow field variables \((\mathbf{v}, p)\), that is:
\[
(\mathbf{v}, p) = f(\mathbf{x})
\]
Here we use the Transolver model to represent this mapping function, expressed in PaddleScience code as follows:
deftrain(cfg:DictConfig):# set modelmodel=ppsci.arch.Transolver(**cfg.MODEL)
In order to accurately and quickly access the value of specific variables during calculation, we specify here that the input variable name of the network model is ["x"], and the output variable names are ["velo_vec", "press"]. These names are consistent with subsequent code.
The detailed configuration of the model is as follows:
Disaggregation: Map slice representations back to original grid points
\[
h' = S \cdot \text{Attn}(Q, K, V) \cdot W
\]
Through this mechanism, the computational complexity is reduced from \(O(N^2)\) to \(O(NG + G^2)\), which can significantly improve efficiency when \(G \ll N\).
# set constrainttrain_data,val_data,coef_norm=load_train_val_fold(cfg.DATA.data_dir,cfg.DATA.val_fold_id,cfg.DATA.save_dir,preprocessed=cfg.DATA.preprocessed,)train_dataset=ShapeNetCarDataset(cfg.DATA.input_keys,cfg.DATA.label_keys,train_data,use_cfd_mesh=cfg.DATA.use_cfd_mesh,r=cfg.DATA.r,training=True,)
# set optimizer## Slightly differnt from transolver's lr setting(OneCycleLR)lr=ppsci.optimizer.lr_scheduler.ExponentialDecay(cfg.TRAIN.epochs,len(sup_constraint.data_loader),cfg.TRAIN.lr.max_lr,gamma=cfg.TRAIN.lr.gamma,decay_steps=cfg.TRAIN.lr.decay_steps,warmup_epoch=cfg.TRAIN.lr.warmup_epoch,warmup_start_lr=cfg.TRAIN.lr.max_lr/25.0,)()optimizer=ppsci.optimizer.Adam(lr)(model)
# set validatorval_dataset=ShapeNetCarDataset(cfg.DATA.input_keys,cfg.DATA.label_keys,val_data,use_cfd_mesh=cfg.DATA.use_cfd_mesh,r=cfg.DATA.r,training=False,)defval_metric_func(output,label):velo_label=label[cfg.DATA.label_keys[0]]press_label=label[cfg.DATA.label_keys[1]]surf_mask=label["surf"]loss_velo_vec=F.mse_loss(output[cfg.DATA.label_keys[0]],velo_label,"none").mean(axis=0)loss_velo=loss_velo_vec.mean()loss_press=F.mse_loss(output[cfg.DATA.label_keys[1]][surf_mask],press_label[surf_mask])return{"press":loss_press,"velo_vec":loss_velo,}validator=ppsci.validate.SupervisedValidator({"dataset":val_dataset,"batch_size":cfg.EVAL.batch_size,"num_workers":0,},metric={"mse":ppsci.metric.FunctionalMetric(val_metric_func),},name="validator",)validator={validator.name:validator}
In the evaluation phase, in addition to calculating conventional error metrics, the prediction error of drag coefficient and Spearman correlation coefficient will also be calculated:
After model training is completed, the prediction performance can be evaluated on the validation set. The main evaluation metrics include:
Relative L2 Error of Velocity Field: Measure the overall accuracy of velocity field prediction
Relative L2 Error of Pressure Field: Measure the overall accuracy of pressure field prediction
Relative Error of Drag Coefficient: Evaluate the prediction accuracy of key aerodynamic parameters
Spearman Correlation Coefficient: Evaluate the accuracy of drag coefficient ranking of different car shapes
Through training, the Transolver model can predict the flow field distribution around the car with high accuracy, significantly reducing calculation time compared to traditional CFD simulation, providing a fast surrogate model for car aerodynamic shape optimization.