Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions src/solve/csv_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// University of California, and others. SPDX-License-Identifier: BSD-3-Clause
#include "csv_writer.h"

#include <iomanip>

/**
* @brief Write results vessel based.
*
Expand All @@ -19,9 +21,8 @@ std::string to_vessel_csv(const std::vector<double> &times,
// Create string stream to buffer output
std::stringstream out;

// Create short and long buffer for lines
char sbuff[140];
char lbuff[236];
// Set floating point format for the entire stream
out << std::scientific << std::setprecision(16);

// Write column labels
if (derivative) {
Expand Down Expand Up @@ -82,21 +83,20 @@ std::string to_vessel_csv(const std::vector<double> &times,
d_outflow_mean /= num_steps;
d_inpres_mean /= num_steps;
d_outpres_mean /= num_steps;
snprintf(
lbuff, 236, "%s,,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e\n",
name.c_str(), inflow_mean, outflow_mean, inpres_mean, outpres_mean,
d_inflow_mean, d_outflow_mean, d_inpres_mean, d_outpres_mean);
out << lbuff;

out << name << ",," << inflow_mean << "," << outflow_mean << ","
<< inpres_mean << "," << outpres_mean << "," << d_inflow_mean << ","
<< d_outflow_mean << "," << d_inpres_mean << "," << d_outpres_mean
<< "\n";
} else {
for (size_t i = 0; i < num_steps; i++) {
snprintf(lbuff, 236,
"%s,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e,%.16e\n",
name.c_str(), times[i], states[i].y[inflow_dof],
states[i].y[outflow_dof], states[i].y[inpres_dof],
states[i].y[outpres_dof], states[i].ydot[inflow_dof],
states[i].ydot[outflow_dof], states[i].ydot[inpres_dof],
states[i].ydot[outpres_dof]);
out << lbuff;
out << name << "," << times[i] << "," << states[i].y[inflow_dof]
<< "," << states[i].y[outflow_dof] << ","
<< states[i].y[inpres_dof] << "," << states[i].y[outpres_dof]
<< "," << states[i].ydot[inflow_dof] << ","
<< states[i].ydot[outflow_dof] << ","
<< states[i].ydot[inpres_dof] << ","
<< states[i].ydot[outpres_dof] << "\n";
}
}
} else {
Expand All @@ -116,16 +116,15 @@ std::string to_vessel_csv(const std::vector<double> &times,
outflow_mean /= num_steps;
inpres_mean /= num_steps;
outpres_mean /= num_steps;
snprintf(sbuff, 140, "%s,,%.16e,%.16e,%.16e,%.16e\n", name.c_str(),
inflow_mean, outflow_mean, inpres_mean, outpres_mean);
out << sbuff;

out << name << ",," << inflow_mean << "," << outflow_mean << ","
<< inpres_mean << "," << outpres_mean << "\n";
} else {
for (size_t i = 0; i < num_steps; i++) {
snprintf(sbuff, 140, "%s,%.16e,%.16e,%.16e,%.16e,%.16e\n",
name.c_str(), times[i], states[i].y[inflow_dof],
states[i].y[outflow_dof], states[i].y[inpres_dof],
states[i].y[outpres_dof]);
out << sbuff;
out << name << "," << times[i] << "," << states[i].y[inflow_dof]
<< "," << states[i].y[outflow_dof] << ","
<< states[i].y[inpres_dof] << "," << states[i].y[outpres_dof]
<< "\n";
}
}
}
Expand All @@ -151,9 +150,8 @@ std::string to_variable_csv(const std::vector<double> &times,
// Create string stream to buffer output
std::stringstream out;

// Create short and long buffer for lines
char sbuff[87];
char lbuff[110];
// Set floating point format for the entire stream
out << std::scientific << std::setprecision(16);

// Determine number of time steps
int num_steps = times.size();
Expand All @@ -173,17 +171,15 @@ std::string to_variable_csv(const std::vector<double> &times,
}
mean_y /= num_steps;
mean_ydot /= num_steps;
snprintf(lbuff, 110, "%s,,%.16e,%.16e\n", name.c_str(), mean_y,
mean_ydot);
out << lbuff;

out << name << ",," << mean_y << "," << mean_ydot << "\n";
}
} else {
for (size_t i = 0; i < model.dofhandler.size(); i++) {
std::string name = model.dofhandler.variables[i];
for (size_t j = 0; j < num_steps; j++) {
snprintf(lbuff, 110, "%s,%.16e,%.16e,%.16e\n", name.c_str(), times[j],
states[j].y[i], states[j].ydot[i]);
out << lbuff;
out << name << "," << times[j] << "," << states[j].y[i] << ","
<< states[j].ydot[i] << "\n";
}
}
}
Expand All @@ -197,20 +193,18 @@ std::string to_variable_csv(const std::vector<double> &times,
mean_y += states[j].y[i];
}
mean_y /= num_steps;
snprintf(sbuff, 87, "%s,,%.16e\n", name.c_str(), mean_y);
out << sbuff;

out << name << ",," << mean_y << "\n";
}
} else {
for (size_t i = 0; i < model.dofhandler.size(); i++) {
std::string name = model.dofhandler.variables[i];
for (size_t j = 0; j < num_steps; j++) {
snprintf(sbuff, 87, "%s,%.16e,%.16e\n", name.c_str(), times[j],
states[j].y[i]);
out << sbuff;
out << name << "," << times[j] << "," << states[j].y[i] << "\n";
}
}
}
}

return out.str();
}
}
Loading