diff --git a/bfps/Launcher.py b/bfps/Launcher.py new file mode 100644 index 0000000000000000000000000000000000000000..27d9f739987c5c2d4da8dc17a929c8fed841794c --- /dev/null +++ b/bfps/Launcher.py @@ -0,0 +1,111 @@ +import os + +import sys +import numpy as np +import bfps + +class Launcher: + def __init__( + self, + data_dir = './'): + self.parser = bfps.get_parser( + bfps.NavierStokes, + work_dir = os.path.realpath(data_dir)) + self.parser.add_argument( + '--QR-stats', + action = 'store_true', + dest = 'QR_stats') + self.parser.add_argument( + '--kMeta', + type = float, + dest = 'kMeta', + default = 2.0) + self.parser.add_argument( + '--dtfactor', + type = float, + dest = 'dtfactor', + default = 0.5, + help = 'dt is computed as DTFACTOR / N') + self.parser.add_argument( + '--environment', + type = str, + dest = 'environment', + default = '') + self.parser.add_argument( + '--src-simname', + type = str, + dest = 'src_simname', + default = '') + self.parser.add_argument( + '--src-iteration', + type = int, + dest = 'src_iteration', + default = 0) + self.data_dir = data_dir + self.base_class = bfps.NavierStokes + return None + def __call__( + self, + args = None): + opt = self.parser.parse_args(args) + if opt.environment != '': + bfps.host_info['environment'] = opt.environment + opt.nx = opt.n + opt.ny = opt.n + opt.nz = opt.n + opt.work_dir = os.path.join( + os.path.realpath(opt.work_dir), + 'N{0:0>4}'.format(opt.n)) + c = self.base_class( + fluid_precision = opt.precision, + simname = opt.simname, + QR_stats_on = opt.QR_stats) + c.pars_from_namespace(opt) + # with the default Lundgren forcing, I can estimate the dissipation + # with nondefault forcing, figure out the amplitude for this viscosity + # yourself + c.parameters['nu'] = (opt.kMeta * 2 / opt.n)**(4./3) + c.parameters['dt'] = (opt.dtfactor / opt.n) + if ((c.parameters['niter_todo'] % c.parameters['niter_out']) != 0): + c.parameters['niter_out'] = c.parameters['niter_todo'] + if c.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 * c.parameters['nu']**2 + c.parameters['max_Q_estimate'] = meantrS2 + c.parameters['max_R_estimate'] = .4*meantrS2**1.5 + c.fill_up_fluid_code() + c.finalize_code() + c.write_src() + c.set_host_info(bfps.host_info) + if opt.run: + if not os.path.exists(os.path.join(c.work_dir, c.simname + '.h5')): + c.write_par() + if c.parameters['nparticles'] > 0: + if opt.particle_rand_seed != 0: + rseed = opt.particle_rand_seed + else: + rseed = None + data = c.generate_tracer_state(species = 0, rseed = rseed) + for s in range(1, c.particle_species): + c.generate_tracer_state(species = s, data = data) + init_condition_file = os.path.join( + c.work_dir, + c.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( + c.work_dir, + opt.src_simname + '_cvorticity_i{0:0>5x}'.format(opt.src_iteration)) + os.symlink(src_file, init_condition_file) + else: + c.generate_vector_field( + write_to_file = True, + spectra_slope = 2.0, + amplitude = 0.25) + c.run(ncpu = opt.ncpu, + njobs = opt.njobs) + return c + + diff --git a/bfps/NavierStokes.py b/bfps/NavierStokes.py index e5803618957119b176037f79a07333c186ee5102..7d11b2f2de4ae550a2e342b119354b95ec10c1a4 100644 --- a/bfps/NavierStokes.py +++ b/bfps/NavierStokes.py @@ -579,10 +579,14 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): self.particle_stat_src += '}\n' self.particle_species += nspecies return None + def get_data_file_name(self): + return os.path.join(self.work_dir, self.simname + '.h5') def get_data_file(self): - return h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r') + return h5py.File(self.get_data_file_name(), 'r') def get_postprocess_file_name(self): return os.path.join(self.work_dir, self.simname + '_postprocess.h5') + def get_postprocess_file(self): + return h5py.File(self.get_postprocess_file_name(), 'r') def compute_statistics(self, iter0 = 0, iter1 = None): if len(list(self.statistics.keys())) > 0: return None diff --git a/bfps/__init__.py b/bfps/__init__.py index 37d22327b1d40b4c33ca0db15e7d93c7dc4140a8..519f83c482e24d4cf19fde9c12b5c6e8d55c874f 100644 --- a/bfps/__init__.py +++ b/bfps/__init__.py @@ -25,7 +25,7 @@ import os -import subprocess +import sys import pickle import pkg_resources @@ -43,6 +43,11 @@ install_info = pickle.load( 'install_info.pickle'), 'rb')) +homefolder = os.path.expanduser('~') +bfpsfolder = os.path.join(homefolder, '.config/', 'bfps') +sys.path.append(bfpsfolder) +from host_information import host_info + from .code import code from .fluid_converter import fluid_converter from .fluid_resize import fluid_resize diff --git a/bfps/__main__.py b/bfps/__main__.py new file mode 100644 index 0000000000000000000000000000000000000000..e9b883fb48e35685ecca95ce7f809ce7136f58b3 --- /dev/null +++ b/bfps/__main__.py @@ -0,0 +1,11 @@ +import sys +from .Launcher import Launcher + +def main(): + l = Launcher() + l(sys.argv[1:] + ['--run']) + return None + +if __name__ == '__main__': + main() + diff --git a/bfps/fluid_base.py b/bfps/fluid_base.py index a96d3c3f48c3ab1ba555f03873cf1e142b8603b0..1fdfda12e52fa3ad01cb952286773aebb5239fd8 100644 --- a/bfps/fluid_base.py +++ b/bfps/fluid_base.py @@ -71,9 +71,9 @@ class fluid_particle_base(bfps.code): self.parameters['nparticles'] = 0 self.parameters['dt'] = 0.01 self.parameters['nu'] = 0.1 - self.parameters['famplitude'] = 1.0 self.parameters['fmode'] = 1 - self.parameters['fk0'] = 0.0 + self.parameters['famplitude'] = 0.5 + self.parameters['fk0'] = 1.5 self.parameters['fk1'] = 3.0 self.parameters['forcing_type'] = 'linear' self.parameters['histogram_bins'] = 256 diff --git a/setup.py b/setup.py index ab7e0ae5f8f3228a3326879513e0b32b2b2017c6..cb4ab8c3c2a456d073ba846803113b05e6e95264 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,13 @@ if not os.path.exists(os.path.join(bfpsfolder, 'machine_settings.py')): if not os.path.isdir(bfpsfolder): os.mkdir(bfpsfolder) shutil.copyfile('./machine_settings_py.py', os.path.join(bfpsfolder, 'machine_settings.py')) +# check if .config/bfps/host_information.py file exists, create it if not +if not os.path.exists(os.path.join(bfpsfolder, 'host_information.py')): + if not os.path.isdir(bfpsfolder): + os.mkdir(bfpsfolder) + open(os.path.join(bfpsfolder, 'host_information.py'), + 'w').write('host_info = {\'type\' : \'none\'}\n') + shutil.copyfile('./machine_settings_py.py', os.path.join(bfpsfolder, 'machine_settings.py')) sys.path.append(bfpsfolder) # import stuff required for compilation of static library from machine_settings import include_dirs, library_dirs, extra_compile_args, extra_libraries @@ -190,6 +197,10 @@ setup( cmdclass={'build' : CustomBuild}, package_data = {'bfps': header_list + ['libbfps.a', 'install_info.pickle']}, + entry_points = { + 'console_scripts': [ + 'bfps = bfps.__main__:main'], + }, version = VERSION, ######################################################################## # useless stuff folows