Skip to content

Commit 0502c6a

Browse files
authored
Merge pull request #106 from LukasFuchs/main
update tracer averaging and added timer output
2 parents ba40b72 + e52ceb7 commit 0502c6a

File tree

123 files changed

+1761
-572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1761
-572
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1616
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1717
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1818
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
19+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
20+
21+
[compat]
22+
TimerOutputs = "0.5.29"
64 KB
Loading

docs/src/man/Examples.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,75 @@
11
# Examples and Benchmarks
22

3-
This section provides various one- and two-dimensional examples and benchmark problems for each of the governing equations. The examples demonstrate how to implement different numerical solvers, apply scaling, and evaluate the advantages and limitations of various finite difference schemes.
3+
The `GeoModBox.jl` provides various one- and two-dimensional examples and benchmark problems for each of the governing equations. The examples demonstrate how to implement different numerical solvers, apply scaling, and evaluate the advantages and limitations of various finite difference schemes.
44

5-
By clicking on the title of each page, you will be directed to the corresponding Julia script in the [examples directory](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/examples).
5+
By clicking on the title of each document page, you will be directed to the corresponding Julia script in the [examples directory](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/examples).
6+
7+
**Advection**
8+
- [2-D advection with constant velocity field](./examples/Advection2D.md)
9+
- [Resolution test of 2-D advection](./examples/AdvectionRestest2D.md)
10+
11+
**Heat Diffusion**
12+
- [1-D continental geotherm](./examples/ContinentalGeotherm.md)
13+
- [Comparison of FD schemes on a Gaussian anomaly](./examples/GaussianDiffusion1D.md)
14+
- [1-D oceanic geotherm](./examples/OceanicGeotherm.md)
15+
- [2-D Gaussian anomaly using iterative backward Euler solver](./examples/BackwardEuler_DC.md)
16+
- [2-D Gaussian anomaly using iterative forward Euler solver](./examples/ForwardEuler_DC.md)
17+
- [2-D resolution test with Gaussian anomaly](./examples/GaussianDiffusion2D.md)
18+
- [2-D Poisson equation resolution test](./examples/PoissonRestest.md)
19+
- [](./examples/PoissonVariablek.md)
20+
21+
**Thermal Convection Models**
22+
- [Bottom heated, isoviscous thermal convection](./examples/BottomHeatedConvection.md)
23+
- [Internally heated, isoviscous thermal convection](./examples/InternallyHeatedConvection.md)
24+
- [Mixed heated, isoviscous thermal convection](./examples/MixedHeatedConvection.md)
25+
26+
**Stokes Equation**
27+
- [1D channel flow with constant and depth-dependent viscosity](./examples/ChannelFlow1D.md)
28+
- [2D falling block benchmark](./examples/FallingBlockBenchmark.md)
29+
- [2D falling block with constant or variable viscosity (defect correction)](./examples/FallingBlockDC.md)
30+
- [2D Rayleigh–Taylor instability](./examples/RTI.md)
31+
- [2D Rayleigh–Taylor instability benchmark](./examples/RTI_growth_rate.md)
32+
- [2D viscous inclusion problem](./examples/ViscousInclusion.md)
33+
34+
In the following, the runtime for each of the provided examples is listed as a reference.
35+
36+
| Example | Total Runtime |
37+
| --------------------------------- | ----------------------------------------------------- |
38+
| **Advection ===** |
39+
| 2D_Advection.jl | 1) Upwind: 5.88 s <br> 2) SLF: 6.11 s 3) Semi-lag: 15.7 s <br> 4) Tracers: 172 s |
40+
| 2D_Advection_ResolutionTest.jl | 335 s |
41+
| **Heat Diffusion ===** |
42+
| *1D* --- |
43+
| ContinentalGeotherm_1D.jl | 530 ms |
44+
| Heat_1D_discretization.jl | 2.28 s |
45+
| OceanicGeotherm_1D.jl | 431 ms |
46+
| *2D* --- |
47+
| BackwardEuler.jl | 29.9 s |
48+
| ForwardEuler.jl | 5.89 s |
49+
| Gaussian_Diffusion.jl | 678 s |
50+
| Poisson_RestTest.jl | 34.7 s |
51+
| Poisson_variable_k.jl | 5.24 s |
52+
| **Thermal Convection Models ===** |
53+
| BottomHeated.jl | 6.37 h |
54+
| InternallyHeated.jl | 5.94 h |
55+
| MixedHeated.jl | |
56+
| **Stokes Equation ===** |
57+
| *1D* --- |
58+
| ChannelFlow_1D.jl | 3.61 s |
59+
| *2D* --- |
60+
| FallingBlockBenchmark.jl | 1) Steady State: 8 s <br> 2) Time-Dependent <br> a) Upwind: 74.4 s <br> b) SLF: 170 s <br> c) Semi-lag: 175 s <br> d) Tracers: 233 s |
61+
| FallingBlockConstEta_DC.jl | 332 ms |
62+
| FallingBlockVarEta_DC.jl | 25.8 s |
63+
| RTI.jl | 154 s |
64+
| RTI_GrowthRate.jl | 49.4 s |
65+
| RTI_Growth_Rate_Res_Test.jl | 250 s |
66+
| RTI_Growth_Rate_Res_Test_2.jl | 261 s |
67+
| RTI_Growth_Rate_Res_Test_3.jl | 446 s |
668

769
> **Note:** In `GeoModBox.jl`, thermal and kinematic boundary conditions are explicitly implemented within the solvers. The absolute values at *ghost nodes* are computed based on the values provided in the boundary condition tuple `BC`. Each tuple specifies the `type` (either Dirichlet or Neumann) and the corresponding `val`ue at each boundary.
8-
> For constant velocity boundary conditions, additional values must be defined in `val` for the boundary nodes (e.g., `BC.val.vxW`, `BC.val.vxE`). These additional values are required to directly solve the momentum equation and update the right-hand side of the linear system. Furthermore, these values must be assigned to the initial boundary nodes of the respective velocity fields.
70+
> For constant velocity boundary conditions, additional values must be defined in `val` for the boundary nodes (e.g., `BC.val.vxW`, `BC.val.vxE`). These additional values are required to **directly** solve the momentum equation using a the backslash operator and to update the right-hand side of the linear system. Furthermore, if non-zero, these values must be assigned to the initial boundary nodes of the respective velocity fields.
971
> For more details on the implementation of constant velocity boundaries, refer to the documentation of the [viscous inclusion](./examples/ViscousInclusion.md) example or the [initial velocity setup](Ini.md).
1072
1173
> **Note:** By default, the results of time-dependent examples in `GeoModBox.jl` are stored as GIF animations. To visualize solutions at specific time steps without generating a GIF, set the parameter `save_fig = 0`. In this case, individual plots are not saved, so caution is advised when running problems that require multiple time step iterations.
1274
13-
> **Note:** Some examples use *named tuples* to define constants and parameters. Alternatively, *mutable structures* can be used—particularly useful when parameters need to be modified after initialization (e.g., for scaling purposes). A full transition from *named tuples* to *mutable structures* is planned for future versions of `GeoModBox.jl`.
75+
> **Note:** Some examples use *named tuples* to define constants and parameters. Alternatively, *mutable structures* can be used—particularly useful when parameters need to be modified after initialization (e.g., for scaling purposes). A full transition from *named tuples* to *mutable structures* is planned for future versions of `GeoModBox.jl`.

docs/src/man/examples/RTI_growth_rate.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
# [RTI - Growth Rate Benchmark](https://github.com/GeoSci-FFM/GeoModBox.jl/blob/main/examples/StokesEquation/2D/RTI_GrowthRate.jl)
22

