From 0a53773b1de7f57e482a36e7c7b4b26865e094b3 Mon Sep 17 00:00:00 2001
From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de>
Date: Sun, 24 Jan 2016 16:13:03 +0100
Subject: [PATCH] __main__ uses _fluid_particle_base directly

---
 bfps/NavierStokes.py | 56 ++++++++++++++++++++++++++++++++++++++++++++
 bfps/__main__.py     |  7 +++---
 bfps/_fluid_base.py  |  4 ++++
 3 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/bfps/NavierStokes.py b/bfps/NavierStokes.py
index a4f6408d..7ccc7ed2 100644
--- a/bfps/NavierStokes.py
+++ b/bfps/NavierStokes.py
@@ -27,7 +27,9 @@
 import os
 import numpy as np
 import h5py
+import argparse
 
+import bfps
 from ._fluid_base import _fluid_particle_base
 
 class NavierStokes(_fluid_particle_base):
@@ -970,4 +972,58 @@ class NavierStokes(_fluid_particle_base):
                dest = 'particle_rand_seed',
                default = None)
         return None
+    def launch(
+            self,
+            args = [],
+            **kwargs):
+        # with the default Lundgren forcing, I can estimate the dissipation
+        # with nondefault forcing, figure out the amplitude for this viscosity
+        # yourself
+        parser = argparse.ArgumentParser('bfps ' + type(self).__name__)
+        self.add_parser_arguments(parser)
+        opt = parser.parse_args(args)
+        self.QR_stats_on = opt.QR_stats
+        self.parameters['nu'] = (opt.kMeta * 2 / opt.n)**(4./3)
+        self.parameters['dt'] = (opt.dtfactor / opt.n)
+        if ((self.parameters['niter_todo'] % self.parameters['niter_out']) != 0):
+            self.parameters['niter_out'] = self.parameters['niter_todo']
+        if self.QR_stats_on:
+            # max_Q_estimate and max_R_estimate are just used for the 2D pdf
+            # therefore I just want them to be small multiples of mean trS2
+            # I'm already estimating the dissipation with kMeta...
+            meantrS2 = (opt.n//2 / opt.kMeta)**4 * self.parameters['nu']**2
+            self.parameters['max_Q_estimate'] = meantrS2
+            self.parameters['max_R_estimate'] = .4*meantrS2**1.5
+
+        self.pars_from_namespace(opt)
+        self.fill_up_fluid_code()
+        self.finalize_code()
+        self.write_src()
+        self.set_host_info(bfps.host_info)
+        if not os.path.exists(os.path.join(self.work_dir, self.simname + '.h5')):
+            self.write_par()
+            if self.parameters['nparticles'] > 0:
+                data = self.generate_tracer_state(
+                        species = 0,
+                        rseed = opt.particle_rand_seed)
+                for s in range(1, self.particle_species):
+                    self.generate_tracer_state(species = s, data = data)
+            init_condition_file = os.path.join(
+                    self.work_dir,
+                    self.simname + '_cvorticity_i{0:0>5x}'.format(0))
+            if not os.path.exists(init_condition_file):
+                if len(opt.src_simname) > 0:
+                    src_file = os.path.join(
+                            self.work_dir,
+                            opt.src_simname + '_cvorticity_i{0:0>5x}'.format(opt.src_iteration))
+                    os.symlink(src_file, init_condition_file)
+                else:
+                   self.generate_vector_field(
+                           write_to_file = True,
+                           spectra_slope = 2.0,
+                           amplitude = 0.25)
+        self.run(
+                ncpu = opt.ncpu,
+                njobs = opt.njobs)
+        return None
 
diff --git a/bfps/__main__.py b/bfps/__main__.py
index d3732d33..3efadc7b 100644
--- a/bfps/__main__.py
+++ b/bfps/__main__.py
@@ -28,7 +28,6 @@ import sys
 import argparse
 
 import bfps
-from .Launcher import Launcher
 from .NavierStokes import NavierStokes
 from .FluidConvert import FluidConvert
 from .FluidResize import FluidResize
@@ -46,12 +45,12 @@ def main():
                        'FluidResize'],
             type = str)
     # first option is the choice of base class or -h or -v
-    # all other options are passed on to the Launcher instance
+    # all other options are passed on to the base_class instance
     opt = parser.parse_args(sys.argv[1:2])
     # error is thrown if first option is not a base class, so Launcher
     # cannot be executed by mistake.
-    l = eval('Launcher(base_class = {0})'.format(opt.base_class))
-    l(sys.argv[2:])
+    c = eval('{0}()'.format(opt.base_class))
+    c.launch(sys.argv[2:])
     return None
 
 if __name__ == '__main__':
diff --git a/bfps/_fluid_base.py b/bfps/_fluid_base.py
index e51bd0dc..6fb0db90 100644
--- a/bfps/_fluid_base.py
+++ b/bfps/_fluid_base.py
@@ -396,4 +396,8 @@ class _fluid_particle_base(_code):
             nshells = kspace['nshell'].shape[0]
             ofile.close()
         return None
+    def launch(
+            self,
+            **kwargs):
+        return None
 
-- 
GitLab