Skip to content

Commit f215363

Browse files
committed
fix github rendering problem for periodic bc readme
1 parent fcadc45 commit f215363

1 file changed

Lines changed: 60 additions & 60 deletions

File tree

applications/periodic_bc/README.md

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ filters such as `Warp By Scalar`.
2626

2727
The example solves
2828

29-
$$
29+
```math
3030
-\nabla\cdot(\theta\nabla u)=f
3131
\quad\mathrm{in}\quad \Omega=(0,1)^2,
32-
$$
32+
```
3333

3434
with homogeneous Dirichlet boundary conditions on the bottom and top edges,
3535

36-
$$
36+
```math
3737
u(x,0)=u(x,1)=0,
38-
$$
38+
```
3939

4040
and periodicity between the left and right edges,
4141

42-
$$
42+
```math
4343
u(0,y)=u(1,y).
44-
$$
44+
```
4545

4646
The source term is
4747

48-
$$
48+
```math
4949
f(x,y)=x\sin(5\pi y)
5050
+\exp\left(-\frac{(x-0.5)^2+(y-0.5)^2}{0.02}\right).
51-
$$
51+
```
5252

5353
The material parameter `theta` is treated as the differentiable scalar
5454
parameter in the AD check.
@@ -59,10 +59,10 @@ Let `u_full` be the full vector of nodal degrees of freedom and `u_red` be the
5959
reduced vector after eliminating duplicate periodic degrees of freedom. The
6060
periodic constraint is represented as
6161

62-
$$
62+
```math
6363
\boldsymbol{u}_{\mathrm{full}}
6464
=\boldsymbol{P}\boldsymbol{u}_{\mathrm{red}}.
65-
$$
65+
```
6666

6767
Here `P_mat` has shape `(N, M)`, where `N` is the number of full DOFs before
6868
applying periodic constraints and `M` is the number of independent DOFs after
@@ -75,55 +75,55 @@ or adjoint loads back to the independent reduced DOFs.
7575
For this example, every right-boundary node is matched to the corresponding
7676
left-boundary node shifted by
7777

78-
$$
78+
```math
7979
(x,y)\mapsto(x+1,y).
80-
$$
80+
```
8181

8282
`periodic_boundary_conditions` constructs `P_mat` by assigning the slave
8383
right-boundary DOF to the same reduced column as its master left-boundary DOF.
8484
The nonlinear residual and tangent are then assembled in reduced coordinates:
8585

86-
$$
86+
```math
8787
\boldsymbol{R}_{\mathrm{red}}
8888
=\boldsymbol{P}^{T}\boldsymbol{R}_{\mathrm{full}},
8989
\qquad
9090
\boldsymbol{K}_{\mathrm{red}}
9191
=\boldsymbol{P}^{T}\boldsymbol{K}_{\mathrm{full}}\boldsymbol{P}.
92-
$$
92+
```
9393

9494
Dirichlet rows are eliminated before applying the periodic projection.
9595

9696
## Toy problem
9797

9898
Consider a tiny non-FEM system with four full unknowns,
9999

100-
$$
100+
```math
101101
\boldsymbol{u}_{\mathrm{full}}
102102
=
103103
\begin{bmatrix}
104104
u_0 & u_1 & u_2 & u_3
105105
\end{bmatrix}^{T},
106-
$$
106+
```
107107

108108
and impose one periodic constraint:
109109

110-
$$
110+
```math
111111
u_3=u_0.
112-
$$
112+
```
113113

114114
Only three independent unknowns remain:
115115

116-
$$
116+
```math
117117
\boldsymbol{u}_{\mathrm{red}}
118118
=
119119
\begin{bmatrix}
120120
a & b & c
121121
\end{bmatrix}^{T}.
122-
$$
122+
```
123123

124124
The expansion matrix is
125125

126-
$$
126+
```math
127127
\boldsymbol{P}
128128
=
129129
\begin{bmatrix}
@@ -140,14 +140,14 @@ $$
140140
\begin{bmatrix}
141141
a\\ b\\ c\\ a
142142
\end{bmatrix}.
143-
$$
143+
```
144144

145145
Thus `N = 4`, `M = 3`, and the slave DOF `u_3` reuses the same reduced column as
146146
the master DOF `u_0`.
147147

