177 typedef Thyra::TpetraOperatorVectorExtraction<SC,LO,GO,NO> TOVE_Type;
179 Teuchos::RCP<TpetraMultiVector_Type> tMV = TOVE_Type::getTpetraMultiVector( thyraMV );
183template <
class SC,
class LO,
class GO,
class NO>
184void MultiVector<SC,LO,GO,NO>::norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms)
const {
185 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in norm2 is null.")
186 multiVector_->norm2(norms);
190template <class SC, class LO, class GO, class NO>
191void MultiVector<SC,LO,GO,NO>::normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &normsInf)
const {
192 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in normInf is null.")
193 multiVector_->normInf(normsInf);
197template <class SC, class LO, class GO, class NO>
198void MultiVector<SC,LO,GO,NO>::abs(MultiVectorConstPtr_Type a) {
199 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in abs is null.")
200 multiVector_->abs( *a->getTpetraMultiVector());
203template <class SC, class LO, class GO, class NO>
204void MultiVector<SC,LO,GO,NO>::dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots)
const {
205 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in dot is null.")
206 multiVector_->dot( *a->getTpetraMultiVector(), dots );
209template <class SC, class LO, class GO, class NO>
210void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta) {
211 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.")
212 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta );
215template <class SC, class LO, class GO, class NO>
216void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma) {
217 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.")
219 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta, *B.getTpetraMultiVector(), gamma );
223template <class SC, class LO, class GO, class NO>
224void MultiVector<SC,LO,GO,NO>::putScalar( const SC& alpha ){
225 multiVector_->putScalar( alpha );
228template <
class SC,
class LO,
class GO,
class NO>
229void MultiVector<SC,LO,GO,NO>::scale(
const SC& alpha ){
230 multiVector_->scale( alpha );
233template <
class SC,
class LO,
class GO,
class NO>
234void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B,
const SC &beta){
235 multiVector_->multiply( transA, transB, alpha, *A->getTpetraMultiVector(), *B->getTpetraMultiVector(), beta );
237template <
class SC,
class LO,
class GO,
class NO>
238void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B,
const SC &beta){
242 for (
int i=0; i<A->size(); i++){
243 MultiVectorConstPtr_Type a = A->getBlock(i);
244 MultiVectorConstPtr_Type b = B->getBlock(i);
246 this->multiply( transA, transB, alpha, a, b, beta );
248 this->multiply( transA, transB, alpha, a, b, Teuchos::ScalarTraits<SC>::one() );
253template <
class SC,
class LO,
class GO,
class NO>
254void MultiVector<SC,LO,GO,NO>::importFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseImport, std::string combineMode, std::string type) {
256 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for fillFromVector have different number of vectors.")
258 if ( importer_.is_null() || !reuseImport) {
260 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
261 else if(type==
"Reverse")
262 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
264 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse")
267 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getSourceMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Importer and Multivector are not the same.")
268 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getTargetMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Importer and Multivector are not the same.")
272 if (type==
"Forward") {
273 if ( !combineMode.compare(
"Insert") )
274 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
275 else if ( !combineMode.compare(
"Add") )
276 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
278 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
280 else if(type==
"Reverse"){
281 if ( !combineMode.compare(
"Insert") )
282 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
283 else if ( !combineMode.compare(
"Add") )
284 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
286 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
289 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse")
292template <
class SC,
class LO,
class GO,
class NO>
293void MultiVector<SC,LO,GO,NO>::exportFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseExport, std::string combineMode, std::string type) {
294 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for exportToVector have different number of vectors.")
296 if ( exporter_.is_null() || !reuseExport) {
298 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
299 else if(type==
"Reverse")
300 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
302 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse")
305 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getSourceMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Exporter and Multivector are not the same.")
306 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getTargetMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Exporter and Multivector are not the same.")
308 if (type==
"Forward") {
309 if ( !combineMode.compare(
"Insert") )
310 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
311 else if ( !combineMode.compare(
"Add") )
312 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
314 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
316 else if (type==
"Reverse") {
317 if ( !combineMode.compare(
"Insert") )
318 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
319 else if ( !combineMode.compare(
"Add") )
320 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
322 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
325 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse")
328template <
class SC,
class LO,
class GO,
class NO>
329void MultiVector<SC,LO,GO,NO>::writeMM(std::string fileName)
const{
330 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.")
332 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
341 Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter;
343 tpetraWriter.writeDenseFile(fileName, multiVector_,
"multivector",
"");
347template <class SC, class LO, class GO, class NO>
348void MultiVector<SC,LO,GO,NO>::readMM(std::
string fileName)
const{
349 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.")
351 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
352 typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr;
354 typedef Tpetra::
MultiVector<SC,LO,GO,NO> TpetraMultiVector;
355 typedef Teuchos::RCP<TpetraMultiVector> TpetraMultiVectorPtr;
357 typedef Tpetra::
Map<LO,GO,NO> TpetraMap;
358 typedef Teuchos::RCP<TpetraMap> TpetraMapPtr;
360 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
363 TpetraMultiVectorPtr tpetraMultiVector = multiVector_;
365 Teuchos::RCP<const Tpetra::
Map<LO,GO,NO> > tpetraMap = tpetraMultiVector->getMap();
367 Tpetra::MatrixMarket::Reader< TpetraCrsMatrix > tpetraReader;
369 tpetraMultiVector = tpetraReader.readDenseFile(fileName, multiVector_->getMap()->getComm() ,tpetraMap);
371 for (UN j=0; j<this->getNumVectors(); j++) {
372 Teuchos::ArrayRCP< const SC > valuesIn = tpetraMultiVector->getData(j);
373 Teuchos::ArrayRCP< SC > valuesThis = this->getDataNonConst(j);
374 for (UN i=0; i<valuesThis.size(); i++)
375 valuesThis[i] = valuesIn[i];
382template <
class SC,
class LO,
class GO,
class NO>
383typename MultiVector<SC,LO,GO,NO>::MultiVectorConstPtr_Type MultiVector<SC,LO,GO,NO>::getVector(
int i )
const{
385 TpetraMultiVectorConstPtr_Type tpetraMV = multiVector_->getVector( i );
386 TpetraMultiVectorPtr_Type tpetraMVNonConst = Teuchos::rcp_const_cast<TpetraMultiVector_Type>( tpetraMV );
387 MultiVectorConstPtr_Type singleMV = Teuchos::rcp(
new const MultiVector_Type ( tpetraMVNonConst ) );
392template <
class SC,
class LO,
class GO,
class NO>
393typename MultiVector<SC,LO,GO,NO>::MultiVectorPtr_Type MultiVector<SC,LO,GO,NO>::sumColumns()
const{
395 MultiVectorPtr_Type sumMV = Teuchos::rcp(
new MultiVector_Type ( map_, 1 ) );
396 sumMV->putScalar(0.);
397 for (
int i=0; i<this->getNumVectors(); i++)
398 sumMV->getTpetraMultiVectorNonConst()->getVectorNonConst(0)->update( 1., *multiVector_->getVector(i), 1. );
403template <
class SC,
class LO,
class GO,
class NO>
404SC MultiVector<SC,LO,GO,NO>::getMax()
const{
405 TEUCHOS_TEST_FOR_EXCEPTION( this->getNumVectors() > 1, std::runtime_error,
"numMultiVector>1: max function not implemented!")
406 return multiVector_->getVector(0)->normInf();