Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Key words: stratified turbulence, data-driven modeling

1898 views
License: MIT
ubuntu2204
Kernel: Python 3 (system-wide)
import numpy as np import matplotlib.pyplot as plt import cmocean from matplotlib import cm from matplotlib.colors import ListedColormap, LinearSegmentedColormap import scipy as sp import scipy.special import seaborn as sns import scipy.ndimage from matplotlib.gridspec import GridSpec %matplotlib inline from matplotlib import rc rc('font',**{'family':'sans-serif','sans-serif':['Helvetica'], 'size':20}) rc('text', usetex=True) rc('text.latex', preamble=r'\usepackage{mathrsfs}') from matplotlib.gridspec import GridSpec
RC = {'figure.figsize':(10,5), 'axes.facecolor':'white', 'axes.edgecolor':' .15', 'axes.linewidth':' 1.25', 'axes.grid' : True, 'grid.color': '.8', 'font.size' : 15, "xtick.major.size": 4, "ytick.major.size": 4} plt.rcParams.update(RC) sns.set_palette(sns.color_palette('dark'), n_colors=None, desat=None, color_codes=False)
#Define non-dimensional parameters for the simulation Re = 2.478883e+03 Fr = 1.105914e+00 Ri = 1/((Fr/(2*np.pi)))**2 Pr = 7 ch = 50 #input column height
#Define dimensionless functions f and g from equations (2.14) and (2.15) in the manuscript #These can be easily modified by the user a = 1 b = 0.8 c = 0.9 d = 0.9 def f(x): return 19/8 + 11/8*np.tanh(a*np.log(x)-b) def g(x): return 2 + np.tanh(c*np.log(x)-d)
#Model name model = 'pcnn_eps' dns_data_loc = '../data/DNS_data/Pr7_decaying/' output_loc = '../data/PCNN_eps/'
t = ['T=0.5','T=1', 'T=2', 'T=4', 'T=6', 'T=7.7'] xdim, zdim = 500, 500 dudz, drdz, eps, isotropic_eps, empirical_eps, pcnn_eps, pcnn_mean_eps, reb, drtdz, T = [], [], [],[],[], [],[], [],[], [] count=0 for i in range(0,6): #Choose timestep(s) to load here (from the list 't' above) T.append(t[i]) dudz.append(np.load(dns_data_loc+ T[count]+'/dudz.npy').reshape((xdim,zdim))) drtdz.append(np.load(dns_data_loc+ T[count]+'/drtdz.npy').reshape((xdim,zdim))) eps.append(np.load(dns_data_loc + T[count]+'/eps.npy').reshape((xdim,zdim))) isotropic_eps.append(15/4*(dudz[count])) empirical_eps.append(f(sp.ndimage.gaussian_filter(dudz[count], sigma=(0,50))*Re/Ri)*dudz[count]) reb.append(np.mean(eps[count])*Re/Ri) pcnn_eps.append(np.load(output_loc+model+'_sample_'+T[count]+'.npy')) pcnn_mean_eps.append(np.load(output_loc+model+'_means_'+T[count]+'.npy').reshape((xdim,zdim))) count+=1
print(T)
['T=0.5', 'T=1', 'T=2', 'T=4', 'T=6', 'T=7.7']
maes_iso = [] maes_emp = [] maes_sample = [] maes_ensemble = [] column_iso = [] column_emp = [] column_sample = [] column_ensemble = [] mean = [] mean_surr=[] mean_surr2=[] for i in range(len(T)): maes_ensemble.append(np.mean(abs(10**pcnn_mean_eps[i].reshape(xdim,zdim).T - (eps[i]).reshape(xdim,zdim).T))) maes_sample.append(np.mean(abs(10**pcnn_eps[i].reshape(xdim,zdim).T - (eps[i]).reshape(xdim,zdim).T))) maes_iso.append(np.mean(np.abs((isotropic_eps[i].reshape(xdim,zdim).T) -(eps[i]).reshape(xdim,zdim).T))) maes_emp.append(np.mean(np.abs((empirical_eps[i].reshape(xdim,zdim).T) -(eps[i]).reshape(xdim,zdim).T))) mean.append(np.mean(np.abs((eps[i])))) column_ensemble.append(np.mean(abs(np.mean(10**pcnn_mean_eps[i].reshape(xdim,zdim).T, axis=0) - np.mean((eps[i]).reshape(xdim,zdim).T, axis=0)))) column_iso.append(np.mean(np.abs(np.mean((isotropic_eps[i]).reshape(xdim,zdim).T, axis=0) -np.mean((eps[i]).reshape(xdim,zdim).T, axis=0)))) column_emp.append(np.mean(np.abs(np.mean((empirical_eps[i]).reshape(xdim,zdim).T, axis=0) -np.mean((eps[i]).reshape(xdim,zdim).T, axis=0)))) column_sample.append(np.mean(abs(np.mean(10**pcnn_eps[i].reshape(xdim,zdim).T, axis=0) - np.mean((eps[i]).reshape(xdim,zdim).T, axis=0)))) mean_surr.append(np.mean(np.mean((isotropic_eps[i]).reshape(xdim,zdim).T, axis=0)/np.mean((eps[i]).reshape(xdim,zdim).T, axis=0))) mean_surr2.append(np.mean(np.mean((empirical_eps[i]).reshape(xdim,zdim).T, axis=0)/np.mean((eps[i]).reshape(xdim,zdim).T, axis=0)))
# plt.style.use('seaborn-whitegrid') red = sns.color_palette('deep')[2] log_reb = np.log10(reb) rc('font',**{'family':'sans-serif','sans-serif':['Helvetica'], 'size':15}) gs=GridSpec(1,2, width_ratios=[1,1], wspace=0.2, hspace=0.12) fig=plt.figure(figsize=(10,3)) ax1=fig.add_subplot(gs[0,0]) ax2=fig.add_subplot(gs[0,1]) ax1.plot(log_reb, np.array(maes_ensemble)/np.array(mean), marker='s', markersize=5, label='$\\mathrm{Model\ ensemble}$') ax1.plot(log_reb,np.array(maes_sample)/np.array(mean), marker='s', markersize=5, label='$\\mathrm{Model\ sample}$') ax1.plot(log_reb,np.array(maes_iso)/np.array(mean),color=red, marker='s', markersize=5, label='$\\mathrm{Surrogate}$') ax1.plot(log_reb,np.array(maes_emp)/np.array(mean),color=red, marker='s', markersize=5, label='$\\mathrm{Empirical\ surrogate}$', linestyle='--') ax1.set_xlim(0.1,2) ax1.set_ylim(0,2) ax1.annotate('$b)$', (2.25, 2.05), annotation_clip=False) ax1.annotate('$a)$', (-0.2, 2.05), annotation_clip=False) ax1.set_ylabel('$\\mathrm{Mean\ relative\ error }$') ax1.set_xlabel('$\\log_{10} (Re_b^S)$') # ax1.legend(loc='upper right') ax1.set_title('$\\mathrm{Pointwise\ error\ }$') ax2.plot(log_reb,np.array(column_ensemble)/np.array(mean), marker='s', markersize=5) ax2.plot(log_reb,np.array(column_sample)/np.array(mean), marker='s', markersize=5) ax2.plot(log_reb,np.array(column_iso)/np.array(mean),color=red, marker='s', markersize=5) ax2.plot(log_reb,np.array(column_emp)/np.array(mean), color=red, marker='s', markersize=5, linestyle='--') ax2.set_xlim(0.1,2) ax2.set_ylim(0,2) ax2.set_yticklabels([]) ax2.set_xlabel('$\\log_{10} (Re_b^S)$') ax2.set_title('$\\mathrm{Column\ mean\ error\ }$') fig.show()
Image in a Jupyter notebook