2424
2525class RBCProblem2D ():
2626
27- def __init__ (self , Rayleigh = 1e7 , Prandtl = 1 , resFactor = 1 , meshRatio = 4 ,
27+ def __init__ (self , Rayleigh = 1e7 , Prandtl = 1 ,
28+ resFactor = 1 , aspectRatio = 4 , meshRatio = 1 ,
2829 sComm = COMM_WORLD , mpiBlocks = None , writeSpaceDistr = False ,
2930 initFields = None , seed = 999 ):
3031
@@ -36,15 +37,17 @@ def __init__(self, Rayleigh=1e7, Prandtl=1, resFactor=1, meshRatio=4,
3637 "Pr" : Prandtl ,
3738 }
3839
39- self .buildGrid (meshRatio , sComm , mpiBlocks )
40+ self .buildGrid (aspectRatio , meshRatio , sComm , mpiBlocks )
4041 if writeSpaceDistr : self .writeSpaceDistr ()
4142 self .buildProblem ()
4243 self .initFields (initFields , seed )
4344
4445
45- def buildGrid (self , meshRatio , sComm , mpiBlocks ):
46- Lx , Lz = meshRatio , 1
47- Nx , Nz = int (64 * meshRatio * self .resFactor ), int (64 * self .resFactor )
46+ def buildGrid (self , aspectRatio , meshRatio , sComm , mpiBlocks ):
47+ baseSize = 64
48+ Lx , Lz = aspectRatio , 1
49+ Nx = int (baseSize * aspectRatio * meshRatio * self .resFactor )
50+ Nz = int (baseSize * self .resFactor )
4851 dealias = 3 / 2
4952 dtype = np .float64
5053
@@ -233,6 +236,7 @@ def runSimulation(cls, dirName, tEnd, baseDt, tBeg=0, logEvery=100,
233236 p .infos .update (dirName = dirName )
234237
235238 # Solver
239+ if MPI_RANK == 0 : print (" -- building dedalus solver ..." )
236240 solver = p .problem .build_solver (timeStepper )
237241 solver .sim_time = tBeg
238242 solver .stop_sim_time = tEnd
@@ -309,18 +313,22 @@ def log(msg):
309313
310314class RBCProblem3D (RBCProblem2D ):
311315
312- def __init__ (self , Rayleigh = 1e5 , Prandtl = 0.7 , resFactor = 1 , meshRatio = 0.5 ,
316+ def __init__ (self , Rayleigh = 1e5 , Prandtl = 0.7 ,
317+ resFactor = 1 , aspectRatio = 4 , meshRatio = 0.5 ,
313318 sComm = COMM_WORLD , mpiBlocks = None , writeSpaceDistr = False ,
314319 initFields = None , seed = 999 ):
315320 super ().__init__ (
316- Rayleigh , Prandtl , resFactor , meshRatio ,
321+ Rayleigh , Prandtl ,
322+ resFactor , aspectRatio , meshRatio ,
317323 sComm , mpiBlocks , writeSpaceDistr ,
318324 initFields , seed )
319325
320- def buildGrid (self , meshRatio , sComm , mpiBlocks ):
321- Lx , Ly , Lz = 4 , 4 , 1
322- Nx = Ny = int (meshRatio * 64 * self .resFactor )
323- Nz = int (64 * self .resFactor )
326+ def buildGrid (self , aspectRatio , meshRatio , sComm , mpiBlocks ):
327+ baseSize = 32
328+
329+ Lx , Ly , Lz = int (aspectRatio ), int (aspectRatio ), 1
330+ Nx = Ny = int (baseSize * aspectRatio * meshRatio * self .resFactor )
331+ Nz = int (baseSize * self .resFactor )
324332 dealias = 3 / 2
325333 dtype = np .float64
326334
@@ -372,36 +380,36 @@ def printSpaceDistr(self):
372380 from qmat .lagrange import LagrangeApproximation
373381 import matplotlib .pyplot as plt
374382
375- dirName = "test_M4_R1 "
383+ dirName = "run_3D_A4_R1_M1 "
376384
377- problem = RBCProblem2D .runSimulation (
378- dirName , 140 , 1e-2 / 2 , logEvery = 20 , dtWrite = 1.0 ,
379- meshRatio = 4 , resFactor = 1 )
385+ problem = RBCProblem3D .runSimulation (
386+ dirName , 100 , 1e-2 / 2 , logEvery = 20 , dtWrite = 1.0 ,
387+ aspectRatio = 4 , resFactor = 1 , meshRatio = 1 )
380388
381- output = OutputFiles (dirName )
382- approx = LagrangeApproximation (output .z )
389+ # output = OutputFiles(dirName)
390+ # approx = LagrangeApproximation(output.z)
383391
384- nThrow = 40
385- u = output .vData (0 )[nThrow :]
386- b = output .bData (0 )[nThrow :]
387- ux , uz = u [:, 0 ], u [:, 1 ]
388- nX , nZ = output .nX , output .nZ
392+ # nThrow = 20
393+ # nIgnore = 1
394+ # u = output.vData(0)[nThrow::nIgnore]
395+ # b = output.bData(0)[nThrow::nIgnore]
396+ # ux, uz = u[:, 0], u[:, 1]
397+ # nX, nZ = output.nX, output.nZ
389398
390- # RMS quantities
391- mIz = approx .getIntegrationMatrix ([(0 , 1 )])
392- uRMS = (ux ** 2 + uz ** 2 ).mean (axis = (0 , 1 ))** 0.5
393- bRMS = ((b - b .mean (axis = (0 , 1 )))** 2 ).mean (axis = (0 , 1 ))** 0.5
399+ # # RMS quantities
400+ # uRMS = (ux**2 + uz**2).mean(axis=(0, 1))**0.5
401+ # bRMS = ((b - b.mean(axis=(0, 1)))**2).mean(axis=(0, 1))**0.5
394402
395403
396- plt .figure ("z-profile" )
397- xOptU = sco .minimize_scalar (lambda z : - approx (z , fValues = uRMS ), bounds = [0 , 0.5 ])
398- xOptB = sco .minimize_scalar (lambda z : - approx (z , fValues = bRMS ), bounds = [0 , 0.5 ])
404+ # plt.figure("z-profile")
405+ # xOptU = sco.minimize_scalar(lambda z: -approx(z, fValues=uRMS), bounds=[0, 0.5])
406+ # xOptB = sco.minimize_scalar(lambda z: -approx(z, fValues=bRMS), bounds=[0, 0.5])
399407
400- plt .plot (uRMS , output .z , label = f"uRMS[{ nX = } ,{ nZ = } ]" )
401- plt .hlines (xOptU .x , uRMS .min (), uRMS .max (), linestyles = "--" , colors = "black" )
402- plt .plot (bRMS , output .z , label = f"bRMS[{ nX = } ,{ nZ = } ]" )
403- plt .hlines (xOptB .x , bRMS .min (), bRMS .max (), linestyles = "--" , colors = "black" )
404- plt .legend ()
408+ # plt.plot(uRMS, output.z, label=f"uRMS[{nX=},{nZ=}]")
409+ # plt.hlines(xOptU.x, uRMS.min(), uRMS.max(), linestyles="--", colors="black")
410+ # plt.plot(bRMS, output.z, label=f"bRMS[{nX=},{nZ=}]")
411+ # plt.hlines(xOptB.x, bRMS.min(), bRMS.max(), linestyles="--", colors="black")
412+ # plt.legend()
405413
406414
407415 # keMean = np.sum(mIz*ke, axis=-1).mean(axis=-1)
@@ -451,12 +459,13 @@ def printSpaceDistr(self):
451459
452460 # # 1D spectrum (average)
453461 # spectrum1D = []
454- # for i in range(2):
455- # u = uAll[:, i] # (nT, Nx, Nz)
456- # s = np.fft.rfft(u, axis=-2) # over Nx --> (nT, Kx, Nz)
462+ # mIz = approx.getIntegrationMatrix([(0, 1)])
463+ # uAll = np.concat((u, b[:, None, :, :]), axis=1)
464+ # for i in range(uAll.shape[1]):
465+ # s = np.fft.rfft(uAll[:, i], axis=-2) # RFFT over Nx --> (nT, Kx, Nz)
457466 # s *= np.conj(s) # (nT, Kx, Nz)
458467 # s = np.sum(mIz*s.real, axis=-1) # integrate over Nz --> (nT, Kx)
459- # s = s[40:] .mean(axis=0) # mean over nT -> (Kx,)
468+ # s = s.mean(axis=0) # mean over nT -> (Kx,)
460469 # s /= nX**2
461470
462471 # spectrum1D.append(s)
@@ -465,12 +474,13 @@ def printSpaceDistr(self):
465474 # plt.figure("spectrum-1D")
466475 # plt.loglog(waveNum, spectrum1D[0], label="ux")
467476 # plt.loglog(waveNum, spectrum1D[1], label="uz")
477+ # plt.loglog(waveNum, spectrum1D[2], label="b")
468478 # plt.loglog(waveNum, waveNum**(-5/3), '--k')
469479 # plt.legend()
470480
471481 # print(f"iS[ux] : {float(spectrum1D[0].sum())}")
472482 # print(f"iS[uz] : {float(spectrum1D[1].sum())}")
473483
474- plt .figure (f"contour-{ dirName } " )
475- plt .pcolormesh (output .x , output .z , b [- 1 ].T )
476- plt .colorbar ()
484+ # plt.figure(f"contour-{dirName}")
485+ # plt.pcolormesh(output.x, output.z, b[-1].T)
486+ # plt.colorbar()
0 commit comments