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