Skip to content

Commit f5f9fc2

Browse files
authored
Merge pull request #98 from LukasFuchs/main
Finalize Exercise 12 English Version
2 parents c9af796 + 417bb5e commit f5f9fc2

14 files changed

+1151
-149
lines changed

docs/make.jl

Lines changed: 0 additions & 99 deletions
This file was deleted.
31.9 KB
Loading
28.3 MB
Loading
21.5 KB
Loading

docs/src/man/AdvTwoD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In two dimensions ($x$ and $y$), the advection equation for the temperature conservation equation, for example, is given as follows
44

55
$\begin{equation}
6-
\frac{\partial{T}}{\partial{t}} = -v_x \left(\frac{\partial{T}}{\partial{x}}\right) - -v_y \left(\frac{\partial{T}}{\partial{y}}\right),
6+
\frac{\partial{T}}{\partial{t}} = -v_x \left(\frac{\partial{T}}{\partial{x}}\right) - v_y \left(\frac{\partial{T}}{\partial{y}}\right),
77
\end{equation}$
88

99
where $T$ is the temperature [K], $t$ is the time [s], and $v_x$ and $v_y$ are the velocities in the $x$- and $y$-direction, respectively.

docs/src/man/AdvectMain.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ where $x_i$ are the coordinates and $v_i$ the corresponding velocity components.
4040

4141
## Discretization Schemes
4242

43-
Although simple in form, the advection equation is challenging to solve numerically. The choice of discretization and interpolation schemes—particularly when coupling grid-based fields with Lagrangian tracers—can introduce numerical artifacts such as diffusion, dispersion, or instability.
43+
Although simple in form, the advection equation is challenging to solve numerically. The choice of discretization and interpolation schemes can introduce numerical artifacts such as diffusion, dispersion, or instability.
4444

4545
To promote clarity and modularity, `GeoModBox.jl` employs an **operator-splitting** strategy. This approach decouples the advective and diffusive terms of the temperature conservation equation and solves them sequentially. First, the advective (convective) term is solved, followed by the diffusive term. The latter is handled using the schemes described in the [Diffusion Equation documentation](./DiffMain.md).
4646

@@ -86,5 +86,5 @@ See the [examples documentation](./Examples.md) for further details.
8686

8787
## Exercises
8888

89-
- [1-D Gaussian or block anomaly advection](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/exercises/06_1D_Advection.ipynb)
90-
- [2-D coupled advection-diffusion](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/exercises/07_2D_Energy_Equation.ipynb)
89+
- [1-D Gaussian or block anomaly advection](../man/exercises/06_1D_Advection.md)
90+
- [2-D coupled advection-diffusion](../man/exercises/07_2D_Energy_Equation.md)

