Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_SnapshotCollection.hpp"
00007
00008 #include "MOR_MultiVectorOutputFile.hpp"
00009
00010 #include "Teuchos_TestForException.hpp"
00011
00012 #include <stdexcept>
00013
00014 namespace MOR {
00015
00016 SnapshotCollection::SnapshotCollection(
00017 int period,
00018 const Teuchos::RCP<MultiVectorOutputFile> &snapshotFile) :
00019 period_(period),
00020 snapshotFile_(snapshotFile),
00021 skipCount_(0)
00022 {
00023 TEUCHOS_TEST_FOR_EXCEPTION(
00024 period <= 0,
00025 std::out_of_range,
00026 "period = " << period << ", should have period > 0");
00027 }
00028
00029
00030 SnapshotCollection::~SnapshotCollection()
00031 {
00032 const int vectorCount = snapshots_.size();
00033 if (vectorCount > 0)
00034 {
00035 const Epetra_Vector firstVector = snapshots_[0];
00036 const Epetra_BlockMap &map = firstVector.Map();
00037 Epetra_MultiVector collection(map, vectorCount);
00038 for (int iVec = 0; iVec < vectorCount; ++iVec)
00039 {
00040 *collection(iVec) = snapshots_[iVec];
00041 }
00042
00043 snapshotFile_->write(collection);
00044 }
00045 }
00046
00047 void SnapshotCollection::addVector(double stamp, const Epetra_Vector &value)
00048 {
00049 if (skipCount_ == 0)
00050 {
00051 stamps_.push_back(stamp);
00052 snapshots_.push_back(value);
00053 skipCount_ = period_ - 1;
00054 }
00055 else
00056 {
00057 --skipCount_;
00058 }
00059 }
00060
00061 }