MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_TopRAPFactory_def.hpp
Go to the documentation of this file.
1 /*
2  * MueLu_TopRAPFactory_def.hpp
3  *
4  * Created on: Jan 25, 2016
5  * Author: tawiesn
6  */
7 
8 #ifndef PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPRAPFACTORY_DEF_HPP_
9 #define PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPRAPFACTORY_DEF_HPP_
10 
11 
12 #include "MueLu_ConfigDefs.hpp"
13 
16 //#include "MueLu_HierarchyUtils_fwd.hpp"
17 #include "MueLu_TopRAPFactory.hpp"
18 #include "MueLu_Level_fwd.hpp"
24 #include "MueLu_Hierarchy_fwd.hpp"
26 
27 
28 namespace MueLu {
29 
30  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32  PFact_ (parentFactoryManager->GetFactory("P")),
33  RFact_ (parentFactoryManager->GetFactory("R")),
34  AcFact_(parentFactoryManager->GetFactory("A"))
35  { }
36 
37  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
39  PFact_ (parentFactoryManagerCoarse->GetFactory("P")),
40  RFact_ (parentFactoryManagerCoarse->GetFactory("R")),
41  AcFact_(parentFactoryManagerCoarse->GetFactory("A"))
42  { }
43 
44  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
46 
47  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
49  if (PFact_ != Teuchos::null) coarseLevel.DeclareInput("P", PFact_.get());
50  if (RFact_ != Teuchos::null) coarseLevel.DeclareInput("R", RFact_.get());
51  if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) coarseLevel.DeclareInput("A", AcFact_.get());
52  }
53 
54  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
55  void TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level & /* fineLevel */, Level & coarseLevel) const {
56  if ((PFact_ != Teuchos::null) && (PFact_ != NoFactory::getRCP())) {
57  RCP<Operator> oP = coarseLevel.Get<RCP<Operator> >("P", PFact_.get());
58  RCP<Matrix> P = rcp_dynamic_cast<Matrix>(oP);
59  if (!P.is_null()) coarseLevel.Set("P", P, NoFactory::get());
60  else coarseLevel.Set("P", oP, NoFactory::get());
61  coarseLevel.AddKeepFlag ("P", NoFactory::get(), MueLu::Final); // FIXME2: Order of Remove/Add matter (data removed otherwise). Should do something about this
62  coarseLevel.RemoveKeepFlag("P", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack, I should change behavior of Level::Set() instead. FIXME3: Should not be removed if flag was there already
63 
64  }
65 
66  if ((RFact_ != Teuchos::null) && (RFact_ != NoFactory::getRCP()) ) {
67  RCP<Operator> oR = coarseLevel.Get<RCP<Operator> >("R", RFact_.get());
68  RCP<Matrix> R = rcp_dynamic_cast<Matrix>(oR);
69  if (!R.is_null()) coarseLevel.Set("R", R, NoFactory::get());
70  else coarseLevel.Set("R", oR, NoFactory::get());
71  coarseLevel.AddKeepFlag ("R", NoFactory::get(), MueLu::Final);
72  coarseLevel.RemoveKeepFlag("R", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
73  }
74 
75  if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) {
76  RCP<Operator> oA = coarseLevel.Get<RCP<Operator> >("A", AcFact_.get());
77  RCP<Matrix> A = rcp_dynamic_cast<Matrix>(oA);
78  if (!A.is_null()) coarseLevel.Set("A", A, NoFactory::get());
79  else coarseLevel.Set("A", oA, NoFactory::get());
80  coarseLevel.AddKeepFlag ("A", NoFactory::get(), MueLu::Final);
81  coarseLevel.RemoveKeepFlag("A", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
82  }
83  }
84 }
85 
86 
87 #endif /* PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPRAPFACTORY_DEF_HPP_ */
TopRAPFactory(RCP< const FactoryManagerBase > parentFactoryManager)
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 DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
User data are always kept. This flag is set automatically when Level::Set(&quot;data&quot;, data) is used...
static const NoFactory * get()
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
static const RCP< const NoFactory > getRCP()
Static Get() functions.
bool is_null() const