MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Ifpack2Smoother_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_IFPACK2SMOOTHER_DEF_HPP
47 #define MUELU_IFPACK2SMOOTHER_DEF_HPP
48 
49 #include "MueLu_ConfigDefs.hpp"
50 
51 #if defined(HAVE_MUELU_IFPACK2)
52 
54 
55 #include <Tpetra_RowMatrix.hpp>
56 
57 #include <Ifpack2_Chebyshev.hpp>
58 #include <Ifpack2_Hiptmair.hpp>
59 #include <Ifpack2_RILUK.hpp>
60 #include <Ifpack2_Relaxation.hpp>
61 #include <Ifpack2_ILUT.hpp>
62 #include <Ifpack2_BlockRelaxation.hpp>
63 #include <Ifpack2_Factory.hpp>
64 #include <Ifpack2_Parameters.hpp>
65 
67 #include <Xpetra_CrsMatrix.hpp>
68 #include <Xpetra_CrsMatrixWrap.hpp>
69 #include <Xpetra_TpetraBlockCrsMatrix.hpp>
70 #include <Xpetra_Matrix.hpp>
71 #include <Xpetra_MatrixMatrix.hpp>
72 #include <Xpetra_MultiVectorFactory.hpp>
73 #include <Xpetra_TpetraMultiVector.hpp>
74 
75 #include <Tpetra_BlockCrsMatrix_Helpers.hpp>
76 
78 #include "MueLu_Level.hpp"
79 #include "MueLu_Utilities.hpp"
80 #include "MueLu_Monitor.hpp"
81 #include "MueLu_Aggregates.hpp"
82 
83 #ifdef HAVE_MUELU_INTREPID2
86 #include "Intrepid2_Basis.hpp"
87 #include "Kokkos_DynRankView.hpp"
88 #endif
89 
90 namespace MueLu {
91 
92 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
94  : type_(type)
95  , overlap_(overlap) {
96  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
97  bool isSupported = Ifpack2::Factory::isSupported<tRowMatrix>(type_) || (type_ == "LINESMOOTHING_TRIDI_RELAXATION" ||
98  type_ == "LINESMOOTHING_TRIDI RELAXATION" ||
99  type_ == "LINESMOOTHING_TRIDIRELAXATION" ||
100  type_ == "LINESMOOTHING_TRIDIAGONAL_RELAXATION" ||
101  type_ == "LINESMOOTHING_TRIDIAGONAL RELAXATION" ||
102  type_ == "LINESMOOTHING_TRIDIAGONALRELAXATION" ||
103  type_ == "LINESMOOTHING_BANDED_RELAXATION" ||
104  type_ == "LINESMOOTHING_BANDED RELAXATION" ||
105  type_ == "LINESMOOTHING_BANDEDRELAXATION" ||
106  type_ == "LINESMOOTHING_BLOCK_RELAXATION" ||
107  type_ == "LINESMOOTHING_BLOCK RELAXATION" ||
108  type_ == "LINESMOOTHING_BLOCKRELAXATION" ||
109  type_ == "TOPOLOGICAL" ||
110  type_ == "AGGREGATE");
111  this->declareConstructionOutcome(!isSupported, "Ifpack2 does not provide the smoother '" + type_ + "'.");
112  if (isSupported)
113  SetParameterList(paramList);
114 }
115 
116 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
118  Factory::SetParameterList(paramList);
119 
121  // It might be invalid to change parameters after the setup, but it depends entirely on Ifpack implementation.
122  // TODO: I don't know if Ifpack returns an error code or exception or ignore parameters modification in this case...
123  SetPrecParameters();
124  }
125 }
126 
127 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
129  std::string prefix = this->ShortClassName() + ": SetPrecParameters";
130  RCP<TimeMonitor> tM = rcp(new TimeMonitor(*this, prefix, Timings0));
131  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
132 
133  paramList.setParameters(list);
134 
135  RCP<ParameterList> precList = this->RemoveFactoriesFromList(this->GetParameterList());
136 
137  // Do we want an Ifpack2 apply timer?
138  precList->set("timer for apply", this->IsPrint(Timings));
139 
140  if (!precList.is_null() && precList->isParameter("partitioner: type") && precList->get<std::string>("partitioner: type") == "linear" &&
141  !precList->isParameter("partitioner: local parts")) {
142  LO matrixBlockSize = 1;
143  int lclSize = A_->getRangeMap()->getLocalNumElements();
144  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
145  if (!matA.is_null()) {
146  lclSize = matA->getLocalNumRows();
147  matrixBlockSize = matA->GetFixedBlockSize();
148  }
149  precList->set("partitioner: local parts", lclSize / matrixBlockSize);
150  }
151 
152  prec_->setParameters(*precList);
153 
154  paramList.setParameters(*precList); // what about that??
155 }
156 
157 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
159  this->Input(currentLevel, "A");
160 
161  if (type_ == "LINESMOOTHING_TRIDI_RELAXATION" ||
162  type_ == "LINESMOOTHING_TRIDI RELAXATION" ||
163  type_ == "LINESMOOTHING_TRIDIRELAXATION" ||
164  type_ == "LINESMOOTHING_TRIDIAGONAL_RELAXATION" ||
165  type_ == "LINESMOOTHING_TRIDIAGONAL RELAXATION" ||
166  type_ == "LINESMOOTHING_TRIDIAGONALRELAXATION" ||
167  type_ == "LINESMOOTHING_BANDED_RELAXATION" ||
168  type_ == "LINESMOOTHING_BANDED RELAXATION" ||
169  type_ == "LINESMOOTHING_BANDEDRELAXATION" ||
170  type_ == "LINESMOOTHING_BLOCK_RELAXATION" ||
171  type_ == "LINESMOOTHING_BLOCK RELAXATION" ||
172  type_ == "LINESMOOTHING_BLOCKRELAXATION") {
173  this->Input(currentLevel, "CoarseNumZLayers"); // necessary for fallback criterion
174  this->Input(currentLevel, "LineDetection_VertLineIds"); // necessary to feed block smoother
175  } else if (type_ == "BLOCK RELAXATION" ||
176  type_ == "BLOCK_RELAXATION" ||
177  type_ == "BLOCKRELAXATION" ||
178  // Banded
179  type_ == "BANDED_RELAXATION" ||
180  type_ == "BANDED RELAXATION" ||
181  type_ == "BANDEDRELAXATION" ||
182  // Tridiagonal
183  type_ == "TRIDI_RELAXATION" ||
184  type_ == "TRIDI RELAXATION" ||
185  type_ == "TRIDIRELAXATION" ||
186  type_ == "TRIDIAGONAL_RELAXATION" ||
187  type_ == "TRIDIAGONAL RELAXATION" ||
188  type_ == "TRIDIAGONALRELAXATION") {
189  // We need to check for the "partitioner type" = "line"
190  ParameterList precList = this->GetParameterList();
191  if (precList.isParameter("partitioner: type") &&
192  precList.get<std::string>("partitioner: type") == "line") {
193  this->Input(currentLevel, "Coordinates");
194  }
195  } else if (type_ == "TOPOLOGICAL") {
196  // for the topological smoother, we require an element to node map:
197  this->Input(currentLevel, "pcoarsen: element to node map");
198  } else if (type_ == "AGGREGATE") {
199  // Aggregate smoothing needs aggregates
200  this->Input(currentLevel, "Aggregates");
201  } else if (type_ == "HIPTMAIR") {
202  // Hiptmair needs D0 and NodeMatrix
203  this->Input(currentLevel, "NodeMatrix");
204  this->Input(currentLevel, "D0");
205  }
206 }
207 
208 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
210  FactoryMonitor m(*this, "Setup Smoother", currentLevel);
211  A_ = Factory::Get<RCP<Operator>>(currentLevel, "A");
212  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
213 
214  // If the user asked us to convert the matrix into BlockCrsMatrix form, we do that now
215 
216  if (paramList.isParameter("smoother: use blockcrsmatrix storage") && paramList.get<bool>("smoother: use blockcrsmatrix storage")) {
217  int blocksize = 1;
218  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
219  if (!matA.is_null())
220  blocksize = matA->GetFixedBlockSize();
221  if (blocksize) {
222  // NOTE: Don't think you can move this out of the if block. You can't. The test MueLu_MeshTyingBlocked_SimpleSmoother_2dof_medium_MPI_1 will fail
223 
224  RCP<CrsMatrixWrap> AcrsWrap = rcp_dynamic_cast<CrsMatrixWrap>(A_);
225  if (AcrsWrap.is_null())
226  throw std::runtime_error("Ifpack2Smoother: Cannot convert matrix A to CrsMatrixWrap object.");
227  RCP<CrsMatrix> Acrs = AcrsWrap->getCrsMatrix();
228  if (Acrs.is_null())
229  throw std::runtime_error("Ifpack2Smoother: Cannot extract CrsMatrix from matrix A.");
230  RCP<TpetraCrsMatrix> At = rcp_dynamic_cast<TpetraCrsMatrix>(Acrs);
231  if (At.is_null()) {
233  throw std::runtime_error("Ifpack2Smoother: Cannot extract CrsMatrix or BlockCrsMatrix from matrix A.");
234  this->GetOStream(Statistics0) << "Ifpack2Smoother: Using (native) BlockCrsMatrix storage with blocksize " << blocksize << std::endl;
235  paramList.remove("smoother: use blockcrsmatrix storage");
236  } else {
237  RCP<Tpetra::BlockCrsMatrix<Scalar, LO, GO, Node>> blockCrs = Tpetra::convertToBlockCrsMatrix(*At->getTpetra_CrsMatrix(), blocksize);
238  RCP<CrsMatrix> blockCrs_as_crs = rcp(new TpetraBlockCrsMatrix(blockCrs));
239  RCP<CrsMatrixWrap> blockWrap = rcp(new CrsMatrixWrap(blockCrs_as_crs));
240  A_ = blockWrap;
241  this->GetOStream(Statistics0) << "Ifpack2Smoother: Using BlockCrsMatrix storage with blocksize " << blocksize << std::endl;
242 
243  paramList.remove("smoother: use blockcrsmatrix storage");
244  }
245  }
246  }
247 
248  if (type_ == "SCHWARZ")
249  SetupSchwarz(currentLevel);
250 
251  else if (type_ == "LINESMOOTHING_TRIDI_RELAXATION" ||
252  type_ == "LINESMOOTHING_TRIDI RELAXATION" ||
253  type_ == "LINESMOOTHING_TRIDIRELAXATION" ||
254  type_ == "LINESMOOTHING_TRIDIAGONAL_RELAXATION" ||
255  type_ == "LINESMOOTHING_TRIDIAGONAL RELAXATION" ||
256  type_ == "LINESMOOTHING_TRIDIAGONALRELAXATION" ||
257  type_ == "LINESMOOTHING_BANDED_RELAXATION" ||
258  type_ == "LINESMOOTHING_BANDED RELAXATION" ||
259  type_ == "LINESMOOTHING_BANDEDRELAXATION" ||
260  type_ == "LINESMOOTHING_BLOCK_RELAXATION" ||
261  type_ == "LINESMOOTHING_BLOCK RELAXATION" ||
262  type_ == "LINESMOOTHING_BLOCKRELAXATION")
263  SetupLineSmoothing(currentLevel);
264 
265  else if (type_ == "BLOCK_RELAXATION" ||
266  type_ == "BLOCK RELAXATION" ||
267  type_ == "BLOCKRELAXATION" ||
268  // Banded
269  type_ == "BANDED_RELAXATION" ||
270  type_ == "BANDED RELAXATION" ||
271  type_ == "BANDEDRELAXATION" ||
272  // Tridiagonal
273  type_ == "TRIDI_RELAXATION" ||
274  type_ == "TRIDI RELAXATION" ||
275  type_ == "TRIDIRELAXATION" ||
276  type_ == "TRIDIAGONAL_RELAXATION" ||
277  type_ == "TRIDIAGONAL RELAXATION" ||
278  type_ == "TRIDIAGONALRELAXATION")
279  SetupBlockRelaxation(currentLevel);
280 
281  else if (type_ == "CHEBYSHEV")
282  SetupChebyshev(currentLevel);
283 
284  else if (type_ == "TOPOLOGICAL") {
285 #ifdef HAVE_MUELU_INTREPID2
286  SetupTopological(currentLevel);
287 #else
288  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "'TOPOLOGICAL' smoother choice requires Intrepid2");
289 #endif
290  } else if (type_ == "AGGREGATE")
291  SetupAggregate(currentLevel);
292 
293  else if (type_ == "HIPTMAIR")
294  SetupHiptmair(currentLevel);
295 
296  else {
297  SetupGeneric(currentLevel);
298  }
299 
301 
302  this->GetOStream(Statistics1) << description() << std::endl;
303 }
304 
305 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
307  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
308 
309  bool reusePreconditioner = false;
310  if (this->IsSetup() == true) {
311  // Reuse the constructed preconditioner
312  this->GetOStream(Runtime1) << "MueLu::Ifpack2Smoother::SetupSchwarz(): Setup() has already been called, assuming reuse" << std::endl;
313 
314  bool isTRowMatrix = true;
316  try {
318  } catch (Exceptions::BadCast&) {
319  isTRowMatrix = false;
320  }
321 
323  if (!prec.is_null() && isTRowMatrix) {
324  prec->setMatrix(tA);
325  reusePreconditioner = true;
326  } else {
327  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupSchwarz(): reuse of this type is not available "
328  "(either failed cast to CanChangeMatrix, or to Tpetra Row Matrix), reverting to full construction"
329  << std::endl;
330  }
331  }
332 
333  if (!reusePreconditioner) {
334  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
335 
336  bool isBlockedMatrix = false;
337  RCP<Matrix> merged2Mat;
338 
339  std::string sublistName = "subdomain solver parameters";
340  if (paramList.isSublist(sublistName)) {
341  // If we are doing "user" partitioning, we assume that what the user
342  // really wants to do is make tiny little subdomains with one row
343  // assigned to each subdomain. The rows used for these little
344  // subdomains correspond to those in the 2nd block row. Then,
345  // if we overlap these mini-subdomains, we will do something that
346  // looks like Vanka (grabbing all velocities associated with each
347  // each pressure unknown). In addition, we put all Dirichlet points
348  // as a little mini-domain.
349  ParameterList& subList = paramList.sublist(sublistName);
350 
351  std::string partName = "partitioner: type";
352  // Pretty sure no one has been using this. Unfortunately, old if
353  // statement (which checked for equality with "user") prevented
354  // anyone from employing other types of Ifpack2 user partition
355  // options. Leaving this and switching if to "vanka user" just
356  // in case some day someone might want to use this.
357  if (subList.isParameter(partName) && subList.get<std::string>(partName) == "vanka user") {
358  isBlockedMatrix = true;
359 
360  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
362  "Matrix A must be of type BlockedCrsMatrix.");
363 
364  size_t numVels = bA->getMatrix(0, 0)->getLocalNumRows();
365  size_t numPres = bA->getMatrix(1, 0)->getLocalNumRows();
366  size_t numRows = rcp_dynamic_cast<Matrix>(A_, true)->getLocalNumRows();
367 
369 
370  size_t numBlocks = 0;
371  for (size_t rowOfB = numVels; rowOfB < numVels + numPres; ++rowOfB)
372  blockSeeds[rowOfB] = numBlocks++;
373 
374  RCP<BlockedCrsMatrix> bA2 = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
376  "Matrix A must be of type BlockedCrsMatrix.");
377 
378  merged2Mat = bA2->Merge();
379 
380  // Add Dirichlet rows to the list of seeds
381  ArrayRCP<const bool> boundaryNodes = Utilities::DetectDirichletRows(*merged2Mat, 0.0);
382  bool haveBoundary = false;
383  for (LO i = 0; i < boundaryNodes.size(); i++)
384  if (boundaryNodes[i]) {
385  // FIXME:
386  // 1. would not this [] overlap with some in the previos blockSeed loop?
387  // 2. do we need to distinguish between pressure and velocity Dirichlet b.c.
388  blockSeeds[i] = numBlocks;
389  haveBoundary = true;
390  }
391  if (haveBoundary)
392  numBlocks++;
393 
394  subList.set("partitioner: type", "user");
395  subList.set("partitioner: map", blockSeeds);
396  subList.set("partitioner: local parts", as<int>(numBlocks));
397 
398  } else {
399  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
400  if (!bA.is_null()) {
401  isBlockedMatrix = true;
402  merged2Mat = bA->Merge();
403  }
404  }
405  }
406 
408  if (isBlockedMatrix == true)
409  tA = Utilities::Op2NonConstTpetraRow(merged2Mat);
410  else
412 
413  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
414  SetPrecParameters();
415 
416  prec_->initialize();
417  }
418 
419  prec_->compute();
420 }
421 
422 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
424  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
425 
426  if (this->IsSetup() == true) {
427  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupAggregate(): Setup() has already been called" << std::endl;
428  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupAggregate(): reuse of this type is not available, reverting to full construction" << std::endl;
429  }
430 
431  this->GetOStream(Statistics0) << "Ifpack2Smoother: Using Aggregate Smoothing" << std::endl;
432 
433  RCP<Aggregates> aggregates = Factory::Get<RCP<Aggregates>>(currentLevel, "Aggregates");
434 
435  RCP<const LOMultiVector> vertex2AggId = aggregates->GetVertex2AggId();
436  ArrayRCP<LO> aggregate_ids = rcp_const_cast<LOMultiVector>(vertex2AggId)->getDataNonConst(0);
437  ArrayRCP<LO> dof_ids;
438 
439  // We need to unamalgamate, if the FixedBlockSize > 1
440  LO blocksize = 1;
441  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
442  if (!matA.is_null())
443  blocksize = matA->GetFixedBlockSize();
444  if (blocksize > 1) {
445  dof_ids.resize(aggregate_ids.size() * blocksize);
446  for (LO i = 0; i < (LO)aggregate_ids.size(); i++) {
447  for (LO j = 0; j < (LO)blocksize; j++)
448  dof_ids[i * blocksize + j] = aggregate_ids[i];
449  }
450  } else {
451  dof_ids = aggregate_ids;
452  }
453 
454  paramList.set("partitioner: map", dof_ids);
455  paramList.set("partitioner: type", "user");
456  paramList.set("partitioner: overlap", 0);
457  paramList.set("partitioner: local parts", (int)aggregates->GetNumAggregates());
458 
460 
461  type_ = "BLOCKRELAXATION";
462  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
463  SetPrecParameters();
464  prec_->initialize();
465  prec_->compute();
466 }
467 
468 #ifdef HAVE_MUELU_INTREPID2
469 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
471  /*
472 
473  basic notion:
474 
475  Look for user input indicating topo dimension, something like "topological domain type: {node|edge|face}"
476  Call something like what you can find in Poisson example line 1180 to set seeds for a smoother
477 
478  */
479  if (this->IsSetup() == true) {
480  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupTopological(): Setup() has already been called" << std::endl;
481  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupTopological(): reuse of this type is not available, reverting to full construction" << std::endl;
482  }
483 
484  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
485 
486  typedef typename Node::device_type::execution_space ES;
487 
488  typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> FCO; //
489 
491 
492  using namespace std;
493 
494  const Teuchos::RCP<FCO> elemToNode = Factory::Get<Teuchos::RCP<FCO>>(currentLevel, "pcoarsen: element to node map");
495 
496  string basisString = paramList.get<string>("pcoarsen: hi basis");
497  int degree;
498  // NOTE: To make sure Stokhos works we only instantiate these guys with double. There's a lot
499  // of stuff in the guts of Intrepid2 that doesn't play well with Stokhos as of yet. Here, we only
500  // care about the assignment of basis ordinals to topological entities, so this code is actually
501  // independent of the Scalar type--hard-coding double here won't hurt us.
502  auto basis = MueLuIntrepid::BasisFactory<double, ES>(basisString, degree);
503 
504  string topologyTypeString = paramList.get<string>("smoother: neighborhood type");
505  int dimension;
506  if (topologyTypeString == "node")
507  dimension = 0;
508  else if (topologyTypeString == "edge")
509  dimension = 1;
510  else if (topologyTypeString == "face")
511  dimension = 2;
512  else if (topologyTypeString == "cell")
513  dimension = basis->getBaseCellTopology().getDimension();
514  else
515  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "Unrecognized smoother neighborhood type. Supported types are node, edge, face.");
516  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_, true);
517  vector<vector<LocalOrdinal>> seeds;
518  MueLuIntrepid::FindGeometricSeedOrdinals(basis, *elemToNode, seeds, *matA->getRowMap(), *matA->getColMap());
519 
520  // Ifpack2 wants the seeds in an array of the same length as the number of local elements,
521  // with local partition #s marked for the ones that are seeds, and invalid for the rest
522  int myNodeCount = matA->getRowMap()->getLocalNumElements();
523  ArrayRCP<LocalOrdinal> nodeSeeds(myNodeCount, lo_invalid);
524  int localPartitionNumber = 0;
525  for (LocalOrdinal seed : seeds[dimension]) {
526  nodeSeeds[seed] = localPartitionNumber++;
527  }
528 
529  paramList.remove("smoother: neighborhood type");
530  paramList.remove("pcoarsen: hi basis");
531 
532  paramList.set("partitioner: map", nodeSeeds);
533  paramList.set("partitioner: type", "user");
534  paramList.set("partitioner: overlap", 1);
535  paramList.set("partitioner: local parts", int(seeds[dimension].size()));
536 
537  RCP<const Tpetra::RowMatrix<SC, LO, GO, NO>> tA = Utilities::Op2NonConstTpetraRow(A_);
538 
539  type_ = "BLOCKRELAXATION";
540  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
541  SetPrecParameters();
542  prec_->initialize();
543  prec_->compute();
544 }
545 #endif
546 
547 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
549  if (this->IsSetup() == true) {
550  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupLineSmoothing(): Setup() has already been called" << std::endl;
551  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupLineSmoothing(): reuse of this type is not available, reverting to full construction" << std::endl;
552  }
553 
554  ParameterList& myparamList = const_cast<ParameterList&>(this->GetParameterList());
555 
556  LO CoarseNumZLayers = Factory::Get<LO>(currentLevel, "CoarseNumZLayers");
557  if (CoarseNumZLayers > 0) {
558  Teuchos::ArrayRCP<LO> TVertLineIdSmoo = Factory::Get<Teuchos::ArrayRCP<LO>>(currentLevel, "LineDetection_VertLineIds");
559 
560  // determine number of local parts
561  LO maxPart = 0;
562  for (size_t k = 0; k < Teuchos::as<size_t>(TVertLineIdSmoo.size()); k++) {
563  if (maxPart < TVertLineIdSmoo[k]) maxPart = TVertLineIdSmoo[k];
564  }
565  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_, true);
566  size_t numLocalRows = matA->getLocalNumRows();
567 
568  TEUCHOS_TEST_FOR_EXCEPTION(numLocalRows % TVertLineIdSmoo.size() != 0, Exceptions::RuntimeError,
569  "MueLu::Ifpack2Smoother::Setup(): the number of local nodes is incompatible with the TVertLineIdsSmoo.");
570 
571  // actualDofsPerNode is the actual number of matrix rows per mesh element.
572  // It is encoded in either the MueLu Level, or in the Xpetra matrix block size.
573  // This value is needed by Ifpack2 to do decoupled block relaxation.
574  int actualDofsPerNode = numLocalRows / TVertLineIdSmoo.size();
575  LO matrixBlockSize = matA->GetFixedBlockSize();
576  if (matrixBlockSize > 1 && actualDofsPerNode > 1) {
577  TEUCHOS_TEST_FOR_EXCEPTION(actualDofsPerNode != matrixBlockSize, Exceptions::RuntimeError,
578  "MueLu::Ifpack2Smoother::Setup(): A is a block matrix but its block size and DOFs/node from partitioner disagree");
579  } else if (matrixBlockSize > 1) {
580  actualDofsPerNode = matrixBlockSize;
581  }
582  myparamList.set("partitioner: PDE equations", actualDofsPerNode);
583 
584  if (numLocalRows == Teuchos::as<size_t>(TVertLineIdSmoo.size())) {
585  myparamList.set("partitioner: type", "user");
586  myparamList.set("partitioner: map", TVertLineIdSmoo);
587  myparamList.set("partitioner: local parts", maxPart + 1);
588  } else {
589  if (myparamList.isParameter("partitioner: block size") &&
590  myparamList.get<int>("partitioner: block size") != -1) {
591  int block_size = myparamList.get<int>("partitioner: block size");
592  TEUCHOS_TEST_FOR_EXCEPTION(numLocalRows % block_size != 0, Exceptions::RuntimeError,
593  "MueLu::Ifpack2Smoother::Setup(): the number of local nodes is incompatible with the specified block size.");
594  numLocalRows /= block_size;
595  }
596 
597  // we assume a constant number of DOFs per node
598  size_t numDofsPerNode = numLocalRows / TVertLineIdSmoo.size();
599 
600  // Create a new Teuchos::ArrayRCP<LO> of size numLocalRows and fill it with the corresponding information
602  for (size_t blockRow = 0; blockRow < Teuchos::as<size_t>(TVertLineIdSmoo.size()); ++blockRow)
603  for (size_t dof = 0; dof < numDofsPerNode; dof++)
604  partitionerMap[blockRow * numDofsPerNode + dof] = TVertLineIdSmoo[blockRow];
605  myparamList.set("partitioner: type", "user");
606  myparamList.set("partitioner: map", partitionerMap);
607  myparamList.set("partitioner: local parts", maxPart + 1);
608  }
609 
610  if (type_ == "LINESMOOTHING_BANDED_RELAXATION" ||
611  type_ == "LINESMOOTHING_BANDED RELAXATION" ||
612  type_ == "LINESMOOTHING_BANDEDRELAXATION")
613  type_ = "BANDEDRELAXATION";
614  else if (type_ == "LINESMOOTHING_TRIDI_RELAXATION" ||
615  type_ == "LINESMOOTHING_TRIDI RELAXATION" ||
616  type_ == "LINESMOOTHING_TRIDIRELAXATION" ||
617  type_ == "LINESMOOTHING_TRIDIAGONAL_RELAXATION" ||
618  type_ == "LINESMOOTHING_TRIDIAGONAL RELAXATION" ||
619  type_ == "LINESMOOTHING_TRIDIAGONALRELAXATION")
620  type_ = "TRIDIAGONALRELAXATION";
621  else
622  type_ = "BLOCKRELAXATION";
623  } else {
624  // line detection failed -> fallback to point-wise relaxation
625  this->GetOStream(Runtime0) << "Line detection failed: fall back to point-wise relaxation" << std::endl;
626  myparamList.remove("partitioner: type", false);
627  myparamList.remove("partitioner: map", false);
628  myparamList.remove("partitioner: local parts", false);
629  type_ = "RELAXATION";
630  }
631 
633 
634  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
635  SetPrecParameters();
636  prec_->initialize();
637  prec_->compute();
638 }
639 
640 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
642  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
643 
644  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
645  if (!bA.is_null())
646  A_ = bA->Merge();
647 
649 
650  bool reusePreconditioner = false;
651  if (this->IsSetup() == true) {
652  // Reuse the constructed preconditioner
653  this->GetOStream(Runtime1) << "MueLu::Ifpack2Smoother::SetupBlockRelaxation(): Setup() has already been called, assuming reuse" << std::endl;
654 
656  if (!prec.is_null()) {
657  prec->setMatrix(tA);
658  reusePreconditioner = true;
659  } else {
660  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupBlockRelaxation(): reuse of this type is not available (failed cast to CanChangeMatrix), "
661  "reverting to full construction"
662  << std::endl;
663  }
664  }
665 
666  if (!reusePreconditioner) {
667  ParameterList& myparamList = const_cast<ParameterList&>(this->GetParameterList());
668  myparamList.print();
669  if (myparamList.isParameter("partitioner: type") &&
670  myparamList.get<std::string>("partitioner: type") == "line") {
672  Factory::Get<Teuchos::RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LO, GO, NO>>>(currentLevel, "Coordinates");
674 
675  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
676  size_t lclSize = A_->getRangeMap()->getLocalNumElements();
677  if (!matA.is_null())
678  lclSize = matA->getLocalNumRows();
679  size_t numDofsPerNode = lclSize / xCoordinates->getMap()->getLocalNumElements();
680  myparamList.set("partitioner: coordinates", coordinates);
681  myparamList.set("partitioner: PDE equations", (int)numDofsPerNode);
682  }
683 
684  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
685  SetPrecParameters();
686  prec_->initialize();
687  }
688 
689  prec_->compute();
690 }
691 
692 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
694  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
695  using STS = Teuchos::ScalarTraits<SC>;
696  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
697  if (!bA.is_null())
698  A_ = bA->Merge();
699 
701 
702  bool reusePreconditioner = false;
703 
704  if (this->IsSetup() == true) {
705  // Reuse the constructed preconditioner
706  this->GetOStream(Runtime1) << "MueLu::Ifpack2Smoother::SetupChebyshev(): Setup() has already been called, assuming reuse" << std::endl;
707 
709  if (!prec.is_null()) {
710  prec->setMatrix(tA);
711  reusePreconditioner = true;
712  } else {
713  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupChebyshev(): reuse of this type is not available (failed cast to CanChangeMatrix), "
714  "reverting to full construction"
715  << std::endl;
716  }
717  }
718 
719  // Take care of the eigenvalues
720  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
721  SC negone = -STS::one();
722  SC lambdaMax = SetupChebyshevEigenvalues(currentLevel, "A", "", paramList);
723 
724  if (!reusePreconditioner) {
725  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
726  SetPrecParameters();
727  {
728  SubFactoryMonitor m(*this, "Preconditioner init", currentLevel);
729  prec_->initialize();
730  }
731  } else
732  SetPrecParameters();
733 
734  {
735  SubFactoryMonitor m(*this, "Preconditioner compute", currentLevel);
736  prec_->compute();
737  }
738 
739  if (lambdaMax == negone) {
740  typedef Tpetra::RowMatrix<SC, LO, GO, NO> MatrixType;
741 
743  if (chebyPrec != Teuchos::null) {
744  lambdaMax = chebyPrec->getLambdaMaxForApply();
745  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
746  if (!matA.is_null())
747  matA->SetMaxEigenvalueEstimate(lambdaMax);
748  this->GetOStream(Statistics1) << "chebyshev: max eigenvalue (calculated by Ifpack2)"
749  << " = " << lambdaMax << std::endl;
750  }
751  TEUCHOS_TEST_FOR_EXCEPTION(lambdaMax == negone, Exceptions::RuntimeError, "MueLu::Ifpack2Smoother::Setup(): no maximum eigenvalue estimate");
752  }
753 }
754 
755 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
757  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
758  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
759  if (!bA.is_null())
760  A_ = bA->Merge();
761 
763 
764  bool reusePreconditioner = false;
765  if (this->IsSetup() == true) {
766  // Reuse the constructed preconditioner
767  this->GetOStream(Runtime1) << "MueLu::Ifpack2Smoother::SetupHiptmair(): Setup() has already been called, assuming reuse" << std::endl;
768 
770  if (!prec.is_null()) {
771  prec->setMatrix(tA);
772  reusePreconditioner = true;
773  } else {
774  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupHiptmair(): reuse of this type is not available (failed cast to CanChangeMatrix), "
775  "reverting to full construction"
776  << std::endl;
777  }
778  }
779 
780  // If we're doing Chebyshev subsmoothing, we'll need to get the eigenvalues
782  ParameterList& paramList = const_cast<ParameterList&>(this->GetParameterList());
783  std::string smoother1 = paramList.get("hiptmair: smoother type 1", "CHEBYSHEV");
784  std::string smoother2 = paramList.get("hiptmair: smoother type 2", "CHEBYSHEV");
785  SC lambdaMax11 = negone;
786 
787  if (smoother1 == "CHEBYSHEV") {
788  ParameterList& list1 = paramList.sublist("hiptmair: smoother list 1");
789  lambdaMax11 = SetupChebyshevEigenvalues(currentLevel, "A", "EdgeMatrix ", list1);
790  }
791  if (smoother2 == "CHEBYSHEV") {
792  ParameterList& list2 = paramList.sublist("hiptmair: smoother list 2");
793  SetupChebyshevEigenvalues(currentLevel, "NodeMatrix", "NodeMatrix ", list2);
794  }
795 
796  // FIXME: Should really add some checks to make sure the eigenvalue calcs worked like in
797  // the regular SetupChebyshev
798 
799  // Grab the auxillary matrices and stick them on the list
800  RCP<Operator> NodeMatrix = currentLevel.Get<RCP<Operator>>("NodeMatrix");
801  RCP<Operator> D0 = currentLevel.Get<RCP<Operator>>("D0");
802 
803  RCP<tRowMatrix> tNodeMatrix = Utilities::Op2NonConstTpetraRow(NodeMatrix);
805 
806  Teuchos::ParameterList newlist;
807  newlist.set("P", tD0);
808  newlist.set("PtAP", tNodeMatrix);
809  if (!reusePreconditioner) {
810  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
811  SetPrecParameters(newlist);
812  prec_->initialize();
813  }
814 
815  prec_->compute();
816 
817  // Post-processing the (1,1) eigenvalue, if we have one
818  if (smoother1 == "CHEBYSHEV" && lambdaMax11 == negone) {
819  using Teuchos::rcp_dynamic_cast;
820  typedef Tpetra::RowMatrix<SC, LO, GO, NO> MatrixType;
821  auto hiptmairPrec = rcp_dynamic_cast<Ifpack2::Hiptmair<MatrixType>>(prec_);
822  if (hiptmairPrec != Teuchos::null) {
823  auto chebyPrec = rcp_dynamic_cast<Ifpack2::Chebyshev<MatrixType>>(hiptmairPrec->getPrec1());
824  if (chebyPrec != Teuchos::null) {
825  lambdaMax11 = chebyPrec->getLambdaMaxForApply();
826  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(A_);
827  if (!matA.is_null())
828  matA->SetMaxEigenvalueEstimate(lambdaMax11);
829  this->GetOStream(Statistics1) << "chebyshev: max eigenvalue (calculated by Ifpack2)"
830  << " = " << lambdaMax11 << std::endl;
831  }
832  TEUCHOS_TEST_FOR_EXCEPTION(lambdaMax11 == negone, Exceptions::RuntimeError, "MueLu::Ifpack2Smoother::Setup(): no maximum eigenvalue estimate");
833  }
834  }
835 }
836 
837 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
838 Scalar Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetupChebyshevEigenvalues(Level& currentLevel, const std::string& matrixName, const std::string& label, ParameterList& paramList) const {
839  // Helper: This gets used for smoothers that want to set up Chebyhev
840  typedef Teuchos::ScalarTraits<SC> STS;
841  SC negone = -STS::one();
842  RCP<Operator> currentA = currentLevel.Get<RCP<Operator>>(matrixName);
843  RCP<Matrix> matA = rcp_dynamic_cast<Matrix>(currentA);
844  SC lambdaMax = negone;
845 
846  std::string maxEigString = "chebyshev: max eigenvalue";
847  std::string eigRatioString = "chebyshev: ratio eigenvalue";
848 
849  // Get/calculate the maximum eigenvalue
850  if (paramList.isParameter(maxEigString)) {
851  if (paramList.isType<double>(maxEigString))
852  lambdaMax = paramList.get<double>(maxEigString);
853  else
854  lambdaMax = paramList.get<SC>(maxEigString);
855  this->GetOStream(Statistics1) << label << maxEigString << " (cached with smoother parameter list) = " << lambdaMax << std::endl;
856  if (!matA.is_null())
857  matA->SetMaxEigenvalueEstimate(lambdaMax);
858 
859  } else if (!matA.is_null()) {
860  lambdaMax = matA->GetMaxEigenvalueEstimate();
861  if (lambdaMax != negone) {
862  this->GetOStream(Statistics1) << label << maxEigString << " (cached with matrix) = " << lambdaMax << std::endl;
863  paramList.set(maxEigString, lambdaMax);
864  }
865  }
866 
867  // Calculate the eigenvalue ratio
868  const SC defaultEigRatio = 20;
869 
870  SC ratio = defaultEigRatio;
871  if (paramList.isParameter(eigRatioString)) {
872  if (paramList.isType<double>(eigRatioString))
873  ratio = paramList.get<double>(eigRatioString);
874  else
875  ratio = paramList.get<SC>(eigRatioString);
876  }
877  if (currentLevel.GetLevelID()) {
878  // Update ratio to be
879  // ratio = max(number of fine DOFs / number of coarse DOFs, defaultValue)
880  //
881  // NOTE: We don't need to request previous level matrix as we know for sure it was constructed
882  RCP<const Operator> fineA = currentLevel.GetPreviousLevel()->Get<RCP<Operator>>(matrixName);
883  size_t nRowsFine = fineA->getDomainMap()->getGlobalNumElements();
884  size_t nRowsCoarse = currentA->getDomainMap()->getGlobalNumElements();
885 
886  SC levelRatio = as<SC>(as<double>(nRowsFine) / nRowsCoarse);
887  if (STS::magnitude(levelRatio) > STS::magnitude(ratio))
888  ratio = levelRatio;
889  }
890 
891  this->GetOStream(Statistics1) << label << eigRatioString << " (computed) = " << ratio << std::endl;
892  paramList.set(eigRatioString, ratio);
893 
894  if (paramList.isParameter("chebyshev: use rowsumabs diagonal scaling")) {
895  this->GetOStream(Runtime1) << "chebyshev: using rowsumabs diagonal scaling" << std::endl;
896  bool doScale = false;
897  doScale = paramList.get<bool>("chebyshev: use rowsumabs diagonal scaling");
898  paramList.remove("chebyshev: use rowsumabs diagonal scaling");
899  double chebyReplaceTol = Teuchos::ScalarTraits<Scalar>::eps() * 100;
900  std::string paramName = "chebyshev: rowsumabs diagonal replacement tolerance";
901  if (paramList.isParameter(paramName)) {
902  chebyReplaceTol = paramList.get<double>(paramName);
903  paramList.remove(paramName);
904  }
905  double chebyReplaceVal = Teuchos::ScalarTraits<double>::zero();
906  paramName = "chebyshev: rowsumabs diagonal replacement value";
907  if (paramList.isParameter(paramName)) {
908  chebyReplaceVal = paramList.get<double>(paramName);
909  paramList.remove(paramName);
910  }
911  bool chebyReplaceSingleEntryRowWithZero = false;
912  paramName = "chebyshev: rowsumabs replace single entry row with zero";
913  if (paramList.isParameter(paramName)) {
914  chebyReplaceSingleEntryRowWithZero = paramList.get<bool>(paramName);
915  paramList.remove(paramName);
916  }
917  bool useAverageAbsDiagVal = false;
918  paramName = "chebyshev: rowsumabs use automatic diagonal tolerance";
919  if (paramList.isParameter(paramName)) {
920  useAverageAbsDiagVal = paramList.get<bool>(paramName);
921  paramList.remove(paramName);
922  }
923  if (doScale) {
924  TEUCHOS_ASSERT(!matA.is_null());
925  const bool doReciprocal = true;
926  RCP<Vector> lumpedDiagonal = Utilities::GetLumpedMatrixDiagonal(*matA, doReciprocal, chebyReplaceTol, chebyReplaceVal, chebyReplaceSingleEntryRowWithZero, useAverageAbsDiagVal);
928  paramList.set("chebyshev: operator inv diagonal", tmpVec.getTpetra_Vector());
929  }
930  }
931 
932  return lambdaMax;
933 }
934 
935 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
937  typedef Tpetra::RowMatrix<SC, LO, GO, NO> tRowMatrix;
938  RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_);
939  if (!bA.is_null())
940  A_ = bA->Merge();
941 
943 
944  bool reusePreconditioner = false;
945  if (this->IsSetup() == true) {
946  // Reuse the constructed preconditioner
947  this->GetOStream(Runtime1) << "MueLu::Ifpack2Smoother::SetupGeneric(): Setup() has already been called, assuming reuse" << std::endl;
948 
950  if (!prec.is_null()) {
951  prec->setMatrix(tA);
952  reusePreconditioner = true;
953  } else {
954  this->GetOStream(Warnings0) << "MueLu::Ifpack2Smoother::SetupGeneric(): reuse of this type is not available (failed cast to CanChangeMatrix), "
955  "reverting to full construction"
956  << std::endl;
957  }
958  }
959 
960  if (!reusePreconditioner) {
961  prec_ = Ifpack2::Factory::create(type_, tA, overlap_);
962  SetPrecParameters();
963  prec_->initialize();
964  }
965 
966  prec_->compute();
967 }
968 
969 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
970 void Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
971  TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::Ifpack2Smoother::Apply(): Setup() has not been called");
972 
973  // Forward the InitialGuessIsZero option to Ifpack2
974  // TODO: It might be nice to switch back the internal
975  // "zero starting solution" option of the ifpack2 object prec_ to his
976  // initial value at the end but there is no way right now to get
977  // the current value of the "zero starting solution" in ifpack2.
978  // It's not really an issue, as prec_ can only be used by this method.
979  Teuchos::ParameterList paramList;
980  bool supportInitialGuess = false;
981  const Teuchos::ParameterList params = this->GetParameterList();
982 
983  if (prec_->supportsZeroStartingSolution()) {
984  prec_->setZeroStartingSolution(InitialGuessIsZero);
985  supportInitialGuess = true;
986  } else if (type_ == "SCHWARZ") {
987  paramList.set("schwarz: zero starting solution", InitialGuessIsZero);
988  // Because additive Schwarz has "delta" semantics, it's sufficient to
989  // toggle only the zero initial guess flag, and not pass in already
990  // set parameters. If we call SetPrecParameters, the subdomain solver
991  // will be destroyed.
992  prec_->setParameters(paramList);
993  supportInitialGuess = true;
994  }
995 
996  // TODO JJH 30Apr2014 Calling SetPrecParameters(paramList) when the smoother
997  // is Ifpack2::AdditiveSchwarz::setParameterList() will destroy the subdomain
998  //(aka inner) solver. This behavior is documented but a departure from what
999  // it previously did, and what other Ifpack2 solvers currently do. So I have
1000  // moved SetPrecParameters(paramList) into the if-else block above.
1001 
1002  // Apply
1003  if (InitialGuessIsZero || supportInitialGuess) {
1006  prec_->apply(tpB, tpX);
1007  } else {
1008  typedef Teuchos::ScalarTraits<Scalar> TST;
1009 
1010  RCP<MultiVector> Residual;
1011  {
1012  std::string prefix = this->ShortClassName() + ": Apply: ";
1013  RCP<TimeMonitor> tM = rcp(new TimeMonitor(*this, prefix + "residual calculation", Timings0));
1014  Residual = Utilities::Residual(*A_, X, B);
1015  }
1016 
1017  RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
1018 
1021 
1022  prec_->apply(tpB, tpX);
1023 
1024  X.update(TST::one(), *Correction, TST::one());
1025  }
1026 }
1027 
1028 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1030  RCP<Ifpack2Smoother> smoother = rcp(new Ifpack2Smoother(*this));
1031  smoother->SetParameterList(this->GetParameterList());
1032  return smoother;
1033 }
1034 
1035 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1037  std::ostringstream out;
1039  out << prec_->description();
1040  } else {
1042  out << "{type = " << type_ << "}";
1043  }
1044  return out.str();
1045 }
1046 
1047 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1050 
1051  if (verbLevel & Parameters0)
1052  out0 << "Prec. type: " << type_ << std::endl;
1053 
1054  if (verbLevel & Parameters1) {
1055  out0 << "Parameter list: " << std::endl;
1056  Teuchos::OSTab tab2(out);
1057  out << this->GetParameterList();
1058  out0 << "Overlap: " << overlap_ << std::endl;
1059  }
1060 
1061  if (verbLevel & External)
1062  if (prec_ != Teuchos::null) {
1063  Teuchos::OSTab tab2(out);
1064  out << *prec_ << std::endl;
1065  }
1066 
1067  if (verbLevel & Debug) {
1068  out0 << "IsSetup: " << Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl
1069  << "-" << std::endl
1070  << "RCP<prec_>: " << prec_ << std::endl;
1071  }
1072 }
1073 
1074 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1076  typedef Tpetra::RowMatrix<SC, LO, GO, NO> MatrixType;
1077  // NOTE: Only works for a subset of Ifpack2's smoothers
1079  if (!pr.is_null()) return pr->getNodeSmootherComplexity();
1080 
1082  if (!pc.is_null()) return pc->getNodeSmootherComplexity();
1083 
1085  if (!pb.is_null()) return pb->getNodeSmootherComplexity();
1086 
1087  RCP<Ifpack2::ILUT<MatrixType>> pi = rcp_dynamic_cast<Ifpack2::ILUT<MatrixType>>(prec_);
1088  if (!pi.is_null()) return pi->getNodeSmootherComplexity();
1089 
1090  RCP<Ifpack2::RILUK<MatrixType>> pk = rcp_dynamic_cast<Ifpack2::RILUK<MatrixType>>(prec_);
1091  if (!pk.is_null()) return pk->getNodeSmootherComplexity();
1092 
1094 }
1095 
1096 } // namespace MueLu
1097 
1098 #endif // HAVE_MUELU_IFPACK2
1099 #endif // MUELU_IFPACK2SMOOTHER_DEF_HPP
void DeclareInput(Level &currentLevel) const
Input.
Important warning messages (one line)
void SetupGeneric(Level &currentLevel)
Exception indicating invalid cast attempted.
RCP< Level > & GetPreviousLevel()
Previous level.
High level timing information (use Teuchos::TimeMonitor::summarize() to print)
MueLu::DefaultLocalOrdinal LocalOrdinal
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
void FindGeometricSeedOrdinals(Teuchos::RCP< Basis > basis, const LOFieldContainer &elementToNodeMap, std::vector< std::vector< LocalOrdinal > > &seeds, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &rowMap, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &columnMap)
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.
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
static magnitudeType eps()
Print external lib objects.
GlobalOrdinal GO
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraRow(RCP< Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
friend class Ifpack2Smoother
Constructor.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Print more statistics.
Print additional debugging information.
LocalOrdinal LO
One-liner description of what is happening.
void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
T * get() const
size_type size() const
Integrates Teuchos::TimeMonitor with MueLu verbosity system.
std::string type_
ifpack2-specific key phrase that denote smoother type
void SetupBlockRelaxation(Level &currentLevel)
void resize(const size_type n, const T &val=T())
bool isParameter(const std::string &name) const
void SetupSchwarz(Level &currentLevel)
void SetupLineSmoothing(Level &currentLevel)
Print statistics that do not involve significant additional computation.
bool remove(std::string const &name, bool throwIfNotExists=true)
static RCP< MultiVector > Residual(const Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const MultiVector &X, const MultiVector &RHS)
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
RCP< SmootherPrototype > Copy() const
void declareConstructionOutcome(bool fail, std::string msg)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
bool isSublist(const std::string &name) const
void Setup(Level &currentLevel)
Set up the smoother.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
static Teuchos::ArrayRCP< const bool > DetectDirichletRows(const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Magnitude &tol=Teuchos::ScalarTraits< Magnitude >::zero(), bool count_twos_as_dirichlet=false)
Detect Dirichlet rows.
void SetupHiptmair(Level &currentLevel)
void SetupTopological(Level &currentLevel)
std::string description() const
Return a simple one-line description of this object.
bool IsSetup() const
Get the state of a smoother prototype.
static Teuchos::RCP< Preconditioner< typename MatrixType::scalar_type, typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type > > create(const std::string &precType, const Teuchos::RCP< const MatrixType > &matrix)
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
ParameterList & setParameters(const ParameterList &source)
Print all timing information.
Print class parameters.
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
MatrixType::scalar_type getLambdaMaxForApply() const
Scalar SC
void SetupAggregate(Level &currentLevel)
bool isType(const std::string &name) const
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Vector() const
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
Node NO
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Teuchos::RCP< BlockCrsMatrix< Scalar, LO, GO, Node > > convertToBlockCrsMatrix(const Tpetra::CrsMatrix< Scalar, LO, GO, Node > &pointMatrix, const LO &blockSize, bool use_local_ID=true)
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:76
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
void SetupChebyshev(Level &currentLevel)
#define TEUCHOS_ASSERT(assertion_test)
Description of what is happening (more verbose)
Class that encapsulates Ifpack2 smoothers.
static Teuchos::RCP< Vector > GetLumpedMatrixDiagonal(Matrix const &A, const bool doReciprocal=false, Magnitude tol=Teuchos::ScalarTraits< Scalar >::magnitude(Teuchos::ScalarTraits< Scalar >::zero()), Scalar valReplacement=Teuchos::ScalarTraits< Scalar >::zero(), const bool replaceSingleEntryRowWithZero=false, const bool useAverageAbsDiagVal=false)
Extract Matrix Diagonal of lumped matrix.
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > MV2NonConstTpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> vec)
virtual std::string description() const
Return a simple one-line description of this object.
std::string toString(const T &t)
bool is_null() const
Scalar SetupChebyshevEigenvalues(Level &currentLevel, const std::string &matrixName, const std::string &label, Teuchos::ParameterList &paramList) const