aboutsummaryrefslogtreecommitdiff
path: root/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp
diff options
context:
space:
mode:
authorGravatar MaxThevenet <mthevenet@lbl.gov> 2020-01-30 13:47:33 -0800
committerGravatar GitHub <noreply@github.com> 2020-01-30 13:47:33 -0800
commit880e9f745a8c3c28edd47dafa11a3d28745e97eb (patch)
treee72dcfdf44c186eb9bc24961a0e367bd9780e500 /Source/Diagnostics/ReducedDiags/ReducedDiags.cpp
parenta1f29589f048402ecce003efba2e21319e1d3b53 (diff)
parent1dae292f422a4599409c08f3111b2620a1726b00 (diff)
downloadWarpX-880e9f745a8c3c28edd47dafa11a3d28745e97eb.tar.gz
WarpX-880e9f745a8c3c28edd47dafa11a3d28745e97eb.tar.zst
WarpX-880e9f745a8c3c28edd47dafa11a3d28745e97eb.zip
Merge pull request #580 from Yin-YinjianZhao/reduced_diags
Add Reduced Diagnostics
Diffstat (limited to 'Source/Diagnostics/ReducedDiags/ReducedDiags.cpp')
-rw-r--r--Source/Diagnostics/ReducedDiags/ReducedDiags.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp
new file mode 100644
index 000000000..81831aa79
--- /dev/null
+++ b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp
@@ -0,0 +1,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