18 mLogFile.setstate(std::ios_base::badbit);
30 fs::create_directory(
mFilename.parent_path());
38 std::ofstream(
mFilename, std::ios_base::out | std::ios_base::trunc);
41 std::cerr <<
"Cannot open log file " <<
mFilename << std::endl;
49 if (
mLogFile.tellp() == std::ofstream::pos_type(0)) {
50 mLogFile << std::right << std::setw(14) <<
"time";
51 for (
auto name : names) {
52 mLogFile <<
", " << std::right << std::setw(13) << name;
62 mLogFile << std::scientific << std::right << std::setw(14) << time;
71 mLogFile << std::scientific << std::right << std::setw(14) << time;
72 for (
Int i = 0; i <
data.rows(); ++i) {
73 mLogFile <<
", " << std::right << std::setw(13) <<
data(i, 0);
81 mLogFile << std::scientific << std::right << std::setw(14) << time;
82 for (
Int i = 0; i <
data.rows(); ++i) {
83 mLogFile <<
", " << std::right << std::setw(13) <<
data(i, 0);
90 if (
mLogFile.tellp() == std::ofstream::pos_type(0)) {
91 std::vector<String> names;
93 Int harmonicOffset =
data.rows() / freqNum;
94 Int complexOffset = harmonicOffset / 2;
96 for (
Int freq = 0; freq < freqNum; ++freq) {
97 for (
Int node = 0; node < complexOffset; ++node) {
98 std::stringstream name;
99 name <<
"n" << std::setfill(
'0') << std::setw(5) << node <<
"f"
100 << std::setfill(
'0') << std::setw(2) << freq <<
".re";
101 names.push_back(name.str());
103 for (
Int node = 0; node < complexOffset; ++node) {
104 std::stringstream name;
105 name <<
"n" << std::setfill(
'0') << std::setw(5) << node <<
"f"
106 << std::setfill(
'0') << std::setw(2) << freq <<
".im";
107 names.push_back(name.str());
116 if (
mLogFile.tellp() == std::ofstream::pos_type(0)) {
117 std::vector<String> names;
118 for (
Int i = 0; i <
data.rows(); ++i) {
119 std::stringstream name;
120 name <<
"node" << std::setfill(
'0') << std::setw(5) << i;
121 names.push_back(name.str());
132 if (
mLogFile.tellp() == std::ofstream::pos_type(0)) {
133 mLogFile << std::right << std::setw(14) <<
"time";
135 mLogFile <<
", " << std::right << std::setw(13) << it.first;
139 mLogFile << std::scientific << std::right << std::setw(14) << time;
141 mLogFile <<
", " << std::right << std::setw(13) << it.second->toString();
146 mLogger.log(time, timeStepCount);
150 return std::make_shared<DataLogger::Step>(*
this);
std::shared_ptr< Task > Ptr
void execute(Real time, Int timeStepCount)
virtual void log(Real time, Int timeStepCount) override
void logEMTNodeValues(Real time, const Matrix &data)
virtual CPS::Task::Ptr getTask() override
void logPhasorNodeValues(Real time, const Matrix &data, Int freqNum=1)
virtual void setColumnNames(std::vector< String > names)
virtual void start() override
virtual void logDataLine(Real time, Real data)
virtual void stop() override
DataLogger(Bool enabled=true)
std::map< String, CPS::AttributeBase::Ptr > mAttributes
struct dps_magma_data data
CPS::MatrixComp MatrixComp