FM3DH5Block.cpp 2.83 KB
Newer Older
1
//
gsell's avatar
gsell committed
2 3
// Class FM3DH5Block
//   Class for dynamic 3D field-maps stored in H5hut files.
4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
// Copyright (c) 2020, Achim Gsell, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved.
//
// This file is part of OPAL.
//
// OPAL 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.
//
// You should have received a copy of the GNU General Public License
// along with OPAL.  If not, see <https://www.gnu.org/licenses/>.
//
18

19 20 21
#include "Fields/FM3DH5Block.h"

FM3DH5Block::FM3DH5Block (
22 23
    std::string aFilename
    ) : Fieldmap (
24
        aFilename
25 26
        ) {
        Type = T3DDynamicH5Block;
27

28 29 30 31
        openFileMPIOCollective (aFilename);
        getFieldInfo ("Efield");
        getResonanceFrequency ();
        closeFile ();
gsell's avatar
gsell committed
32 33
}

34 35 36
FM3DH5Block::~FM3DH5Block (
    ) {
    freeMap ();
gsell's avatar
gsell committed
37 38
}

39 40
void FM3DH5Block::readMap (
    ) {
41 42 43
    if (!FieldstrengthEz_m.empty()) {
        return;
    }
44 45 46
    openFileMPIOCollective (Filename_m);
    long long last_step = getNumSteps () - 1;
    setStep (last_step);
47 48 49 50 51 52 53 54 55

    size_t field_size = num_gridpx_m * num_gridpy_m * num_gridpz_m;
    FieldstrengthEx_m.resize (field_size);
    FieldstrengthEy_m.resize (field_size);
    FieldstrengthEz_m.resize (field_size);
    FieldstrengthHx_m.resize (field_size);
    FieldstrengthHy_m.resize (field_size);
    FieldstrengthHz_m.resize (field_size);

56
    readField (
57
        "Efield",
58 59 60
        &(FieldstrengthEx_m[0]),
        &(FieldstrengthEy_m[0]),
        &(FieldstrengthEz_m[0]));
61
    readField (
62
        "Hfield",
63 64 65
        &(FieldstrengthHx_m[0]),
        &(FieldstrengthHy_m[0]),
        &(FieldstrengthHz_m[0]));
66

67
    closeFile ();
68 69 70
    INFOMSG (level3
             << typeset_msg("3d dynamic fieldmap '"
                            + Filename_m  + "' (H5hut format) read", "info")
71
             << endl);
gsell's avatar
gsell committed
72 73
}

74 75 76 77
void FM3DH5Block::freeMap (
    ) {
    if(FieldstrengthEz_m.empty ()) {
        return;
gsell's avatar
gsell committed
78
    }
79 80 81 82 83 84 85
    FieldstrengthEx_m.clear ();
    FieldstrengthEy_m.clear ();
    FieldstrengthEz_m.clear ();
    FieldstrengthHx_m.clear ();
    FieldstrengthHy_m.clear ();
    FieldstrengthHz_m.clear ();

86 87 88
    INFOMSG (level3
             << typeset_msg ("freed fieldmap '" + Filename_m + "'", "info")
             << endl);
gsell's avatar
gsell committed
89 90
}

91 92 93 94 95 96 97
bool FM3DH5Block::getFieldstrength (
    const Vector_t& R,
    Vector_t& E,
    Vector_t& B
    ) const {
    if (!isInside(R)) {
        return true;
gsell's avatar
gsell committed
98
    }
99 100
    E += interpolateTrilinearly (FieldstrengthEx_m, FieldstrengthEy_m, FieldstrengthEz_m, R);
    B += interpolateTrilinearly (FieldstrengthHx_m, FieldstrengthHy_m, FieldstrengthHz_m, R);
gsell's avatar
gsell committed
101 102 103
    return false;
}

104 105
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
106
// mode:c++
107
// c-basic-offset: 4
gsell's avatar
gsell committed
108 109
// indent-tabs-mode: nil
// require-final-newline: nil
110
// End: