PolyFEM
Loading...
Searching...
No Matches
SolverCSVWriter.cpp
Go to the documentation of this file.
1#include "SolverCSVWriter.hpp"
2
8
9#include <spdlog/fmt/fmt.h>
10
11namespace polyfem::io
12{
13 EnergyCSVWriter::EnergyCSVWriter(const std::string &path, const solver::SolveData &solve_data)
14 : file(path), solve_data(solve_data)
15 {
16 file << "i,";
17 for (const auto &[name, _] : solve_data.named_forms())
18 file << name << ",";
19 file << "total_energy" << std::endl;
20 }
21
23 {
24 file.close();
25 }
26
27 void EnergyCSVWriter::write(const int i, const Eigen::MatrixXd &sol)
28 {
29 const double s = solve_data.time_integrator
30 ? solve_data.time_integrator->acceleration_scaling()
31 : 1;
32 file << i << ",";
33 for (const auto &[_, form] : solve_data.named_forms())
34 {
35 // Divide by acceleration scaling to get the energy (units of J).
36 file << ((form && form->enabled()) ? form->value(sol) : 0) / s << ",";
37 }
38 file << solve_data.nl_problem->value(sol) / s << "\n";
39 file.flush();
40 }
41
43 const std::string &path,
44 const int n_bases,
45 const int n_elements,
46 const double t0,
47 const double dt)
48 : file(path), n_bases(n_bases), n_elements(n_elements), t0(t0), dt(dt)
49 {
50 file << "step,time,forward,remeshing,global_relaxation,peak_mem,#V,#T" << std::endl;
51 }
52
57
59 const int t,
60 const double forward,
61 const double remeshing,
62 const double global_relaxation)
63 {
64 const double peak_mem = getPeakRSS() / double(1 << 30);
65 file << fmt::format(
66 "{},{},{},{},{},{},{},{}\n",
67 t, t0 + dt * t, forward, remeshing, global_relaxation, peak_mem,
69 file.flush();
70 }
71} // namespace polyfem::io
EnergyCSVWriter(const std::string &path, const solver::SolveData &solve_data)
const solver::SolveData & solve_data
void write(const int i, const Eigen::MatrixXd &sol)
RuntimeStatsCSVWriter(const std::string &path, const int n_bases, const int n_elements, const double t0, const double dt)
void write(const int t, const double forward, const double remeshing, const double global_relaxation)
class to store time stepping data
Definition SolveData.hpp:59
std::shared_ptr< solver::NLProblem > nl_problem
std::vector< std::pair< std::string, std::shared_ptr< solver::Form > > > named_forms() const
std::shared_ptr< time_integrator::ImplicitTimeIntegrator > time_integrator
size_t getPeakRSS(void)
Returns the peak (maximum so far) resident set size (physical memory use) measured in bytes,...
Definition getRSS.c:37