3-
This script performs a benchmark for the growth rate of a Rayleigh–Taylor instability, following Gerya (2009). The benchmark is based on the analytical solution by Ramberg (1968) and is used to assess the accuracy of the velocity field in a purely gravity-driven flow.
3+
This script benchmarks the **growth rate of a Rayleigh–Taylor instability**, following *Gerya (2009)*.
4+
The benchmark is based on the analytical solution by *Ramberg (1968)* and is used to evaluate the accuracy of the velocity field in a purely gravity-driven flow.
45

5-
While small-amplitude perturbations can be analyzed theoretically—facilitated by the use of tracers and bilinear interpolation of density onto centroids—a relatively large perturbation amplitude is employed here to accommodate practical implementation constraints.
6+
The script calculates the **diapiric growth rate** at the tip of the perturbation for different **perturbation amplitudes** ($\delta A$), **wavelengths** ($\lambda$), and **viscosity ratios** ($\eta_r$).
7+
The numerical solution is plotted alongside the analytical one, which is arbitrarily scaled by certain constants for visualization purposes, following *Gerya (2009)*.
8+
9+
The amplitude of the cosine perturbation is defined as:
10+
11+
$\begin{equation}
12+
\delta A = \cos\left( 2\pi \frac{x_m - L/2}{\lambda} \right),
13+
\end{equation}$
14+
15+
where $x_m$ is the x-coordinate of the marker, and $L$ is the length of the model domain.
16+
The perturbation is applied to the tracers by adding the perturbation amplitude to the y-coordinate of an initially equally distributed or randomly perturbed tracer field.
17+
18+
Using a **bilinear interpolation scheme** to map tracer properties onto the regular numerical grid, one can test how accurately the Stokes solver reproduces the analytical growth rate of the diapiric instability.
19+
However, care must be taken when defining the initial tracer positions or when averaging tracer properties onto the grid to avoid numerical artifacts.
620

721
---
822

@@ -34,7 +48,7 @@ Pl = (
3448
)
3549
```
3650

37-
The parameters for an initial cosinusoidal tracer perturbation are defined for a two-layer model. For benchmarking purposes, a range of wavelengths is specified.
51+
The parameters for an initial cosinusoidal tracer perturbation are defined for a two-layer model. For benchmarking purposes, a range of wavelengths is specified. One can define, if the density is interpolated from the tracers to the centroids or the vertices.
3852

3953
```Julia
4054
# Define Initial Condition ========================================== #
@@ -480,3 +494,6 @@ end
480494

481495
**Figure 2. RTI Growth Rate.** Growth rate of an initial cosinusoidal perturbation in a two-layer system across various wavelengths $\lambda$. The growth rate is arbitrarily scaled using $b_1$ and $b_2$ for visualization, following the approach of Gerya (2000). The lines are the analytical solutions for different viscosity ratios $\eta_r$ and the markers show the corresponding numerical results for models with decreasing amplitudes (black - scaled by 15, red - scaled by 150, yellow - scaled by 1500). The rising velocity is numerically calculated following the approach shown in Figure 1.
482496

497+
![RTI_Growth_Rate_Res_test](../../assets/RTI_Growth_Rate_Res_Test_const_NM_arith.png)
498+
499+
**Figure 3. RTI Resolution Test.** Resolution test for the RTI growth rate using a fixed layer thickness (1500 km), a fixed wavelength $\lambda = 4000 \text{ km}$ and fixed number of markers per cell (5x5) for different horizontal and vertical grid resolutions $\left(nc_x,nc_y\right)$, different perturbation amplitudes $\left(\delta{A}\right)$ (colored markers), different viscosity ratios $\eta_r$, and without (top row) and with (bottom row) additional noise ontop of the initial marker position (before assigning the layer phases). The viscosity is interpolate from the tracers to the centroids and the vertices using an arithmetic mean.

examples/AdvectionEquation/2D_Advection.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ using GeoModBox.AdvectionEquation.TwoD, GeoModBox.Tracers.TwoD
2626
using GeoModBox.InitialCondition
2727
using Base.Threads
2828
using Printf
29+
using TimerOutputs
2930

