第33回:保存則をニューラルPDEへ入れる — mixed formulationとflux
ChatGPTで作る有限要素プログラム入門 Season 3 第9回(通算第33回)
はじめに――solutionだけを学ぶと,fluxはあとから微分するしかない
第27–32回では,主にstate \[ u_\theta \] のstrong residualを点で観測してきました.
しかしdiffusion problemでは, 実際に知りたい量が
\[ \boxed{ \text{flux}, \quad \text{mass balance}, \quad \text{local conservation} } \tag{1} \]であることも多くあります.
そこで今回はfluxをあとから微分で作るのではなく, 未知量としてnetworkに持たせます.
\[ \boxed{ \text{state }u_\theta + \text{flux }\boldsymbol q_\theta } \]
を同時に学べば,ニューラルPDEへ保存則をどこまで構造として入れられるか?
1.Poisson型問題とfluxの符号を固定する
bounded domain \(\Omega\subset\mathbb R^d\) で
\[ \boxed{ -\nabla\cdot(A\nabla u) = f \quad\text{in }\Omega, \qquad u=g \quad\text{on }\partial\Omega } \tag{2} \]を考えます. \(A(x)\) はsymmetric uniformly positive definiteとします.
本記事ではphysical fluxを
\[ \boxed{ \boldsymbol q = A\nabla u } \tag{3} \]と定義します. 従って
\[ \boxed{ \nabla\cdot\boldsymbol q = -f. } \tag{4} \]文献によっては \(-A\nabla u\) をfluxと呼ぶので, 符号は最初に固定します.
2.second-order PDEをfirst-order systemへ分解する
式 (2) は
\[ \boxed{ \begin{cases} \boldsymbol q-A\nabla u=0, \\[4pt] \nabla\cdot\boldsymbol q+f=0 \end{cases} \quad\text{in }\Omega } \tag{5} \]と書けます.
上の式はconstitutive relation, 下の式はequilibrium / conservation lawです.
3.mixed neural systemでは二つのnetwork outputを持つ
2次元なら一つのnetworkから
\[ \boxed{ N_\theta(x,y) = \bigl( u_\theta^{\rm raw}, q_{\theta,1}, q_{\theta,2} \bigr) } \tag{6} \]を出力させます.
zero Dirichlet boundary conditionなら
\[ \boxed{ u_\theta(x,y) = x(1-x)y(1-y) u_\theta^{\rm raw}(x,y) } \tag{7} \]としてstateだけhard constraintにできます.
fluxにはこのboundary factorを掛けません.
4.constitutive residual
fluxとstate gradientのずれを
\[ \boxed{ \boldsymbol r_{\rm c} = \boldsymbol q_\theta - A\nabla u_\theta } \tag{8} \]とします.
natural weighted normとして
\[ \boxed{ \mathcal L_{\rm c} = \int_\Omega \boldsymbol r_{\rm c}^{\top} A^{-1} \boldsymbol r_{\rm c} \,dx } \tag{9} \]を使えます.
5.equilibrium residual
保存則のdefectは
\[ \boxed{ r_{\rm e} = \nabla\cdot\boldsymbol q_\theta + f } \tag{10} \]です.
continuous equilibrium lossを
\[ \boxed{ \mathcal L_{\rm e} = \int_\Omega |r_{\rm e}|^2dx } \tag{11} \]とします.
6.mixed loss
最も単純には
\[ \boxed{ \mathcal J_{\rm mix} = \lambda_{\rm c} \mathcal L_{\rm c} + \lambda_{\rm e} \mathcal L_{\rm e} } \tag{12} \]を最小化します.
soft boundary conditionならさらに \[ \lambda_{\partial}\mathcal L_{\partial} \] を加えます. 今回はstateにhard Dirichlet conditionを入れて, flux structureへ集中します.
7.二つのresidualは両方必要である
\(\mathcal L_{\rm c}\) だけ小さくても
\[ \boldsymbol q_\theta \approx A\nabla u_\theta \]というだけで,PDEを解いているとは限りません.
逆に \(\mathcal L_{\rm e}\) だけ小さくても
\[ \nabla\cdot\boldsymbol q_\theta \approx -f \]というconservative fluxとstate \(u_\theta\) が無関係でも構いません.
従って
\[ \boxed{ \text{constitutive relation} + \text{equilibrium} } \tag{13} \]を同時に監査します.
8.continuous lossがzeroなら元のPDEへ戻る
もし
\[ \boldsymbol r_{\rm c}=0, \qquad r_{\rm e}=0 \]がcontinuousに成立すれば
\[ \boldsymbol q_\theta = A\nabla u_\theta, \]\[ \nabla\cdot(A\nabla u_\theta) = -f. \]
従ってboundary conditionと合わせて
\[ \boxed{ -\nabla\cdot(A\nabla u_\theta) = f } \tag{14} \]へ戻ります.
9.mixed first-order systemでは微分次数を一段下げられる
primal strong-form PINNでは
\[ -\nabla\cdot(A\nabla u_\theta) \]を直接計算するため,\(u_\theta\) のsecond derivativesが必要です.
mixed systemでは
\[ \boldsymbol q_\theta-A\nabla u_\theta \]と
\[ \nabla\cdot\boldsymbol q_\theta+f \]なので,
\[ \boxed{ u_\theta:\text{ first derivatives}, \qquad \boldsymbol q_\theta:\text{ first derivatives} } \tag{15} \]で済みます.
10.ただし「mixed」と呼ぶものを区別する
ここまでの式 (5)–(12) は strong first-order neural systemです.
classical mixed variational formulationでは
\[ \boxed{ \boldsymbol q \in H(\operatorname{div};\Omega), \qquad u\in L^2(\Omega) } \tag{16} \]を自然な空間として使います.
strong constitutive residual \[ \boldsymbol q-A\nabla u \] を使うneural formulationでは \(u\) にgradientを要求するので, classical mixed methodよりstrongなstate regularityを使っています.
11.classical mixed variational formulation
\(\boldsymbol q=A\nabla u\) の符号でintegration by partsすると
\[ \boxed{ (A^{-1}\boldsymbol q,\boldsymbol v) + (u,\nabla\cdot\boldsymbol v) = \langle g, \boldsymbol v\cdot\boldsymbol n \rangle_{\partial\Omega} } \tag{17} \]for all \[ \boldsymbol v\in H(\operatorname{div};\Omega), \]
および
\[ \boxed{ (\nabla\cdot\boldsymbol q,w) = -(f,w) } \tag{18} \]for all \[ w\in L^2(\Omega) \] となります.
zero Dirichletなら式 (17) の右辺はzeroです.
12.weak mixed residualをnetworkで評価することもできる
test functions \[ \boldsymbol v_j, \quad w_k \] を有限個選び,
\[ \boxed{ R^{(1)}_j = (A^{-1}\boldsymbol q_\theta,\boldsymbol v_j) + (u_\theta,\nabla\cdot\boldsymbol v_j) - \langle g,\boldsymbol v_j\cdot\boldsymbol n\rangle } \tag{19} \]と
\[ \boxed{ R^{(2)}_k = (\nabla\cdot\boldsymbol q_\theta,w_k) + (f,w_k) } \tag{20} \]を最小化するweak neural formulationも考えられます.
ここではpointwise strong residualとweak mixed residualを同一視しません.
13.保存則はintegral identityとして見る
任意のcontrol volume \(K\subset\Omega\) に対し, exact fluxは
\[ \int_K \nabla\cdot\boldsymbol q\,dx = -\int_Kf\,dx. \]divergence theoremから
\[ \boxed{ \int_{\partial K} \boldsymbol q\cdot\boldsymbol n_K\,ds + \int_Kf\,dx = 0. } \tag{21} \]これがlocal conservationです.
14.neural fluxのcellwise balance defect
neural fluxに対して
\[ \boxed{ B_K(\theta) = \int_{\partial K} \boldsymbol q_\theta\cdot\boldsymbol n_K\,ds + \int_Kf\,dx } \tag{22} \]を定義します.
\[ B_K=0 \] ならcell \(K\) のnet outgoing fluxとsourceがbalanceしています.
15.pointwise residual lossとlocal balanceは同じではない
もしcontinuousに \[ r_{\rm e}=0 \] なら全 \(K\) で \[ B_K=0 \] です.
しかしfinite collocationで
\[ r_{\rm e}(x_i)\approx0 \]でも,
\[ \boxed{ B_K \ne 0 } \tag{23} \]は可能です.
点の間にequilibrium defectが残るからです.
16.逆にbalanceだけzeroでも十分ではない
\[ B_K=0 \]
はcell内でpositive / negative residualがcancelしても成立します.
従って
\[ \boxed{ B_K=0 \quad\not\Rightarrow\quad r_{\rm e}=0 \text{ in }K. } \tag{24} \]local conservation defectと \[ \|r_{\rm e}\|_{L^2(K)} \] は別々に監査します.
17.balance lossを追加する
audit partition \[ \mathcal T_{\rm audit} \] を作り,
\[ \boxed{ \mathcal L_{\rm bal} = \sum_{K\in\mathcal T_{\rm audit}} \frac{ |B_K(\theta)|^2 }{ |K| } } \tag{25} \]を追加できます.
これはFEM trial meshである必要はありません. 保存則を測るcontrol-volume partitionです.
18.mixed neural lossを三つに分ける
実装上は
\[ \boxed{ \mathcal J = \lambda_{\rm c}\mathcal L_{\rm c} + \lambda_{\rm e}\mathcal L_{\rm e} + \lambda_{\rm bal}\mathcal L_{\rm bal} } \tag{26} \]とできます.
ただし三つは違うquantityなので,
\[ \boxed{ \lambda_{\rm c}, \quad \lambda_{\rm e}, \quad \lambda_{\rm bal} } \tag{27} \]をpoint countと混同せず記録します.
19.global smooth flux networkなら \(H(\operatorname{div})\) conformityは自然に満たしやすい
一つのsmooth global network \[ \boldsymbol q_\theta:\Omega\to\mathbb R^d \] を使えば, 通常
\[ \boxed{ \boldsymbol q_\theta \in H(\operatorname{div};\Omega) } \tag{28} \]を満たすだけのregularityを持ちます.
artificial cell interfaceを横切っても同じglobal functionなので, normal fluxはsingle-valuedです.
20.local networksを使うならnormal-flux jumpが現れる
domain decompositionでcellごとに別network \[ \boldsymbol q_\theta|_K \] を持つと, interior face \(F=K^+\cap K^-\) で
\[ \boxed{ J_F = \boldsymbol q_\theta^+\cdot\boldsymbol n^+ + \boldsymbol q_\theta^-\cdot\boldsymbol n^-. } \tag{29} \]\(H(\operatorname{div})\)-conforming fluxなら
\[ \boxed{ J_F=0. } \tag{30} \]従ってpiecewise neural fluxではnormal continuityも独立に課す必要があります.
21.jump penaltyはlocal conservationそのものではない
\[ J_F\approx0 \]
はinterface fluxの整合性を表します.
一方 \[ B_K\approx0 \]
はcell balanceです.
従って
\[ \boxed{ \text{normal continuity} \neq \text{local equilibrium}. } \tag{31} \]RT finite elementで両方が同時に現れるからといって, 一つのlossへ混ぜてはいけません.
22.manufactured solutionでfluxまでexactに知る
\[ \Omega=(0,1)^2, \qquad A=I, \]
\[ \boxed{ u^\ast(x,y) = \sin(\pi x)\sin(\pi y) } \tag{32} \]
とします.
すると
\[ \boxed{ \boldsymbol q^\ast = \nabla u^\ast = \begin{pmatrix} \pi\cos(\pi x)\sin(\pi y) \\ \pi\sin(\pi x)\cos(\pi y) \end{pmatrix}, } \tag{33} \]\[ \boxed{ f = 2\pi^2 \sin(\pi x)\sin(\pi y). } \tag{34} \]
23.state errorとflux errorを分けて測る
exact solutionが分かるtestでは
\[ \boxed{ E_u = |u_\theta-u^\ast|_{H^1(\Omega)} } \tag{35} \]と
\[ \boxed{ E_q = \|\boldsymbol q_\theta-\boldsymbol q^\ast\|_{L^2(\Omega)} } \tag{36} \]を別々に記録します.
さらに
\[ \boxed{ E_{\rm div} = \|\nabla\cdot\boldsymbol q_\theta+f\|_{L^2(\Omega)} } \tag{37} \]も独立なquality metricです.
24.mixed networkを実装する
class MixedNet(torch.nn.Module):
def __init__(self, width=64, depth=4):
super().__init__()
layers = [
torch.nn.Linear(2, width),
torch.nn.Tanh()
]
for _ in range(depth - 1):
layers += [
torch.nn.Linear(width, width),
torch.nn.Tanh()
]
layers += [
torch.nn.Linear(width, 3)
]
self.net = torch.nn.Sequential(*layers)
def forward(self, x):
raw = self.net(x)
xx = x[:, 0:1]
yy = x[:, 1:2]
u_raw = raw[:, 0:1]
q = raw[:, 1:3]
u = (
xx * (1.0 - xx)
* yy * (1.0 - yy)
* u_raw
)
return u, q
25.gradientとdivergenceを一階微分だけで作る
def mixed_residuals(model, x):
x = (
x.clone()
.detach()
.requires_grad_(True)
)
u, q = model(x)
grad_u = torch.autograd.grad(
u,
x,
grad_outputs=torch.ones_like(u),
create_graph=True
)[0]
qx = q[:, 0:1]
qy = q[:, 1:2]
dqx = torch.autograd.grad(
qx,
x,
grad_outputs=torch.ones_like(qx),
create_graph=True
)[0][:, 0:1]
dqy = torch.autograd.grad(
qy,
x,
grad_outputs=torch.ones_like(qy),
create_graph=True
)[0][:, 1:2]
div_q = dqx + dqy
xx = x[:, 0:1]
yy = x[:, 1:2]
f = (
2.0 * math.pi ** 2
* torch.sin(math.pi * xx)
* torch.sin(math.pi * yy)
)
r_const = q - grad_u
r_equil = div_q + f
return r_const, r_equil
26.sampled mixed loss
def mixed_loss(
model,
x,
lambda_const=1.0,
lambda_equil=1.0
):
r_const, r_equil = mixed_residuals(
model,
x
)
loss_const = torch.mean(
torch.sum(r_const ** 2, dim=1)
)
loss_equil = torch.mean(
r_equil ** 2
)
loss = (
lambda_const * loss_const
+ lambda_equil * loss_equil
)
return loss, loss_const, loss_equil
variable \(A\) では \[ A^{-1} \] weighted constitutive lossへ置き換えます.
27.finite samplingではmixed systemでも見落としは残る
collocation pointsを含まないopen set \(D\subset\Omega\) を取り,
\[ \psi\in C_c^\infty(D) \]をnonzeroとします.
\[ \boxed{ \widetilde u = u^\ast+\psi, \qquad \widetilde{\boldsymbol q} = \nabla\widetilde u } \tag{38} \]
とすればconstitutive residualはeverywhere zeroです.
さらにtraining pointsは \(\psi\) のsupport外なので
\[ \boxed{ r_{\rm e}(x_i)=0 } \tag{39} \]も成立します.
従ってmixed formulationにしても finite observation problemそのものは消えません.
28.local balance auditはfinite samplingの穴を別方向から見る
式 (38) のperturbationがあるcell \(K\) に対し, independent face / volume quadratureで
\[ B_K \]を測れば, training pointsでは見えなかったequilibrium defectを検出できる場合があります.
従って
\[ \boxed{ \text{point residual audit} + \text{integral flux-balance audit} } \tag{40} \]を組み合わせる意味があります.
29.ただしlocal balanceだけでもoscillationを見落とす
cell内で \[ r_{\rm e} \] が正負にoscillateすれば
\[ \int_Kr_{\rm e}\,dx=0 \]でも
\[ \|r_{\rm e}\|_{L^2(K)} \]は大きくなれます.
従って
\[ \boxed{ \text{integral conservation} + \text{residual norm} } \tag{41} \]を両方見る必要があります.
30.Raviart–Thomas reconstructionでfluxを構造化する
neural fluxをそのまま使う代わりに, audit mesh \(\mathcal T_h\) 上で
\[ \boxed{ \boldsymbol\sigma_h \in RT_0(\mathcal T_h) } \tag{42} \]へreconstructできます.
cell mean
\[ \boxed{ f_K = \frac1{|K|} \int_Kf\,dx } \tag{43} \]を使い,
\[ \boxed{ \nabla\cdot\boldsymbol\sigma_h|_K = -f_K } \tag{44} \]をexactly課します.
31.equilibrated projectionとして定義する
equilibrated RT spaceを
\[ \boxed{ \Sigma_h^{\rm eq} = \{ \boldsymbol\tau_h\in RT_0(\mathcal T_h): \nabla\cdot\boldsymbol\tau_h|_K=-f_K \ \forall K \} } \tag{45} \]とします.
neural fluxへ近いequilibrated fieldを
\[ \boxed{ \boldsymbol\sigma_h = \operatorname*{arg\,min}_{ \boldsymbol\tau_h\in\Sigma_h^{\rm eq} } \| A^{-1/2} ( \boldsymbol\tau_h-\boldsymbol q_\theta ) \|_{L^2(\Omega)} } \tag{46} \]として作れます.
32.reconstructed fluxはcellwise conservationをexactに満たす
式 (44) とdivergence theoremから
\[ \int_{\partial K} \boldsymbol\sigma_h\cdot\boldsymbol n_K\,ds = -|K|f_K. \]cell meanの定義より
\[ |K|f_K = \int_Kf\,dx. \]従って
\[ \boxed{ \int_{\partial K} \boldsymbol\sigma_h\cdot\boldsymbol n_K\,ds + \int_Kf\,dx = 0 } \tag{47} \]が各cellでexactly成立します.
33.これは「neural fluxがexactly conservative」という意味ではない
exact conservationを持つのは
\[ \boxed{ \boldsymbol\sigma_h } \]というpostprocessed / reconstructed fluxです.
raw neural output \[ \boldsymbol q_\theta \] がexactly conservativeだと主張してはいけません.
両者の差
\[ \boxed{ \| A^{-1/2} ( \boldsymbol\sigma_h-\boldsymbol q_\theta ) \|_{L^2} } \tag{48} \]自体がflux-structure defectの一つになります.
34.equilibrated fluxはcertificationへ接続できる
もしconforming state \(u_\theta\in H_0^1(\Omega)\) と, exactly equilibrated flux
\[ \nabla\cdot\boldsymbol\sigma=-f \]があれば,hypercircle型評価から
\[ \boxed{ \|u-u_\theta\|_A \le \| A^{-1/2} ( \boldsymbol\sigma-A\nabla u_\theta ) \|_{L^2} } \tag{49} \]を得られます.
RT\(_0\) で非piecewise-constant \(f\) を投影して使う場合は, data oscillationを別に扱う必要があります.
35.保存則,accuracy,certificationは三段階に分ける
| level | 確認するもの |
|---|---|
| neural residual | constitutive / equilibrium sampled loss |
| conservation audit | cellwise flux balance,normal continuity |
| certification | equilibrated \(H(\mathrm{div})\) flux + guaranteed bound |
この三つを同じ「physics-informed」という言葉でまとめない方が安全です.
36.mixed lossをpoint placementへ接続する
mixed formulationでは一種類のindicatorではなく
\[ \boxed{ \eta_{{\rm c},K}^2 \approx \int_K \boldsymbol r_{\rm c}^{\top} A^{-1} \boldsymbol r_{\rm c}\,dx, } \tag{50} \]\[ \boxed{ \eta_{{\rm e},K}^2 \approx \int_K |r_{\rm e}|^2dx, \qquad b_K=|B_K| } \tag{51} \]
を分けて持てます.
次のsampling pointsを constitutive defectから増やすのか, equilibrium defectから増やすのか, balance defectから増やすのかを選べます.
37.保存則から見たadaptive sampling
例えば
\[ \boxed{ \eta_K^2 = \alpha_{\rm c}\eta_{{\rm c},K}^2 + \alpha_{\rm e}\eta_{{\rm e},K}^2 + \alpha_{\rm b}\frac{|B_K|^2}{|K|} } \tag{52} \]というcombined indicatorを作り, 第32回のDörfler-like markingへ渡せます.
ただしweights \[ \alpha_{\rm c},\alpha_{\rm e},\alpha_{\rm b} \] はmethod design parameterであり, guaranteed estimatorの係数ではありません.
38.AIがmixed neural PDEで間違えやすい点
| mistake | 何が壊れるか |
|---|---|
| flux signを途中で変える | equilibrium式の符号が反転する |
| constitutive lossだけでmixed PDEを解いたとする | 保存則を課していない |
| equilibrium lossだけでstateも正しいとする | fluxとstateがdecoupleできる |
| pointwise div residualをlocal conservationと呼ぶ | integral balanceを確認していない |
| cell balance zeroならresidualもzeroとする | cell内cancellationを見落とす |
| global smooth fluxとpiecewise local fluxを同じに扱う | normal continuity conditionを落とす |
| RT reconstruction後の保存則をraw neural fluxの性質と呼ぶ | postprocessingとtrainingを混同する |
| sampled residual proxyをcertified boundと呼ぶ | equilibration / oscillation条件を飛ばす |
39.mixed-flux audit prompt
このmixed neural PDE implementationを数学的に監査してください.
(1) flux convention \(\boldsymbol q=A\nabla u\) と \(\nabla\cdot\boldsymbol q=-f\) の符号が一貫しているか,
(2) constitutive residualとequilibrium residualを別々に定義しているか,
(3) strong first-order neural systemとclassical mixed variational formulationを区別しているか,
(4) flux outputが必要な \(H(\operatorname{div})\) regularityを持つか,またpiecewise networkならnormal jumpを監査しているか,
(5) pointwise divergence residualとcellwise conservationを同一視していないか,
(6) cell balanceだけでcell内residual normを置き換えていないか,
(7) state error,flux error,divergence defectを別々に報告しているか,
(8) finite collocationによるbetween-point failureを残しているか,
(9) RT reconstructionを使う場合,raw neural fluxとequilibrated fluxを区別しているか,
(10) \(f\) のcell mean projectionとdata oscillationの扱いを明示しているか,
(11) guaranteed error boundを使う場合,exact equilibrationまたはoscillation correctionを確認しているか,
(12) adaptive samplingではconstitutive・equilibrium・balance indicatorsの役割を分離しているか
を順に確認してください.
40.第33回の結論
solutionだけを出力するPINNでは, fluxは
\[ A\nabla u_\theta \]として後から作ります.
mixed neural formulationでは
\[ \boxed{ (u_\theta,\boldsymbol q_\theta) } \tag{53} \]を同時に持ち,
\[ \boxed{ \boldsymbol q_\theta \approx A\nabla u_\theta, \qquad \nabla\cdot\boldsymbol q_\theta \approx -f } \tag{54} \]を別々に監査できます.
さらにcontrol-volume balance
\[ \boxed{ \int_{\partial K} \boldsymbol q_\theta\cdot\boldsymbol n_K\,ds + \int_Kf\,dx } \tag{55} \]を見ることで, pointwise residualとは別の保存則auditを持てます.
そしてRT reconstructionを加えれば
\[ \boxed{ \text{neural approximation} \longrightarrow \text{equilibrated }H(\operatorname{div})\text{ flux} \longrightarrow \text{certification} } \tag{56} \]まで接続できます.
保存則を入れるとは,residual lossに一項足すことではない. fluxという未知量,normal trace,local balance,equilibrationを区別して設計することである.
次回は一つのright-hand sideに対するsolutionではなく, 第34回:解を学ぶのではなくsolution operatorを学ぶ へ進みます.
参考文献・関連ページ
- P.-A. Raviart and J.-M. Thomas, “A mixed finite element method for 2nd order elliptic problems”, in Mathematical Aspects of Finite Element Methods, Lecture Notes in Mathematics 606, Springer, 1977, 292–315.
- D. Boffi, F. Brezzi and M. Fortin, Mixed Finite Element Methods and Applications, Springer, 2013.
- M. Raissi, P. Perdikaris and G. E. Karniadakis, “Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations”, Journal of Computational Physics 378 (2019), 686–707.
- 第14回:Raviart–Thomas要素を実装する — normal flux・Piola変換・向き
- 第16回:mixed Poissonを実装する — RT0–P0と局所保存
- 第23回:有限要素解の誤差を保証する — equilibrated fluxとhypercircle
- 第32回:点配置を誤差から変える — residual-adaptive sampling
