MueLu Version of the Day
Loading...
Searching...
No Matches
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
26namespace MueLu {
27
28template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
29TopRAPFactory<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
34template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
35TopRAPFactory<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
40template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
42
43template <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
50template <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_ */
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
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)
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
static const RCP< const NoFactory > getRCP()
Static Get() functions.
static const NoFactory * get()
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
TopRAPFactory(RCP< const FactoryManagerBase > parentFactoryManager)
Namespace for MueLu classes and methods.
@ Final
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....