3031
function Advection_2D()
31-
32+
to = TimerOutput()
3233
@printf("Running on %d thread(s)\n", nthreads())
3334

3435
save_fig = 1
3536

37+
@timeit to "Ini" begin
3638
# Define Numerical Scheme ============================================ #
3739
# Advection ---
3840
# 1) upwind, 2) slf, 3) semilag, 4) tracers
39-
FD = (Method = (Adv=:tracers,),)
41+
FD = (Method = (Adv=:upwind,),)
4042
# -------------------------------------------------------------------- #
4143
# Define Initial Condition =========================================== #
4244
# Temperature ---
@@ -126,7 +128,9 @@ D = (
126128
Tmean = [0.0],
127129
)
128130
# -------------------------------------------------------------------- #
131+
end
129132
# Initial Conditions ================================================= #
133+
@timeit to "IniCondition" begin
130134
# Temperature ---
131135
IniTemperature!(Ini.T,M,NC,D,x,y)
132136
if FD.Method.Adv==:slf
@@ -145,6 +149,7 @@ IniVelocity!(Ini.V,D,BC,NV,Δ,M,x,y) # [ m/s ]
145149
end
146150
end
147151
@. D.vc = sqrt(D.vxc^2 + D.vyc^2)
152+
end
148153
# -------------------------------------------------------------------- #
149154
# Time =============================================================== #
150155
T = (
@@ -159,6 +164,7 @@ nt = ceil(Int,T.tmax[1]/T.Δ[1])
159164
# -------------------------------------------------------------------- #
160165
# Tracer Advection =================================================== #
161166
if FD.Method.Adv==:tracers
167+
@timeit to "TracerIni" begin
162168
# Tracer Initialization ---
163169
nmx,nmy = 3,3
164170
noise = 1
@@ -186,6 +192,7 @@ if FD.Method.Adv==:tracers
186192
end
187193
# Count marker per cell ---
188194
CountMPC(Ma,nmark,MPC,M,x,y,Δ,NC,NV,1)
195+
end
189196
end
190197
# -------------------------------------------------------------------- #
191198
# Visualize initial condition ======================================== #
@@ -228,6 +235,7 @@ for i=2:nt
228235
@printf("Time step: #%04d\n ",i)
229236

230237
# Advection ===
238+
@timeit to "Advection" begin
231239
if FD.Method.Adv==:upwind
232240
upwindc2D!(D.T,D.T_ex,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
233241
elseif FD.Method.Adv==:slf
@@ -243,6 +251,7 @@ for i=2:nt
243251
Markers2Cells(Ma,nmark,MAVG.PC_th,D.T_ex,MAVG.wte_th,D.wte,x,y,Δ,Aparam,0)
244252
D.T .= D.T_ex[2:end-1,2:end-1]
245253
end
254+
end
246255

247256
display(string("ΔT = ",((maximum(filter(!isnan,D.T))-D.Tmax[1])/D.Tmax[1])*100))
248257

@@ -292,6 +301,7 @@ elseif save_fig == 0
292301
display(plot(p))
293302
end
294303
# -------------------------------------------------------------------- #
304+
display(to)
295305
end # Function end
296306

297307
Advection_2D()

examples/AdvectionEquation/2D_Advection_ResolutionTest.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using GeoModBox.AdvectionEquation.TwoD
33
using GeoModBox.InitialCondition, GeoModBox.Tracers.TwoD
44
using Base.Threads
55
using Printf
6+
using TimerOutputs
67

78
@doc raw"""
89
Advection_2D_ResTest()
@@ -11,7 +12,7 @@ using Printf
1112
1213
"""
1314
function Advection_2D_ResTest()
14-
15+
to = TimerOutput()
1516
@printf("Running on %d thread(s)\n", nthreads())
1617

1718
nrnxny = 5
@@ -35,6 +36,7 @@ St = (
3536
# 1) RigidBody, 2) ShearCell
3637
Ini = (T=:circle,V=:RigidBody,)
3738
# -------------------------------------------------------------------- #
39+
@timeit to "AdvectionScLoop" begin
3840
for m = 1:ns # Loop over advection schemes
3941
# Define Numerical Scheme ======================================== #
4042
FD = (Method = (Adv=Scheme[m],),)
@@ -57,6 +59,7 @@ for m = 1:ns # Loop over advection schemes
5759
)
5860
BC = () # dummy
5961
# ---------------------------------------------------------------- #
62+
@timeit to "ResolutionLoop" begin
6063
for l = 1:nrnxny # Loop over differnet resolutions
6164
# Numerical Constants ======================================== #
6265
NC = (
@@ -124,6 +127,7 @@ for m = 1:ns # Loop over advection schemes
124127
Tmean = [0.0],
125128
)
126129
# Initial Condition ========================================== #
130+
@timeit to "IniCondition" begin
127131
# Temperature ---
128132
IniTemperature!(Ini.T,M,NC,D,x,y)
129133
if FD.Method.Adv == "slf"
@@ -142,6 +146,7 @@ for m = 1:ns # Loop over advection schemes
142146
end
143147
end
144148
@. D.vc = sqrt(D.vxc^2 + D.vyc^2)
149+
end
145150
# ------------------------------------------------------------ #
146151
# Time ======================================================= #
147152
T = (
@@ -156,6 +161,7 @@ for m = 1:ns # Loop over advection schemes
156161
# ------------------------------------------------------------ #
157162
# Tracer Advection =========================================== #
158163
if FD.Method.Adv == "tracers"
164+
@timeit to "TracerIni" begin
159165
# Tracer Initialization ---
160166
nmx,nmy = 3,3
161167
noise = 1
@@ -184,6 +190,7 @@ for m = 1:ns # Loop over advection schemes
184190
end
185191
# Count marker per cell ---
186192
CountMPC(Ma,nmark,MPC,M,x,y,Δ,NC,NV,1)
193+
end
187194
end
188195
# ------------------------------------------------------------ #
189196
# Visualize initial condition -------------------------------- #
@@ -223,6 +230,7 @@ for m = 1:ns # Loop over advection schemes
223230
for i=2:nt
224231
#@printf("Time step: #%04d\n ",i)
225232

233+
@timeit to "Advection" begin
226234
if FD.Method.Adv == "upwind"
227235
upwindc2D!(D.T,D.T_ex,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
228236
elseif FD.Method.Adv == "slf"
@@ -239,7 +247,7 @@ for m = 1:ns # Loop over advection schemes
239247
Markers2Cells(Ma,nmark,MAVG.PC_th,D.T_ex,MAVG.wte_th,D.wte,x,y,Δ,Aparam,0)
240248
D.T .= D.T_ex[2:end-1,2:end-1]
241249
end
242-
250+
end
243251
display(string("ΔT = ",((maximum(filter(!isnan,D.T))-D.Tmax[1])/D.Tmax[1])*100))
244252

245253
# Plot Solution ---
@@ -295,9 +303,9 @@ for m = 1:ns # Loop over advection schemes
295303
# ------------------------------------------------------------ #
296304

297305
end # End resolution loop
298-
306+
end
299307
end # End method loop
300-
308+
end
301309
q = plot(0,0,layout=(1,3))
302310
for m=1:ns
303311
plot!(q,St.nxny[m,:],St.Δ[m,:],
@@ -331,7 +339,7 @@ if save_fig == 1 || save_fig == -1
331339
Ini.V,"_ResTest.png"))
332340
end
333341
# --------------------------------------------------------------------- #
334-
342+
display(to)
335343
end # Function end
336344

337345
Advection_2D_ResTest()
228 Bytes
Loading
344 KB
Loading
1.7 MB
Loading
-5.08 KB
Loading

0 commit comments

Comments
 (0)