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 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
47 #define MUELU_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
48 
49 #include <Xpetra_Matrix.hpp>
50 
52 
53 #include "MueLu_FactoryManager.hpp"
54 #include "MueLu_Level.hpp"
55 #include "MueLu_MasterList.hpp"
56 
57 namespace MueLu {
58 
59  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
61  RCP<ParameterList> validParamList = rcp(new ParameterList());
62 
63  validParamList->set< RCP<const FactoryBase> >("A", Teuchos::null, "Generating factory of the matrix A");
64  validParamList->set< std::string > ("orientation", "Z", "Lines orientation");
65  validParamList->set< RCP<const FactoryBase> >("lNodesPerDim", Teuchos::null, "Number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
66 
67  return validParamList;
68  }
69 
70  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
72  Input(currentLevel, "A");
73  // Request the global number of nodes per dimensions
74  if(currentLevel.GetLevelID() == 0) {
75  if(currentLevel.IsAvailable("lNodesPerDim", NoFactory::get())) {
76  currentLevel.DeclareInput("lNodesPerDim", NoFactory::get(), this);
77  } else {
78  TEUCHOS_TEST_FOR_EXCEPTION(currentLevel.IsAvailable("gNodesPerDim", NoFactory::get()),
80  "lNodesPerDim was not provided by the user on level0!");
81  }
82  } else {
83  Input(currentLevel, "lNodesPerDim");
84  }
85  }
86 
87  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
89 
90  // The following three variables are needed by the line smoothers in Ifpack/Ifpack2
91  LO NumZDir = 0;
92  Teuchos::ArrayRCP<LO> VertLineId = Teuchos::arcp<LO>(0);
93 
94  // collect information provided by user
95  const ParameterList& pL = GetParameterList();
96  const std::string lineOrientation = pL.get<std::string>("orientation");
97 
98  // Extract data from currentLevel
99  RCP<Matrix> A = Get< RCP<Matrix> >(currentLevel, "A");
100  Array<LO> lNodesPerDir = Get<Array<LO> > (currentLevel, "lNodesPerDim");
101  LO numNodes = lNodesPerDir[0]*lNodesPerDir[1]*lNodesPerDir[2];
102  VertLineId.resize(numNodes);
103  if(lineOrientation == "X") {
104  NumZDir = lNodesPerDir[0];
105  } else if(lineOrientation == "Y") {
106  NumZDir = lNodesPerDir[1];
107  } else if(lineOrientation == "Z") {
108  NumZDir = lNodesPerDir[2];
109  }
110 
111  for(LO k = 0; k < lNodesPerDir[2]; ++k) {
112  for(LO j = 0; j < lNodesPerDir[1]; ++j) {
113  for(LO i = 0; i < lNodesPerDir[0]; ++i) {
114  if(lineOrientation == "X") {
115  VertLineId[k*lNodesPerDir[1]*lNodesPerDir[0] + j*lNodesPerDir[0] + i] = k*lNodesPerDir[1] + j;
116  } else if(lineOrientation == "Y") {
117  VertLineId[k*lNodesPerDir[1]*lNodesPerDir[0] + j*lNodesPerDir[0] + i] = k*lNodesPerDir[0] + i;
118  } else if(lineOrientation == "Z") {
119  VertLineId[k*lNodesPerDir[1]*lNodesPerDir[0] + j*lNodesPerDir[0] + i] = j*lNodesPerDir[0] + i;
120  }
121  }
122  }
123  }
124 
125  Set(currentLevel, "CoarseNumZLayers", NumZDir);
126  Set(currentLevel, "LineDetection_VertLineIds", VertLineId);
127  }
128 
129 } //namespace MueLu
130 
131 #endif // MUELU_STRUCTUREDLINEDETECTIONFACTORY_DEF_HPP
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
LocalOrdinal LO
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:99
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:76
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.