00001
00002
00003
00004
00005
00006 #include "MOR_ReducedSpace.hpp"
00007
00008 #include "MOR_BasisOps.hpp"
00009
00010 #include "Teuchos_TestForException.hpp"
00011
00012 namespace MOR {
00013
00014 using Teuchos::RCP;
00015 using Teuchos::rcp;
00016
00017 ReducedSpace::ReducedSpace(const Teuchos::RCP<const Epetra_MultiVector> &orthogonalBasis) :
00018 basis_(orthogonalBasis),
00019 projector_(basis_),
00020 componentMap_(createComponentMap(this->basis()))
00021 {
00022
00023 }
00024
00025 ReducedSpace::ReducedSpace(const Epetra_MultiVector &orthogonalBasis) :
00026 basis_(new Epetra_MultiVector(orthogonalBasis)),
00027 projector_(basis_),
00028 componentMap_(createComponentMap(this->basis()))
00029 {
00030
00031 }
00032
00033 ReducedSpace::ReducedSpace(
00034 const Teuchos::RCP<const Epetra_MultiVector> &basis,
00035 const Teuchos::RCP<const Epetra_MultiVector> &projector) :
00036 basis_(basis),
00037 projector_(projector),
00038 componentMap_(createComponentMap(this->basis()))
00039 {
00040
00041 TEUCHOS_TEST_FOR_EXCEPT(!this->basis().Map().SameAs(this->projector().Map()));
00042 }
00043
00044 ReducedSpace::~ReducedSpace()
00045 {
00046
00047 }
00048
00049 int ReducedSpace::basisSize() const
00050 {
00051 return basis().NumVectors();
00052 }
00053
00054 const Epetra_Comm &ReducedSpace::comm() const
00055 {
00056 return basis().Comm();
00057 }
00058
00059 const Epetra_BlockMap &ReducedSpace::basisMap() const
00060 {
00061 return basis().Map();
00062 }
00063
00064 const Epetra_MultiVector &ReducedSpace::linearExpansion(const Epetra_MultiVector &reducedVector,
00065 Epetra_MultiVector &target) const
00066 {
00067 const int err = expand(this->basis(), reducedVector, target);
00068 TEUCHOS_TEST_FOR_EXCEPT(err != 0);
00069 return target;
00070 }
00071
00072 RCP<Epetra_MultiVector> ReducedSpace::linearExpansion(const Epetra_MultiVector &reducedVector) const
00073 {
00074 RCP<Epetra_MultiVector> result = rcp(new Epetra_MultiVector(this->basisMap(),
00075 reducedVector.NumVectors(),
00076 false));
00077 this->linearExpansion(reducedVector, *result);
00078 return result;
00079 }
00080
00081 RCP<Epetra_Vector> ReducedSpace::linearExpansion(const Epetra_Vector &reducedVector) const
00082 {
00083 RCP<Epetra_Vector> result = rcp(new Epetra_Vector(this->basisMap(), false));
00084 this->linearExpansion(reducedVector, *result);
00085 return result;
00086 }
00087
00088 const Epetra_MultiVector &ReducedSpace::linearReduction(const Epetra_MultiVector &fullVector,
00089 Epetra_MultiVector &target) const
00090 {
00091 const int err = reduce(this->projector(), fullVector, target);
00092 TEUCHOS_TEST_FOR_EXCEPT(err != 0);
00093 return target;
00094 }
00095
00096 RCP<Epetra_MultiVector> ReducedSpace::linearReduction(const Epetra_MultiVector &fullVector) const
00097 {
00098 RCP<Epetra_MultiVector> result = rcp(new Epetra_MultiVector(this->componentMap(),
00099 fullVector.NumVectors(),
00100 false));
00101 this->linearReduction(fullVector, *result);
00102 return result;
00103 }
00104
00105 RCP<Epetra_Vector> ReducedSpace::linearReduction(const Epetra_Vector &fullVector) const
00106 {
00107 RCP<Epetra_Vector> result = rcp(new Epetra_Vector(this->componentMap(), false));
00108 this->linearReduction(fullVector, *result);
00109 return result;
00110 }
00111
00112 LinearReducedSpace::LinearReducedSpace(const Teuchos::RCP<const Epetra_MultiVector> &orthogonalBasis) :
00113 ReducedSpace(orthogonalBasis)
00114 {
00115
00116 }
00117
00118 LinearReducedSpace::LinearReducedSpace(const Epetra_MultiVector &orthogonalBasis) :
00119 ReducedSpace(orthogonalBasis)
00120 {
00121
00122 }
00123
00124 LinearReducedSpace::LinearReducedSpace(
00125 const Teuchos::RCP<const Epetra_MultiVector> &basis,
00126 const Teuchos::RCP<const Epetra_MultiVector> &projector) :
00127 ReducedSpace(basis, projector)
00128 {
00129
00130 }
00131
00132 RCP<Epetra_MultiVector> LinearReducedSpace::expansion(const Epetra_MultiVector &reducedVector) const
00133 {
00134 return linearExpansion(reducedVector);
00135 }
00136
00137 RCP<Epetra_Vector> LinearReducedSpace::expansion(const Epetra_Vector &reducedVector) const
00138 {
00139 return linearExpansion(reducedVector);
00140 }
00141
00142 const Epetra_MultiVector &LinearReducedSpace::expansion(const Epetra_MultiVector &reducedVector,
00143 Epetra_MultiVector &target) const
00144 {
00145 return linearExpansion(reducedVector, target);
00146 }
00147
00148 RCP<Epetra_MultiVector> LinearReducedSpace::reduction(const Epetra_MultiVector &fullVector) const
00149 {
00150 return linearReduction(fullVector);
00151 }
00152
00153 RCP<Epetra_Vector> LinearReducedSpace::reduction(const Epetra_Vector &fullVector) const
00154 {
00155 return linearReduction(fullVector);
00156 }
00157
00158 const Epetra_MultiVector &LinearReducedSpace::reduction(const Epetra_MultiVector &fullVector,
00159 Epetra_MultiVector &target) const
00160 {
00161 return linearReduction(fullVector, target);
00162 }
00163
00164 AffineReducedSpace::AffineReducedSpace(const Teuchos::RCP<const Epetra_MultiVector> &orthogonalBasis,
00165 const Epetra_Vector &origin) :
00166 ReducedSpace(orthogonalBasis),
00167 origin_(origin)
00168 {
00169 TEUCHOS_TEST_FOR_EXCEPT(!this->basis().Map().SameAs(this->origin().Map()));
00170 }
00171
00172 AffineReducedSpace::AffineReducedSpace(const Epetra_MultiVector &orthogonalBasis,
00173 const Epetra_Vector &origin) :
00174 ReducedSpace(orthogonalBasis),
00175 origin_(origin)
00176 {
00177 TEUCHOS_TEST_FOR_EXCEPT(!this->basis().Map().SameAs(this->origin().Map()));
00178 }
00179
00180 AffineReducedSpace::AffineReducedSpace(
00181 const Teuchos::RCP<const Epetra_MultiVector> &basis,
00182 const Teuchos::RCP<const Epetra_MultiVector> &projector,
00183 const Epetra_Vector &origin) :
00184 ReducedSpace(basis, projector),
00185 origin_(origin)
00186 {
00187 TEUCHOS_TEST_FOR_EXCEPT(!this->basis().Map().SameAs(this->origin().Map()));
00188 }
00189
00190 void AffineReducedSpace::addLinearExpansion(const Epetra_MultiVector &reducedVector,
00191 Epetra_MultiVector &target) const
00192 {
00193 const int err = expandAdd(this->basis(), reducedVector, target);
00194 TEUCHOS_TEST_FOR_EXCEPT(err != 0);
00195 }
00196
00197 RCP<Epetra_MultiVector> AffineReducedSpace::expansion(const Epetra_MultiVector &reducedVector) const
00198 {
00199 const int vectorCount = reducedVector.NumVectors();
00200 const RCP<Epetra_MultiVector> result = rcp(new Epetra_MultiVector(this->basisMap(),
00201 vectorCount,
00202 false));
00203 for (int i = 0; i < vectorCount; ++i) {
00204 Epetra_Vector &v = *(*result)(i);
00205 v = origin_;
00206 }
00207
00208 addLinearExpansion(reducedVector, *result);
00209 return result;
00210 }
00211
00212 RCP<Epetra_Vector> AffineReducedSpace::expansion(const Epetra_Vector &reducedVector) const
00213 {
00214 RCP<Epetra_Vector> result = rcp(new Epetra_Vector(origin_));
00215 addLinearExpansion(reducedVector, *result);
00216 return result;
00217 }
00218
00219 const Epetra_MultiVector &AffineReducedSpace::expansion(const Epetra_MultiVector &reducedVector,
00220 Epetra_MultiVector &target) const
00221 {
00222 target = origin_;
00223 addLinearExpansion(reducedVector, target);
00224 return target;
00225 }
00226
00227 void AffineReducedSpace::substractOrigin(Epetra_Vector &target) const
00228 {
00229 const int err = target.Update(-1.0, origin_, 1.0);
00230 TEUCHOS_TEST_FOR_EXCEPT(err != 0);
00231 }
00232
00233 void AffineReducedSpace::substractOrigin(Epetra_MultiVector &target) const
00234 {
00235 for (int i = 0, i_end = target.NumVectors(); i < i_end; ++i) {
00236 substractOrigin(*target(i));
00237 }
00238 }
00239
00240 template <typename Epetra_MultiVectorT>
00241 void AffineReducedSpace::computeReduction(const Epetra_MultiVectorT &fullVector,
00242 Epetra_MultiVectorT &target) const
00243 {
00244 Epetra_MultiVectorT temp(fullVector);
00245 substractOrigin(temp);
00246 linearReduction(temp, target);
00247 }
00248
00249 RCP<Epetra_MultiVector> AffineReducedSpace::reduction(const Epetra_MultiVector &fullVector) const
00250 {
00251 RCP<Epetra_MultiVector> result = rcp(new Epetra_MultiVector(this->componentMap(),
00252 fullVector.NumVectors(),
00253 false));
00254 computeReduction(fullVector, *result);
00255 return result;
00256 }
00257
00258 RCP<Epetra_Vector> AffineReducedSpace::reduction(const Epetra_Vector &fullVector) const
00259 {
00260 RCP<Epetra_Vector> result = rcp(new Epetra_Vector(this->componentMap(), false));
00261 computeReduction(fullVector, *result);
00262 return result;
00263 }
00264
00265 const Epetra_MultiVector &AffineReducedSpace::reduction(const Epetra_MultiVector &fullVector,
00266 Epetra_MultiVector &target) const
00267 {
00268 computeReduction(fullVector, target);
00269 return target;
00270 }
00271
00272 }