OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
FM3DH5BlockBase.h
Go to the documentation of this file.
1//
2// Class FM3DH5BlockBase
3// Base class for 3D field-maps in stored in H5hut files.
4//
5// Copyright (c) 2020, Achim Gsell, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved.
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18
19#ifndef CLASSIC_FIELDMAP3DH5BLOCKBASE_H
20#define CLASSIC_FIELDMAP3DH5BLOCKBASE_H
21
22#include "Fields/Fieldmap.h"
23#include <vector>
24
25#include "H5hut.h"
26static_assert (sizeof(double) == sizeof (h5_float64_t),
27 "double and h5_float64_t are not the same type" );
28static_assert (sizeof(long long) == sizeof (h5_int64_t),
29 "long long and h5_int64_t are not the same type" );
30
31class FM3DH5BlockBase: virtual public Fieldmap {
32
33public:
34 virtual void readMap (
35 ) {};
36
37 virtual void freeMap (
38 ) {};
39
40 virtual bool getFieldstrength (
41 const Vector_t& /*R*/, Vector_t& /*E*/, Vector_t& /*B*/) const = 0;
42
43 virtual void getFieldDimensions (
44 double &zBegin, double &zEnd
45 ) const {
46 zBegin = zbegin_m;
47 zEnd = zend_m;
48 }
49
50 virtual void getFieldDimensions (
51 double &xIni, double &xFinal,
52 double &yIni, double &yFinal,
53 double &zIni, double &zFinal
54 ) const {
55 xIni = xbegin_m;
56 xFinal = xend_m;
57 yIni = ybegin_m;
58 yFinal = yend_m;
59 zIni = zbegin_m;
60 zFinal = zend_m;
61 }
62
63 virtual bool getFieldDerivative (
64 const Vector_t &/*R*/,
65 Vector_t &/*E*/,
66 Vector_t &/*B*/,
67 const DiffDirection &/*dir*/
68 ) const {
69 return false;
70 }
71
72 virtual void swap(
73 ) {};
74
75 virtual void getInfo (
76 Inform *msg);
77
78 virtual double getFrequency (
79 ) const;
80
81 virtual void setFrequency (
82 double freq);
83
84 virtual void getOnaxisEz (
85 std::vector<std::pair<double, double> >& F);
86
87protected:
89 ) {};
90
92 ) {};
93
95 const std::string aFilename);
96
97 long long getNumSteps (
98 void);
99
100 void setStep (
101 const long long);
102
103 void getFieldInfo (
104 const char*);
105
107 void);
108
109 void readField (
110 const char* name,
111 double* x,
112 double* y,
113 double* z
114 );
115
116 void closeFile (
117 void);
118
119 virtual bool isInside (
120 const Vector_t &r
121 ) const {
122 return ((r(0) >= xbegin_m && r(0) < xend_m) &&
123 (r(1) >= ybegin_m && r(1) < yend_m) &&
124 (r(2) >= zbegin_m && r(2) < zend_m));
125 }
126
128 unsigned int i;
129 unsigned int j;
130 unsigned int k;
133 i(0),
134 j(0),
135 k(0),
136 weight(0.0)
137 {}
138 };
139
140 /*
141 The 3-dimensional fieldmaps are stored in a 1-dimensional arrays.
142 Please note that the FORTRAN indexing scheme is used in H5hut!
143
144 This functions maps the 3-dimensional index (i, j, k) to the
145 corresponding index in the 1-dimensional array.
146 */
147 unsigned long getIndex (
148 unsigned int i,
149 unsigned int j,
150 unsigned int k
151 ) const {
152 unsigned long result = j + k * num_gridpy_m;
153 result = i + result * num_gridpx_m;
154
155 return result;
156 }
157
159 IndexTriplet idx;
160 idx.i = std::floor((X(0) - xbegin_m) / hx_m);
161 idx.j = std::floor((X(1) - ybegin_m) / hy_m);
162 idx.k = std::floor((X(2) - zbegin_m) / hz_m);
163 PAssert_LT(idx.i, num_gridpx_m - 1);
164 PAssert_LT(idx.j, num_gridpy_m - 1);
165 PAssert_LT(idx.k, num_gridpz_m - 1);
166
167 idx.weight(0) = (X(0) - xbegin_m) / hx_m - idx.i;
168 idx.weight(1) = (X(1) - ybegin_m) / hy_m - idx.j;
169 idx.weight(2) = (X(2) - zbegin_m) / hz_m - idx.k;
170
171 return idx;
172 }
173
174 double getWeightedData (
175 const std::vector<double>& data,
176 const IndexTriplet& idx,
177 unsigned short corner) const;
178
180 const std::vector<double>&,
181 const std::vector<double>&,
182 const std::vector<double>&,
183 const Vector_t& X) const;
184
185 enum : unsigned short {
186 LX = 0, // low X
187 LY = 0, // low Y
188 LZ = 0, // low Z
189 HX = 4, // high X
190 HY = 2, // high Y
191 HZ = 1}; // high Z
192
193 h5_file_t file_m;
194 std::vector<double> FieldstrengthEz_m;
195 std::vector<double> FieldstrengthEx_m;
196 std::vector<double> FieldstrengthEy_m;
198 double xbegin_m;
199 double xend_m;
200
201 double ybegin_m;
202 double yend_m;
203
204 double zbegin_m;
205 double zend_m;
206
207 double hx_m;
208 double hy_m;
209 double hz_m;
216
217 bool swap_m;
218 friend class Fieldmap;
219};
220
221#endif
DiffDirection
Definition: Fieldmap.h:54
#define X(arg)
Definition: fftpack.cpp:112
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:733
#define PAssert_LT(a, b)
Definition: PAssert.h:106
const std::string name
virtual void setFrequency(double freq)
void getFieldInfo(const char *)
long long getNumSteps(void)
void openFileMPIOCollective(const std::string aFilename)
unsigned long getIndex(unsigned int i, unsigned int j, unsigned int k) const
virtual ~FM3DH5BlockBase()
std::vector< double > FieldstrengthEz_m
virtual bool isInside(const Vector_t &r) const
virtual double getFrequency() const
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
void setStep(const long long)
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &F)
virtual void swap()
Vector_t interpolateTrilinearly(const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const Vector_t &X) const
virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const
virtual void readMap()
IndexTriplet getIndex(const Vector_t &X) const
double getWeightedData(const std::vector< double > &data, const IndexTriplet &idx, unsigned short corner) const
void getResonanceFrequency(void)
std::vector< double > FieldstrengthEx_m
void readField(const char *name, double *x, double *y, double *z)
virtual void getInfo(Inform *msg)
virtual bool getFieldDerivative(const Vector_t &, Vector_t &, Vector_t &, const DiffDirection &) const
virtual void freeMap()
virtual bool getFieldstrength(const Vector_t &, Vector_t &, Vector_t &) const =0
std::vector< double > FieldstrengthEy_m
Definition: Inform.h:42