docs/src/man/DiffMain.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ This equation captures temperature changes due to **diffusion** (right-hand side
3535

3636
# Heat Diffusion Equation
3737

38+
Neglecting the advection part of the temperature equation, the heat diffusion equation is defined as:
39+
40+
$\begin{equation}
41+
\rho c_p \frac{\partial T}{\partial t} = -\frac{\partial q_i}{\partial x_i} + \rho H.
42+
\end{equation}$
43+
3844
```GeoModBox.jl``` provides several finite difference (FD) schemes to solve the diffusive component of the time-dependent or steady-state temperature equation—including optional radioactive heating—in both [1-D](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/src/HeatEquation/1Dsolvers.jl) and [2-D](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/src/HeatEquation/2Dsolvers.jl). Available methods include:
3945

4046
- Forward Euler
4147
- Backward Euler
4248
- Crank–Nicolson
4349
- Alternating Direction Implicit (ADI)
50+
- Defection Correction
4451

4552
See the documentation for the [1-D](./DiffOneD.md) and [2-D](./DiffTwoD.md) solvers for detailed descriptions of each method.
4653

docs/src/man/DiffOneD.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ $k$ is the thermal conductivity [W/m/K],
369369
$H$ is the internal heat generation rate per unit mass [W/kg], and
370370
$y$ is the vertical coordinate (depth) [m]
371371

372-
## Discretization
372+
### Discretization
373373

374374
In a conservative scheme, the vertical conductive heat flux $q_y$ is defined on vertices, as:
375375

@@ -379,7 +379,7 @@ $\begin{equation}
379379

380380
where $n_v$ is the number of *vertices*.
381381

382-
## Explicit Finite Difference Formulation
382+
### Explicit Finite Difference Formulation
383383

384384
Using the above discretization, the time evolution of temperature at each centroid is computed from:
385385

docs/src/man/DiffTwoD.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ $\begin{equation}
265265
Discretizing the equation in space and time using implicit finite differences yields:
266266

267267
$\begin{equation}
268-
\frac{T_i^{n+1}-T_i^{n}}{\Delta{t}} - \kappa
268+
\frac{T_{i,j}^{n+1}-T_{i,j}^{n}}{\Delta{t}} - \kappa
269269
\left( \frac{T_{i-1,j}^{n+1} - 2 T_{i,j}^{n+1} + T_{i+1,j}^{n+1}}{\Delta{x}^2} + \frac{T_{i,j-1}^{n+1} - 2 T_{i,j}^{n+1} + T_{i,j+1}^{n+1}}{\Delta{y}^2}
270270
\right) - \frac{Q_{i,j}^n}{\rho c_p} = R.
271271
\end{equation}$
@@ -298,13 +298,13 @@ In 2-D, the diffusive part of the heat equation (Equation 3) using the Crank–N
298298
$\begin{equation}\begin{gather*}
299299
& \frac{T_{i,j}^{n+1} - T_{i,j}^{n}}{\Delta t} = \\ &
300300
\frac{\kappa}{2}\frac{(T_{i-1,j}^{n+1}-2T_{i,j}^{n+1}+T_{i+1,j}^{n+1})+(T_{i-1,j}^{n}-2T_{i,j}^{n}+T_{i+1,j}^{n})}{\Delta x^2} + \\ &
301-
\frac{\kappa}{2}\frac{(T_{i,j-1}^{n+1}-2T_{i,j}^{n+1}+T_{i,j+1}^{n+1})+(T_{i,j-1}^{n}-2T_{i,j}^{n}+T_{i,j+1}^{n})}{\Delta y^2}
301+
\frac{\kappa}{2}\frac{(T_{i,j-1}^{n+1}-2T_{i,j}^{n+1}+T_{i,j+1}^{n+1})+(T_{i,j-1}^{n}-2T_{i,j}^{n}+T_{i,j+1}^{n})}{\Delta y^2} + \frac{Q_{i,j}^n}{\rho c_p}
302302
\end{gather*}\end{equation}$
303303

304304
Rearranging into a form that separates known and unknown variables gives the linear system:
305305

306306
$\begin{equation}\begin{gather*}
307-
& -b T_{i,j-1}^{n+1} -aT_{i-1,j}^{n+1}+\left(2a + 2b + c\right)T_{i,j}^{n+1} -aT_{i+1,j}^{n+1} -b T_{i,j+1}^{n+1} = \\ &b T_{i,j-1}^{n} +aT_{i-1,j}^{n}-\left(2a + 2b - c\right)T_{i,j}^{n} +aT_{i+1,j}^{n} +b T_{i,j+1}^{n}
307+
& -b T_{i,j-1}^{n+1} -aT_{i-1,j}^{n+1}+\left(2a + 2b + c\right)T_{i,j}^{n+1} -aT_{i+1,j}^{n+1} -b T_{i,j+1}^{n+1} = \\ &b T_{i,j-1}^{n} +aT_{i-1,j}^{n}-\left(2a + 2b - c\right)T_{i,j}^{n} +aT_{i+1,j}^{n} +b T_{i,j+1}^{n} + \frac{Q_{i,j}^n}{\rho c_p}
308308
\end{gather*}\end{equation}$
309309

310310
where the coefficients are defined as:
@@ -325,7 +325,7 @@ $\begin{equation}\begin{gather*}
325325
& -b T_{1,j-1}^{n+1} +
326326
\left(3a + 2b + c \right) T_{1,j}^{n+1}
327327
-a T_{2,j}^{n+1} - b T_{1,j+1}^{n+1} = \\ &
328-
b T_{1,j-1}^{n} - \left( 3a + 2b - c \right) T_{1,j}^{n} + a T_{2,j}^{n} + b T_{1,j+1}^{n} + 4 a T_{BC,W},
328+
b T_{1,j-1}^{n} - \left( 3a + 2b - c \right) T_{1,j}^{n} + a T_{2,j}^{n} + b T_{1,j+1}^{n} + 4 a T_{BC,W} + \frac{Q_{i,j}^n}{\rho c_p},
329329
\end{gather*}\end{equation}$
330330

331331
**East boundary**
@@ -335,22 +335,22 @@ $\begin{equation}\begin{gather*}
335335
\left(3a + 2b + c \right) T_{ncx,j}^{n+1}
336336
-b T_{ncx,j+1}^{n+1} = \\ &
337337
b T_{ncx,j-1}^{n} + a T_{ncx-1,j}^{n} -
338-
\left( 3a + 2b - c \right) T_{ncx,j}^{n} + b T_{ncx,j+1}^{n} + 4 a T_{BC,E},
338+
\left( 3a + 2b - c \right) T_{ncx,j}^{n} + b T_{ncx,j+1}^{n} + 4 a T_{BC,E} + \frac{Q_{i,j}^n}{\rho c_p},
339339
\end{gather*}\end{equation}$
340340

341341
**South boundary**
342342

343343
$\begin{equation}\begin{gather*}
344344
& -a T_{i-1,1}^{n+1} +
345345
\left(2a + 3b + c \right) T_{i,1}^{n+1} - a T_{i+1,1}^{n+1} - b T_{i,2}^{n+1} = \\ &
346-
a T_{i-1,1}^{n} - \left( 2a + 3b - c \right) T_{i,1}^{n} + a T_{i+1,1}^{n} + b T_{i,2}^{n} + 4 b T_{BC,S},
346+
a T_{i-1,1}^{n} - \left( 2a + 3b - c \right) T_{i,1}^{n} + a T_{i+1,1}^{n} + b T_{i,2}^{n} + 4 b T_{BC,S} + \frac{Q_{i,j}^n}{\rho c_p},
347347
\end{gather*}\end{equation}$
348348

349349
**North boundary**
350350

351351
$\begin{equation}\begin{gather*}
352352
& -b T_{i,ncy-1}^{n+1} + a T_{i-1,ncy}^{n+1} + \left(2a + 3b + c \right) T_{i,ncy}^{n+1} - a T_{i+1,ncy}^{n+1} = \\ &
353-
b T_{i,ncy-1}^{n} + a T_{i-1,ncy}^{n} - \left( 2a + 3b - c \right) T_{i,ncy}^{n} + a T_{i+1,ncy}^{n} + 4 b T_{BC,N}.
353+
b T_{i,ncy-1}^{n} + a T_{i-1,ncy}^{n} - \left( 2a + 3b - c \right) T_{i,ncy}^{n} + a T_{i+1,ncy}^{n} + 4 b T_{BC,N} + \frac{Q_{i,j}^n}{\rho c_p}.
354354
\end{gather*}\end{equation}$
355355

356356
**Neumann Boundary Conditions**
@@ -359,28 +359,28 @@ b T_{i,ncy-1}^{n} + a T_{i-1,ncy}^{n} - \left( 2a + 3b - c \right) T_{i,ncy}^{n}
359359

360360
$\begin{equation}\begin{gather*}
361361
& -b T_{1,j-1}^{n+1} + \left(a + 2b + c \right) T_{1,j}^{n+1} - a T_{2,j}^{n+1} - b T_{1,j+1}^{n+1} = \\ &
362-
b T_{1,j-1}^{n} - \left( a + 2b - c \right) T_{1,j}^{n} + a T_{2,j}^{n} + b T_{1,j+1}^{n} - 2 a c_W \Delta{x},
362+
b T_{1,j-1}^{n} - \left( a + 2b - c \right) T_{1,j}^{n} + a T_{2,j}^{n} + b T_{1,j+1}^{n} - 2 a c_W \Delta{x} + \frac{Q_{i,j}^n}{\rho c_p},
363363
\end{gather*}\end{equation}$
364364

365365
**East boundary**
366366

367367
$\begin{equation}\begin{gather*}
368368
& -b T_{ncx,j-1}^{n+1} - a T_{ncx-1,j}^{n+1} + \left(a + 2b + c \right) T_{ncx,j}^{n+1} - b T_{ncx,j+1}^{n+1} = \\ &
369-
b T_{ncx,j-1}^{n} + a T_{ncx-1,j}^{n} - \left( a + 2b - c \right) T_{ncx,j}^{n} + b T_{ncx,j+1}^{n} + 2 a c_E \Delta{x},
369+
b T_{ncx,j-1}^{n} + a T_{ncx-1,j}^{n} - \left( a + 2b - c \right) T_{ncx,j}^{n} + b T_{ncx,j+1}^{n} + 2 a c_E \Delta{x} + \frac{Q_{i,j}^n}{\rho c_p},
370370
\end{gather*}\end{equation}$
371371

372372
**South boundary**
373373

374374
$\begin{equation}\begin{gather*}
375375
& -a T_{i-1,1}^{n+1} + \left(2a + b + c \right) T_{i,1}^{n+1} - a T_{i+1,1}^{n+1} - b T_{i,2}^{n+1} = \\ &
376-
a T_{i-1,1}^{n} - \left( 2a + b - c \right) T_{i,1}^{n} + a T_{i+1,1}^{n} + b T_{i,2}^{n} - 2 b c_S \Delta{y}
376+
a T_{i-1,1}^{n} - \left( 2a + b - c \right) T_{i,1}^{n} + a T_{i+1,1}^{n} + b T_{i,2}^{n} - 2 b c_S \Delta{y} + \frac{Q_{i,j}^n}{\rho c_p},
377377
\end{gather*}\end{equation}$
378378

379379
**North boundary**
380380

381381
$\begin{equation}\begin{gather*}
382382
& -b T_{i,ncy-1}^{n+1} + a T_{i-1,ncy}^{n+1} + \left(2a + b + c \right) T_{i,ncy}^{n+1} - a T_{i+1,ncy}^{n+1} = \\ &
383-
b T_{i,ncy-1}^{n} + a T_{i-1,ncy}^{n} - \left( 2a + b - c \right) T_{i,ncy}^{n} + a T_{i+1,ncy}^{n} + 2 b c_N \Delta{y}
383+
b T_{i,ncy-1}^{n} + a T_{i-1,ncy}^{n} - \left( 2a + b - c \right) T_{i,ncy}^{n} + a T_{i+1,ncy}^{n} + 2 b c_N \Delta{y} + \frac{Q_{i,j}^n}{\rho c_p}.
384384
\end{gather*}\end{equation}$
385385

386386
For implementation details, refer to the [source code](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/src/HeatEquation/2Dsolvers.jl).
@@ -396,7 +396,7 @@ $\begin{equation}
396396
\left(
397397
\frac{T_{i-1,j}^n-2T_{i,j}^n+T_{i+1,j}^n}{\Delta x^2} +
398398
\frac{T_{i,j-1}^{n+1/2}-2T_{i,j}^{n+1/2}+T_{i,j+1}^{n+1/2}}{\Delta y^2}
399-
\right)
399+
\right) + \frac{Q_{i,j}^n}{\rho c_p}
400400
\end{equation}$
401401

