NSVE_field_stats.cpp 5.76 KB
Newer Older
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 2019 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                                         *
*                                                                             *
******************************************************************************/



Cristian Lalescu's avatar
Cristian Lalescu committed
26
27
28
#include <string>
#include <cmath>
#include "NSVE_field_stats.hpp"
29
#include "fftw_tools.hpp"
Cristian Lalescu's avatar
Cristian Lalescu committed
30
31
32
33
34
35
#include "scope_timer.hpp"


template <typename rnumber>
int NSVE_field_stats<rnumber>::initialize(void)
{
36
    TIMEZONE("NSVE_field_stats::initialize");
Cristian Lalescu's avatar
Cristian Lalescu committed
37
38
39
40
    this->postprocess::read_parameters();
    this->vorticity = new field<rnumber, FFTW, THREE>(
            nx, ny, nz,
            this->comm,
Cristian Lalescu's avatar
Cristian Lalescu committed
41
            fftw_planner_string_to_flag[this->fftw_plan_rigor]);
Cristian Lalescu's avatar
Cristian Lalescu committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    this->vorticity->real_space_representation = false;
    hid_t parameter_file = H5Fopen(
            (this->simname + std::string(".h5")).c_str(),
            H5F_ACC_RDONLY,
            H5P_DEFAULT);
    if (!H5Lexists(parameter_file, "field_dtype", H5P_DEFAULT))
        this->bin_IO = NULL;
    else
    {
        hid_t dset = H5Dopen(parameter_file, "field_dtype", H5P_DEFAULT);
        hid_t space = H5Dget_space(dset);
        hid_t memtype = H5Dget_type(dset);
        char *string_data = (char*)malloc(256);
        H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string_data);
        // check that we're using the correct data type
        // field_dtype SHOULD be something like "<f4", "<f8", ">f4", ">f8"
        // first character is ordering, which is machine specific
        // for the other two I am checking that they have the correct values
        assert(string_data[1] == 'f');
        assert(string_data[2] == '0' + sizeof(rnumber));
        free(string_data);
        H5Sclose(space);
        H5Tclose(memtype);
        H5Dclose(dset);
        this->bin_IO = new field_binary_IO<rnumber, COMPLEX, THREE>(
                this->vorticity->clayout->sizes,
                this->vorticity->clayout->subsizes,
                this->vorticity->clayout->starts,
                this->vorticity->clayout->comm);
    }
Cristian Lalescu's avatar
Cristian Lalescu committed
72
    this->fftw_plan_rigor = hdf5_tools::read_string(parameter_file, "parameters/fftw_plan_rigor");
Cristian Lalescu's avatar
Cristian Lalescu committed
73
74
75
76
77
78
79
    H5Fclose(parameter_file);
    return EXIT_SUCCESS;
}

template <typename rnumber>
int NSVE_field_stats<rnumber>::read_current_cvorticity(void)
{
80
    TIMEZONE("NSVE_field_stats::read_current_cvorticity");
Cristian Lalescu's avatar
Cristian Lalescu committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    this->vorticity->real_space_representation = false;
    if (this->bin_IO != NULL)
    {
        char itername[16];
        sprintf(itername, "i%.5x", this->iteration);
        std::string native_binary_fname = (
                this->simname +
                std::string("_cvorticity_") +
                std::string(itername));
        this->bin_IO->read(
                native_binary_fname,
                this->vorticity->get_cdata());
    }
    else
    {
        this->vorticity->io(
                this->simname + std::string("_fields.h5"),
                "vorticity",
                this->iteration,
                true);
    }
    return EXIT_SUCCESS;
}
sniklas142's avatar
sniklas142 committed
104
template <typename rnumber>
sniklas142's avatar
sniklas142 committed
105
int NSVE_field_stats<rnumber>::read_arbitrary_cvorticity(int arbitrary_iteration)
sniklas142's avatar
sniklas142 committed
106
107
108
109
110
111
{
    TIMEZONE("NSVE_field_stats::read_arbitrary_cvorticity");
    this->vorticity->real_space_representation = false;
    if (this->bin_IO != NULL)
    {
        char itername[16];
sniklas142's avatar
sniklas142 committed
112
        sprintf(itername, "i%.5x", arbitrary_iteration);
sniklas142's avatar
sniklas142 committed
113
114
115
116
117
118
119
120
121
122
123
124
125
        std::string native_binary_fname = (
                this->simname +
                std::string("_cvorticity_") +
                std::string(itername));
        this->bin_IO->read(
                native_binary_fname,
                this->vorticity->get_cdata());
    }
    else
    {
        this->vorticity->io(
                this->simname + std::string("_fields.h5"),
                "vorticity",
sniklas142's avatar
sniklas142 committed
126
                arbitrary_iteration,
sniklas142's avatar
sniklas142 committed
127
128
129
130
                true);
    }
    return EXIT_SUCCESS;
}
Cristian Lalescu's avatar
Cristian Lalescu committed
131
132
133
134

template <typename rnumber>
int NSVE_field_stats<rnumber>::finalize(void)
{
135
    TIMEZONE("NSVE_field_stats::finalize");
Cristian Lalescu's avatar
Cristian Lalescu committed
136
137
138
139
140
141
142
143
144
    if (this->bin_IO != NULL)
        delete this->bin_IO;
    delete this->vorticity;
    return EXIT_SUCCESS;
}

template <typename rnumber>
int NSVE_field_stats<rnumber>::work_on_current_iteration(void)
{
145
    TIMEZONE("NSVE_field_stats::work_on_current_iteration");
Cristian Lalescu's avatar
Cristian Lalescu committed
146
147
148
149
150
151
    return EXIT_SUCCESS;
}

template class NSVE_field_stats<float>;
template class NSVE_field_stats<double>;