test_turtle_NSVEparticles.py 4.24 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                  #
#                                                                     #
Cristian Lalescu's avatar
Cristian Lalescu committed
7
#  This file is part of TurTLE.                                       #
8
#                                                                     #
Cristian Lalescu's avatar
Cristian Lalescu committed
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.                             #
#                                                                     #
Cristian Lalescu's avatar
Cristian Lalescu committed
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  #
Cristian Lalescu's avatar
Cristian Lalescu committed
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

Cristian Lalescu's avatar
Cristian 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
Cristian Lalescu's avatar
Cristian 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
Cristian Lalescu's avatar
Cristian Lalescu committed
55
56
    c = DNS()
    c.launch(
57
58
            ['NSVEparticles',
             '-n', '32',
Cristian Lalescu's avatar
Cristian Lalescu committed
59
             '--src-simname', 'B32p1e4',
60
             '--src-wd', TurTLE.data_dir,
Cristian Lalescu's avatar
Cristian Lalescu committed
61
             '--src-iteration', '0',
62
63
64
             '--simname', 'dns_nsveparticles',
             '--np', '4',
             '--ntpp', '1',
Cristian Lalescu's avatar
Cristian Lalescu committed
65
             '--fftw_plan_rigor', 'FFTW_PATIENT',
66
67
68
69
70
71
             '--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',
Cristian Lalescu's avatar
Cristian Lalescu committed
72
             '--cpp_random_particles', '0',
73
             '--njobs', '{0}'.format(njobs),
Cristian Lalescu's avatar
Cristian Lalescu committed
74
75
76
77
             '--wd', './'] +
             sys.argv[1:])
    f0 = h5py.File(
            os.path.join(
78
                TurTLE.data_dir,
Cristian Lalescu's avatar
Cristian Lalescu committed
79
                'B32p1e4_checkpoint_0.h5'),
Cristian Lalescu's avatar
Cristian 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)][...]
Cristian Lalescu's avatar
Cristian 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)][...]
Cristian Lalescu's avatar
Cristian 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)][...]
Cristian Lalescu's avatar
Cristian Lalescu committed
91
        rhs_error = np.max(np.abs(y0 - y1))
92
        print(field_error, traj_error, rhs_error)
Cristian Lalescu's avatar
Cristian Lalescu committed
93
94
95
        assert(field_error < 1e-5)
        assert(traj_error < 1e-5)
        assert(rhs_error < 1e-5)
Cristian Lalescu's avatar
Cristian Lalescu committed
96
    print('SUCCESS! Basic test passed.')
97
98
99
100
101
    return None

if __name__ == '__main__':
    main()