Commit 80f8280b authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

improve modularity of DNS class

parent 57770e6b
...@@ -60,84 +60,87 @@ class DNS(_code): ...@@ -60,84 +60,87 @@ class DNS(_code):
self.rtype = self.fluid_dtype self.rtype = self.fluid_dtype
if self.rtype == np.float32: if self.rtype == np.float32:
self.ctype = np.dtype(np.complex64) self.ctype = np.dtype(np.complex64)
self.C_dtype = 'float' self.C_field_dtype = 'float'
elif self.rtype == np.float64: elif self.rtype == np.float64:
self.ctype = np.dtype(np.complex128) self.ctype = np.dtype(np.complex128)
self.C_dtype = 'double' self.C_field_dtype = 'double'
if self.dns_type == 'NSVE':
self.parameters['dealias_type'] = 1
self.parameters['dkx'] = 1.0
self.parameters['dky'] = 1.0
self.parameters['dkz'] = 1.0
self.parameters['niter_todo'] = 8
self.parameters['niter_part'] = 1
self.parameters['niter_stat'] = 1
self.parameters['niter_out'] = 1024
self.parameters['nparticles'] = 0
self.parameters['dt'] = 0.01
self.parameters['nu'] = float(0.1)
self.parameters['fmode'] = 1
self.parameters['famplitude'] = float(0.5)
self.parameters['fk0'] = float(2.0)
self.parameters['fk1'] = float(4.0)
self.parameters['forcing_type'] = 'linear'
self.parameters['histogram_bins'] = int(256)
self.parameters['max_velocity_estimate'] = float(1)
self.parameters['max_vorticity_estimate'] = float(1)
self.parameters['checkpoints_per_file'] = int(1)
self.version_message = ( self.version_message = (
'/***********************************************************************\n' + '/***********************************************************************\n' +
'* this code automatically generated by bfps\n' + '* this code automatically generated by bfps\n' +
'* version {0}\n'.format(bfps.__version__) + '* version {0}\n'.format(bfps.__version__) +
'***********************************************************************/\n\n\n') '***********************************************************************/\n\n\n')
self.includes = """ self.include_list = [
//begincpp '"base.hpp"',
#include "base.hpp" '"scope_timer.hpp"',
#include "scope_timer.hpp" '"fftw_interface.hpp"',
#include "fftw_interface.hpp" '"full_code/main_code.hpp"',
#include "full_code/main_code.hpp" '<iostream>',
#include <iostream> '<hdf5.h>',
#include <hdf5.h> '<string>',
#include <string> '<cstring>',
#include <cstring> '<fftw3-mpi.h>',
#include <fftw3-mpi.h> '<omp.h>',
#include <omp.h> '<cfenv>',
#include <cfenv> '<cstdlib>',
#include <cstdlib> '"full_code/{0}.hpp"\n'.format(self.dns_type)]
//endcpp
"""
self.includes += '#include "full_code/{0}.hpp"\n'.format(self.dns_type)
self.variables = ''
self.definitions = ''
self.main = """ self.main = """
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{{ {{
bool fpe = ( bool fpe = (
(getenv("BFPS_FPE_OFF") == nullptr) || (getenv("BFPS_FPE_OFF") == nullptr) ||
(getenv("BFPS_FPE_OFF") != std::string("TRUE"))); (getenv("BFPS_FPE_OFF") != std::string("TRUE")));
return main_code<{0}>(argc, argv, fpe); return main_code< {0} >(argc, argv, fpe);
}} }}
""".format(self.dns_type + '<{0}>'.format(self.C_dtype)) """.format(self.dns_type + '<{0}>'.format(self.C_field_dtype))
self.host_info = {'type' : 'cluster', self.host_info = {'type' : 'cluster',
'environment' : None, 'environment' : None,
'deltanprocs' : 1, 'deltanprocs' : 1,
'queue' : '', 'queue' : '',
'mail_address': '', 'mail_address': '',
'mail_events' : None} 'mail_events' : None}
self.generate_default_parameters()
return None
def generate_default_parameters(self):
# these parameters are relevant for all DNS classes
self.parameters['dealias_type'] = 1
self.parameters['dkx'] = 1.0
self.parameters['dky'] = 1.0
self.parameters['dkz'] = 1.0
self.parameters['niter_todo'] = 8
self.parameters['niter_stat'] = 1
self.parameters['niter_out'] = 8
self.parameters['checkpoints_per_file'] = int(1)
self.parameters['dt'] = 0.01
self.parameters['nu'] = float(0.1)
self.parameters['fmode'] = 1
self.parameters['famplitude'] = float(0.5)
self.parameters['fk0'] = float(2.0)
self.parameters['fk1'] = float(4.0)
self.parameters['forcing_type'] = 'linear'
self.parameters['histogram_bins'] = int(256)
self.parameters['max_velocity_estimate'] = float(1)
self.parameters['max_vorticity_estimate'] = float(1)
# parameters specific to particle version
if self.dns_type == 'NSVEp':
self.parameters['niter_part'] = 1
self.parameters['nparticles'] = 0
return None return None
def write_src(self): def write_src(self):
self.includes = '\n'.join(
['#include ' + hh
for hh in self.include_list])
with open(self.name + '.cpp', 'w') as outfile: with open(self.name + '.cpp', 'w') as outfile:
outfile.write(self.version_message) outfile.write(self.version_message + '\n\n')
outfile.write(self.includes) outfile.write(self.includes + '\n\n')
outfile.write(self.cread_pars( outfile.write(self.cread_pars(
template_class = 'NSVE<rnumber>::', template_class = '{0}<rnumber>::'.format(self.dns_type),
template_prefix = 'template <typename rnumber> ', template_prefix = 'template <typename rnumber> ',
simname_variable = 'simname.c_str()')) simname_variable = 'simname.c_str()') + '\n\n')
for rnumber in ['float', 'double']: for rnumber in ['float', 'double']:
outfile.write(self.cread_pars( outfile.write(self.cread_pars(
template_class = 'NSVE<{0}>::'.format(rnumber), template_class = '{0}<{1}>::'.format(self.dns_type, rnumber),
template_prefix = 'template '.format(rnumber), template_prefix = 'template '.format(rnumber),
just_declaration = True)) just_declaration = True) + '\n\n')
outfile.write(self.main) outfile.write(self.main + '\n')
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