def main_integral(targetpath, simdir, relambda, simnblocks): nSimBins = simnblocks * 16//2 - 1 eps, nu = epsNuFromRe(relambda) runData = getAllData(simdir, eps, nu, nSimBins, 1) vecParams, vecMean, vecStd = readAllFiles(targetpath, [relambda]) vecSpectra, vecEnStdev, fullSpectra, vecCovLogE = readAllSpectra(targetpath, [relambda]) plt.figure() axes = [plt.subplot(1, 1, 1)] axes[0].set_xlabel(r'$k \eta$') axes[0].grid() axes[0].set_ylabel(r'$\Delta E(k) / E(k)$') ci = 0 nyquist, nruns = vecSpectra.shape[0], vecSpectra.shape[1] print(nyquist) leta = np.power(nu**3 / eps, 0.25) Ekscal = np.power(nu**5 * eps, 0.25) nyquist = simnblocks * 16 // 2 - 1 logE = np.log(runData['spectra']) logE = np.mean(logE, axis=0) logEtgt = vecSpectra[:nyquist, 0] print(logE.shape, logEtgt.shape, vecEnStdev.shape) dLogE = np.zeros(nyquist) for i in range(nyquist): dLogE[i] = (logE[i] - logEtgt[i]) / vecEnStdev[i] K = np.arange(1, nyquist+1, dtype=np.float64) * leta axes[0].plot(K, dLogE) plt.show()
def findBestHyperParams(path, re, token, gridSize, logSpectra, logEnStdev): bestDir, bestLL, bestStats = None, -1e9, None gridToken = 'BPD%03d' % gridSize actualNbins = gridSize // 2 - 1 binSize = clipBinSize if clipBinSize else actualNbins logSpectra, logEnStdev = logSpectra[:binSize], logEnStdev[:binSize] eps, nu = epsNuFromRe(re) # allow token to be actually a path if token[0] == '/': alldirs = glob.glob(token + '*' + ('RE%03d' % re) + '*') else: alldirs = glob.glob(path + '/*' + ('RE%03d' % re) + '*') for dirn in alldirs: if token not in dirn: continue if gridToken not in dirn: continue # if token did not produce any stats file (e.g. not applicable to dns): if bestDir is None: bestDir = dirn runData = getAllData(dirn, eps, nu, actualNbins, fSkip=1) avgLogSpec = np.log(runData['spectra'][:, :binSize]) LL = -np.sum(((avgLogSpec - logSpectra) / logEnStdev)**2, axis=1) #print('RL size', avgLogSpec.shape, LL.shape) avgLL = np.mean(LL, axis=0) if avgLL > bestLL: bestDir, bestLL = dirn, avgLL assert bestDir is not None, "token %s - %d not found" % (token, re) return bestDir
def readAvgStdLL(dirn, re, logSpectra, logEnStdev): ''' filen1 = '/simulation_000_00000/run_00000000/spectrumProbability.text' filen2 = '/spectrumProbability.text' if os.path.isfile(dirn+filen1): stats = np.fromfile(dirn+filen1, sep=' ') elif os.path.isfile(dirn+filen2): stats = np.fromfile(dirn+filen2, sep=' ') else : assert False, 'not found %s' % dirname return stats[1], stats[2] ''' eps, nu = epsNuFromRe(re) runData = getAllData(dirn, eps, nu, 2 * 16//2 - 1, fSkip=1) logE = np.log(runData['spectra']) LLt = - np.sum(0.5 * ((logE - logSpectra)/logEnStdev) ** 2, axis=1) print('%s found %d samples' % (dirn, LLt.size) ) return np.mean(LLt, axis=0), np.std(LLt, axis=0)
def main_integral(runspath, target, REs, tokens, labels): nBins = 2 * 16 // 2 - 1 modes = np.arange(1, nBins + 1, dtype=np.float64) # assumes box is 2 pi plt.figure() #REs = findAllParams(path) nRes = len(REs) axes, lines = [], [] for j in range(nRes): axes += [plt.subplot(1, nRes, j + 1)] for j in range(nRes): RE = REs[j] # read target file logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) for i in range(len(tokens)): eps, nu = epsNuFromRe(RE) dirn = findDirectory(runspath, RE, tokens[i]) runData = getAllData(dirn, eps, nu, nBins, fSkip=1) logE = np.log(runData['spectra']) avgLogSpec = np.mean(logE, axis=0) assert (avgLogSpec.size == nBins) LL = (avgLogSpec.ravel() - logSpectra.ravel()) / logEnStdev.ravel() print(LL.shape) p = axes[j].plot(LL, modes, label=labels[i], color=colors[i]) #p = axes[j].plot(LL, modes, color=colors[i]) if j == 0: lines += [p] #stdLogSpec = np.std(logE, axis=0) #covLogSpec = np.cov(logE, rowvar=False) #print(covLogSpec.shape) axes[0].set_ylabel(r'$k$') for j in range(nRes): axes[j].set_title(r'$Re_\lambda$ = %d' % REs[j]) #axes[j].set_xscale("log") axes[j].set_ylim([1, 15]) axes[j].grid() axes[j].set_xlabel( r'$\frac{\log E(k) - \mu_{\log E(k)}}{\sigma_{\log E(k)}}$') for j in range(1, nRes): axes[j].set_yticklabels([]) #axes[0].legend(lines, labels, bbox_to_anchor=(-0.1, 2.5), borderaxespad=0) assert (len(lines) == len(labels)) #axes[0].legend(lines, labels, bbox_to_anchor=(0.5, 0.5)) axes[0].legend(bbox_to_anchor=(0.5, 0.5)) plt.tight_layout() plt.show()
def findBestHyperParams(path, re, token, logSpectra, logEnStdev): bestDir, bestLL, bestStats = None, -1e9, None eps, nu = epsNuFromRe(re) # allow token to be actually a path if token[0] == '/': alldirs = glob.glob(token + '*' + ('RE%03d' % re) + '*') else: alldirs = glob.glob(path + '/*' + ('RE%03d' % re) + '*') for dirn in alldirs: if token not in dirn: continue # if token did not produce any stats file (e.g. not applicable to dns): if bestDir is None: bestDir = dirn runData = getAllData(dirn, eps, nu, 15, fSkip=1) avgLogSpec = np.mean(np.log(runData['spectra']), axis=0) #print(avgLogSpec.shape, logSpectra.shape, logEnStdev.shape) LL = -np.sum((avgLogSpec[:15] - logSpectra) / logEnStdev)**2 if LL > bestLL: bestDir, bestLL = dirn, LL assert bestDir is not None, "token %s - %d not found" % (token, re) return bestDir
def main_integral(runspath, target, tokens): REs = findAllParams(target) nRes, nBins = len(REs), 2 * 16 // 2 - 1 vecParams, vecMean, vecStd = readAllFiles(target, REs) nQoItoPlot = len(QoI) fig, axes = plt.subplots(1, 4, sharex=True, figsize=[12, 3], frameon=False, squeeze=True) for ax in axes.ravel(): ax.grid() #for ax in axes[:nQoItoPlot] : ax.set_xticklabels([]) #for ax in axes[nQoItoPlot:] : ax.set_xlabel('Energy Injection Rate') nNonDimTkeMean, nNonDimTkeStd = np.zeros(nRes), np.zeros(nRes) nNonDimLintMean, nNonDimLintStd = np.zeros(nRes), np.zeros(nRes) nNonDimViscMean, nNonDimViscStd = np.zeros(nRes), np.zeros(nRes) nNonDimTotMean, nNonDimTotStd = np.zeros(nRes), np.zeros(nRes) LintMean = np.zeros(nRes) epses = np.zeros(nRes) for k in range(nRes): for i in range(vecParams.shape[1]): eps, nu, re = vecParams[0, i], vecParams[1, i], vecParams[2, i] if np.abs(REs[k] - re) > 0: continue eta = np.power(nu * nu * nu / eps, 0.25) uprime = np.sqrt(2.0 / 3.0 * vecMean[1, i]) lambd = np.sqrt(15 * nu / eps) * uprime Kscal = np.power(eps, 2.0 / 3.0) epses[k] = eps LintMean[k] = vecMean[4, i] nNonDimTkeMean[k] = vecMean[1, i] / Kscal nNonDimTkeStd[k] = vecStd[1, i] / Kscal nNonDimLintMean[k] = vecMean[4, i] / eta nNonDimLintStd[k] = vecStd[4, i] / eta nNonDimViscMean[k] = vecMean[6, i] / eps nNonDimViscStd[k] = vecStd[6, i] / eps nNonDimTotMean[k] = vecMean[7, i] / eps nNonDimTotStd[k] = vecStd[7, i] / eps dataM = [nNonDimTkeMean, nNonDimLintMean, nNonDimViscMean, nNonDimTotMean] dataS = [nNonDimTkeStd, nNonDimLintStd, nNonDimViscStd, nNonDimTotStd] for k in [0, 2]: top, bot = dataM[k] + dataS[k], dataM[k] - dataS[k] axes[k].fill_between(REs, bot, top, facecolor=colors[0], alpha=0.5) axes[k].plot(REs, dataM[k], '.-', color=colors[0]) for i, token in enumerate(tokens): for j, RE in enumerate(REs): eps, nu = epsNuFromRe(REs[j]) logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) dirn = findBestHyperParams(runspath[i], RE, token, logSpectra, logEnStdev) runData = getAllData(dirn, eps, nu, nBins, fSkip=1) dissip_SGS = getSGSdissip(dirn, runData['dissip_visc'], nu, i, j) eta = np.power(nu * nu * nu / eps, 0.25) uprime = np.sqrt(2.0 / 3.0 * vecMean[1, i]) lambd = np.sqrt(15 * nu / eps) * uprime Kscal = np.power(eps, 2.0 / 3.0) nNonDimTkeMean[j] = np.mean(runData['tke']) / Kscal nNonDimTkeStd[j] = np.std(runData['tke']) / Kscal nNonDimLintMean[j] = np.mean(runData['l_integral']) / LintMean[j] nNonDimLintStd[j] = np.std(runData['l_integral']) / LintMean[j] nNonDimViscMean[j] = np.mean(runData['dissip_visc']) / eps nNonDimViscStd[j] = np.std(runData['dissip_visc']) / eps nNonDimTotMean[j] = np.mean(dissip_SGS) / eps nNonDimTotStd[j] = np.std(dissip_SGS) / eps #nNonDimTotMean[j] = np.mean(runData['dissip_tot']) / eps #nNonDimTotStd[j] = np.std(runData['dissip_tot']) / eps dataM = [ nNonDimTkeMean, nNonDimLintMean, nNonDimViscMean, nNonDimTotMean ] dataS = [nNonDimTkeStd, nNonDimLintStd, nNonDimViscStd, nNonDimTotStd] for k in range(4): top, bot = dataM[k] + dataS[k], dataM[k] - dataS[k] axes[k].fill_between(REs, bot, top, facecolor=colors[i + 1], alpha=0.5) axes[k].plot(REs, dataM[k], '.-', color=colors[i + 1]) for ax in axes.ravel(): ax.set_xscale('log') ax.set_xlim((60, 205)) ax.set_xlabel(r'$Re_\lambda$') ax.set_xticks([60, 82, 111, 151, 205]) ax.set_xticks([], True) # no minor ticks ax.set_xticklabels(['60', '82', '111', '151', '205']) axes[0].set_ylabel(r'$k \,/\, \epsilon^{2/3}$') axes[0].set_ylim((2.55, 3.69)) axes[1].set_ylabel(r'$l_{int,\,LES} \,/\, l_{int,\,DNS}$') axes[1].set_ylim((0.8, 1.21)) axes[2].set_ylabel(r'$\epsilon_{visc} \,/\, \epsilon$') axes[2].set_ylim((0.042, 1.125)) axes[3].set_ylabel(r'$\epsilon_{SGS} \,/\, \epsilon$') axes[3].set_ylim((0.19, 1.78)) #axes[1].set_yscale('log') fig.tight_layout() plt.show()
def main_integral(runspaths, target, REs, tokens, labels, gridSize): nBins = [0] * len(gridSize) scores = [0] * len(tokens) for i, gs in enumerate(gridSize): nBins[i] = gs // 2 - 1 minNbins = min(nBins) nRes = len(REs) axes, lines = [], [] if kXaxis: fig, axes = plt.subplots(2, nRes, sharex=True, figsize=[12, 4], frameon=False, squeeze=True) else: fig, axes = plt.subplots(2, nRes, sharey='row', figsize=[12, 4.8], frameon=False, squeeze=True) maxLL, minLL = [1] * len(REs), [-1] * len(REs) for j, RE in enumerate(REs): eps, nu = epsNuFromRe(RE) Ekscal = np.power(nu**5 * eps, 0.25) # read target file logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) logSpectra = logSpectra.reshape([logSpectra.size]) logEnStdev = logEnStdev.reshape([logSpectra.size]) minNbins = min(minNbins, logSpectra.size) modes = np.arange(1, minNbins + 1, dtype=np.float64) # assumes box is 2 pi LLTop = np.exp(logSpectra + logEnStdev) / Ekscal LLBot = np.exp(logSpectra - logEnStdev) / Ekscal xTheory = np.linspace(4, 14) coef = np.exp(logSpectra[1]) / Ekscal * np.power(4, 5.0 / 3.0) yTheory = coef * np.power(xTheory, -5.0 / 3.0) if kXaxis: axes[0][j].plot(xTheory, yTheory, 'k--') axes[0][j].plot(modes, np.exp(logSpectra) / Ekscal, color='k') axes[0][j].fill_between(modes, LLBot, LLTop, facecolor='k', alpha=.5) axes[1][j].plot(modes, np.zeros(minNbins), 'k-') else: axes[1][j].plot(np.zeros(minNbins), modes, 'k-') axes[0][j].plot(yTheory, xTheory, 'k--') axes[0][j].plot(np.exp(logSpectra) / Ekscal, modes, color='k') axes[0][j].fill_betweenx(modes, LLBot, LLTop, facecolor='k', alpha=.5) for i, token in enumerate(tokens): runspath = runspaths[i] #dirn = findBestHyperParams(runspath, RE, tokens[i], logSpectra, logEnStdev) dirn = findDirectory(runspath, RE, token, gridSize[i]) #print(dirn) runData = getAllData(dirn, eps, nu, nBins[i], fSkip=1) logE = np.log(runData['spectra']) #print(logE.shape[0]) avgLogSpec, stdLogSpec = np.mean(logE, axis=0), np.std(logE, axis=0) assert (avgLogSpec.size == nBins[i]) avgLogSpec = avgLogSpec[:minNbins] stdLogSpec = stdLogSpec[:minNbins] #print(avgLogSpec.shape, logSpectra.shape, logEnStdev.shape) LL = (avgLogSpec - logSpectra) / logEnStdev LLTop = (avgLogSpec + stdLogSpec - logSpectra) / logEnStdev LLBot = (avgLogSpec - stdLogSpec - logSpectra) / logEnStdev Ek = np.exp(avgLogSpec) / Ekscal EkTop = np.exp(avgLogSpec + stdLogSpec) / Ekscal EkBot = np.exp(avgLogSpec - stdLogSpec) / Ekscal if LLTop.max() < 100: maxLL[j] = np.maximum(LLTop.max(), maxLL[j]) if LLBot.min() > -100: minLL[j] = np.minimum(LLBot.min(), minLL[j]) if kXaxis: p = axes[1][j].plot(modes, LL, label=labels[i], color=colors[i]) # , label=labels[i] axes[1][j].fill_between(modes, LLBot, LLTop, facecolor=colors[i], alpha=.5) axes[0][j].plot(modes, Ek, label=labels[i], color=colors[i]) # , label=labels[i] axes[0][j].fill_between(modes, EkBot, EkTop, facecolor=colors[i], alpha=.5) else: p = axes[1][j].plot(LL, modes, label=labels[i], color=colors[i]) # , label=labels[i] axes[1][j].fill_betweenx(modes, LLBot, LLTop, facecolor=colors[i], alpha=.5) axes[0][j].plot(Ek, modes, label=labels[i], color=colors[i]) # , label=labels[i] axes[0][j].fill_betweenx(modes, EkBot, EkTop, facecolor=colors[i], alpha=.5) scores[i] += np.sum(LL) #LLt = (0.5 * (logE - logSpectra) / logEnStdev ) ** 2 #sumLLt = np.sqrt(np.sum(LLt, axis=1)) #nSamples = sumLLt.size #print('found %d samples' % nSamples) #p = axes[j].plot(np.arange(nSamples), sumLLt, label=labels[i], color=colors[i]) if j == 0: lines += [p] for j in range(nRes): axes[0][j].set_title(r'$Re_\lambda$ = %d' % REs[j]) axes[1][j].grid() axes[0][j].grid() for i, token in enumerate(tokens): print(token, scores[i]) if kXaxis: axes[0][0].set_ylabel(r'$E_{LES} \,/\, \eta u^2_\eta$') axes[1][0].set_ylabel( r'$\frac{\log E_{LES} - \mu(\log E_{DNS})}{\sigma(\log E_{DNS})}$') #axes[0][0].set_xscale("log") for j in range(nRes): axes[1][j].set_xlabel(r'$k \cdot L / 2 \pi$') axes[0][j].set_yscale("log") axes[0][j].set_xlim([1, 15]) axes[1][j].set_ylim([minLL[j], maxLL[j]]) else: axes[1][0].set_ylim([1, 15]) axes[1][0].set_ylabel(r'$k \cdot L / 2 \pi$') axes[1][0].invert_yaxis() for j in range(nRes): #axes[1][j].set_xlabel(r'$\frac{\log E^{LES}(k) - \mu[\log E^{DNS}(k)]}{\sigma[\log E^{DNS}(k)]}$') axes[1][j].set_xlabel( r'$\frac{\log E_{LES} - \mu(\log E_{DNS})}{\sigma(\log E_{DNS})}$' ) axes[0][0].set_ylim([1, 15]) axes[0][0].set_ylabel(r'$k \cdot L / 2 \pi$') axes[0][0].invert_yaxis() for j in range(nRes): axes[0][j].set_xlabel(r'$E_{LES} \,/\, \eta u^2_\eta$') axes[0][j].set_xscale("log") #axes[1][0].invert_yaxis() #for j in range(1,nRes): axes[j].set_yticklabels([]) #axes[0].legend(lines, labels, bbox_to_anchor=(-0.1, 2.5), borderaxespad=0) assert (len(lines) == len(labels)) #axes[0].legend(lines, labels, bbox_to_anchor=(0.5, 0.5)) #fig.subplots_adjust(right=0.17, wspace=0.2) #axes[0][-1].legend(bbox_to_anchor=(0.25, 0.25), borderaxespad=0) #axes[-1].legend(bbox_to_anchor=(1, 0.5),fancybox=False, shadow=False) #fig.legend(lines, labels, loc=7, borderaxespad=0) fig.tight_layout() #fig.subplots_adjust(right=0.75) plt.show()
def main_integral(runspath, target, REs, tokens, labels): nBins = 2 * 16 // 2 - 1 modes = np.arange(1, nBins + 1, dtype=np.float64) # assumes box is 2 pi #plt.figure() #REs = findAllParams(path) nRes = len(REs) axes, lines = [], [] fig, axes = plt.subplots(1, nRes, sharex=True, sharey=True, figsize=[12, 4.8]) #for j in range(nRes): # axes += [ plt.subplot(1, nRes, j+1) ] for j in range(nRes): RE = REs[j] # read target file logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) logSpectra = logSpectra.reshape([logSpectra.size]) logEnStdev = logEnStdev.reshape([logSpectra.size]) axes[j].plot(np.zeros(nBins), modes, 'k-') for i in range(len(tokens)): eps, nu = epsNuFromRe(RE) dirn = findBestHyperParams(runspath, RE, tokens[i]) runData = getAllData(dirn, eps, nu, nBins, fSkip=1) logE = np.log(runData['spectra']) print(logE.shape[0]) avgLogSpec, stdLogSpec = np.mean(logE, axis=0), np.std(logE, axis=0) assert (avgLogSpec.size == nBins) LL = (avgLogSpec - logSpectra) / logEnStdev p = axes[j].plot(LL, modes, label=labels[i], color=colors[i]) # , label=labels[i] LLTop = (avgLogSpec + stdLogSpec - logSpectra) / logEnStdev LLBot = (avgLogSpec - stdLogSpec - logSpectra) / logEnStdev axes[j].fill_betweenx(modes, LLBot, LLTop, facecolor=colors[i], alpha=.5) ''' LLt = (0.5 * (logE - logSpectra) / logEnStdev ) ** 2 sumLLt = np.sum(LLt, axis=1) nSamples = sumLLt.size print('found %d samples' % nSamples) p = axes[j].plot(np.arange(nSamples), sumLLt, label=labels[i], color=colors[i]) ''' if j == 0: lines += [p] axes[0].set_ylabel(r'$k$') for j in range(nRes): axes[j].set_title(r'$Re_\lambda$ = %d' % REs[j]) #axes[j].set_xscale("log") axes[j].set_ylim([1, 15]) axes[j].grid() axes[j].invert_yaxis() axes[j].set_xlabel( r'$\frac{\log E(k) - \mu^{DNS}_{\log E(k)}}{\sigma^{DNS}_{\log E(k)}}$' ) #for j in range(1,nRes): axes[j].set_yticklabels([]) #axes[0].legend(lines, labels, bbox_to_anchor=(-0.1, 2.5), borderaxespad=0) assert (len(lines) == len(labels)) #axes[0].legend(lines, labels, bbox_to_anchor=(0.5, 0.5)) #fig.subplots_adjust(right=0.17, wspace=0.2) #axes[-1].legend(bbox_to_anchor=(0.25, 0.25), borderaxespad=0) #axes[-1].legend(bbox_to_anchor=(1, 0.5),fancybox=False, shadow=False) #fig.legend(lines, labels, loc=7, borderaxespad=0) fig.tight_layout() #fig.subplots_adjust(right=0.75) plt.show()
def main_integral(runspath, target, REs, tokens, labels, nBins): minNbins = min(nBins) #plt.figure() #REs = findAllParams(path) nRes = len(REs) axes, lines = [], [] fig, axes = plt.subplots(2, nRes, sharey=True, figsize=[12, 4.8], frameon=False, squeeze=True) #for j in range(nRes): # axes += [ plt.subplot(1, nRes, j+1) ] for j in range(nRes): RE = REs[j] eps, nu = epsNuFromRe(RE) Ekscal = np.power(nu**5 * eps, 0.25) # read target file logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) logSpectra = logSpectra.reshape([logSpectra.size]) logEnStdev = logEnStdev.reshape([logSpectra.size]) minNbins = min(minNbins, logSpectra.size) modes = np.arange(1, minNbins+1, dtype=np.float64) # assumes box is 2 pi axes[1][j].plot(np.zeros(minNbins), modes, 'k-') LLTop = np.exp(logSpectra + logEnStdev)/Ekscal LLBot = np.exp(logSpectra - logEnStdev)/Ekscal axes[0][j].plot(np.exp(logSpectra)/Ekscal, modes, color='k') axes[0][j].fill_betweenx(modes, LLBot, LLTop, facecolor='k', alpha=.5) for i in range(len(tokens)): dirn = findBestHyperParams(runspath, RE, tokens[i]) print(nBins[i]) runData = getAllData(dirn, eps, nu, nBins[i], fSkip=1) logE = np.log(runData['spectra']) print(logE.shape[0]) avgLogSpec, stdLogSpec = np.mean(logE, axis=0), np.std(logE, axis=0) assert(avgLogSpec.size == nBins[i]) avgLogSpec = avgLogSpec[:minNbins] stdLogSpec = stdLogSpec[:minNbins] #print(avgLogSpec.shape, logSpectra.shape, logEnStdev.shape) LL = (avgLogSpec - logSpectra) / logEnStdev p = axes[1][j].plot(LL, modes, label=labels[i], color=colors[i]) # , label=labels[i] LLTop = (avgLogSpec + stdLogSpec - logSpectra) / logEnStdev LLBot = (avgLogSpec - stdLogSpec - logSpectra) / logEnStdev axes[1][j].fill_betweenx(modes, LLBot, LLTop, facecolor=colors[i], alpha=.5) Ek = np.exp(avgLogSpec) / Ekscal axes[0][j].plot(Ek, modes, label=labels[i], color=colors[i]) # , label=labels[i] LLTop = np.exp(avgLogSpec+stdLogSpec) / Ekscal LLBot = np.exp(avgLogSpec-stdLogSpec) / Ekscal axes[0][j].fill_betweenx(modes, LLBot, LLTop, facecolor=colors[i], alpha=.5) ''' LLt = (0.5 * (logE - logSpectra) / logEnStdev ) ** 2 sumLLt = np.sum(LLt, axis=1) nSamples = sumLLt.size print('found %d samples' % nSamples) p = axes[j].plot(np.arange(nSamples), sumLLt, label=labels[i], color=colors[i]) ''' if j == 0: lines += [p] axes[0][0].set_ylabel(r'$k \cdot L / 2 \pi$') axes[1][0].set_ylabel(r'$k \cdot L / 2 \pi$') for j in range(nRes): axes[0][j].set_title(r'$Re_\lambda$ = %d' % REs[j]) axes[0][j].set_xscale("log") axes[0][j].set_ylim([1, 15]) axes[1][j].set_ylim([1, 15]) axes[0][j].grid() axes[1][j].grid() #axes[1][j].set_xlabel(r'$\frac{\log E^{LES}(k) - \mu[\log E^{DNS}(k)]}{\sigma[\log E^{DNS}(k)]}$') axes[1][j].set_xlabel(r'$\frac{\log E_{LES} - \mu(\log E_{DNS})}{\sigma(\log E_{DNS})}$') axes[0][j].set_xlabel(r'$E_{LES} \,/\, \eta u^2_\eta$') axes[0][0].invert_yaxis() #axes[1][0].invert_yaxis() #for j in range(1,nRes): axes[j].set_yticklabels([]) #axes[0].legend(lines, labels, bbox_to_anchor=(-0.1, 2.5), borderaxespad=0) assert(len(lines) == len(labels)) #axes[0].legend(lines, labels, bbox_to_anchor=(0.5, 0.5)) #fig.subplots_adjust(right=0.17, wspace=0.2) #axes[0][-1].legend(bbox_to_anchor=(0.25, 0.25), borderaxespad=0) #axes[-1].legend(bbox_to_anchor=(1, 0.5),fancybox=False, shadow=False) #fig.legend(lines, labels, loc=7, borderaxespad=0) fig.tight_layout() #fig.subplots_adjust(right=0.75) plt.show()
def main_integral(runspath, target, REs, tokens, labels, gridSizes, refs): nBins = np.zeros(len(gridSizes), dtype=int) for i in range(len(gridSizes)): nBins[i] = gridSizes[i] // 2 - 1 maxNbins, nRes = max(nBins), len(REs) axes, lines = [], [] fig, axes = plt.subplots(1, nRes, sharey=True, figsize=[12, 3], frameon=False, squeeze=True) for j in range(nRes): RE, colorid = REs[j], 0 eps, nu = epsNuFromRe(RE) logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) logSpectra = logSpectra.reshape([logSpectra.size]) logEnStdev = logEnStdev.reshape([logSpectra.size]) modes = np.arange(1, maxNbins + 1, dtype=np.float64) # assumes box is 2 pi axes[j].plot(np.zeros(maxNbins), modes, 'k-') for i in range(len(tokens)): for k in range(len(gridSizes)): dirn = findBestHyperParams(runspath, RE, tokens[i], gridSizes[k]) runData = getAllData(dirn, eps, nu, nBins[k], fSkip=1) logE = np.log(runData['spectra']) avgLogSpec, stdLogSpec = np.mean(logE, axis=0), np.std(logE, axis=0) assert (avgLogSpec.size == nBins[k]) modes = np.arange(1, nBins[k] + 1, dtype=np.float64) # assumes box is 2 pi M, S = logSpectra[:nBins[k]], logEnStdev[:nBins[k]] LL = (avgLogSpec - M) / S color, colorid = colors[colorid], colorid + 1 p = axes[j].plot(LL, modes, label=labels[i], color=color) # , label=labels[i] LLTop = (avgLogSpec + stdLogSpec - M) / S LLBot = (avgLogSpec - stdLogSpec - M) / S axes[j].fill_betweenx(modes, LLBot, LLTop, facecolor=color, alpha=.5) if j * k == 0: lines += [p] for i in range(len(refs)): dirn = findBestHyperParamsReference(runspath, RE, refs[i]) if 'BPD2' in dirn: gridsize = 32 if 'BPD4' in dirn: gridsize = 64 if 'BPD8' in dirn: gridsize = 128 nBin = gridsize // 2 - 1 runData = getAllData(dirn, eps, nu, nBin, fSkip=1) logE = np.log(runData['spectra']) avgLogSpec, stdLogSpec = np.mean(logE, axis=0), np.std(logE, axis=0) assert (avgLogSpec.size == nBin) modes = np.arange(1, nBin + 1, dtype=np.float64) # assumes box is 2 pi M, S = logSpectra[:nBin], logEnStdev[:nBin] LL = (avgLogSpec - M) / S color, colorid = colors[colorid], colorid + 1 p = axes[j].plot(LL, modes, color=color) # , label=labels[i] LLTop = (avgLogSpec + stdLogSpec - M) / S LLBot = (avgLogSpec - stdLogSpec - M) / S axes[j].fill_betweenx(modes, LLBot, LLTop, facecolor=color, alpha=.5) axes[0].set_ylabel(r'$k \cdot L / 2 \pi$') axes[0].set_yscale("symlog", linthreshy=15) axes[0].set_ylim([1, maxNbins]) axes[0].set_yticks([10, 15, 31, 63]) axes[0].set_yticklabels(['10', '15', '31', '63']) axes[0].invert_yaxis() for j in range(nRes): axes[j].grid() axes[j].set_title(r'$Re_\lambda$ = %d' % REs[j]) axes[j].set_xlabel( r'$\frac{\log E_{LES} - \mu(\log E_{DNS})}{\sigma(\log E_{DNS})}$') axes[0].set_xlim([-6.2, 2.9]) axes[1].set_xlim([-6.7, 5.0]) axes[2].set_xlim([-7.2, 7]) axes[3].set_xlim([-6.5, 8.5]) axes[4].set_xlim([-7.2, 10]) axes[5].set_xlim([-6.8, 11.5]) axes[6].set_xlim([-6.9, 13]) #assert(len(lines) == len(labels)) fig.tight_layout() plt.show()
def main_integral(runspaths, refspath, target, REs, tokens, gridSizes, ref): nRes, nTokens, nGrids = len(REs), len(tokens), len(gridSizes) fig, ax = plt.subplots(1, 1, figsize=[6, 4], frameon=False, squeeze=True) err_means = np.zeros((nTokens * nGrids, nRes)) err_upper = np.zeros((nTokens * nGrids, nRes)) err_lower = np.zeros((nTokens * nGrids, nRes)) referr_means = np.zeros((len(gridSizes), nRes)) referr_upper = np.zeros((len(gridSizes), nRes)) referr_lower = np.zeros((len(gridSizes), nRes)) for j, RE in enumerate(REs): colorid = 0 eps, nu = epsNuFromRe(RE) logSpectra, logEnStdev, _, _ = readAllSpectra(target, [RE]) logSpectra = logSpectra.reshape([logSpectra.size]) logEnStdev = logEnStdev.reshape([logSpectra.size]) for i, token in enumerate(tokens): for k, gs in enumerate(gridSizes): actualNbins = gs // 2 - 1 binSize = clipBinSize if clipBinSize else actualNbins dirn = findDirectory(runspaths[i], RE, token, gs) #print(dirn, token, gs) #findBestHyperParams(runspaths[i], RE, token, gs, logSpectra, logEnStdev) runData = getAllData(dirn, eps, nu, actualNbins, fSkip=1) M, S = logSpectra[:binSize], logEnStdev[:binSize] logE = np.log(runData['spectra'][:, :binSize]) if logE.shape[0] < 2: err_means[i * nGrids + k, j] = np.NAN err_upper[i * nGrids + k, j] = np.NAN err_lower[i * nGrids + k, j] = np.NAN continue coef = -0.5 / binSize LL = np.sum(coef * ((logE - M) / S)**2, axis=1) #print(i * nGrids + k, logE.shape, LL.shape) #err_means[i * nGrids + k, j] = np.mean(LL, axis=0) err_means[i * nGrids + k, j] = np.percentile(LL, 50, axis=0) err_upper[i * nGrids + k, j] = np.percentile(LL, topPercentile, axis=0) err_lower[i * nGrids + k, j] = np.percentile(LL, botPercentile, axis=0) for k, gridsize in enumerate(gridSizes): dirn = findDirectory(refspath, RE, ref, gridsize) #findBestHyperParamsReference(refspaths[i], RE, ref) #if 'BPD2' in dirn or 'BPD032' in dirn: gridsize = 32 #if 'BPD4' in dirn or 'BPD064' in dirn: gridsize = 64 #if 'BPD8' in dirn or 'BPD128' in dirn: gridsize = 128 actualNbins = gridsize // 2 - 1 binSize = clipBinSize if clipBinSize else actualNbins runData = getAllData(dirn, eps, nu, actualNbins, fSkip=1) M, S = logSpectra[:binSize], logEnStdev[:binSize] logE = np.log(runData['spectra'][:, :binSize]) if logE.shape[0] < 2: referr_means[k, j] = np.NAN referr_upper[k, j] = np.NAN referr_lower[k, j] = np.NAN continue coef = -0.5 / binSize #norm, arg = np.log(2*np.pi * S**2), ((logE - M)/S)**2 #LL = np.sum(coef * (norm + arg), axis=1) LL = np.sum(coef * ((logE - M) / S)**2, axis=1) #print(nTokens * nGrids + i, logE.shape, LL.shape) #err_means[nTokens * nGrids + i, j] = np.mean(LL, axis=0) referr_means[k, j] = np.percentile(LL, 50, axis=0) referr_upper[k, j] = np.percentile(LL, topPercentile, axis=0) referr_lower[k, j] = np.percentile(LL, botPercentile, axis=0) for i, gs in enumerate(gridSizes): ax.plot(REs, referr_means[i, :], '.-', color=refcolors[i]) top, bot = referr_upper[i, :], referr_lower[i, :] ax.fill_between(REs, bot, top, facecolor=refcolors[i], alpha=.5) for i in reversed(range(nTokens * nGrids)): ax.plot(REs, err_means[i, :], '.-', color=colors[i]) top, bot = err_upper[i, :], err_lower[i, :] ax.fill_between(REs, bot, top, facecolor=colors[i], alpha=.5) ax.set_yscale("symlog", linthreshy=1e-3) ax.set_ylim((-42, -0.2)) #ax.set_ylim((-13.5, -0.29)) #ax.set_yscale("log") ax.set_xlim((60, 205)) ax.set_xscale("log") ax.set_xticks([60, 70, 82, 95, 111, 130, 151, 176, 205]) ax.set_xticks([], True) # no minor ticks ax.set_xticklabels( ['60', '70', '82', '95', '111', '130', '151', '176', '205']) ax.set_yticks([-0.3, -1, -3, -10, -30]) ax.set_yticks([], True) # no minor ticks ax.set_yticklabels(["-0.3", "-1", "-3", "-10", "-30"]) ax.set_xlabel(r'$Re_\lambda$') ax.set_ylabel(r'$\widetilde{LL}(E_{LES}\,\|\,E_{DNS})$') ax.grid() fig.tight_layout() plt.show()
def main_integral(path, nBlocks=32): REs = findAllParams(path) print(REs) nRes, nBins = len(REs), nBlocks * 16 // 2 - 1 fig, axes = plt.subplots(1, 8, sharey=False, figsize=[15, 3], frameon=False, squeeze=True) #axes[0].set_xlabel(r'$k \eta$') #axes[0].grid() #axes[0].set_ylabel(r'$\frac{E(k)} {\eta u^2_\eta}$') ci = 0 for i in range(1, nRes, 4): eps, nu = epsNuFromRe(REs[i]) print(REs[i]) data = gatherAllData(path, REs[i], eps, nu, nBins, fSkip=1) leta, lint = np.power(nu**3 / eps, 0.25), np.mean(data['l_integral']) Ekscal = np.power(nu**5 * eps, 0.25) ci += 1 ck = 0 for k in range(0, 15, 2): #print(data['spectra'].shape) Ek = data['spectra'][:, k] / Ekscal logEk = np.log(Ek) avgLogEk, stdLogEk = np.mean(logEk, axis=0), np.std(logEk, axis=0) minLogEk, maxLogEk = avgLogEk - 3 * stdLogEk, avgLogEk + 3 * stdLogEk minEk, maxEk = np.exp(minLogEk), np.exp(maxLogEk) color_l = colors_lines[ci - 1] color_h = colors_hist[ci - 1] if doLogScale: bins = np.linspace(minLogEk, maxLogEk, num=100) norml = 1 / (stdLogEk * np.sqrt(2 * np.pi)) P = np.exp(-0.5 * ((bins - avgLogEk) / stdLogEk)**2) * norml axes[ck].plot(bins, P, '--', color=color_l) bins = np.linspace(minLogEk, maxLogEk, num=20) axes[ck].hist(logEk, bins=bins, density=True, log=False, color=color_h, label=None) else: bins = np.geomspace(minEk, maxEk, num=20) axes[ck].hist(Ek, bins=bins, density=True, log=True, color=color_h, label=None) # ck += 1 ''' Ekscal = np.power(nu**5 * eps, 0.25) K = np.arange(1, nyquist+1, dtype=np.float64) E = np.exp(vecSpectra[:,i]) #X, Y = K, E / Ekscal X, Y = K * leta, E / Ekscal fit = np.array([EkBrief([k, eps,leta,lint,nu], popt) for k in K])/Ekscal Yb = np.exp(vecSpectra[:,i] - vecEnStdev[:,i])/Ekscal Yt = np.exp(vecSpectra[:,i] + vecEnStdev[:,i])/Ekscal fullE = np.exp(fullSpectra[:,i]) fullN = fullSpectra.shape[0] fullK = np.arange(1, fullN+1, dtype=np.float64) eTot = np.sum(fullE) eCDF = np.array([np.sum(fullE[:k+1]) for k in range(fullN)]) / eTot #print(fullE, eCDF) label = r'$Re_\lambda=%d$' % re ci += 1 color = colors[ - ci ] #axes[0].fill_between(X, Yb, Yt, facecolor=color, alpha=.5) #axes[0].plot(X[1:], fit[1:], 'o', color=color) #axes[0].plot(X, Y, color=color, label=label) #axes[1].plot(fullK, 1-eCDF, color=color, label=label) ''' #for ax in axes: ax.set_xscale("log") for ax in axes: ax.set_yticks([]) for ax in axes: ax.set_yticklabels([]) k = 1 for ax in axes: ax.set_title(r'$k = %d \pi / L$' % (2 * k)) ax.set_xlabel(r'$\log\left[ E(k) \,/\, \eta u^2_\eta\right]$') k += 2 axes[0].set_ylabel( r'$\mathcal{P}\left[\,\log\left( E \,/\, \eta u^2_\eta\right)\right]$') #axes[1].set_xlabel(r'$k$') #axes[1].set_ylabel(r'$1 - CDF(E)$') #axes[1].set_xlim([1,63]) #axes[1].set_ylim([0.5, 1e-3]) #axes[0].legend(loc='lower left', ncol=3) fig.tight_layout() plt.show()
def main_integral(path, nBlocks=32): REs = findAllParams(path) print(REs) nRes, nBins = len(REs), nBlocks * 16 // 2 - 1 fig, axes = plt.subplots(1, 8, sharey=False, figsize=[15, 3], frameon=False, squeeze=True) #axes[0].set_xlabel(r'$k \eta$') #axes[0].grid() #axes[0].set_ylabel(r'$\frac{E(k)} {\eta u^2_\eta}$') ci = 0 for i in range(1, nRes, 4): eps, nu = epsNuFromRe(REs[i]) #print(REs[i]) data = gatherAllData(path, REs[i], eps, nu, nBins, fSkip=1) leta, lint = np.power(nu**3 / eps, 0.25), np.mean(data['l_integral']) Ekscal = np.power(nu**5 * eps, 0.25) ci += 1 ck = 0 for k in range(0, 15, 2): #print(data['spectra'].shape) Ek = data['spectra'][:, k] / Ekscal logEk = np.log(Ek) avgLogEk, stdLogEk = np.mean(logEk, axis=0), np.std(logEk, axis=0) minLogEk, maxLogEk = avgLogEk - 3 * stdLogEk, avgLogEk + 3 * stdLogEk minEk, maxEk = np.exp(minLogEk), np.exp(maxLogEk) color_l = colors_lines[ci - 1] color_h = colors_hist[ci - 1] if doLogScale: bins = np.linspace(minLogEk, maxLogEk, num=100) norml = 1 / (stdLogEk * np.sqrt(2 * np.pi)) P = np.exp(-0.5 * ((bins - avgLogEk) / stdLogEk)**2) * norml axes[ck].plot(bins, P, '--', color=color_l) bins = np.linspace(minLogEk, maxLogEk, num=20) axes[ck].hist(logEk, bins=bins, density=True, log=False, color=color_h, label=None) else: bins = np.geomspace(minEk, maxEk, num=20) axes[ck].hist(Ek, bins=bins, density=True, log=True, color=color_h, label=None) # ck += 1 #for ax in axes: ax.set_xscale("log") for ax in axes: ax.set_yticks([]) for ax in axes: ax.set_yticklabels([]) k = 1 for ax in axes: ax.set_title(r'$k = %d \pi / L$' % (2 * k)) ax.set_xlabel(r'$\log\left[ E(k) \,/\, \eta u^2_\eta\right]$') k += 2 axes[0].set_ylabel( r'$\mathcal{P}\left[\,\log\left( E \,/\, \eta u^2_\eta\right)\right]$') #axes[1].set_xlabel(r'$k$') #axes[1].set_ylabel(r'$1 - CDF(E)$') #axes[1].set_xlim([1,63]) #axes[1].set_ylim([0.5, 1e-3]) #axes[0].legend(loc='lower left', ncol=3) fig.tight_layout() plt.show()