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 // @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 /*
11  * MueLu_TopRAPFactory_def.hpp
12  *
13  * Created on: Jan 25, 2016
14  * Author: tawiesn
15  */
16 
17 #ifndef PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPRAPFACTORY_DEF_HPP_
18 #define PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPRAPFACTORY_DEF_HPP_
19 
20 #include "MueLu_ConfigDefs.hpp"
21 
23 //#include "MueLu_HierarchyUtils_fwd.hpp"
25 
26 namespace MueLu {
27 
28 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
30  : PFact_(parentFactoryManager->GetFactory("P"))
31  , RFact_(parentFactoryManager->GetFactory("R"))
32  , AcFact_(parentFactoryManager->GetFactory("A")) {}
33 
34 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
36  : PFact_(parentFactoryManagerCoarse->GetFactory("P"))
37  , RFact_(parentFactoryManagerCoarse->GetFactory("R"))
38  , AcFact_(parentFactoryManagerCoarse->GetFactory("A")) {}
39 
40 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
42 
43 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
45  if (PFact_ != Teuchos::null) coarseLevel.DeclareInput("P", PFact_.get());
46  if (RFact_ != Teuchos::null) coarseLevel.DeclareInput("R", RFact_.get());
47  if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) coarseLevel.DeclareInput("A", AcFact_.get());
48 }
49 
50 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
52  if ((PFact_ != Teuchos::null) && (PFact_ != NoFactory::getRCP())) {
53  RCP<Operator> oP = coarseLevel.Get<RCP<Operator> >("P", PFact_.get());
54  // Don't have a valid operator (e.g., # global aggregates is 0) so we just bail out
55  // This level will ultimately be removed in MueLu_Hierarchy_defs.h via a resize()j
56  if (oP == Teuchos::null) return;
57  RCP<Matrix> P = rcp_dynamic_cast<Matrix>(oP);
58  if (!P.is_null())
59  coarseLevel.Set("P", P, NoFactory::get());
60  else
61  coarseLevel.Set("P", oP, NoFactory::get());
62  coarseLevel.AddKeepFlag("P", NoFactory::get(), MueLu::Final); // FIXME2: Order of Remove/Add matter (data removed otherwise). Should do something about this
63  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
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())
70  coarseLevel.Set("R", R, NoFactory::get());
71  else
72  coarseLevel.Set("R", oR, NoFactory::get());
73  coarseLevel.AddKeepFlag("R", NoFactory::get(), MueLu::Final);
74  coarseLevel.RemoveKeepFlag("R", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
75  }
76 
77  if ((AcFact_ != Teuchos::null) && (AcFact_ != NoFactory::getRCP())) {
78  RCP<Operator> oA = coarseLevel.Get<RCP<Operator> >("A", AcFact_.get());
79  RCP<Matrix> A = rcp_dynamic_cast<Matrix>(oA);
80  if (!A.is_null())
81  coarseLevel.Set("A", A, NoFactory::get());
82  else
83  coarseLevel.Set("A", oA, NoFactory::get());
84  coarseLevel.AddKeepFlag("A", NoFactory::get(), MueLu::Final);
85  coarseLevel.RemoveKeepFlag("A", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
86  }
87 }
88 } // namespace MueLu
89 
90 #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:63
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)
static const RCP< const NoFactory > getRCP()
Static Get() functions.
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()
bool is_null() const