Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "MOR_ReducedJacobianFactory.hpp"
00007
00008 #include "MOR_BasisOps.hpp"
00009
00010 #include "Epetra_CrsMatrix.h"
00011 #include "Epetra_LocalMap.h"
00012 #include "Epetra_Vector.h"
00013 #include "Epetra_Comm.h"
00014
00015 #include "Teuchos_Ptr.hpp"
00016 #include "Teuchos_Array.hpp"
00017
00018 namespace MOR {
00019
00020 using ::Teuchos::Ptr;
00021 using ::Teuchos::ptr;
00022 using ::Teuchos::RCP;
00023 using ::Teuchos::rcp;
00024 using ::Teuchos::Array;
00025
00026 ReducedJacobianFactory::ReducedJacobianFactory(const RCP<const Epetra_MultiVector> &rightProjector) :
00027 rightProjector_(rightProjector),
00028 premultipliedRightProjector_(new Epetra_MultiVector(*rightProjector)),
00029 reducedGraph_(Copy,
00030 Epetra_Map(rightProjector->NumVectors(), isMasterProcess() ? rightProjector->NumVectors() : 0, 0, rightProjector->Comm()),
00031 rightProjector->NumVectors(),
00032 true )
00033 {
00034 const int rowColCount = rightProjector->NumVectors();
00035
00036 if (isMasterProcess())
00037 {
00038 Array<int> entryIndices(rowColCount);
00039 for (int iCol = 0; iCol < entryIndices.size(); ++iCol) {
00040 entryIndices[iCol] = iCol;
00041 }
00042
00043 for (int iRow = 0; iRow < rowColCount; ++iRow) {
00044 const int err = reducedGraph_.InsertGlobalIndices(iRow, rowColCount, entryIndices.getRawPtr());
00045 TEUCHOS_ASSERT(err == 0);
00046 }
00047 }
00048
00049 {
00050 const Epetra_LocalMap replicationMap(rowColCount, 0, rightProjector->Comm());
00051 const int err = reducedGraph_.FillComplete(replicationMap, replicationMap);
00052 TEUCHOS_ASSERT(err == 0);
00053 }
00054
00055 {
00056 const int err = reducedGraph_.OptimizeStorage();
00057 TEUCHOS_ASSERT(err == 0);
00058 }
00059 }
00060
00061 void ReducedJacobianFactory::fullJacobianIs(const Epetra_Operator &op) {
00062 const int err = op.Apply(*rightProjector_, *premultipliedRightProjector_);
00063 TEUCHOS_ASSERT(err == 0);
00064 }
00065
00066 RCP<Epetra_CrsMatrix> ReducedJacobianFactory::reducedMatrixNew() const
00067 {
00068 return rcp(new Epetra_CrsMatrix(Copy, reducedGraph_));
00069 }
00070
00071 const Epetra_CrsMatrix &ReducedJacobianFactory::reducedMatrix(const Epetra_MultiVector &leftProjector,
00072 Epetra_CrsMatrix &result) const
00073 {
00074 TEUCHOS_ASSERT(leftProjector.NumVectors() == rightProjector_->NumVectors());
00075 TEUCHOS_ASSERT(result.Filled());
00076
00077 Ptr<const int> entryIndices;
00078 if (isMasterProcess())
00079 {
00080 int dummyEntryCount;
00081 int *entryIndicesTemp;
00082 const int err = reducedGraph_.ExtractMyRowView(0, dummyEntryCount, entryIndicesTemp);
00083 TEUCHOS_ASSERT(err == 0);
00084 entryIndices = ptr(entryIndicesTemp);
00085 }
00086
00087 Epetra_Vector rowVector(result.RangeMap(), false);
00088 for (int iRow = 0; iRow < leftProjector.NumVectors(); ++iRow) {
00089 {
00090 const int err = reduce(*premultipliedRightProjector_, *(leftProjector)(iRow), rowVector);
00091 TEUCHOS_ASSERT(err == 0);
00092 }
00093 if (isMasterProcess())
00094 {
00095 const int err = result.ReplaceMyValues(iRow, rightProjector_->NumVectors(), rowVector.Values(), entryIndices.get());
00096 TEUCHOS_ASSERT(err == 0);
00097 }
00098 }
00099
00100 return result;
00101 }
00102
00103 bool ReducedJacobianFactory::isMasterProcess() const
00104 {
00105 return rightProjector_->Comm().MyPID() == 0;
00106 }
00107
00108 }