diff --git a/bfps/DNS.py b/bfps/DNS.py index dd75854d9e7aa3a61c47e680a6a4b4a93dd51239..ffcaea49772e8a26f12c7983ecb86ec3abd3a1d0 100644 --- a/bfps/DNS.py +++ b/bfps/DNS.py @@ -791,13 +791,17 @@ class DNS(_code): ncomponents = 6 with h5py.File(self.get_checkpoint_0_fname(), 'a') as data_file: nn = self.parameters['nparticles'] + if not 'tracers{0}'.format(species) in data_file.keys(): + data_file.create_group('tracers{0}'.format(species)) + data_file.create_group('tracers{0}/rhs'.format(species)) + data_file.create_group('tracers{0}/state'.format(species)) data_file['tracers{0}/rhs'.format(species)].create_dataset( '0', shape = ( (self.parameters['tracers{0}_integration_steps'.format(species)],) + (nn, ncomponents,)), dtype = np.float) - dset = data_file['tracers{0}/state'.format(s)].create_dataset( + dset = data_file['tracers{0}/state'.format(species)].create_dataset( '0', shape = (nn, ncomponents,), dtype = np.float) @@ -958,12 +962,6 @@ class DNS(_code): self, opt = None): if self.parameters['nparticles'] > 0: - with h5py.File(self.get_checkpoint_0_fname(), 'a') as ofile: - s = 0 - if not 'tracers{0}'.format(s) in ofile.keys(): - ofile.create_group('tracers{0}'.format(s)) - ofile.create_group('tracers{0}/rhs'.format(s)) - ofile.create_group('tracers{0}/state'.format(s)) self.generate_tracer_state( species = 0, rseed = opt.particle_rand_seed) diff --git a/bfps/__main__.py b/bfps/__main__.py index 16a7cf7d099c49a39368a8ff09cb05bf890feb6f..cf269edbaea91acd4b3de595782b92e32e1cbd3b 100644 --- a/bfps/__main__.py +++ b/bfps/__main__.py @@ -33,7 +33,7 @@ from .PP import PP from .TEST import TEST def main(): - parser = argparse.ArgumentParser(prog = 'bfps') + parser = argparse.ArgumentParser(prog = 'bfps', conflict_handler = 'resolve') parser.add_argument( '-v', '--version', action = 'version', diff --git a/bfps/test/test_bfps_NSVEparticles.py b/bfps/test/test_bfps_NSVEparticles.py index f914ad7dbfa7f23466c19cfba64f730b9e4cda45..fe1e7875a651b17dd9180f3cbe6d6bfe1f1b5c27 100644 --- a/bfps/test/test_bfps_NSVEparticles.py +++ b/bfps/test/test_bfps_NSVEparticles.py @@ -1,4 +1,29 @@ #! /usr/bin/env python +####################################################################### +# # +# Copyright 2019 Max Planck Institute # +# for Dynamics and Self-Organization # +# # +# This file is part of bfps. # +# # +# bfps is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published # +# by the Free Software Foundation, either version 3 of the License, # +# or (at your option) any later version. # +# # +# bfps is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with bfps. If not, see <http://www.gnu.org/licenses/> # +# # +# Contact: Cristian.Lalescu@ds.mpg.de # +# # +####################################################################### + + import os import numpy as np diff --git a/bfps/test/test_particle_clouds.py b/bfps/test/test_particle_clouds.py index 1a890495ca263b4f317722c0fb6cfe4a22d57f87..5d2045390f51e7f529f78a3eb7037acb3fcae3b9 100644 --- a/bfps/test/test_particle_clouds.py +++ b/bfps/test/test_particle_clouds.py @@ -33,15 +33,22 @@ import sys import bfps from bfps import DNS + def main(): - nclouds = 4 - nparticles_per_cloud = 3 + nclouds = 10 + nparticles_per_cloud = 1000 nparticles = nclouds*nparticles_per_cloud niterations = 32 c = DNS() + c.dns_type = 'NSVEparticles' + c.parameters['nparticles'] = nparticles + c.parameters['tracers1_integration_steps'] = 4 + c.generate_tracer_state(rseed = 2, species = 1) + del c.parameters['nparticles'] + del c.parameters['tracers1_integration_steps'] ic_file = h5py.File(c.get_checkpoint_0_fname(), 'a') - ic_file['tracers0/state/0'] = np.random.random((nclouds, nparticles_per_cloud, 3)) - ic_file['tracers0/rhs/0'] = np.zeros((2, nclouds, nparticles_per_cloud, 3)) + ic_file['tracers0/state/0'] = ic_file['tracers1/state/0'].value.reshape(nclouds, nparticles_per_cloud, 3) + ic_file['tracers0/rhs/0'] = ic_file['tracers1/rhs/0'].value.reshape(4, nclouds, nparticles_per_cloud, 3) ic_file.close() c.launch( ['NSVEparticles', @@ -57,8 +64,28 @@ def main(): '--niter_out', '{0}'.format(niterations), '--niter_stat', '1', '--nparticles', '{0}'.format(nparticles), - '--tracers0_integration_steps', '2', + '--njobs', '2', '--wd', './']) + f0 = h5py.File( + os.path.join( + os.path.join(bfps.lib_dir, 'test'), + 'B32p1e4_checkpoint_0.h5'), + 'r') + f1 = h5py.File(c.get_checkpoint_0_fname(), 'r') + for iteration in [0, 32, 64]: + field0 = f0['vorticity/complex/{0}'.format(iteration)].value + field1 = f1['vorticity/complex/{0}'.format(iteration)].value + field_error = np.max(np.abs(field0 - field1)) + x0 = f0['tracers0/state/{0}'.format(iteration)].value + x1 = f1['tracers0/state/{0}'.format(iteration)].value.reshape(x0.shape) + traj_error = np.max(np.abs(x0 - x1)) + y0 = f0['tracers0/rhs/{0}'.format(iteration)].value + y1 = f1['tracers0/rhs/{0}'.format(iteration)].value.reshape(y0.shape) + rhs_error = np.max(np.abs(y0 - y1)) + assert(field_error < 1e-5) + assert(traj_error < 1e-5) + assert(rhs_error < 1e-5) + print('SUCCESS! Basic test passed.') return None if __name__ == '__main__':