Commit 11e0f4d4 by Lukas Bentkamp

### Energy considerations

parent a2309ff0
 ... ... @@ -742,7 +742,10 @@ class DNS(_code): opt.nz > opt.n): opt.n = min(opt.nx, opt.ny, opt.nz) print("Warning: '-n' parameter changed to minimum of nx, ny, nz. This affects the computation of nu.") self.parameters['dt'] = (opt.dtfactor / opt.n) if self.dns_type in ['kraichnan_field']: self.parameters['dt'] = opt.dtfactor * 0.5 / opt.n**2 else: self.parameters['dt'] = (opt.dtfactor / opt.n) self.parameters['nu'] = (opt.kMeta * 2 / opt.n)**(4./3) # check value of kMax kM = opt.n * 0.5 ... ...
 ... ... @@ -3,6 +3,7 @@ import numpy as np from scipy import trapz from scipy.stats import norm from scipy.integrate import quad import h5py import sys import time ... ... @@ -18,11 +19,13 @@ except: def main(): c = TEST() # size of grid n = 128 n = 256 slope = -5./3. k_cutoff = 16. coeff = 1. bin_no = 129 k_cutoff = 30. func = lambda k, k_c=k_cutoff, s=slope : k**s*np.exp(-k/k_c) total_energy = quad(func, 1, k_cutoff*4)[0] coeff = 3./2./total_energy bin_no = 100 rseed = int(time.time()) c.launch( ... ... @@ -35,25 +38,29 @@ def main(): '--ntpp', '1', '--wd', './', '--histogram_bins', str(bin_no), '--max_velocity_estimate', '2.', '--max_velocity_estimate', '8.', '--spectrum_slope', str(slope), '--spectrum_k_cutoff', str(k_cutoff), '--spectrum_coefficient', str(coeff), '--field_random_seed', str(rseed)] + sys.argv[1:]) plot_stuff(c.simname) df = h5py.File(c.simname + '.h5', 'r') def plot_stuff(simname): df = h5py.File(simname + '.h5', 'r') for kk in ['spectrum_slope', 'spectrum_k_cutoff', 'spectrum_coefficient', 'field_random_seed', 'histogram_bins']: print(kk, df['parameters/' + kk][...]) coeff = df['parameters/spectrum_coefficient'][()] k_cutoff = df['parameters/spectrum_k_cutoff'][()] slope = df['parameters/spectrum_slope'][()] bin_no = df['parameters/histogram_bins'][()] f = plt.figure() # EVERYTHING SHOULD BE READ FROM FILE BECAUSE WE CANT BE SURE THE CODE RAN AGAIN # test spectrum a = f.add_subplot(121) kk = df['kspace/kshell'][...] ... ... @@ -74,8 +81,8 @@ def main(): hist_vel = df['statistics/histograms/velocity'][0, :, :3] f_vel = hist_vel / np.sum(hist_vel, axis=0, keepdims=True).astype(float) / velbinsize print('Energy integral: {}'.format(trapz(energy[1:-2], kk[1:-2]))) print('Energy sum: {}'.format(np.sum(energy[1:-2]))) print('Energy analytically: {}'.format(total_energy)) print('Energy sum: {}'.format(np.sum(energy*df['kspace/dk'][()]))) print('Moment sum: {}'.format(df['statistics/moments/velocity'][0,2,3]/2)) print('Velocity variances: {}'.format(trapz(vel[:,None]**2*f_vel, vel[:,None], axis=0))) ... ...