From 1cb5aadbb927c4fbd77c8b70d8a4441fbdc27e79 Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de> Date: Sun, 8 May 2016 17:38:05 +0200 Subject: [PATCH] add ManyParticle code I might as well make it a separate class, since this way I can keep track of it... --- bfps/NSManyParticles.py | 92 +++++++++++++++++++++++++++++++++++++++++ bfps/__main__.py | 8 +++- tests/test_plain.py | 2 +- 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 bfps/NSManyParticles.py diff --git a/bfps/NSManyParticles.py b/bfps/NSManyParticles.py new file mode 100644 index 00000000..03f7345f --- /dev/null +++ b/bfps/NSManyParticles.py @@ -0,0 +1,92 @@ +####################################################################### +# # +# Copyright 2015 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 bfps + +class NSManyParticles(bfps.NavierStokes): + def specific_parser_arguments( + self, + parser): + bfps.NavierStokes.specific_parser_arguments(self, parser) + parser.add_argument( + '--particle-class', + default = 'rFFTW_distributed_particles', + dest = 'particle_class', + type = str) + parser.add_argument( + '--interpolator-class', + default = 'rFFTW_interpolator', + dest = 'interpolator_class', + type = str) + parser.add_argument('--neighbours', + type = int, + dest = 'neighbours', + default = 3) + parser.add_argument('--smoothness', + type = int, + dest = 'smoothness', + default = 2) + return None + def launch( + self, + args = [], + **kwargs): + opt = self.prepare_launch(args = args) + self.fill_up_fluid_code() + if type(opt.nparticles) == int: + if opt.nparticles > 0: + self.add_3D_rFFTW_field( + name = 'rFFTW_acc') + interp_list = [] + for n in range(1, opt.neighbours): + interp_list.append('Lagrange_n{0}'.format(n)) + self.add_interpolator( + interp_type = 'Lagrange', + name = interp_list[-1], + neighbours = n, + class_name = opt.interpolator_class) + for m in range(1, opt.smoothness): + interp_list.append('spline_n{0}m{1}'.format(n, m)) + self.add_interpolator( + interp_type = 'spline', + name = interp_list[-1], + neighbours = n, + smoothness = m, + class_name = opt.interpolator_class) + self.add_particles( + integration_steps = 2, + interpolator = interp_list, + acc_name = 'rFFTW_acc', + class_name = opt.particle_class) + self.add_particles( + integration_steps = 4, + interpolator = interp_list, + acc_name = 'rFFTW_acc', + class_name = opt.particle_class) + self.finalize_code() + self.launch_jobs(opt = opt) + return None + diff --git a/bfps/__main__.py b/bfps/__main__.py index 3ddfd1bc..a26d84d0 100644 --- a/bfps/__main__.py +++ b/bfps/__main__.py @@ -31,6 +31,7 @@ import bfps from .NavierStokes import NavierStokes from .FluidResize import FluidResize from .FluidConvert import FluidConvert +from .NSManyParticles import NSManyParticles def main(): parser = argparse.ArgumentParser(prog = 'bfps') @@ -51,9 +52,12 @@ def main(): 'FR-single', 'FR-double'] FCoptions = ['FluidConvert'] + NSMPopt = ['NSManyParticles', + 'NSManyParticles-single', + 'NSManyParticles-double'] parser.add_argument( 'base_class', - choices = NSoptions + FRoptions + FCoptions, + choices = NSoptions + FRoptions + FCoptions + NSMPopt, type = str) # first option is the choice of base class or -h or -v # all other options are passed on to the base_class instance @@ -70,6 +74,8 @@ def main(): base_class = FluidResize elif opt.base_class in FCoptions: base_class = FluidConvert + elif opt.base_class in NSMPopt: + base_class = NSManyParticles c = base_class(fluid_precision = precision) c.launch(args = sys.argv[2:]) return None diff --git a/tests/test_plain.py b/tests/test_plain.py index a5305ea0..ad30224f 100644 --- a/tests/test_plain.py +++ b/tests/test_plain.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 ####################################################################### # # # Copyright 2015 Max Planck Institute # -- GitLab