OPALX (Object Oriented Parallel Accelerator Library for Exascal)
master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
FieldWriter.hpp
Go to the documentation of this file.
1
//
2
// Class FieldWriter
3
// This class writes the bunch internal fields on the grid to
4
// file. It supports single core execution only.
5
//
6
// Copyright (c) 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7
// All rights reserved
8
//
9
// This file is part of OPAL.
10
//
11
// OPAL is free software: you can redistribute it and/or modify
12
// it under the terms of the GNU General Public License as published by
13
// the Free Software Foundation, either version 3 of the License, or
14
// (at your option) any later version.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18
//
19
#include <fstream>
20
#include <iomanip>
21
22
#include <filesystem>
23
24
#include "
AbstractObjects/OpalData.h
"
25
#include "
Utilities/Util.h
"
26
// #include "Algorithms/PBunchDefs.h"
27
28
template
<
typename
FieldType>
29
void
FieldWriter::dumpField
(
30
FieldType& field, std::string name, std::string unit,
long
long
step, FieldType* image) {
31
if
(ippl::Comm->size() > 1) {
32
return
;
33
}
34
/*
35
constexpr bool isVectorField = std::is_same<VField_t, FieldType>::value;
36
std::string type = (isVectorField) ? "field" : "scalar";
37
38
INFOMSG("*** START DUMPING " + Util::toUpper(name) + " FIELD ***" << endl);
39
*/
40
/* Save the files in the output directory of the simulation. The file
41
* name of vector fields is
42
*
43
* 'basename'-'name'_field-'******'.dat
44
*
45
* and of scalar fields
46
*
47
* 'basename'-'name'_scalar-'******'.dat
48
*
49
* with
50
* 'basename': OPAL input file name (*.in)
51
* 'name': field name (input argument of function)
52
* '******': step padded with zeros to 6 digits
53
*/
54
/*
55
std::string dirname = "";
56
std::filesystem::path file(dirname);
57
std::string filename = std::format("{}-{}-{:06d}.dat", basename, name + std::string("_") + type,
58
step); std::string basename = OpalData::getInstance()->getInputBasename(); filename % basename %
59
(name + std::string("_") + type) % step; file /= filename.str(); INFOMSG("*** FILE NAME " +
60
file.string() << endl); std::ofstream fout(file.string(), std::ios::out); fout.precision(9);
61
62
fout << "# " << name << " " << type << " data on grid" << std::endl
63
<< "#"
64
<< std::setw(4) << "i"
65
<< std::setw(5) << "j"
66
<< std::setw(5) << "k"
67
<< std::setw(17) << "x [m]"
68
<< std::setw(17) << "y [m]"
69
<< std::setw(17) << "z [m]";
70
if (isVectorField) {
71
fout << std::setw(10) << name << "x [" << unit << "]"
72
<< std::setw(10) << name << "y [" << unit << "]"
73
<< std::setw(10) << name << "z [" << unit << "]";
74
} else {
75
fout << std::setw(13) << name << " [" << unit << "]";
76
}
77
78
if (image) {
79
fout << std::setw(13) << name << " image [" << unit << "]";
80
}
81
82
fout << std::endl;
83
84
Vector_t origin = field.get_mesh().get_origin();
85
Vector_t spacing(field.get_mesh().get_meshSpacing(0),
86
field.get_mesh().get_meshSpacing(1),
87
field.get_mesh().get_meshSpacing(2));
88
89
NDIndex<3> localIdx = field.getLayout().getLocalNDIndex();
90
for (int x = localIdx[0].first(); x <= localIdx[0].last(); x++) {
91
for (int y = localIdx[1].first(); y <= localIdx[1].last(); y++) {
92
for (int z = localIdx[2].first(); z <= localIdx[2].last(); z++) {
93
NDIndex<3> idx(Index(x, x), Index(y, y), Index(z, z));
94
fout << std::setw(5) << x + 1
95
<< std::setw(5) << y + 1
96
<< std::setw(5) << z + 1
97
<< std::setw(17) << origin(0) + x * spacing(0)
98
<< std::setw(17) << origin(1) + y * spacing(1)
99
<< std::setw(17) << origin(2) + z * spacing(2);
100
if (isVectorField) {
101
Vector_t vfield = field.localElement(idx);
102
fout << std::setw(17) << vfield[0]
103
<< std::setw(17) << vfield[1]
104
<< std::setw(17) << vfield[2];
105
} else {
106
fout << std::setw(17) << field.localElement(idx);
107
}
108
109
if (image) {
110
fout << std::setw(17) << image->localElement(idx);
111
}
112
fout << std::endl;
113
}
114
}
115
}
116
fout.close();
117
INFOMSG("*** FINISHED DUMPING " + Util::toUpper(name) + " FIELD ***" << endl);
118
*/
119
}
OpalData.h
Util.h
FieldWriter::dumpField
void dumpField(FieldType &field, std::string name, std::string unit, long long step, FieldType *image=nullptr)
Dump a scalar or vector field to a file.
Definition
FieldWriter.hpp:29
src
Structure
FieldWriter.hpp
Generated on Mon Jun 1 2026 10:40:53 for OPALX (Object Oriented Parallel Accelerator Library for Exascal) by
1.9.8