148148
Suppose the full residual is
149149

150-
$$
150+
```math
151151
\boldsymbol{R}_{\mathrm{full}}
152152
(\boldsymbol{u},\theta)
153153
=
@@ -168,11 +168,11 @@ $$
168168
\begin{bmatrix}
169169
1\\0\\0\\1
170170
\end{bmatrix}.
171-
$$
171+
```
172172

173173
The reduced residual is
174174

175-
$$
175+
```math
176176
\boldsymbol{R}_{\mathrm{red}}
177177
=
178178
\boldsymbol{P}^{T}
@@ -181,11 +181,11 @@ $$
181181
=
182182
\boldsymbol{K}_{\mathrm{red}}\boldsymbol{u}_{\mathrm{red}}
183183
-\theta\boldsymbol{f}_{\mathrm{red}},
184-
$$
184+
```
185185

186186
where
187187

188-
$$
188+
```math
189189
\boldsymbol{K}_{\mathrm{red}}
190190
=
191191
\boldsymbol{P}^{T}\boldsymbol{K}_{\mathrm{full}}\boldsymbol{P}
@@ -203,40 +203,40 @@ $$
203203
\begin{bmatrix}
204204
2\\0\\0
205205
\end{bmatrix}.
206-
$$
206+
```
207207

208208
The first reduced residual component contains the sum of the master and slave
209209
full residual entries. For example, if
210210

211-
$$
211+
```math
212212
\boldsymbol{R}_{\mathrm{full}}
213213
=
214214
\begin{bmatrix}
215215
R_0\\R_1\\R_2\\R_3
216216
\end{bmatrix},
217-
$$
217+
```
218218

219219
then
220220

221-
$$
221+
```math
222222
\boldsymbol{P}^{T}\boldsymbol{R}_{\mathrm{full}}
223223
=
224224
\begin{bmatrix}
225225
R_0+R_3\\R_1\\R_2
226226
\end{bmatrix}.
227-
$$
227+
```
228228

229229
At `theta = 1`, solving
230230

231-
$$
231+
```math
232232
\boldsymbol{K}_{\mathrm{red}}\boldsymbol{u}_{\mathrm{red}}
233233
=
234234
\boldsymbol{f}_{\mathrm{red}}
235-
$$
235+
```
236236

237237
gives
238238

239-
$$
239+
```math
240240
\boldsymbol{u}_{\mathrm{red}}
241241
=
242242
\begin{bmatrix}
@@ -250,39 +250,39 @@ $$
250250
\begin{bmatrix}
251251
1\\1\\1\\1
252252
\end{bmatrix}.
253-
$$
253+
```
254254

255255
## Sensitivity in reduced coordinates
256256

257257
Let $\hat{\boldsymbol{u}}\in\mathbb{R}^{M}$ denote the independent reduced DOFs
258258
and $\boldsymbol{u}\in\mathbb{R}^{N}$ denote the full DOFs. The forward solve
259259
can be viewed as
260260

261-
$$
261+
```math
262262
\boldsymbol{u}
263263
=
264264
\boldsymbol{P}\hat{\boldsymbol{u}},
265265
\qquad
266266
\boldsymbol{P}\in\mathbb{R}^{N\times M},
267267
\qquad
268268
N\ge M.
269-
$$
269+
```
270270

271271
After applying periodic constraints, the full residual equation
272272
$\boldsymbol{R}(\boldsymbol{u},\theta)=\boldsymbol{0}$ becomes the reduced
273273
equation
274274

275-
$$
275+
```math
276276
\boldsymbol{P}^{T}
277277
\boldsymbol{R}
278278
\left(\boldsymbol{P}\hat{\boldsymbol{u}},\theta\right)
279279
=
280280
\boldsymbol{0}.
281-
$$
281+
```
282282

283283
Differentiating with respect to $\theta$ gives
284284

285-
$$
285+
```math
286286
\boldsymbol{P}^{T}
287287
\frac{\partial \boldsymbol{R}}{\partial \boldsymbol{u}}
288288
\boldsymbol{P}
@@ -292,11 +292,11 @@ $$
292292
\frac{\partial \boldsymbol{R}}{\partial \theta}
293293
=
294294
\boldsymbol{0}.
295-
$$
295+
```
296296

