MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_StructuredLineDetectionFactory_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_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
11 #define MUELU_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
12 
13 #include <Xpetra_Matrix.hpp>
14 
16 
17 #include "MueLu_Level.hpp"
18 
19 namespace MueLu {
20 
21 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
23  RCP<ParameterList> validParamList = rcp(new ParameterList());
24 
25  validParamList->set<RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory of the matrix A");
26  validParamList->set<std::string>("orientation", "Z", "Lines orientation");
27  validParamList->set<RCP<const FactoryBase> >("lNodesPerDim", Teuchos::null, "Number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
28 
29  return validParamList;
30 }
31 
32 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
34  Input(currentLevel, "A");
35  // Request the global number of nodes per dimensions
36  if (currentLevel.GetLevelID() == 0) {
37  if (currentLevel.IsAvailable("lNodesPerDim", NoFactory::get())) {
38  currentLevel.DeclareInput("lNodesPerDim", NoFactory::get(), this);
39  } else {
40  TEUCHOS_TEST_FOR_EXCEPTION(currentLevel.IsAvailable("gNodesPerDim", NoFactory::get()),
42  "lNodesPerDim was not provided by the user on level0!");
43  }
44  } else {
45  Input(currentLevel, "lNodesPerDim");
46  }
47 }
48 
49 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
51  // The following three variables are needed by the line smoothers in Ifpack/Ifpack2
52  LO NumZDir = 0;
53  Teuchos::ArrayRCP<LO> VertLineId = Teuchos::arcp<LO>(0);
54 
55  // collect information provided by user
56  const ParameterList& pL = GetParameterList();
57  const std::string lineOrientation = pL.get<std::string>("orientation");
58 
59  // Extract data from currentLevel
60  RCP<Matrix> A = Get<RCP<Matrix> >(currentLevel, "A");
61  Array<LO> lNodesPerDir = Get<Array<LO> >(currentLevel, "lNodesPerDim");
62  LO numNodes = lNodesPerDir[0] * lNodesPerDir[1] * lNodesPerDir[2];
63  VertLineId.resize(numNodes);
64  if (lineOrientation == "X") {
65  NumZDir = lNodesPerDir[0];
66  } else if (lineOrientation == "Y") {
67  NumZDir = lNodesPerDir[1];
68  } else if (lineOrientation == "Z") {
69  NumZDir = lNodesPerDir[2];
70  }
71 
72  for (LO k = 0; k < lNodesPerDir[2]; ++k) {
73  for (LO j = 0; j < lNodesPerDir[1]; ++j) {
74  for (LO i = 0; i < lNodesPerDir[0]; ++i) {
75  if (lineOrientation == "X") {
76  VertLineId[k * lNodesPerDir[1] * lNodesPerDir[0] + j * lNodesPerDir[0] + i] = k * lNodesPerDir[1] + j;
77  } else if (lineOrientation == "Y") {
78  VertLineId[k * lNodesPerDir[1] * lNodesPerDir[0] + j * lNodesPerDir[0] + i] = k * lNodesPerDir[0] + i;
79  } else if (lineOrientation == "Z") {
80  VertLineId[k * lNodesPerDir[1] * lNodesPerDir[0] + j * lNodesPerDir[0] + i] = j * lNodesPerDir[0] + i;
81  }
82  }
83  }
84  }
85 
86  Set(currentLevel, "CoarseNumZLayers", NumZDir);
87  Set(currentLevel, "LineDetection_VertLineIds", VertLineId);
88 }
89 
90 } // namespace MueLu
91 
92 #endif // MUELU_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
LocalOrdinal LO
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static const NoFactory * get()
void resize(const size_type n, const T &val=T())
void Build(Level &currentLevel) const
Build method.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:51
Exception throws to report errors in the internal logical of the program.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need&#39;s value has been saved.