182template <
class SC,
class LO,
class GO,
class NO>
183void MultiVector<SC,LO,GO,NO>::fromThyraMultiVector( Teuchos::RCP< Thyra::MultiVectorBase<SC> > thyraMV){
185 typedef Thyra::TpetraOperatorVectorExtraction<SC,LO,GO,NO> TOVE_Type;
187 Teuchos::RCP<TpetraMultiVector_Type> tMV = TOVE_Type::getTpetraMultiVector( thyraMV );
191template <
class SC,
class LO,
class GO,
class NO>
192void MultiVector<SC,LO,GO,NO>::norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<SC>::magnitudeType> &norms)
const {
193 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in norm2 is null.")
194 multiVector_->norm2(norms);
198template <class SC, class LO, class GO, class NO>
199void MultiVector<SC,LO,GO,NO>::normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &normsInf)
const {
200 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in normInf is null.")
201 multiVector_->normInf(normsInf);
205template <class SC, class LO, class GO, class NO>
206void MultiVector<SC,LO,GO,NO>::abs(MultiVectorConstPtr_Type a) {
207 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in abs is null.")
208 multiVector_->abs( *a->getTpetraMultiVector());
211template <class SC, class LO, class GO, class NO>
212void MultiVector<SC,LO,GO,NO>::dot(MultiVectorConstPtr_Type a, const Teuchos::ArrayView< typename Teuchos::ScalarTraits<SC>::magnitudeType> &dots)
const {
213 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in dot is null.")
214 multiVector_->dot( *a->getTpetraMultiVector(), dots );
217template <class SC, class LO, class GO, class NO>
218void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta) {
219 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.")
220 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta );
223template <class SC, class LO, class GO, class NO>
224void MultiVector<SC,LO,GO,NO>::update( const SC& alpha, const MultiVector_Type& A, const SC& beta , const MultiVector_Type& B, const SC& gamma) {
225 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != A.getNumVectors(), std::logic_error,
"MultiVectors for update have different number of vectors.")
227 multiVector_->update( alpha, *A.getTpetraMultiVector(), beta, *B.getTpetraMultiVector(), gamma );
231template <class SC, class LO, class GO, class NO>
232void MultiVector<SC,LO,GO,NO>::putScalar( const SC& alpha ){
233 multiVector_->putScalar( alpha );
236template <
class SC,
class LO,
class GO,
class NO>
237void MultiVector<SC,LO,GO,NO>::scale(
const SC& alpha ){
238 multiVector_->scale( alpha );
241template <
class SC,
class LO,
class GO,
class NO>
242void MultiVector<SC,LO,GO,NO>::multiply(Teuchos::ETransp transA, Teuchos::ETransp transB,
const SC &alpha, MultiVectorConstPtr_Type &A, MultiVectorConstPtr_Type &B,
const SC &beta){
243 multiVector_->multiply( transA, transB, alpha, *A->getTpetraMultiVector(), *B->getTpetraMultiVector(), beta );
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, BlockMultiVectorConstPtr_Type &A, BlockMultiVectorConstPtr_Type &B,
const SC &beta){
250 for (
int i=0; i<A->size(); i++){
251 MultiVectorConstPtr_Type a = A->getBlock(i);
252 MultiVectorConstPtr_Type b = B->getBlock(i);
254 this->multiply( transA, transB, alpha, a, b, beta );
256 this->multiply( transA, transB, alpha, a, b, Teuchos::ScalarTraits<SC>::one() );
261template <
class SC,
class LO,
class GO,
class NO>
262void MultiVector<SC,LO,GO,NO>::importFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseImport, std::string combineMode, std::string type) {
264 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for fillFromVector have different number of vectors.")
266 if ( importer_.is_null() || !reuseImport) {
268 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
269 else if(type==
"Reverse")
270 importer_ = Teuchos::RCP(
new Tpetra::Import<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
272 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse")
275 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getSourceMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Importer and Multivector are not the same.")
276 TEUCHOS_TEST_FOR_EXCEPTION( !importer_->getTargetMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Importer and Multivector are not the same.")
280 if (type==
"Forward") {
281 if ( !combineMode.compare(
"Insert") )
282 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
283 else if ( !combineMode.compare(
"Add") )
284 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
286 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
288 else if(type==
"Reverse"){
289 if ( !combineMode.compare(
"Insert") )
290 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::INSERT);
291 else if ( !combineMode.compare(
"Add") )
292 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *importer_, Tpetra::ADD);
294 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
297 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for import. Choose Forward or Reverse")
300template <
class SC,
class LO,
class GO,
class NO>
301void MultiVector<SC,LO,GO,NO>::exportFromVector( MultiVectorConstPtr_Type mvIn,
bool reuseExport, std::string combineMode, std::string type) {
302 TEUCHOS_TEST_FOR_EXCEPTION( getNumVectors() != mvIn->getNumVectors(), std::logic_error,
"MultiVectors for exportToVector have different number of vectors.")
304 if ( exporter_.is_null() || !reuseExport) {
306 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(mvIn->getMapTpetra(), this->getMapTpetra() ));
307 else if(type==
"Reverse")
308 exporter_ = Teuchos::RCP(
new Tpetra::Export<LO, GO, NO>(this->getMapTpetra(), mvIn->getMapTpetra() ));
310 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse")
313 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getSourceMap()->isSameAs( *this->getMap()->getTpetraMap() ), std::logic_error,
"Source maps of Exporter and Multivector are not the same.")
314 TEUCHOS_TEST_FOR_EXCEPTION( !exporter_->getTargetMap()->isSameAs( *mvIn->getMap()->getTpetraMap() ), std::logic_error,
"Target maps of Exporter and Multivector are not the same.")
316 if (type==
"Forward") {
317 if ( !combineMode.compare(
"Insert") )
318 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
319 else if ( !combineMode.compare(
"Add") )
320 multiVector_->doExport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
322 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
324 else if (type==
"Reverse") {
325 if ( !combineMode.compare(
"Insert") )
326 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::INSERT);
327 else if ( !combineMode.compare(
"Add") )
328 multiVector_->doImport ( *mvIn->getTpetraMultiVector(), *exporter_, Tpetra::ADD);
330 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown combine mode.")
333 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Unknown type for export. Choose Forward or Reverse")
336template <
class SC,
class LO,
class GO,
class NO>
337void MultiVector<SC,LO,GO,NO>::writeMM(std::string fileName)
const{
338 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.")
340 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
349 Tpetra::MatrixMarket::Writer< TpetraCrsMatrix > tpetraWriter;
351 tpetraWriter.writeDenseFile(fileName, multiVector_,
"multivector",
"");
355template <class SC, class LO, class GO, class NO>
356void MultiVector<SC,LO,GO,NO>::readMM(std::
string fileName)
const{
357 TEUCHOS_TEST_FOR_EXCEPTION( multiVector_.is_null(), std::runtime_error,
"MultiVector in writeMM is null.")
359 typedef Tpetra::CrsMatrix<SC,LO,GO,NO> TpetraCrsMatrix;
360 typedef Teuchos::RCP<TpetraCrsMatrix> TpetraCrsMatrixPtr;
362 typedef Tpetra::
MultiVector<SC,LO,GO,NO> TpetraMultiVector;
363 typedef Teuchos::RCP<TpetraMultiVector> TpetraMultiVectorPtr;
365 typedef Tpetra::
Map<LO,GO,NO> TpetraMap;
366 typedef Teuchos::RCP<TpetraMap> TpetraMapPtr;
368 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
371 TpetraMultiVectorPtr tpetraMultiVector = multiVector_;
373 Teuchos::RCP<const Tpetra::
Map<LO,GO,NO> > tpetraMap = tpetraMultiVector->getMap();
375 Tpetra::MatrixMarket::Reader< TpetraCrsMatrix > tpetraReader;
377 tpetraMultiVector = tpetraReader.readDenseFile(fileName, multiVector_->getMap()->getComm() ,tpetraMap);
379 for (UN j=0; j<this->getNumVectors(); j++) {
380 Teuchos::ArrayRCP< const SC > valuesIn = tpetraMultiVector->getData(j);
381 Teuchos::ArrayRCP< SC > valuesThis = this->getDataNonConst(j);
382 for (UN i=0; i<valuesThis.size(); i++)
383 valuesThis[i] = valuesIn[i];
390template <
class SC,
class LO,
class GO,
class NO>
391typename MultiVector<SC,LO,GO,NO>::MultiVectorConstPtr_Type MultiVector<SC,LO,GO,NO>::getVector(
int i )
const{
393 TpetraMultiVectorConstPtr_Type tpetraMV = multiVector_->getVector( i );
394 TpetraMultiVectorPtr_Type tpetraMVNonConst = Teuchos::rcp_const_cast<TpetraMultiVector_Type>( tpetraMV );
395 MultiVectorConstPtr_Type singleMV = Teuchos::rcp(
new const MultiVector_Type ( tpetraMVNonConst ) );
400template <
class SC,
class LO,
class GO,
class NO>
401typename MultiVector<SC,LO,GO,NO>::MultiVectorPtr_Type MultiVector<SC,LO,GO,NO>::sumColumns()
const{
403 MultiVectorPtr_Type sumMV = Teuchos::rcp(
new MultiVector_Type ( map_, 1 ) );
404 sumMV->putScalar(0.);
405 for (
int i=0; i<this->getNumVectors(); i++)
406 sumMV->getTpetraMultiVectorNonConst()->getVectorNonConst(0)->update( 1., *multiVector_->getVector(i), 1. );
411template <
class SC,
class LO,
class GO,
class NO>
412SC MultiVector<SC,LO,GO,NO>::getMax()
const{
413 TEUCHOS_TEST_FOR_EXCEPTION( this->getNumVectors() > 1, std::runtime_error,
"numMultiVector>1: max function not implemented!")
414 return multiVector_->getVector(0)->normInf();