Skip to content

Commit 739d0c6

Browse files
committed
TL: wip
1 parent ee3ee9c commit 739d0c6

File tree

1 file changed

+25
-17
lines changed
  • pySDC/playgrounds/dedalus/problems

1 file changed

+25
-17
lines changed

pySDC/playgrounds/dedalus/problems/rbc.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,10 @@ def shape(self):
444444
elif self.dim == 3:
445445
return (5, self.nX, self.nY, self.nZ)
446446

447-
@property
448-
def waveNumbers(self) -> np.ndarray:
449-
nX = self.nX
450-
k = np.fft.rfftfreq(nX, 1/nX) + 0.5
451-
return k[:-1].copy()
447+
def getK(self, kRes=1) -> np.ndarray:
448+
size = self.nX//2
449+
dk = 1/kRes
450+
return np.arange(0, size, dk) + 0.5
452451

453452
@property
454453
def vData(self):
@@ -678,16 +677,20 @@ def getBoundaryLayers(self,
678677

679678
return deltas
680679

681-
def getSpectrum(self, which=["uv", "uh"], zVal="all",
680+
def getSpectrum(self, which=["uv", "uh"], zVal="all", kRes=1,
682681
start=0, stop=None, step=1, batchSize=None):
683682
if stop is None:
684683
stop = self.nFields
685684
if which == "all":
686685
which = ["uv", "uh", "b"]
687686
else:
688687
which = list(which)
689-
waveNum = self.waveNumbers
690-
spectrum = {name: np.zeros(waveNum.size) for name in which}
688+
689+
if self.dim == 2:
690+
assert kRes == 1, "cannot have kRes != 1 for 2D case"
691+
692+
k = self.getK(kRes)
693+
spectrum = {name: np.zeros(k.size) for name in which}
691694

692695
approx = LagrangeApproximation(self.z, weightComputation="STABLE")
693696
if zVal == "all":
@@ -711,6 +714,7 @@ def getSpectrum(self, which=["uv", "uh"], zVal="all",
711714
field = u[:, :-1]
712715
if name == "b":
713716
field = self.readFields("buoyancy", r.start, r.stop, r.step)[:, None, ...]
717+
field -= field.mean(axis=(2, 3))[:, :, None, None]
714718
# field.shape = (nT,nVar,nX[,nY],nZ)
715719

716720
if zVal != "all":
@@ -737,16 +741,17 @@ def getSpectrum(self, which=["uv", "uh"], zVal="all",
737741

738742
assert self.nX == self.nY, "nX != nY, that will be some weird spectrum"
739743
nT, nVar, nX, nY, nZ = field.shape
740-
size = waveNum.size
744+
745+
size = k.size
746+
dk = 1/kRes
741747

742748
# compute 2D mode disks
743749
k1D = np.fft.fftfreq(nX, 1/nX)**2
744750
kMod = k1D[:, None] + k1D[None, :]
745751
kMod **= 0.5
746-
idx = kMod.copy()
747-
748-
import pdb; pdb.set_trace()
749752

753+
idx = kMod/dk
754+
np.trunc(idx, out=idx)
750755
idx *= (kMod < size)
751756
idx -= (kMod >= size)
752757

@@ -850,7 +855,8 @@ def toVTR(self, idxFormat="{:06d}"):
850855
# Rayleigh=Rayleigh,
851856
# aspectRatio=aspectRatio, meshRatio=meshRatio, resFactor=resFactor)
852857

853-
dirName = "run_3D_A4_M0.5_R1_Ra1e6"
858+
dirName = "run_3D_A4_M0.5_R1_Ra1e5"
859+
# dirName = "run_3D_A4_M1_R1"
854860
# dirName = "run_M4_R2"
855861
OutputFiles.VERBOSE = True
856862
output = OutputFiles(dirName)
@@ -885,11 +891,13 @@ def toVTR(self, idxFormat="{:06d}"):
885891
plt.xlabel("profile")
886892
plt.ylabel("z coord")
887893

888-
spectrum = output.getSpectrum(which=["b"], zVal="all", start=30, stop=None)
889-
waveNum = output.waveNumbers
894+
kRes = 1
895+
spectrum = output.getSpectrum(
896+
which=["b"], zVal="all", start=30, stop=None, kRes=kRes)
897+
kappa = output.getK(kRes)
890898

891899
plt.figure("spectrum")
892900
for name, vals in spectrum.items():
893-
plt.loglog(waveNum, vals, label=name)
894-
plt.loglog(waveNum, waveNum**(-5/3), '--k')
901+
plt.loglog(kappa, vals, label=name)
902+
plt.loglog(kappa, kappa**(-5/3), '--k')
895903
plt.legend()

0 commit comments

Comments
 (0)