MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Utilities_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
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 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_UTILITIES_DEF_HPP
47 #define MUELU_UTILITIES_DEF_HPP
48 
49 #include <Teuchos_DefaultComm.hpp>
51 
52 #include "MueLu_ConfigDefs.hpp"
53 
54 #ifdef HAVE_MUELU_EPETRA
55 # ifdef HAVE_MPI
56 # include "Epetra_MpiComm.h"
57 # endif
58 #endif
59 
60 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
61 #include <EpetraExt_MatrixMatrix.h>
62 #include <EpetraExt_RowMatrixOut.h>
64 #include <EpetraExt_CrsMatrixIn.h>
66 #include <EpetraExt_BlockMapIn.h>
67 #include <Xpetra_EpetraUtils.hpp>
69 #include <EpetraExt_BlockMapOut.h>
70 #endif
71 
72 #ifdef HAVE_MUELU_TPETRA
73 #include <MatrixMarket_Tpetra.hpp>
74 #include <Tpetra_RowMatrixTransposer.hpp>
75 #include <TpetraExt_MatrixMatrix.hpp>
76 #include <Xpetra_TpetraMultiVector.hpp>
77 #include <Xpetra_TpetraCrsMatrix.hpp>
79 #endif
80 
81 #ifdef HAVE_MUELU_EPETRA
82 #include <Xpetra_EpetraMap.hpp>
83 #endif
84 
86 //#include <Xpetra_DefaultPlatform.hpp>
87 #include <Xpetra_IO.hpp>
88 #include <Xpetra_Import.hpp>
89 #include <Xpetra_ImportFactory.hpp>
90 #include <Xpetra_Map.hpp>
91 #include <Xpetra_MapFactory.hpp>
92 #include <Xpetra_Matrix.hpp>
93 #include <Xpetra_MatrixFactory.hpp>
94 #include <Xpetra_MultiVector.hpp>
96 #include <Xpetra_Operator.hpp>
97 #include <Xpetra_Vector.hpp>
98 #include <Xpetra_VectorFactory.hpp>
99 
100 #include <Xpetra_MatrixMatrix.hpp>
101 
102 #include <MueLu_Utilities_decl.hpp>
103 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_ML)
104 #include <ml_operator.h>
105 #include <ml_epetra_utils.h>
106 #endif
107 
108 namespace MueLu {
109 
110 #ifdef HAVE_MUELU_EPETRA
111  //using Xpetra::EpetraCrsMatrix; // TODO: mv in Xpetra_UseShortNamesScalar
112  //using Xpetra::EpetraMultiVector;
113 #endif
114 
115 #ifdef HAVE_MUELU_EPETRA
116  template<typename SC,typename LO,typename GO,typename NO>
118  return Xpetra::Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap<SC,LO,GO,NO>(epAB);
119  }
120 #endif
121 
122 #ifdef HAVE_MUELU_EPETRA
123  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
126  if (tmpVec == Teuchos::null)
127  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
128  return tmpVec->getEpetra_MultiVector();
129  }
130 
131  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
134  if (tmpVec == Teuchos::null)
135  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::EpetraMultiVector failed");
136  return tmpVec->getEpetra_MultiVector();
137  }
138 
139  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
142  return *(tmpVec.getEpetra_MultiVector());
143  }
144 
145  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
148  return *(tmpVec.getEpetra_MultiVector());
149  }
150 
151  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
154  if (crsOp == Teuchos::null)
155  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
156  const RCP<const Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node>>& tmp_ECrsMtx = rcp_dynamic_cast<const Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> >(crsOp->getCrsMatrix());
157  if (tmp_ECrsMtx == Teuchos::null)
158  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
159  return tmp_ECrsMtx->getEpetra_CrsMatrix();
160  }
161 
162  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
165  if (crsOp == Teuchos::null)
166  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
167  const RCP<const Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> > &tmp_ECrsMtx = rcp_dynamic_cast<const Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> >(crsOp->getCrsMatrix());
168  if (tmp_ECrsMtx == Teuchos::null)
169  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
170  return tmp_ECrsMtx->getEpetra_CrsMatrixNonConst();
171  }
172 
173  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
175  try {
177  try {
179  return *tmp_ECrsMtx.getEpetra_CrsMatrix();
180  } catch (std::bad_cast) {
181  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
182  }
183  } catch (std::bad_cast) {
184  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
185  }
186  }
187 
188  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
190  try {
192  try {
194  return *tmp_ECrsMtx.getEpetra_CrsMatrixNonConst();
195  } catch (std::bad_cast) {
196  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::EpetraCrsMatrix failed");
197  }
198  } catch (std::bad_cast) {
199  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
200  }
201  }
202 
203  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
205  RCP<const Xpetra::EpetraMapT<GlobalOrdinal,Node> > xeMap = rcp_dynamic_cast<const Xpetra::EpetraMapT<GlobalOrdinal,Node> >(rcpFromRef(map));
206  if (xeMap == Teuchos::null)
207  throw Exceptions::BadCast("Utilities::Map2EpetraMap : Cast from Xpetra::Map to Xpetra::EpetraMap failed");
208  return xeMap->getEpetra_Map();
209  }
210 #endif
211 
212 #ifdef HAVE_MUELU_TPETRA
213  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
217  if (tmpVec == Teuchos::null)
218  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
219  return tmpVec->getTpetra_MultiVector();
220  }
221 
222  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
225  if (tmpVec == Teuchos::null)
226  throw Exceptions::BadCast("Cast from Xpetra::MultiVector to Xpetra::TpetraMultiVector failed");
227  return tmpVec->getTpetra_MultiVector();
228  }
229 
230  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
233  return *(tmpVec.getTpetra_MultiVector());
234  }
235 
236  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
239  return tmpVec.getTpetra_MultiVector();
240  }
241 
242  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
243  const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>&
246  return *(tmpVec.getTpetra_MultiVector());
247  }
248 
249  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
251  // Get the underlying Tpetra Mtx
253  if (crsOp == Teuchos::null)
254  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
256  if (tmp_ECrsMtx == Teuchos::null)
257  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
258  return tmp_ECrsMtx->getTpetra_CrsMatrix();
259  }
260 
261  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
264  if (crsOp == Teuchos::null)
265  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
267  if (tmp_ECrsMtx == Teuchos::null)
268  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
269  return tmp_ECrsMtx->getTpetra_CrsMatrixNonConst();
270  }
271 
272  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
273  const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Utilities<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Op2TpetraCrs(const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Op) {
274  try {
276  try {
278  return *tmp_ECrsMtx.getTpetra_CrsMatrix();
279  } catch (std::bad_cast) {
280  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
281  }
282  } catch (std::bad_cast) {
283  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
284  }
285  }
286 
287  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
289  try {
291  try {
293  return *tmp_ECrsMtx.getTpetra_CrsMatrixNonConst();
294  } catch (std::bad_cast) {
295  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix failed");
296  }
297  } catch (std::bad_cast) {
298  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
299  }
300  }
301 
302  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
305  if (crsOp == Teuchos::null)
306  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
307 
311  if(!tmp_Crs.is_null()) {
312  return tmp_Crs->getTpetra_CrsMatrixNonConst();
313  }
314  else {
315  tmp_BlockCrs= rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(crsMat);
316  if (tmp_BlockCrs.is_null())
317  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
318  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
319  }
320  }
321 
322  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
325  if (crsOp == Teuchos::null)
326  throw Exceptions::BadCast("Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
327 
331  if(!tmp_Crs.is_null()) {
332  return tmp_Crs->getTpetra_CrsMatrixNonConst();
333  }
334  else {
335  tmp_BlockCrs= rcp_dynamic_cast<const Xpetra::TpetraBlockCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(crsMat);
336  if (tmp_BlockCrs.is_null())
337  throw Exceptions::BadCast("Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
338  return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
339  }
340  }
341 
342 
343  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
346  if (tmp_TMap == Teuchos::null)
347  throw Exceptions::BadCast("Utilities::Map2TpetraMap : Cast from Xpetra::Map to Xpetra::TpetraMap failed");
348  return tmp_TMap->getTpetra_Map();
349  }
350 #endif
351 
352  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
354  bool doFillComplete,
355  bool doOptimizeStorage)
356  {
357  Scalar one = Teuchos::ScalarTraits<Scalar>::one();
358  Teuchos::ArrayRCP<Scalar> sv(scalingVector.size());
359  if (doInverse) {
360  for (int i = 0; i < scalingVector.size(); ++i)
361  sv[i] = one / scalingVector[i];
362  } else {
363  for (int i = 0; i < scalingVector.size(); ++i)
364  sv[i] = scalingVector[i];
365  }
366 
367  switch (Op.getRowMap()->lib()) {
368  case Xpetra::UseTpetra:
369  MyOldScaleMatrix_Tpetra(Op, sv, doFillComplete, doOptimizeStorage);
370  break;
371 
372  case Xpetra::UseEpetra:
373  MyOldScaleMatrix_Epetra(Op, sv, doFillComplete, doOptimizeStorage);
374  break;
375 
376  default:
377  throw Exceptions::RuntimeError("Only Epetra and Tpetra matrices can be scaled.");
378  }
379  }
380 
381  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
382  void Utilities<Scalar, LocalOrdinal, GlobalOrdinal, Node>::MyOldScaleMatrix_Epetra(Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>& /* Op */, const Teuchos::ArrayRCP<Scalar>& /* scalingVector */, bool /* doFillComplete */, bool /* doOptimizeStorage */) {
383  throw Exceptions::RuntimeError("MyOldScaleMatrix_Epetra: Epetra needs SC=double and LO=GO=int.");
384  }
385 
386  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
388  bool doFillComplete,
389  bool doOptimizeStorage)
390  {
391 #ifdef HAVE_MUELU_TPETRA
392  try {
393  Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& tpOp = Op2NonConstTpetraCrs(Op);
394 
395  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rowMap = tpOp.getRowMap();
396  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > domainMap = tpOp.getDomainMap();
397  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rangeMap = tpOp.getRangeMap();
398 
399  size_t maxRowSize = tpOp.getNodeMaxNumRowEntries();
400  if (maxRowSize == Teuchos::as<size_t>(-1)) // hasn't been determined yet
401  maxRowSize = 20;
402 
403  std::vector<Scalar> scaledVals(maxRowSize);
404  if (tpOp.isFillComplete())
405  tpOp.resumeFill();
406 
407  if (Op.isLocallyIndexed() == true) {
410 
411  for (size_t i = 0; i < rowMap->getNodeNumElements(); ++i) {
412  tpOp.getLocalRowView(i, cols, vals);
413  size_t nnz = tpOp.getNumEntriesInLocalRow(i);
414  if (nnz > maxRowSize) {
415  maxRowSize = nnz;
416  scaledVals.resize(maxRowSize);
417  }
418  for (size_t j = 0; j < nnz; ++j)
419  scaledVals[j] = vals[j]*scalingVector[i];
420 
421  if (nnz > 0) {
422  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
423  tpOp.replaceLocalValues(i, cols, valview);
424  }
425  } //for (size_t i=0; ...
426 
427  } else {
430 
431  for (size_t i = 0; i < rowMap->getNodeNumElements(); ++i) {
432  GlobalOrdinal gid = rowMap->getGlobalElement(i);
433  tpOp.getGlobalRowView(gid, cols, vals);
434  size_t nnz = tpOp.getNumEntriesInGlobalRow(gid);
435  if (nnz > maxRowSize) {
436  maxRowSize = nnz;
437  scaledVals.resize(maxRowSize);
438  }
439  // FIXME FIXME FIXME FIXME FIXME FIXME
440  for (size_t j = 0; j < nnz; ++j)
441  scaledVals[j] = vals[j]*scalingVector[i]; //FIXME i or gid?
442 
443  if (nnz > 0) {
444  Teuchos::ArrayView<const Scalar> valview(&scaledVals[0], nnz);
445  tpOp.replaceGlobalValues(gid, cols, valview);
446  }
447  } //for (size_t i=0; ...
448  }
449 
450  if (doFillComplete) {
451  if (domainMap == Teuchos::null || rangeMap == Teuchos::null)
452  throw Exceptions::RuntimeError("In Utilities::Scaling: cannot fillComplete because the domain and/or range map hasn't been defined");
453 
455  params->set("Optimize Storage", doOptimizeStorage);
456  params->set("No Nonlocal Changes", true);
457  Op.fillComplete(Op.getDomainMap(), Op.getRangeMap(), params);
458  }
459  } catch(...) {
460  throw Exceptions::RuntimeError("Only Tpetra::CrsMatrix types can be scaled (Err.1)");
461  }
462 #else
463  throw Exceptions::RuntimeError("Matrix scaling is not possible because Tpetra has not been enabled.");
464 #endif
465  } //MyOldScaleMatrix_Tpetra()
466 
467  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
470  Transpose (Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Op, bool /* optimizeTranspose */,const std::string & label,const Teuchos::RCP<Teuchos::ParameterList> &params) {
471 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
472  std::string TorE = "epetra";
473 #else
474  std::string TorE = "tpetra";
475 #endif
476 
477 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_EPETRAEXT)
478  try {
480  (void) epetraOp; // silence "unused variable" compiler warning
481  } catch (...) {
482  TorE = "tpetra";
483  }
484 #endif
485 
486 #ifdef HAVE_MUELU_TPETRA
487  if (TorE == "tpetra") {
488  try {
489  const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& tpetraOp = Utilities<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Op2TpetraCrs(Op);
490 
492  Tpetra::RowMatrixTransposer<Scalar, LocalOrdinal, GlobalOrdinal, Node> transposer(rcpFromRef(tpetraOp),label); //more than meets the eye
493  A = transposer.createTranspose(params);
494 
498  if (!AAAA->isFillComplete())
499  AAAA->fillComplete(Op.getRangeMap(), Op.getDomainMap());
500 
501  if (Op.IsView("stridedMaps"))
502  AAAA->CreateView("stridedMaps", Teuchos::rcpFromRef(Op), true/*doTranspose*/);
503 
504  return AAAA;
505 
506  } catch (std::exception& e) {
507  std::cout << "threw exception '" << e.what() << "'" << std::endl;
508  throw Exceptions::RuntimeError("Utilities::Transpose failed, perhaps because matrix is not a Crs matrix");
509  }
510  } //if
511 #endif
512 
513  // Epetra case
514  std::cout << "Utilities::Transpose() not implemented for Epetra" << std::endl;
515  return Teuchos::null;
516 
517  } // Transpose
518 
519 
520  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
525 #if defined(HAVE_XPETRA_TPETRA) && (defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) || defined(HAVE_TPETRA_INST_COMPLEX_FLOAT))
526  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType real_type;
527  // Need to cast the real-valued multivector to Scalar=complex
528  if ((typeid(Scalar).name() == typeid(std::complex<double>).name()) ||
529  (typeid(Scalar).name() == typeid(std::complex<float>).name())) {
530  Xscalar = Xpetra::MultiVectorFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Build(X->getMap(),X->getNumVectors());
531  size_t numVecs = X->getNumVectors();
532  for (size_t j=0;j<numVecs;j++) {
533  Teuchos::ArrayRCP<const real_type> XVec = X->getData(j);
534  Teuchos::ArrayRCP<Scalar> XVecScalar = Xscalar->getDataNonConst(j);
535  for(size_t i = 0; i < static_cast<size_t>(XVec.size()); ++i)
536  XVecScalar[i]=XVec[i];
537  }
538  } else
539 #endif
540  Xscalar = rcp_dynamic_cast<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(X);
541  return Xscalar;
542  }
543 
544 
545  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
549 
550  RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LocalOrdinal,GlobalOrdinal,Node> > coordinates = Teuchos::null;
551 
552  // check whether coordinates are contained in parameter list
553  if(paramList.isParameter ("Coordinates") == false)
554  return coordinates;
555 
556 #if defined(HAVE_MUELU_TPETRA)
557  // only Tpetra code
558 
559  // define Tpetra::MultiVector type with Scalar=float only if
560  // * ETI is turned off, since then the compiler will instantiate it automatically OR
561  // * Tpetra is instantiated on Scalar=float
562 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
563  typedef Tpetra::MultiVector<float, LocalOrdinal, GlobalOrdinal, Node> tfMV;
564  RCP<tfMV> floatCoords = Teuchos::null;
565 #endif
566 
567  // define Tpetra::MultiVector type with Scalar=double only if
568  // * ETI is turned off, since then the compiler will instantiate it automatically OR
569  // * Tpetra is instantiated on Scalar=double
570 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_DOUBLE)
571  typedef Tpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LocalOrdinal, GlobalOrdinal, Node> tdMV;
572  RCP<tdMV> doubleCoords = Teuchos::null;
573  if (paramList.isType<RCP<tdMV> >("Coordinates")) {
574  // Coordinates are stored as a double vector
575  doubleCoords = paramList.get<RCP<tdMV> >("Coordinates");
576  paramList.remove("Coordinates");
577  }
578 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT)
579  else if (paramList.isType<RCP<tfMV> >("Coordinates")) {
580  // check if coordinates are stored as a float vector
581  floatCoords = paramList.get<RCP<tfMV> >("Coordinates");
582  paramList.remove("Coordinates");
583  doubleCoords = rcp(new tdMV(floatCoords->getMap(), floatCoords->getNumVectors()));
584  deep_copy(*doubleCoords, *floatCoords);
585  }
586 #endif
587  // We have the coordinates in a Tpetra double vector
588  if(doubleCoords != Teuchos::null) {
589  //rcp(new Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(Vtpetra));
590  coordinates = Teuchos::rcp_dynamic_cast<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LocalOrdinal,GlobalOrdinal,Node> >(MueLu::TpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType,LocalOrdinal,GlobalOrdinal,Node>(doubleCoords));
592  TEUCHOS_TEST_FOR_EXCEPT(doubleCoords->getNumVectors() != coordinates->getNumVectors());
593  }
594 #else
595  // coordinates usually are stored as double vector
596  // Tpetra is not instantiated on scalar=double
597  throw Exceptions::RuntimeError("ExtractCoordinatesFromParameterList: The coordinates vector in parameter list is expected to be a Tpetra multivector with SC=double or float.");
598 #endif
599 #endif // endif HAVE_TPETRA
600 
601  // check for Xpetra coordinates vector
602  if(paramList.isType<decltype(coordinates)>("Coordinates")) {
603  coordinates = paramList.get<decltype(coordinates)>("Coordinates");
604  }
605 
606  return coordinates;
607  } // ExtractCoordinatesFromParameterList
608 
609 } //namespace MueLu
610 
611 #define MUELU_UTILITIES_SHORT
612 #endif // MUELU_UTILITIES_DEF_HPP
613 
614 // LocalWords: LocalOrdinal
Exception indicating invalid cast attempted.
static const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > Map2TpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
static RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2TpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > const vec)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
RCP< CrsMatrix > getCrsMatrix() const
static void MyOldScaleMatrix(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< const Scalar > &scalingVector, bool doInverse=true, bool doFillComplete=true, bool doOptimizeStorage=true)
static RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraCrs(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
static const Epetra_Map & Map2EpetraMap(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map)
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
T & get(const std::string &name, T def_value)
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
static RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > ExtractCoordinatesFromParameterList(ParameterList &paramList)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool is_null(const std::shared_ptr< T > &p)
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > const vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
size_type size() const
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > vec)
bool isParameter(const std::string &name) const
bool remove(std::string const &name, bool throwIfNotExists=true)
virtual void fillComplete(const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const RCP< ParameterList > &params=null)=0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > vec)
static RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > RealValuedToScalarMultiVector(RCP< Xpetra::MultiVector< typename Teuchos::ScalarTraits< Scalar >::magnitudeType, LocalOrdinal, GlobalOrdinal, Node > > X)
void deep_copy(const DynRankView< DT, DP...> &dst, typename ViewTraits< DT, DP...>::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP...>::specialize, void >::value >::type *=0)
static RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV2(Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec)
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Transpose(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, bool optimizeTranspose=false, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
static RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2TpetraRow(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
RCP< Xpetra::CrsMatrixWrap< SC, LO, GO, NO > > Convert_Epetra_CrsMatrix_ToXpetra_CrsMatrixWrap(RCP< Epetra_CrsMatrix > &epAB)
static void MyOldScaleMatrix_Epetra(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool doFillComplete, bool doOptimizeStorage)
static RCP< const Epetra_CrsMatrix > Op2EpetraCrs(RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
virtual bool isLocallyIndexed() const =0
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrixNonConst() const
bool isType(const std::string &name) const
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
virtual Teuchos::RCP< const Map > getRangeMap() const =0
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Exception throws to report errors in the internal logical of the program.
static RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraRow(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
static void MyOldScaleMatrix_Tpetra(Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Teuchos::ArrayRCP< Scalar > &scalingVector, bool doFillComplete, bool doOptimizeStorage)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual Teuchos::RCP< const Map > getDomainMap() const =0
bool is_null() const