conditional-analysis-dns/fluctuation_product_u_ddxc.py
2021-03-11 04:52:36 +09:00

61 lines
1.6 KiB
Python

import argparse
import datetime
import numpy as np
import dnstool
from pycompact import CompactScheme
program_description = '''\
Calculate product of conditional fluctuations of u and ddx(c).
'''
# Commandline argument parser
parser = argparse.ArgumentParser(description=program_description)
parser.add_argument("-c", "--case", help="target case name", required=True)
args = parser.parse_args()
params = vars(args)
cases = dnstool.case_library()
casename = params["case"]
case = cases[casename]
nx, ny, nz = case.shape
cs = CompactScheme(nx, ny, nz, False, True, True, 4, 2, 2)
cfile = "c.dat"
ufile = "u.dat"
ddxcfile = "ddxc.dat"
resfile = "uddxc.dat"
c = np.memmap(cfile, mode="r", dtype=np.double).reshape((nx,-1,ny,nz))
u = np.memmap(ufile, mode="r", dtype=np.double).reshape((nx,-1,ny,nz))
ddxc = np.memmap(ddxcfile, mode="r", dtype=np.double).reshape((nx,-1,ny,nz))
storage = np.memmap(resfile, mode='w+', dtype=np.double, shape=c.shape)
batch_cmean_ddxc_c = np.load('./cmean_ddxc_given_c.npz')
print(*batch_cmean_ddxc_c.keys())
cstar_ddxc_c = batch_cmean_ddxc_c['cstar']
cmean_ddxc_c = batch_cmean_ddxc_c['cmean']
batch_cmean_u_c = np.load('./cmean_u_given_c.npz')
cstar_u_c = batch_cmean_u_c['cstar']
cmean_u_c = batch_cmean_u_c['cmean']
for xidx in range(nx):
print (datetime.datetime.now(), xidx)
u_mean_at_x = np.interp (c[xidx], cstar_u_c[xidx], cmean_u_c[xidx])
u_at_x = u[xidx]
u_flux_at_x = u_at_x - u_mean_at_x
ddxc_mean_at_x = np.interp (c[xidx], cstar_ddxc_c[xidx], cmean_ddxc_c[xidx])
ddxc_at_x = u[xidx]
ddxc_flux_at_x = ddxc_at_x - ddxc_mean_at_x
storage[xidx,:,:,:] = u_flux_at_x * ddxc_flux_at_x
storage.flush()