Commit a622d95a authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

Merge branch 'feature/executable' into develop

parents ebfc89ca 9b81285a
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
......@@ -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
......
......@@ -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
......
import sys
from .Launcher import Launcher
def main():
l = Launcher()
l(sys.argv[1:] + ['--run'])
return None
if __name__ == '__main__':
main()
......@@ -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
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment