All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_BlockedCrsMatrix.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jeremie Gaidamour (jngaida@sandia.gov)
40 // Jonathan Hu (jhu@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 /*
47  * Xpetra_BlockedCrsMatrix.hpp
48  *
49  * Created on: Aug 17, 2011
50  * Author: wiesner
51  */
52 
53 // WARNING: This code is experimental. Backwards compatibility should not be expected.
54 
55 #ifndef XPETRA_BLOCKEDCRSMATRIX_HPP
56 #define XPETRA_BLOCKEDCRSMATRIX_HPP
57 
58 #include <Kokkos_DefaultNode.hpp>
60 
62 #include <Teuchos_Hashtable.hpp>
63 
64 #include "Xpetra_ConfigDefs.hpp"
65 #include "Xpetra_Exceptions.hpp"
66 
67 #include "Xpetra_MapFactory.hpp"
68 #include "Xpetra_MultiVector.hpp"
70 #include "Xpetra_CrsGraph.hpp"
71 #include "Xpetra_CrsMatrix.hpp"
73 
74 #include "Xpetra_MapExtractor.hpp"
75 
76 #include "Xpetra_Matrix.hpp"
77 
78 #define sumAll(rcpComm, in, out) \
79  Teuchos::reduceAll(*rcpComm, Teuchos::REDUCE_SUM, in, Teuchos::outArg(out));
80 
85 namespace Xpetra {
86 
87  typedef std::string viewLabel_t;
88 
89 template <class Scalar,
90  class LocalOrdinal = int,
91  class GlobalOrdinal = LocalOrdinal,
93  class LocalMatOps = typename Kokkos::DefaultKernels<Scalar,LocalOrdinal,Node>::SparseOps > //TODO: or BlockSparseOp ?
94 class BlockedCrsMatrix : public Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> {
95 
101 #ifdef HAVE_CTHULHU_TPETRA
103 #endif
106 
107 public:
108 
110 
111 
113 
121  size_t npr,
123  : domainmaps_(domainMaps),
124  rangemaps_(rangeMaps)
125  {
126  // Set matrix data
127  //matrixData_ = Teuchos::null; //CrsMatrixFactory::Build(rowMap, maxNumEntriesPerRow, pftype); // TODO remove me
128 
129  blocks_.reserve(Rows()*Cols());
130 
131  // add CrsMatrix objects in row,column order
132  for (size_t r=0; r<Rows(); ++r)
133  {
134  for(size_t c=0; c<Cols(); ++c)
135  {
137  blocks_.push_back(matblock);
138  }
139  }
140 
141  // Default view
143  }
144 
146  virtual ~BlockedCrsMatrix() {}
147 
149 
150 
152 
153 
155 
166  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals)
167  {
169  "insertGlobalValues not supported by BlockedCrsMatrix" );
170  }
171 
173 
180  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
182  "insertLocalValues not supported by BlockedCrsMatrix" );
183  }
184 
187  "removeEmptyProcesses not supported by BlockedCrsMatrix");
188  }
189 
191 
196  void replaceGlobalValues(GlobalOrdinal globalRow,
197  const ArrayView<const GlobalOrdinal> &cols,
198  const ArrayView<const Scalar> &vals) {
200  "replaceGlobalValues not supported by BlockedCrsMatrix" );
201  }
202 
204 
207  void replaceLocalValues(LocalOrdinal localRow,
208  const ArrayView<const LocalOrdinal> &cols,
209  const ArrayView<const Scalar> &vals) {
211  "replaceLocalValues not supported by BlockedCrsMatrix" );
212  }
213 
215  virtual void setAllToScalar(const Scalar &alpha) {
217  "setAllToScalar not supported by BlockedCrsMatrix");
218  }
219 
221  void scale(const Scalar &alpha) {
223  "scale not supported by BlockedCrsMatrix" );
224  }
225 
226 
228 
230 
231 
240  void resumeFill(const RCP< ParameterList > &params=null) {
242  "resumeFill not supported for block matrices" );
243  }
244 
256  void fillComplete(const RCP<const MapClass> &domainMap, const RCP<const MapClass> &rangeMap, const RCP<ParameterList> &params=null)
257  {
259  "fillComplete with arguments not supported for block matrices" );
260  }
261 
275  //TODO : Get ride of "Tpetra"::OptimizeOption
276  void fillComplete(const RCP<ParameterList> &params=null)
277  {
278  for (size_t r=0; r<Rows(); ++r)
279  {
280  for (size_t c=0; c<Cols(); ++c)
281  {
282  if(getMatrix(r,c)->isFillComplete() == false)
283  getMatrix(r,c)->fillComplete(getDomainMap(c),getRangeMap(r),params);
284  }
285  }
286 
287  // get full row map
288  //fullrowmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), rangemaps_->getFullMap()->getNodeNumElements(), rangemaps_->getFullMap()->getNodeElementList(), rangemaps_->getFullMap()->getIndexBase(), rangemaps_->getFullMap()->getComm());//rangemaps_->FullMap(); //->Clone();
289  fullrowmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), rangemaps_->getFullMap()->getGlobalNumElements(), rangemaps_->getFullMap()->getNodeElementList(), rangemaps_->getFullMap()->getIndexBase(), rangemaps_->getFullMap()->getComm());//rangemaps_->FullMap(); //->Clone();
290 
291  // TODO: check me, clean up, use only ArrayView instead of std::vector
292  // build full col map
293  if (fullcolmap_ == Teuchos::null)
294  {
295  std::vector<GlobalOrdinal> colmapentries;
296  for (size_t c=0; c<Cols(); ++c)
297  {
298  std::set<GlobalOrdinal> colset;
299  for (size_t r=0; r<Rows(); ++r)
300  {
301  if(getMatrix(r,c) != Teuchos::null) {
302  Teuchos::RCP<const MapClass> colmap = getMatrix(r,c)->getColMap();
303  copy(colmap->getNodeElementList().getRawPtr(),
304  colmap->getNodeElementList().getRawPtr()+colmap->getNodeNumElements(),
305  inserter(colset,colset.begin()));
306  }
307  }
308  colmapentries.reserve(colmapentries.size()+colset.size());
309  copy(colset.begin(), colset.end(), back_inserter(colmapentries));
310  sort(colmapentries.begin(), colmapentries.end());
311  typename std::vector<GlobalOrdinal>::iterator gendLocation;
312  gendLocation = std::unique(colmapentries.begin(), colmapentries.end());
313  colmapentries.erase(gendLocation,colmapentries.end());
314  }
315 
316  // sum up number of local elements
317  size_t numGlobalElements = 0;
318  sumAll(rangemaps_->getFullMap()->getComm(), colmapentries.size(), numGlobalElements)
319 
321  fullcolmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), numGlobalElements, aView, 0,rangemaps_->getFullMap()->getComm());
322  //fullcolmap_ = Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(rangemaps_->getFullMap()->lib(), domainmaps_->getFullMap()->getGlobalNumElements(), aView, 0,domainmaps_->getFullMap()->getComm());
323  }
324 
325 
326  }
327 
329 
331 
334  {
335  global_size_t globalNumRows= 0;
336  for (size_t r=0; r<Rows(); ++r)
337  {
338  globalNumRows += getMatrix(r,0)->getGlobalNumRows();
339  }
340  return globalNumRows;
341  }
342 
344 
347  {
348  global_size_t globalNumCols= 0;
349  for (size_t c=0; c<Cols(); ++c)
350  {
351  globalNumCols += getMatrix(0,c)->getGlobalNumCols();
352  }
353  return globalNumCols;
354  }
355 
357  size_t getNodeNumRows() const
358  {
359  global_size_t nodeNumRows= 0;
360  for (size_t r=0; r<Rows(); ++r)
361  {
362  nodeNumRows += getMatrix(r,0)->getNodeNumRows();
363  }
364  return nodeNumRows;
365  }
366 
369  {
370  global_size_t globalNumEntries= 0;
371  for (size_t r=0; r<Rows(); ++r)
372  {
373  for(size_t c=0; c<Cols(); ++c)
374  {
375  globalNumEntries += getMatrix(r,c)->getGlobalNumEntries();
376  }
377  }
378  return globalNumEntries;
379  }
380 
382  size_t getNodeNumEntries() const
383  {
384  global_size_t nodeNumEntries= 0;
385  for (size_t r=0; r<Rows(); ++r)
386  {
387  for(size_t c=0; c<Cols(); ++c)
388  {
389  nodeNumEntries += getMatrix(r,c)->getNodeNumEntries();
390  }
391  }
392  return nodeNumEntries;
393  }
394 
396 
397  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
398  {
400  "getNumEntriesInLocalRow not supported by BlockedCrsMatrix" );
401  return 0;
402  }
403 
405 
408  {
410  "getGlobalNumDiags() not supported by BlockedCrsMatrix" );
411  return 0;
412  }
413 
415 
417  size_t getNodeNumDiags() const
418  {
420  "getNodeNumDiags() not supported by BlockedCrsMatrix" );
421  return 0;
422  }
423 
425 
428  {
430  "getGlobalMaxNumRowEntries() not supported by BlockedCrsMatrix" );
431  return 0;
432  }
433 
435 
437  size_t getNodeMaxNumRowEntries() const
438  {
440  "getNodeMaxNumRowEntries() not supported by BlockedCrsMatrix" );
441  return 0;
442  }
443 
445 
448  bool isLocallyIndexed() const
449  {
450  for (size_t i=0; i<blocks_.size(); ++i)
451  if (not blocks_[i]->isLocallyIndexed())
452  return false;
453  return true;
454  }
455 
457 
460  bool isGloballyIndexed() const
461  {
462  for (size_t i=0; i<blocks_.size(); ++i)
463  if (not blocks_[i]->isGloballyIndexed())
464  return false;
465  return true;
466  }
467 
469  bool isFillComplete() const
470  {
471  for (size_t i=0; i<blocks_.size(); ++i)
472  if (not blocks_[i]->isFillComplete())
473  return false;
474  return true;
475  }
476 
478 
490  virtual void getLocalRowCopy(LocalOrdinal LocalRow,
491  const ArrayView<LocalOrdinal> &Indices,
492  const ArrayView<Scalar> &Values,
493  size_t &NumEntries
494  ) const
495  {
497  "getLocalRowCopy not supported by BlockedCrsMatrix" );
498  }
499 
501 
510  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const
511  {
513  "getGlobalRowView not supported by BlockedCrsMatrix" );
514  }
515 
517 
526  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const
527  {
529  "getLocalRowView not supported by BlockedCrsMatrix" );
530  }
531 
533 
536  {
538  "getLocalDiagCopy not supported by BlockedCrsMatrix" );
539  }
540 
543  {
545  "getFrobeniusNorm() not supported by BlockedCrsMatrix, yet" );
546  }
547 
549 
551 
552 
554 
563  //TODO virtual=0 // TODO: Add default parameters ?
564 // void multiply(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & X, MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y, Teuchos::ETransp trans, Scalar alpha, Scalar beta) const {
565 // matrixData_->multiply(X, Y, trans, alpha, beta);
566 // }
567 
569 
571 
572 
574 
579  Scalar alpha = ScalarTraits<Scalar>::one(),
580  Scalar beta = ScalarTraits<Scalar>::zero()) const
581  {
582  // TODO: check maps
583 
586 
587  if (mode == Teuchos::NO_TRANS)
588  {
589  for(size_t rblock=0; rblock<Rows(); ++rblock)
590  {
591  Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > rowresult = rangemaps_->getVector(rblock,Y.getNumVectors()); // end result for block row
592  Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > rowy = rangemaps_->getVector(rblock,Y.getNumVectors()); // helper vector
593  for (size_t cblock=0; cblock<Cols(); ++cblock)
594  {
596  Teuchos::RCP<CrsMatrixClass> bmat = getMatrix(rblock,cblock);
597  bmat->apply(*colx,*rowy);
598  rowresult->update(ScalarTraits< Scalar >::one(),*rowy,ScalarTraits< Scalar >::one());
599  }
600  rangemaps_->InsertVector(rowresult,rblock,tmpY);
601  }
602  Y.update(alpha,*tmpY,beta);
603  }
604  else if (mode == Teuchos::TRANS)
605  {
606  // TODO: test me!
607  for (size_t cblock = 0; cblock<Cols(); ++cblock)
608  {
609  Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > rowresult = domainmaps_->getVector(cblock,Y.getNumVectors()); // end result for block row
610  Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > rowy = domainmaps_->getVector(cblock,Y.getNumVectors()); // helper vector
611  for (size_t rblock = 0; rblock<Rows(); ++rblock)
612  {
614  Teuchos::RCP<CrsMatrixClass> bmat = getMatrix(rblock,cblock);
615  bmat->apply(*colx,*rowy,Teuchos::TRANS);
616  rowresult->update(ScalarTraits< Scalar >::one(),*rowy,ScalarTraits< Scalar >::one());
617  }
618  domainmaps_->InsertVector(rowresult,cblock,tmpY);
619  }
620  Y.update(alpha,*tmpY,beta);
621  }
622  else
624  "apply() only supports NO_TRANS and TRANS." );
625 
626  }
627 
631  {
632  return domainmaps_->getFullMap();
633  }
634 
637  const RCP<const MapClass > getDomainMap(size_t i) const
638  {
639  return domainmaps_->getMap(i);
640  }
641 
645  {
646  return rangemaps_->getFullMap();
647  }
648 
651  const RCP<const MapClass > getRangeMap(size_t i) const
652  {
653  return rangemaps_->getMap(i);
654  }
655 
658  {
659  return rangemaps_;
660  }
661 
664  {
665  return domainmaps_;
666  }
667 
669 
671  //{@
672 
675  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "BlockedCrsMatrix::getMap(): operation not supported.");
676  }
677 
679  void doImport(const Matrix &source,
681  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "BlockedCrsMatrix::doImport(): operation not supported.");
682  }
683 
685  void doExport(const Matrix &dest,
687  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "BlockedCrsMatrix::doExport(): operation not supported.");
688  }
689 
691  void doImport(const Matrix &source,
693  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "BlockedCrsMatrix::doImport(): operation not supported.");
694  }
695 
697  void doExport(const Matrix &dest,
699  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "BlockedCrsMatrix::doExport(): operation not supported.");
700  }
701 
702  // @}
703 
705 
706 
708  std::string description() const {
709  std::ostringstream oss;
710  oss << "Xpetra_BlockedCrsMatrix.description()" << std::endl;
711  return oss.str();
712  }
713 
716  // Teuchos::EVerbosityLevel vl = verbLevel;
717  // if (vl == VERB_DEFAULT) vl = VERB_LOW;
718  // RCP<const Comm<int> > comm = this->getComm();
719  // const int myImageID = comm->getRank(),
720  // numImages = comm->getSize();
721 
722  // if (myImageID == 0) out << this->description() << std::endl;
723 
724  out << "Xpetra::BlockedCrsMatrix: " << Rows() << " x " << Cols() << std::endl;
725 
726  if(isFillComplete())
727  {
728  out << "BlockMatrix is filled" << std::endl;
729  out << "fullRowMap" << std::endl;
730  fullrowmap_->describe(out,verbLevel);
731  out << "fullColMap" << std::endl;
732  fullcolmap_->describe(out,verbLevel);
733  }
734  else
735  out << "BlockMatrix is NOT filled" << std::endl;
736 
737  for (size_t r=0; r<Rows(); ++r)
738  {
739  for(size_t c=0; c<Cols(); ++c)
740  {
741  out << "Block(" << r << "," << c << ")" << std::endl;
742  getMatrix(r,c)->describe(out,verbLevel);
743  }
744  }
745 
746 
747  //matrixData_->describe(out,verbLevel);
748 
749  // Teuchos::OSTab tab(out);
750  }
751 
752  // JG: Added:
753 
756  {
758  "getCrsGraph() not supported by BlockedCrsMatrix");
759  return Teuchos::null;
760  }
761 
763 
765 
766 
768  virtual size_t Rows() const { return rangemaps_->NumMaps(); }
769 
771  virtual size_t Cols() const { return domainmaps_->NumMaps(); }
772 
774  Teuchos::RCP<CrsMatrixClass> getMatrix(size_t r, size_t c) const { return blocks_[r*Cols()+c]; }
775 
777  void setMatrix(size_t r, size_t c, Teuchos::RCP<CrsMatrixClass>& mat)
778  {
779  // TODO: if filled -> return error
780 
781  TEUCHOS_TEST_FOR_EXCEPTION(r > Rows(), std::out_of_range, "Error, r = " << Rows() << " is too big");
782  TEUCHOS_TEST_FOR_EXCEPTION(c > Cols(), std::out_of_range, "Error, c = " << Cols() << " is too big");
783 
784  // check row map
785  //if (!rangemaps_->Map(r)->isSameAs(mat->getRowMap()))
786  // TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Error. row maps do not fit.");
787 
788  // set matrix
789  blocks_[r*Cols()+c] = mat;
790  }
791 
793  /*
794  * This is a rather expensive operation, since all blocks are copied into a new big CrsMatrix
795  */
797  {
798  Teuchos::RCP<CrsMatrixClass> sparse = Teuchos::rcp_dynamic_cast<CrsMatrixClass>(Xpetra::CrsMatrixFactory<Scalar,LocalOrdinal,GlobalOrdinal>::Build(fullrowmap_,33));// Teuchos::rcp(new CrsMatrixClass(*fullrowmap_,33));
799  for (size_t i=0; i<blocks_.size(); ++i)
800  {
801  Teuchos::RCP<CrsMatrixClass> block = Teuchos::rcp_dynamic_cast<CrsMatrixClass>(blocks_[i]);
803  }
805  return sparse;
806  }
808 
809 
810 private:
811 
814 
816 
826  void Add(Teuchos::RCP<CrsMatrixClass>& A, const Scalar scalarA, Teuchos::RCP<CrsMatrixClass>& B, const Scalar scalarB) const
827  {
829  "Matrix A is not completed");
830 
831  B->scale(scalarB);
832 
833  size_t MaxNumEntries = std::max(A->getNodeMaxNumRowEntries(),B->getNodeMaxNumRowEntries());
834  std::vector<GlobalOrdinal> vecIndices(MaxNumEntries);
835  std::vector<Scalar> vecValues (MaxNumEntries);
836 
837  const Teuchos::ArrayView<GlobalOrdinal> Indices(&vecIndices[0], vecIndices.size());
838  const Teuchos::ArrayView<Scalar> Values (&vecValues[0], vecValues.size());
839  size_t NumEntries;
840 
841  Teuchos::ArrayView<const GlobalOrdinal> MyGlobalRowIds = A->getRowMap()->getNodeElementList(); // global row ids
842 
843  if(scalarA)
844  {
845  for(size_t i=0; i<A->getNodeNumRows(); ++i)
846  {
847  GlobalOrdinal Row = MyGlobalRowIds[i];
848 
849  //A->getGlobalRowCopy(Row, Indices, Values, NumEntries);
850  A->getLocalRowCopy(i, Indices, Values, NumEntries);
851 
852  if(scalarA != ScalarTraits< Scalar >::one())
853  for (size_t j=0; j<NumEntries; ++j)
854  Values[j] *= scalarA;
855 
856 
857 #if 0
858  for (size_t j=0; j<NumEntries; ++j)
859  {
860  std::vector<GlobalOrdinal> tempVec; tempVec.push_back(Indices[j]);
861  std::vector<Scalar> tempVal; tempVal.push_back(Values[j]);
862  Teuchos::ArrayView<GlobalOrdinal> tempIndex(&tempVec[0], 1);
863  Teuchos::ArrayView<Scalar> tempValue(&tempVal[0], 1);
864  B->insertGlobalValues(Row, tempIndex, tempValue); // insert should be ok, since blocks in BlockedCrsOpeartor do not overlap!
865  }
866 #else
867 
868  std::vector<GlobalOrdinal> tempvecIndices(NumEntries);
869  std::copy(Indices.getRawPtr(),
870  Indices.getRawPtr()+NumEntries,
871  std::inserter(tempvecIndices,tempvecIndices.begin()));
872  std::vector<Scalar> tempvecValues(NumEntries);
873  std::copy(Values.getRawPtr(),
874  Values.getRawPtr()+NumEntries,
875  std::inserter(tempvecValues,tempvecValues.begin()));
876  Teuchos::ArrayView<GlobalOrdinal> tempIndex(&tempvecIndices[0], NumEntries);
877  Teuchos::ArrayView<Scalar> tempValue(&tempvecValues[0], NumEntries);
878  B->insertGlobalValues(Row, tempIndex, tempValue); // insert should be ok, since blocks in BlockedCrsOpeartor do not overlap!
879 #endif
880 
881 
882  }
883  }
884  }
885 
887 
888  // Default view is created after fillComplete()
889  // Because ColMap might not be available before fillComplete().
891 
892  // Create default view
893  this->defaultViewLabel_ = "point";
895 
896  // Set current view
897  this->currentViewLabel_ = this->GetDefaultViewLabel();
898  }
899 
900 private:
901  // Teuchos::RCP<CrsMatrixClass> matrixData_;
902 
905 
908 
910  std::vector<Teuchos::RCP<CrsMatrixClass> > blocks_;
911 
914 
917 
918 
919 }; //class BlockedCrsMatrix
920 
921 } //namespace Xpetra
922 
923 #define XPETRA_BLOCKEDCRSMATRIX_SHORT
924 #endif /* XPETRA_BLOCKEDCRSMATRIX_HPP */
void doImport(const Matrix &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsMatrixClass
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const =0
Return a view of the global indices owned by this node.
Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsGraph
Teuchos::RCP< const MapExtractorClass > rangemaps_
the full range map together with all partial domain maps
void CreateView(viewLabel_t viewLabel, const RCP< const Map > &rowMap, const RCP< const Map > &colMap)
virtual bool isFillComplete() const =0
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
const RCP< const MapClass > getDomainMap() const
Returns the Map associated with the full domain of this operator. This will be null until fillComplet...
virtual void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)=0
Insert matrix entries, using global IDs.
virtual size_t getNodeMaxNumRowEntries() const =0
Returns the maximum number of entries across all rows/columns on this node.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
const RCP< const MapExtractorClass > getRangeMapExtractor()
Returns map extractor class for range map.
const RCP< const MapClass > getRangeMap() const
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Teuchos::RCP< CrsMatrixClass > Merge() const
merge BlockedCrsMatrix blocks in a CrsMatrix
void doExport(const Matrix &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
virtual void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const =0
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
void setMatrix(size_t r, size_t c, Teuchos::RCP< CrsMatrixClass > &mat)
set matrix block
void doExport(const Matrix &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const RCP< const MapExtractorClass > getDomainMapExtractor()
Returns map extractor for domain map.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=Kokkos::Details::getNode< Node >())
Map constructor with Xpetra-defined contiguous uniform distribution.
virtual size_t getNodeNumElements() const =0
The number of elements belonging to the calling node.
Exception throws to report errors in the internal logical of the program.
std::vector< Teuchos::RCP< CrsMatrixClass > > blocks_
row major matrix block storage
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
bool isFillComplete() const
Returns true if fillComplete() has been called and the matrix is in compute mode. ...
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)=0
Signal that data entry is complete, specifying domain and range maps.
virtual size_t Rows() const
number of row blocks
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row idices.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
virtual size_t getNodeNumRows() const =0
Returns the number of matrix rows owned on the calling node.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > MapExtractorClass
virtual const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
RCP< const CrsGraph > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Teuchos::RCP< MapClass > fullrowmap_
full matrix row map
virtual const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
Returns the Map that describes the row distribution in this matrix.
viewLabel_t currentViewLabel_
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
void fillComplete(const RCP< ParameterList > &params=null)
Signal that data entry is complete.
const RCP< const MapClass > getRangeMap(size_t i) const
Teuchos::RCP< const MapExtractorClass > domainmaps_
the full domain map together with all partial domain maps
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
std::string viewLabel_t
size_t global_size_t
Global size_t object.
Xpetra::CrsMatrixFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsMatrixFactory
static const EVerbosityLevel verbLevel_default
void Add(Teuchos::RCP< CrsMatrixClass > &A, const Scalar scalarA, Teuchos::RCP< CrsMatrixClass > &B, const Scalar scalarB) const
Add a Xpetra::CrsMatrix to another: B = B*scalarB + A*scalarA.
global_size_t getGlobalNumRows() const
Returns the number of global rows.
Xpetra::MatrixView< LocalOrdinal, GlobalOrdinal, Node > MatrixView
BlockedCrsMatrix(Teuchos::RCP< const MapExtractorClass > &rangeMaps, Teuchos::RCP< const MapExtractorClass > &domainMaps, size_t npr, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor.
Teuchos::RCP< CrsMatrixClass > getMatrix(size_t r, size_t c) const
return block (r,c)
viewLabel_t defaultViewLabel_
std::string description() const
Return a simple one-line description of this object.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Xpetra::TpetraCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > TpetraCrsMatrix
const RCP< const MapClass > getDomainMap(size_t i) const
Returns the Map associated with the i&#39;th block domain of this operator. This will be null until fillC...
virtual ~BlockedCrsMatrix()
Destructor.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
bool isLocallyIndexed() const
If matrix indices of all matrix blocks are in the local range, this function returns true...
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
virtual ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Get Frobenius norm of the matrix.
CombineMode
Xpetra::Combine Mode enumerable type.
virtual void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const =0
Computes the sparse matrix-multivector multiplication.
#define sumAll(rcpComm, in, out)
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
virtual size_t Cols() const
number of column blocks
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
void resumeFill(const RCP< ParameterList > &params=null)
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
const viewLabel_t & GetDefaultViewLabel() const
void removeEmptyProcessesInPlace(const Teuchos::RCP< const MapClass > &newMap)
virtual void scale(const Scalar &alpha)=0
Scale the current values of a matrix, this = alpha*this.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
global_size_t getGlobalNumCols() const
Returns the number of global columns in the matrix.
virtual void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalar.
Teuchos::RCP< MapClass > fullcolmap_
full matrix column map
void fillComplete(const RCP< const MapClass > &domainMap, const RCP< const MapClass > &rangeMap, const RCP< ParameterList > &params=null)
Signal that data entry is complete, specifying domain and range maps.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > MapClass
Xpetra-specific matrix class.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > Matrix
void doImport(const Matrix &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.