402402
### Second half-step (implicit in $x$, explicit in $y$):
@@ -407,7 +407,7 @@ $\begin{equation}
407407
\left(
408408
\frac{T_{i-1,j}^{n+1}-2T_{i,j}^{n+1}+T_{i+1,j}^{n+1}}{\Delta x^2} +
409409
\frac{T_{i,j-1}^{n+1/2}-2T_{i,j}^{n+1/2}+T_{i,j+1}^{n+1/2}}{\Delta y^2}
410-
\right)
410+
\right) + \frac{Q_{i,j}^n}{\rho c_p}
411411
\end{equation}$
412412

413413
Each fractional step results in a tridiagonal linear system, alternating between the $x$- and $y$-directions. This decomposition improves computational efficiency while retaining the stability benefits of implicit schemes.
@@ -443,7 +443,7 @@ $\begin{equation}
443443
\rho_{i,j} c_{p,(i,j)}\left(\frac{T_{i,j}^{n+1} - T_{i,j}^{n}}{\Delta{t}}\right)
444444
+\frac{q_{x,(i+1,j)} - q_{x,(i,j)}}{\Delta{x}}
445445
+\frac{q_{y,(i,j+1)} - q_{y,(i,j)}}{\Delta{y}}
446-
-\rho_{i,j} H_{i,j} = R,
446+
-\rho_{i,j} H_{i,j} = R_{i,j},
447447
\end{equation}$
448448

