fluid_resize.py 4.6 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 bfps
import bfps.fluid_base

30
31
import numpy as np

32
33
34
class fluid_resize(bfps.fluid_base.fluid_particle_base):
    def __init__(
            self,
35
            name = 'fluid_resize',
36
            work_dir = './',
37
            simname = 'test',
38
39
            dtype = np.float32,
            use_fftw_wisdom = False):
40
41
42
        super(fluid_resize, self).__init__(
                name = name,
                work_dir = work_dir,
43
                simname = simname,
44
45
                dtype = dtype,
                use_fftw_wisdom = use_fftw_wisdom)
46
        self.parameters['src_simname'] = 'test'
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        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
62
                                 'fluid_solver<' + self.C_dtype + '> *fs0, *fs1;\n')
63
64
65
        self.fluid_start += """
                //begincpp
                char fname[512];
66
                fs0 = new fluid_solver<{0}>(
67
                        src_simname,
68
69
                        nx, ny, nz,
                        dkx, dky, dkz);
70
                fs1 = new fluid_solver<{0}>(
71
72
73
                        dst_simname,
                        dst_nx, dst_ny, dst_nz,
                        dst_dkx, dst_dky, dst_dkz);
Chichi Lalescu's avatar
Chichi Lalescu committed
74
                fs0->iteration = iteration;
75
                fs1->iteration = 0;
76
                DEBUG_MSG("about to read field\\n");
77
                fs0->read('v', 'c');
78
                DEBUG_MSG("field read, about to copy data\\n");
79
                double a, b;
80
                fs0->compute_velocity(fs0->cvorticity);
81
82
                a = 0.5*fs0->autocorrel(fs0->cvelocity);
                b = 0.5*fs0->autocorrel(fs0->cvorticity);
83
                DEBUG_MSG("old field %d %g %g\\n", fs0->iteration, a, b);
84
85
86
                copy_complex_array<{0}>(fs0->cd, fs0->cvorticity,
                                        fs1->cd, fs1->cvorticity,
                                        3);
87
                DEBUG_MSG("data copied, about to write new field\\n");
88
                fs1->write('v', 'c');
89
90
                DEBUG_MSG("finished writing\\n");
                fs1->compute_velocity(fs1->cvorticity);
91
92
                a = 0.5*fs1->autocorrel(fs1->cvelocity);
                b = 0.5*fs1->autocorrel(fs1->cvorticity);
93
94
                DEBUG_MSG("new field %d %g %g\\n", fs1->iteration, a, b);
                //endcpp
Chichi Lalescu's avatar
Chichi Lalescu committed
95
                """.format(self.C_dtype)
96
97
98
99
100
101
102
103
        self.fluid_end += """
                //begincpp
                delete fs0;
                delete fs1;
                //endcpp
                """
        return None