Commit 5e664268 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

update tracer state generation

it should work for many many particles now.
parent 74ca7af1
...@@ -700,29 +700,26 @@ class DNS(_code): ...@@ -700,29 +700,26 @@ class DNS(_code):
def generate_tracer_state( def generate_tracer_state(
self, self,
rseed = None, rseed = None,
iteration = 0, species = 0):
species = 0, with h5py.File(self.get_checkpoint_0_fname(), 'a') as data_file:
write_to_file = False, dset = data_file[
ncomponents = 3, 'tracers{0}/state/0'.format(species)]
testing = False,
data = None):
if (type(data) == type(None)):
if not type(rseed) == type(None): if not type(rseed) == type(None):
np.random.seed(rseed) np.random.seed(rseed)
#point with problems: 5.37632864e+00, 6.10414710e+00, 6.25256493e+00] nn = self.parameters['nparticles']
data = np.zeros(self.parameters['nparticles']*ncomponents).reshape(-1, ncomponents) cc = int(0)
data[:, :3] = np.random.random((self.parameters['nparticles'], 3))*2*np.pi batch_size = int(1e6)
if testing: while nn > 0:
#data[0] = np.array([3.26434, 4.24418, 3.12157]) if nn > batch_size:
data[:] = np.array([ 0.72086101, 2.59043666, 6.27501953]) dset[cc*batch_size:(cc+1)*batch_size] = np.random.random(
with h5py.File(self.get_checkpoint_0_fname(), 'a') as data_file: (batch_size, 3))*2*np.pi
data_file['tracers{0}/state/0'.format(species)][:] = data nn -= batch_size
if write_to_file: else:
data.tofile( dset[cc*batch_size:cc*batch_size+nn] = np.random.random(
os.path.join( (nn, 3))*2*np.pi
self.work_dir, nn = 0
"tracers{0}_state_i{1:0>5x}".format(species, iteration))) cc += 1
return data return None
def generate_vector_field( def generate_vector_field(
self, self,
rseed = 7547, rseed = 7547,
...@@ -876,38 +873,37 @@ class DNS(_code): ...@@ -876,38 +873,37 @@ class DNS(_code):
amplitude = 0.05) amplitude = 0.05)
f['vorticity/complex/{0}'.format(0)] = data f['vorticity/complex/{0}'.format(0)] = data
f.close() f.close()
# take care of particles' initial condition ## take care of particles' initial condition
if self.dns_type in ['NSVEp', 'NSVEparticles']: #if self.dns_type in ['NSVEp', 'NSVEparticles']:
if opt.pclouds > 1: # if opt.pclouds > 1:
np.random.seed(opt.particle_rand_seed) # np.random.seed(opt.particle_rand_seed)
if opt.pcloud_type == 'random-cube': # if opt.pcloud_type == 'random-cube':
particle_initial_condition = ( # particle_initial_condition = (
np.random.random((opt.pclouds, 1, 3))*2*np.pi + # np.random.random((opt.pclouds, 1, 3))*2*np.pi +
np.random.random((1, self.parameters['nparticles'], 3))*opt.particle_cloud_size) # np.random.random((1, self.parameters['nparticles'], 3))*opt.particle_cloud_size)
elif opt.pcloud_type == 'regular-cube': # elif opt.pcloud_type == 'regular-cube':
onedarray = np.linspace( # onedarray = np.linspace(
-opt.particle_cloud_size/2, # -opt.particle_cloud_size/2,
opt.particle_cloud_size/2, # opt.particle_cloud_size/2,
self.parameters['nparticles']) # self.parameters['nparticles'])
particle_initial_condition = np.zeros( # particle_initial_condition = np.zeros(
(opt.pclouds, # (opt.pclouds,
self.parameters['nparticles'], # self.parameters['nparticles'],
self.parameters['nparticles'], # self.parameters['nparticles'],
self.parameters['nparticles'], 3), # self.parameters['nparticles'], 3),
dtype = np.float64) # dtype = np.float64)
particle_initial_condition[:] = \ # particle_initial_condition[:] = \
np.random.random((opt.pclouds, 1, 1, 1, 3))*2*np.pi # np.random.random((opt.pclouds, 1, 1, 1, 3))*2*np.pi
particle_initial_condition[..., 0] += onedarray[None, None, None, :] # particle_initial_condition[..., 0] += onedarray[None, None, None, :]
particle_initial_condition[..., 1] += onedarray[None, None, :, None] # particle_initial_condition[..., 1] += onedarray[None, None, :, None]
particle_initial_condition[..., 2] += onedarray[None, :, None, None] # particle_initial_condition[..., 2] += onedarray[None, :, None, None]
self.write_par( self.write_par(
particle_ic = particle_initial_condition) particle_ic = None)
if self.dns_type in ['NSVEp', 'NSVEparticles']: if self.dns_type in ['NSVEp', 'NSVEparticles']:
if self.parameters['nparticles'] > 0: if self.parameters['nparticles'] > 0:
data = self.generate_tracer_state( self.generate_tracer_state(
species = 0, species = 0,
rseed = opt.particle_rand_seed, rseed = opt.particle_rand_seed)
data = particle_initial_condition)
self.run( self.run(
nb_processes = opt.nb_processes, nb_processes = opt.nb_processes,
nb_threads_per_process = opt.nb_threads_per_process, nb_threads_per_process = opt.nb_threads_per_process,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment