def read_psd(fdir, **kwargs): y_symm = kwargs.get('y_symm', True) fname = fdir + 'spectra/' + 'psd.bin' # generate file name # fetch nx, ny, nz dnsdict = ch.read_dnsin(fdir + 'dns.in') mesh = ch.mesh(dnsdict) # create memmap diskacc = np.memmap(fname, mode='r', dtype=np.float64, shape=(6, mesh.ny + 1, mesh.nz + 1, mesh.nx + 1)) # check file size and allocate memory tct.io.size_ram_check(fname) all_spectra = np.zeros((6, mesh.ny + 1, mesh.nz + 1, mesh.nx + 1)) # load all_spectra += diskacc # average on y (if requested) if y_symm: all_spectra += diskacc[:, ::-1, :, :] all_spectra /= 2 return all_spectra, mesh.kx, mesh.kz, mesh.y[1:-1]
def get_ebox(fdir, t_cnvrg, problem, uk, tau_w): _, _, _, _, kkint, _ = uiuj.read_integrals(fdir) dns_in = ch.read_dnsin(fdir + 'dns.in') realpha, repi, alpha, beta = get_properties(fdir, t_cnvrg, problem, uk, tau_w) upi = repi / dns_in['re'] powt = upi**3 if has_been_set: powt = local_power #phil = 1/(realpha+1) #pl = realpha/(realpha+1) if problem == 'cou': pl = (repi * alpha**2) / 2 * (sqrt(1 + 4 / (repi * alpha**2)) - 1) phid = repi * (beta - alpha**2) elif problem == 'poi': pl = (3 * repi * alpha**2) / 2 * (sqrt(1 + 4 / (3 * repi * alpha**2)) - 1) phid = repi * (beta - 3 * alpha**2) phil = 1 - pl pd = -phid eps = -kkint['psdiss'] / powt / 2 return phil, phid, pl, pd, eps
def get_properties(fdir, t_cnvrg, problem, uk, tau_w): _, me, uv, uu, vv, ww, kk, mk = uiuj.read(fdir, variant=None) dns_in = ch.read_dnsin(fdir + 'dns.in') # calculate power input and upi powt = tau_w * uk # <-------------------- upi = powt**(1 / 3) # <-------------------- repi = dns_in['re'] * upi local_power = powt has_been_set = True # calculate alpha for realpha if problem == 'cou': barealpha = integrate.simps(-uv['var'].values, uv['y'].values) / 2 elif problem == 'poi': integrand = np.multiply(-uv['var'].values, (1 - uv['y'].values)) barealpha = integrate.simps(integrand, uv['y'].values) / 2 realpha = dns_in['re'] * barealpha / uk # calculate alpha and beta uvpow = uv['var'].values / (upi**2) beta = integrate.simps(np.square(uvpow), uv['y'].values) / 2 if problem == 'cou': alpha = integrate.simps(-uvpow, uv['y'].values) / 2 elif problem == 'poi': integrand = np.multiply(-uvpow, (1 - uv['y'].values)) alpha = integrate.simps(integrand, uv['y'].values) / 2 return realpha, repi, alpha, beta
import channel as ch # get mesh info dnsin = ch.read_dnsin('') mesh = ch.mesh(dnsin) retau = input('Please enter extimate of friction Re number: ') retau = float(retau) print(dnsin) print('dx_plus', mesh.dx * retau) print('dz_plus', mesh.dz * retau) print('dy_wall', mesh.dyw * retau) print('dy_center', mesh.dyc * retau) print('simulation time to achieve 150 mixed units', 150 / retau * dnsin['re'])
description= 'Plot the variance history previously calculated by var_history.') argpar.add_argument( '--animate', help='''Animate the plot of instantaneous variances of selected components. For instance, "--animate uv" creates the animation for components u and v, while "--animate w" only animates the w component.''' ) settings = argpar.parse_args() # read postpro cumul = np.fromfile("var_history/cumulative.bin", dtype=np.float64) insta = np.fromfile("var_history/instantaneous.bin", dtype=np.float64) # create dictionary for dnsdata meshdata = ch.read_dnsin("dns.in") re = meshdata['re'] ny = meshdata['ny'] # generate mesh data m = ch.mesh(meshdata) m.y = m.y[1:-1] # remove ghost cells # get viscous units with open('var_history/dudy.txt') as f: dudy = float(f.readline()) #dudy = 500 tauw = 1 / re * dudy utau = sqrt(tauw) retau = re * utau print("ReTau:", retau)
import sys import os from math import floor argz = sys.argv[1:] # generate path to exec and verify its existance exec_dir = sys.path[0] + '/print_time' # path where script resides + exec name if not os.path.isfile(exec_dir): raise (Exception( 'missing executable file "print_time". Please run "make" in the utilities folder of your "channel".' )) # get time of selected fields stream = os.popen(exec_dir + ' ' + ' '.join(argz)) read_timez = stream.read().split('\n')[0] read_timez = read_timez.split(' ') read_timez = list(filter(lambda x: x != '', read_timez)) # read dtfield from dns.in indns = read_dnsin('dns.in') dtfield = float(indns['dt_field']) # THIS PRINTS ONLY FILES WITH MISMATCH BETWEEN TIME AND FILE NUMBER ii = 0 for ff in argz: fno = int(''.join(c for c in ff if c.isdigit())) # file number rndt = float(read_timez[ii]) if not fno == int(round(rndt / dtfield)): print(ff, "-->", rndt) ii += 1
def tennis(fdir, t_cnvrg, problem, uk, tau_w): # Calculates ebox terms with both extended Reynolds decomposition of mean field and large/small decomposition of fluctuation field. # Syntax: # phil, pl_s, pl_l, pd_s, pd_l, t_cross, eps_s, eps_l, phid = tennis(fdir, t_cnvrg, problem) # ------------------------------------------------------------------------------------------ # - fdir is a string containing the path to the postprocessed files # - t_cnvrg is the instant of time (as of Runtimedata) at which statistical convergence is achieved # - problem is a string, either 'cou' or 'poi', which indicates the type of flow in analysis # rapid discussion of signs of returned quantities: # - production terms are a SOURCE FOR TKE, so they are positive if power is passed to TKE # - dissipation terms (laminar, deviation, turbulent large/small) here calculated are always positive # - sign of tcross is positive if energy flows from small to large # read data _, _, _, _, kkint_large, _ = uiuj.read_integrals(fdir, variant='large') _, _, _, _, kkint_small, _ = uiuj.read_integrals(fdir, variant='small') _, me, uv, _, _, _, _, _ = uiuj.read(fdir, variant=None) _, _, uvS, _, _, _, _, _ = uiuj.read(fdir, variant='small') _, _, uvL, _, _, _, _, _ = uiuj.read(fdir, variant='large') dns_in = ch.read_dnsin(fdir + 'dns.in') # get properties realpha, repi, alpha, beta = get_properties(fdir, t_cnvrg, problem, uk, tau_w) upi = repi / dns_in['re'] powt = upi**3 uk_upi = repi * alpha / realpha # = uk / upi # hence calculate phid phil = 1 / (1 + realpha) # <-------------------- if problem == 'cou': phid = repi * (beta - alpha**2) elif problem == 'poi': phid = repi * (beta - 3 * alpha**2) # <-------------------- # now read terms from integrals of large/small fluctuations eps_s = -kkint_small['psdiss'] / powt / 2 # <-------------------- eps_l = -kkint_large['psdiss'] / powt / 2 # <-------------------- t_cross = (kkint_large['tcross'] - kkint_small['tcross']) / 2 / powt / 2 # <-------------------- # sign: positive if power to large # now production terms are missing; for this, in addition to uv, # profiles of du_l/dy and du_delta/dy are needed dul = np.empty_like(uv['var'].values) if problem == 'cou': dul[:] = uk_upi elif problem == 'poi': dul[:] = -3 * uk_upi * me['y'].values dud = me['Uy'].values / upi - dul # shortcuts for uv profiles uvsp = uvS['var'] / (upi**2) uvlp = uvL['var'] / (upi**2) # small production pl_s = -integrate.simps(np.multiply(dul, uvsp), uv['y'].values) / 2 # <-------------------- pd_s = -integrate.simps(np.multiply(dud, uvsp), uv['y'].values) / 2 # <-------------------- # large production pl_l = -integrate.simps(np.multiply(dul, uvlp), uv['y'].values) / 2 # <-------------------- pd_l = -integrate.simps(np.multiply(dud, uvlp), uv['y'].values) / 2 # <-------------------- return phil, pl_s, pl_l, pd_s, pd_l, t_cross, eps_s, eps_l, phid
import channel as ch from copy import copy # get mesh info dnsin = ch.read_dnsin('dns.in') mesh = ch.mesh(dnsin) retau = input('Please enter extimate of friction Re number: ') retau = float(retau) def get_nzd(nzz): guess = 3*nzz once_more = True while once_more: prev_guess = copy(guess) while (guess%2) == 0: guess /= 2 if guess==1 or guess==3: once_more = False else: guess = copy(prev_guess) + 1 return prev_guess print() print('Parallelisation') print('---------------') print('nx+1', mesh.nx+1) print('nzd (extimate!)', get_nzd(mesh.nz)) print()
import numpy as np from argparse import ArgumentParser from channel import read_dnsin from progressbar import progressbar indict = read_dnsin('dns.in') nx = indict['nx'] ny = indict['ny'] nz = indict['nz'] # parse input arguments argpar = ArgumentParser( description= 'Shift a velocity field in the x direction by half an extimate of the centerline velocity; designed for Poiseuille (symmetric) flows.' ) argpar.add_argument('--centerline', '-c', help='Extimate of centerline velocity.', nargs=1, type=float) argpar.add_argument( '--reverse', '-r', help='Reverse a previous shift, so that wall velocity becomes zero.', action='store_true') argpar.add_argument('file_list', metavar='file.ext', type=str, nargs='+', help='Files on which to apply shift.') settings = argpar.parse_args()