Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_ProjectionError.hpp"
00007
00008 #include "MOR_MultiVectorOutputFile.hpp"
00009 #include "MOR_ReducedSpace.hpp"
00010
00011 #include "Epetra_Comm.h"
00012 #include "Epetra_LocalMap.h"
00013 #include "Epetra_Vector.h"
00014
00015
00016 #include <iostream>
00017
00018 namespace MOR {
00019
00020 namespace {
00021
00022 const int ZERO_BASED_INDEXING = 0;
00023 const bool NO_INIT = false;
00024
00025 }
00026
00027 ProjectionError::ProjectionError(
00028 const Teuchos::RCP<ReducedSpace> &projectionSpace,
00029 const Teuchos::RCP<MultiVectorOutputFile> &errorFile) :
00030 projectionSpace_(projectionSpace),
00031 errorFile_(errorFile)
00032 {
00033
00034 }
00035
00036
00037 ProjectionError::~ProjectionError()
00038 {
00039 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00040 typedef int GlobalIndex;
00041 #else
00042 typedef long long GlobalIndex;
00043 #endif
00044 Epetra_LocalMap entryMap(
00045 static_cast<GlobalIndex>(relativeErrorNorms_.size()),
00046 ZERO_BASED_INDEXING,
00047 projectionSpace_->comm());
00048 Epetra_Vector entries(entryMap, NO_INIT);
00049
00050 for (int i = 0; i < entries.MyLength(); ++i) {
00051 entries[i] = relativeErrorNorms_[i];
00052 }
00053
00054 errorFile_->write(entries);
00055 }
00056
00057 const Epetra_Comm &ProjectionError::projectionBasisComm() const {
00058 return projectionSpace_->comm();
00059 }
00060
00061 void ProjectionError::process(const Epetra_MultiVector &v)
00062 {
00063
00064 const Teuchos::RCP<const Epetra_MultiVector> components = projectionSpace_->reduction(v);
00065
00066
00067 const Teuchos::RCP<Epetra_MultiVector> absoluteError = projectionSpace_->expansion(*components);
00068 absoluteError->Update(-1.0, v, 1.0);
00069
00070
00071 const Epetra_LocalMap normMap(components->NumVectors(), ZERO_BASED_INDEXING, projectionSpace_->comm());
00072 Epetra_Vector absoluteErrorNorm(normMap, NO_INIT);
00073 absoluteError->Norm2(absoluteErrorNorm.Values());
00074
00075 Epetra_Vector referenceNorm(normMap, NO_INIT);
00076 v.Norm2(referenceNorm.Values());
00077
00078
00079 Epetra_Vector relativeErrorNorm(normMap, NO_INIT);
00080 relativeErrorNorm.ReciprocalMultiply(1.0, referenceNorm, absoluteErrorNorm, 0.0);
00081
00082
00083 for (int i = 0; i < relativeErrorNorm.MyLength(); ++i) {
00084 relativeErrorNorms_.push_back(relativeErrorNorm[i]);
00085 }
00086
00087
00088
00089 components->Print(std::cout);
00090 referenceNorm.Print(std::cout);
00091 absoluteErrorNorm.Print(std::cout);
00092 relativeErrorNorm.Print(std::cout);
00093 }
00094
00095 }