297297
Therefore
298298

299-
$$
299+
```math
300300
\frac{d\hat{\boldsymbol{u}}}{d\theta}
301301
=
302302
-
@@ -307,12 +307,12 @@ $$
307307
\right)^{-1}
308308
\boldsymbol{P}^{T}
309309
\frac{\partial \boldsymbol{R}}{\partial \theta}.
310-
$$
310+
```
311311

312312
For an objective $J(\boldsymbol{u},\theta)$, write gradients of $J$ as row
313313
vectors. The reduced and full gradients are related by
314314

315-
$$
315+
```math
316316
\left(
317317
\frac{\partial J}{\partial \hat{\boldsymbol{u}}}
318318
\right)^{T}
@@ -321,12 +321,12 @@ $$
321321
\left(
322322
\frac{\partial J}{\partial \boldsymbol{u}}
323323
\right)^{T}.
324-
$$
324+
```
325325

326326
The adjoint variable $\boldsymbol{\lambda}\in\mathbb{R}^{M}$ is defined in the
327327
reduced space:
328328

329-
$$
329+
```math
330330
\left(
331331
\boldsymbol{P}^{T}
332332
\frac{\partial \boldsymbol{R}}{\partial \boldsymbol{u}}
@@ -337,22 +337,22 @@ $$
337337
\left(
338338
\frac{\partial J}{\partial \hat{\boldsymbol{u}}}
339339
\right)^{T}.
340-
$$
340+
```
341341

342342
Start from the chain rule in reduced coordinates:
343343

344-
$$
344+
```math
345345
\frac{dJ}{d\theta}
346346
=
347347
\frac{\partial J}{\partial \theta}
348348
+
349349
\frac{\partial J}{\partial \hat{\boldsymbol{u}}}
350350
\frac{d\hat{\boldsymbol{u}}}{d\theta}.
351-
$$
351+
```
352352

353353
Using the adjoint definition,
354354

355-
$$
355+
```math
356356
\frac{\partial J}{\partial \hat{\boldsymbol{u}}}
357357
=
358358
\boldsymbol{\lambda}^{T}
@@ -361,11 +361,11 @@ $$
361361
\frac{\partial \boldsymbol{R}}{\partial \boldsymbol{u}}
362362
\boldsymbol{P}
363363
\right),
364-
$$
364+
```
365365

366366
so
367367

368-
$$
368+
```math
369369
\frac{dJ}{d\theta}
370370
=
371371
\frac{\partial J}{\partial \theta}
@@ -377,11 +377,11 @@ $$
377377
\boldsymbol{P}
378378
\right)
379379
\frac{d\hat{\boldsymbol{u}}}{d\theta}.
380-
$$
380+
```
381381

382382
The differentiated reduced residual gives
383383

384-
$$
384+
```math
385385
\left(
386386
\boldsymbol{P}^{T}
387387
\frac{\partial \boldsymbol{R}}{\partial \boldsymbol{u}}
@@ -392,19 +392,19 @@ $$
392392
-
393393
\boldsymbol{P}^{T}
394394
\frac{\partial \boldsymbol{R}}{\partial \theta}.
395-
$$
395+
```
396396

397397
Substituting this into the chain rule gives
398398

399-
$$
399+
```math
400400
\frac{dJ}{d\theta}
401401
=
402402
\frac{\partial J}{\partial \theta}
403403
-
404404
\boldsymbol{\lambda}^{T}
405405
\boldsymbol{P}^{T}
406406
\frac{\partial \boldsymbol{R}}{\partial \theta}.
407-
$$
407+
```
408408

409409
The important point is that both the tangent solve and the adjoint solve live
410410
in the reduced space. The full residual and full tangent are evaluated at
@@ -423,9 +423,9 @@ The script generates a Gmsh mesh, solves the forward problem, writes the VTU
423423
solution, and prints a finite-difference versus automatic-differentiation check
424424
for
425425

426-
$$
426+
```math
427427
J(\theta)=\sum_i u_i(\theta)^2.
428-
$$
428+
```
429429

430430
For derivative verification, prefer a direct linear solve such as
431431
`spsolve_solver`, or PETSc with `ksp_type="preonly"` and `pc_type="lu"`.

0 commit comments

Comments
 (0)