MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_MultiVectorTransferFactory_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_MULTIVECTORTRANSFER_FACTORY_DEF_HPP
11 #define MUELU_MULTIVECTORTRANSFER_FACTORY_DEF_HPP
12 
14 #include "Xpetra_MultiVectorFactory.hpp"
15 
16 #include "MueLu_Level.hpp"
17 #include "MueLu_Monitor.hpp"
18 
19 namespace MueLu {
20 
21 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
23  RCP<ParameterList> validParamList = rcp(new ParameterList());
24 
25  validParamList->set<std::string>("Vector name", "undefined", "Name of the vector that will be transferred on the coarse grid (level key)"); // TODO: how to set a validator without default value?
26  validParamList->set<RCP<const FactoryBase> >("Vector factory", Teuchos::null, "Factory of the vector");
27  validParamList->set<RCP<const FactoryBase> >("R", Teuchos::null, "Factory of the transfer operator (restriction)");
28 
29  return validParamList;
30 }
31 
32 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
34  SetParameter("Vector name", ParameterEntry(vectorName));
35 }
36 
37 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
39  const ParameterList &pL = GetParameterList();
40  std::string vectorName = pL.get<std::string>("Vector name");
41 
42  fineLevel.DeclareInput(vectorName, GetFactory("Vector factory").get(), this);
43  Input(coarseLevel, "R");
44 }
45 
46 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
48  FactoryMonitor m(*this, "Build", coarseLevel);
49 
50  const ParameterList &pL = GetParameterList();
51  std::string vectorName = pL.get<std::string>("Vector name");
52 
53  RCP<MultiVector> fineVector = fineLevel.Get<RCP<MultiVector> >(vectorName, GetFactory("Vector factory").get());
54  RCP<Matrix> transferOp = Get<RCP<Matrix> >(coarseLevel, "R");
55 
56  RCP<MultiVector> coarseVector = MultiVectorFactory::Build(transferOp->getRangeMap(), fineVector->getNumVectors());
57  GetOStream(Runtime0) << "Transferring multivector \"" << vectorName << "\"" << std::endl;
58 
59  RCP<MultiVector> onesVector = MultiVectorFactory::Build(transferOp->getDomainMap(), 1);
60  onesVector->putScalar(Teuchos::ScalarTraits<Scalar>::one());
61  RCP<MultiVector> rowSumVector = MultiVectorFactory::Build(transferOp->getRangeMap(), 1);
62  transferOp->apply(*onesVector, *rowSumVector);
63  transferOp->apply(*fineVector, *coarseVector);
64 
65  if (vectorName == "Coordinates")
66  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "Use CoordinatesTransferFactory to transfer coordinates instead of MultiVectorTransferFactory.");
67 
68  Set<RCP<MultiVector> >(coarseLevel, vectorName, coarseVector);
69 
70 } // Build
71 
72 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74  if (blksize == 1)
75  return coordinates;
76 
77  ArrayRCP<SC> expandCoord(coordinates.size() * blksize); // TODO: how to avoid automatic initialization of the vector? using arcp()?
78 
79  for (int i = 0; i < coordinates.size(); i++) {
80  for (int j = 0; j < blksize; j++) {
81  expandCoord[i * blksize + j] = coordinates[i];
82  }
83  }
84  return expandCoord;
85 
86 } // expandCoordinates
87 
88 } // namespace MueLu
89 
90 #endif // MUELU_MULTIVECTORTRANSFER_FACTORY_DEF_HPP
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
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.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
One-liner description of what is happening.
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
size_type size() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
static ArrayRCP< SC > expandCoordinates(ArrayRCP< SC > coord, LocalOrdinal blksize)
Exception throws to report errors in the internal logical of the program.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.