Skip to content
Snippets Groups Projects
Commit 96e9436e authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

finalize test of particle cloud code

parent 54d91695
Branches
Tags
1 merge request!23WIP: Feature/use cmake
Pipeline #43298 failed
...@@ -791,13 +791,17 @@ class DNS(_code): ...@@ -791,13 +791,17 @@ class DNS(_code):
ncomponents = 6 ncomponents = 6
with h5py.File(self.get_checkpoint_0_fname(), 'a') as data_file: with h5py.File(self.get_checkpoint_0_fname(), 'a') as data_file:
nn = self.parameters['nparticles'] 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( data_file['tracers{0}/rhs'.format(species)].create_dataset(
'0', '0',
shape = ( shape = (
(self.parameters['tracers{0}_integration_steps'.format(species)],) + (self.parameters['tracers{0}_integration_steps'.format(species)],) +
(nn, ncomponents,)), (nn, ncomponents,)),
dtype = np.float) dtype = np.float)
dset = data_file['tracers{0}/state'.format(s)].create_dataset( dset = data_file['tracers{0}/state'.format(species)].create_dataset(
'0', '0',
shape = (nn, ncomponents,), shape = (nn, ncomponents,),
dtype = np.float) dtype = np.float)
...@@ -958,12 +962,6 @@ class DNS(_code): ...@@ -958,12 +962,6 @@ class DNS(_code):
self, self,
opt = None): opt = None):
if self.parameters['nparticles'] > 0: 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( self.generate_tracer_state(
species = 0, species = 0,
rseed = opt.particle_rand_seed) rseed = opt.particle_rand_seed)
......
...@@ -33,7 +33,7 @@ from .PP import PP ...@@ -33,7 +33,7 @@ from .PP import PP
from .TEST import TEST from .TEST import TEST
def main(): def main():
parser = argparse.ArgumentParser(prog = 'bfps') parser = argparse.ArgumentParser(prog = 'bfps', conflict_handler = 'resolve')
parser.add_argument( parser.add_argument(
'-v', '--version', '-v', '--version',
action = 'version', action = 'version',
......
#! /usr/bin/env python #! /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 os
import numpy as np import numpy as np
......
...@@ -33,15 +33,22 @@ import sys ...@@ -33,15 +33,22 @@ import sys
import bfps import bfps
from bfps import DNS from bfps import DNS
def main(): def main():
nclouds = 4 nclouds = 10
nparticles_per_cloud = 3 nparticles_per_cloud = 1000
nparticles = nclouds*nparticles_per_cloud nparticles = nclouds*nparticles_per_cloud
niterations = 32 niterations = 32
c = DNS() 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 = h5py.File(c.get_checkpoint_0_fname(), 'a')
ic_file['tracers0/state/0'] = np.random.random((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'] = np.zeros((2, 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() ic_file.close()
c.launch( c.launch(
['NSVEparticles', ['NSVEparticles',
...@@ -57,8 +64,28 @@ def main(): ...@@ -57,8 +64,28 @@ def main():
'--niter_out', '{0}'.format(niterations), '--niter_out', '{0}'.format(niterations),
'--niter_stat', '1', '--niter_stat', '1',
'--nparticles', '{0}'.format(nparticles), '--nparticles', '{0}'.format(nparticles),
'--tracers0_integration_steps', '2', '--njobs', '2',
'--wd', './']) '--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 return None
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment