22 #include <boost/format.hpp>
28 template<
typename FieldType>
30 std::string unit,
long long step,
37 constexpr
bool isVectorField = std::is_same<VField_t, FieldType>::value;
38 std::string
type = (isVectorField) ?
"field" :
"scalar";
57 std::filesystem::path file(dirname);
58 std::format filename(
"%1%-%2%-%|3$06|.dat");
60 filename % basename % (name + std::string(
"_") +
type) % step;
61 file /= filename.str();
63 std::ofstream fout(file.string(), std::ios::out);
66 fout <<
"# " << name <<
" " << type <<
" data on grid" <<
std::endl
68 << std::setw(4) <<
"i"
69 << std::setw(5) <<
"j"
70 << std::setw(5) <<
"k"
71 << std::setw(17) <<
"x [m]"
72 << std::setw(17) <<
"y [m]"
73 << std::setw(17) <<
"z [m]";
75 fout << std::setw(10) << name <<
"x [" << unit <<
"]"
76 << std::setw(10) << name <<
"y [" << unit <<
"]"
77 << std::setw(10) << name <<
"z [" << unit <<
"]";
79 fout << std::setw(13) << name <<
" [" << unit <<
"]";
83 fout << std::setw(13) << name <<
" image [" << unit <<
"]";
88 Vector_t origin = field.get_mesh().get_origin();
89 Vector_t spacing(field.get_mesh().get_meshSpacing(0),
90 field.get_mesh().get_meshSpacing(1),
91 field.get_mesh().get_meshSpacing(2));
93 NDIndex<3> localIdx = field.getLayout().getLocalNDIndex();
94 for (
int x = localIdx[0].first(); x <= localIdx[0].last(); x++) {
95 for (
int y = localIdx[1].first(); y <= localIdx[1].last(); y++) {
96 for (
int z = localIdx[2].first(); z <= localIdx[2].last(); z++) {
98 fout << std::setw(5) << x + 1
99 << std::setw(5) << y + 1
100 << std::setw(5) << z + 1
101 << std::setw(17) << origin(0) + x * spacing(0)
102 << std::setw(17) << origin(1) + y * spacing(1)
103 << std::setw(17) << origin(2) + z * spacing(2);
105 Vector_t vfield = field.localElement(idx);
106 fout << std::setw(17) << vfield[0]
107 << std::setw(17) << vfield[1]
108 << std::setw(17) << vfield[2];
110 fout << std::setw(17) << field.localElement(idx);
114 fout << std::setw(17) << image->localElement(idx);
static OpalData * getInstance()
std::string toUpper(const std::string &str)
Inform & endl(Inform &inf)
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.
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
std::string getInputBasename()
get input file name without extension