test_turtle_NSVEparticles.py 4.22 KB
Newer Older
Cristian Lalescu's avatar
Cristian Lalescu committed
1
#! /usr/bin/env python
2
3
4
5
6
#######################################################################
#                                                                     #
#  Copyright 2019 Max Planck Institute                                #
#                 for Dynamics and Self-Organization                  #
#                                                                     #
7
#  This file is part of TurTLE.                                         #
8
#                                                                     #
9
#  TurTLE is free software: you can redistribute it and/or modify       #
10
11
12
13
#  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.                             #
#                                                                     #
14
#  TurTLE is distributed in the hope that it will be useful,            #
15
16
17
18
19
#  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  #
20
#  along with TurTLE.  If not, see <http://www.gnu.org/licenses/>       #
21
22
23
24
25
26
#                                                                     #
# Contact: Cristian.Lalescu@ds.mpg.de                                 #
#                                                                     #
#######################################################################


Cristian Lalescu's avatar
Cristian Lalescu committed
27

Chichi Lalescu's avatar
Chichi Lalescu committed
28
import os
29
30
import numpy as np
import h5py
31
import sys
32

33
34
import TurTLE
from TurTLE import DNS
Chichi Lalescu's avatar
Chichi Lalescu committed
35

36
37

def main():
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    """
        Run short DNS, test against archived data.

        This test runs two MPI jobs, generating a short DNS from initial
        conditions stored as python package data.
        This is a full DNS of Navier-Stokes with particles, and we check that
        the new fields, trajectories and velocity sampled along trajectories
        agree to within numerical precision (single precision).

        Implicitly, this checks that the entire compilation mechanism is set
        up properly, as well as the correctness of the code.
        4 MPI processes with one OpenMP thread per process are used by default,
        but this may be changed with command line parameters as desired.
    """
52
53
    niterations = 32
    nparticles = 10000
54
    njobs = 2
Chichi Lalescu's avatar
Chichi Lalescu committed
55
56
    c = DNS()
    c.launch(
57
58
            ['NSVEparticles',
             '-n', '32',
Cristian Lalescu's avatar
Cristian Lalescu committed
59
             '--src-simname', 'B32p1e4',
Cristian Lalescu's avatar
Cristian Lalescu committed
60
             '--forcing_type', 'linear',
61
             '--src-wd', TurTLE.lib_dir + '/test',
Chichi Lalescu's avatar
Chichi Lalescu committed
62
             '--src-iteration', '0',
63
64
65
             '--simname', 'dns_nsveparticles',
             '--np', '4',
             '--ntpp', '1',
Cristian Lalescu's avatar
Cristian Lalescu committed
66
             '--fftw_plan_rigor', 'FFTW_PATIENT',
67
68
69
70
71
72
73
             '--niter_todo', '{0}'.format(niterations),
             '--niter_out', '{0}'.format(niterations),
             '--niter_stat', '1',
             '--checkpoints_per_file', '{0}'.format(3),
             '--nparticles', '{0}'.format(nparticles),
             '--particle-rand-seed', '2',
             '--njobs', '{0}'.format(njobs),
Chichi Lalescu's avatar
Chichi Lalescu committed
74
75
76
77
             '--wd', './'] +
             sys.argv[1:])
    f0 = h5py.File(
            os.path.join(
78
                os.path.join(TurTLE.lib_dir, 'test'),
Cristian Lalescu's avatar
Cristian Lalescu committed
79
                'B32p1e4_checkpoint_0.h5'),
Chichi Lalescu's avatar
Chichi Lalescu committed
80
81
82
            'r')
    f1 = h5py.File(c.get_checkpoint_0_fname(), 'r')
    for iteration in [0, 32, 64]:
83
84
        field0 = f0['vorticity/complex/{0}'.format(iteration)][...]
        field1 = f1['vorticity/complex/{0}'.format(iteration)][...]
Chichi Lalescu's avatar
Chichi Lalescu committed
85
        field_error = np.max(np.abs(field0 - field1))
86
87
        x0 = f0['tracers0/state/{0}'.format(iteration)][...]
        x1 = f1['tracers0/state/{0}'.format(iteration)][...]
Chichi Lalescu's avatar
Chichi Lalescu committed
88
        traj_error = np.max(np.abs(x0 - x1))
89
90
        y0 = f0['tracers0/rhs/{0}'.format(iteration)][...]
        y1 = f1['tracers0/rhs/{0}'.format(iteration)][...]
Chichi Lalescu's avatar
Chichi Lalescu committed
91
92
93
94
        rhs_error = np.max(np.abs(y0 - y1))
        assert(field_error < 1e-5)
        assert(traj_error < 1e-5)
        assert(rhs_error < 1e-5)
Chichi Lalescu's avatar
Chichi Lalescu committed
95
    print('SUCCESS! Basic test passed.')
96
97
98
99
100
    return None

if __name__ == '__main__':
    main()