Commit 96ec4dc2 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

add DNS option to executable script

parent 7cbaa8ee
...@@ -45,12 +45,22 @@ class DNS(_code): ...@@ -45,12 +45,22 @@ class DNS(_code):
def __init__( def __init__(
self, self,
work_dir = './', work_dir = './',
simname = 'test', simname = 'test'):
dns_type = 'NSVE', _code.__init__(
fluid_dtype = 'single'): self,
_code.__init__(self, work_dir = work_dir, simname = simname) work_dir = work_dir,
self.dns_type = dns_type simname = simname)
self.name = self.dns_type + '-v' + bfps.__version__ self.host_info = {'type' : 'cluster',
'environment' : None,
'deltanprocs' : 1,
'queue' : '',
'mail_address': '',
'mail_events' : None}
self.generate_default_parameters()
return None
def set_precision(
self,
fluid_dtype):
if fluid_dtype in [np.float32, np.float64]: if fluid_dtype in [np.float32, np.float64]:
self.fluid_dtype = fluid_dtype self.fluid_dtype = fluid_dtype
elif fluid_dtype in ['single', 'double']: elif fluid_dtype in ['single', 'double']:
...@@ -62,9 +72,13 @@ class DNS(_code): ...@@ -62,9 +72,13 @@ class DNS(_code):
if self.rtype == np.float32: if self.rtype == np.float32:
self.ctype = np.dtype(np.complex64) self.ctype = np.dtype(np.complex64)
self.C_field_dtype = 'float' self.C_field_dtype = 'float'
self.fluid_precision = 'single'
elif self.rtype == np.float64: elif self.rtype == np.float64:
self.ctype = np.dtype(np.complex128) self.ctype = np.dtype(np.complex128)
self.C_field_dtype = 'double' self.C_field_dtype = 'double'
self.fluid_precision = 'double'
return None
def write_src(self):
self.version_message = ( self.version_message = (
'/***********************************************************************\n' + '/***********************************************************************\n' +
'* this code automatically generated by bfps\n' + '* this code automatically generated by bfps\n' +
...@@ -94,13 +108,22 @@ class DNS(_code): ...@@ -94,13 +108,22 @@ class DNS(_code):
return main_code< {0} >(argc, argv, fpe); return main_code< {0} >(argc, argv, fpe);
}} }}
""".format(self.dns_type + '<{0}>'.format(self.C_field_dtype)) """.format(self.dns_type + '<{0}>'.format(self.C_field_dtype))
self.host_info = {'type' : 'cluster', self.includes = '\n'.join(
'environment' : None, ['#include ' + hh
'deltanprocs' : 1, for hh in self.include_list])
'queue' : '', with open(self.name + '.cpp', 'w') as outfile:
'mail_address': '', outfile.write(self.version_message + '\n\n')
'mail_events' : None} outfile.write(self.includes + '\n\n')
self.generate_default_parameters() outfile.write(self.cread_pars(
template_class = '{0}<rnumber>::'.format(self.dns_type),
template_prefix = 'template <typename rnumber> ',
simname_variable = 'simname.c_str()') + '\n\n')
for rnumber in ['float', 'double']:
outfile.write(self.cread_pars(
template_class = '{0}<{1}>::'.format(self.dns_type, rnumber),
template_prefix = 'template '.format(rnumber),
just_declaration = True) + '\n\n')
outfile.write(self.main + '\n')
return None return None
def generate_default_parameters(self): def generate_default_parameters(self):
# these parameters are relevant for all DNS classes # these parameters are relevant for all DNS classes
...@@ -123,30 +146,12 @@ class DNS(_code): ...@@ -123,30 +146,12 @@ class DNS(_code):
self.parameters['max_velocity_estimate'] = float(1) self.parameters['max_velocity_estimate'] = float(1)
self.parameters['max_vorticity_estimate'] = float(1) self.parameters['max_vorticity_estimate'] = float(1)
# parameters specific to particle version # parameters specific to particle version
if self.dns_type == 'NSVEp': self.NSVEp_extra_parameters = {}
self.parameters['niter_part'] = int(1) self.NSVEp_extra_parameters['niter_part'] = int(1)
self.parameters['nparticles'] = int(10) self.NSVEp_extra_parameters['nparticles'] = int(10)
self.parameters['tracers0_integration_steps'] = int(4) self.NSVEp_extra_parameters['tracers0_integration_steps'] = int(4)
self.parameters['tracers0_neighbours'] = int(1) self.NSVEp_extra_parameters['tracers0_neighbours'] = int(1)
self.parameters['tracers0_smoothness'] = int(1) self.NSVEp_extra_parameters['tracers0_smoothness'] = int(1)
return None
def write_src(self):
self.includes = '\n'.join(
['#include ' + hh
for hh in self.include_list])
with open(self.name + '.cpp', 'w') as outfile:
outfile.write(self.version_message + '\n\n')
outfile.write(self.includes + '\n\n')
outfile.write(self.cread_pars(
template_class = '{0}<rnumber>::'.format(self.dns_type),
template_prefix = 'template <typename rnumber> ',
simname_variable = 'simname.c_str()') + '\n\n')
for rnumber in ['float', 'double']:
outfile.write(self.cread_pars(
template_class = '{0}<{1}>::'.format(self.dns_type, rnumber),
template_prefix = 'template '.format(rnumber),
just_declaration = True) + '\n\n')
outfile.write(self.main + '\n')
return None return None
def get_kspace(self): def get_kspace(self):
kspace = {} kspace = {}
...@@ -376,7 +381,6 @@ class DNS(_code): ...@@ -376,7 +381,6 @@ class DNS(_code):
for k in vec_stat_datasets: for k in vec_stat_datasets:
time_chunk = 2**20//(8*3*3*nshells) time_chunk = 2**20//(8*3*3*nshells)
time_chunk = max(time_chunk, 1) time_chunk = max(time_chunk, 1)
print(ofile)
ofile.create_dataset('statistics/spectra/' + k + '_' + k, ofile.create_dataset('statistics/spectra/' + k + '_' + k,
(1, nshells, 3, 3), (1, nshells, 3, 3),
chunks = (time_chunk, nshells, 3, 3), chunks = (time_chunk, nshells, 3, 3),
...@@ -434,10 +438,71 @@ class DNS(_code): ...@@ -434,10 +438,71 @@ class DNS(_code):
(3,)), (3,)),
dtype = np.float) dtype = np.float)
return None return None
def specific_parser_arguments( def job_parser_arguments(
self, self,
parser): parser):
_code.specific_parser_arguments(self, parser) parser.add_argument(
'--ncpu',
type = int,
dest = 'ncpu',
default = -1)
parser.add_argument(
'--np', '--nprocesses',
metavar = 'NPROCESSES',
help = 'number of mpi processes to use',
type = int,
dest = 'nb_processes',
default = 4)
parser.add_argument(
'--ntpp', '--nthreads-per-process',
type = int,
dest = 'nb_threads_per_process',
metavar = 'NTHREADS_PER_PROCESS',
help = 'number of threads to use per MPI process',
default = 1)
parser.add_argument(
'--no-submit',
action = 'store_true',
dest = 'no_submit')
parser.add_argument(
'--environment',
type = str,
dest = 'environment',
default = None)
parser.add_argument(
'--minutes',
type = int,
dest = 'minutes',
default = 5,
help = 'If environment supports it, this is the requested wall-clock-limit.')
parser.add_argument(
'--njobs',
type = int, dest = 'njobs',
default = 1)
return None
def simulation_parser_arguments(
self,
parser):
parser.add_argument(
'--simname',
type = str, dest = 'simname',
default = 'test')
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(
'--wd',
type = str, dest = 'work_dir',
default = './')
parser.add_argument(
'--precision',
choices = ['single', 'double'],
type = str,
default = 'single')
parser.add_argument( parser.add_argument(
'--src-wd', '--src-wd',
type = str, type = str,
...@@ -453,10 +518,6 @@ class DNS(_code): ...@@ -453,10 +518,6 @@ class DNS(_code):
type = int, type = int,
dest = 'src_iteration', dest = 'src_iteration',
default = 0) default = 0)
parser.add_argument(
'--njobs',
type = int, dest = 'njobs',
default = 1)
parser.add_argument( parser.add_argument(
'--kMeta', '--kMeta',
type = float, type = float,
...@@ -468,6 +529,10 @@ class DNS(_code): ...@@ -468,6 +529,10 @@ class DNS(_code):
dest = 'dtfactor', dest = 'dtfactor',
default = 0.5, default = 0.5,
help = 'dt is computed as DTFACTOR / N') help = 'dt is computed as DTFACTOR / N')
return None
def particle_parser_arguments(
self,
parser):
parser.add_argument( parser.add_argument(
'--particle-rand-seed', '--particle-rand-seed',
type = int, type = int,
...@@ -503,6 +568,31 @@ class DNS(_code): ...@@ -503,6 +568,31 @@ class DNS(_code):
dest = 'smoothness', dest = 'smoothness',
default = 1) default = 1)
return None return None
def add_parser_arguments(
self,
parser):
subparsers = parser.add_subparsers(
dest = 'DNS_class',
help = 'type of simulation to run')
subparsers.required = True
parser_NSVE = subparsers.add_parser(
'NSVE',
help = 'plain Navier-Stokes vorticity formulation')
self.simulation_parser_arguments(parser_NSVE)
self.job_parser_arguments(parser_NSVE)
self.parameters_to_parser_arguments(parser_NSVE)
parser_NSVEp = subparsers.add_parser(
'NSVEp',
help = 'plain Navier-Stokes vorticity formulation, with basic fluid tracers')
self.simulation_parser_arguments(parser_NSVEp)
self.job_parser_arguments(parser_NSVEp)
self.particle_parser_arguments(parser_NSVEp)
self.parameters_to_parser_arguments(parser_NSVEp)
self.parameters_to_parser_arguments(
parser_NSVEp,
self.NSVEp_extra_parameters)
return None
def prepare_launch( def prepare_launch(
self, self,
args = []): args = []):
...@@ -532,6 +622,13 @@ class DNS(_code): ...@@ -532,6 +622,13 @@ class DNS(_code):
""" """
opt = _code.prepare_launch(self, args = args) opt = _code.prepare_launch(self, args = args)
self.set_precision(opt.precision)
self.dns_type = opt.DNS_class
self.name = self.dns_type + '-' + self.fluid_precision + '-v' + bfps.__version__
# merge parameters if needed
if self.dns_type == 'NSVEp':
for k in self.NSVEp_extra_parameters.keys():
self.parameters[k] = self.NSVEp_extra_parameters[k]
self.parameters['nu'] = (opt.kMeta * 2 / opt.n)**(4./3) self.parameters['nu'] = (opt.kMeta * 2 / opt.n)**(4./3)
self.parameters['dt'] = (opt.dtfactor / opt.n) self.parameters['dt'] = (opt.dtfactor / opt.n)
# custom famplitude for 288 and 576 # custom famplitude for 288 and 576
......
...@@ -28,6 +28,7 @@ import sys ...@@ -28,6 +28,7 @@ import sys
import argparse import argparse
import bfps import bfps
from .DNS import DNS
from .NavierStokes import NavierStokes from .NavierStokes import NavierStokes
from .NSVorticityEquation import NSVorticityEquation from .NSVorticityEquation import NSVorticityEquation
from .FluidResize import FluidResize from .FluidResize import FluidResize
...@@ -64,13 +65,22 @@ def main(): ...@@ -64,13 +65,22 @@ def main():
'NSManyParticles-double'] 'NSManyParticles-double']
parser.add_argument( parser.add_argument(
'base_class', 'base_class',
choices = NSoptions + NSVEoptions + FRoptions + FCoptions + NSMPopt, choices = ['DNS'] +
NSoptions +
NSVEoptions +
FRoptions +
FCoptions +
NSMPopt,
type = str) type = str)
# first option is the choice of base class or -h or -v # first option is the choice of base class or -h or -v
# all other options are passed on to the base_class instance # all other options are passed on to the base_class instance
opt = parser.parse_args(sys.argv[1:2]) opt = parser.parse_args(sys.argv[1:2])
# error is thrown if first option is not a base class, so launch # error is thrown if first option is not a base class, so launch
# cannot be executed by mistake. # cannot be executed by mistake.
if opt.base_class == 'DNS':
c = DNS()
c.launch(args = sys.argv[2:])
return None
if 'double' in opt.base_class: if 'double' in opt.base_class:
precision = 'double' precision = 'double'
else: else:
......
...@@ -2,12 +2,13 @@ from bfps.DNS import DNS ...@@ -2,12 +2,13 @@ from bfps.DNS import DNS
def main(): def main():
niterations = 16 niterations = 32
nparticles = 100 nparticles = 10000
c = DNS(dns_type = 'NSVEp') c = DNS()
c.launch( c.launch(
['-n', '32', ['NSVEp',
'--simname', 'vorticity_equation', '-n', '32',
'--simname', 'dns_nsvep',
'--np', '4', '--np', '4',
'--ntpp', '1', '--ntpp', '1',
'--niter_todo', '{0}'.format(niterations), '--niter_todo', '{0}'.format(niterations),
...@@ -16,7 +17,7 @@ def main(): ...@@ -16,7 +17,7 @@ def main():
'--checkpoints_per_file', '{0}'.format(3), '--checkpoints_per_file', '{0}'.format(3),
'--nparticles', '{0}'.format(nparticles), '--nparticles', '{0}'.format(nparticles),
'--particle-rand-seed', '2', '--particle-rand-seed', '2',
#'--njobs', '2', '--njobs', '2',
'--wd', './']) '--wd', './'])
return 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