OPALX (Object Oriented Parallel Accelerator Library for Exascal)
MINIorX
OPALX
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 <iomanip>
20
#include <fstream>
21
22
#include <boost/filesystem.hpp>
23
#include <boost/format.hpp>
24
25
#include "
Utilities/Util.h
"
26
#include "
AbstractObjects/OpalData.h
"
27
// #include "Algorithms/PBunchDefs.h"
28
29
template
<
typename
FieldType>
30
void
FieldWriter::dumpField
(FieldType& field, std::string name,
31
std::string unit,
long
long
step,
32
FieldType* image)
33
{
34
if
(ippl::Comm->size() > 1) {
35
return
;
36
}
37
/*
38
constexpr bool isVectorField = std::is_same<VField_t, FieldType>::value;
39
std::string type = (isVectorField) ? "field" : "scalar";
40
41
INFOMSG("*** START DUMPING " + Util::toUpper(name) + " FIELD ***" << endl);
42
*/
43
/* Save the files in the output directory of the simulation. The file
44
* name of vector fields is
45
*
46
* 'basename'-'name'_field-'******'.dat
47
*
48
* and of scalar fields
49
*
50
* 'basename'-'name'_scalar-'******'.dat
51
*
52
* with
53
* 'basename': OPAL input file name (*.in)
54
* 'name': field name (input argument of function)
55
* '******': step padded with zeros to 6 digits
56
*/
57
/*
58
std::string dirname = "";
59
boost::filesystem::path file(dirname);
60
boost::format filename("%1%-%2%-%|3$06|.dat");
61
std::string basename = OpalData::getInstance()->getInputBasename();
62
filename % basename % (name + std::string("_") + type) % step;
63
file /= filename.str();
64
INFOMSG("*** FILE NAME " + file.string() << endl);
65
std::ofstream fout(file.string(), std::ios::out);
66
fout.precision(9);
67
68
fout << "# " << name << " " << type << " data on grid" << std::endl
69
<< "#"
70
<< std::setw(4) << "i"
71
<< std::setw(5) << "j"
72
<< std::setw(5) << "k"
73
<< std::setw(17) << "x [m]"
74
<< std::setw(17) << "y [m]"
75
<< std::setw(17) << "z [m]";
76
if (isVectorField) {
77
fout << std::setw(10) << name << "x [" << unit << "]"
78
<< std::setw(10) << name << "y [" << unit << "]"
79
<< std::setw(10) << name << "z [" << unit << "]";
80
} else {
81
fout << std::setw(13) << name << " [" << unit << "]";
82
}
83
84
if (image) {
85
fout << std::setw(13) << name << " image [" << unit << "]";
86
}
87
88
fout << std::endl;
89
90
Vector_t origin = field.get_mesh().get_origin();
91
Vector_t spacing(field.get_mesh().get_meshSpacing(0),
92
field.get_mesh().get_meshSpacing(1),
93
field.get_mesh().get_meshSpacing(2));
94
95
NDIndex<3> localIdx = field.getLayout().getLocalNDIndex();
96
for (int x = localIdx[0].first(); x <= localIdx[0].last(); x++) {
97
for (int y = localIdx[1].first(); y <= localIdx[1].last(); y++) {
98
for (int z = localIdx[2].first(); z <= localIdx[2].last(); z++) {
99
NDIndex<3> idx(Index(x, x), Index(y, y), Index(z, z));
100
fout << std::setw(5) << x + 1
101
<< std::setw(5) << y + 1
102
<< std::setw(5) << z + 1
103
<< std::setw(17) << origin(0) + x * spacing(0)
104
<< std::setw(17) << origin(1) + y * spacing(1)
105
<< std::setw(17) << origin(2) + z * spacing(2);
106
if (isVectorField) {
107
Vector_t vfield = field.localElement(idx);
108
fout << std::setw(17) << vfield[0]
109
<< std::setw(17) << vfield[1]
110
<< std::setw(17) << vfield[2];
111
} else {
112
fout << std::setw(17) << field.localElement(idx);
113
}
114
115
if (image) {
116
fout << std::setw(17) << image->localElement(idx);
117
}
118
fout << std::endl;
119
}
120
}
121
}
122
fout.close();
123
INFOMSG("*** FINISHED DUMPING " + Util::toUpper(name) + " FIELD ***" << endl);
124
*/
125
}
Util.h
OpalData.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:30