Skip to content

Commit bc80d21

Browse files
authored
Merge pull request #39 from GeoSci-FFM/development
Finalize Exercise 9 and 10
2 parents dbd4641 + a111605 commit bc80d21

File tree

57 files changed

+3688
-146
lines changed

Some content is hidden

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

57 files changed

+3688
-146
lines changed

README.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The **Geod**ynamic **Mod**elling Tool**Box** is a julia package mainly used for
2525
- Solution of the conductive part -->
2626
------------------
2727
### [Heat Diffusion Equation](./examples/DiffusionEquation/1D/README.md)
28-
  The **GeoModBox** provides different finite difference (**FD**) schemes (e.g., [forward](./src/HeatEquation/ForwardEuler.jl) and [backward](./src/HeatEquation/BackwardEuler.jl) Euler, [Crank-Nicholson approach](./src/HeatEquation/CNA.jl), [ADI](./src/HeatEquation/ADI.jl)) to solve the diffusive part of the time-dependent or steady-state *temperature equation* including radioactive heating, in [1-D](./examples/DiffusionEquation/1D/README.md) and [2-D](./examples/DiffusionEquation/2D/README.md). The solvers are located in [src/HeatEquation](./src/HeatEquation/). So far, only *Dirichlet* and *Neumann* thermal boundary conditions are available. Currently, most of the functions assume constant thermal parameters.
28+
  The **GeoModBox** provides different finite difference (**FD**) schemes (e.g., [forward](./src/HeatEquation/ForwardEuler.jl) and [backward](./src/HeatEquation/BackwardEuler.jl) Euler, [Crank-Nicholson approach](./src/HeatEquation/CNA.jl), [ADI](./src/HeatEquation/ADI.jl)) to solve the *diffusive part* of the time-dependent or steady-state *temperature equation* including radioactive heating, in [1-D](./examples/DiffusionEquation/1D/README.md) and [2-D](./examples/DiffusionEquation/2D/README.md). The solvers are located in [src/HeatEquation](./src/HeatEquation/). So far, only *Dirichlet* and *Neumann* thermal boundary conditions are available. Currently, most of the functions assume constant thermal parameters (except for the 1-D solvers).
2929

3030
The examples of solving the *heat diffusion equation* include, amongst others:
3131
- the determination of an [oceanic](./examples/DiffusionEquation/1D/OceanicGeotherm_1D.jl) and [continental](./examples/DiffusionEquation/1D/ContinentalGeotherm_1D.jl) 1-D geotherm profile,
@@ -44,6 +44,25 @@ All numerical schemes methods can be used in the [thermal convection code]() and
4444
------------------ -->
4545

4646
### [Heat Advection Equation](./examples/AdvectionEquation/README.md)
47+
48+
  To solve the *advective part* of the *temperature equation*, the ```GeoModBox.jl``` provides the following different methods:
49+
- an upwind scheme,
50+
- the staggered -leaped frog scheme,
51+
- a semi-lagrangian advection, and
52+
- passive tracers/markers.
53+
54+
The solvers for a the tracer advection method are located in [./src/Tracers](./src/Tracers/), where the remaining advection routines are located in [./src/AdvectionEquation](./src/AdvectionEquation/). The routines are structured in such a way, that any property, as long as the property is defined on the *centroids* including *ghost nodes* on all boundaries, can be advected with the first **three** advection methods listed above. Using passive tracers, one can so far choose to either advect the temperature or to advect the phases. In case of advecting phases, one can define a certain rheology ($\eta$) or density ($\rho$) associated to each phase. The phase ID is used to interpolate the corresponding property from the tracers to the *centroids*.
55+
56+
  A key aspect for the advection equation is the conservation of the **amplitude** and the **shape** of an anomaly. Depending on the method, numerical diffusion or interpolation effects lead to strong deviations of the initial anomaly. For more details see [here](./examples/AdvectionEquation/README.md). The ```GeoModBox.jl``` contains several [routines](./src/InitialCondition/2Dini.jl) to setup a certain initial anomaly, either for properties defined on their correspondig grid (i.e., temperature, velocity, or phase) or for tracers advecting (so far) a certain temperature or phase. Within the examples and the exercise one can choose differen initial temperature and velocity conditions.
57+
58+
  The examples for a two dimensional advection problem include:
