14 timestamp(timestamp_),
15 numberOfDataEntries(database._numberOfGlobalDataPoints) {
27 timestamp(copy.timestamp),
28 numberOfDataEntries(copy.numberOfDataEntries) {
81 std::ostringstream snapshotFileName;
82 snapshotFileName << _fileName;
88 snapshotFileName <<
"-rank-" << _rank;
91 if (_clearDatabaseAfterFlush) {
92 static int snapshotCounter = -1;
94 snapshotFileName <<
"-snapshot-" << snapshotCounter;
97 snapshotFileName <<
".csv";
100 if (not _data.empty()) {
101 logInfo(
"dumpCSVFile()",
"dump particle trajectory database " << snapshotFileName.str() );
102 std::ofstream file( snapshotFileName.str() );
103 file << std::scientific;
104 file <<
"t," << _dataName << std::endl;
106 for (
auto& snapshot: _data) {
107 file << snapshot.timestamp;
109 if (snapshot.data!=
nullptr) {
110 if(_precision>0){ file.precision(_precision); }
111 for (
int i=0; i<_numberOfGlobalDataPoints; i++) {
122 logInfo(
"dumpCSVFile()",
"particle trajectory database is empty. Do not dump " << snapshotFileName.str() );
126 if (_clearDatabaseAfterFlush) {
132 _deltaBetweenTwoDatabaseFlushes = deltaBetweenTwoDatabaseFlushes;
136 _fileName = filename;
140 _dataName = dataname;
144 _precision = precision;
148 _clearDatabaseAfterFlush = value;
154 _maxDataDelta = 1e-20;
155 _deltasAreRelative = deltasAreRelative;
171 logWarning(
"getAction(...)",
"There were two values for same time stamp " << timestamp <<
". This is inconsistent");
174 else if(timestamp - _data.front().timestamp >=_timeDelta and _timeDelta>=0.0 ){
186 int numberOfDataEntries,
193 double maxDataDeltaThisAction = 0;
194 for (
int i=0; i<numberOfDataEntries; i++) {
195 maxDataDeltaThisAction = std::max( maxDataDeltaThisAction,
196 std::abs( _data.front().data[i] - data[i] ));
198 _maxDataDelta = std::max( _maxDataDelta, maxDataDeltaThisAction );
203 if( maxDataDeltaThisAction > _dataDelta ){
206 else if( _deltasAreRelative
207 and maxDataDeltaThisAction>=_deltaCutOffThreshold
208 and maxDataDeltaThisAction/_maxDataDelta >= _dataDelta ){
211 else if ( not _deltasAreRelative and maxDataDeltaThisAction >= _dataDelta ) {
223 const int totalSize = _data.size();
224 return tarch::la::greater(_maxTimestamp,0.0) and totalSize >= _thresholdForNextDatabaseFlush;
237 _maxTimestamp = std::max(_maxTimestamp,timestamp);
238 switch ( getAction(timestamp) ) {
239 case AddSnapshotAction::Ignore:
241 case AddSnapshotAction::Append:
242 _data.push_front(
Entry(*
this,timestamp) );
243 for (
int i=0; i<_numberOfGlobalDataPoints; i++) {
244 _data.front().data[i] = 0.0;
247 case AddSnapshotAction::Replace:
248 for (
int i=0; i<_numberOfGlobalDataPoints; i++) {
249 _data.front().data[i] = 0.0;
255 if (dumpDatabaseSnapshot()) {
257 logInfo(
"addSnapshot(...)",
"flushed database file (temporary flush - simulation has not terminated yet)" );
258 _thresholdForNextDatabaseFlush += _deltaBetweenTwoDatabaseFlushes;
265 int numberOfDataEntries,
268 assertion( _numberOfGlobalDataPoints==numberOfDataEntries or _data.empty());
269 _numberOfGlobalDataPoints = std::max(_numberOfGlobalDataPoints,numberOfDataEntries);
276 _maxTimestamp = std::max(_maxTimestamp,timestamp);
277 switch ( getAction(timestamp,numberOfDataEntries,data) ) {
278 case AddSnapshotAction::Ignore:
280 case AddSnapshotAction::Append:
281 _data.push_front(
Entry(*
this,timestamp) );
282 for (
int i=0; i<_numberOfGlobalDataPoints; i++) {
283 _data.front().data[i] = data[i];
286 case AddSnapshotAction::Replace:
287 for (
int i=0; i<_numberOfGlobalDataPoints; i++) {
288 _data.front().data[i] = data[i];
294 if (dumpDatabaseSnapshot()) {
296 logInfo(
"addSnapshot(...)",
"flush database file " << _fileName <<
" (temporary flush - simulation has not terminated yet)" );
297 _thresholdForNextDatabaseFlush = _deltaBetweenTwoDatabaseFlushes;
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
static Rank & getInstance()
This operation returns the singleton instance.
int getRank() const
Return rank of this node.
Create a lock around a boolean semaphore region.
void free()
Free the lock.
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
const int numberOfDataEntries
Have to memorise this guy to be able to write a proper copy constructor.