Commit 57bf7ed4 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

add new wrapper

parent 7f9cf2c4
#######################################################################
# #
# Copyright 2015 Max Planck Institute #
# for Dynamics and Self-Organization #
# #
# This file is part of bfps. #
# #
# bfps is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published #
# by the Free Software Foundation, either version 3 of the License, #
# or (at your option) any later version. #
# #
# bfps is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with bfps. If not, see <http://www.gnu.org/licenses/> #
# #
# Contact: Cristian.Lalescu@ds.mpg.de #
# #
#######################################################################
import os
import sys
import shutil
import subprocess
import argparse
import h5py
import math
import numpy as np
import warnings
import bfps
from ._code import _code
class DNS(_code):
"""This class is meant to stitch together the C++ code into a final source file,
compile it, and handle all job launching.
"""
def __init__(
self,
work_dir = './',
simname = 'test',
dns_type = 'NSVE',
fluid_dtype = 'single'):
_code.__init__(self, work_dir = work_dir, simname = simname)
self.dns_type = dns_type
self.name = self.dns_type + '-v' + bfps.__version__
if fluid_dtype in [np.float32, np.float64]:
self.fluid_dtype = fluid_dtype
elif fluid_dtype in ['single', 'double']:
if fluid_dtype == 'single':
self.fluid_dtype = np.dtype(np.float32)
elif fluid_dtype == 'double':
self.fluid_dtype = np.dtype(np.float64)
self.rtype = self.fluid_dtype
if self.rtype == np.float32:
self.ctype = np.dtype(np.complex64)
self.C_dtype = 'float'
elif self.rtype == np.float64:
self.ctype = np.dtype(np.complex128)
self.C_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 = (
'/***********************************************************************\n' +
'* this code automatically generated by bfps\n' +
'* version {0}\n'.format(bfps.__version__) +
'***********************************************************************/\n\n\n')
self.includes = """
//begincpp
#include "base.hpp"
#include "scope_timer.hpp"
#include "fftw_interface.hpp"
#include "full_code/main_code.hpp"
#include <iostream>
#include <hdf5.h>
#include <string>
#include <cstring>
#include <fftw3-mpi.h>
#include <omp.h>
#include <cfenv>
#include <cstdlib>
//endcpp
"""
self.includes += '#include "full_code/{0}.hpp"\n'.format(self.dns_type)
self.variables = ''
self.definitions = ''
self.main = """
int main(int argc, char *argv[])
{{
bool fpe = (
(getenv("BFPS_FPE_OFF") == nullptr) ||
(getenv("BFPS_FPE_OFF") != std::string("TRUE")));
return main_code<{0}>(argc, argv, fpe);
}}
""".format(self.dns_type + '<{0}>'.format(self.C_dtype))
self.host_info = {'type' : 'cluster',
'environment' : None,
'deltanprocs' : 1,
'queue' : '',
'mail_address': '',
'mail_events' : None}
return None
def write_src(self):
with open(self.name + '.cpp', 'w') as outfile:
outfile.write(self.version_message)
outfile.write(self.includes)
outfile.write(self.cread_pars(
template_class = 'NSVE<rnumber>::',
template_prefix = 'template <typename rnumber> ',
simname_variable = 'simname.c_str()'))
for rnumber in ['float', 'double']:
outfile.write(self.cread_pars(
template_class = 'NSVE<{0}>::'.format(rnumber),
template_prefix = 'template '.format(rnumber),
just_declaration = True))
outfile.write(self.main)
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