59+
- [a 2-D advection, assuming a constant velocity field (e.g., a rigid body rotation)](./examples/AdvectionEquation/2D_Advection.jl), and
60+
- [a resolution test of the same advection example](./examples/AdvectionEquation/2D_Advection_ResolutionTest.jl).
61+
62+
  The exercises include a:
63+
- [1-D advection of a gaussian or block anomaly](./exercises/06_1D_Advection.ipynb), and
64+
- [a 2-D advection coupled with the solution of the diffusion equation](./exercises/07_2D_Energy_Equation.ipynb).
65+
4766
<!--
4867
- Different properties can be advected!
4968
### Discretization Schemes
@@ -54,9 +73,34 @@ All numerical schemes methods can be used in the [thermal convection code]() and
5473
------------------
5574
------------------
5675
## [Momentum Conservation Equation](./examples/StokesEquation/README.md)
76+
77+
<!--
78+
- Constant viscosity
79+
- Variable viscosity
80+
- Coefficients assembly
81+
- Right-hand side updates
82+
- Direct solution
83+
- Defect correction
84+
-->
85+
86+
------------------
87+
------------------
88+
## Code Structure
89+
90+
### Initial Conditions
91+
92+
<!---
93+
- IniTemperature, IniVelocity, IniPhase,
94+
- Tracer Initialization
95+
- ...
96+
-->
97+
98+
### Scaling
99+
57100
------------------
58101
------------------
59102
## [Benchmarks](./examples/)
103+
60104
### [Gaussian Temperature Diffusion](./examples/DiffusionEquation/2D/Gaussian_Diffusion.jl)
61105
<img src="./examples/DiffusionEquation/2D/Results/Gaussian_Diffusion_CNA_nx_100_ny_100.gif" alt="drawing" width="600"/> <br>
62106
**Figure 1. Gaussian Diffusion.** Time-dependent, diffusive solution of a 2-D Gaussian temperature anomaly using the [Crank-Nicholson approach](./src/HeatEquation/CNA.jl) in comparison to its analytical solution. Top Left: 2-D temperature field of the numerical solution and isotherms lines of the numerical (solid black) and analytical (dashed yellow) solution. Top Right: Total deviation to the analytical solution. Bottom Left: 1-D y-profile along x=0. Bottom Right: Root Mean Square total devation of the temperature over time.
@@ -74,6 +118,23 @@ All numerical schemes methods can be used in the [thermal convection code]() and
74118

75119
**Figure 3. Rigid-Body-Rotation.** Time-dependent solution of a rotating circular temperature anomaly using the **upwind (first)**, **semi-lagrangian (second)**, and **tracer (third)** method. Within a circular area of our model domain the velocity is set to the velocity of a rigid rotation and outside euqal to zero. The temperature is scaled by the maximum temperature of the anomaly.
76120

121+
### [Falling Block](./examples/StokesEquation/2D/FallingBlockBenchmark.jl)
122+
123+
<img src="./examples/StokesEquation/2D/Results/Falling_block_ηr_0.0_tracers.gif" alt="drawing" width="500"/> <br>
124+
125+
**Figure 4. Isoviscous Falling Block.** Time-dependent solution of an isoviscous falling block example. The problem is solved with a solver for variable viscosities. The tracers advect the phase ID, which is used to interpolate the density and viscosity on the centroids and vertices, respectively.
126+
127+
<img src="./examples/StokesEquation/2D/Results/FallingBlock_SinkingVeloc_tracers.png" alt="drawing" width="500"/> <br>
128+
129+
**Figure 5. Falling Block Sinking Velocity.** Sinking velocity of the block with respect to the viscosity ratio $\eta_r$ at the initial condition.
130+
131+
<img src="./examples/StokesEquation/2D/Results/FallingBlock_FinalStage_tracers.png" alt="drawing" width="500"/> <br>
132+
133+
**Figure 6. Falling Block Benchmark.** Final tracers distribution for specific cases with $\eta_r \ge 0$.
134+
135+
------------------
136+
------------------
137+
77138
<!--
78139
- Blanckenbach
79140
- Channel Flow
@@ -83,6 +144,3 @@ All numerical schemes methods can be used in the [thermal convection code]() and
83144
- Rigid Body Rotation, check!
84145
- Viscous Inclusion
85146
-->
86-
87-
------------------
88-
------------------

examples/AdvectionEquation/2D_Advection.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ using GeoModBox.InitialCondition
2727
using Base.Threads
2828
using Printf
2929