449449
where $\Delta{x}$ and $\Delta{y}$ are the horizontal and vertical grid resolution, respectively, $\Delta{t}$ is the time step length and $i$ and $j$ the horizontal and vertical indices, respectively.
@@ -462,7 +462,7 @@ $\begin{equation}
462462
+k_{y,(i,j)}\frac{T_{i,j}^{n+1}-T_{i,j-1}^{n+1}}{\Delta{y}}}
463463
{\Delta{y}}
464464
\right)
465-
-\rho_{i,j} H_{i,j} = R.
465+
-\rho_{i,j} H_{i,j} = R_{i,j}.
466466
\end{equation}$
467467

468468
Rewriting this in a matrix-compatible form leads to:
@@ -474,7 +474,7 @@ aT_{i,j-1}^{n+1}
474474
+dT_{i+1,j}^{n+1}
475475
+eT_{i,j+1}^{n+1}
476476
+fT_{i,j}^{n}
477-
-\rho_{i,j} H_{i,j} = R,
477+
-\rho_{i,j} H_{i,j} = R_{i,j},
478478
\end{equation}$
479479

480480
where

docs/src/man/Exercises.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ All exercises were performed on a single CPU: *AMD Ryzen 7 7735U with Radeon Gra
3939
| 9 | 2-D Falling Block (steady state) | 20.764 (0.891) |
4040
| 10 | 2-D Falling Block (time-dep.) | 1) Upwind: 33.295 (3.68) <br/> 2) SLF: 32.333 (3.629) <br/> 3) SL: 37.537 (3.755) <br/> 4) Tracers: 36.291 (6.12) |
4141
| 11<sup>1</sup> | Thermal Convection (dim) | **Ra = 1e4** (Diff+Adv+Momentum) <br/> 1) Explicit+upwind+direct: 262.912 (1703) <br/> 2) Implicit+upwind+direct: 283.031 (1709) <br/> 3) CNA+upwind+direct: 284.944 (1708) <br/> 4) ADI+upwind+direct: 645.181 (1708) <br/> 5) DC+upwind+direct: 294.1 (1710) <br/> 6) Explicit+SLF+direct: 354.35 (2341) <br/> 7) Implicit+SLF+direct: 382.307 (2345) <br/> 8) CNA+SLF+direct: 386.764 (2344) <br/> 9) ADI+SLF+direct: 892.411 (2344) <br/> 10) DC+SLF+direct: 492.168 (2346) <br/> 11) Explicit+semilag+direct: 334.941 (1743) <br/> 12) Implicit+semilag+direct: 367.501 (1746) <br/> 13) CNA+semilag+direct: 371.289 (1744) <br/> 14) ADI+semilag+direct: 704.852 (1744) <br/> 15) DC+semilag+direct: 390.767 (1749) <br/> 16) Explicit+upwind+DC: 371.091 (1703) <br/> 17) Implicit+upwind+DC: 358.323 (1709) <br/> 18) CNA+upwind+DC: 338.862 (1708) <br/> 19) ADI+upwind+DC: 654.069 (1708) <br/> 20) DC+upwind+DC: 316.456 (1710) <br/> 21) Explicit+SLF+DC: 394.471 (2341) <br/> 22) Implicit+SLF+DC: 417.712 (2345) <br/> 23) CNA+SLF+DC: 412.717 (2344) <br/> 24) ADI+slf+DC: 890.714 (2344) <br/> 25) DC+SLF+DC: 403.217 (2346) <br/> 26) Explicit+semilag+DC: 286.046 (1743) <br/> 27) Implicit+semilag+DC: 295.961 (1746) <br/> 28) CNA+semilag+DC: 288.067 (1744) <br/> 29) ADI+semilag+DC: 671.159 (1744) <br/> 30) DC+semilag+DC: 357.894 (1749) <br/> <br/> **Ra = 1e5** (Diff+Adv+Momentum) <br/> 1) Explicit+semilag+dc: 489.869 (2433) <br/> 2) CNA+semilag+dc: 515.539 (2448) <br/> 3) CNA+upwind+dc: 1327.856 (8000) <br/><br/> **Ra = 1e6** (Diff+Adv+Momentum) <br/> 4) Explicit+semilag+dc: 1280.077 (8000) <br/> 5) CNA+semilag+dc: 1324.29 (8000) <br/> 6) CNA+upwind+dc: 1272.997 (8000) |
42-
| 12 |
42+
| 12 | Thermal Convection (scaled) | **Ra = 1e4** (Diff+Adv+Momentum) <br/> 1) Explicit+upwind+direct: 310.208 (1950) <br/> 2) Implicit+upwind+direct: 333.82 (1957) <br/> 3) CNA+upwind+direct: 331.791 (1955) <br/> 4) ADI+upwind+direct: 739.821 (1955) <br/> 5) DC+upwind+direct: 352.163 (1953) <br/> 6) Explicit+SLF+direct: 437.435 (2704) <br/> 7) Implicit+SLF+direct: 468.642 (2708) <br/> 8) CNA+SLF+direct: 464.97 (2707) <br/> 9) ADI+SLF+direct: 1013.196 (2707) <br/> 10) DC+SLF+direct: 476.063 (2706) <br/> 11) Explicit+semilag+direct: 358.84 (1999) <br/> 12) Implicit+semilag+direct: 341.811 (2002) <br/> 13) CNA+semilag+direct: 384.29 (2000) <br/> 14) ADI+semilag+direct: 754.453 (2000) <br/> 15) DC+semilag+direct: 359.703 (2001) <br/> 16) Explicit+upwind+DC: 683.465 (1950) <br/> 17) Implicit+upwind+DC: 614.899 (1957) <br/> 18) CNA+upwind+DC: 649.386 (1955) <br/> 19) ADI+upwind+DC: 1048.092 (1955) <br/> 20) DC+upwind+DC: 640.199 (1953) <br/> 21) Explicit+SLF+DC: 835.568 (2704) <br/> 22) Implicit+SLF+DC: 862.991 (2708) <br/> 23) CNA+SLF+DC: 868.07 (2707) <br/> 24) ADI+slf+DC: 1402.997 (2707) <br/> 25) DC+SLF+DC: 876.505 (2706) <br/> 26) Explicit+semilag+DC: 613.413 (1999) <br/> 27) Implicit+semilag+DC: 652.126 (2002) <br/> 28) CNA+semilag+DC: 638.264 (2000) <br/> 29) ADI+semilag+DC: 1027.153 (2000) <br/> 30) DC+semilag+DC: 620. 945 (2001) <br/> <br/> **Ra = 1e5** (Diff+Adv+Momentum) <br/> 31) Explicit+semilag+dc: 3502.72 (8000) <br/> 32) CNA+semilag+dc: 3175.01 (8000) <br/> 33) CNA+upwind+dc: 3330.177 (8000) <br/><br/> **Ra = 1e6** (Diff+Adv+Momentum) <br/> 34) Explicit+semilag+dc: 3327.062 (8000) <br/> 35) CNA+semilag+dc: 3387.836 (8000) <br/> 36) CNA+upwind+dc: 3277.684 (8000) <br/> |
4343

4444
---
4545

0 commit comments

Comments
 (0)