blob: 81831aa791380b637f063e662d606ea841ef105d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/* Copyright 2019-2020 Maxence Thevenet, Yinjian Zhao
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "ReducedDiags.H"
#include "WarpX.H"
#include "AMReX_ParmParse.H"
#include "AMReX_Utility.H"
#include <iomanip>
using namespace amrex;
// constructor
ReducedDiags::ReducedDiags (std::string rd_name)
{
m_rd_name = rd_name;
ParmParse pp(m_rd_name);
// read path
pp.query("path", m_path);
// read extension
pp.query("extension", m_extension);
// creater folder
if (!UtilCreateDirectory(m_path, 0755))
{ CreateDirectoryFailed(m_path); }
// check if it is a restart run
std::string restart_chkfile = "";
ParmParse pp_amr("amr");
pp_amr.query("restart", restart_chkfile);
m_IsNotRestart = restart_chkfile.empty();
// replace / create output file
if ( m_IsNotRestart ) // not a restart
{
std::ofstream ofs;
ofs.open(m_path+m_rd_name+"."+m_extension, std::ios::trunc);
ofs.close();
}
// read reduced diags frequency
pp.query("frequency", m_freq);
// read separator
pp.query("separator", m_sep);
}
// end constructor
// write to file function
void ReducedDiags::WriteToFile (int step) const
{
// open file
std::ofstream ofs;
ofs.open(m_path + m_rd_name + "." + m_extension,
std::ofstream::out | std::ofstream::app);
// write step
ofs << step+1;
ofs << m_sep;
// set precision
ofs << std::fixed << std::setprecision(14) << std::scientific;
// write time
ofs << WarpX::GetInstance().gett_new(0);
// loop over data size and write
for (int i = 0; i < m_data.size(); ++i)
{
ofs << m_sep;
ofs << m_data[i];
}
// end loop over data size
// end line
ofs << std::endl;
// close file
ofs.close();
}
// end ReducedDiags::WriteToFile
|