| 1 |
#ifndef OPTIMIZATION_STATUSFUNCTION_HPP |
| 2 |
#define OPTIMIZATION_STATUSFUNCTION_HPP |
| 3 |
#include "config.h" |
| 4 |
#include "io/DumpWriter.hpp" |
| 5 |
#include "io/StatWriter.hpp" |
| 6 |
|
| 7 |
namespace OpenMD { |
| 8 |
class StatusFunction { |
| 9 |
public: |
| 10 |
virtual ~StatusFunction() {} |
| 11 |
virtual void writeStatus(int functionCount, int gradientCount, const DynamicVector<RealType>& x, RealType f) { std::cerr << "doing status\n"; } |
| 12 |
}; |
| 13 |
|
| 14 |
//! No status |
| 15 |
class NoStatus : public StatusFunction { |
| 16 |
public: |
| 17 |
virtual void writeStatus(int functionCount, int gradientCount, const DynamicVector<RealType>& x, RealType f) {}; |
| 18 |
}; |
| 19 |
|
| 20 |
class DumpStatusFunction : public StatusFunction { |
| 21 |
|
| 22 |
public: |
| 23 |
DumpStatusFunction(SimInfo* info) : StatusFunction(), info_(info), thermo(info) { |
| 24 |
dumpWriter = new DumpWriter(info_); |
| 25 |
StatsBitSet mask; |
| 26 |
mask.set(Stats::TIME); |
| 27 |
mask.set(Stats::POTENTIAL_ENERGY); |
| 28 |
statWriter = new StatWriter(info_->getStatFileName(), mask); |
| 29 |
} |
| 30 |
virtual void writeStatus(int functionCount, int gradientCount, const DynamicVector<RealType>& x, RealType f) { |
| 31 |
Snapshot* curSnapshot =info_->getSnapshotManager()->getCurrentSnapshot(); |
| 32 |
thermo.saveStat(); |
| 33 |
curSnapshot->setTime(functionCount); |
| 34 |
dumpWriter->writeDumpAndEor(); |
| 35 |
statWriter->writeStat(curSnapshot->statData); |
| 36 |
} |
| 37 |
~DumpStatusFunction() { |
| 38 |
delete dumpWriter; |
| 39 |
delete statWriter; |
| 40 |
} |
| 41 |
|
| 42 |
private: |
| 43 |
SimInfo* info_; |
| 44 |
DumpWriter* dumpWriter; |
| 45 |
StatWriter* statWriter; |
| 46 |
Thermo thermo; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
} |
| 51 |
#endif |