Commit 74ca7af1 authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

executable using NSVE child compiles and runs

there were a few issues with read_parameters, which is now a virtual
function in NSVE.
parent 9f4edcbe
...@@ -114,15 +114,22 @@ class DNS(_code): ...@@ -114,15 +114,22 @@ class DNS(_code):
with open(self.name + '.cpp', 'w') as outfile: with open(self.name + '.cpp', 'w') as outfile:
outfile.write(self.version_message + '\n\n') outfile.write(self.version_message + '\n\n')
outfile.write(self.includes + '\n\n') outfile.write(self.includes + '\n\n')
outfile.write(self.cread_pars( outfile.write(
template_class = '{0}<rnumber>::'.format(self.dns_type), self.cread_pars(
template_prefix = 'template <typename rnumber> ', template_class = '{0}<rnumber>::'.format(self.dns_type),
simname_variable = 'simname.c_str()') + '\n\n') template_prefix = 'template <typename rnumber> ',
simname_variable = 'this->simname.c_str()',
prepend_this = True) +
'\n\n')
for rnumber in ['float', 'double']: for rnumber in ['float', 'double']:
outfile.write(self.cread_pars( outfile.write(self.cread_pars(
template_class = '{0}<{1}>::'.format(self.dns_type, rnumber), template_class = '{0}<{1}>::'.format(self.dns_type, rnumber),
template_prefix = 'template '.format(rnumber), template_prefix = 'template '.format(rnumber),
just_declaration = True) + '\n\n') just_declaration = True) + '\n\n')
if self.dns_type == 'NSVEparticles':
outfile.write('template <typename rnumber> int NSVE<rnumber>::read_parameters(){return EXIT_SUCCESS;}\n')
outfile.write('template int NSVE<float>::read_parameters();\n')
outfile.write('template int NSVE<double>::read_parameters();\n\n')
outfile.write(self.main + '\n') outfile.write(self.main + '\n')
return None return None
def generate_default_parameters(self): def generate_default_parameters(self):
...@@ -365,7 +372,7 @@ class DNS(_code): ...@@ -365,7 +372,7 @@ class DNS(_code):
assert (self.parameters['niter_todo'] % self.parameters['niter_stat'] == 0) assert (self.parameters['niter_todo'] % self.parameters['niter_stat'] == 0)
assert (self.parameters['niter_todo'] % self.parameters['niter_out'] == 0) assert (self.parameters['niter_todo'] % self.parameters['niter_out'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_stat'] == 0) assert (self.parameters['niter_out'] % self.parameters['niter_stat'] == 0)
if self.dns_type == 'NSVEp': if self.dns_type in ['NSVEp', 'NSVEparticles']:
assert (self.parameters['niter_todo'] % self.parameters['niter_part'] == 0) assert (self.parameters['niter_todo'] % self.parameters['niter_part'] == 0)
assert (self.parameters['niter_out'] % self.parameters['niter_part'] == 0) assert (self.parameters['niter_out'] % self.parameters['niter_part'] == 0)
_code.write_par(self, iter0 = iter0) _code.write_par(self, iter0 = iter0)
...@@ -591,6 +598,17 @@ class DNS(_code): ...@@ -591,6 +598,17 @@ class DNS(_code):
self.parameters_to_parser_arguments( self.parameters_to_parser_arguments(
parser_NSVEp, parser_NSVEp,
self.NSVEp_extra_parameters) self.NSVEp_extra_parameters)
parser_NSVEp2 = subparsers.add_parser(
'NSVEparticles',
help = 'plain Navier-Stokes vorticity formulation, with basic fluid tracers')
self.simulation_parser_arguments(parser_NSVEp2)
self.job_parser_arguments(parser_NSVEp2)
self.particle_parser_arguments(parser_NSVEp2)
self.parameters_to_parser_arguments(parser_NSVEp2)
self.parameters_to_parser_arguments(
parser_NSVEp2,
self.NSVEp_extra_parameters)
return None return None
def prepare_launch( def prepare_launch(
self, self,
...@@ -625,7 +643,7 @@ class DNS(_code): ...@@ -625,7 +643,7 @@ class DNS(_code):
self.dns_type = opt.DNS_class self.dns_type = opt.DNS_class
self.name = self.dns_type + '-' + self.fluid_precision + '-v' + bfps.__version__ self.name = self.dns_type + '-' + self.fluid_precision + '-v' + bfps.__version__
# merge parameters if needed # merge parameters if needed
if self.dns_type == 'NSVEp': if self.dns_type in ['NSVEp', 'NSVEparticles']:
for k in self.NSVEp_extra_parameters.keys(): for k in self.NSVEp_extra_parameters.keys():
self.parameters[k] = self.NSVEp_extra_parameters[k] 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)
...@@ -655,11 +673,14 @@ class DNS(_code): ...@@ -655,11 +673,14 @@ class DNS(_code):
# hardcoded FFTW complex representation size # hardcoded FFTW complex representation size
field_size = 3*(opt.nx+2)*opt.ny*opt.nz*self.fluid_dtype.itemsize field_size = 3*(opt.nx+2)*opt.ny*opt.nz*self.fluid_dtype.itemsize
checkpoint_size = field_size checkpoint_size = field_size
if self.dns_type == 'NSVEp': if self.dns_type in ['NSVEp', 'NSVEparticles']:
rhs_size = self.parameters['tracers0_integration_steps'] rhs_size = self.parameters['tracers0_integration_steps']
if type(opt.tracers0_integration_steps) != type(None): if type(opt.tracers0_integration_steps) != type(None):
rhs_size = opt.tracers0_integration_steps rhs_size = opt.tracers0_integration_steps
particle_size = (1+rhs_size)*3*opt.nparticles*8 nparticles = opt.nparticles
if type(nparticles) == type(None):
nparticles = self.NSVEp_extra_parameters['nparticles']
particle_size = (1+rhs_size)*3*nparticles*8
checkpoint_size += particle_size checkpoint_size += particle_size
if checkpoint_size < 1e9: if checkpoint_size < 1e9:
opt.checkpoints_per_file = int(1e9 / checkpoint_size) opt.checkpoints_per_file = int(1e9 / checkpoint_size)
...@@ -856,7 +877,7 @@ class DNS(_code): ...@@ -856,7 +877,7 @@ class DNS(_code):
f['vorticity/complex/{0}'.format(0)] = data f['vorticity/complex/{0}'.format(0)] = data
f.close() f.close()
# take care of particles' initial condition # take care of particles' initial condition
if self.dns_type == 'NSVEp': if self.dns_type in ['NSVEp', 'NSVEparticles']:
if opt.pclouds > 1: if opt.pclouds > 1:
np.random.seed(opt.particle_rand_seed) np.random.seed(opt.particle_rand_seed)
if opt.pcloud_type == 'random-cube': if opt.pcloud_type == 'random-cube':
...@@ -881,7 +902,7 @@ class DNS(_code): ...@@ -881,7 +902,7 @@ class DNS(_code):
particle_initial_condition[..., 2] += onedarray[None, :, None, None] particle_initial_condition[..., 2] += onedarray[None, :, None, None]
self.write_par( self.write_par(
particle_ic = particle_initial_condition) particle_ic = particle_initial_condition)
if self.dns_type == 'NSVEp': if self.dns_type in ['NSVEp', 'NSVEparticles']:
if self.parameters['nparticles'] > 0: if self.parameters['nparticles'] > 0:
data = self.generate_tracer_state( data = self.generate_tracer_state(
species = 0, species = 0,
......
...@@ -80,7 +80,8 @@ class _base(object): ...@@ -80,7 +80,8 @@ class _base(object):
template_prefix = '', template_prefix = '',
file_group = 'parameters', file_group = 'parameters',
just_declaration = False, just_declaration = False,
simname_variable = 'simname'): simname_variable = 'simname',
prepend_this = False):
if type(parameters) == type(None): if type(parameters) == type(None):
parameters = self.parameters parameters = self.parameters
key = sorted(list(parameters.keys())) key = sorted(list(parameters.keys()))
...@@ -98,19 +99,22 @@ class _base(object): ...@@ -98,19 +99,22 @@ class _base(object):
'char *string_data;\n' + 'char *string_data;\n' +
'sprintf(fname, "%s.h5", {0});\n'.format(simname_variable) + 'sprintf(fname, "%s.h5", {0});\n'.format(simname_variable) +
'parameter_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);\n') 'parameter_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);\n')
key_prefix = ''
if prepend_this:
key_prefix = 'this->'
for i in range(len(key)): for i in range(len(key)):
src_txt += 'dset = H5Dopen(parameter_file, "/{0}/{1}", H5P_DEFAULT);\n'.format( src_txt += 'dset = H5Dopen(parameter_file, "/{0}/{1}", H5P_DEFAULT);\n'.format(
file_group, key[i]) file_group, key[i])
if (type(parameters[key[i]]) == int and parameters[key[i]] >= 1<<30): if (type(parameters[key[i]]) == int and parameters[key[i]] >= 1<<30):
src_txt += 'H5Dread(dset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key[i]) src_txt += 'H5Dread(dset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key_prefix + key[i])
elif type(parameters[key[i]]) == int: elif type(parameters[key[i]]) == int:
src_txt += 'H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key[i]) src_txt += 'H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key_prefix + key[i])
elif type(parameters[key[i]]) == str: elif type(parameters[key[i]]) == str:
src_txt += ('space = H5Dget_space(dset);\n' + src_txt += ('space = H5Dget_space(dset);\n' +
'memtype = H5Dget_type(dset);\n' + 'memtype = H5Dget_type(dset);\n' +
'string_data = (char*)malloc(256);\n' + 'string_data = (char*)malloc(256);\n' +
'H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string_data);\n' + 'H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string_data);\n' +
'sprintf({0}, "%s", string_data);\n'.format(key[i]) + 'sprintf({0}, "%s", string_data);\n'.format(key_prefix + key[i]) +
'free(string_data);\n' 'free(string_data);\n'
'H5Sclose(space);\n' + 'H5Sclose(space);\n' +
'H5Tclose(memtype);\n') 'H5Tclose(memtype);\n')
...@@ -120,9 +124,9 @@ class _base(object): ...@@ -120,9 +124,9 @@ class _base(object):
elif parameters[key[i]].dtype == np.float64: elif parameters[key[i]].dtype == np.float64:
template_par = 'double' template_par = 'double'
src_txt += '{0} = read_vector<{1}>(parameter_file, "/{2}/{0}");\n'.format( src_txt += '{0} = read_vector<{1}>(parameter_file, "/{2}/{0}");\n'.format(
key[i], template_par, file_group) key_prefix + key[i], template_par, file_group)
else: else:
src_txt += 'H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key[i]) src_txt += 'H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &{0});\n'.format(key_prefix + key[i])
src_txt += 'H5Dclose(dset);\n' src_txt += 'H5Dclose(dset);\n'
src_txt += 'H5Fclose(parameter_file);\n' src_txt += 'H5Fclose(parameter_file);\n'
src_txt += 'return 0;\n}\n' # finishing read_parameters src_txt += 'return 0;\n}\n' # finishing read_parameters
......
...@@ -69,7 +69,7 @@ class NSVE: public direct_numerical_simulation ...@@ -69,7 +69,7 @@ class NSVE: public direct_numerical_simulation
int step(void); int step(void);
int finalize(void); int finalize(void);
int read_parameters(void); virtual int read_parameters(void);
int write_checkpoint(void); int write_checkpoint(void);
int do_stats(void); int do_stats(void);
}; };
......
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