MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_InitialBlockNumberFactory_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_INITIALBLOCKNUMBER_FACTORY_DEF_HPP
11#define MUELU_INITIALBLOCKNUMBER_FACTORY_DEF_HPP
12
13#include "Xpetra_VectorFactory.hpp"
14#include "Xpetra_Map.hpp"
15#include "Xpetra_Matrix.hpp"
16#include "Xpetra_IO.hpp"
17
19
20#include "MueLu_MasterList.hpp"
21#include "MueLu_Level.hpp"
22#include "MueLu_Monitor.hpp"
23
24namespace MueLu {
25
26template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
28 RCP<ParameterList> validParamList = rcp(new ParameterList());
29
30#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
31 SET_VALID_ENTRY("aggregation: block diagonal: interleaved blocksize");
32#undef SET_VALID_ENTRY
33
34 validParamList->set<RCP<const FactoryBase>>("A", Teuchos::null, "Generating factory of the matrix A");
35 validParamList->set<RCP<const FactoryBase>>("BlockNumber", Teuchos::null, "Generating factory of the BlockNumber vector");
36
37 return validParamList;
38}
39
40template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
42 Input(currentLevel, "A");
43
44 if (currentLevel.GetLevelID() == 0 && currentLevel.IsAvailable("BlockNumber", NoFactory::get()))
45 Input(currentLevel, "BlockNumber");
46}
47
48template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
50 FactoryMonitor m(*this, "Build", currentLevel);
51 const ParameterList& pL = GetParameterList();
52
53 RCP<LocalOrdinalVector> BlockNumber;
54
55 if (currentLevel.IsAvailable("BlockNumber", NoFactory::get())) {
56 // Set already provided BlockNumber
57 BlockNumber = Get<RCP<LocalOrdinalVector>>(currentLevel, "BlockNumber");
58 GetOStream(Statistics1) << "Use user-given blocknumber with length=" << BlockNumber->getGlobalLength() << std::endl;
59 } else {
60 // Creating interleaved BlockNumber from scratch
61 RCP<Matrix> A = Get<RCP<Matrix>>(currentLevel, "A");
62 LO blocksize = as<LO>(pL.get<int>("aggregation: block diagonal: interleaved blocksize"));
63
64 GetOStream(Statistics1) << "Generating new interleaved blocking with " << blocksize << " equations" << std::endl;
65 BlockNumber = LocalOrdinalVectorFactory::Build(A->getRowMap(), false);
66 Teuchos::ArrayRCP<LO> bn_data = BlockNumber->getDataNonConst(0);
67 for (LO i = 0; i < (LO)A->getRowMap()->getLocalNumElements(); i++)
68 bn_data[i] = i % blocksize;
69 }
70
71 Set(currentLevel, "BlockNumber", BlockNumber);
72}
73
74} // namespace MueLu
75
76#endif // MUELU_INITIALBLOCKNUMBER_FACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
Timer to be used in factories. Similar to Monitor but with additional timers.
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
int GetLevelID() const
Return level number.
static const NoFactory * get()
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.