Skip to content

Commit 01c7e09

Browse files
committed
TL: added script for stability investigation
1 parent bc44fd5 commit 01c7e09

File tree

4 files changed

+77
-16
lines changed

4 files changed

+77
-16
lines changed

pySDC/playgrounds/dedalus/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ scripts/run_*
1111
scripts/init_*
1212
scripts/runInit_*
1313
scripts/initRun_*
14+
scripts/stab_*

pySDC/playgrounds/dedalus/problems/rbc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,13 +1156,13 @@ def checkDNS(spectrum:np.ndarray, kappa:np.ndarray, sRatio:int=4, nThrow:int=0):
11561156
11571157
.. math::
11581158
\log(s_{tail}) \simeq
1159-
a\log(\kappa_{tail})^2 + b\log(\kappa_{tail}) + c
1159+
c_2\log(\kappa_{tail})^2 + c_1\log(\kappa_{tail}) + c_0
11601160
11611161
where :math:`(\kappa_{tail},s_{tail})` is continuous subset of the
11621162
mapping :math:`(\kappa,s)` for large values of :math:`\kappa`
11631163
(i.e spectrum tail).
11641164
If the quadratic regression produces a convex polynomial
1165-
(i.e :math:`a > 0`) then the simulation is considered as under-resolved
1165+
(i.e :math:`c_2 > 0`) then the simulation is considered as under-resolved
11661166
(no DNS).
11671167
Per default, the tail is built considering the
11681168
**last quarter of the spectrum**.
@@ -1187,7 +1187,7 @@ def checkDNS(spectrum:np.ndarray, kappa:np.ndarray, sRatio:int=4, nThrow:int=0):
11871187
Dictionnary containing the results, with keys :
11881188
11891189
- `DNS` : boolean indicating if the simulation is well resolved
1190-
- `coeffs` : the :math:`a,b,c` regression coefficients, stored in a tuple
1190+
- `coeffs` : the :math:`c_2,c_1,c_0` regression coefficients, stored in a tuple
11911191
- `kTail` : the :math:`\kappa_{tail}` values used for the regression
11921192
- `sTail` : the :math:`s_{tail}` values used for the regression
11931193
@@ -1226,7 +1226,7 @@ def fun(coeffs):
12261226
import matplotlib.pyplot as plt
12271227

12281228
# dirName = "run_3D_A4_M0.5_R1_Ra1e6"
1229-
dirName = "run_3D_A4_M1_R2_Ra1e6"
1229+
dirName = "run_3D_A4_M1_R2_Ra1.5e5"
12301230
# dirName = "run_M4_R2"
12311231
# dirName = "test_M4_R2"
12321232
OutputFiles.VERBOSE = True
@@ -1304,7 +1304,7 @@ def fun(coeffs):
13041304

13051305
kappa = output.kappa
13061306
plt.figure("spectrum")
1307-
for name in ["u"]:
1307+
for name in ["u", "uv", "uh", "b", "p"]:
13081308
vals = spectrum[name]
13091309
check = checkDNS(vals, kappa, sRatio=3)
13101310
a, b, c = check["coeffs"]

pySDC/playgrounds/dedalus/scripts/checkDNS.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
"run_3D_A4_M0.5_R1_Ra1e5",
2222
]
2323

24-
# simDirs = [
25-
# "run_3D_A4_M1_R1_Ra5e4",
26-
# "run_3D_A4_M1_R1_Ra1e5",
27-
# "run_3D_A4_M1_R1_Ra1.5e5",
28-
# "run_3D_A4_M1_R1_Ra2e5",
29-
# "run_3D_A4_M1_R1_Ra1e6",
30-
# ]
24+
simDirs = [
25+
"run_3D_A4_M1_R1_Ra5e4",
26+
"run_3D_A4_M1_R1_Ra1e5",
27+
"run_3D_A4_M1_R1_Ra1.5e5",
28+
"run_3D_A4_M1_R1_Ra2e5",
29+
"run_3D_A4_M1_R1_Ra1e6",
30+
]
31+
32+
simDirs = [
33+
"run_3D_A4_M1_R2_Ra1.5e5",
34+
"run_3D_A4_M1_R2_Ra1e6",
35+
]
3136

3237
df = pd.DataFrame(
3338
columns=["Ra", "c_2[u]", "c_2[uv]", "c_2[uh]", "c_2[b]", "c_2[p]"])
@@ -38,10 +43,11 @@
3843
df.loc[i, "Ra"] = float(dirName.split("_Ra")[-1])
3944

4045
# assert len(output.times) == 61, f"not 61 fields for {dirName}"
41-
if len(output.times) == 61:
42-
start = 20
43-
else:
44-
start = 60
46+
# if len(output.times) == 61:
47+
# start = 20
48+
# else:
49+
# start = 60
50+
start = 20
4551

4652
spectrum = output.getSpectrum(
4753
which="all", zVal="all",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Tue Sep 30 13:02:50 2025
5+
6+
@author: cpf5546
7+
"""
8+
import os
9+
import matplotlib.pyplot as plt
10+
11+
from pySDC.playgrounds.dedalus.timestepper import SDCIMEX
12+
from pySDC.playgrounds.dedalus.problems.rbc import RBCProblem3D, OutputFiles
13+
14+
15+
dtBase = 2.50e-03
16+
nSteps = 10
17+
nCycles = 2
18+
19+
Rayleigh = 1.5e5
20+
timeScheme = "SDC"
21+
stabDir = f"stab_A4_M1_R1_{timeScheme}"
22+
initSol = "init_3D_A4_M1_R1.pySDC"
23+
24+
SDCIMEX.setParameters(
25+
nNodes=4, nodeType="LEGENDRE", quadType="RADAU-RIGHT",
26+
nSweeps=4, initSweep="COPY", explSweep="PIC", implSweep="MIN-SR-FLEX",
27+
)
28+
29+
os.makedirs(stabDir, exist_ok=True)
30+
31+
dtFactors = [f*10**e for e in range(nCycles) for f in [1, 2, 5]]
32+
fmtSuffix = f":0{nCycles}d"
33+
34+
plt.figure("spectrum")
35+
for fac in dtFactors:
36+
dtRun = dtBase*fac
37+
runDir = f"{stabDir}/dt_f" + ("{"+fmtSuffix+"}").format(fac)
38+
39+
prob = RBCProblem3D.runSimulation(
40+
runDir, dtRun*nSteps, dtRun, timeScheme=timeScheme,
41+
dtWrite=dtRun*nSteps, initField=initSol,
42+
aspectRatio=4, meshRatio=1, resFactor=1,
43+
Rayleigh=Rayleigh, Prandtl=0.7,
44+
)
45+
46+
if "tComp" in prob.infos:
47+
break
48+
49+
output = OutputFiles(runDir)
50+
spectrum = output.getSpectrum(which="all", start=1)
51+
52+
# plt.loglog(spectrum["kappa"], spectrum["p"], label="f"+("{"+fmtSuffix+"}").format(fac))
53+
54+
# plt.legend()

0 commit comments

Comments
 (0)