182template <
class SC,
class LO,
class GO,
class NO>
183void MultiVector<SC,LO,GO,NO>::fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV){
185 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector is null but we need to know the underlying lib for function fromThyraMultiVector().");
187 typedef Thyra::TpetraOperatorVectorExtraction<SC,LO,GO,NO> TOVE_Type;
189 Teuchos::RCP<TpetraMultiVector_Type> tMV = TOVE_Type::getTpetraMultiVector( thyraMV );
194template <
class SC,
class LO,
class GO,
class NO>
195void MultiVector<SC,LO,GO,NO>::norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms)
const {
196 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in norm2 is null.");
197 multiVector_->norm2(norms);
201template <
class SC,
class LO,
class GO,
class NO>
202void MultiVector<SC,LO,GO,NO>::normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<SC>::magnitudeType> &normsInf)
const {
203 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in normInf is null.");
204 multiVector_->normInf(normsInf);
208template <
class SC,
class LO,
class GO,
class NO>
209void MultiVector<SC,LO,GO,NO>::abs(MultiVectorConstPtr_Type a) {
210 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in abs is null.");
211 multiVector_->abs( *a->getTpetraMultiVector());
214template <
class SC,
class LO,
class GO,
class NO>
215void MultiVector<SC,LO,GO,NO>::dot(MultiVectorConstPtr_Type a,
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots)
const {
216 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in dot is null.");
217 multiVector_->dot( *a->getTpetraMultiVector(), dots );
220template <
class SC,
class LO,
class GO,
class NO>
221void MultiVector<SC,LO,GO,NO>::update(
const SC& alpha,
const MultiVector_Type& A,
const SC& beta) {
222 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.");
223 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta );
227template <
class SC,
class LO,
class GO,
class NO>
228void MultiVector<SC,LO,GO,NO>::update(
const SC& alpha,
const MultiVector_Type& A,
const SC& beta ,
const MultiVector_Type& B,
const SC& gamma) {
229 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.");
231 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta, *B.getTpetraMultiVector(), gamma );
235template <
class SC,
class LO,
class GO,
class NO>
236void MultiVector<SC,LO,GO,NO>::putScalar(
const SC& alpha ){
237 multiVector_->putScalar( alpha );
240template <
class SC,
class LO,
class GO,
class NO>
241void MultiVector<SC,LO,GO,NO>::scale(
const SC& alpha ){
242 multiVector_->scale( alpha );
245template <
class SC,
class LO,
class GO,
class NO>
246void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B,
const SC &beta){
247 multiVector_->multiply( transA, transB, alpha, *A->getTpetraMultiVector(), *B->getTpetraMultiVector(), beta );
249template <
class SC,
class LO,
class GO,
class NO>
250void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const SC &alpha, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B,
const SC &beta){
254 for (
int i=0; i<A->size(); i++){
255 MultiVectorConstPtr_Type a = A->getBlock(i);
256 MultiVectorConstPtr_Type b = B->getBlock(i);
258 this->multiply( transA, transB, alpha, a, b, beta );
260 this->multiply( transA, transB, alpha, a, b, Teuchos::ScalarTraits<SC>::one() );
265template <
class SC,
class LO,
class GO,
class NO>
266void MultiVector<SC,LO,GO,NO>::importFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseImport, std::string combineMode, std::string type) {
268 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for fillFromVector have different number of vectors.");
270 if ( importer_.is_null() || !reuseImport) {
272 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
273 else if(type==
"Reverse")
274 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
276 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse");
279 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getSourceMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Importer and Multivector are not the same.");
280 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getTargetMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Importer and Multivector are not the same.");
284 if (type==
"Forward") {
285 if ( !combineMode.compare(
"Insert") )
286 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
287 else if ( !combineMode.compare(
"Add") )
288 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
290 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.");
292 else if(type==
"Reverse"){
293 if ( !combineMode.compare(
"Insert") )
294 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
295 else if ( !combineMode.compare(
"Add") )
296 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
298 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.");
301 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse");
304template <
class SC,
class LO,
class GO,
class NO>
305void MultiVector<SC,LO,GO,NO>::exportFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseExport, std::string combineMode, std::string type) {
306 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for exportToVector have different number of vectors.");
308 if ( exporter_.is_null() || !reuseExport) {
310 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
311 else if(type==
"Reverse")
312 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
314 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse");
317 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getSourceMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Exporter and Multivector are not the same.");
318 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getTargetMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Exporter and Multivector are not the same.");
320 if (type==
"Forward") {
321 if ( !combineMode.compare(
"Insert") )
322 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
323 else if ( !combineMode.compare(
"Add") )
324 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
326 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.");
328 else if (type==
"Reverse") {
329 if ( !combineMode.compare(
"Insert") )
330 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
331 else if ( !combineMode.compare(
"Add") )
332 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
334 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.");
337 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse");
340template <
class SC,
class LO,
class GO,
class NO>
341void MultiVector<SC,LO,GO,NO>::writeMM(std::string fileName)
const{
342 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.");
344 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
353 Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter;
355 tpetraWriter.writeDenseFile(fileName, multiVector_,
"multivector",
"");
359template <
class SC,
class LO,
class GO,
class NO>
360void MultiVector<SC,LO,GO,NO>::readMM(std::string fileName)
const{
361 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.");
363 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
364 typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr;
366 typedef Tpetra::MultiVector<SC,LO,GO,NO> TpetraMultiVector;
367 typedef Teuchos::RCP<TpetraMultiVector> TpetraMultiVectorPtr;
369 typedef Tpetra::Map<LO,GO,NO> TpetraMap;
370 typedef Teuchos::RCP<TpetraMap> TpetraMapPtr;
372 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
375 TpetraMultiVectorPtr tpetraMultiVector = multiVector_;
377 Teuchos::RCP<const Tpetra::Map<LO,GO,NO> > tpetraMap = tpetraMultiVector->getMap();
379 Tpetra::MatrixMarket::Reader< TpetraCrsMatrix > tpetraReader;
381 tpetraMultiVector = tpetraReader.readDenseFile(fileName, multiVector_->getMap()->getComm() ,tpetraMap);
383 for (UN j=0; j<this->getNumVectors(); j++) {
384 Teuchos::ArrayRCP< const SC > valuesIn = tpetraMultiVector->getData(j);
385 Teuchos::ArrayRCP< SC > valuesThis = this->getDataNonConst(j);
386 for (UN i=0; i<valuesThis.size(); i++)
387 valuesThis[i] = valuesIn[i];
394template <
class SC,
class LO,
class GO,
class NO>
395typename MultiVector<SC,LO,GO,NO>::MultiVectorConstPtr_Type MultiVector<SC,LO,GO,NO>::getVector(
int i )
const{
397 TpetraMultiVectorConstPtr_Type tpetraMV = multiVector_->getVector( i );
398 TpetraMultiVectorPtr_Type tpetraMVNonConst = Teuchos::rcp_const_cast<TpetraMultiVector_Type>( tpetraMV );
399 MultiVectorConstPtr_Type singleMV = Teuchos::rcp(
new const MultiVector_Type ( tpetraMVNonConst ) );
404template <
class SC,
class LO,
class GO,
class NO>
405typename MultiVector<SC,LO,GO,NO>::MultiVectorPtr_Type MultiVector<SC,LO,GO,NO>::sumColumns()
const{
407 MultiVectorPtr_Type sumMV = Teuchos::rcp(
new MultiVector_Type ( map_, 1 ) );
408 sumMV->putScalar(0.);
409 for (
int i=0; i<this->getNumVectors(); i++)
410 sumMV->getTpetraMultiVectorNonConst()->getVectorNonConst(0)->update( 1., *multiVector_->getVector(i), 1. );
415template <
class SC,
class LO,
class GO,
class NO>
416SC MultiVector<SC,LO,GO,NO>::getMax()
const{
417 TEUCHOS_TEST_FOR_EXCEPTION( this->getNumVectors() > 1, std::runtime_error,
"numMultiVector>1: max function not implemented!");
418 return multiVector_->getVector(0)->normInf();