Commit 3e3cd9b3 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

move parser functionality from Launcher to _base

parent 95e800f8
......@@ -90,9 +90,10 @@ class FluidConvert(_fluid_particle_base):
"""
self.fluid_end += 'delete fs;\n'
return None
def add_parser_arguments(
def specific_parser_arguments(
self,
parser):
_fluid_particle_base.specific_parser_arguments(self, parser)
parser.add_argument(
'--src-wd',
type = str,
......
......@@ -104,15 +104,16 @@ class FluidResize(_fluid_particle_base):
//endcpp
"""
return None
def add_parser_arguments(
def specific_parser_arguments(
self,
parser):
_fluid_particle_base.specific_parser_arguments(self, parser)
parser.add_argument(
'-n',
'-N',
type = int,
dest = 'n',
dest = 'N',
default = 32,
metavar = 'N',
help = 'resize to N')
metavar = 'M',
help = 'resize from N to M')
return None
......@@ -43,39 +43,9 @@ class Launcher:
self,
base_class = NavierStokes):
self.base_class = base_class
self.parser = argparse.ArgumentParser(prog = 'bfps-' + self.base_class.__name__)
# generic arguments, all classes may use these
self.parser.add_argument(
'-v', '--version',
action = 'version',
version = '%(prog)s ' + bfps.__version__)
self.parser.add_argument(
'--ncpu',
type = int, dest = 'ncpu',
default = 2)
self.parser.add_argument(
'--simname',
type = str, dest = 'simname',
default = 'test')
self.parser.add_argument(
'--environment',
type = str,
dest = 'environment',
default = '')
self.parser.add_argument(
'--wd',
type = str, dest = 'work_dir',
default = './')
self.parser = argparse.ArgumentParser(prog = 'bfps ' + self.base_class.__name__)
c = self.base_class()
# now add class specific arguments
c.add_parser_arguments(self.parser)
# now add code parameters
for k in sorted(c.parameters.keys()):
self.parser.add_argument(
'--{0}'.format(k),
type = type(c.parameters[k]),
dest = k,
default = None)
return None
def __call__(
self,
......
......@@ -921,9 +921,10 @@ class NavierStokes(_fluid_particle_base):
self.fluid_start += update_fields
self.fluid_loop += update_fields
return None
def add_parser_arguments(
def specific_parser_arguments(
self,
parser):
_fluid_particle_base.specific_parser_arguments(self, parser)
parser.add_argument(
'--src-wd',
type = str,
......@@ -939,13 +940,6 @@ class NavierStokes(_fluid_particle_base):
type = int,
dest = 'src_iteration',
default = 0)
parser.add_argument(
'-n', '--cube-size',
type = int,
dest = 'n',
default = 32,
metavar = 'N',
help = 'code is run by default in a grid of NxNxN')
parser.add_argument(
'--precision',
type = str, dest = 'precision',
......
......@@ -29,6 +29,7 @@ import sys
import numpy as np
import h5py
from bfps import install_info
from bfps import __version__
class _base(object):
"""This class contains simulation parameters, and handles parameter related
......@@ -119,13 +120,66 @@ class _base(object):
self.parameters[k] = type(self.parameters[k])(data_file['parameters/' + k].value)
return None
def pars_from_namespace(self, opt):
new_pars = vars(opt)
cmd_line_pars = vars(opt)
for k in ['nx', 'ny', 'nz']:
if type(cmd_line_pars[k]) == type(None):
cmd_line_pars[k] = opt.n
for k in self.parameters.keys():
if k in cmd_line_pars.keys():
if not type(cmd_line_pars[k]) == type(None):
self.parameters[k] = cmd_line_pars[k]
self.simname = opt.simname
self.work_dir = opt.work_dir
for k in self.parameters.keys():
self.parameters[k] = new_pars[k]
return None
def get_coord(self, direction):
assert(direction == 'x' or direction == 'y' or direction == 'z')
return np.arange(.0, self.parameters['n' + direction])*2*np.pi / self.parameters['n' + direction]
def add_parser_arguments(
self,
parser):
self.specific_parser_arguments(parser)
self.parameters_to_parser_arguments(parser)
return None
def specific_parser_arguments(
self,
parser):
parser.add_argument(
'-v', '--version',
action = 'version',
version = '%(prog)s ' + __version__)
parser.add_argument(
'-n', '--cube-size',
type = int,
dest = 'n',
default = 32,
metavar = 'N',
help = 'code is run by default in a grid of NxNxN')
parser.add_argument(
'--ncpu',
type = int, dest = 'ncpu',
default = 2)
parser.add_argument(
'--simname',
type = str, dest = 'simname',
default = 'test')
parser.add_argument(
'--environment',
type = str,
dest = 'environment',
default = '')
parser.add_argument(
'--wd',
type = str, dest = 'work_dir',
default = './')
return None
def parameters_to_parser_arguments(
self,
parser):
for k in sorted(self.parameters.keys()):
parser.add_argument(
'--{0}'.format(k),
type = type(self.parameters[k]),
dest = k,
default = None)
return None
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