Skip to content

Commit

Permalink
【hydra No.10】labelfree_DNN_surrogate (#591)
Browse files Browse the repository at this point in the history
* Add poiseuille_flow hydra

* Fix

* Fix
  • Loading branch information
co63oc authored Oct 26, 2023
1 parent da4f020 commit b3fad87
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 86 deletions.
44 changes: 28 additions & 16 deletions docs/zh/examples/labelfree_DNN_surrogate.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# LabelFree-DNN-Surrogate (Aneurysm flow & Pipe flow)

=== "模型训练命令"

``` sh
python poiseuille_flow.py
```

=== "模型评估命令"

``` sh
python poiseuille_flow.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/poiseuille_flow/poiseuille_flow_pretrained.pdparams
```

## 1. 背景简介

流体动力学问题的数值模拟主要依赖于使用多项式将控制方程在空间或/和时间上离散化为有限维代数系统。由于物理的多尺度特性和对复杂几何体进行网格划分的敏感性,这样的过程对于大多数实时应用程序(例如,临床诊断和手术计划)和多查询分析(例如,优化设计和不确定性量化)。在本文中,我们提供了一种物理约束的 DL 方法,用于在不依赖任何模拟数据的情况下对流体流动进行代理建模。 具体来说,设计了一种结构化深度神经网络 (DNN) 架构来强制执行初始条件和边界条件,并将控制偏微分方程(即 Navier-Stokes 方程)纳入 DNN的损失中以驱动训练。 对与血液动力学应用相关的许多内部流动进行了数值实验,并研究了流体特性和域几何中不确定性的前向传播。结果表明,DL 代理近似与第一原理数值模拟之间的流场和前向传播不确定性非常吻合。
Expand Down Expand Up @@ -79,15 +91,15 @@ $$

上式中 $f_1, f_2, f_3$ 即为 MLP 模型本身,$transform_{input}, transform_{output}$, 表示施加额外的结构化自定义层,用于施加约束和丰富输入,用 PaddleScience 代码表示如下:

``` py linenums="95"
``` py linenums="78"
--8<--
examples/pipe/poiseuille_flow.py:95:98
examples/pipe/poiseuille_flow.py:78:80
--8<--
```

``` py linenums="123"
``` py linenums="105"
--8<--
examples/pipe/poiseuille_flow.py:123:129
examples/pipe/poiseuille_flow.py:105:111
--8<--
```

Expand All @@ -99,9 +111,9 @@ examples/pipe/poiseuille_flow.py:123:129

由于本案例使用的是 Navier-Stokes 方程的2维稳态形式,因此可以直接使用 PaddleScience 内置的 `NavierStokes`

``` py linenums="134"
``` py linenums="117"
--8<--
examples/pipe/poiseuille_flow.py:134:137
examples/pipe/poiseuille_flow.py:117:121
--8<--
```

Expand All @@ -111,9 +123,9 @@ examples/pipe/poiseuille_flow.py:134:137

本文中本案例的计算域和参数自变量 $\nu$ 由`numpy`随机数生成的点云构成,因此可以直接使用 PaddleScience 内置的点云几何 `PointCloud` 组合成空间的 `Geometry` 计算域。

``` py linenums="67"
``` py linenums="52"
--8<--
examples/pipe/poiseuille_flow.py:67:94
examples/pipe/poiseuille_flow.py:52:75
--8<--
```

Expand Down Expand Up @@ -175,9 +187,9 @@ examples/pipe/poiseuille_flow.py:67:94

以作用在流体域内部点上的 `InteriorConstraint` 为例,代码如下:

``` py linenums="143"
``` py linenums="128"
--8<--
examples/pipe/poiseuille_flow.py:143:164
examples/pipe/poiseuille_flow.py:128:146
--8<--
```

Expand All @@ -201,19 +213,19 @@ examples/pipe/poiseuille_flow.py:67:94

训练过程会调用优化器来更新模型参数,此处选择较为常用的 `Adam` 优化器。

``` py linenums="131"
``` py linenums="127"
--8<--
examples/pipe/poiseuille_flow.py:131:132
examples/pipe/poiseuille_flow.py:114:114
--8<--
```

#### 2.2.7 模型训练、评估与可视化

完成上述设置之后,只需要将上述实例化的对象按顺序传递给 `ppsci.solver.Solver`,然后启动训练。

``` py linenums="167"
``` py linenums="152"
--8<--
examples/pipe/poiseuille_flow.py:167:181
examples/pipe/poiseuille_flow.py:152:164
--8<--
```

Expand All @@ -223,9 +235,9 @@ examples/pipe/poiseuille_flow.py:167:181

2. 当我们选取截断高斯分布的动力粘性系数 ${\nu}$ 采样(均值为 $\hat{\nu} = 10^{−3}$, 方差 $\sigma_{\nu}​=2.67×10^{−4}$),中心处速度的概率密度函数和解析解对比

``` py linenums="185"
``` py linenums="166"
--8<--
examples/pipe/poiseuille_flow.py:185:293
examples/pipe/poiseuille_flow.py:166:274
--8<--
```

Expand Down
74 changes: 74 additions & 0 deletions examples/pipe/conf/poiseuille_flow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
hydra:
run:
# dynamic output directory according to running time and override name
dir: outputs_poiseuille_flow/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
job:
name: ${mode} # name of logfile
chdir: false # keep current working direcotry unchaned
config:
override_dirname:
exclude_keys:
- TRAIN.checkpoint_path
- TRAIN.pretrained_model_path
- EVAL.pretrained_model_path
- mode
- output_dir
- log_freq
sweep:
# output directory for multirun
dir: ${hydra.run.dir}
subdir: ./

# general settings
mode: train # running mode: train/eval
seed: 42
output_dir: ${hydra:run.dir}

# set working condition
NU_MEAN: 0.001
NU_STD: 0.9
L: 1.0 # length of pipe
R: 0.05 # radius of pipe
RHO: 1 # density
P_OUT: 0 # pressure at the outlet of pipe
P_IN: 0.1 # pressure at the inlet of pipe
N_x: 10
N_y: 50
N_p: 50
X_IN: 0

# model settings
MODEL:
u_net:
input_keys: ["sin(x)", "cos(x)", "y", "nu"]
output_keys: ["u"]
num_layers: 3
hidden_size: 50
activation: "swish"
v_net:
input_keys: ["sin(x)", "cos(x)", "y", "nu"]
output_keys: ["v"]
num_layers: 3
hidden_size: 50
activation: "swish"
p_net:
input_keys: ["sin(x)", "cos(x)", "y", "nu"]
output_keys: ["p"]
num_layers: 3
hidden_size: 50
activation: "swish"

# training settings
TRAIN:
epochs: 3000
batch_size:
pde_constraint: 128
learning_rate: 5.0e-3
eval_during_train: false
save_freq: 10
pretrained_model_path: null
checkpoint_path: null

# evaluation settings
EVAL:
pretrained_model_path: null
Loading

0 comments on commit b3fad87

Please sign in to comment.