*** I do not see any option to attach files except images. So I am pasting the entire script here.
---------------------------------------------------------------------- DNS code ------------------------------------------------------------
import numpy as np
import mpi4py as MPI
import h5py as hp
import dedalus.public as de
from dedalus.extras import flow_tools
import time
import os
from mpi4py import MPI
from dedalus.tools import post
de.logging_setup.rootlogger.setLevel('DEBUG')
import logging
logger = logging.getLogger(__name__)
## Geometrical arameters
Lx=2*np.pi
Ly=np.pi
Lz=2
## Numerical parameters
Nx=32
Ny=32
Nz=32
## Total time of simulation
Tf=20
## Control Parameters
Retau=60
Recl=Retau**2/2.0
## Name of case
csn3d="U"
csn2d="XYslice"
#Time interval to save data
dT3d=10
dT2d=5
## Time interval for computation of CFL and flow monitoring
dT=1.0
## Initial time step
dt=0.01
## Create bases
xbasis=de.Fourier('x',Nx,interval=(0,Lx),dealias=3/2)
ybasis=de.Fourier('y',Ny,interval=(0,Ly),dealias=3/2)
zbasis=de.Chebyshev('z',Nz,interval=(-Lz/2.0,Lz/2.0))
## Creat the domain
domain = de.Domain([xbasis, ybasis, zbasis], grid_dtype=np.float64)
## Declare the problem
problem=de.IVP(domain, variables=['u','uz','v','vz','w','wz','p'])
## Declare the problem parameters
problem.parameters['Re']=Recl
problem.substitutions['U']='1-z**2'
problem.substitutions['Uz']='-2*z'
## Write the wquations
problem.add_equation("dx(u) + dy(v) + wz = 0")
problem.add_equation("dt(u) + U*dx(u) - (1.0/Re)*( dx(dx(u)) + dy(dy(u)) + dz(uz) ) + dx(p) + w*Uz = - u*dx(u) - v*dy(u) - w*uz ")
problem.add_equation("dt(v) + U*dx(v) - (1.0/Re)*( dx(dx(v)) + dy(dy(v)) + dz(vz) ) + dy(p) = - u*dx(v) - v*dy(v) - w*vz ")
problem.add_equation("dt(w) + U*dx(w) - (1.0/Re)*( dx(dx(w)) + dy(dy(w)) + dz(wz) ) + dz(p) = - u*dx(w) - v*dy(w) - w*wz ")
problem.add_equation("uz-dz(u)=0")
problem.add_equation("vz-dz(v)=0")
problem.add_equation("wz-dz(w)=0")
## Add the boundary conditions
problem.add_bc("left(u) = 0")
problem.add_bc("left(v) = 0")
problem.add_bc("left(w) = 0")
problem.add_bc("right(u) = 0")
problem.add_bc("right(v) = 0")
problem.add_bc("right(w) = 0",condition="(nx != 0) or (ny != 0)")
problem.add_bc("integ_z(p) = 0",condition="(nx == 0) and (ny == 0)")
# Build solver and set up the integration limits
solver = problem.build_solver(de.timesteppers.SBDF2)
solver.stop_sim_time = Tf
## Set up the initial condition
u = solver.state['u']
uz = solver.state['uz']
v = solver.state['v']
vz = solver.state['vz']
w = solver.state['w']
wz = solver.state['wz']
## Multiple seeds initial condition
nseeds=2
Amp=7
xc,yc,zc=domain.grids(scales=1)
for ns in range(0,nseeds):
a=np.random.uniform(0,Lx)
b=np.random.uniform(0,Ly)
theta=np.deg2rad(np.random.uniform(15,60))
xp=(xc-a)*np.cos(theta) + (yc-b)*np.sin(theta)
yp=-(xc-a)*np.sin(theta) + (yc-b)*np.cos(theta)
u['g']+=0
v['g']+=-Amp*(1-zc**2)*xp*yp*np.exp(-xp**2-yp**2)*(1-5*zc**2)
w['g']+=Amp*zc*(1-zc**2)**2*xp*np.exp(-xp**2-yp**2)*(1-2*yp**2)
u.differentiate('z', out=uz)
v.differentiate('z', out=vz)
w.differentiate('z', out=wz)
### Store full 3D field
Ustore = solver.evaluator.add_file_handler(csn3d, sim_dt=dT3d, max_writes=1)
Ustore.add_system(solver.state)
### Save the XY slices
XYslice = solver.evaluator.add_file_handler(csn2d, sim_dt=dT2d, max_writes=1)
# Save the midplane streamwise velocity
XYslice.add_task("interp(u,z=0)", scales=1,name='u')
#Save Ub(x,y)
XYslice.add_task("integ_z(u)",scales=1,name='ub')
#Save dudz
XYslice.add_task("interp(dz(u),z=1)",scales=1,name='dudzt')
XYslice.add_task("interp(dz(u),z=-1)",scales=1,name='dudzb')
#Save dvdz
XYslice.add_task("interp(dz(v),z=1)",scales=1,name='dvdzt')
XYslice.add_task("interp(dz(v),z=-1)",scales=1,name='dvdzb')
## Save int(u**2), int(v**2), int(w**2)
XYslice.add_task("integ_z(u**2)",scales=1,name='iu2')
XYslice.add_task("integ_z(v**2)",scales=1,name='iv2')
XYslice.add_task("integ_z(w**2)",scales=1,name='iw2')
# CFL
CFL = flow_tools.CFL(solver, initial_dt=dt, safety=0.5, max_dt=0.2)
CFL.add_velocities(('U+u', 'v', 'w'))
# Flow properties
# flow = flow_tools.GlobalFlowProperty(solver)
# flow.add_property("sqrt(u*u + v*v + w*w)", name='L2')
# Main loop
try:
start_run_time = time.time()
count=0
while solver.ok:
# Compute CFL and adjust
dt = CFL.compute_dt()
nsteps=int(dT/dt)
for i in range(0,nsteps):
#Time step
solver.step(dt)
############-------------------------- Print properties of the state -----------------------############
## Viscosity of the flow
nu=1.0/solver.problem.namespace['Re'].value
## Compute the bulk flow
u.set_scales(1)
ub=u['g'].mean()
## Compute the wall shear
dudy=u.differentiate('z')
dudy.set_scales(1)
DuDy=0.5*( np.abs((-2+np.average(dudy['g'][:,:,0])))+np.abs((2+np.average(dudy['g'][:,:,-1]))) )
tauw=nu*DuDy
## L2 norm
# L2=flow.grid_average('L2')
## Compute the Cf
cf=2*tauw/(ub+2.0/3.0)**2
## Log the info
except:
logger.error('Exception raised, triggering end of main loop.')
raise
finally:
end_run_time = time.time()
logger.info('Run time: %.2f sec' %(end_run_time-start_run_time))
logger.info('Run time: %f cpu-hr' %((end_run_time-start_run_time)/60/60*domain.dist.comm_cart.size))
## Clean up the file system
post.merge_process_files("XYslice", cleanup=True)
post.merge_process_files("U", cleanup=True)
------------------------------------------------------------------ end of script --------------------------------------------------------
I also tried to compute the CFL every time step with the similar conditions as in the 3D Rayleigh Bernard example. But, it slows the code even more.
Thank you for taking time to help me out.
Regards,
Pavan