Debian Codegraph @

packages/muelu/src/MueCentral/MueLu_TopRAPFactory_def.hpp

raw
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
22 #include "MueLu_FactoryManagerBase.hpp"
23 //#include "MueLu_HierarchyUtils_fwd.hpp"
24 #include "MueLu_TopRAPFactory_decl.hpp"
25
26 namespace MueLu {
27
28 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
29 TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TopRAPFactory(RCP<const FactoryManagerBase> parentFactoryManager)
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>
35 TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TopRAPFactory(RCP<const FactoryManagerBase> /* parentFactoryManagerFine */, RCP<const FactoryManagerBase> parentFactoryManagerCoarse)
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>
41 TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::~TopRAPFactory() {}
42
43 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
44 void TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& /* fineLevel */, Level& coarseLevel) const {
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>
51 void TopRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& /* fineLevel */, Level& coarseLevel) const {
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_ */