30-
@doc raw"""
31-
Advection_2D()
32-
33-
...
34-
35-
"""
3630
function Advection_2D()
3731

3832
@printf("Running on %d thread(s)\n", nthreads())
@@ -175,7 +169,7 @@ if FD.Method.Adv==:tracers
175169
wt_th = [similar(D.wt) for _ = 1:nthreads()], # per thread
176170
)
177171
MPC = merge(MPC,MPC1)
178-
Ma = IniTracer2D(Aparam,nmx,nmy,Δ,M,NC,noise)
172+
Ma = IniTracer2D(Aparam,nmx,nmy,Δ,M,NC,noise,0,0)
179173
# RK4 weights ---
180174
rkw = 1.0/6.0*[1.0 2.0 2.0 1.0] # for averaging
181175
rkv = 1.0/2.0*[1.0 1.0 2.0 2.0] # for time stepping
@@ -231,18 +225,18 @@ for i=2:nt
231225

232226
# Advection ===
233227
if FD.Method.Adv==:upwind
234-
upwindc2D!(D,NC,T)
228+
upwindc2D!(D.T,D.T_ex,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
235229
elseif FD.Method.Adv==:slf
236-
slfc2D!(D,NC,T,Δ)
230+
slfc2D!(D.T,D.T_ex,D.T_exo,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
237231
elseif FD.Method.Adv==:semilag
238-
semilagc2D!(D,[],[],x,y,T)
232+
semilagc2D!(D.T,D.T_ex,D.vxc,D.vyc,[],[],x,y,T.Δ[1])
239233
elseif FD.Method.Adv==:tracers
240234
# Advect tracers ---
241235
AdvectTracer2D(Ma,nmark,D,x,y,T.Δ[1],Δ,NC,rkw,rkv,1)
242236
CountMPC(Ma,nmark,MPC,M,x,y,Δ,NC,i)
243237

244238
# Interpolate temperature from tracers to grid ---
245-
Markers2Cells(Ma,nmark,MPC.PG_th,D.T,MPC.wt_th,D.wt,x,y,Δ,Aparam)
239+
Markers2Cells(Ma,nmark,MPC.PG_th,D.T,MPC.wt_th,D.wt,x,y,Δ,Aparam,0)
246240
D.T_ex[2:end-1,2:end-1] .= D.T
247241
end
248242

examples/AdvectionEquation/2D_Advection_ResolutionTest.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ for m = 1:ns # Loop over advection schemes
167167
wt_th = [similar(D.wt) for _ = 1:nthreads()], # per thread
168168
)
169169
MPC = merge(MPC,MPC1)
170-
Ma = IniTracer2D(Aparam,nmx,nmy,Δ,M,NC,noise)
170+
Ma = IniTracer2D(Aparam,nmx,nmy,Δ,M,NC,noise,Ini.p,phase)
171171
# RK4 weights ---
172172
rkw = 1.0/6.0*[1.0 2.0 2.0 1.0] # for averaging
173173
rkv = 1.0/2.0*[1.0 1.0 2.0 2.0] # for time stepping
@@ -222,18 +222,18 @@ for m = 1:ns # Loop over advection schemes
222222
#@printf("Time step: #%04d\n ",i)
223223

224224
if FD.Method.Adv == "upwind"
225-
upwindc2D!(D,NC,T)
225+
upwindc2D!(D.T,D.T_ex,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
226226
elseif FD.Method.Adv == "slf"
227-
slfc2D!(D,NC,T,Δ)
227+
slfc2D!(D.T,D.T_ex,D.T_exo,D.vxc,D.vyc,NC,T.Δ[1],Δ.x,Δ.y)
228228
elseif FD.Method.Adv == "semilag"
229-
semilagc2D!(D,[],[],x,y,T)
229+
semilagc2D!(D.T,D.T_ex,D.vxc,D.vyc,[],[],x,y,T.Δ[1])
230230
elseif FD.Method.Adv == "tracers"
231231
# Advect tracers ---
232232
AdvectTracer2D(Ma,nmark,D,x,y,T.Δ[1],Δ,NC,rkw,rkv,1)
233233
CountMPC(Ma,nmark,MPC,M,x,y,Δ,NC,i)
234234

235235
# Interpolate temperature from tracers to grid ---
236-
Markers2Cells(Ma,nmark,MPC.PG_th,D.T,MPC.wt_th,D.wt,x,y,Δ,Aparam)
236+
Markers2Cells(Ma,nmark,MPC.PG_th,D.T,MPC.wt_th,D.wt,x,y,Δ,Aparam,0)
237237
end
238238

239239
display(string("ΔT = ",((maximum(filter(!isnan,D.T))-D.Tmax[1])/D.Tmax[1])*100))
344 KB
Loading
1.7 MB
Loading
519 KB
Loading
639 KB
Loading
1.05 KB
Binary file not shown.

examples/DiffusionEquation/1D/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111

112112
$$
113113
\begin{equation}
114-
\left. c_{W} = \frac{\partial{T}}{\partial{x}} \right\vert_{W},\ and \ \left. c_{E} = \frac{\partial{T}}{\partial{x}} \right\vert_{E},
114+
\left. c_{W} = \frac{\partial{T}}{\partial{x}} \right\vert_{W},\ \textrm{and}\ \left. c_{E} = \frac{\partial{T}}{\partial{x}} \right\vert_{E},
115115
\end{equation}
116116
$$
117117

@@ -186,7 +186,7 @@ $$
186186
\end{equation}
187187
$$
188188

189-
### Defection Correction Method
189+
### Defect Correction Method
190190

191191
&emsp; The defection correction method is an iterative solution, in which the residual of the conductive part of the *temperature equation* for an initial temperature condition is reduced by a correction term. In case, the system is linear, one iteration is sufficient enough to optain the exact solution.
192192

@@ -256,7 +256,7 @@ where
256256

257257
$$
258258
\begin{equation}
259-
a = \frac{\kappa}{\Delta{x}^2},\ and \ b = \frac{1}{\Delta{t}}.
259+
a = \frac{\kappa}{\Delta{x}^2},\ \textrm{and} \ b = \frac{1}{\Delta{t}}.
260260
\end{equation}
261261
$$
262262

@@ -377,7 +377,7 @@ where $\rho, c_{p}, T, t, k, H,$ and $y$ are the density [kg/m<sup>3</sup>], the
377377
&emsp;A proper conservative finite difference scheme means that the 1-D vertical heat flux and the thermal conductivity *k* are defined on the vertices and *q* is defined as:
378378

379379
$$\begin{equation}
380-
\left. q_{y,m} = -k_m \frac{\partial T}{\partial y}\right\vert_{m},\ for\ m = 1:nv,
380+
\left. q_{y,m} = -k_m \frac{\partial T}{\partial y}\right\vert_{m},\ \textrm{for}\ m = 1:nv,
381381
\end{equation}
382382
$$
383383

@@ -388,7 +388,7 @@ where $nv$ is the number of vertices.
388388
&emsp;Following the discretization as described above, one needs to solve the following equation for each centroid (in an [explicit finite difference formulation](../../../src/HeatEquation/1Dsolvers.jl)):
389389

390390
$$\begin{equation}
391-
\rho_j c_{p,j} \frac{T_{j}^{n+1} - T_{j}^{n}}{\Delta{t}} = -\frac{q_{y,j+1}^{n} - q_{y,j}^{n} }{\Delta{y}} + \rho_j H_j,\ for\ j = 1:nc,
391+
\rho_j c_{p,j} \frac{T_{j}^{n+1} - T_{j}^{n}}{\Delta{t}} = -\frac{q_{y,j+1}^{n} - q_{y,j}^{n} }{\Delta{y}} + \rho_j H_j,\ \textrm{for}\ j = 1:nc,
392392
\end{equation}
393393
$$
394394

examples/DiffusionEquation/2D/Poisson_variable_k.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using GeoModBox.HeatEquation.TwoD, ExtendableSparse, Plots
22

3+
function Poisson_variable_k()
4+
35
# Physikalischer Parameter ---------------------------------------------- #
46
P = (
57
L = 4e3, # [m]
@@ -106,6 +108,9 @@ display(q)
106108
savefig(p,"./examples/DiffusionEquation/2D/Results/Poisson_variable_k_01.png")
107109
savefig(q,"./examples/DiffusionEquation/2D/Results/Poisson_variable_k_02.png")
108110
# ----------------------------------------------------------------------- #
111+
end
112+
113+
Poisson_variable_k()
109114

110115

111116

0 commit comments

Comments
 (0)