FluidResize.py 5.16 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
from ._fluid_base import _fluid_particle_base
28

29
30
import numpy as np

31
class FluidResize(_fluid_particle_base):
32
33
34
35
    """This class is meant to resize snapshots of DNS states to new grids.
    Typical stuff for DNS of turbulence.
    It will become superfluous when HDF5 is used for field I/O.
    """
36
37
    def __init__(
            self,
38
            name = 'FluidResize',
39
            work_dir = './',
40
            simname = 'test',
41
42
            dtype = np.float32,
            use_fftw_wisdom = False):
43
44
        _fluid_particle_base.__init__(
                self,
45
46
                name = name,
                work_dir = work_dir,
47
                simname = simname,
48
49
                dtype = dtype,
                use_fftw_wisdom = use_fftw_wisdom)
50
        self.parameters['src_simname'] = 'test'
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        self.parameters['dst_iter'] = 0
        self.parameters['dst_nx'] = 32
        self.parameters['dst_ny'] = 32
        self.parameters['dst_nz'] = 32
        self.parameters['dst_simname'] = 'new_test'
        self.parameters['dst_dkx'] = 1.0
        self.parameters['dst_dky'] = 1.0
        self.parameters['dst_dkz'] = 1.0
        self.fill_up_fluid_code()
        self.finalize_code()
        return None
    def fill_up_fluid_code(self):
        self.fluid_includes += '#include <cstring>\n'
        self.fluid_includes += '#include "fftw_tools.hpp"\n'
        self.fluid_variables += ('double t;\n' +
Chichi Lalescu's avatar
Chichi Lalescu committed
66
                                 'fluid_solver<' + self.C_dtype + '> *fs0, *fs1;\n')
67
68
69
        self.fluid_start += """
                //begincpp
                char fname[512];
70
                fs0 = new fluid_solver<{0}>(
71
                        src_simname,
72
73
                        nx, ny, nz,
                        dkx, dky, dkz);
74
                fs1 = new fluid_solver<{0}>(
75
76
77
                        dst_simname,
                        dst_nx, dst_ny, dst_nz,
                        dst_dkx, dst_dky, dst_dkz);
Chichi Lalescu's avatar
Chichi Lalescu committed
78
                fs0->iteration = iteration;
79
                fs1->iteration = 0;
80
                DEBUG_MSG("about to read field\\n");
81
                fs0->read('v', 'c');
82
                DEBUG_MSG("field read, about to copy data\\n");
83
                double a, b;
84
                fs0->compute_velocity(fs0->cvorticity);
85
86
                a = 0.5*fs0->autocorrel(fs0->cvelocity);
                b = 0.5*fs0->autocorrel(fs0->cvorticity);
87
                DEBUG_MSG("old field %d %g %g\\n", fs0->iteration, a, b);
88
89
90
                copy_complex_array<{0}>(fs0->cd, fs0->cvorticity,
                                        fs1->cd, fs1->cvorticity,
                                        3);
91
                DEBUG_MSG("data copied, about to write new field\\n");
92
                fs1->write('v', 'c');
93
94
                DEBUG_MSG("finished writing\\n");
                fs1->compute_velocity(fs1->cvorticity);
95
96
                a = 0.5*fs1->autocorrel(fs1->cvelocity);
                b = 0.5*fs1->autocorrel(fs1->cvorticity);
97
98
                DEBUG_MSG("new field %d %g %g\\n", fs1->iteration, a, b);
                //endcpp
Chichi Lalescu's avatar
Chichi Lalescu committed
99
                """.format(self.C_dtype)
100
101
102
103
104
105
106
        self.fluid_end += """
                //begincpp
                delete fs0;
                delete fs1;
                //endcpp
                """
        return None
107
    def specific_parser_arguments(
108
109
            self,
            parser):
110
        _fluid_particle_base.specific_parser_arguments(self, parser)
111
        parser.add_argument(
112
                '-N',
113
                type = int,
114
                dest = 'N',
115
                default = 32,
116
117
                metavar = 'M',
                help = 'resize from N to M')
118
        return None
119