OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
FM3DH5Block_nonscale.cpp
Go to the documentation of this file.
1//
2// Class FM3DH5Block_nonscale
3// Class for dynamic non-scaled 3D field-maps 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//
19
20#include "Fields/Fieldmap.h"
21#include "Physics/Physics.h"
22#include "Physics/Units.h"
23
24#include <cstddef>
25
27 const std::string& filename
28 ) : _Fieldmap (
29 filename),
31 ) {
33
34 openFileMPIOCollective (filename);
35 getFieldInfo ("Efield");
37 closeFile ();
38}
39
44
46{
47 return FM3DH5Block_nonscale(new _FM3DH5Block_nonscale(filename));
48}
49
51 ) {
52 if (!FieldstrengthEz_m.empty()) {
53 return;
54 }
56 long long last_step = getNumSteps () - 1;
57 setStep (last_step);
58
59 std::size_t field_size = num_gridpx_m * num_gridpy_m * num_gridpz_m;
60 FieldstrengthEx_m.allocate (field_size);
61 FieldstrengthEy_m.allocate (field_size);
62 FieldstrengthEz_m.allocate (field_size);
63 FieldstrengthHx_m.allocate (field_size);
64 FieldstrengthHy_m.allocate (field_size);
65 FieldstrengthHz_m.allocate (field_size);
66
67 readField (
68 "Efield",
72 readField (
73 "Hfield",
77
78 closeFile ();
79
80 // This class rescales the samples in place, so it always owns its buffers and is
81 // never backed by a read-only mapping of the file.
82 double* ex = FieldstrengthEx_m.mutableData();
83 double* ey = FieldstrengthEy_m.mutableData();
84 double* ez = FieldstrengthEz_m.mutableData();
85 double* hx = FieldstrengthHx_m.mutableData();
86 double* hy = FieldstrengthHy_m.mutableData();
87 double* hz = FieldstrengthHz_m.mutableData();
88
89 const double muFactor = 1.0e6 * Physics::mu_0;
90 for (long long unsigned i = 0; i < num_gridpx_m * num_gridpy_m * num_gridpz_m; i++) {
91 ez[i] *= Units::MVpm2Vpm ;
92 ex[i] *= Units::MVpm2Vpm ;
93 ey[i] *= Units::MVpm2Vpm ;
94 hx[i] *= muFactor ;
95 hy[i] *= muFactor ;
96 hz[i] *= muFactor ;
97 }
99 << typeset_msg("3d dynamic (non-scaled) fieldmap '"
100 + Filename_m + "' (H5hut format) read", "info")
101 << endl);
102}
103
116
118 const Vector_t& R,
119 Vector_t& E,
120 Vector_t& B
121 ) const {
122 if (!isInside(R)) {
123 return true;
124 }
129
130 return false;
131}
std::shared_ptr< _FM3DH5Block_nonscale > FM3DH5Block_nonscale
@ T3DDynamicH5Block
Definition Fieldmap.h:36
#define INFOMSG(msg)
Definition IpplInfo.h:348
Inform & endl(Inform &inf)
Definition Inform.cpp:42
Inform & level3(Inform &inf)
Definition Inform.cpp:47
constexpr double mu_0
The permeability of vacuum in Vs/Am.
Definition Physics.h:48
constexpr double MVpm2Vpm
Definition Units.h:128
bool empty() const
Definition FieldArray.h:48
void allocate(std::size_t n)
void reset()
Release the buffer or the mapping.
double * mutableData()
Definition FieldArray.h:71
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition Fieldmap.cpp:649
std::string Filename_m
Definition Fieldmap.h:118
MapType Type
Definition Fieldmap.h:116
_FM3DH5Block_nonscale(const std::string &filename)
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
static FM3DH5Block_nonscale create(const std::string &filename)
virtual bool isInside(const Vector_t &r) const
void setStep(const long long)
FieldArray FieldstrengthEx_m
void getResonanceFrequency(void)
unsigned int num_gridpx_m
void getFieldInfo(const char *)
Vector_t interpolateTrilinearly(const FieldArray &, const FieldArray &, const FieldArray &, const Vector_t &X) const
void readField(const char *name, double *x, double *y, double *z)
void openFileMPIOCollective(const std::string &filename)
long long getNumSteps(void)
unsigned int num_gridpz_m
unsigned int num_gridpy_m
FieldArray FieldstrengthEz_m
FieldArray FieldstrengthEy_m