FluidConvert.py 4.61 KB
Newer Older
Chichi Lalescu's avatar
Chichi Lalescu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#######################################################################
#                                                                     #
#  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                                 #
#                                                                     #
#######################################################################


26
27
28
29

import numpy as np
import pickle
import os
30
from ._fluid_base import _fluid_particle_base
31
import bfps
32

33
class FluidConvert(_fluid_particle_base):
34
35
36
37
38
    """This class is meant to be used for conversion of native DNS field
    representations to real-space representations of velocity/vorticity
    fields.
    It may be superseeded by streamlined functionality in the future...
    """
39
40
    def __init__(
            self,
41
            name = 'FluidConvert-v' + bfps.__version__,
42
            work_dir = './',
43
            simname = 'test',
44
45
            fluid_precision = 'single',
            use_fftw_wisdom = True):
46
47
        _fluid_particle_base.__init__(
                self,
48
                name = name + '-' + fluid_precision,
49
                work_dir = work_dir,
50
                simname = simname,
51
52
                dtype = fluid_precision,
                use_fftw_wisdom = use_fftw_wisdom)
53
54
55
56
57
58
59
60
61
        self.parameters['write_rvelocity']  = 1
        self.parameters['write_rvorticity'] = 1
        self.parameters['fluid_name'] = 'test'
        self.fill_up_fluid_code()
        self.finalize_code()
        return None
    def fill_up_fluid_code(self):
        self.fluid_includes += '#include <cstring>\n'
        self.fluid_variables += ('double t;\n' +
62
                                 'fluid_solver<{0}> *fs;\n').format(self.C_dtype)
63
64
        self.fluid_definitions += """
                //begincpp
65
                void do_conversion(fluid_solver<{0}> *bla)
66
                {{
67
68
69
70
71
                    bla->read('v', 'c');
                    if (write_rvelocity)
                        bla->write('u', 'r');
                    if (write_rvorticity)
                        bla->write('v', 'r');
72
                }}
73
                //endcpp
74
                """.format(self.C_dtype)
75
76
        self.fluid_start += """
                //begincpp
77
                fs = new fluid_solver<{0}>(
78
79
80
                        fluid_name,
                        nx, ny, nz,
                        dkx, dky, dkz);
Chichi Lalescu's avatar
Chichi Lalescu committed
81
                fs->iteration = iteration;
82
83
                do_conversion(fs);
                //endcpp
84
                """.format(self.C_dtype)
85
86
87
88
89
90
91
        self.fluid_loop += """
                //begincpp
                fs->iteration++;
                if (fs->iteration % niter_out == 0)
                    do_conversion(fs);
                //endcpp
                """
Chichi Lalescu's avatar
Chichi Lalescu committed
92
        self.fluid_end += 'delete fs;\n'
93
        return None
94
    def specific_parser_arguments(
95
96
            self,
            parser):
97
        _fluid_particle_base.specific_parser_arguments(self, parser)
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        parser.add_argument(
                '--src-wd',
                type = str,
                dest = 'src_work_dir',
                default = './')
        parser.add_argument(
                '--src-simname',
                type = str,
                dest = 'src_simname',
                default = '')
        parser.add_argument(
                '--src-iteration',
                type = int,
                dest = 'src_iteration',
                default = 0)
        return None
114