Commit 2212daf8 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

broken --- rename files and classes

only test_io passes right now.
parent 5f87cc6a
......@@ -24,22 +24,21 @@
import bfps
import bfps.fluid_base
import bfps.tools
import numpy as np
import pickle
import os
from ._fluid_base import _fluid_particle_base
class fluid_converter(bfps.fluid_base.fluid_particle_base):
class FluidConvert(_fluid_particle_base):
def __init__(
self,
name = 'fluid_converter',
name = 'FluidConvert',
work_dir = './',
simname = 'test',
fluid_precision = 'single',
use_fftw_wisdom = True):
super(fluid_converter, self).__init__(
_fluid_particle_base.__init__(
self,
name = name,
work_dir = work_dir,
simname = simname,
......
......@@ -24,20 +24,20 @@
import bfps
import bfps.fluid_base
from ._fluid_base import _fluid_particle_base
import numpy as np
class fluid_resize(bfps.fluid_base.fluid_particle_base):
class FluidResize(_fluid_particle_base):
def __init__(
self,
name = 'fluid_resize',
name = 'FluidResize',
work_dir = './',
simname = 'test',
dtype = np.float32,
use_fftw_wisdom = False):
super(fluid_resize, self).__init__(
_fluid_particle_base.__init__(
self,
name = name,
work_dir = work_dir,
simname = simname,
......
import os
import argparse
import bfps
import .__init__ as bfps
from .NavierStokes import NavierStokes
from .FluidResize import FluidResize
from .FluidConvert import FluidConvert
class Launcher:
def __init__(self):
self.base_class = bfps.NavierStokes
def __init__(
self,
base_class = NavierStokes):
self.base_class = base_class
self.parser = argparse.ArgumentParser(prog = 'bfps')
self.parser.add_argument(
'-v', '--version',
......@@ -18,10 +24,6 @@ class Launcher:
default = 32,
metavar = 'N',
help = 'code is run by default in a grid of NxNxN')
self.parser.add_argument(
'--run',
dest = 'run',
action = 'store_true')
self.parser.add_argument(
'--ncpu',
type = int, dest = 'ncpu',
......@@ -128,29 +130,28 @@ class Launcher:
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:
data = c.generate_tracer_state(species = 0, rseed = opt.particle_rand_seed)
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)
if not os.path.exists(os.path.join(c.work_dir, c.simname + '.h5')):
c.write_par()
if c.parameters['nparticles'] > 0:
data = c.generate_tracer_state(species = 0, rseed = opt.particle_rand_seed)
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
......@@ -28,11 +28,9 @@ import os
import numpy as np
import h5py
import bfps
import bfps.fluid_base
import bfps.tools
from ._fluid_base import _fluid_particle_base
class NavierStokes(bfps.fluid_base.fluid_particle_base):
class NavierStokes(_fluid_particle_base):
def __init__(
self,
name = 'NavierStokes',
......@@ -46,7 +44,8 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
self.QR_stats_on = QR_stats_on
self.frozen_fields = frozen_fields
self.fftw_plan_rigor = fftw_plan_rigor
super(NavierStokes, self).__init__(
_fluid_particle_base.__init__(
self,
name = name,
work_dir = work_dir,
simname = simname,
......@@ -715,7 +714,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
self.parameters['nx']//2+1,
3))
def write_par(self, iter0 = 0):
super(NavierStokes, self).write_par(iter0 = iter0)
_fluid_particle_base.write_par(self, iter0 = iter0)
with h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r+') as ofile:
kspace = self.get_kspace()
nshells = kspace['nshell'].shape[0]
......
......@@ -48,8 +48,45 @@ 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
from .FluidConvert import FluidConvert
from .FluidResize import FluidResize
from .NavierStokes import NavierStokes
import argparse
def get_parser(base_class = NavierStokes,
n = 32,
ncpu = 2,
precision = 'single',
simname = 'test',
work_dir = './',
njobs = 1):
parser = argparse.ArgumentParser()
parser.add_argument('--run', dest = 'run', action = 'store_true')
parser.add_argument('-n',
type = int, dest = 'n',
default = n)
parser.add_argument('--ncpu',
type = int, dest = 'ncpu',
default = ncpu)
parser.add_argument('--precision',
type = str, dest = 'precision',
default = precision)
parser.add_argument('--simname',
type = str, dest = 'simname',
default = simname)
parser.add_argument('--wd',
type = str, dest = 'work_dir',
default = work_dir)
parser.add_argument('--njobs',
type = int, dest = 'njobs',
default = njobs)
c = base_class(simname = simname)
for k in sorted(c.parameters.keys()):
parser.add_argument(
'--{0}'.format(k),
type = type(c.parameters[k]),
dest = k,
default = c.parameters[k])
return parser
......@@ -3,7 +3,7 @@ from .Launcher import Launcher
def main():
l = Launcher()
l(sys.argv[1:] + ['--run'])
l(sys.argv[1:])
return None
if __name__ == '__main__':
......
......@@ -28,9 +28,9 @@ import os
import sys
import numpy as np
import h5py
import bfps
from bfps import install_info
class base(object):
class _base(object):
"""
This class contains simulation parameters, and handles parameter related
functionalities of both python objects and C++ codes.
......@@ -109,8 +109,8 @@ class base(object):
else:
ofile['parameters/' + k] = self.parameters[k]
ofile['iteration'] = int(iter0)
for k in bfps.install_info.keys():
ofile['install_info/' + k] = str(bfps.install_info[k])
for k in install_info.keys():
ofile['install_info/' + k] = str(install_info[k])
ofile.close()
return None
def read_parameters(self):
......
......@@ -31,10 +31,11 @@ import subprocess
import h5py
from datetime import datetime
import math
import bfps
from bfps.base import base
from ._base import _base
class code(base):
class _code(_base):
"""
This class is meant to stitch together the C++ code into a final source file,
compile it, and handle all job launching.
......@@ -43,7 +44,7 @@ class code(base):
self,
work_dir = './',
simname = 'test'):
super(code, self).__init__(work_dir = work_dir, simname = simname)
_base.__init__(self, work_dir = work_dir, simname = simname)
self.version_message = ('/***********************************************************************\n' +
'* this code automatically generated by bfps\n' +
'* version {0}\n'.format(bfps.__version__) +
......
......@@ -24,15 +24,14 @@
import bfps
import bfps.code
import bfps.tools
from ._code import _code
from bfps import tools
import os
import numpy as np
import h5py
class fluid_particle_base(bfps.code):
class _fluid_particle_base(_code):
def __init__(
self,
name = 'solver',
......@@ -40,7 +39,8 @@ class fluid_particle_base(bfps.code):
simname = 'test',
dtype = np.float32,
use_fftw_wisdom = True):
super(fluid_particle_base, self).__init__(
_code.__init__(
self,
work_dir = work_dir,
simname = simname)
self.use_fftw_wisdom = use_fftw_wisdom
......@@ -284,19 +284,19 @@ class fluid_particle_base(bfps.code):
field_name = 'vorticity',
write_to_file = False):
np.random.seed(rseed)
Kdata00 = bfps.tools.generate_data_3D(
Kdata00 = tools.generate_data_3D(
self.parameters['nz']//2,
self.parameters['ny']//2,
self.parameters['nx']//2,
p = spectra_slope,
amplitude = amplitude).astype(self.ctype)
Kdata01 = bfps.tools.generate_data_3D(
Kdata01 = tools.generate_data_3D(
self.parameters['nz']//2,
self.parameters['ny']//2,
self.parameters['nx']//2,
p = spectra_slope,
amplitude = amplitude).astype(self.ctype)
Kdata02 = bfps.tools.generate_data_3D(
Kdata02 = tools.generate_data_3D(
self.parameters['nz']//2,
self.parameters['ny']//2,
self.parameters['nx']//2,
......@@ -308,7 +308,7 @@ class fluid_particle_base(bfps.code):
Kdata0[..., 0] = Kdata00
Kdata0[..., 1] = Kdata01
Kdata0[..., 2] = Kdata02
Kdata1 = bfps.tools.padd_with_zeros(
Kdata1 = tools.padd_with_zeros(
Kdata0,
self.parameters['nz'],
self.parameters['ny'],
......@@ -396,7 +396,7 @@ class fluid_particle_base(bfps.code):
assert (self.parameters['niter_todo'] % self.parameters['niter_part'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_stat'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_part'] == 0)
super(fluid_particle_base, self).write_par(iter0 = iter0)
_code.write_par(self, iter0 = iter0)
with h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r+') as ofile:
ofile['field_dtype'] = np.dtype(self.dtype).str
kspace = self.get_kspace()
......
......@@ -33,7 +33,7 @@ import numpy as np
import matplotlib.pyplot as plt
import bfps
from bfps import fluid_resize
from bfps import FluidResize
from bfps.tools import particle_finite_diff_test as acceleration_test
parser = bfps.get_parser()
......@@ -54,7 +54,7 @@ parser.add_argument(
def double(opt):
old_simname = 'N{0:0>3x}'.format(opt.n)
new_simname = 'N{0:0>3x}'.format(opt.n*2)
c = fluid_resize(
c = FluidResize(
work_dir = opt.work_dir,
simname = old_simname + '_double',
dtype = opt.precision)
......
......@@ -26,7 +26,10 @@
from base import *
class test_io(bfps.code):
import bfps
from bfps._code import _code
class test_io(_code):
def __init__(
self,
name = 'test_io',
......
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