OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
FM3DH5Block.cpp
Go to the documentation of this file.
1//
2// Class _FM3DH5Block
3// Class for dynamic 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//
18
19#include "Fields/FM3DH5Block.h"
20
21#include "Fields/Fieldmap.h"
22
23#include <cstddef>
24
26 const std::string& filename
27 ) : _Fieldmap(
28 filename
29 ) {
31
32 openFileMPIOCollective (filename);
33 getFieldInfo ("Efield");
35 closeFile ();
36}
37
42
43FM3DH5Block _FM3DH5Block::create(const std::string& filename)
44{
45 return FM3DH5Block(new _FM3DH5Block(filename));
46}
47
49 ) {
50 if (loaded_m) {
51 return;
52 }
54 long long last_step = getNumSteps () - 1;
55 setStep (last_step);
56
57 std::size_t field_size = num_gridpx_m * num_gridpy_m * num_gridpz_m;
58
59 // One physical copy per node instead of one per rank, when the file allows it.
60 bool mapped = false;
61 if (tryMapComponents ("Efield", last_step,
63 if (tryMapComponents ("Hfield", last_step,
65 FieldstrengthHz_m, field_size)) {
66 mapped = true;
67 } else {
71 }
72 }
73 if (!mapped) {
74 FieldstrengthEx_m.allocate (field_size);
75 FieldstrengthEy_m.allocate (field_size);
76 FieldstrengthEz_m.allocate (field_size);
77 FieldstrengthHx_m.allocate (field_size);
78 FieldstrengthHy_m.allocate (field_size);
79 FieldstrengthHz_m.allocate (field_size);
80
81 readField (
82 "Efield",
86 readField (
87 "Hfield",
91 }
92 closeFile ();
93
94 // A group that is zero everywhere, such as the Efield of a static magnet map or the
95 // Hfield of an E-only RF export, costs as much to interpolate as a real one and adds
96 // exactly nothing. Find out once, release it, and skip it in getFieldstrength().
97 // Proving a group zero means reading all of it, so on the mapped path this reads each
98 // zero group from disk once per job at startup, split across the ranks.
101 if (!hasE_m) {
106 << "field map '" << Filename_m << "' Efield: zero everywhere, not interpolated"
107 << endl);
108 }
109 if (!hasH_m) {
114 << "field map '" << Filename_m << "' Hfield: zero everywhere, not interpolated"
115 << endl);
116 }
117 loaded_m = true;
118
119 if (!mapped) {
121 << typeset_msg("3d dynamic fieldmap '"
122 + Filename_m + "' (H5hut format) read", "info")
123 << endl);
124 }
125}
126
128 ) {
129 if (!loaded_m) {
130 return;
131 }
138 hasE_m = true;
139 hasH_m = true;
140 loaded_m = false;
141}
142
144 const Vector_t& R,
145 Vector_t& E,
146 Vector_t& B
147 ) const {
148 if (!isInside(R)) {
149 return true;
150 }
151 // Skipping a zero group is exact: its interpolation would add a signed zero.
152 if (hasE_m) {
154 }
155 if (hasH_m) {
157 }
158 return false;
159}
std::shared_ptr< _FM3DH5Block > FM3DH5Block
Definition FM3DH5Block.h:64
@ T3DDynamicH5Block
Definition Fieldmap.h:36
#define INFOMSG(msg)
Definition IpplInfo.h:348
Inform & endl(Inform &inf)
Definition Inform.cpp:42
Inform & level1(Inform &inf)
Definition Inform.cpp:45
Inform & level3(Inform &inf)
Definition Inform.cpp:47
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
FieldArray FieldstrengthHy_m
Definition FM3DH5Block.h:52
bool hasH_m
False once readMap() has found every Hfield sample to be exactly zero.
Definition FM3DH5Block.h:55
virtual ~_FM3DH5Block()
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
_FM3DH5Block(const std::string &filename)
virtual void freeMap()
static FM3DH5Block create(const std::string &filename)
FieldArray FieldstrengthHx_m
Definition FM3DH5Block.h:51
virtual void readMap()
bool loaded_m
readMap() has run. The arrays cannot tell any more: a zero group is released.
Definition FM3DH5Block.h:58
FieldArray FieldstrengthHz_m
Definition FM3DH5Block.h:50
virtual bool isInside(const Vector_t &r) const
bool anyNonZero(const FieldArray &x, const FieldArray &y, const FieldArray &z) 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
bool tryMapComponents(const char *name, long long step, FieldArray &x, FieldArray &y, FieldArray &z, std::size_t n)